From: geert@linux-m68k.org (Geert Uytterhoeven)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V2 1/3] clk: add clk_bulk_get accessories
Date: Mon, 8 May 2017 17:08:46 +0200 [thread overview]
Message-ID: <CAMuHMdVDOor0E2cjEKO+=Pm+1MGO4BibGTdULPvPKd390fTxuw@mail.gmail.com> (raw)
In-Reply-To: <1494252233-21074-2-git-send-email-aisheng.dong@nxp.com>
Hi Dong,
On Mon, May 8, 2017 at 4:03 PM, Dong Aisheng <aisheng.dong@nxp.com> wrote:
> --- /dev/null
> +++ b/drivers/clk/clk-bulk.c
> @@ -0,0 +1,165 @@
> +int __must_check clk_bulk_get(struct device *dev, int num_clks,
> + struct clk_bulk_data *clks)
> +{
> + int ret;
> + int i;
> +
> + for (i = 0; i < num_clks; i++)
> + clks[i].clk = NULL;
> +
> + for (i = 0; i < num_clks; i++) {
> + clks[i].clk = clk_get(dev, clks[i].id);
> + if (IS_ERR(clks[i].clk)) {
> + ret = PTR_ERR(clks[i].clk);
> + dev_err(dev, "Failed to get clk '%s': %d\n",
> + clks[i].id, ret);
> + clks[i].clk = NULL;
> + goto err;
> + }
> + }
> +
> + return 0;
> +
> +err:
> + while (--i >= 0)
> + clk_put(clks[i].clk);
These are released in inverse order, which is good.
> +
> + return ret;
> +}
> +EXPORT_SYMBOL(clk_bulk_get);
> +
> +void clk_bulk_put(int num_clks, struct clk_bulk_data *clks)
> +{
> + int i;
> +
> + for (i = 0; i < num_clks; i++) {
> + clk_put(clks[i].clk);
> + clks[i].clk = NULL;
These aren't.
Typically resources are released in the inverse order. Not doing so may
cause subtle issues.
I can't come up with an example. but I'm quite sure the real world will find
one soon ;-)
The same is true for enable vs. disable, and prepare vs. unprepare.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
next prev parent reply other threads:[~2017-05-08 15:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-08 14:03 [PATCH V2 0/3] clk: introduce clk_bulk_get accessories Dong Aisheng
2017-05-08 14:03 ` [PATCH V2 1/3] clk: add " Dong Aisheng
2017-05-08 15:08 ` Geert Uytterhoeven [this message]
2017-05-09 12:14 ` Dong Aisheng
2017-05-08 14:03 ` [PATCH V2 2/3] clk: add managed version of clk_bulk_get Dong Aisheng
2017-05-08 14:03 ` [PATCH V2 3/3] cpufreq: imx6q: refine clk operations Dong Aisheng
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='CAMuHMdVDOor0E2cjEKO+=Pm+1MGO4BibGTdULPvPKd390fTxuw@mail.gmail.com' \
--to=geert@linux-m68k.org \
--cc=linux-arm-kernel@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;
as well as URLs for NNTP newsgroup(s).