diff mbox series

usb: gadget: udc: fix possible null-ptr-deref in mv_u3d_req_to_trb()

Message ID 20241026102740.2653458-1-yiyang13@huawei.com
State New
Headers show
Series usb: gadget: udc: fix possible null-ptr-deref in mv_u3d_req_to_trb() | expand

Commit Message

Yi Yang Oct. 26, 2024, 10:27 a.m. UTC
The mv_u3d_build_trb_one() will return NULL when kzalloc() fails, fix
possible null-ptr-deref by add check for mv_u3d_build_trb_one().

Fixes: 3d4eb9dfa3e8 ("usb: gadget: mv: Add USB 3.0 device driver for Marvell PXA2128 chip.")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 drivers/usb/gadget/udc/mv_u3d_core.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Greg Kroah-Hartman Oct. 29, 2024, 3:36 a.m. UTC | #1
On Sat, Oct 26, 2024 at 10:27:40AM +0000, Yi Yang wrote:
> The mv_u3d_build_trb_one() will return NULL when kzalloc() fails, fix
> possible null-ptr-deref by add check for mv_u3d_build_trb_one().
> 
> Fixes: 3d4eb9dfa3e8 ("usb: gadget: mv: Add USB 3.0 device driver for Marvell PXA2128 chip.")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
>  drivers/usb/gadget/udc/mv_u3d_core.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c
> index 062f43e146aa..c882c377c4f4 100644
> --- a/drivers/usb/gadget/udc/mv_u3d_core.c
> +++ b/drivers/usb/gadget/udc/mv_u3d_core.c
> @@ -417,6 +417,8 @@ static int mv_u3d_req_to_trb(struct mv_u3d_req *req)
>  	 */
>  	if (length <= (unsigned)MV_U3D_EP_MAX_LENGTH_TRANSFER) {
>  		trb = mv_u3d_build_trb_one(req, &count, &dma);
> +		if (!trb)
> +			return -ENOMEM;
>  		list_add_tail(&trb->trb_list, &req->trb_list);
>  		req->trb_head = trb;
>  		req->trb_count = 1;
> -- 
> 2.25.1
> 
> 

How was this tested to verify it works properly?

thanks,.

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c
index 062f43e146aa..c882c377c4f4 100644
--- a/drivers/usb/gadget/udc/mv_u3d_core.c
+++ b/drivers/usb/gadget/udc/mv_u3d_core.c
@@ -417,6 +417,8 @@  static int mv_u3d_req_to_trb(struct mv_u3d_req *req)
 	 */
 	if (length <= (unsigned)MV_U3D_EP_MAX_LENGTH_TRANSFER) {
 		trb = mv_u3d_build_trb_one(req, &count, &dma);
+		if (!trb)
+			return -ENOMEM;
 		list_add_tail(&trb->trb_list, &req->trb_list);
 		req->trb_head = trb;
 		req->trb_count = 1;