Re: [PATCH net v2] net: lan966x: Free skb when PTP TX timestamp request fails in xmit

From: Daniel Machon

Date: Thu Dec 03 2026 - 10:06:23 EST


> When all LAN966X_MAX_PTP_ID timestamp slots are in flight,
> lan966x_ptp_txtstamp_request() returns -EBUSY without queuing or freeing
> skb, and lan966x_port_xmit() returns that negative errno directly from
> .ndo_start_xmit. Because dev_xmit_complete() treats negative return
> values (< NET_XMIT_MASK) as packets already consumed by the driver, skb
> is never freed or requeued, leaking the sk_buff and its socket
> sk_wmem_alloc accounting (which can eventually stall the sending PTP
> socket once its send buffer fills).
>
> Free skb with dev_kfree_skb_any(), account the drop with
> dev_core_stats_tx_dropped_inc(dev), and return NETDEV_TX_OK on failure.
> Using dev_core_stats_tx_dropped_inc() ensures the software drop is
> included by dev_get_stats() alongside lan966x_stats_get(), which reads
> hardware counters only and ignores dev->stats.
>
> Discovered by compiling an x86_64 allyesconfig kernel with Clang's
> -Wimplicit-int-enum-cast and verified by code inspection of
> lan966x_ptp_txtstamp_request(), lan966x_port_xmit(), and
> dev_xmit_complete(); Gemini assisted with auditing the warning and
> drafting the patch and commit message. The issue was not triggered at
> runtime and the fix is compile-tested only (LLVM=1 W=1 -Werror) because
> Microchip LAN966x hardware is not available.
>
> Fixes: 77eecf25bd9d ("net: lan966x: Update extraction/injection for timestamping")
> Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>

The v2 looks good.

Thanks!

Reviewed-by: Daniel Machon <daniel.machon@xxxxxxxxxxxxx>