From: sashiko-bot@kernel.org
To: "Birger Koblitz" <mail@birger-koblitz.de>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH net-next v20 03/13] ax88179_178a: Split driver into library and device specific code
Date: Sat, 07 Nov 2026 07:21:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-202693@kernel.org> (raw)
In-Reply-To: <20261106-ax88179a-v20-3-37b5a1189983@birger-koblitz.de>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net: usb: ax88179: premature MTU state update in
ax88179_change_mtu()
- [Medium] net: usb: ax88179: incomplete medium_status_mutex locking in
ax88179_link_reset()
--
commit 8e0b6dd22d7460dd33bd4e07faf824de7c0a7ad6
Author: Birger Koblitz <mail@birger-koblitz.de>
ax88179_178a: Split driver into library and device specific code
This commit splits common helpers and definitions out of ax88179_178a.c
into ax88179_lib.c and ax88179_lib.h, renames the module to ax88179, and
adds medium_status_mutex and error handling to ax88179_change_mtu().
> diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c
> new file mode 100644
> index 0000000000000..063427ff55e42
> --- /dev/null
> +++ b/drivers/net/usb/ax88179_lib.c
[ ... ]
> +int ax88179_change_mtu(struct net_device *net, int new_mtu)
> +{
> + struct usbnet *dev = netdev_priv(net);
> + struct ax88179_data *data;
> + u16 tmp16;
> + int err;
> +
> + data = dev->driver_priv;
> + mutex_lock(&data->medium_status_mutex);
> + WRITE_ONCE(net->mtu, new_mtu);
> + dev->hard_mtu = net->mtu + net->hard_header_len;
> + if (net->mtu > 1500) {
> + err = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
> + 2, 2, &tmp16);
> + if (err < 0)
> + goto err_out;
> + tmp16 |= AX_MEDIUM_JUMBO_EN;
> + err = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
> + 2, 2, &tmp16);
> + if (err < 0)
> + goto err_out;
> + } else {
> + err = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
> + 2, 2, &tmp16);
> + if (err < 0)
> + goto err_out;
> + tmp16 &= ~AX_MEDIUM_JUMBO_EN;
> + err = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
> + 2, 2, &tmp16);
> + if (err < 0)
> + goto err_out;
> + }
> + mutex_unlock(&data->medium_status_mutex);
> +
> + /* max qlen depend on hard_mtu and rx_urb_size */
> + usbnet_update_max_qlen(dev);
> +
> + return 0;
> +
> +err_out:
> + mutex_unlock(&data->medium_status_mutex);
> + return err;
> +}
[Severity: Medium]
Does jumping to err_out leave net->mtu and dev->hard_mtu updated when a
register read or write fails?
netif_set_mtu_ext() assumes dev->mtu is unchanged when ndo_change_mtu()
returns an error, so it neither restores the old MTU nor fires
NETDEV_CHANGEMTU notifiers, and err_out also skips
usbnet_update_max_qlen(). This leaves net->mtu and dev->hard_mtu out of
sync with the hardware AX_MEDIUM_JUMBO_EN setting and dev->tx_qlen, and
causes later attempts to set the same new_mtu to return early in
netif_set_mtu_ext() because dev->mtu already equals new_mtu. Updating
net->mtu and dev->hard_mtu only after the register access succeeds would
avoid this regression.
> diff --git a/drivers/net/usb/ax88179_lib.h b/drivers/net/usb/ax88179_lib.h
> new file mode 100644
> index 0000000000000..9111a1395eb2f
> --- /dev/null
> +++ b/drivers/net/usb/ax88179_lib.h
[ ... ]
> +struct ax88179_data {
> + struct mutex medium_status_mutex; /* protect AX_MEDIUM_STATUS_MODE */
> + u8 eee_enabled;
> + u8 eee_active;
> + u16 rxctl;
> + u8 in_pm;
> + u32 wol_supported;
> + u32 wolopts;
> + u8 disconnecting;
> +};
[Severity: Medium]
Should ax88179_link_reset() also take medium_status_mutex when updating
AX_MEDIUM_STATUS_MODE?
ax88179_link_reset() runs from usbnet_deferred_kevent() without rtnl_lock
or medium_status_mutex, reads dev->net->mtu, sleeps in a USB control
transfer for AX_RX_BULKIN_QCTRL, and then writes AX_MEDIUM_STATUS_MODE:
drivers/net/usb/ax88179_178a.c:ax88179_link_reset() {
...
} else if (GMII_PHY_PHYSR_GIGA == (tmp16 & GMII_PHY_PHYSR_SMASK)) {
mode |= AX_MEDIUM_GIGAMODE | AX_MEDIUM_EN_125MHZ;
if (dev->net->mtu > 1500)
mode |= AX_MEDIUM_JUMBO_EN;
...
ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
...
ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
2, 2, &mode);
}
This allows a race with ax88179_change_mtu():
CPU0 kworker
ax88179_change_mtu() ax88179_link_reset()
read dev->net->mtu (1500)
ax88179_write_cmd(... BULKIN_QCTRL ...)
mutex_lock(&medium_status_mutex)
WRITE_ONCE(net->mtu, 4000)
read AX_MEDIUM_STATUS_MODE
write AX_MEDIUM_STATUS_MODE
(sets AX_MEDIUM_JUMBO_EN)
mutex_unlock(&medium_status_mutex)
write AX_MEDIUM_STATUS_MODE
<-- overwrites AX_MEDIUM_JUMBO_EN
If the writes interleave in the opposite order, ax88179_change_mtu() can
read AX_MEDIUM_STATUS_MODE before ax88179_link_reset() updates it and
write back stale speed and duplex bits.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261106-ax88179a-v20-0-37b5a1189983@birger-koblitz.de?part=3
next prev parent reply other threads:[~2026-11-07 7:21 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 7:21 [PATCH net-next v20 00/13] ax88179_178a: Add support for AX88179A-based chips Birger Koblitz
2026-11-06 7:21 ` [PATCH net-next v20 01/13] phylink: Add phylink_mac_interrupt Birger Koblitz
2026-11-06 10:11 ` Maxime Chevallier
2026-11-06 15:32 ` Birger Koblitz
2026-11-06 15:55 ` Andrew Lunn
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 02/13] phylib: Add support for PHYs with broken forced mode Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 03/13] ax88179_178a: Split driver into library and device specific code Birger Koblitz
2026-11-07 7:21 ` sashiko-bot [this message]
2026-11-06 7:21 ` [PATCH net-next v20 04/13] ax88179_178a: Add HW support for AX179A-based chips Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 05/13] ax88179_178a: Add EEE configuration support for AX88179A MACs Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 06/13] ax88179_178a: Add EEE configuration support for AX88179A PHYs Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 07/13] ax88179_178a: Add VLAN offload support for AX88179A Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 08/13] ax88179_178a: Add AX179A/AX279 multicast configuration Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 09/13] ax88179_178a: Add Suspend/resume support for AX88179A/772D/279 Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 10/13] ax88179_178a: Add ethtool get_drvinfo Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 11/13] ax88179_178a: Update driver name and information Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 12/13] ax88179_178a: Add support for AX88179A/772D/279 EEPROM access Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
2026-11-06 7:21 ` [PATCH net-next v20 13/13] ax88796b: Add support for AX88772D, AX88179A and AX88279 Birger Koblitz
2026-11-07 7:21 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-202693@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mail@birger-koblitz.de \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox