net: dsa: hellcreek: Get rid of custom led_init_default_state_get()
PATCH v5 1/1 net: dsa: hellcreek: Get rid of custom led_init_default_state_get()
LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.
---
v5: resent after v6.3-rc1 with proper net-next prefix
drivers/net/dsa/hirschmann/hellcreek_ptp.c | 45 ++++++++++++---------- 1 file changed, 24 insertions(+), 21 deletions(-)
drivers/net/dsa/hirschmann/hellcreek_ptp.c +24 -21
@@ -297,7 +297,8 @@ static enum led_brightness hellcreek_led_is_gm_get(struct led_classdev *ldev)static int hellcreek_led_setup (struct hellcreek *hellcreek) {struct device_node *leds, *led =NULL ; -const char *label, *state; +enum led_default_state state; +const char *label;int ret = -EINVAL ;of_node_get (hellcreek->dev->of_node);
@@ -318,16 +319,17 @@ static int hellcreek_led_setup(struct hellcreek *hellcreek) ret =of_property_read_string (led,"label" , &label); hellcreek->led_sync_good.name = ret ?"sync_good" : label; - ret =of_property_read_string (led,"default-state" , &state); -if (!ret) { -if (!strcmp (state,"on" )) - hellcreek->led_sync_good.brightness =1 ; -else if (!strcmp (state,"off" )) - hellcreek->led_sync_good.brightness =0 ; -else if (!strcmp (state,"keep" )) - hellcreek->led_sync_good.brightness = -hellcreek_get_brightness (hellcreek, -STATUS_OUT_SYNC_GOOD ); + state =led_init_default_state_get (of_fwnode_handle (led)); +switch (state) { +case LEDS_DEFSTATE_ON : + hellcreek->led_sync_good.brightness =1 ; +break ; +case LEDS_DEFSTATE_KEEP : + hellcreek->led_sync_good.brightness = +hellcreek_get_brightness (hellcreek,STATUS_OUT_SYNC_GOOD ); +break ; +default : + hellcreek->led_sync_good.brightness =0 ; } hellcreek->led_sync_good.max_brightness =1 ;
@@ -344,16 +346,17 @@ static int hellcreek_led_setup(struct hellcreek *hellcreek) ret =of_property_read_string (led,"label" , &label); hellcreek->led_is_gm.name = ret ?"is_gm" : label; - ret =of_property_read_string (led,"default-state" , &state); -if (!ret) { -if (!strcmp (state,"on" )) - hellcreek->led_is_gm.brightness =1 ; -else if (!strcmp (state,"off" )) - hellcreek->led_is_gm.brightness =0 ; -else if (!strcmp (state,"keep" )) - hellcreek->led_is_gm.brightness = -hellcreek_get_brightness (hellcreek, -STATUS_OUT_IS_GM ); + state =led_init_default_state_get (of_fwnode_handle (led)); +switch (state) { +case LEDS_DEFSTATE_ON : + hellcreek->led_is_gm.brightness =1 ; +break ; +case LEDS_DEFSTATE_KEEP : + hellcreek->led_is_gm.brightness = +hellcreek_get_brightness (hellcreek,STATUS_OUT_IS_GM ); +break ; +default : + hellcreek->led_is_gm.brightness =0 ; } hellcreek->led_is_gm.max_brightness =1 ;
Signature · 1 line
2.39.1
Quoted 36 lines · Andy Shevchenko
LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.
Signed-off-by Andy Shevchenko <[email protected]>Reviewed-by Kurt Kanzenbach <[email protected]>---
v5: resent after v6.3-rc1 with proper net-next prefixdrivers/net/dsa/hirschmann/hellcreek_ptp.c | 45 ++++++++++++---------- 1 file changed, 24 insertions(+), 21 deletions(-)drivers/net/dsa/hirschmann/hellcreek_ptp.c +2
-9@@ -297,7 +297,8 @@ static enum led_brightness hellcreek_led_is_gm_get(struct led_classdev *ldev)static int hellcreek_led_setup (struct hellcreek *hellcreek) {struct device_node *leds, *led =NULL ; -const char *label, *state; +enum led_default_state state; +const char *label;int ret = -EINVAL ;of_node_get (hellcreek->dev->of_node);@@ -318,16 +319,17 @@ static int hellcreek_led_setup(struct hellcreek *hellcreek) ret =of_property_read_string (led,"label" , &label); hellcreek->led_sync_good.name = ret ?"sync_good" : label; - ret =of_property_read_string (led,"default-state" , &state); -if (!ret) { -if (!strcmp (state,"on" )) - hellcreek->led_sync_good.brightness =1 ; -else if (!strcmp (state,"off" )) - hellcreek->led_sync_good.brightness =0 ; -else if (!strcmp (state,"keep" )) - hellcreek->led_sync_good.brightness =
drivers/net/dsa/hirschmann/hellcreek_ptp.c static int hellcreek_led_setup(struct hellcreek *hellcreek) · line 329
Quoted 10 lines
drivers/net/dsa/hirschmann/hellcreek_ptp.c +8
-2-hellcreek_get_brightness (hellcreek, -STATUS_OUT_SYNC_GOOD ); + state =led_init_default_state_get (of_fwnode_handle (led)); +switch (state) { +case LEDS_DEFSTATE_ON : + hellcreek->led_sync_good.brightness =1 ; +break ; +case LEDS_DEFSTATE_KEEP : + hellcreek->led_sync_good.brightness = +hellcreek_get_brightness (hellcreek,STATUS_OUT_SYNC_GOOD );
nit: I think < 80 columns wide is still preferred for network code
Quoted 22 lines
drivers/net/dsa/hirschmann/hellcreek_ptp.c +5
-10+break ; +default : + hellcreek->led_sync_good.brightness =0 ; } hellcreek->led_sync_good.max_brightness =1 ;@@ -344,16 +346,17 @@ static int hellcreek_led_setup(struct hellcreek *hellcreek) ret =of_property_read_string (led,"label" , &label); hellcreek->led_is_gm.name = ret ?"is_gm" : label; - ret =of_property_read_string (led,"default-state" , &state); -if (!ret) { -if (!strcmp (state,"on" )) - hellcreek->led_is_gm.brightness =1 ; -else if (!strcmp (state,"off" )) - hellcreek->led_is_gm.brightness =0 ; -else if (!strcmp (state,"keep" )) - hellcreek->led_is_gm.brightness = -hellcreek_get_brightness (hellcreek, -STATUS_OUT_IS_GM ); + state =led_init_default_state_get (of_fwnode_handle (led)); +switch (state) {
drivers/net/dsa/hirschmann/hellcreek_ptp.c static int hellcreek_led_setup(struct hellcreek *hellcreek) · line 360
Quoted 10 lines
drivers/net/dsa/hirschmann/hellcreek_ptp.c +9
-0+case LEDS_DEFSTATE_ON : + hellcreek->led_is_gm.brightness =1 ; +break ; +case LEDS_DEFSTATE_KEEP : + hellcreek->led_is_gm.brightness = +hellcreek_get_brightness (hellcreek,STATUS_OUT_IS_GM ); +break ; +default : + hellcreek->led_is_gm.brightness =0 ; }
This seems to duplicate the logic in the earlier hunk of this patch. Could it be moved into a helper?
Quoted 5 lines
drivers/net/dsa/hirschmann/hellcreek_ptp.c +0
-0hellcreek->led_is_gm.max_brightness =1 ;Signature · 1 line
2.39.1
Quoted 1 line · Simon Horman
On Fri, Mar 10, 2023 at 06:38:55PM +0200, Andy Shevchenko wrote:
...
Quoted 4 lines
drivers/net/dsa/hirschmann/hellcreek_ptp.c static int hellcreek_led_setup(struct hellcreek *hellcreek) · line 329
Quoted 2 lines
drivers/net/dsa/hirschmann/hellcreek_ptp.c +2
-0+ hellcreek->led_sync_good.brightness = +hellcreek_get_brightness (hellcreek,STATUS_OUT_SYNC_GOOD );nit: I think < 80 columns wide is still preferred for network code
I can do it if it's a strict rule here.
...
Quoted 2 lines
This seems to duplicate the logic in the earlier hunk of this patch. Could it be moved into a helper?
It's possible, but in a separate patch as it's out of scope of this one. Do you want to create a such?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Simon Horman
On Fri, Mar 10, 2023 at 06:38:55PM +0200, Andy Shevchenko wrote:
...
Quoted 5 lines
Quoted 2 lines
This seems to duplicate the logic in the earlier hunk of this patch. Could it be moved into a helper?
It's possible, but in a separate patch as it's out of scope of this one. Do you want to create a such?
FWIW, I tried and it gives us +9 lines of code. So, what would be the point? I can send as RFC in v6.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Simon Horman
On Fri, Mar 10, 2023 at 06:38:55PM +0200, Andy Shevchenko wrote:
...
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
This seems to duplicate the logic in the earlier hunk of this patch. Could it be moved into a helper?
It's possible, but in a separate patch as it's out of scope of this one. Do you want to create a such?
FWIW, I tried and it gives us +9 lines of code. So, what would be the point? I can send as RFC in v6.
Less duplication is good, IMHO. But it's not a hard requirement from my side.
Quoted 4 lines · Simon Horman
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Simon Horman
On Fri, Mar 10, 2023 at 06:38:55PM +0200, Andy Shevchenko wrote:
...
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
This seems to duplicate the logic in the earlier hunk of this patch. Could it be moved into a helper?
It's possible, but in a separate patch as it's out of scope of this one. Do you want to create a such?
FWIW, I tried and it gives us +9 lines of code. So, what would be the point? I can send as RFC in v6.
Less duplication is good, IMHO. But it's not a hard requirement from my side.
With what I see as PoC it becomes:
a) longer (+9 LoCs);
b) less understandable.
So, I would wait for maintainers to tell me if I need this at all.
Thank you for the review!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 1 line · Simon Horman
On Fri, Mar 10, 2023 at 06:38:55PM +0200, Andy Shevchenko wrote:
...
Quoted 4 lines
drivers/net/dsa/hirschmann/hellcreek_ptp.c static int hellcreek_led_setup(struct hellcreek *hellcreek) · line 329
Quoted 2 lines
drivers/net/dsa/hirschmann/hellcreek_ptp.c +2
-0+ hellcreek->led_sync_good.brightness = +hellcreek_get_brightness (hellcreek,STATUS_OUT_SYNC_GOOD );nit: I think < 80 columns wide is still preferred for network code
I can do it if it's a strict rule here.
I think it is more a preference than a strict rule at this point.
Jakub Kicinski
maintainerQuoted 5 lines · On Fri, 10 Mar 2023 21:17:06 +0100 Simon Horman wrote:
Quoted 3 lines
Quoted 1 line
nit: I think < 80 columns wide is still preferred for network code
I can do it if it's a strict rule here.
I think it is more a preference than a strict rule at this point.
You're right, but the longer I think about it the more I feel like it should be.
80 chars is an artificial constraint these day but it simply results in more readable code.
I can't see the entirety of "hellcreek->led_sync_good.brightness" at once, using it as lval in 3 different places is not great. Maybe it's my poor eyesight.