From: Stephen Boyd <sboyd@kernel.org>
To: "Nuno Sá" <nuno.sa@analog.com>, linux-clk@vger.kernel.org
Cc: Michael Turquette <mturquette@baylibre.com>
Subject: Re: [RFC PATCH 1/4] clk: clk-conf: properly release of nodes
Date: Thu, 21 Apr 2022 12:58:00 -0700 [thread overview]
Message-ID: <20220421195802.2127DC385A1@smtp.kernel.org> (raw)
In-Reply-To: <20220407133036.213217-2-nuno.sa@analog.com>
Quoting Nuno Sá (2022-04-07 06:30:33)
> We need to call 'of_node_put()' when we are done with the node or on
> error paths. Otherwise this can leak memory in DYNAMIC_OF setups.
>
> Fixes: 86be408bfbd8 ("clk: Support for clock parents and rates assigned from device tree")
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> (cherry picked from commit 69eb47a26e7f728a5c052687380993cd9a0dd643)
This line should be removed.
> ---
> drivers/clk/clk-conf.c | 18 ++++++++++++++----
> 1 file changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c
> index 2ef819606c41..d6065cdf1540 100644
> --- a/drivers/clk/clk-conf.c
> +++ b/drivers/clk/clk-conf.c
> @@ -33,9 +33,12 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier)
> else
> return rc;
> }
> - if (clkspec.np == node && !clk_supplier)
> + if (clkspec.np == node && !clk_supplier) {
> + of_node_put(clkspec.np);
> return 0;
> + }
> pclk = of_clk_get_from_provider(&clkspec);
> + of_node_put(clkspec.np);
> if (IS_ERR(pclk)) {
> if (PTR_ERR(pclk) != -EPROBE_DEFER)
> pr_warn("clk: couldn't get parent clock %d for %pOF\n",
I suspect it would be easier to follow and fix if the code was
reorganized to have most of the contents inside this function as a
sub-routine that is called for each index. Then all the node putting and
clk putting can be in one place in that other function and this is a
simple loop around that stops on the first error.
> @@ -49,7 +52,7 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier)
> goto err;
> if (clkspec.np == node && !clk_supplier) {
> rc = 0;
> - goto err;
> + goto err_of_put;
> }
> clk = of_clk_get_from_provider(&clkspec);
> if (IS_ERR(clk)) {
next prev parent reply other threads:[~2022-04-21 19:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-07 13:30 [RFC PATCH 0/4] Dynamic OF and use after free related fixes Nuno Sá
2022-04-07 13:30 ` [RFC PATCH 1/4] clk: clk-conf: properly release of nodes Nuno Sá
2022-04-21 19:58 ` Stephen Boyd [this message]
2022-04-22 7:18 ` Sa, Nuno
2022-04-22 7:20 ` Sa, Nuno
2022-04-07 13:30 ` [RFC PATCH 2/4] clk: fix clk not being unlinked from consumers list Nuno Sá
2022-04-22 0:20 ` Stephen Boyd
2022-04-22 7:40 ` Sa, Nuno
2022-04-07 13:30 ` [RFC PATCH 3/4] clk: refcount the active parent clk_core Nuno Sá
2022-04-07 13:30 ` [RFC PATCH 4/4] clk: use clk_core_unlink_consumer() helper Nuno Sá
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=20220421195802.2127DC385A1@smtp.kernel.org \
--to=sboyd@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=nuno.sa@analog.com \
/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