Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2575698rwa; Mon, 22 Aug 2022 09:50:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR6V4fAGUFEpx3NlUstV4miMVieUxFRCDfCKvmrdAeTC/aAgqIK6PAhQ0ULRWq52elLIbEj+ X-Received: by 2002:a05:6a00:1496:b0:52f:734f:9122 with SMTP id v22-20020a056a00149600b0052f734f9122mr21786272pfu.85.1661187031616; Mon, 22 Aug 2022 09:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661187031; cv=none; d=google.com; s=arc-20160816; b=eIj8T2RNSyN9GQwTGTwVGOjjKqre8lmnWOFb7zt5y/fyuT3chpGC+ylQHf+9F7IwL0 nLjU6DhRY5fT7KCIvlshuy9fwt/lXW8NFFtVi4Z2mKAwcZQqrYVqn0yGZgCWPbnZvnvQ /4R5Ht6ZPbgxok2kak6jSVDI7gk0IW/FPas5p50gKo1CvGjTUv/keLkJM20FlWRMeMF1 G2l9K7bsLEGODxu/MB0szNo46L/rtQkuERRNLL70V0CpLZO5qjil0RYD6LM3au/LzJ1u 0ot2Wd8RFxs7aM9ufUURjcwfuBpQgRTbxBkYOVZNYXBVlZ3eiIoRkYIAI3KLta7bcdyS Umnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=28oTaBj3QQ5qfaOFdNPJMDdWbmEaZFUPrH2tNyFmGNs=; b=WpPJk04ls58+OwRYlpgG2BX34j5nmrwfQRpwYcLGvhXfWT9GjgquVG90DsURGJ508J AOM5QW2CuJswfAw9DJHheVQLnA072ICyAhwESQ6J9qXbvE3GhVozQKkrDOAoU8/at6ty rtPxznmKbWKhvNO0fyCCjBWEl1lApp1KQnLEXIQH7Eh/HheE1WMSQsT3mlAi7kdmDZLr ESUzT5uU6c6wnii1F8zJb71ov6J9w+MhoiWVaWp/Iz/AmEJxsDNLn32UADKjMcvnNh5g +AloRZBRBYes9KAurtJROstMsLAHV8W84R52Ca5CXc0YR6sP7H4kfBQaU3S9bojJdmGb 8FQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=Mz37NWka; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020aa78b43000000b005352d5716adsi12120187pfd.349.2022.08.22.09.50.20; Mon, 22 Aug 2022 09:50:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=Mz37NWka; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236609AbiHVP2q (ORCPT + 99 others); Mon, 22 Aug 2022 11:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236586AbiHVP2T (ORCPT ); Mon, 22 Aug 2022 11:28:19 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E9927662 for ; Mon, 22 Aug 2022 08:27:32 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id a4so13697387wrq.1 for ; Mon, 22 Aug 2022 08:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=28oTaBj3QQ5qfaOFdNPJMDdWbmEaZFUPrH2tNyFmGNs=; b=Mz37NWkaYb8tMZzMmpyuq6NH9EzKNwvmWsb3pTvm4FhWcQbDGD11j6E62eklimeBJY 3p9KSEGRD+4Fy+N918v25mr32pNsi3krgMHS4wTrb3BK+xetSFwNVbMS7Cb23Bp80yhL yAcgkqmXLCeB4oudoaBtSXH/QLAv8qCTE33weqW3pJ3VszCOnzEpZHy7IvvL45PLN58k 4SqzJnOs9xSWK282JiFioTkTntzb2mEbq1Q0ysUWJYCgFiCrjht1OXBUByxGq270M3bB mQG8vG6s3rZAmCDJ0xm/c0Cy9C374UIWueZy882vN51ffj+1HCVc0lx1FlNB6atJDOno a7Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=28oTaBj3QQ5qfaOFdNPJMDdWbmEaZFUPrH2tNyFmGNs=; b=NRZ6eYg6AUzdjTZXUUUub9zQUEIRCAIROScKPV01wDjSBZxJ/xmQ8M1oLckCeE5j2g shjys/+zVyX5kn8x2r1q6auT5sW6FRZfnnUPg7SG7sj9xJwMtmC+u3nySZsNYRMthTjR sUvZ5D9n6JfoNmT2TtXysj0s1lG8Xm17guiB5RyHNbXsH4FCyl3RwRI52aP30TB2NjTX FiAmczCYRIPCG2anfb0JukwigQzzzu51JmRgWckMEaHu0PvTYaeR04sL5OL/xgYXZMjV qKUllvM4rY3NW9uxT61qJTT31zZ/lY8xlo/i8MPdUabaws5PEuKBF413yCXLSP3qi31y Bsfg== X-Gm-Message-State: ACgBeo01oF8tGzgluAUs7Ob2FJ8uUW8PNlPlGsiHiGfjFfY+R5oShvto 1iCHGs7N36gnLTwrpkC5/VpMQA== X-Received: by 2002:a05:6000:1867:b0:21f:f2cf:74a8 with SMTP id d7-20020a056000186700b0021ff2cf74a8mr11191849wri.344.1661182050812; Mon, 22 Aug 2022 08:27:30 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4090:a245:8020:2658:1f7c:362:3e99]) by smtp.gmail.com with ESMTPSA id u18-20020adfdb92000000b0021eaf4138aesm14492011wri.108.2022.08.22.08.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 08:27:30 -0700 (PDT) From: Markus Schneider-Pargmann To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Matthias Brugger , Fabien Parent , AngeloGioacchino Del Regno Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH v4 2/4] clk: mediatek: Provide mtk_devm_alloc_clk_data Date: Mon, 22 Aug 2022 17:26:50 +0200 Message-Id: <20220822152652.3499972-3-msp@baylibre.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220822152652.3499972-1-msp@baylibre.com> References: <20220822152652.3499972-1-msp@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide a helper that replaces the kzalloc with devm_kzalloc so error handling gets easier. Signed-off-by: Markus Schneider-Pargmann --- Notes: Changes in v3: - New patch drivers/clk/mediatek/clk-mtk.c | 33 ++++++++++++++++++++++++++++----- drivers/clk/mediatek/clk-mtk.h | 2 ++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 05a188c62119..ef4c29422bbb 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -18,19 +18,42 @@ #include "clk-mtk.h" #include "clk-gate.h" -struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num) +static void mtk_init_clk_data(struct clk_hw_onecell_data *clk_data, + unsigned int clk_num) { int i; + + clk_data->num = clk_num; + + for (i = 0; i < clk_num; i++) + clk_data->hws[i] = ERR_PTR(-ENOENT); +} + +struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev, + unsigned int clk_num) +{ struct clk_hw_onecell_data *clk_data; - clk_data = kzalloc(struct_size(clk_data, hws, clk_num), GFP_KERNEL); + clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, clk_num), + GFP_KERNEL); if (!clk_data) return NULL; - clk_data->num = clk_num; + mtk_init_clk_data(clk_data, clk_num); - for (i = 0; i < clk_num; i++) - clk_data->hws[i] = ERR_PTR(-ENOENT); + return clk_data; +} +EXPORT_SYMBOL_GPL(mtk_devm_alloc_clk_data); + +struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num) +{ + struct clk_hw_onecell_data *clk_data; + + clk_data = kzalloc(struct_size(clk_data, hws, clk_num), GFP_KERNEL); + if (!clk_data) + return NULL; + + mtk_init_clk_data(clk_data, clk_num); return clk_data; } diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index 1b95c484d5aa..190fe66ae79f 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -184,6 +184,8 @@ void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num, struct clk_hw_onecell_data *clk_data); struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num); +struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev, + unsigned int clk_num); void mtk_free_clk_data(struct clk_hw_onecell_data *clk_data); struct clk_hw *mtk_clk_register_ref2usb_tx(const char *name, -- 2.37.2