From patchwork Wed Mar 24 15:18:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 407865 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp501854jai; Wed, 24 Mar 2021 08:19:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhwl5cUxsQDQxmOs5uGCuc4q4V67/R1XtmHwihcWA07EVBPGmHajYUbw1y0NGCmLurpfJq X-Received: by 2002:aa7:956d:0:b029:1f1:5ba6:2a58 with SMTP id x13-20020aa7956d0000b02901f15ba62a58mr3708509pfq.63.1616599160677; Wed, 24 Mar 2021 08:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616599160; cv=none; d=google.com; s=arc-20160816; b=wlFEskzDc3cLNbYRZxXsU+CUA9QO8iGziY1inEfNhOLa9ah3CHQiaDFe8y7/sEddpn 28u5d37ZAmz0CN/LrxeLcAO16w8jVSjFm6wpgD4BCvHo+Qx8gMLMaUjNY2b6tosqpEbE 9b4Wc3iaXOeXr7sBU9O9Lx55+j0TvIWXCbntFVQgoaI/+gNv9V4CpdBVbLYyPmngpiG1 1j1MAom+7IUCZV940zAMsGAWLRnhNZi/bChtuzNuqyTnYeZJ+N6bU73VJSNGhr85+a8z 2RTKTXDGcmyT1nTWCU+MuLKBVXrM03ouscVHSSzzlFO8XBWl6CpT1ZzjN8A8tA8pHYoS SlyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:delivered-to; bh=9dhBzSYBDKoEQa/4g+X1BAfk27Dp0AlOfHX5cjpTqrQ=; b=jdsrRPf/R7HNc/1kIbNIByUjLPVi4d7/X929f4EyTx1NU5RTNg/LLtCzvKgSWdZ53f O0Vw+Ct4DQ5XwSWrK+eSpJjH9xRhBkB3MSTsOsFMqexRXiZcN8TnWikfXeyMRIRQYvb/ 6bdFEcYdOztM7p68Wxdjo3AoPvQr+it6wUjj45sMGQVu3iidfHA8bOSB/HaZMkjg5td6 4hMgmn9nrvqwphamYtO29hOokwqXKdxaFapbidiniMgZyslOskTOcIXS2vmDWNvHHEku 6lv+lVpKuJl41fum3Pgk92g29RsVLmAK5C1F9tHy3Z8cy+0BesHtqycNmzAXRBhbpIz2 U9WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=umv8kGD2; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id d5si2376025pll.383.2021.03.24.08.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 08:19:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=umv8kGD2; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EFEF36EC69; Wed, 24 Mar 2021 15:19:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 381896EA1F for ; Wed, 24 Mar 2021 15:19:09 +0000 (UTC) Received: by mail-lf1-x12d.google.com with SMTP id o126so23037427lfa.0 for ; Wed, 24 Mar 2021 08:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7jEz8oihVJdadZw/hP+a4+zFOQ5LD0ulQWufz9UuUgQ=; b=umv8kGD2XAiabDM1eKGbsE+1QjsA7nf8WlZCAwm+jjA8SUY+de6PtmpOmplebBTrmK uR5yYJUbpQ1NTFSaeMDWa/4ENqtACs0W9iENlaa9EEJDeO/J/5WFR5f4qD50e3Ln/pEz AgXWxhqAONka76khzwgmVMTJbI5WoApWNS6PQyAfMlmXVRdP8M8Lku1pG6nGCKJRPWmE gPROGTT7Ka3bm0rbgD9ChWkbcHRQ+qIAdlvSqH8U1y92LguFTTBBtjlfvF98AxiO2uPk EaJVxwRRnkzO9RPmc++A4GExaAc9TSm4G7bP1OR/ZOEGgEFXlKzhXvsz/Kky3p2cWzOA QjLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7jEz8oihVJdadZw/hP+a4+zFOQ5LD0ulQWufz9UuUgQ=; b=iOJsOnl8CB/PRcLOxvXf1i+W3RqgnrdSRzJVZv6Yceb1myrnjS5pQ7zYtkZQycmS3L rUd6p5nZZpDd27h3VwHoca7tLfXvAUBxH+lnONS0FlvCew7/o1zg0MN8MqtvMF1VzsUQ vHt0hTiOcmOW1FsMUtyRXjMjaJosfsl8i4DLofF5mcymWBnGWp/mdfa78eD2QRhsIIj9 1C92IDPShPPIjGlTSCrXeLOAZvs2esEQ5yX2pNp/Q3s70HH5/8ikuGAK/i8FBrhVR1yN 9r47gds3F66cm79w0WcwAY4AYb518Kj2XK0IyRqu0x+WNjX2NMlOXZinR3vJa2yt0wKs 0yLQ== X-Gm-Message-State: AOAM53165/s99UJIsMG3U75GFeK1kfcTZZgVujeF5pQv/3ghCrXDIkV9 4+jaDd5Vc4zWK2zO971STadeEw== X-Received: by 2002:a05:6512:1192:: with SMTP id g18mr2136641lfr.408.1616599147684; Wed, 24 Mar 2021 08:19:07 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id d22sm255199lfm.267.2021.03.24.08.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 08:19:06 -0700 (PDT) From: Dmitry Baryshkov To: Rob Clark , Sean Paul , Jonathan Marek , Michael Turquette Subject: [PATCH v2 01/28] clk: fixed: add devm helper for clk_hw_register_fixed_factor() Date: Wed, 24 Mar 2021 18:18:19 +0300 Message-Id: <20210324151846.2774204-2-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324151846.2774204-1-dmitry.baryshkov@linaro.org> References: <20210324151846.2774204-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stephen Boyd , linux-arm-msm@vger.kernel.org, Daniel Palmer , dri-devel@lists.freedesktop.org, David Airlie , freedreno@lists.freedesktop.org, linux-clk@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Daniel Palmer Add a devm helper for clk_hw_register_fixed_factor() so that drivers that internally register fixed factor clocks for things like dividers don't need to manually unregister them on remove or if probe fails. Signed-off-by: Daniel Palmer Link: https://lore.kernel.org/r/20210211052206.2955988-4-daniel@0x0f.com Signed-off-by: Stephen Boyd --- drivers/clk/clk-fixed-factor.c | 39 ++++++++++++++++++++++++++++------ include/linux/clk-provider.h | 4 +++- 2 files changed, 36 insertions(+), 7 deletions(-) -- 2.30.2 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel Reviewed-by: Abhinav Kumar diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c index 910e6e74ae90..4f7bf3929d6d 100644 --- a/drivers/clk/clk-fixed-factor.c +++ b/drivers/clk/clk-fixed-factor.c @@ -64,10 +64,16 @@ const struct clk_ops clk_fixed_factor_ops = { }; EXPORT_SYMBOL_GPL(clk_fixed_factor_ops); +static void devm_clk_hw_register_fixed_factor_release(struct device *dev, void *res) +{ + clk_hw_unregister_fixed_factor(&((struct clk_fixed_factor *)res)->hw); +} + static struct clk_hw * __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np, const char *name, const char *parent_name, int index, - unsigned long flags, unsigned int mult, unsigned int div) + unsigned long flags, unsigned int mult, unsigned int div, + bool devm) { struct clk_fixed_factor *fix; struct clk_init_data init = { }; @@ -75,7 +81,15 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np, struct clk_hw *hw; int ret; - fix = kmalloc(sizeof(*fix), GFP_KERNEL); + /* You can't use devm without a dev */ + if (devm && !dev) + return ERR_PTR(-EINVAL); + + if (devm) + fix = devres_alloc(devm_clk_hw_register_fixed_factor_release, + sizeof(*fix), GFP_KERNEL); + else + fix = kmalloc(sizeof(*fix), GFP_KERNEL); if (!fix) return ERR_PTR(-ENOMEM); @@ -99,9 +113,13 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np, else ret = of_clk_hw_register(np, hw); if (ret) { - kfree(fix); + if (devm) + devres_free(fix); + else + kfree(fix); hw = ERR_PTR(ret); - } + } else if (devm) + devres_add(dev, fix); return hw; } @@ -111,7 +129,7 @@ struct clk_hw *clk_hw_register_fixed_factor(struct device *dev, unsigned int mult, unsigned int div) { return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, -1, - flags, mult, div); + flags, mult, div, false); } EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor); @@ -153,6 +171,15 @@ void clk_hw_unregister_fixed_factor(struct clk_hw *hw) } EXPORT_SYMBOL_GPL(clk_hw_unregister_fixed_factor); +struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev, + const char *name, const char *parent_name, unsigned long flags, + unsigned int mult, unsigned int div) +{ + return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, -1, + flags, mult, div, true); +} +EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor); + #ifdef CONFIG_OF static const struct of_device_id set_rate_parent_matches[] = { { .compatible = "allwinner,sun4i-a10-pll3-2x-clk" }, @@ -185,7 +212,7 @@ static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node) flags |= CLK_SET_RATE_PARENT; hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, 0, - flags, mult, div); + flags, mult, div, false); if (IS_ERR(hw)) { /* * Clear OF_POPULATED flag so that clock registration can be diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index e4316890661a..58f6fe866ae9 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -941,7 +941,9 @@ struct clk_hw *clk_hw_register_fixed_factor(struct device *dev, const char *name, const char *parent_name, unsigned long flags, unsigned int mult, unsigned int div); void clk_hw_unregister_fixed_factor(struct clk_hw *hw); - +struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev, + const char *name, const char *parent_name, unsigned long flags, + unsigned int mult, unsigned int div); /** * struct clk_fractional_divider - adjustable fractional divider clock *