From: Andrew Donnellan <ajd@linux.ibm.com>
To: Kunwu Chan <chentao@kylinos.cn>,
mpe@ellerman.id.au, npiggin@gmail.com,
christophe.leroy@csgroup.eu
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
mirimmad17@gmail.com, Kunwu Chan <kunwu.chan@hotmail.com>,
robh@kernel.org
Subject: Re: [PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one
Date: Mon, 18 Dec 2023 15:56:48 +1100 [thread overview]
Message-ID: <2b35027ca6c61c2211117d30bd84c0e26cced1f6.camel@linux.ibm.com> (raw)
In-Reply-To: <20231208085937.107210-1-chentao@kylinos.cn>
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
next prev parent reply other threads:[~2023-12-18 4:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-08 8:59 Kunwu Chan
2023-12-18 4:56 ` Andrew Donnellan [this message]
2023-12-21 10:38 ` Michael Ellerman
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=2b35027ca6c61c2211117d30bd84c0e26cced1f6.camel@linux.ibm.com \
--to=ajd@linux.ibm.com \
--cc=chentao@kylinos.cn \
--cc=christophe.leroy@csgroup.eu \
--cc=kunwu.chan@hotmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mirimmad17@gmail.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=robh@kernel.org \
/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®