Browse Source

[components/drivers] add checking code after allocating memory

miaoxingr 2 years ago
parent
commit
f36a1bb514
1 changed files with 10 additions and 0 deletions
  1. 10 0
      components/drivers/usb/usbhost/core/hub.c

+ 10 - 0
components/drivers/usb/usbhost/core/hub.c

@@ -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;