]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
net: phy: avoid undefined behavior in *_led_polarity_set()
authorArnd Bergmann <arnd@arndb.de>
Tue, 17 Dec 2024 08:10:34 +0000 (09:10 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 19 Dec 2024 00:50:23 +0000 (16:50 -0800)
gcc runs into undefined behavior at the end of the three led_polarity_set()
callback functions if it were called with a zero 'modes' argument and it
just ends the function there without returning from it.

This gets flagged by 'objtool' as a function that continues on
to the next one:

drivers/net/phy/aquantia/aquantia_leds.o: warning: objtool: aqr_phy_led_polarity_set+0xf: can't find jump dest instruction at .text+0x5d9
drivers/net/phy/intel-xway.o: warning: objtool: xway_gphy_led_polarity_set() falls through to next function xway_gphy_config_init()
drivers/net/phy/mxl-gpy.o: warning: objtool: gpy_led_polarity_set() falls through to next function gpy_led_hw_control_get()

There is no point to micro-optimize the behavior here to save a single-digit
number of bytes in the kernel, so just change this to a "return -EINVAL"
as we do when any unexpected bits are set.

Fixes: 1758af47b98c ("net: phy: intel-xway: add support for PHY LEDs")
Fixes: 9d55e68b19f2 ("net: phy: aquantia: correctly describe LED polarity override")
Fixes: eb89c79c1b8f ("net: phy: mxl-gpy: correctly describe LED polarity")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20241217081056.238792-1-arnd@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/aquantia/aquantia_leds.c
drivers/net/phy/intel-xway.c
drivers/net/phy/mxl-gpy.c

index 00ad2313fed36eed549ffa55eb06e527f7c3de92..951f46104eff04ed42aa25e94a8acfcb9d5eeaaa 100644 (file)
@@ -156,5 +156,5 @@ int aqr_phy_led_polarity_set(struct phy_device *phydev, int index, unsigned long
        if (force_active_high || force_active_low)
                return aqr_phy_led_active_low_set(phydev, index, force_active_low);
 
-       unreachable();
+       return -EINVAL;
 }
index b672c55a7a4e7c4f305bfe88c42c3bc5d5a3696a..e6ed2413e514c72985780b4e60c3cd92cdfee549 100644 (file)
@@ -529,7 +529,7 @@ static int xway_gphy_led_polarity_set(struct phy_device *phydev, int index,
        if (force_active_high)
                return phy_clear_bits(phydev, XWAY_MDIO_LED, XWAY_GPHY_LED_INV(index));
 
-       unreachable();
+       return -EINVAL;
 }
 
 static struct phy_driver xway_gphy[] = {
index db3c1f72b40734d7189feb0c3d93ef28f7974d12..a8ccf257c109439dcd52a39b80dcad4815fb9bd3 100644 (file)
@@ -1014,7 +1014,7 @@ static int gpy_led_polarity_set(struct phy_device *phydev, int index,
        if (force_active_high)
                return phy_clear_bits(phydev, PHY_LED, PHY_LED_POLARITY(index));
 
-       unreachable();
+       return -EINVAL;
 }
 
 static struct phy_driver gpy_drivers[] = {