Skip to contentSkip to conversation

usb: gadget: s3c-hsudc: Use struct_size() in devm_kzalloc()

PATCH In review Gustavo A. R. Silva 2 participants 2 messages May 13, 2021 – May 14, 2021 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: s3c-hsudc: Use struct_size() in devm_kzalloc()

Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows.

This code was detected with the help of Coccinelle and, audited and fixed manually.

---
 drivers/usb/gadget/udc/s3c-hsudc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/s3c-hsudc.c +2 -3
index 7bd5182ce3ef..89f1f8c9f02e 100644
@@ -1220,9 +1220,8 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
 	struct s3c24xx_hsudc_platdata *pd = dev_get_platdata(&pdev->dev);
 	int ret, i;
 
-	hsudc = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsudc) +
-			sizeof(struct s3c_hsudc_ep) * pd->epnum,
-			GFP_KERNEL);
+	hsudc = devm_kzalloc(&pdev->dev, struct_size(hsudc, ep, pd->epnum),
+			     GFP_KERNEL);
 	if (!hsudc)
 		return -ENOMEM;
 
Signature · 1 line
2.27.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows.

This code was detected with the help of Coccinelle and, audited and fixed manually.

Signature · 1 line
balbi