mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Kunwu Chan <chentao@kylinos.cn>,
	mpe@ellerman.id.au, npiggin@gmail.com, aneesh.kumar@kernel.org,
	naveen.n.rao@linux.ibm.com,
	"maddy@linux.ibm.com" <maddy@linux.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs
Date: Mon, 1 Sep 2025 11:10:54 +0200	[thread overview]
Message-ID: <35c5cd6d-6929-42e5-9505-b38ed316da8b@csgroup.eu> (raw)
In-Reply-To: <20240117091706.153431-1-chentao@kylinos.cn>



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++;


  reply	other threads:[~2025-09-01  9:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-17  9:17 Kunwu Chan
2025-09-01  9:10 ` Christophe Leroy [this message]
2026-09-14  7:20 ` Madhavan Srinivasan

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=35c5cd6d-6929-42e5-9505-b38ed316da8b@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=aneesh.kumar@kernel.org \
    --cc=chentao@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=npiggin@gmail.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®