This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28388D: Is this a bug in C2000Ware LWIP example code?

Part Number: TMS320F28388D
Other Parts Discussed in Thread: C2000WARE

Can anyone confirm my understanding of this example code in C2000Ware version 3.01.00.00?

In f2838xif.c, in the routine f2838xif_transmit() the descriptor data pointer is set to the pbuf data pointer:

        pktDescPtr->dataBuffer = q->payload;

The caller of f2838xif_transmit() subsequently calls pbuf_free() as the call stack unwinds.

This is a bug, because there is no synchronization between these two events:

1) copying of the memory by the DMA engine
2) freeing of the pbuf, and subsequent reuse by some other code

What should be done, if I understand LWIP's pbuf model correctly, is that the f2838xif interface layer increments the reference count using pbuf_ref() and then somehow saves the pbuf pointer, and then when TX completion happens in f2338xif_process_transmit(), recovers the pbuf pointer, and calls pbuf_free(). The result is that whichever pbuf_free() happens last will cause the memory to actually be freed, and the DMA access is guaranteed to precede it.

Thank you for your attention and advice.

Regards,

Nik

  • Hi Nik,

    Nicholas Langrind said:
    , if I understand LWIP's pbuf model correctly, is that the f2838xif interface layer increments the reference count using pbuf_ref()

    Thanks for the feedback. You are right about it. if pbuf is freed databuffer will not be valid anymore. But did you face any issue when you used it? 

    We haven't seen that issue with the webserver application, we used this port layer with. 

    Thanks for the input about pbuf_ref(). I did not know about that, shall file a defect and update in one of the upcoming releases. 

    Regards,

    Sudharsanan

  • Hi Sudharsanan,

    I did not face any issue from this behavior, I only noticed it as a result of reading the code while debugging.

    Thanks for confirming my understanding, I appreciate your time.

    Regards,

    Nik