Skip to content

Commit

Permalink
net: phy: leds: Refactor "no link" handler into a separate function
Browse files Browse the repository at this point in the history
Currently, phy_led_trigger_change_speed() is handling a "no link" condition
like it was some kind of an error (using "goto" to a code at the function
end).

However, having no link at PHY is an ordinary operational state, so let's
handle it in an appropriately named separate function so it is more obvious
what the code is doing.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Maciej S. Szmigiero authored and David S. Miller committed Nov 8, 2017
1 parent fffcefe commit ff198cd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions drivers/net/phy/phy_led_triggers.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ static struct phy_led_trigger *phy_speed_to_led_trigger(struct phy_device *phy,
return NULL;
}

static void phy_led_trigger_no_link(struct phy_device *phy)
{
if (phy->last_triggered) {
led_trigger_event(&phy->last_triggered->trigger, LED_OFF);
phy->last_triggered = NULL;
}
}

void phy_led_trigger_change_speed(struct phy_device *phy)
{
struct phy_led_trigger *plt;

if (!phy->link)
goto out_change_speed;
return phy_led_trigger_no_link(phy);

if (phy->speed == 0)
return;
Expand All @@ -42,22 +50,14 @@ void phy_led_trigger_change_speed(struct phy_device *phy)
netdev_alert(phy->attached_dev,
"No phy led trigger registered for speed(%d)\n",
phy->speed);
goto out_change_speed;
return phy_led_trigger_no_link(phy);
}

if (plt != phy->last_triggered) {
led_trigger_event(&phy->last_triggered->trigger, LED_OFF);
led_trigger_event(&plt->trigger, LED_FULL);
phy->last_triggered = plt;
}
return;

out_change_speed:
if (phy->last_triggered) {
led_trigger_event(&phy->last_triggered->trigger,
LED_OFF);
phy->last_triggered = NULL;
}
}
EXPORT_SYMBOL_GPL(phy_led_trigger_change_speed);

Expand Down

0 comments on commit ff198cd

Please sign in to comment.