All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb: gadget: atmel: use calloc() to allocate endpoint list
@ 2026-06-06  8:27 Zixun LI
  2026-06-06 19:12 ` Marek Vasut
  2026-06-08  7:02 ` Mattijs Korpershoek
  0 siblings, 2 replies; 3+ messages in thread
From: Zixun LI @ 2026-06-06  8:27 UTC (permalink / raw)
  To: Mattijs Korpershoek, Stephan Gerhold, u-boot
  Cc: Lukasz Majewski, Marek Vasut, Tom Rini, Andrew Goodbody, 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")
Signed-off-by: Zixun LI <admin@hifiphile.com>
---
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/20260521-udc_malloc-v1-1-b6118f809ada@hifiphile.com
---
 drivers/usb/gadget/atmel_usba_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index f7a92ded6da..a5a2252dee9 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -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,
--  
Zixun LI <admin@hifiphile.com>


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

end of thread, other threads:[~2026-06-08  7:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-06  8:27 [PATCH v2] usb: gadget: atmel: use calloc() to allocate endpoint list Zixun LI
2026-06-06 19:12 ` Marek Vasut
2026-06-08  7:02 ` Mattijs Korpershoek

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.