More anomalous code fragments in the USB 5.0 stack

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

More anomalous code fragments in the USB 5.0 stack

699 Views
johnstrohm
Contributor III

This shows up in several places, most severely in usb_phdc.c, at lines 844-849.

    devicePtr->user_handle = *phdcHandle;

    #if USB_METADATA_SUPPORTED  

    devicePtr->phdc_metadata = FALSE; /* metadata feature disabled */

    #endif

    *phdcHandle =(unsigned long)devicePtr;

phdcHandle is described as an OUT parameter, meaning that it points SOMEWHERE valid, but the contents are unlikely to be anything useful.  This means that the assignment at line 844 is likely to store garbage in a well-defined place.

If the two assignments are reversed in order, garbage is not stored.  Instead, devicePtr->user_handle points to itself, which does not seem particularly useful, since you would then have devicePtr->user_handle == devicePtr.

usb_hid.c has the assignments in reverse order, viz.,

    *hidHandle =(unsigned long)devicePtr;

    //devicePtr->user_handle = *hidHandle;

but the self-looper creation is commented out.

usb_audio.c has the assignments in reverse order, making the self-looper.

    *audioHandle =(uint32_t)devicePtr;

    devicePtr->user_handle = *audioHandle;

The other class drivers all define a user_handle field in their respective header files, but do not bother to assign anything to it.

This looks like something that could be cleaned up.

Labels (2)
Tags (2)
4 Replies

457 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi John,

I am sorry, but which version are you referring to? I just checked usb_phdc.c in KSDK 1.1, the line 844-849 is not what you mentioned above, so would you please help to clarify?

1.png


Have a great day,
Kan

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

0 Kudos

457 Views
johnstrohm
Contributor III

USB_STACK_V5.0: USB Stack v5.0-Beta Freescale bare metal (no OS) USB Stack, freshly downloaded from USB Stack|Freescale


I just pulled a brand-new copy, and verified it.


The lines in question are about 70 lines down from where your version shows line 844.


0 Kudos

457 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi John,

Thanks for reporting this! I have forwarded this question to our USB stack team, and will let you know when I have any more information!


Have a great day,

Kan

0 Kudos

457 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi John,

I just got the feedback, and the software team told me The code of PHDC init is wrong, actually user_handle is obsolete and should not be used. so in the later version usb_handle will all be commented. Thanks for your reporting!


Have a great day,
Kan

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