diff mbox series

[net-next,v1,1/1] net: dsa: hellcreek: Get rid of custom led_init_default_state_get()

Message ID 20220802212144.6743-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v1,1/1] net: dsa: hellcreek: Get rid of custom led_init_default_state_get() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 0 this patch: 8
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang fail Errors and warnings before: 0 this patch: 8
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 0 this patch: 8
netdev/checkpatch warning WARNING: line length of 86 exceeds 80 columns WARNING: line length of 90 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Andy Shevchenko Aug. 2, 2022, 9:21 p.m. UTC
LED core provides a helper to parse default state from firmware node.
Use it instead of custom implementation.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/net/dsa/hirschmann/hellcreek_ptp.c | 45 ++++++++++++----------
 1 file changed, 24 insertions(+), 21 deletions(-)

Comments

Kurt Kanzenbach Aug. 3, 2022, 5:35 a.m. UTC | #1
On Wed Aug 03 2022, Andy Shevchenko wrote:
> LED core provides a helper to parse default state from firmware node.
> Use it instead of custom implementation.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/net/dsa/hirschmann/hellcreek_ptp.c | 45 ++++++++++++----------
>  1 file changed, 24 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/net/dsa/hirschmann/hellcreek_ptp.c b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
> index b28baab6d56a..793b2c296314 100644
> --- a/drivers/net/dsa/hirschmann/hellcreek_ptp.c
> +++ b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
> @@ -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));

Applied your patch to net-next/master and this yields:

|drivers/net/dsa/hirschmann/hellcreek_ptp.c: In function ‘hellcreek_led_setup’:
|drivers/net/dsa/hirschmann/hellcreek_ptp.c:430:10: error: implicit declaration of function ‘led_init_default_state_get’; did you mean ‘led_get_default_pattern’? [-Werror=implicit-function-declaration]
|  430 |  state = led_init_default_state_get(of_fwnode_handle(led));
|      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
|      |          led_get_default_pattern

The header is missing:

|diff --git a/drivers/net/dsa/hirschmann/hellcreek_ptp.c b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
|index df339f3e1803..430f39172d58 100644
|--- a/drivers/net/dsa/hirschmann/hellcreek_ptp.c
|+++ b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
|@@ -14,6 +14,8 @@
| #include "hellcreek_ptp.h"
| #include "hellcreek_hwtstamp.h"
| 
|+#include "../../../leds/leds.h"
|+
| u16 hellcreek_ptp_read(struct hellcreek *hellcreek, unsigned int offset)
| {
|        return readw(hellcreek->ptp_base + offset);

Maybe move led_init_default_state_get() to linux/leds.h?

Thanks,
Kurt
Andy Shevchenko Aug. 3, 2022, 11:24 a.m. UTC | #2
On Wed, Aug 3, 2022 at 7:39 AM Kurt Kanzenbach <kurt@linutronix.de> wrote:
>
> On Wed Aug 03 2022, Andy Shevchenko wrote:
> > LED core provides a helper to parse default state from firmware node.
> > Use it instead of custom implementation.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  drivers/net/dsa/hirschmann/hellcreek_ptp.c | 45 ++++++++++++----------
> >  1 file changed, 24 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/net/dsa/hirschmann/hellcreek_ptp.c b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
> > index b28baab6d56a..793b2c296314 100644
> > --- a/drivers/net/dsa/hirschmann/hellcreek_ptp.c
> > +++ b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
> > @@ -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));
>
> Applied your patch to net-next/master and this yields:
>
> |drivers/net/dsa/hirschmann/hellcreek_ptp.c: In function ‘hellcreek_led_setup’:
> |drivers/net/dsa/hirschmann/hellcreek_ptp.c:430:10: error: implicit declaration of function ‘led_init_default_state_get’; did you mean ‘led_get_default_pattern’? [-Werror=implicit-function-declaration]
> |  430 |  state = led_init_default_state_get(of_fwnode_handle(led));
> |      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
> |      |          led_get_default_pattern
>
> The header is missing:
>
> |diff --git a/drivers/net/dsa/hirschmann/hellcreek_ptp.c b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
> |index df339f3e1803..430f39172d58 100644
> |--- a/drivers/net/dsa/hirschmann/hellcreek_ptp.c
> |+++ b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
> |@@ -14,6 +14,8 @@
> | #include "hellcreek_ptp.h"
> | #include "hellcreek_hwtstamp.h"
> |
> |+#include "../../../leds/leds.h"
> |+
> | u16 hellcreek_ptp_read(struct hellcreek *hellcreek, unsigned int offset)
> | {
> |        return readw(hellcreek->ptp_base + offset);
>
> Maybe move led_init_default_state_get() to linux/leds.h?

Yep, thanks! Missed patch and all of them should be sent as a series...
diff mbox series

Patch

diff --git a/drivers/net/dsa/hirschmann/hellcreek_ptp.c b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
index b28baab6d56a..793b2c296314 100644
--- a/drivers/net/dsa/hirschmann/hellcreek_ptp.c
+++ b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
@@ -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;