mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] clk: implement clk_get_enabled helper
Date: Thu, 14 Sep 2023 09:46:40 +0200	[thread overview]
Message-ID: <20230914074640.GI637806@pengutronix.de> (raw)
In-Reply-To: <20230913120807.1869600-2-a.fatoum@pengutronix.de>

On Wed, Sep 13, 2023 at 02:08:06PM +0200, Ahmad Fatoum wrote:
> Kernel code increasingly uses devm_clk_get_enabled to make driver code
> more compact. Port a devres-less version to barebox to make porting such
> Linux code easier.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  include/linux/clk.h | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/include/linux/clk.h b/include/linux/clk.h
> index 82022e78e39d..398427eca676 100644
> --- a/include/linux/clk.h
> +++ b/include/linux/clk.h
> @@ -951,4 +951,33 @@ static inline struct clk *clk_get_optional(struct device *dev, const char *id)
>  	return clk;
>  }
>  
> +/**
> + * clk_get_enabled - clk_get() + clk_prepare_enable()
> + * @dev: device for clock "consumer"
> + * @id: clock consumer ID
> + *
> + * Return: a struct clk corresponding to the clock producer, or
> + * valid IS_ERR() condition containing errno.  The implementation
> + * uses @dev and @id to determine the clock consumer, and thereby
> + * the clock producer.  (IOW, @id may be identical strings, but
> + * clk_get may return different clock producers depending on @dev.)
> + *
> + * The returned clk (if valid) is enabled.
> + */
> +static inline struct clk *clk_get_enabled(struct device *dev, const char *id)
> +{
> +	struct clk *clk;
> +	int ret;
> +
> +	clk = clk_get(dev, id);
> +	if (IS_ERR(clk))
> +		return clk;
> +
> +	ret = clk_enable(clk);
> +	if (ret)
> +		return ERR_PTR(ret);

As this isn't devm managed you should release the clock in the error
path.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2023-09-14  7:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13 12:08 [PATCH 0/2] watchdog: add Cadence watchdog support for Xilinx SoCs Ahmad Fatoum
2023-09-13 12:08 ` [PATCH 1/2] clk: implement clk_get_enabled helper Ahmad Fatoum
2023-09-14  7:46   ` Sascha Hauer [this message]
2023-09-14  7:52     ` Ahmad Fatoum
2023-09-14  7:52     ` Sascha Hauer
2023-09-13 12:08 ` [PATCH 2/2] watchdog: add Cadence watchdog support for Xilinx SoCs Ahmad Fatoum

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=20230914074640.GI637806@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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