Post Go back to editing

ADIN2111 Driver library bug

Thread Summary

The user identified a bug in the ADIN2111 Non Operating System Driver where the `hDevice->adinDevice` pointer is overwritten in `adi_spi_generic.c`, causing undefined behavior. The issue will be fixed in the next driver release. Additionally, the user reported that the library adds FCS twice to the same frame when `fcsCheckEn` is true and the port is set to `ADIN2111_TX_PORT_FLOOD` or for multicast packets, leading to buffer overflow if the buffer size is `packet_size + fcs_size`.
AI Generated Content
Category: Software
Product Number: ADIN2111
Software Version: 1.0.0.0

Hi,

I have found a bug in your code and architecture of the Adin2111 driver available from here: https://www.analog.com/en/products/adin2111.html#software-resources  -> ADIN2111 Non Operating System Driver.

The library is constructed in such way that hal parameter hDevice->adinDevice is assumed to be the adin2111_DeviceHandle_t type. And in current code it actually is this type as it does not support passing custom parameter and this struct is passed as hal parameter to the macInit. But when one wants to change it and pass there something different (as the API supposed to be and thankfully mostly is) then one line in adi_spi_generic.c is writing over this pointer and casues undefined behavior as it may rewrite user memory without its knowledge.

I came into this problem when I was enabling ADIN2111 device in a C++ project where I needed to pass my custom parameter to the library as adinDevice.

Please consider to fix at least the line below (and possibly slighly adapt adin2111_Init function so that it fully supports user-defined parameters across HAL functions and callbacks.

Problem n adi_spi_generic.c, line 245:

hDevice->cbFunc[ADI_MAC_EVT_DYN_TBL_UPDATE](hDevice->adinDevice, Event, hDevice->pRxQueue->pEntries[tail].pBufDesc);
You use the hDevice->adinDevice as parameter and it should be parameter registered in callback registration:

hDevice->cbFunc[ADI_MAC_EVT_DYN_TBL_UPDATE](hDevice->cbParam[ADI_MAC_EVT_DYN_TBL_UPDATE], Event, hDevice->pRxQueue->pEntries[tail].pBufDesc);



Edit Notes

Added ADIN2111 to title
[edited by: matirekrut at 2:22 PM (GMT -5) on 6 Mar 2026]

Thread Notes

  • Hi  

    You're right. Thanks for flagging the issue. This will be corrected in the next driver release so custom parameters are handled safely and consistently.

    Regards,

    Shazia

  • Thanks for confirmation!

    And I can add another issueI found today, description below.

    Problem:

    - Library adds FCS twice to the same frame on adin2111_SubmitTxBuffer when:
      - fcsCheckEn is true,
      - port is set to 
    ADIN2111_TX_PORT_FLOOD or it is multicast packet (FLOOD is forced then).
    - In this case packet is sent on 2 ports and MAC_SubmitTxBuffer function adds FCS to the buffer on call to port 1 and second time on call to submit packet to port 2.

    When buffer is set to packet_size + fcs_size then adin2111_SubmitTxBuffer fails as there is not enough room for second FCS.

  • Hi  

    Thank you for bringing this to our attention. We are aware of this issue and will be resolved in the next release.

    Regards,

    Shazia

  • Hi once again Slight smile

    I am coming with another bugs to the same library.

    1. adi_mac.c -> macCallback() lines 368-400. Notice that the driver performs MAC_RecvFrame() twice due to this logic.

    2. adi_spi_generic.c -> MAC_Read() lines 576-595. There are data to be received but either RxQueue is empty (it goes through this case when above bug is not fixed) OR when application buffer is too small to receive the data. And it is ok, but please consider dropping RX frames in such situation as the driver will be in an endless processing of that RX frame it could not pass to the application. Resulting mostly in a deadloop.

    3. Your example suggest that application buffer should be of size:

    /* Extra 4 bytes for FCS and 2 bytes for the frame header */
    #define MAX_FRAME_BUF_SIZE  (MAX_FRAME_SIZE + 4 + 2)
    where:
    /*! Maximum frame size, without FCS. */
    #define MAX_FRAME_SIZE                      (1518)

    And this makes sense but can end up in a deadloop when bug 2. shows up. Hardware is configured to receive up to 1560 bytes by default. It is > MAX_FRAME_BUF_SIZE and when sending jumbo frames on the interface (just a little above standard ETH frame size) the driver ends up in a deadloop due to bug 2. It would be nice if you at least add a comment to the examples so that users are aware of this case. In particular that the HW drops frames from size 1560+ by default so there is a gap to be exploited.
    By the way, SPI buffer has size of 2000 bytes (random big value that comes from nowhere, just big enough for standard usage). It could be configurable - when user decides to configure HW to receive frames of size 2000+ there would probably be a buffer overflow.

    Regards,
    Mateusz
  • Thanks for getting in touch. We’ve checked, and the fixes are already included in our upcoming release. Appreciate you flagging this to our attention. 

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.