Skip to contentSkip to conversation

usb: gadget: atmel: use calloc() to allocate endpoint list

PATCH In review Zixun LI 3 participants 4 messages Jun 6 – Jun 15

Subsystems (2)
lore
Share & tools
lore

Zixun LI

author
#0 lore raw

PATCH v2 1/1 usb: gadget: atmel: use calloc() to allocate endpoint list

malloc() doesn't zero out memory, leaving ep->ep.enabled uninitiated, which could make this flag falsely true.

In next usb_ep_enable() call since this flag is true, ep->ops->enable() will be skipped. Then usb_ep_queue() will fail on uninitialized endpoint.

Fixes 59310d1ecb9f ("usb: gadget: introduce 'enabled' flag in struct usb_ep")

---
On SAM9X60 I had a problem with unreliable usb_ether functionality, sometimes 'dhcp' command returns with error 'rx submit --> -108'.
---
Changes in v2:
- Add more details to commit message.
- Link to v1: https://patch.msgid.link/[email protected]

---
 drivers/usb/gadget/atmel_usba_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/atmel_usba_udc.c +1 -1
index f7a92ded6da..a5a2252dee9 100644
@@ -1219,7 +1219,7 @@ static struct usba_ep *usba_udc_pdata(struct usba_platform_data *pdata,
 	struct usba_ep *eps;
 	int i;
 
-	eps = malloc(sizeof(struct usba_ep) * pdata->num_ep);
+	eps = calloc(pdata->num_ep, sizeof(struct usba_ep));
 	if (!eps) {
 		log_err("failed to alloc eps\n");
 		return NULL;

---
base-commit: 5732bd0f457b4c671e46574d64d4acb099c0f0a5
change-id: 20260521-udc_malloc-eb8355d08afe

Best regards,

Signature · 1 line
Zixun LI <[email protected]>
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Zixun LI

malloc() doesn't zero out memory, leaving ep->ep.enabled uninitiated, which could make this flag falsely true.

In next usb_ep_enable() call since this flag is true, ep->ops->enable() will be skipped. Then usb_ep_queue() will fail on uninitialized endpoint.

Fixes 59310d1ecb9f ("usb: gadget: introduce 'enabled' flag in struct usb_ep")
Reviewed-by on v2 1/1
#2 lore raw
In reply to Zixun LI

Hi Zixun,

Thank you for the patch.

Quoted 8 lines · Zixun LI

malloc() doesn't zero out memory, leaving ep->ep.enabled uninitiated, which could make this flag falsely true.

In next usb_ep_enable() call since this flag is true, ep->ops->enable() will be skipped. Then usb_ep_queue() will fail on uninitialized endpoint.

Fixes 59310d1ecb9f ("usb: gadget: introduce 'enabled' flag in struct usb_ep")
Quoted 32 lines

---
On SAM9X60 I had a problem with unreliable usb_ether functionality, sometimes 'dhcp' command returns with error 'rx submit --> -108'.
---
Changes in v2:
- Add more details to commit message.
- Link to v1: https://patch.msgid.link/[email protected]

---
 drivers/usb/gadget/atmel_usba_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/atmel_usba_udc.c +1 -2
index f7a92ded6da..a5a2252dee9 100644
@@ -1219,7 +1219,7 @@ static struct usba_ep *usba_udc_pdata(struct usba_platform_data *pdata,
 	struct usba_ep *eps;
 	int i;
 
-	eps = malloc(sizeof(struct usba_ep) * pdata->num_ep);
+	eps = calloc(pdata->num_ep, sizeof(struct usba_ep));
 	if (!eps) {
 		log_err("failed to alloc eps\n");
 		return NULL;
 
---

base-commit: 5732bd0f457b4c671e46574d64d4acb099c0f0a5
change-id: 20260521-udc_malloc-eb8355d08afe

Best regards,

Signature · 1 line
Zixun LI <[email protected]>
#3 lore raw
In reply to Zixun LI

Hi,

Quoted 8 lines · Zixun LI

malloc() doesn't zero out memory, leaving ep->ep.enabled uninitiated, which could make this flag falsely true.

In next usb_ep_enable() call since this flag is true, ep->ops->enable() will be skipped. Then usb_ep_queue() will fail on uninitialized endpoint.

[...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)

[1/1] usb: gadget: atmel: use calloc() to allocate endpoint list

      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/033eb908d0a8ed938bc652f34a2d702a29a8726f

--
Mattijs