linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: udc: add return value check of kzalloc in mv_udc_probe
@ 2023-02-24  9:20 void0red
  2023-02-24 11:03 ` Dongliang Mu
  0 siblings, 1 reply; 13+ messages in thread
From: void0red @ 2023-02-24  9:20 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, linux-kernel, Kang Chen

From: Kang Chen <void0red@gmail.com>

Even an 8-byte kzalloc will fail when we don't have enough memory,
so we need a nullptr check and do the cleanup when it fails.

Reported-by: eriri <1527030098@qq.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217081

Signed-off-by: Kang Chen <void0red@gmail.com>
---
 drivers/usb/gadget/udc/mv_udc_core.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c
index b397f3a84..6dd6d52de 100644
--- a/drivers/usb/gadget/udc/mv_udc_core.c
+++ b/drivers/usb/gadget/udc/mv_udc_core.c
@@ -2230,6 +2230,10 @@ static int mv_udc_probe(struct platform_device *pdev)
 
 	/* allocate a small amount of memory to get valid address */
 	udc->status_req->req.buf = kzalloc(8, GFP_KERNEL);
+	if (!udc->status_req->req.buf) {
+		retval = -ENOMEM;
+		goto err_destroy_dma;
+	}
 	udc->status_req->req.dma = DMA_ADDR_INVALID;
 
 	udc->resume_state = USB_STATE_NOTATTACHED;
-- 
2.34.1


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

end of thread, other threads:[~2023-02-25  4:12 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-24  9:20 [PATCH] usb: gadget: udc: add return value check of kzalloc in mv_udc_probe void0red
2023-02-24 11:03 ` Dongliang Mu
2023-02-24 12:43   ` Kang Chen
2023-02-24 13:02   ` [PATCH] usb: gadget: udc: replace kzalloc with devm_kzalloc in mv_udc_probe and add a check for this allocation void0red
2023-02-24 13:13     ` Greg KH
2023-02-24 13:14       ` Dongliang Mu
2023-02-24 14:11         ` [PATCH v2] " void0red
2023-02-24 14:19           ` Greg KH
2023-02-24 17:01           ` Sergei Shtylyov
2023-02-25  4:11             ` [PATCH v3 1/2] usb: gadget: udc: add return value check of kzalloc in mv_udc_probe void0red
2023-02-25  4:11               ` [PATCH v3 2/2] usb: gadget: udc: replace kzalloc with devm_kzalloc " void0red
2023-02-24 14:31         ` [PATCH v2] usb: gadget: udc: replace kzalloc with devm_kzalloc in mv_udc_probe and add a check for this allocation void0red
2023-02-24 16:33           ` 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).