Skip to content

[BUG] net/w5500: two latent code defects (build break with NETDEV_STATISTICS; wrong d_private) #19306

Description

@ricardgb

Disclaimer: This report was prepared with AI assistance (Claude Code). I reviewed it, verified the code citations against master myself, and validated the behaviour on real hardware where noted before filing.

Line numbers vs drivers/net/w5500.c at master 50f91ef502.

1. NETDEV_RXERRORS(&priv->dev) references variables that do not exist

l. 1351, in w5500_receive():

NETDEV_RXERRORS(&priv->dev);

Neither priv nor a field named dev exists in this function — the
variable is self and the field is w_dev. This compiles today only
because NETDEV_RXERRORS() expands to nothing without
CONFIG_NETDEV_STATISTICS; enabling statistics breaks the build.

Fix: NETDEV_RXERRORS(&self->w_dev);

2. d_private set to the device array instead of the instance

l. 2069, in w5500_initialize():

self->w_dev.d_private = g_w5500;   /* Used to recover private state from dev */

Should be self. Harmless for device 0 (g_w5500 == &g_w5500[0]), wrong
for any devno > 0 — every callback that recovers the driver state via
dev->d_private would operate on device 0's state.

Fix: self->w_dev.d_private = self;

Both fixes are included in the reference branch:
https://github.com/ricardgb/nuttx/tree/w5500-driver-fixes


Disclosure: found during an AI-assisted (Claude Code) audit, verified by
me by reading the cited lines against master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions