Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

r8169: improve checking for valid LED modes

After 3a2746320403 ("leds: trigger: netdev: Display only supported link
speed attribute") the check for valid link modes can be simplified.
In addition factor it out, so that it can be re-used by the upcoming
LED support for RTL8125.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/8876a9f4-7a2d-48c3-8eae-0d834f5c27c5@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Heiner Kallweit and committed by
Jakub Kicinski
4c49b682 876e3247

+20 -18
+20 -18
drivers/net/ethernet/realtek/r8169_leds.c
··· 20 20 21 21 #define RTL8168_NUM_LEDS 3 22 22 23 - #define RTL8168_SUPPORTED_MODES \ 24 - (BIT(TRIGGER_NETDEV_LINK_1000) | BIT(TRIGGER_NETDEV_LINK_100) | \ 25 - BIT(TRIGGER_NETDEV_LINK_10) | BIT(TRIGGER_NETDEV_RX) | \ 26 - BIT(TRIGGER_NETDEV_TX)) 27 - 28 23 struct r8169_led_classdev { 29 24 struct led_classdev led; 30 25 struct net_device *ndev; ··· 28 33 29 34 #define lcdev_to_r8169_ldev(lcdev) container_of(lcdev, struct r8169_led_classdev, led) 30 35 36 + static bool r8169_trigger_mode_is_valid(unsigned long flags) 37 + { 38 + bool rx, tx; 39 + 40 + if (flags & BIT(TRIGGER_NETDEV_HALF_DUPLEX)) 41 + return false; 42 + if (flags & BIT(TRIGGER_NETDEV_FULL_DUPLEX)) 43 + return false; 44 + 45 + rx = flags & BIT(TRIGGER_NETDEV_RX); 46 + tx = flags & BIT(TRIGGER_NETDEV_TX); 47 + 48 + return rx == tx; 49 + } 50 + 31 51 static int rtl8168_led_hw_control_is_supported(struct led_classdev *led_cdev, 32 52 unsigned long flags) 33 53 { 34 54 struct r8169_led_classdev *ldev = lcdev_to_r8169_ldev(led_cdev); 35 55 struct rtl8169_private *tp = netdev_priv(ldev->ndev); 36 56 int shift = ldev->index * 4; 37 - bool rx, tx; 38 57 39 - if (flags & ~RTL8168_SUPPORTED_MODES) 40 - goto nosupp; 41 - 42 - rx = flags & BIT(TRIGGER_NETDEV_RX); 43 - tx = flags & BIT(TRIGGER_NETDEV_TX); 44 - if (rx != tx) 45 - goto nosupp; 58 + if (!r8169_trigger_mode_is_valid(flags)) { 59 + /* Switch LED off to indicate that mode isn't supported */ 60 + rtl8168_led_mod_ctrl(tp, 0x000f << shift, 0); 61 + return -EOPNOTSUPP; 62 + } 46 63 47 64 return 0; 48 - 49 - nosupp: 50 - /* Switch LED off to indicate that mode isn't supported */ 51 - rtl8168_led_mod_ctrl(tp, 0x000f << shift, 0); 52 - return -EOPNOTSUPP; 53 65 } 54 66 55 67 static int rtl8168_led_hw_control_set(struct led_classdev *led_cdev,