* [PATCH] soc: ti: knav_dma: Fix device node leak in of_channel_match_helper()
@ 2026-11-10 10:11 zhaofeng2
2026-11-20 16:06 ` Nishanth Menon
2026-11-23 6:50 ` [PATCH v2] soc: ti: knav_dma: fix " zhaofeng2
0 siblings, 2 replies; 4+ messages in thread
From: zhaofeng2 @ 2026-11-10 10:11 UTC (permalink / raw)
To: Nishanth Menon, Santosh Shilimkar
Cc: Zhao Feng, linux-arm-kernel, linux-kernel
From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
of_channel_match_helper() resolves the "ti,navigator-dmas" phandle
with of_parse_phandle_with_fixed_args() to obtain the channel number,
which takes a reference on the dma device node in args.np, but the
reference is never dropped after the channel number has been read
from args.args[0], so the dma node is leaked on every channel open.
Drop the reference once the channel number has been retrieved. The
phandle stored in dma_node is deliberately kept, as its ->name string
is handed out through *dma_instance and compared against later in
knav_dma_open_channel().
Fixes: 88139ed03058 ("soc: ti: add Keystone Navigator DMA support")
Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
---
drivers/soc/ti/knav_dma.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
--- a/drivers/soc/ti/knav_dma.c
+++ b/drivers/soc/ti/knav_dma.c
@@ -387,6 +387,8 @@
return -ENODEV;
}
+ of_node_put(args.np);
+
return args.args[0];
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] soc: ti: knav_dma: Fix device node leak in of_channel_match_helper()
2026-11-10 10:11 [PATCH] soc: ti: knav_dma: Fix device node leak in of_channel_match_helper() zhaofeng2
@ 2026-11-20 16:06 ` Nishanth Menon
2026-11-23 6:50 ` [PATCH v2] soc: ti: knav_dma: fix " zhaofeng2
1 sibling, 0 replies; 4+ messages in thread
From: Nishanth Menon @ 2026-11-20 16:06 UTC (permalink / raw)
To: zhaofeng2; +Cc: Santosh Shilimkar, linux-arm-kernel, linux-kernel
On 18:11-20261110, zhaofeng2 wrote:
> From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
>
> of_channel_match_helper() resolves the "ti,navigator-dmas" phandle
> with of_parse_phandle_with_fixed_args() to obtain the channel number,
> which takes a reference on the dma device node in args.np, but the
> reference is never dropped after the channel number has been read
> from args.args[0], so the dma node is leaked on every channel open.
>
> Drop the reference once the channel number has been retrieved. The
> phandle stored in dma_node is deliberately kept, as its ->name string
> is handed out through *dma_instance and compared against later in
> knav_dma_open_channel().
But, do we need to take care of dma_node around error paths?
>
> Fixes: 88139ed03058 ("soc: ti: add Keystone Navigator DMA support")
> Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
> ---
> drivers/soc/ti/knav_dma.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
> --- a/drivers/soc/ti/knav_dma.c
> +++ b/drivers/soc/ti/knav_dma.c
> @@ -387,6 +387,8 @@
> return -ENODEV;
> }
>
> + of_node_put(args.np);
> +
> return args.args[0];
> }
>
>
>
--
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3 1A34 DDB5 849D 1736 249D
https://ti.com/opensource
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] soc: ti: knav_dma: fix device node leak in of_channel_match_helper()
2026-11-10 10:11 [PATCH] soc: ti: knav_dma: Fix device node leak in of_channel_match_helper() zhaofeng2
2026-11-20 16:06 ` Nishanth Menon
@ 2026-11-23 6:50 ` zhaofeng2
2026-12-03 16:08 ` Andrew Davis
1 sibling, 1 reply; 4+ messages in thread
From: zhaofeng2 @ 2026-11-23 6:50 UTC (permalink / raw)
To: Nishanth Menon, Santosh Shilimkar
Cc: Zhao Feng, linux-arm-kernel, linux-kernel
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.
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;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] soc: ti: knav_dma: fix device node leak in of_channel_match_helper()
2026-11-23 6:50 ` [PATCH v2] soc: ti: knav_dma: fix " zhaofeng2
@ 2026-12-03 16:08 ` Andrew Davis
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Davis @ 2026-12-03 16:08 UTC (permalink / raw)
To: zhaofeng2, Nishanth Menon, Santosh Shilimkar
Cc: linux-arm-kernel, linux-kernel
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;
> }
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 16:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 10:11 [PATCH] soc: ti: knav_dma: Fix device node leak in of_channel_match_helper() 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 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®