From: Greg KH <gregkh@linuxfoundation.org>
To: Charles Han <hanchunchao@inspur.com>
Cc: arnd@arndb.de, naveenkrishna.chatradhi@amd.com,
akshay.gupta@amd.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] misc: amd-sbi: Add NULL check in create_misc_rmi_device
Date: Fri, 12 Sep 2025 13:38:36 +0200 [thread overview]
Message-ID: <2025091212-dole-multitask-ee06@gregkh> (raw)
In-Reply-To: <20250912101451.1928-1-hanchunchao@inspur.com>
On Fri, Sep 12, 2025 at 06:14:51PM +0800, Charles Han wrote:
> Add check for the return value of devm_kmemdup() to prevent
> potential null pointer dereference.
>
> Fixes: 35ac2034db72 ("misc: amd-sbi: Add support for AMD_SBI IOCTL")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
> drivers/misc/amd-sbi/rmi-core.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c
> index 3dec2fc00124..50b8e9e02833 100644
> --- a/drivers/misc/amd-sbi/rmi-core.c
> +++ b/drivers/misc/amd-sbi/rmi-core.c
> @@ -471,6 +471,9 @@ int create_misc_rmi_device(struct sbrmi_data *data,
> GFP_KERNEL,
> "sbrmi-%x",
> data->dev_static_addr);
> + if (!data->sbrmi_misc_dev.name)
> + return -ENOMEM;
> +
> data->sbrmi_misc_dev.minor = MISC_DYNAMIC_MINOR;
> data->sbrmi_misc_dev.fops = &sbrmi_fops;
> data->sbrmi_misc_dev.parent = dev;
> @@ -478,6 +481,9 @@ int create_misc_rmi_device(struct sbrmi_data *data,
> GFP_KERNEL,
> "sbrmi-%x",
> data->dev_static_addr);
> + if (!data->sbrmi_misc_dev.nodename)
> + return -ENOMEM;
> +
Why not just make this a single if statement? And this really can't
ever fail in real life :)
thanks,
greg k-h
prev parent reply other threads:[~2025-09-12 11:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 10:14 [PATCH] misc: amd-sbi: Add NULL check in create_misc_rmi_device Charles Han
2025-09-12 11:38 ` Greg KH [this message]
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=2025091212-dole-multitask-ee06@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=akshay.gupta@amd.com \
--cc=arnd@arndb.de \
--cc=hanchunchao@inspur.com \
--cc=linux-kernel@vger.kernel.org \
--cc=naveenkrishna.chatradhi@amd.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