net: phy: leds: Deduplicate link LED trigger registration
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 27 Oct 2020 18:21:46 +0000 (20:21 +0200)
committerJakub Kicinski <kuba@kernel.org>
Fri, 30 Oct 2020 17:43:37 +0000 (10:43 -0700)
Refactor phy_led_trigger_register() and deduplicate its functionality
when registering LED trigger for link.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20201027182146.21355-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/phy_led_triggers.c

index 59a94e0..f550576 100644 (file)
@@ -66,11 +66,11 @@ static void phy_led_trigger_format_name(struct phy_device *phy, char *buf,
 
 static int phy_led_trigger_register(struct phy_device *phy,
                                    struct phy_led_trigger *plt,
-                                   unsigned int speed)
+                                   unsigned int speed,
+                                   const char *suffix)
 {
        plt->speed = speed;
-       phy_led_trigger_format_name(phy, plt->name, sizeof(plt->name),
-                                   phy_speed_to_str(speed));
+       phy_led_trigger_format_name(phy, plt->name, sizeof(plt->name), suffix);
        plt->trigger.name = plt->name;
 
        return led_trigger_register(&plt->trigger);
@@ -99,12 +99,7 @@ int phy_led_triggers_register(struct phy_device *phy)
                goto out_clear;
        }
 
-       phy_led_trigger_format_name(phy, phy->led_link_trigger->name,
-                                   sizeof(phy->led_link_trigger->name),
-                                   "link");
-       phy->led_link_trigger->trigger.name = phy->led_link_trigger->name;
-
-       err = led_trigger_register(&phy->led_link_trigger->trigger);
+       err = phy_led_trigger_register(phy, phy->led_link_trigger, 0, "link");
        if (err)
                goto out_free_link;
 
@@ -119,7 +114,8 @@ int phy_led_triggers_register(struct phy_device *phy)
 
        for (i = 0; i < phy->phy_num_led_triggers; i++) {
                err = phy_led_trigger_register(phy, &phy->phy_led_triggers[i],
-                                              speeds[i]);
+                                              speeds[i],
+                                              phy_speed_to_str(speeds[i]));
                if (err)
                        goto out_unreg;
        }