All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: udc: add NULL pointer check
@ 2022-03-29  5:54 cgel.zte
  2022-03-29 14:32 ` Shuah Khan
  2022-03-29 18:47 ` Christophe JAILLET
  0 siblings, 2 replies; 3+ messages in thread
From: cgel.zte @ 2022-03-29  5:54 UTC (permalink / raw)
  To: balbi
  Cc: gregkh, peter.chen, christophe.jaillet, skhan, lv.ruyi, johan,
	jakobkoschel, linux-usb, linux-kernel, Zeal Robot

From: Lv Ruyi <lv.ruyi@zte.com.cn>

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@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
---
 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;
+	}
 	udc->status_req->req.dma = DMA_ADDR_INVALID;
 
 	udc->resume_state = USB_STATE_NOTATTACHED;
-- 
2.25.1


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

* Re: [PATCH] usb: gadget: udc: add NULL pointer check
  2022-03-29  5:54 [PATCH] usb: gadget: udc: add NULL pointer check cgel.zte
@ 2022-03-29 14:32 ` Shuah Khan
  2022-03-29 18:47 ` Christophe JAILLET
  1 sibling, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2022-03-29 14:32 UTC (permalink / raw)
  To: cgel.zte, balbi
  Cc: gregkh, peter.chen, christophe.jaillet, lv.ruyi, johan,
	jakobkoschel, linux-usb, linux-kernel, Zeal Robot, Shuah Khan

On 3/28/22 11:54 PM, cgel.zte@gmail.com wrote:
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
> 
> kzalloc() is a memory allocation function which can return NULL when some
> internal memory errors happen. It is safer to check NULL pointer.
> 

Please add information on how this problem was found, including the
tool used and warn message.

> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
> ---
>   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;
> +	}

Looks good to me.

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

With that change to the commit log

Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>

thanks,
-- Shuah

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

* Re: [PATCH] usb: gadget: udc: add NULL pointer check
  2022-03-29  5:54 [PATCH] usb: gadget: udc: add NULL pointer check cgel.zte
  2022-03-29 14:32 ` Shuah Khan
@ 2022-03-29 18:47 ` Christophe JAILLET
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-03-29 18:47 UTC (permalink / raw)
  To: cgel.zte, balbi
  Cc: gregkh, peter.chen, skhan, lv.ruyi, johan, jakobkoschel,
	linux-usb, linux-kernel, Zeal Robot


Le 29/03/2022 à 07:54, cgel.zte@gmail.com a écrit :
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
>
> 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@zte.com.cn>
> Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
> ---
>   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;

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

end of thread, other threads:[~2022-03-29 18:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29  5:54 [PATCH] usb: gadget: udc: add NULL pointer check cgel.zte
2022-03-29 14:32 ` Shuah Khan
2022-03-29 18:47 ` Christophe JAILLET

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.