@@ -410,36 +410,38 @@ void K64F_EMAC::packet_tx()
410
410
*/
411
411
bool K64F_EMAC::link_out (emac_mem_buf_t *buf)
412
412
{
413
- emac_mem_buf_t *temp_pbuf;
414
-
415
413
// If buffer is chained or not aligned then make a contiguous aligned copy of it
416
414
if (memory_manager->get_next (buf) ||
417
415
reinterpret_cast <uint32_t >(memory_manager->get_ptr (buf)) % ENET_BUFF_ALIGNMENT) {
418
- temp_pbuf = memory_manager->alloc_heap (memory_manager->get_total_len (buf), ENET_BUFF_ALIGNMENT);
419
- if (NULL == temp_pbuf)
420
- return false ;
416
+ emac_mem_buf_t *copy_buf;
417
+ copy_buf = memory_manager->alloc_heap (memory_manager->get_total_len (buf), ENET_BUFF_ALIGNMENT);
418
+ if (NULL == copy_buf) {
419
+ memory_manager->free (buf);
420
+ return false ;
421
+ }
421
422
422
423
// Copy to new buffer and free original
423
- memory_manager->copy (temp_pbuf , buf);
424
+ memory_manager->copy (copy_buf , buf);
424
425
memory_manager->free (buf);
425
- } else {
426
- temp_pbuf = buf;
426
+ buf = copy_buf;
427
427
}
428
428
429
429
/* Check if a descriptor is available for the transfer. */
430
- if (xTXDCountSem.wait (0 ) == 0 )
430
+ if (xTXDCountSem.wait (0 ) == 0 ) {
431
+ memory_manager->free (buf);
431
432
return false ;
433
+ }
432
434
433
435
/* Get exclusive access */
434
436
TXLockMutex.lock ();
435
437
436
438
/* Save the buffer so that it can be freed when transmit is done */
437
- tx_buff[tx_produce_index % ENET_TX_RING_LEN] = temp_pbuf ;
439
+ tx_buff[tx_produce_index % ENET_TX_RING_LEN] = buf ;
438
440
tx_produce_index += 1 ;
439
441
440
442
/* Setup transfers */
441
- g_handle.txBdCurrent ->buffer = static_cast <uint8_t *>(memory_manager->get_ptr (temp_pbuf ));
442
- g_handle.txBdCurrent ->length = memory_manager->get_len (temp_pbuf );
443
+ g_handle.txBdCurrent ->buffer = static_cast <uint8_t *>(memory_manager->get_ptr (buf ));
444
+ g_handle.txBdCurrent ->length = memory_manager->get_len (buf );
443
445
g_handle.txBdCurrent ->control |= (ENET_BUFFDESCRIPTOR_TX_READY_MASK | ENET_BUFFDESCRIPTOR_TX_LAST_MASK);
444
446
445
447
/* Increase the buffer descriptor address. */
0 commit comments