<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC MicrocontrollersのトピックLPC17xx-40xx emac driver memory leak on TX (found and fixed)</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC17xx-40xx-emac-driver-memory-leak-on-TX-found-and-fixed/m-p/1001618#M39332</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have found and fixed a memory leak in the EMAC driver, in file lpc17xx_40xx_emac.c.&lt;BR /&gt;Note: I have NO_SYS=1 and LPC_NUM_BUFF_TXDESCS=4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The memory leak happens when 4 calls of the lpc_low_level_output() functions are performed from the LWIP stack before returning to the user code (for example the ARP protocol adds some packets each ARP_AGE_REREQUEST_USED_UNICAST seconds).&lt;BR /&gt;Then if the user code spends some time doing other things, the CONSUME register can make a 'full loop' and go back to its original value.&lt;BR /&gt;When this happens, the lpc_tx_reclaim() function does not detect it and returns immediately leaving 4 pbuf which pointers will be overwritten at the next lpc_low_level_output() calls. These pbuf will never be freed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To fix this, I have added the following code inside the lpc_low_level_output() function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (dn == 0) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Save size of packet and signal it's ready */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lpc_enetif-&amp;gt;ptxd[idx].Control = ENET_TCTRL_SIZE(q-&amp;gt;len) | ENET_TCTRL_INT |&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENET_TCTRL_LAST;&lt;BR /&gt;// NEW CODE&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (lpc_enetif-&amp;gt;txb[idx] != NULL) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; pbuf_free(lpc_enetif-&amp;gt;txb[idx]);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;// END NEW CODE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lpc_enetif-&amp;gt;txb[idx] = p;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that calling the lpc_tx_reclaim() function is not needed any more, although it can be a good idea to free the pbuf on idle time, rather than at the time we need to send a packet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;BR /&gt;Sébastien&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 08 Mar 2020 15:24:49 GMT</pubDate>
    <dc:creator>engineering1</dc:creator>
    <dc:date>2020-03-08T15:24:49Z</dc:date>
    <item>
      <title>LPC17xx-40xx emac driver memory leak on TX (found and fixed)</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC17xx-40xx-emac-driver-memory-leak-on-TX-found-and-fixed/m-p/1001618#M39332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have found and fixed a memory leak in the EMAC driver, in file lpc17xx_40xx_emac.c.&lt;BR /&gt;Note: I have NO_SYS=1 and LPC_NUM_BUFF_TXDESCS=4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The memory leak happens when 4 calls of the lpc_low_level_output() functions are performed from the LWIP stack before returning to the user code (for example the ARP protocol adds some packets each ARP_AGE_REREQUEST_USED_UNICAST seconds).&lt;BR /&gt;Then if the user code spends some time doing other things, the CONSUME register can make a 'full loop' and go back to its original value.&lt;BR /&gt;When this happens, the lpc_tx_reclaim() function does not detect it and returns immediately leaving 4 pbuf which pointers will be overwritten at the next lpc_low_level_output() calls. These pbuf will never be freed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To fix this, I have added the following code inside the lpc_low_level_output() function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (dn == 0) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Save size of packet and signal it's ready */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lpc_enetif-&amp;gt;ptxd[idx].Control = ENET_TCTRL_SIZE(q-&amp;gt;len) | ENET_TCTRL_INT |&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENET_TCTRL_LAST;&lt;BR /&gt;// NEW CODE&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (lpc_enetif-&amp;gt;txb[idx] != NULL) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; pbuf_free(lpc_enetif-&amp;gt;txb[idx]);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;// END NEW CODE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lpc_enetif-&amp;gt;txb[idx] = p;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that calling the lpc_tx_reclaim() function is not needed any more, although it can be a good idea to free the pbuf on idle time, rather than at the time we need to send a packet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;BR /&gt;Sébastien&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Mar 2020 15:24:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC17xx-40xx-emac-driver-memory-leak-on-TX-found-and-fixed/m-p/1001618#M39332</guid>
      <dc:creator>engineering1</dc:creator>
      <dc:date>2020-03-08T15:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: LPC17xx-40xx emac driver memory leak on TX (found and fixed)</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC17xx-40xx-emac-driver-memory-leak-on-TX-found-and-fixed/m-p/1001619#M39333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am glad to hear that the problem has been resolved, and thanks for sharing the fix. Please don't hesitate to contact our technical support if you have any other question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Felipe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Mar 2020 17:25:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC17xx-40xx-emac-driver-memory-leak-on-TX-found-and-fixed/m-p/1001619#M39333</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2020-03-12T17:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: LPC17xx-40xx emac driver memory leak on TX (found and fixed)</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC17xx-40xx-emac-driver-memory-leak-on-TX-found-and-fixed/m-p/1001620#M39334</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for sharing this. I am working on an LPC17xx-based project that uses the EMAC, with FreeRTOS and lwIP. I haven't noticed this bug during my testing, but perhaps it has occurred and I haven't noticed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm interested to know if NXP engineers have done testing and/or code reviews of this bug fix, and what their assessment is.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2020 06:13:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC17xx-40xx-emac-driver-memory-leak-on-TX-found-and-fixed/m-p/1001620#M39334</guid>
      <dc:creator>craigmcqueenir</dc:creator>
      <dc:date>2020-07-21T06:13:10Z</dc:date>
    </item>
  </channel>
</rss>

