* [PATCH] arch: fix resource leak in chmc.c
@ 2025-07-18 9:22 Jacky Liu
2025-07-18 13:25 ` Krzysztof Kozlowski
2025-07-18 13:43 ` [PATCH] " Markus Elfring
0 siblings, 2 replies; 10+ messages in thread
From: Jacky Liu @ 2025-07-18 9:22 UTC (permalink / raw)
To: davem; +Cc: andreas, 1972843537, sparclinux, linux-kernel
From: Siyang Liu <1972843537@qq.com>
In the jbusmc_probe function, the device node mem_node fetched
via of_find_node_by_path("/memory") is not properly freed
on all code paths.
This can lead to leakage of device node reference counts,
which may result in kernel resources not being released.
This issue was detected by rule based static tools
developed by Tencent.
Signed-off-by: Siyang Liu <1972843537@qq.com>
---
arch/sparc/kernel/chmc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/sparc/kernel/chmc.c b/arch/sparc/kernel/chmc.c
index d4c74d6b2e1b..a7040ee7e5bc 100644
--- a/arch/sparc/kernel/chmc.c
+++ b/arch/sparc/kernel/chmc.c
@@ -4,6 +4,7 @@
* Copyright (C) 2001, 2007, 2008 David S. Miller (davem@davemloft.net)
*/
+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
@@ -397,14 +398,14 @@ static void jbusmc_construct_dimm_groups(struct jbusmc *p,
static int jbusmc_probe(struct platform_device *op)
{
const struct linux_prom64_registers *mem_regs;
- struct device_node *mem_node;
+ struct device_node *mem_node __free(device_node) =
+ of_find_node_by_path("/memory");
int err, len, num_mem_regs;
struct jbusmc *p;
const u32 *prop;
const void *ml;
err = -ENODEV;
- mem_node = of_find_node_by_path("/memory");
if (!mem_node) {
printk(KERN_ERR PFX "Cannot find /memory node.\n");
goto out;
--
2.43.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] arch: fix resource leak in chmc.c
2025-07-18 9:22 [PATCH] arch: fix resource leak in chmc.c Jacky Liu
@ 2025-07-18 13:25 ` Krzysztof Kozlowski
2025-07-21 2:04 ` jackysliu
2025-07-18 13:43 ` [PATCH] " Markus Elfring
1 sibling, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-07-18 13:25 UTC (permalink / raw)
To: Jacky Liu, davem; +Cc: andreas, sparclinux, linux-kernel
On 18/07/2025 11:22, Jacky Liu wrote:
> From: Siyang Liu <1972843537@qq.com>
>
> In the jbusmc_probe function, the device node mem_node fetched
> via of_find_node_by_path("/memory") is not properly freed
> on all code paths.
> This can lead to leakage of device node reference counts,
> which may result in kernel resources not being released.
>
> This issue was detected by rule based static tools
> developed by Tencent.
Last time you were using AI, so I have doubts this is "static tools".
Please describe it properly, so we can make informed decision whether to
allocate time on this.
>
> Signed-off-by: Siyang Liu <1972843537@qq.com>
> ---
> arch/sparc/kernel/chmc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/sparc/kernel/chmc.c b/arch/sparc/kernel/chmc.c
> index d4c74d6b2e1b..a7040ee7e5bc 100644
> --- a/arch/sparc/kernel/chmc.c
> +++ b/arch/sparc/kernel/chmc.c
> @@ -4,6 +4,7 @@
> * Copyright (C) 2001, 2007, 2008 David S. Miller (davem@davemloft.net)
> */
>
> +#include <linux/cleanup.h>
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/types.h>
> @@ -397,14 +398,14 @@ static void jbusmc_construct_dimm_groups(struct jbusmc *p,
> static int jbusmc_probe(struct platform_device *op)
> {
> const struct linux_prom64_registers *mem_regs;
> - struct device_node *mem_node;
> + struct device_node *mem_node __free(device_node) =
> + of_find_node_by_path("/memory");
Nah, just free it immediately after user. Don't over complicate this.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] arch: fix resource leak in chmc.c
2025-07-18 9:22 [PATCH] arch: fix resource leak in chmc.c Jacky Liu
2025-07-18 13:25 ` Krzysztof Kozlowski
@ 2025-07-18 13:43 ` Markus Elfring
2025-07-21 3:57 ` [PATCH v2] arch: fix resource leak in jbusmc_probe() jackysliu
1 sibling, 1 reply; 10+ messages in thread
From: Markus Elfring @ 2025-07-18 13:43 UTC (permalink / raw)
To: Siyang Liu, sparclinux; +Cc: LKML, Andreas Larsson, David S. Miller
> In the jbusmc_probe function, the device node mem_node fetched
> via of_find_node_by_path("/memory") is not properly freed
> on all code paths.
…
You may occasionally put more than 62 characters into text lines
of such a change description.
See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc6#n94
* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
* Will an other subsystem specification be more appropriate?
* Would it be more helpful to refer to “jbusmc_probe()” instead of “chmc.c”
in the summary phrase?
Regards,
Markus
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re:[PATCH] arch: fix resource leak in chmc.c
2025-07-18 13:25 ` Krzysztof Kozlowski
@ 2025-07-21 2:04 ` jackysliu
0 siblings, 0 replies; 10+ messages in thread
From: jackysliu @ 2025-07-21 2:04 UTC (permalink / raw)
To: krzk; +Cc: 1972843537, andreas, davem, linux-kernel, sparclinux
On Fri, Jul 18 2025 15:25:47 +0200 Krzysztof Kozlowski wrote:
>Last time you were using AI, so I have doubts this is "static tools".
>Please describe it properly, so we can make informed decision whether to
>allocate time on this.
The tool determines which api is responsible for resource request
and release, and determines if there are resource leak or double free
issues in the code by determining the use of release specifications.
So no AI involved, don't worry.
>Nah, just free it immediately after user. Don't over complicate this.
OK, I'll resubmit a new patch later
Siyang Liu
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] arch: fix resource leak in jbusmc_probe()
2025-07-18 13:43 ` [PATCH] " Markus Elfring
@ 2025-07-21 3:57 ` jackysliu
2025-07-21 7:18 ` Markus Elfring
2025-07-21 8:25 ` [PATCH v2] arch: " Krzysztof Kozlowski
0 siblings, 2 replies; 10+ messages in thread
From: jackysliu @ 2025-07-21 3:57 UTC (permalink / raw)
To: markus.elfring; +Cc: 1972843537, andreas, davem, linux-kernel, sparclinux
From: Siyang Liu <1972843537@qq.com>
In the jbusmc_probe function, the device node mem_node fetched
via of_find_node_by_path("/memory") is not properly freed
on all code paths.
This can lead to leakage of device node reference counts,
which may result in kernel resources not being released.
This issue was detected by rule based static tools
developed by Tencent.
Signed-off-by: Siyang Liu <1972843537@qq.com>
---
arch/sparc/kernel/chmc.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/arch/sparc/kernel/chmc.c b/arch/sparc/kernel/chmc.c
index d4c74d6b2e1b..fd20e4ee0971 100644
--- a/arch/sparc/kernel/chmc.c
+++ b/arch/sparc/kernel/chmc.c
@@ -412,7 +412,7 @@ static int jbusmc_probe(struct platform_device *op)
mem_regs = of_get_property(mem_node, "reg", &len);
if (!mem_regs) {
printk(KERN_ERR PFX "Cannot get reg property of /memory node.\n");
- goto out;
+ goto out_put;
}
num_mem_regs = len / sizeof(*mem_regs);
@@ -420,7 +420,7 @@ static int jbusmc_probe(struct platform_device *op)
p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p) {
printk(KERN_ERR PFX "Cannot allocate struct jbusmc.\n");
- goto out;
+ goto out_put;
}
INIT_LIST_HEAD(&p->list);
@@ -473,6 +473,10 @@ static int jbusmc_probe(struct platform_device *op)
err = 0;
+out_put:
+ of_node_put(mem_node);
+ goto out;
+
out:
return err;
@@ -481,7 +485,7 @@ static int jbusmc_probe(struct platform_device *op)
out_free:
kfree(p);
- goto out;
+ goto out_put;
}
/* Does BANK decode PHYS_ADDR? */
--
2.43.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2] arch: fix resource leak in jbusmc_probe()
2025-07-21 3:57 ` [PATCH v2] arch: fix resource leak in jbusmc_probe() jackysliu
@ 2025-07-21 7:18 ` Markus Elfring
2025-07-21 7:55 ` [PATCH v3] sparc: " jackysliu
2025-07-21 8:25 ` [PATCH v2] arch: " Krzysztof Kozlowski
1 sibling, 1 reply; 10+ messages in thread
From: Markus Elfring @ 2025-07-21 7:18 UTC (permalink / raw)
To: Siyang Liu, sparclinux; +Cc: LKML, Andreas Larsson, David S. Miller
…> This can lead to leakage of device node reference counts,
> which may result in kernel resources not being released.
…
See also one more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc6#n94
* Will you become more interested in additional tags (like “Fixes” and “Cc”)?
* Would the subsystem specification “sparc” be more appropriate
in the summary phrase?
…> ---
> arch/sparc/kernel/chmc.c | 10 +++++++---
…
How do you think about to improve your version management?
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc6#n784
Regards,
Markus
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3] sparc: fix resource leak in jbusmc_probe()
2025-07-21 7:18 ` Markus Elfring
@ 2025-07-21 7:55 ` jackysliu
2025-07-21 8:17 ` Markus Elfring
2025-07-22 6:22 ` Krzysztof Kozlowski
0 siblings, 2 replies; 10+ messages in thread
From: jackysliu @ 2025-07-21 7:55 UTC (permalink / raw)
To: markus.elfring; +Cc: 1972843537, andreas, davem, linux-kernel, sparclinux
From: Siyang Liu <1972843537@qq.com>
In the jbusmc_probe function, the device node mem_node fetched
via of_find_node_by_path("/memory") is not properly freed
on all code paths.
This can lead to leakage of device node reference counts,
which may result in kernel resources not being released.
This issue was detected by rule based static tools
developed by Tencent.
Fixes: e70140ba0d2b ("Get rid of 'remove_new' relic from platform driver struct")
Signed-off-by: Siyang Liu <1972843537@qq.com>
---
arch/sparc/kernel/chmc.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/arch/sparc/kernel/chmc.c b/arch/sparc/kernel/chmc.c
index d4c74d6b2e1b..fd20e4ee0971 100644
--- a/arch/sparc/kernel/chmc.c
+++ b/arch/sparc/kernel/chmc.c
@@ -412,7 +412,7 @@ static int jbusmc_probe(struct platform_device *op)
mem_regs = of_get_property(mem_node, "reg", &len);
if (!mem_regs) {
printk(KERN_ERR PFX "Cannot get reg property of /memory node.\n");
- goto out;
+ goto out_put;
}
num_mem_regs = len / sizeof(*mem_regs);
@@ -420,7 +420,7 @@ static int jbusmc_probe(struct platform_device *op)
p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p) {
printk(KERN_ERR PFX "Cannot allocate struct jbusmc.\n");
- goto out;
+ goto out_put;
}
INIT_LIST_HEAD(&p->list);
@@ -473,6 +473,10 @@ static int jbusmc_probe(struct platform_device *op)
err = 0;
+out_put:
+ of_node_put(mem_node);
+ goto out;
+
out:
return err;
@@ -481,7 +485,7 @@ static int jbusmc_probe(struct platform_device *op)
out_free:
kfree(p);
- goto out;
+ goto out_put;
}
/* Does BANK decode PHYS_ADDR? */
--
2.43.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3] sparc: fix resource leak in jbusmc_probe()
2025-07-21 7:55 ` [PATCH v3] sparc: " jackysliu
@ 2025-07-21 8:17 ` Markus Elfring
2025-07-22 6:22 ` Krzysztof Kozlowski
1 sibling, 0 replies; 10+ messages in thread
From: Markus Elfring @ 2025-07-21 8:17 UTC (permalink / raw)
To: Siyang Liu, sparclinux; +Cc: LKML, Andreas Larsson, David S. Miller
…> ---
> arch/sparc/kernel/chmc.c | 10 +++++++---
…
Why did you overlook mentioned patch requirements once more?
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc6#n784
Regards,
Markus
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] arch: fix resource leak in jbusmc_probe()
2025-07-21 3:57 ` [PATCH v2] arch: fix resource leak in jbusmc_probe() jackysliu
2025-07-21 7:18 ` Markus Elfring
@ 2025-07-21 8:25 ` Krzysztof Kozlowski
1 sibling, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-07-21 8:25 UTC (permalink / raw)
To: jackysliu, markus.elfring; +Cc: andreas, davem, linux-kernel, sparclinux
On 21/07/2025 05:57, jackysliu wrote:
> From: Siyang Liu <1972843537@qq.com>
>
> In the jbusmc_probe function, the device node mem_node fetched
> via of_find_node_by_path("/memory") is not properly freed
> on all code paths.
> This can lead to leakage of device node reference counts,
> which may result in kernel resources not being released.
Please wrap commit message according to Linux coding style / submission
process (neither too early nor over the limit):
https://elixir.bootlin.com/linux/v6.4-rc1/source/Documentation/process/submitting-patches.rst#L597
Do not attach (thread) your patchsets to some other threads (unrelated
or older versions). This buries them deep in the mailbox and might
interfere with applying entire sets.
>
> This issue was detected by rule based static tools
> developed by Tencent.
What tools? This must be specific, give their name.
Previously Tencent reports were often bogus or low quality.
>
> Signed-off-by: Siyang Liu <1972843537@qq.com>
> ---
> arch/sparc/kernel/chmc.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/arch/sparc/kernel/chmc.c b/arch/sparc/kernel/chmc.c
> index d4c74d6b2e1b..fd20e4ee0971 100644
> --- a/arch/sparc/kernel/chmc.c
> +++ b/arch/sparc/kernel/chmc.c
> @@ -412,7 +412,7 @@ static int jbusmc_probe(struct platform_device *op)
> mem_regs = of_get_property(mem_node, "reg", &len);
> if (!mem_regs) {
> printk(KERN_ERR PFX "Cannot get reg property of /memory node.\n");
> - goto out;
> + goto out_put;
You did not implement at all what I asked. I wanted the code to be
simpler, you just made it more complicated. Read again previous feedback.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3] sparc: fix resource leak in jbusmc_probe()
2025-07-21 7:55 ` [PATCH v3] sparc: " jackysliu
2025-07-21 8:17 ` Markus Elfring
@ 2025-07-22 6:22 ` Krzysztof Kozlowski
1 sibling, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-07-22 6:22 UTC (permalink / raw)
To: jackysliu, markus.elfring; +Cc: andreas, davem, linux-kernel, sparclinux
On 21/07/2025 09:55, jackysliu wrote:
> From: Siyang Liu <1972843537@qq.com>
>
> In the jbusmc_probe function, the device node mem_node fetched
> via of_find_node_by_path("/memory") is not properly freed
> on all code paths.
> This can lead to leakage of device node reference counts,
> which may result in kernel resources not being released.
>
> This issue was detected by rule based static tools
> developed by Tencent.
>
> Fixes: e70140ba0d2b ("Get rid of 'remove_new' relic from platform driver struct")
>
> Signed-off-by: Siyang Liu <1972843537@qq.com>
> ---
> arch/sparc/kernel/chmc.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/arch/sparc/kernel/chmc.c b/arch/sparc/kernel/chmc.c
> index d4c74d6b2e1b..fd20e4ee0971 100644
> --- a/arch/sparc/kernel/chmc.c
> +++ b/arch/sparc/kernel/chmc.c
> @@ -412,7 +412,7 @@ static int jbusmc_probe(struct platform_device *op)
> mem_regs = of_get_property(mem_node, "reg", &len);
> if (!mem_regs) {
> printk(KERN_ERR PFX "Cannot get reg property of /memory node.\n");
> - goto out;
> + goto out_put;
Nothing improved. You just ignored all the comments.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-07-22 6:22 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-18 9:22 [PATCH] arch: fix resource leak in chmc.c Jacky Liu
2025-07-18 13:25 ` Krzysztof Kozlowski
2025-07-21 2:04 ` jackysliu
2025-07-18 13:43 ` [PATCH] " Markus Elfring
2025-07-21 3:57 ` [PATCH v2] arch: fix resource leak in jbusmc_probe() jackysliu
2025-07-21 7:18 ` Markus Elfring
2025-07-21 7:55 ` [PATCH v3] sparc: " jackysliu
2025-07-21 8:17 ` Markus Elfring
2025-07-22 6:22 ` Krzysztof Kozlowski
2025-07-21 8:25 ` [PATCH v2] arch: " Krzysztof Kozlowski
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).