[components/drivers] add checking code after allocating memory

This commit is contained in:
miaoxingr 2023-05-12 13:39:51 +08:00 committed by GitHub
parent 9dd0d41251
commit f36a1bb514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -14,6 +14,11 @@
#define USB_THREAD_STACK_SIZE 4096
#define DBG_TAG "usbhost.hub"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
// static struct rt_messagequeue *usb_mq;
static struct uclass_driver hub_driver;
// static struct uhub root_hub;
@ -702,6 +707,11 @@ void rt_usbh_hub_init(uhcd_t hcd)
rt_thread_t thread;
/* create root hub for hcd */
hcd->roothub = rt_malloc(sizeof(struct uhub));
if(hcd->roothub == RT_NULL)
{
LOG_E("hcd->roothub: allocate buffer failed.");
return;
}
rt_memset(hcd->roothub, 0, sizeof(struct uhub));
hcd->roothub->is_roothub = RT_TRUE;
hcd->roothub->hcd = hcd;