leds: pca955x: Get rid of custom led_init_default_state_get()
PATCH 1/1 leds: pca955x: 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.
--- drivers/leds/leds-pca955x.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)
drivers/leds/leds-pca955x.c +6 -19
@@ -130,7 +130,7 @@ struct pca955x_led {struct led_classdev led_cdev;int led_num;/* 0 .. 15 potentially */ u32 type; -int default_state; +enum led_default_state default_state;struct fwnode_handle *fwnode; };
@@ -454,19 +454,9 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip) led = &pdata->leds[reg]; led->type =PCA955X_TYPE_LED ; led->fwnode = child; -fwnode_property_read_u32 (child,"type" , &led->type); + led->default_state =led_init_default_state_get (child); -if (!fwnode_property_read_string (child,"default-state" , - &state)) { -if (!strcmp (state,"keep" )) - led->default_state =LEDS_GPIO_DEFSTATE_KEEP ; -else if (!strcmp (state,"on" )) - led->default_state =LEDS_GPIO_DEFSTATE_ON ; -else - led->default_state =LEDS_GPIO_DEFSTATE_OFF ; - }else { - led->default_state =LEDS_GPIO_DEFSTATE_OFF ; - } +fwnode_property_read_u32 (child,"type" , &led->type); } pdata->num_leds = chip->bits;
@@ -578,13 +568,11 @@ static int pca955x_probe(struct i2c_client *client) led->brightness_set_blocking = pca955x_led_set; led->brightness_get = pca955x_led_get; -if (pdata->leds[i].default_state == -LEDS_GPIO_DEFSTATE_OFF ) { +if (pdata->leds[i].default_state ==LEDS_DEFSTATE_OFF ) { err =pca955x_led_set (led,LED_OFF );if (err)return err; - }else if (pdata->leds[i].default_state == -LEDS_GPIO_DEFSTATE_ON ) { + }else if (pdata->leds[i].default_state ==LEDS_DEFSTATE_ON ) { err =pca955x_led_set (led,LED_FULL );if (err)return err;
@@ -623,8 +611,7 @@ static int pca955x_probe(struct i2c_client *client)* brightness to see if it's using PWM1. If so, PWM1 * should not be written below. */ -if (pdata->leds[i].default_state == -LEDS_GPIO_DEFSTATE_KEEP ) { +if (pdata->leds[i].default_state ==LEDS_DEFSTATE_KEEP ) {if (led->brightness !=LED_FULL && led->brightness !=LED_OFF && led->brightness !=LED_HALF )
Signature · 1 line
2.35.1
kernel test robot
build botI love your patch! Yet something to improve:
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-pca955x-Get-rid-of-custom-led_init_default_state_get/20220803-052712 base: git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next config: x86_64-randconfig-a002-20220801 (https://download.01.org/0day-ci/archive/20220803/[email protected]/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/46936c7c7d9d52d3029e319fc78b727a9e0fc046
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Andy-Shevchenko/leds-pca955x-Get-rid-of-custom-led_init_default_state_get/20220803-052712 git checkout 46936c7c7d9d52d3029e319fc78b727a9e0fc046
# 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=x86_64 SHELL=/bin/bash drivers/leds/
If you fix the issue, kindly add following tag where applicable
All error/warnings (new ones prefixed by >>):
>> drivers/leds/leds-pca955x.c:457: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);
^
>> drivers/leds/leds-pca955x.c:446:15: warning: unused variable 'state' [-Wunused-variable]
const char *state;
^
drivers/leds/leds-pca955x.c:494:15: warning: cast to smaller integer type 'enum pca955x_type' from 'const void *' [-Wvoid-pointer-to-enum-cast]
chip_type = (enum pca955x_type)md;
^~~~~~~~~~~~~~~~~~~~~2 warnings and 1 error generated.
vim +/led_init_default_state_get +457 drivers/leds/leds-pca955x.c
422
423 static struct pca955x_platform_data *
424 pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
425 {
426 struct pca955x_platform_data *pdata;
427 struct pca955x_led *led;
428 struct fwnode_handle *child;
429 int count;
430
431 count = device_get_child_node_count(&client->dev);
432 if (count > chip->bits)
433 return ERR_PTR(-ENODEV);
434
435 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
436 if (!pdata)
437 return ERR_PTR(-ENOMEM);
438
439 pdata->leds = devm_kcalloc(&client->dev,
440 chip->bits, sizeof(struct pca955x_led),
441 GFP_KERNEL);
442 if (!pdata->leds)
443 return ERR_PTR(-ENOMEM);
444
445 device_for_each_child_node(&client->dev, child) {
> 446 const char *state; 447 u32 reg; 448 int res; 449 450 res = fwnode_property_read_u32(child, "reg", ®); 451 if ((res != 0) || (reg >= chip->bits)) 452 continue; 453 454 led = &pdata->leds[reg]; 455 led->type = PCA955X_TYPE_LED; 456 led->fwnode = child; > 457 led->default_state = led_init_default_state_get(child);
458
459 fwnode_property_read_u32(child, "type", &led->type);
460 }
461
462 pdata->num_leds = chip->bits;
463
464 return pdata;
465 }
466
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi Andy,
I love your patch! Perhaps something to improve:
[auto build test WARNING on pavel-leds/for-next]
[also build test WARNING 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-pca955x-Get-rid-of-custom-led_init_default_state_get/20220803-052712 base: git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220803/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-3) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/46936c7c7d9d52d3029e319fc78b727a9e0fc046 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Andy-Shevchenko/leds-pca955x-Get-rid-of-custom-led_init_default_state_get/20220803-052712 git checkout 46936c7c7d9d52d3029e319fc78b727a9e0fc046 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/leds/
If you fix the issue, kindly add following tag where applicable
All warnings (new ones prefixed by >>):
drivers/leds/leds-pca955x.c: In function 'pca955x_get_pdata':
drivers/leds/leds-pca955x.c:457:38: error: implicit declaration of function 'led_init_default_state_get'; did you mean 'led_get_default_pattern'? [-Werror=implicit-function-declaration]
457 | led->default_state = led_init_default_state_get(child);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
| led_get_default_pattern
>> drivers/leds/leds-pca955x.c:446:29: warning: unused variable 'state' [-Wunused-variable]
446 | const char *state;
| ^~~~~cc1: some warnings being treated as errors
vim +/state +446 drivers/leds/leds-pca955x.c
561099a1a2e992 Cédric Le Goater 2017-08-08 422ed1f4b9676a8eb Cédric Le Goater 2017-08-08 423 static struct pca955x_platform_data *967f69de81478c Andy Shevchenko 2019-03-25 424 pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 425 {
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 426 struct pca955x_platform_data *pdata;
2420ae02ce0a92 Eddie James 2021-07-16 427 struct pca955x_led *led;
967f69de81478c Andy Shevchenko 2019-03-25 428 struct fwnode_handle *child;
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 429 int count;
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 430
967f69de81478c Andy Shevchenko 2019-03-25 431 count = device_get_child_node_count(&client->dev);
e26557a0aa68ac Andrew Jeffery 2021-09-21 432 if (count > chip->bits)
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 433 return ERR_PTR(-ENODEV);
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 434
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 435 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 436 if (!pdata)
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 437 return ERR_PTR(-ENOMEM);
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 438
a86854d0c599b3 Kees Cook 2018-06-12 439 pdata->leds = devm_kcalloc(&client->dev,
a86854d0c599b3 Kees Cook 2018-06-12 440 chip->bits, sizeof(struct pca955x_led),
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 441 GFP_KERNEL);
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 442 if (!pdata->leds)
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 443 return ERR_PTR(-ENOMEM);
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 444
967f69de81478c Andy Shevchenko 2019-03-25 445 device_for_each_child_node(&client->dev, child) {
e46cb6d0c760a5 Eddie James 2021-07-16 @446 const char *state;
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 447 u32 reg;
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 448 int res;
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 449
967f69de81478c Andy Shevchenko 2019-03-25 450 res = fwnode_property_read_u32(child, "reg", ®);
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 451 if ((res != 0) || (reg >= chip->bits))
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 452 continue;
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 453
2420ae02ce0a92 Eddie James 2021-07-16 454 led = &pdata->leds[reg];
2420ae02ce0a92 Eddie James 2021-07-16 455 led->type = PCA955X_TYPE_LED;
7c4815929276b2 Eddie James 2021-07-16 456 led->fwnode = child;
46936c7c7d9d52 Andy Shevchenko 2022-08-03 457 led->default_state = led_init_default_state_get(child);
e46cb6d0c760a5 Eddie James 2021-07-16 458
46936c7c7d9d52 Andy Shevchenko 2022-08-03 459 fwnode_property_read_u32(child, "type", &led->type);
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 460 }
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 461
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 462 pdata->num_leds = chip->bits;
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 463
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 464 return pdata;
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 465 }
ed1f4b9676a8eb Cédric Le Goater 2017-08-08 466 Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp