Re: [PATCH] usb: gadget: udc: add NULL pointer check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Le 29/03/2022 à 07:54, cgel.zte@xxxxxxxxx a écrit :
From: Lv Ruyi <lv.ruyi@xxxxxxxxxx>

kzalloc() is a memory allocation function which can return NULL when some
internal memory errors happen. It is safer to check NULL pointer.

Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
Signed-off-by: Lv Ruyi <lv.ruyi@xxxxxxxxxx>
---
  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 fdb17d86cd65..f52eb3f2420a 100644
--- a/drivers/usb/gadget/udc/mv_udc_core.c
+++ b/drivers/usb/gadget/udc/mv_udc_core.c
@@ -2231,6 +2231,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;
+	}

Hi,

not directly related to this patch, but I wonder if this kzalloc should be freed in the error handling path, and maybe also in the .remove function. It seems to be leaking.

CJ

  	udc->status_req->req.dma = DMA_ADDR_INVALID;
udc->resume_state = USB_STATE_NOTATTACHED;



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux