Skip to content

Commit f36a1bb

Browse files
authored
[components/drivers] add checking code after allocating memory
1 parent 9dd0d41 commit f36a1bb

File tree

1 file changed

+10
-0
lines changed
  • components/drivers/usb/usbhost/core

1 file changed

+10
-0
lines changed

Diff for: components/drivers/usb/usbhost/core/hub.c

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
#define USB_THREAD_STACK_SIZE 4096
1616

17+
#define DBG_TAG "usbhost.hub"
18+
#define DBG_LVL DBG_INFO
19+
#include <rtdbg.h>
20+
21+
1722
// static struct rt_messagequeue *usb_mq;
1823
static struct uclass_driver hub_driver;
1924
// static struct uhub root_hub;
@@ -702,6 +707,11 @@ void rt_usbh_hub_init(uhcd_t hcd)
702707
rt_thread_t thread;
703708
/* create root hub for hcd */
704709
hcd->roothub = rt_malloc(sizeof(struct uhub));
710+
if(hcd->roothub == RT_NULL)
711+
{
712+
LOG_E("hcd->roothub: allocate buffer failed.");
713+
return;
714+
}
705715
rt_memset(hcd->roothub, 0, sizeof(struct uhub));
706716
hcd->roothub->is_roothub = RT_TRUE;
707717
hcd->roothub->hcd = hcd;

0 commit comments

Comments
 (0)