public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: aspeed: Check return value of kasprintf in ast_vhub_alloc_epn
@ 2023-11-22  1:42 Kunwu Chan
  2023-11-22 10:48 ` Andy Shevchenko
  2023-11-22 12:10 ` Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: Kunwu Chan @ 2023-11-22  1:42 UTC (permalink / raw)
  To: gregkh, joel, andrew, andriy.shevchenko
  Cc: linux-usb, linux-arm-kernel, kunwu.chan, linux-aspeed,
	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>
---
 drivers/usb/gadget/udc/aspeed-vhub/epn.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/gadget/udc/aspeed-vhub/epn.c b/drivers/usb/gadget/udc/aspeed-vhub/epn.c
index 148d7ec3ebf4..e0854e878411 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/epn.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/epn.c
@@ -826,6 +826,8 @@ struct ast_vhub_ep *ast_vhub_alloc_epn(struct ast_vhub_dev *d, u8 addr)
 	ep->vhub = vhub;
 	ep->ep.ops = &ast_vhub_epn_ops;
 	ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", addr);
+	if (!ep->ep.name)
+		return NULL;
 	d->epns[addr-1] = ep;
 	ep->epn.g_idx = i;
 	ep->epn.regs = vhub->regs + 0x200 + (i * 0x10);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-11 10:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22  1:42 [PATCH] usb: gadget: aspeed: Check return value of kasprintf in ast_vhub_alloc_epn Kunwu Chan
2023-11-22 10:48 ` Andy Shevchenko
2023-11-22 12:10 ` Greg KH
2024-01-11  9:31   ` Kunwu Chan
2024-01-11 10:03     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox