diff options
author | Jakub Kicinski <kuba@kernel.org> | 2025-03-26 00:35:33 +0300 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2025-03-26 00:35:34 +0300 |
commit | a19f40d919ca6d16bbc03d858690f60f1a9bf3ed (patch) | |
tree | 7a4f6f5861ea19862846e77f45add5f18ed46623 | |
parent | 4f74a45c6b1906574669999b9748feb1a92bee84 (diff) | |
parent | 61997271a5a7dcd5a7dd5f0d81e4cb045e1db9ef (diff) | |
download | linux-a19f40d919ca6d16bbc03d858690f60f1a9bf3ed.tar.xz |
Merge branch 'net-usb-asix-ax88772-fix-potential-string-cut'
Andy Shevchenko says:
====================
net: usb: asix: ax88772: Fix potential string cut
The agreement and also PHY_MAX_ADDR limit suggest that the PHY address
can't occupy more than two hex digits. In some cases GCC complains about
potential string cut. In course of fixing this, introduce the PHY_ID_SIZE
predefined constant to make it easier for the users to know the bare
minimum for the buffer that holds PHY ID string (patch 1). With that,
fix the ASIX driver that triggers GCC accordingly (patch 2).
====================
Link: https://patch.msgid.link/20250324144751.1271761-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r-- | drivers/net/usb/ax88172a.c | 12 | ||||
-rw-r--r-- | include/linux/phy.h | 1 |
2 files changed, 9 insertions, 4 deletions
diff --git a/drivers/net/usb/ax88172a.c b/drivers/net/usb/ax88172a.c index e47bb125048d..f613e4bc68c8 100644 --- a/drivers/net/usb/ax88172a.c +++ b/drivers/net/usb/ax88172a.c @@ -18,8 +18,8 @@ struct ax88172a_private { struct mii_bus *mdio; struct phy_device *phydev; - char phy_name[20]; - u16 phy_addr; + char phy_name[PHY_ID_SIZE]; + u8 phy_addr; u16 oldmode; int use_embdphy; struct asix_rx_fixup_info rx_fixup_info; @@ -210,7 +210,11 @@ static int ax88172a_bind(struct usbnet *dev, struct usb_interface *intf) ret = asix_read_phy_addr(dev, priv->use_embdphy); if (ret < 0) goto free; - + if (ret >= PHY_MAX_ADDR) { + netdev_err(dev->net, "Invalid PHY address %#x\n", ret); + ret = -ENODEV; + goto free; + } priv->phy_addr = ret; ax88172a_reset_phy(dev, priv->use_embdphy); @@ -308,7 +312,7 @@ static int ax88172a_reset(struct usbnet *dev) rx_ctl); /* Connect to PHY */ - snprintf(priv->phy_name, 20, PHY_ID_FMT, + snprintf(priv->phy_name, sizeof(priv->phy_name), PHY_ID_FMT, priv->mdio->id, priv->phy_addr); priv->phydev = phy_connect(dev->net, priv->phy_name, diff --git a/include/linux/phy.h b/include/linux/phy.h index bfdbdc538910..a2bfae80c449 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -292,6 +292,7 @@ static inline long rgmii_clock(int speed) /* Used when trying to connect to a specific phy (mii bus id:phy device id) */ #define PHY_ID_FMT "%s:%02x" +#define PHY_ID_SIZE (MII_BUS_ID_SIZE + 3) #define MII_BUS_ID_SIZE 61 |