diff mbox series

[v1,1/1] leds: mt6360: Get rid of custom led_init_default_state_get()

Message ID 20220802212532.7091-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1,1/1] leds: mt6360: Get rid of custom led_init_default_state_get() | expand

Commit Message

Andy Shevchenko Aug. 2, 2022, 9:25 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/leds/flash/leds-mt6360.c | 38 +++++---------------------------
 1 file changed, 6 insertions(+), 32 deletions(-)

Comments

kernel test robot Aug. 2, 2022, 11:32 p.m. UTC | #1
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on pavel-leds/for-next]
[also build test ERROR on linus/master v5.19 next-20220728]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/leds-mt6360-Get-rid-of-custom-led_init_default_state_get/20220803-052854
base:   git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next
config: hexagon-randconfig-r045-20220802 (https://download.01.org/0day-ci/archive/20220803/202208030736.6ZT2jOdB-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 52cd00cabf479aa7eb6dbb063b7ba41ea57bce9e)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/260d7c20cbd2b5da92dfa5ffa7c73499661c838f
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Andy-Shevchenko/leds-mt6360-Get-rid-of-custom-led_init_default_state_get/20220803-052854
        git checkout 260d7c20cbd2b5da92dfa5ffa7c73499661c838f
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/leds/flash/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/leds/flash/leds-mt6360.c:832:24: error: call to undeclared function 'led_init_default_state_get'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                   led->default_state = led_init_default_state_get(child);
                                        ^
   1 error generated.


vim +/led_init_default_state_get +832 drivers/leds/flash/leds-mt6360.c

   770	
   771	static int mt6360_led_probe(struct platform_device *pdev)
   772	{
   773		struct mt6360_priv *priv;
   774		struct fwnode_handle *child;
   775		size_t count;
   776		int i = 0, ret;
   777	
   778		count = device_get_child_node_count(&pdev->dev);
   779		if (!count || count > MT6360_MAX_LEDS) {
   780			dev_err(&pdev->dev,
   781				"No child node or node count over max led number %zu\n",
   782				count);
   783			return -EINVAL;
   784		}
   785	
   786		priv = devm_kzalloc(&pdev->dev,
   787				    struct_size(priv, leds, count), GFP_KERNEL);
   788		if (!priv)
   789			return -ENOMEM;
   790	
   791		priv->leds_count = count;
   792		priv->dev = &pdev->dev;
   793		mutex_init(&priv->lock);
   794	
   795		priv->regmap = dev_get_regmap(pdev->dev.parent, NULL);
   796		if (!priv->regmap) {
   797			dev_err(&pdev->dev, "Failed to get parent regmap\n");
   798			return -ENODEV;
   799		}
   800	
   801		device_for_each_child_node(&pdev->dev, child) {
   802			struct mt6360_led *led = priv->leds + i;
   803			struct led_init_data init_data = { .fwnode = child, };
   804			u32 reg, led_color;
   805	
   806			ret = fwnode_property_read_u32(child, "color", &led_color);
   807			if (ret)
   808				goto out_flash_release;
   809	
   810			if (led_color == LED_COLOR_ID_RGB ||
   811			    led_color == LED_COLOR_ID_MULTI)
   812				reg = MT6360_VIRTUAL_MULTICOLOR;
   813			else {
   814				ret = fwnode_property_read_u32(child, "reg", &reg);
   815				if (ret)
   816					goto out_flash_release;
   817	
   818				if (reg >= MT6360_MAX_LEDS) {
   819					ret = -EINVAL;
   820					goto out_flash_release;
   821				}
   822			}
   823	
   824			if (priv->leds_active & BIT(reg)) {
   825				ret = -EINVAL;
   826				goto out_flash_release;
   827			}
   828			priv->leds_active |= BIT(reg);
   829	
   830			led->led_no = reg;
   831			led->priv = priv;
 > 832			led->default_state = led_init_default_state_get(child);
   833	
   834			if (reg == MT6360_VIRTUAL_MULTICOLOR ||
   835			    reg <= MT6360_LED_ISNKML)
   836				ret = mt6360_init_isnk_properties(led, &init_data);
   837			else
   838				ret = mt6360_init_flash_properties(led, &init_data);
   839	
   840			if (ret)
   841				goto out_flash_release;
   842	
   843			ret = mt6360_led_register(&pdev->dev, led, &init_data);
   844			if (ret)
   845				goto out_flash_release;
   846	
   847			i++;
   848		}
   849	
   850		platform_set_drvdata(pdev, priv);
   851		return 0;
   852	
   853	out_flash_release:
   854		mt6360_v4l2_flash_release(priv);
   855		return ret;
   856	}
   857
kernel test robot Aug. 2, 2022, 11:43 p.m. UTC | #2
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on pavel-leds/for-next]
[also build test ERROR on linus/master v5.19 next-20220728]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/leds-mt6360-Get-rid-of-custom-led_init_default_state_get/20220803-052854
base:   git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next
config: arc-randconfig-r043-20220802 (https://download.01.org/0day-ci/archive/20220803/202208030728.Yo6CynF9-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/260d7c20cbd2b5da92dfa5ffa7c73499661c838f
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Andy-Shevchenko/leds-mt6360-Get-rid-of-custom-led_init_default_state_get/20220803-052854
        git checkout 260d7c20cbd2b5da92dfa5ffa7c73499661c838f
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash drivers/leds/flash/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/leds/flash/leds-mt6360.c: In function 'mt6360_led_probe':
>> drivers/leds/flash/leds-mt6360.c:832:38: error: implicit declaration of function 'led_init_default_state_get'; did you mean 'led_get_default_pattern'? [-Werror=implicit-function-declaration]
     832 |                 led->default_state = led_init_default_state_get(child);
         |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                      led_get_default_pattern
   cc1: some warnings being treated as errors


vim +832 drivers/leds/flash/leds-mt6360.c

   770	
   771	static int mt6360_led_probe(struct platform_device *pdev)
   772	{
   773		struct mt6360_priv *priv;
   774		struct fwnode_handle *child;
   775		size_t count;
   776		int i = 0, ret;
   777	
   778		count = device_get_child_node_count(&pdev->dev);
   779		if (!count || count > MT6360_MAX_LEDS) {
   780			dev_err(&pdev->dev,
   781				"No child node or node count over max led number %zu\n",
   782				count);
   783			return -EINVAL;
   784		}
   785	
   786		priv = devm_kzalloc(&pdev->dev,
   787				    struct_size(priv, leds, count), GFP_KERNEL);
   788		if (!priv)
   789			return -ENOMEM;
   790	
   791		priv->leds_count = count;
   792		priv->dev = &pdev->dev;
   793		mutex_init(&priv->lock);
   794	
   795		priv->regmap = dev_get_regmap(pdev->dev.parent, NULL);
   796		if (!priv->regmap) {
   797			dev_err(&pdev->dev, "Failed to get parent regmap\n");
   798			return -ENODEV;
   799		}
   800	
   801		device_for_each_child_node(&pdev->dev, child) {
   802			struct mt6360_led *led = priv->leds + i;
   803			struct led_init_data init_data = { .fwnode = child, };
   804			u32 reg, led_color;
   805	
   806			ret = fwnode_property_read_u32(child, "color", &led_color);
   807			if (ret)
   808				goto out_flash_release;
   809	
   810			if (led_color == LED_COLOR_ID_RGB ||
   811			    led_color == LED_COLOR_ID_MULTI)
   812				reg = MT6360_VIRTUAL_MULTICOLOR;
   813			else {
   814				ret = fwnode_property_read_u32(child, "reg", &reg);
   815				if (ret)
   816					goto out_flash_release;
   817	
   818				if (reg >= MT6360_MAX_LEDS) {
   819					ret = -EINVAL;
   820					goto out_flash_release;
   821				}
   822			}
   823	
   824			if (priv->leds_active & BIT(reg)) {
   825				ret = -EINVAL;
   826				goto out_flash_release;
   827			}
   828			priv->leds_active |= BIT(reg);
   829	
   830			led->led_no = reg;
   831			led->priv = priv;
 > 832			led->default_state = led_init_default_state_get(child);
   833	
   834			if (reg == MT6360_VIRTUAL_MULTICOLOR ||
   835			    reg <= MT6360_LED_ISNKML)
   836				ret = mt6360_init_isnk_properties(led, &init_data);
   837			else
   838				ret = mt6360_init_flash_properties(led, &init_data);
   839	
   840			if (ret)
   841				goto out_flash_release;
   842	
   843			ret = mt6360_led_register(&pdev->dev, led, &init_data);
   844			if (ret)
   845				goto out_flash_release;
   846	
   847			i++;
   848		}
   849	
   850		platform_set_drvdata(pdev, priv);
   851		return 0;
   852	
   853	out_flash_release:
   854		mt6360_v4l2_flash_release(priv);
   855		return ret;
   856	}
   857
Matthias Brugger Aug. 3, 2022, 11:44 a.m. UTC | #3
On 02/08/2022 23:25, 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>

Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> ---
>   drivers/leds/flash/leds-mt6360.c | 38 +++++---------------------------
>   1 file changed, 6 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/leds/flash/leds-mt6360.c b/drivers/leds/flash/leds-mt6360.c
> index e1066a52d2d2..1af6c5898343 100644
> --- a/drivers/leds/flash/leds-mt6360.c
> +++ b/drivers/leds/flash/leds-mt6360.c
> @@ -71,10 +71,6 @@ enum {
>   #define MT6360_STRBTO_STEPUS		32000
>   #define MT6360_STRBTO_MAXUS		2432000
>   
> -#define STATE_OFF			0
> -#define STATE_KEEP			1
> -#define STATE_ON			2
> -
>   struct mt6360_led {
>   	union {
>   		struct led_classdev isnk;
> @@ -84,7 +80,7 @@ struct mt6360_led {
>   	struct v4l2_flash *v4l2_flash;
>   	struct mt6360_priv *priv;
>   	u32 led_no;
> -	u32 default_state;
> +	enum led_default_state default_state;
>   };
>   
>   struct mt6360_priv {
> @@ -405,10 +401,10 @@ static int mt6360_isnk_init_default_state(struct mt6360_led *led)
>   		level = LED_OFF;
>   
>   	switch (led->default_state) {
> -	case STATE_ON:
> +	case LEDS_DEFSTATE_ON:
>   		led->isnk.brightness = led->isnk.max_brightness;
>   		break;
> -	case STATE_KEEP:
> +	case LEDS_DEFSTATE_KEEP:
>   		led->isnk.brightness = min(level, led->isnk.max_brightness);
>   		break;
>   	default:
> @@ -443,10 +439,10 @@ static int mt6360_flash_init_default_state(struct mt6360_led *led)
>   		level = LED_OFF;
>   
>   	switch (led->default_state) {
> -	case STATE_ON:
> +	case LEDS_DEFSTATE_ON:
>   		flash->led_cdev.brightness = flash->led_cdev.max_brightness;
>   		break;
> -	case STATE_KEEP:
> +	case LEDS_DEFSTATE_KEEP:
>   		flash->led_cdev.brightness =
>   			min(level, flash->led_cdev.max_brightness);
>   		break;
> @@ -760,25 +756,6 @@ static int mt6360_init_flash_properties(struct mt6360_led *led,
>   	return 0;
>   }
>   
> -static int mt6360_init_common_properties(struct mt6360_led *led,
> -					 struct led_init_data *init_data)
> -{
> -	const char *const states[] = { "off", "keep", "on" };
> -	const char *str;
> -	int ret;
> -
> -	if (!fwnode_property_read_string(init_data->fwnode,
> -					 "default-state", &str)) {
> -		ret = match_string(states, ARRAY_SIZE(states), str);
> -		if (ret < 0)
> -			ret = STATE_OFF;
> -
> -		led->default_state = ret;
> -	}
> -
> -	return 0;
> -}
> -
>   static void mt6360_v4l2_flash_release(struct mt6360_priv *priv)
>   {
>   	int i;
> @@ -852,10 +829,7 @@ static int mt6360_led_probe(struct platform_device *pdev)
>   
>   		led->led_no = reg;
>   		led->priv = priv;
> -
> -		ret = mt6360_init_common_properties(led, &init_data);
> -		if (ret)
> -			goto out_flash_release;
> +		led->default_state = led_init_default_state_get(child);
>   
>   		if (reg == MT6360_VIRTUAL_MULTICOLOR ||
>   		    reg <= MT6360_LED_ISNKML)
diff mbox series

Patch

diff --git a/drivers/leds/flash/leds-mt6360.c b/drivers/leds/flash/leds-mt6360.c
index e1066a52d2d2..1af6c5898343 100644
--- a/drivers/leds/flash/leds-mt6360.c
+++ b/drivers/leds/flash/leds-mt6360.c
@@ -71,10 +71,6 @@  enum {
 #define MT6360_STRBTO_STEPUS		32000
 #define MT6360_STRBTO_MAXUS		2432000
 
-#define STATE_OFF			0
-#define STATE_KEEP			1
-#define STATE_ON			2
-
 struct mt6360_led {
 	union {
 		struct led_classdev isnk;
@@ -84,7 +80,7 @@  struct mt6360_led {
 	struct v4l2_flash *v4l2_flash;
 	struct mt6360_priv *priv;
 	u32 led_no;
-	u32 default_state;
+	enum led_default_state default_state;
 };
 
 struct mt6360_priv {
@@ -405,10 +401,10 @@  static int mt6360_isnk_init_default_state(struct mt6360_led *led)
 		level = LED_OFF;
 
 	switch (led->default_state) {
-	case STATE_ON:
+	case LEDS_DEFSTATE_ON:
 		led->isnk.brightness = led->isnk.max_brightness;
 		break;
-	case STATE_KEEP:
+	case LEDS_DEFSTATE_KEEP:
 		led->isnk.brightness = min(level, led->isnk.max_brightness);
 		break;
 	default:
@@ -443,10 +439,10 @@  static int mt6360_flash_init_default_state(struct mt6360_led *led)
 		level = LED_OFF;
 
 	switch (led->default_state) {
-	case STATE_ON:
+	case LEDS_DEFSTATE_ON:
 		flash->led_cdev.brightness = flash->led_cdev.max_brightness;
 		break;
-	case STATE_KEEP:
+	case LEDS_DEFSTATE_KEEP:
 		flash->led_cdev.brightness =
 			min(level, flash->led_cdev.max_brightness);
 		break;
@@ -760,25 +756,6 @@  static int mt6360_init_flash_properties(struct mt6360_led *led,
 	return 0;
 }
 
-static int mt6360_init_common_properties(struct mt6360_led *led,
-					 struct led_init_data *init_data)
-{
-	const char *const states[] = { "off", "keep", "on" };
-	const char *str;
-	int ret;
-
-	if (!fwnode_property_read_string(init_data->fwnode,
-					 "default-state", &str)) {
-		ret = match_string(states, ARRAY_SIZE(states), str);
-		if (ret < 0)
-			ret = STATE_OFF;
-
-		led->default_state = ret;
-	}
-
-	return 0;
-}
-
 static void mt6360_v4l2_flash_release(struct mt6360_priv *priv)
 {
 	int i;
@@ -852,10 +829,7 @@  static int mt6360_led_probe(struct platform_device *pdev)
 
 		led->led_no = reg;
 		led->priv = priv;
-
-		ret = mt6360_init_common_properties(led, &init_data);
-		if (ret)
-			goto out_flash_release;
+		led->default_state = led_init_default_state_get(child);
 
 		if (reg == MT6360_VIRTUAL_MULTICOLOR ||
 		    reg <= MT6360_LED_ISNKML)