diff options
| author | kunpHust <[email protected]> | 2023-05-15 14:35:38 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-15 14:35:38 +0800 |
| commit | 7a2bccd1c28eb770971ab8f7e5a1bfb529156f39 (patch) | |
| tree | cfeb8cc9ca5882c9101ef42879e72e6cb019ce65 /components/drivers | |
| parent | ca5845684388e564495ea0108091a580d8a8e419 (diff) | |
[HUST CSE][components][udisk.c] add two checkout procedures after malloc to make sure allocating successfully (#7475)
Diffstat (limited to 'components/drivers')
| -rw-r--r-- | components/drivers/usb/usbhost/class/udisk.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/components/drivers/usb/usbhost/class/udisk.c b/components/drivers/usb/usbhost/class/udisk.c index 1796450348..deda263b78 100644 --- a/components/drivers/usb/usbhost/class/udisk.c +++ b/components/drivers/usb/usbhost/class/udisk.c @@ -13,6 +13,10 @@ #include <drivers/usb_host.h> #include "mass.h" +#define DBG_TAG "usbhost.udisk" +#define DBG_LVL DBG_INFO +#include <rtdbg.h> + #ifdef RT_USBH_MSTORAGE #define UDISK_MAX_COUNT 8 @@ -311,6 +315,11 @@ rt_err_t rt_udisk_run(struct uhintf* intf) if (ret == RT_EOK) { struct ustor_data* data = rt_malloc(sizeof(struct ustor_data)); + if (data == RT_NULL) + { + LOG_E("Allocate partition data buffer failed."); + continue; + } rt_memset(data, 0, sizeof(struct ustor_data)); data->intf = intf; data->udisk_id = udisk_get_id(); @@ -349,6 +358,11 @@ rt_err_t rt_udisk_run(struct uhintf* intf) if(i == 0) { struct ustor_data* data = rt_malloc(sizeof(struct ustor_data)); + if (data == RT_NULL) + { + LOG_E("Allocate partition data buffer failed."); + break; + } rt_memset(data, 0, sizeof(struct ustor_data)); data->udisk_id = udisk_get_id(); |
