All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one
@ 2023-12-08  8:59 ` Kunwu Chan
  0 siblings, 0 replies; 6+ messages in thread
From: Kunwu Chan @ 2023-12-08  8:59 UTC (permalink / raw)
  To: mpe, npiggin, christophe.leroy, ajd
  Cc: linuxppc-dev, linux-kernel, mirimmad17, Kunwu Chan, Kunwu Chan

kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.
Add a null pointer check, and release 'ent' to avoid memory leaks.

Fixes: bfd2f0d49aef ("powerpc/powernv: Get rid of old scom_controller abstraction")
Cc: Kunwu Chan <kunwu.chan@hotmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 arch/powerpc/platforms/powernv/opal-xscom.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/opal-xscom.c b/arch/powerpc/platforms/powernv/opal-xscom.c
index 262cd6fac907..748c2b97fa53 100644
--- a/arch/powerpc/platforms/powernv/opal-xscom.c
+++ b/arch/powerpc/platforms/powernv/opal-xscom.c
@@ -165,6 +165,11 @@ static int scom_debug_init_one(struct dentry *root, struct device_node *dn,
 	ent->chip = chip;
 	snprintf(ent->name, 16, "%08x", chip);
 	ent->path.data = (void *)kasprintf(GFP_KERNEL, "%pOF", dn);
+	if (!ent->path.data) {
+		kfree(ent);
+		return -ENOMEM;
+	}
+
 	ent->path.size = strlen((char *)ent->path.data);
 
 	dir = debugfs_create_dir(ent->name, root);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one
@ 2023-12-08  8:59 ` Kunwu Chan
  0 siblings, 0 replies; 6+ messages in thread
From: Kunwu Chan @ 2023-12-08  8:59 UTC (permalink / raw)
  To: mpe, npiggin, christophe.leroy, ajd
  Cc: Kunwu Chan, linuxppc-dev, linux-kernel, Kunwu Chan, mirimmad17

kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.
Add a null pointer check, and release 'ent' to avoid memory leaks.

