public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Michael Turquette" <mturquette@baylibre.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: Re: [PATCH v1 1/1] clk: devres: Simplify devres handling functions
Date: Tue, 27 Aug 2024 17:19:04 -0700	[thread overview]
Message-ID: <9e16ddb1c1a697464ce1f5438ab9ca31.sboyd@kernel.org> (raw)
In-Reply-To: <20240822155822.1771677-1-andriy.shevchenko@linux.intel.com>

Quoting Andy Shevchenko (2024-08-22 08:58:22)
> diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
> index 90e6078fb6e1..f03d60706a85 100644
> --- a/drivers/clk/clk-devres.c
> +++ b/drivers/clk/clk-devres.c
> @@ -28,15 +30,13 @@ static struct clk *__devm_clk_get(struct device *dev, const char *id,
>         struct clk *clk;
>         int ret;
>  
> -       state = devres_alloc(devm_clk_release, sizeof(*state), GFP_KERNEL);
> +       state = devm_kmalloc(dev, sizeof(*state), GFP_KERNEL);

When is this allocation freed if the get() fails? When the calling
device driver detaches?

>         if (!state)
>                 return ERR_PTR(-ENOMEM);
>  
>         clk = get(dev, id);
> -       if (IS_ERR(clk)) {
> -               ret = PTR_ERR(clk);
> -               goto err_clk_get;
> -       }
> +       if (IS_ERR(clk))
> +               return clk;
>  
>         if (init) {
>                 ret = init(clk);
> @@ -47,16 +47,14 @@ static struct clk *__devm_clk_get(struct device *dev, const char *id,
>         state->clk = clk;
>         state->exit = exit;
>  
> -       devres_add(dev, state);
> +       ret = devm_add_action_or_reset(dev, devm_clk_release, state);
> +       if (ret)
> +               goto err_clk_init;

Shouldn't we return an error here? Otherwise we call clk_put() twice?

>  
>         return clk;
>  
>  err_clk_init:
> -
>         clk_put(clk);
> -err_clk_get:
> -
> -       devres_free(state);
>         return ERR_PTR(ret);
>  }
>  

I stopped reading, sorry! If you want to do this, please add a bunch of
KUnit tests.

  reply	other threads:[~2024-08-28  0:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22 15:58 [PATCH v1 1/1] clk: devres: Simplify devres handling functions Andy Shevchenko
2024-08-28  0:19 ` Stephen Boyd [this message]
2024-08-28 13:08   ` Andy Shevchenko
2024-08-28 18:39     ` Stephen Boyd
2024-08-28 19:13       ` Andy Shevchenko

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=9e16ddb1c1a697464ce1f5438ab9ca31.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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