From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, <linux-rtc@vger.kernel.org>,
<linux-pwm@vger.kernel.org>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Alessandro Zummo <a.zummo@towertech.it>,
Mark Brown <broonie@kernel.org>,
Claudiu Beznea <claudiu.beznea@microchip.com>,
Wolfram Sang <wsa@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
Ludovic Desroches <ludovic.desroches@microchip.com>,
Thierry Reding <thierry.reding@gmail.com>,
<kernel@pengutronix.de>,
Andrew Morton <akpm@linux-foundation.org>,
<linux-spi@vger.kernel.org>, Lee Jones <lee.jones@linaro.org>,
<linux-clk@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v6 RESEND 1/6] clk: generalize devm_clk_get() a bit
Date: Mon, 10 May 2021 18:02:05 +0100 [thread overview]
Message-ID: <20210510180205.000004dd@Huawei.com> (raw)
In-Reply-To: <20210510061724.940447-2-u.kleine-koenig@pengutronix.de>
On Mon, 10 May 2021 08:17:19 +0200
Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
> Allow to add an exit hook to devm managed clocks. Also use
> clk_get_optional() in devm_clk_get_optional instead of open coding it.
> The generalisation will be used in the next commit to add some more
> devm_clk helpers.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
If feels marginally odd to register cleanup that we know won't do anything
for the optional case, but it works as far as I can tell and it would be
a little fiddly to special case it.
FWIW
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/clk/clk-devres.c | 67 ++++++++++++++++++++++++++++++----------
> 1 file changed, 50 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
> index be160764911b..91c995815b57 100644
> --- a/drivers/clk/clk-devres.c
> +++ b/drivers/clk/clk-devres.c
> @@ -4,39 +4,72 @@
> #include <linux/export.h>
> #include <linux/gfp.h>
>
> +struct devm_clk_state {
> + struct clk *clk;
> + void (*exit)(struct clk *clk);
> +};
> +
> static void devm_clk_release(struct device *dev, void *res)
> {
> - clk_put(*(struct clk **)res);
> + struct devm_clk_state *state = *(struct devm_clk_state **)res;
> +
> + if (state->exit)
> + state->exit(state->clk);
> +
> + clk_put(state->clk);
> }
>
> -struct clk *devm_clk_get(struct device *dev, const char *id)
> +static struct clk *__devm_clk_get(struct device *dev, const char *id,
> + struct clk *(*get)(struct device *dev, const char *id),
> + int (*init)(struct clk *clk),
> + void (*exit)(struct clk *clk))
> {
> - struct clk **ptr, *clk;
> + struct devm_clk_state *state;
> + struct clk *clk;
> + int ret;
>
> - ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
> - if (!ptr)
> + state = devres_alloc(devm_clk_release, sizeof(*state), GFP_KERNEL);
> + if (!state)
> return ERR_PTR(-ENOMEM);
>
> - clk = clk_get(dev, id);
> - if (!IS_ERR(clk)) {
> - *ptr = clk;
> - devres_add(dev, ptr);
> - } else {
> - devres_free(ptr);
> + clk = get(dev, id);
> + if (IS_ERR(clk)) {
> + ret = PTR_ERR(clk);
> + goto err_clk_get;
> }
>
> + if (init) {
> + ret = init(clk);
> + if (ret)
> + goto err_clk_init;
> + }
> +
> + state->clk = clk;
> + state->exit = exit;
> +
> + devres_add(dev, state);
> +
> return clk;
> +
> +err_clk_init:
> +
> + clk_put(clk);
> +err_clk_get:
> +
> + devres_free(state);
> + return ERR_PTR(ret);
> }
> -EXPORT_SYMBOL(devm_clk_get);
>
> -struct clk *devm_clk_get_optional(struct device *dev, const char *id)
> +struct clk *devm_clk_get(struct device *dev, const char *id)
> {
> - struct clk *clk = devm_clk_get(dev, id);
> + return __devm_clk_get(dev, id, clk_get, NULL, NULL);
>
> - if (clk == ERR_PTR(-ENOENT))
> - return NULL;
> +}
> +EXPORT_SYMBOL(devm_clk_get);
>
> - return clk;
> +struct clk *devm_clk_get_optional(struct device *dev, const char *id)
> +{
> + return __devm_clk_get(dev, id, clk_get_optional, NULL, NULL);
> }
> EXPORT_SYMBOL(devm_clk_get_optional);
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-05-10 17:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-10 6:17 [PATCH v6 RESEND 0/6] clk: provide new devm helpers for prepared and enabled clocks Uwe Kleine-König
2021-05-10 6:17 ` [PATCH v6 RESEND 1/6] clk: generalize devm_clk_get() a bit Uwe Kleine-König
2021-05-10 17:02 ` Jonathan Cameron [this message]
2021-05-10 17:27 ` Uwe Kleine-König
2021-05-10 6:17 ` [PATCH v6 RESEND 2/6] clk: Provide new devm_clk_helpers for prepared and enabled clocks Uwe Kleine-König
2021-05-10 17:05 ` Jonathan Cameron
2021-05-10 6:17 ` [PATCH v6 RESEND 4/6] rtc: at91sam9: Simplify using devm_clk_get_enabled() Uwe Kleine-König
2021-05-10 6:17 ` [PATCH v6 RESEND 5/6] i2c: imx: " Uwe Kleine-König
2021-05-10 17:07 ` [PATCH v6 RESEND 0/6] clk: provide new devm helpers for prepared and enabled clocks Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210510180205.000004dd@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=a.zummo@towertech.it \
--cc=akpm@linux-foundation.org \
--cc=alexandre.belloni@bootlin.com \
--cc=broonie@kernel.org \
--cc=claudiu.beznea@microchip.com \
--cc=kernel@pengutronix.de \
--cc=lee.jones@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=ludovic.desroches@microchip.com \
--cc=mturquette@baylibre.com \
--cc=o.rempel@pengutronix.de \
--cc=sboyd@kernel.org \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
--cc=wsa@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).