[ drivers/usb]Fixed a bug may cause stackover flow

This commit is contained in:
David Lin 2020-06-10 12:53:51 +08:00 committed by GitHub
parent ce83371504
commit 1703c70fd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -162,6 +162,10 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device)
/* alloc memory for configuration descriptor */
device->cfg_desc = (ucfg_desc_t)rt_malloc(cfg_desc.wTotalLength);
if(device->cfg_desc == RT_NULL)
{
return RT_ENOMEM;
}
rt_memset(device->cfg_desc, 0, cfg_desc.wTotalLength);
/* get full configuration descriptor */
@ -219,6 +223,10 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device)
{
/* allocate memory for interface device */
device->intf[i] = (struct uhintf*)rt_malloc(sizeof(struct uhintf));
if(device->intf[i] == RT_NULL)
{
return RT_ENOMEM;
}
device->intf[i]->drv = drv;
device->intf[i]->device = device;
device->intf[i]->intf_desc = intf_desc;