* [PATCH] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs
@ 2024-01-17 9:17 Kunwu Chan
2025-09-01 9:10 ` Christophe Leroy
2026-09-14 7:20 ` Madhavan Srinivasan
0 siblings, 2 replies; 3+ messages in thread
From: Kunwu Chan @ 2024-01-17 9:17 UTC (permalink / raw)
To: mpe, npiggin, christophe.leroy, aneesh.kumar, naveen.n.rao
Cc: linuxppc-dev, linux-kernel, Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
arch/powerpc/platforms/pasemi/setup.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/powerpc/platforms/pasemi/setup.c b/arch/powerpc/platforms/pasemi/setup.c
index 0761d98e5be3..8f98f3b58888 100644
--- a/arch/powerpc/platforms/pasemi/setup.c
+++ b/arch/powerpc/platforms/pasemi/setup.c
@@ -165,6 +165,8 @@ static int __init pas_setup_mce_regs(void)
while (dev && reg < MAX_MCE_REGS) {
mce_regs[reg].name = kasprintf(GFP_KERNEL,
"mc%d_mcdebug_errsta", reg);
+ if (!mce_regs[reg].name)
+ return -ENOMEM;
mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
reg++;
--
2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs
2024-01-17 9:17 [PATCH] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs Kunwu Chan
@ 2025-09-01 9:10 ` Christophe Leroy
2026-09-14 7:20 ` Madhavan Srinivasan
1 sibling, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2025-09-01 9:10 UTC (permalink / raw)
To: Kunwu Chan, mpe, npiggin, aneesh.kumar, naveen.n.rao, maddy
Cc: linuxppc-dev, linux-kernel
Le 17/01/2024 à 10:17, Kunwu Chan a écrit :
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure. Ensure the allocation was successful
> by checking the pointer validity.
>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> arch/powerpc/platforms/pasemi/setup.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/powerpc/platforms/pasemi/setup.c b/arch/powerpc/platforms/pasemi/setup.c
> index 0761d98e5be3..8f98f3b58888 100644
> --- a/arch/powerpc/platforms/pasemi/setup.c
> +++ b/arch/powerpc/platforms/pasemi/setup.c
> @@ -165,6 +165,8 @@ static int __init pas_setup_mce_regs(void)
> while (dev && reg < MAX_MCE_REGS) {
> mce_regs[reg].name = kasprintf(GFP_KERNEL,
> "mc%d_mcdebug_errsta", reg);
> + if (!mce_regs[reg].name)
> + return -ENOMEM;
I think you will leak the reference taken with last call to
pci_get_device() here. I think we need a call to pci_dev_put(dev) before
bailing out.
By the way there will also be the same leak if the while loop ends when
reg reaches MAX_MCE_REGS while dev is still not NULL.
> mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
> dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
> reg++;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs
2024-01-17 9:17 [PATCH] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs Kunwu Chan
2025-09-01 9:10 ` Christophe Leroy
@ 2026-09-14 7:20 ` Madhavan Srinivasan
1 sibling, 0 replies; 3+ messages in thread
From: Madhavan Srinivasan @ 2026-09-14 7:20 UTC (permalink / raw)
To: mpe, npiggin, aneesh.kumar, Christophe Leroy, Naveen N Rao, Kunwu Chan
Cc: linuxppc-dev, linux-kernel
On Wed, 17 Jan 2024 17:17:06 +0800, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure. Ensure the allocation was successful
> by checking the pointer validity.
>
>
Applied to powerpc/fixes.
[1/1] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs
https://git.kernel.org/powerpc/c/9e5c53d75c560a058abef0e4338c5e3e52cb432a
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-14 7:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 9:17 [PATCH] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs Kunwu Chan
2025-09-01 9:10 ` Christophe Leroy
2026-09-14 7:20 ` Madhavan Srinivasan
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®