From: Andrew Davis <afd@ti.com>
To: Markus Elfring <Markus.Elfring@web.de>,
<linux-remoteproc@vger.kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Hari Nagalla <hnagalla@ti.com>,
Martyn Welch <martyn.welch@collabora.com>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Suman Anna <s-anna@ti.com>, Wadim Egorov <w.egorov@phytec.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
<kernel-janitors@vger.kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Subject: Re: [PATCH] remoteproc: k3: Call of_node_put(rmem_np) only once in three functions
Date: Tue, 24 Sep 2024 10:29:35 -0500 [thread overview]
Message-ID: <666e3f5a-6b22-4530-b018-c194f33415b8@ti.com> (raw)
In-Reply-To: <c46b06f9-72b1-420b-9dce-a392b982140e@web.de>
On 9/24/24 7:43 AM, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 24 Sep 2024 14:28:35 +0200
>
> An of_node_put(rmem_np) call was immediately used after a pointer check
> for a of_reserved_mem_lookup() call in three function implementations.
> Thus call such a function only once instead directly before the checks.
>
> This issue was transformed by using the Coccinelle software.
>
Quick check of all the users of of_reserved_mem_lookup(), they almost
all do the same thing, get the phandle, mem_lookup, then node_put.
Maybe a helper function like this:
struct reserved_mem *of_reserved_mem_region_lookup(const struct device_node *node, int index)
{
struct device_node *np;
struct reserved_mem *rmem;
np = of_parse_phandle(node, "memory-region", index);
if (!np)
return ERR_PTR(-ENODEV);
rmem = of_reserved_mem_lookup(np);
of_node_put(np);
if (!rmem)
return ERR_PTR(-EINVAL);
return rmem;
}
Added to of_reserved_mem.c would allow us to clean up these cases in
this patch, and then several more spots (and also help force standard
property name usage).
Andrew
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/remoteproc/ti_k3_dsp_remoteproc.c | 6 ++----
> drivers/remoteproc/ti_k3_m4_remoteproc.c | 6 ++----
> drivers/remoteproc/ti_k3_r5_remoteproc.c | 3 +--
> 3 files changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
> index 8be3f631c192..d08a3a98ada1 100644
> --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
> +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
> @@ -576,11 +576,9 @@ static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc)
> return -EINVAL;
>
> rmem = of_reserved_mem_lookup(rmem_np);
> - if (!rmem) {
> - of_node_put(rmem_np);
> - return -EINVAL;
> - }
> of_node_put(rmem_np);
> + if (!rmem)
> + return -EINVAL;
>
> kproc->rmem[i].bus_addr = rmem->base;
> /* 64-bit address regions currently not supported */
> diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
> index 09f0484a90e1..a16fb165fced 100644
> --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
> +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
> @@ -433,11 +433,9 @@ static int k3_m4_reserved_mem_init(struct k3_m4_rproc *kproc)
> return -EINVAL;
>
> rmem = of_reserved_mem_lookup(rmem_np);
> - if (!rmem) {
> - of_node_put(rmem_np);
> - return -EINVAL;
> - }
> of_node_put(rmem_np);
> + if (!rmem)
> + return -EINVAL;
>
> kproc->rmem[i].bus_addr = rmem->base;
> /* 64-bit address regions currently not supported */
> diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c
> index 747ee467da88..d0ebdd5cfa70 100644
> --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c
> +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c
> @@ -1001,12 +1001,11 @@ static int k3_r5_reserved_mem_init(struct k3_r5_rproc *kproc)
> }
>
> rmem = of_reserved_mem_lookup(rmem_np);
> + of_node_put(rmem_np);
> if (!rmem) {
> - of_node_put(rmem_np);
> ret = -EINVAL;
> goto unmap_rmem;
> }
> - of_node_put(rmem_np);
>
> kproc->rmem[i].bus_addr = rmem->base;
> /*
> --
> 2.46.1
>
next prev parent reply other threads:[~2024-09-24 15:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-24 12:43 Markus Elfring
2024-09-24 14:32 ` Martyn Welch
2024-09-24 15:29 ` Andrew Davis [this message]
2024-09-30 16:45 ` Mathieu Poirier
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=666e3f5a-6b22-4530-b018-c194f33415b8@ti.com \
--to=afd@ti.com \
--cc=Markus.Elfring@web.de \
--cc=andersson@kernel.org \
--cc=hnagalla@ti.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=martyn.welch@collabora.com \
--cc=mathieu.poirier@linaro.org \
--cc=s-anna@ti.com \
--cc=w.egorov@phytec.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
all inboxes | Powered by JetHome®