Skip to content

Commit 7f6755c

Browse files
authored
Merge pull request #3472 from DavidLin1577/patch-2
[components/usb]Fixed a stack overflow bug
2 parents c1a3de7 + 985a70a commit 7f6755c

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

components/drivers/usb/usbdevice/class/cdc_vcom.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ static rt_err_t _function_enable(ufunction_t func)
493493

494494
data = (struct vcom*)func->user_data;
495495
data->ep_out->buffer = rt_malloc(CDC_RX_BUFSIZE);
496+
RT_ASSERT(data->ep_out->buffer != RT_NULL);
496497

497498
data->ep_out->request.buffer = data->ep_out->buffer;
498499
data->ep_out->request.size = EP_MAXPACKET(data->ep_out);
@@ -593,6 +594,7 @@ ufunction_t rt_usbd_function_cdc_create(udevice_t device)
593594

594595
/* allocate memory for cdc vcom data */
595596
data = (struct vcom*)rt_malloc(sizeof(struct vcom));
597+
RT_ASSERT(data != RT_NULL);
596598
rt_memset(data, 0, sizeof(struct vcom));
597599
func->user_data = (void*)data;
598600

components/drivers/usb/usbdevice/class/ecm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ ufunction_t rt_usbd_function_ecm_create(udevice_t device)
565565
/* create a cdc class */
566566
cdc = rt_usbd_function_new(device, &_dev_desc, &ops);
567567
rt_usbd_device_set_qualifier(device, &dev_qualifier);
568-
_ecm_eth= rt_malloc(sizeof(struct rt_ecm_eth));
568+
_ecm_eth= rt_malloc(sizeof(struct rt_ecm_eth));
569+
RT_ASSERT(_ecm_eth != RT_NULL);
569570
rt_memset(_ecm_eth, 0, sizeof(struct rt_ecm_eth));
570571
cdc->user_data = _ecm_eth;
571572

components/drivers/usb/usbhost/core/hub.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ static rt_err_t rt_usbh_hub_enable(void *arg)
508508

509509
/* create a hub instance */
510510
hub = rt_malloc(sizeof(struct uhub));
511+
RT_ASSERT(hub != RT_NULL);
511512
rt_memset(hub, 0, sizeof(struct uhub));
512513

513514
/* make interface instance's user data point to hub instance */

0 commit comments

Comments
 (0)