From: Andrew Davis <afd@ti.com>
To: <zhaofeng2@cmss.chinamobile.com>, Nishanth Menon <nm@ti.com>,
"Santosh Shilimkar" <ssantosh@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] soc: ti: knav_dma: fix device node leak in of_channel_match_helper()
Date: Thu, 3 Dec 2026 10:08:33 -0600 [thread overview]
Message-ID: <b5b56a8c-ea36-4354-a319-ac16d61aeb75@ti.com> (raw)
In-Reply-To: <20261123065006.275-1-zhaofeng2@cmss.chinamobile.com>
On 11/23/26 12:50 AM, zhaofeng2@cmss.chinamobile.com wrote:
> From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
>
> of_channel_match_helper() takes two OF references: one via
> of_parse_phandle() into dma_node (for the ->name string handed out
> through *dma_instance) and one via of_parse_phandle_with_fixed_args()
> into args.np (for the channel number). Both are leaked:
>
> - The three error paths (property match failure, fixed-args parse
> failure, missing args) drop neither dma_node nor args.np.
>
> - The successful path leaked both prior to the initial fix.
>
> Drop dma_node on the two error paths present in upstream, drop
> args.np on the one error path where it is obtained, and on success
> transfer dma_node to the caller so that knav_dma_open_channel(),
> which only uses the ->name string to locate the matching DMA instance
> within the function, can release the reference once the lookup is
> complete.
>
It looks like dma_node->name/instance is also printed out in some
error and debug messages also, which is why you do the of_node_put()
until the very end of knav_dma_open_channel().
Would it be easier to just make and return a copy of the ->name
which gets freed instead? (or pass in a stack char[32] since that
is the max length of the string we compare against, then we
don't even need to free it either).
Andrew
> Fixes: 88139ed03058 ("soc: ti: add Keystone Navigator DMA support")
> Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
> ---
> v2: also release dma_node on error paths and transfer it to
> knav_dma_open_channel() for release after last use, per review
> from Nishanth Menon.
>
> drivers/soc/ti/knav_dma.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> --- a/drivers/soc/ti/knav_dma.c
> +++ b/drivers/soc/ti/knav_dma.c
> @@ -364,7 +364,8 @@
> DEFINE_SHOW_ATTRIBUTE(knav_dma_debug);
>
> static int of_channel_match_helper(struct device_node *np, const char *name,
> - const char **dma_instance)
> + const char **dma_instance,
> + struct device_node **dma_node_out)
> {
> struct of_phandle_args args;
> struct device_node *dma_node;
> @@ -378,15 +379,20 @@
> index = of_property_match_string(np, "ti,navigator-dma-names", name);
> if (index < 0) {
> dev_err(kdev->dev, "No 'ti,navigator-dma-names' property\n");
> + of_node_put(dma_node);
> return -ENODEV;
> }
>
> if (of_parse_phandle_with_fixed_args(np, "ti,navigator-dmas",
> 1, index, &args)) {
> dev_err(kdev->dev, "Missing the phandle args name %s\n", name);
> + of_node_put(dma_node);
> return -ENODEV;
> }
>
> + of_node_put(args.np);
> +
> + *dma_node_out = dma_node;
> return args.args[0];
> }
>
> @@ -403,6 +409,7 @@
> {
> struct knav_dma_device *dma = NULL, *iter1;
> struct knav_dma_chan *chan = NULL, *iter2;
> + struct device_node *dma_node;
> int chan_num = -1;
> const char *instance;
>
> @@ -411,7 +418,7 @@
> return NULL;
> }
>
> - chan_num = of_channel_match_helper(dev->of_node, name, &instance);
> + chan_num = of_channel_match_helper(dev->of_node, name, &instance, &dma_node);
> if (chan_num < 0) {
> dev_err(kdev->dev, "No DMA instance with name %s\n", name);
> return NULL;
> @@ -425,6 +432,7 @@
> if (config->direction != DMA_MEM_TO_DEV &&
> config->direction != DMA_DEV_TO_MEM) {
> dev_err(kdev->dev, "bad direction\n");
> + of_node_put(dma_node);
> return NULL;
> }
>
> @@ -437,6 +445,7 @@
> }
> if (!dma) {
> dev_err(kdev->dev, "No DMA instance with name %s\n", instance);
> + of_node_put(dma_node);
> return NULL;
> }
>
> @@ -457,6 +466,7 @@
> if (!chan) {
> dev_err(kdev->dev, "channel %d is not in DMA %s\n",
> chan_num, instance);
> + of_node_put(dma_node);
> return NULL;
> }
>
> @@ -464,6 +474,7 @@
> if (!check_config(chan, config)) {
> dev_err(kdev->dev, "channel %d config miss-match\n",
> chan_num);
> + of_node_put(dma_node);
> return NULL;
> }
> }
> @@ -476,6 +487,8 @@
>
> dev_dbg(kdev->dev, "channel %d opened from DMA %s\n",
> chan_num, instance);
> +
> + of_node_put(dma_node);
>
> return chan;
> }
>
>
>
prev parent reply other threads:[~2026-12-03 16:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 10:11 [PATCH] soc: ti: knav_dma: Fix " zhaofeng2
2026-11-20 16:06 ` Nishanth Menon
2026-11-23 6:50 ` [PATCH v2] soc: ti: knav_dma: fix " zhaofeng2
2026-12-03 16:08 ` Andrew Davis [this message]
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=b5b56a8c-ea36-4354-a319-ac16d61aeb75@ti.com \
--to=afd@ti.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nm@ti.com \
--cc=ssantosh@kernel.org \
--cc=zhaofeng2@cmss.chinamobile.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
all inboxes | Powered by JetHome®