Fixes: bfd2f0d49aef ("powerpc/powernv: Get rid of old scom_controller abstraction")
Cc: Kunwu Chan <kunwu.chan@hotmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 arch/powerpc/platforms/powernv/opal-xscom.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/opal-xscom.c b/arch/powerpc/platforms/powernv/opal-xscom.c
index 262cd6fac907..748c2b97fa53 100644
--- a/arch/powerpc/platforms/powernv/opal-xscom.c
+++ b/arch/powerpc/platforms/powernv/opal-xscom.c
@@ -165,6 +165,11 @@ static int scom_debug_init_one(struct dentry *root, struct device_node *dn,
 	ent->chip = chip;
 	snprintf(ent->name, 16, "%08x", chip);
 	ent->path.data = (void *)kasprintf(GFP_KERNEL, "%pOF", dn);
+	if (!ent->path.data) {
+		kfree(ent);
+		return -ENOMEM;
+	}
+
 	ent->path.size = strlen((char *)ent->path.data);
 
 	dir = debugfs_create_dir(ent->name, root);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one
  2023-12-08  8:59 ` Kunwu Chan
@ 2023-12-18  4:56   ` Andrew Donnellan
  -1 siblings, 0 replies; 6+ messages in thread
From: Andrew Donnellan @ 2023-12-18  4:56 UTC (permalink / raw)
  To: Kunwu Chan, mpe, npiggin, christophe.leroy
  Cc: linuxppc-dev, linux-kernel, mirimmad17, Kunwu Chan, robh

On Fri, 2023-12-08 at 16:59 +0800, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
> Add a null pointer check, and release 'ent' to avoid memory leaks.
> 
> Fixes: bfd2f0d49aef ("powerpc/powernv: Get rid of old scom_controller
> abstraction")

[+ robh]

This commit just reshuffled around some existing code. The commit that
appears to have added this is actually b7c670d673d1 ("powerpc: Convert
to using %pOF instead of full_name").

> Cc: Kunwu Chan <kunwu.chan@hotmail.com>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
>  arch/powerpc/platforms/powernv/opal-xscom.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/powerpc/platforms/powernv/opal-xscom.c
> b/arch/powerpc/platforms/powernv/opal-xscom.c
> index 262cd6fac907..748c2b97fa53 100644
> --- a/arch/powerpc/platforms/powernv/opal-xscom.c
> +++ b/arch/powerpc/platforms/powernv/opal-xscom.c
> @@ -165,6 +165,11 @@ static int scom_debug_init_one(struct dentry
> *root, struct device_node *dn,
>  	ent->chip = chip;
>  	snprintf(ent->name, 16, "%08x", chip);
>  	ent->path.data = (void *)kasprintf(GFP_KERNEL, "%pOF", dn);
> +	if (!ent->path.data) {
> +		kfree(ent);
> +		return -ENOMEM;

The caller of this function (scom_debug_init()) uses a bitwise OR to
aggregate the return codes of multiple calls to scom_debug_init_one().
This doesn't really work for returning specific error codes, so I'd
just return -1 here (or change the way the return codes are handled on
the caller side).

> +	}
> +
>  	ent->path.size = strlen((char *)ent->path.data);
>  
>  	dir = debugfs_create_dir(ent->name, root);

-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one
@ 2023-12-18  4:56   ` Andrew Donnellan
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Donnellan @ 2023-12-18  4:56 UTC (permalink / raw)
  To: Kunwu Chan, mpe, npiggin, christophe.leroy
  Cc: robh, Kunwu Chan, linuxppc-dev, linux-kernel, mirimmad17

On Fri, 2023-12-08 at 16:59 +0800, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
> Add a null pointer check, and release 'ent' to avoid memory leaks.
> 
> Fixes: bfd2f0d49aef ("powerpc/powernv: Get rid of old scom_controller
> abstraction")

[+ robh]

This commit just reshuffled around some existing code. The commit that
appears to have added this is actually b7c670d673d1 ("powerpc: Convert
to using %pOF instead of full_name").

> Cc: Kunwu Chan <kunwu.chan@hotmail.com>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
>  arch/powerpc/platforms/powernv/opal-xscom.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/powerpc/platforms/powernv/opal-xscom.c
> b/arch/powerpc/platforms/powernv/opal-xscom.c
> index 262cd6fac907..748c2b97fa53 100644
> --- a/arch/powerpc/platforms/powernv/opal-xscom.c
> +++ b/arch/powerpc/platforms/powernv/opal-xscom.c
> @@ -165,6 +165,11 @@ static int scom_debug_init_one(struct dentry
> *root, struct device_node *dn,
>  	ent->chip = chip;
>  	snprintf(ent->name, 16, "%08x", chip);
>  	ent->path.data = (void *)kasprintf(GFP_KERNEL, "%pOF", dn);
> +	if (!ent->path.data) {
> +		kfree(ent);
> +		return -ENOMEM;

The caller of this function (scom_debug_init()) uses a bitwise OR to
aggregate the return codes of multiple calls to scom_debug_init_one().
This doesn't really work for returning specific error codes, so I'd
just return -1 here (or change the way the return codes are handled on
the caller side).

> +	}
> +
>  	ent->path.size = strlen((char *)ent->path.data);
>  
>  	dir = debugfs_create_dir(ent->name, root);

-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one
  2023-12-08  8:59 ` Kunwu Chan
@ 2023-12-21 10:38   ` Michael Ellerman
  -1 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2023-12-21 10:38 UTC (permalink / raw)
  To: npiggin, christophe.leroy, ajd, Kunwu Chan
  Cc: linuxppc-dev, linux-kernel, mirimmad17, Kunwu Chan

On Fri, 08 Dec 2023 16:59:37 +0800, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
> Add a null pointer check, and release 'ent' to avoid memory leaks.
> 
> 

Applied to powerpc/next.

[1/1] powerpc/powernv: Add a null pointer check to scom_debug_init_one
      https://git.kernel.org/powerpc/c/9a260f2dd827bbc82cc60eb4f4d8c22707d80742

cheers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one
@ 2023-12-21 10:38   ` Michael Ellerman
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2023-12-21 10:38 UTC (permalink / raw)
  To: npiggin, christophe.leroy, ajd, Kunwu Chan
  Cc: Kunwu Chan, linuxppc-dev, linux-kernel, mirimmad17

On Fri, 08 Dec 2023 16:59:37 +0800, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
> Add a null pointer check, and release 'ent' to avoid memory leaks.
> 
> 

Applied to powerpc/next.

[1/1] powerpc/powernv: Add a null pointer check to scom_debug_init_one
      https://git.kernel.org/powerpc/c/9a260f2dd827bbc82cc60eb4f4d8c22707d80742

cheers

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-21 10:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-08  8:59 [PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one Kunwu Chan
2023-12-08  8:59 ` Kunwu Chan
2023-12-18  4:56 ` Andrew Donnellan
2023-12-18  4:56   ` Andrew Donnellan
2023-12-21 10:38 ` Michael Ellerman
2023-12-21 10:38   ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.