Obvious bug in 5.0 USB stack, in file usb_cdc.c

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Obvious bug in 5.0 USB stack, in file usb_cdc.c

跳至解决方案
705 次查看
johnstrohm
Contributor III

Routines USB_Cdc_Allocate_Handle() and USB_Cdc_Free_Handle both walk through cdc_device_array.

cdc_device_struct_t   cdc_device_array[MAX_CDC_DEVICE];

static usb_status USB_Cdc_Allocate_Handle(cdc_handle_t* handle)

{

    uint32_t cnt = 0;

    for (;cnt< MAX_CDC_DEVICE;cnt++)

    {

        if (cdc_device_array[cnt].controller_handle == NULL)

        {

            *handle = (cdc_handle_t)&cdc_device_array[cnt];

            return USB_OK;

        }

    }

    return USBERR_DEVICE_BUSY;

}

static usb_status USB_Cdc_Free_Handle(cdc_handle_t handle)

{

    int32_t cnt = 0;

    for (;cnt< USBCFG_DEV_MAX_CLASS_OBJECT;cnt++)

    {

        if (((cdc_handle_t)&cdc_device_array[cnt]) == handle)

        {

            OS_Mem_zero((void *)handle, sizeof(cdc_device_struct_t));

            return USB_OK;

        }

    }

    return USBERR_INVALID_PARAM;

}

If some poor maintenance guy changes USBCFG_DEV_MAX_CLASS_OBJECT, and forgets to update MAX_CDC_DEVICE, he will break USB_Cdc_Free_Handle().

The for-statement in USB_Cdc_Free_Handle()

    for (;cnt< USBCFG_DEV_MAX_CLASS_OBJECT;cnt++)

should be identical to the for-statement in USB_Cdc_Allocate_Handle().

    for (;cnt< MAX_CDC_DEVICE;cnt++)

标签 (2)
标记 (3)
1 解答
504 次查看
jeremyzhou
NXP Employee
NXP Employee

Hi John,

I'll report this issue to AE team for checking and thank you very much for your focus on Freescale product.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
1 回复
505 次查看
jeremyzhou
NXP Employee
NXP Employee

Hi John,

I'll report this issue to AE team for checking and thank you very much for your focus on Freescale product.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复