* [PATCH] Subject: [PATCH] usb: gadget: aspeed: Add NULL check in the ast_vhub_init_dev
@ 2025-03-29 0:29 Henry Martin
2025-04-01 3:47 ` Benjamin Herrenschmidt
2025-04-05 11:07 ` Greg KH
0 siblings, 2 replies; 3+ messages in thread
From: Henry Martin @ 2025-03-29 0:29 UTC (permalink / raw)
To: linux-usb, linux-aspeed; +Cc: gregkh, linux-arm-kernel, Henry Martin
When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function ast_vhub_init_dev.
A NULL check should be added after the devm_kasprintf call to prevent potential NULL pointer dereference error.
Fixes: 7ecca2a4080cb ("usb/gadget: Add driver for Aspeed SoC virtual hub")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
drivers/usb/gadget/udc/aspeed-vhub/dev.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/udc/aspeed-vhub/dev.c b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
index 573109ca5b79..1709a58299a5 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/dev.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
@@ -545,9 +545,11 @@ int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned int idx)
struct device *parent = &vhub->pdev->dev;
int rc;
+ d->name = devm_kasprintf(parent, GFP_KERNEL, "port%d", idx + 1);
+ if (!d->name)
+ return -ENOMEM;
d->vhub = vhub;
d->index = idx;
- d->name = devm_kasprintf(parent, GFP_KERNEL, "port%d", idx+1);
d->regs = vhub->regs + 0x100 + 0x10 * idx;
ast_vhub_init_ep0(vhub, &d->ep0, d);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Subject: [PATCH] usb: gadget: aspeed: Add NULL check in the ast_vhub_init_dev
2025-03-29 0:29 [PATCH] Subject: [PATCH] usb: gadget: aspeed: Add NULL check in the ast_vhub_init_dev Henry Martin
@ 2025-04-01 3:47 ` Benjamin Herrenschmidt
2025-04-05 11:07 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2025-04-01 3:47 UTC (permalink / raw)
To: Henry Martin, linux-usb, linux-aspeed; +Cc: gregkh, linux-arm-kernel
On Sat, 2025-03-29 at 08:29 +0800, Henry Martin wrote:
> When devm_kasprintf() fails, it returns a NULL pointer. However, this
> return value is not properly checked in the function
> ast_vhub_init_dev.
>
> A NULL check should be added after the devm_kasprintf call to prevent
> potential NULL pointer dereference error.
>
> Fixes: 7ecca2a4080cb ("usb/gadget: Add driver for Aspeed SoC virtual
> hub")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
> drivers/usb/gadget/udc/aspeed-vhub/dev.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/udc/aspeed-vhub/dev.c
> b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
> index 573109ca5b79..1709a58299a5 100644
> --- a/drivers/usb/gadget/udc/aspeed-vhub/dev.c
> +++ b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
> @@ -545,9 +545,11 @@ int ast_vhub_init_dev(struct ast_vhub *vhub,
> unsigned int idx)
> struct device *parent = &vhub->pdev->dev;
> int rc;
>
> + d->name = devm_kasprintf(parent, GFP_KERNEL, "port%d", idx +
> 1);
> + if (!d->name)
> + return -ENOMEM;
> d->vhub = vhub;
> d->index = idx;
> - d->name = devm_kasprintf(parent, GFP_KERNEL, "port%d",
> idx+1);
> d->regs = vhub->regs + 0x100 + 0x10 * idx;
>
> ast_vhub_init_ep0(vhub, &d->ep0, d);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Subject: [PATCH] usb: gadget: aspeed: Add NULL check in the ast_vhub_init_dev
2025-03-29 0:29 [PATCH] Subject: [PATCH] usb: gadget: aspeed: Add NULL check in the ast_vhub_init_dev Henry Martin
2025-04-01 3:47 ` Benjamin Herrenschmidt
@ 2025-04-05 11:07 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2025-04-05 11:07 UTC (permalink / raw)
To: Henry Martin; +Cc: linux-usb, linux-aspeed, linux-arm-kernel
On Sat, Mar 29, 2025 at 08:29:11AM +0800, Henry Martin wrote:
> When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function ast_vhub_init_dev.
>
> A NULL check should be added after the devm_kasprintf call to prevent potential NULL pointer dereference error.
Please properly wrap your changelog text.
> Fixes: 7ecca2a4080cb ("usb/gadget: Add driver for Aspeed SoC virtual hub")
No cc: stable?
Also, your Subject line has "Subject:" in it twice, something went wrong
with the patch when you sent it out :(
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-05 11:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-29 0:29 [PATCH] Subject: [PATCH] usb: gadget: aspeed: Add NULL check in the ast_vhub_init_dev Henry Martin
2025-04-01 3:47 ` Benjamin Herrenschmidt
2025-04-05 11:07 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).