mbox series

[leds,v3,0/9] Start moving parsing of `linux,default-trigger` to LED core (a cleanup of LED drivers)

Message ID 20200919180304.2885-1-marek.behun@nic.cz
Headers show
Series Start moving parsing of `linux,default-trigger` to LED core (a cleanup of LED drivers) | expand

Message

Marek Behún Sept. 19, 2020, 6:02 p.m. UTC
Hi Pavel,

this is v3, on top of your current for-next branch.

Changes:
- lm36274 again with the use-after-free issue you mentioned solved
- lm3532 does not need to parse `label` since it uses init_data
- leds-syscon can also use init_data by simple change
- the last patch, which moves parsing of `linux,default-trigger`, is now
  compatible with current version of the patches

Marek

Marek Behún (9):
  leds: lm36274: cosmetic: rename lm36274_data to chip
  leds: lm36274: don't iterate through children since there is only one
  leds: lm36274: use struct led_init_data when registering
  leds: lm36274: do not set chip settings in DT parsing function
  leds: lm36274: use platform device as parent of LED
  leds: lm36274: use devres LED registering function
  leds: lm3532: don't parse label DT property
  leds: syscon: use struct led_init_data when registering
  leds: parse linux,default-trigger DT property in LED core

 drivers/leds/led-class.c         |   5 ++
 drivers/leds/leds-an30259a.c     |   3 -
 drivers/leds/leds-aw2013.c       |   3 -
 drivers/leds/leds-bcm6328.c      |   4 -
 drivers/leds/leds-bcm6358.c      |   4 -
 drivers/leds/leds-cr0014114.c    |   3 -
 drivers/leds/leds-el15203000.c   |   3 -
 drivers/leds/leds-gpio.c         |   3 -
 drivers/leds/leds-is31fl32xx.c   |   3 -
 drivers/leds/leds-lm3532.c       |  15 ----
 drivers/leds/leds-lm36274.c      | 128 ++++++++++++++-----------------
 drivers/leds/leds-lm3692x.c      |   3 -
 drivers/leds/leds-lm3697.c       |   3 -
 drivers/leds/leds-lp50xx.c       |   3 -
 drivers/leds/leds-lp8860.c       |   4 -
 drivers/leds/leds-lt3593.c       |   3 -
 drivers/leds/leds-max77650.c     |   3 -
 drivers/leds/leds-mt6323.c       |   4 -
 drivers/leds/leds-ns2.c          |   3 -
 drivers/leds/leds-pm8058.c       |   2 -
 drivers/leds/leds-pwm.c          |   5 --
 drivers/leds/leds-syscon.c       |   9 +--
 drivers/leds/leds-tlc591xx.c     |   3 -
 drivers/leds/leds-turris-omnia.c |   2 -
 24 files changed, 68 insertions(+), 153 deletions(-)


base-commit: a0e550dc351ab5fabe8ea86e45b974494a0a6bf8

Comments

Dan Murphy Sept. 22, 2020, 3:42 p.m. UTC | #1
Hello

On 9/19/20 1:02 PM, Marek Behún wrote:
> Do not use device_for_each_child_node. Since this driver works only with
> once child node present, use device_get_next_child_node instead.
> This also saves one level of indentation.
>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>
> Cc: Dan Murphy <dmurphy@ti.com>
> ---
>   drivers/leds/leds-lm36274.c | 50 +++++++++++++++++--------------------
>   1 file changed, 23 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
> index 4a9f786bb9727..e0fce74a76675 100644
> --- a/drivers/leds/leds-lm36274.c
> +++ b/drivers/leds/leds-lm36274.c
> @@ -72,40 +72,36 @@ static int lm36274_parse_dt(struct lm36274 *chip)
>   	char label[LED_MAX_NAME_SIZE];
>   	struct device *dev = &chip->pdev->dev;
>   	const char *name;
> -	int child_cnt;
> -	int ret = -EINVAL;
> +	int ret;
>   
>   	/* There should only be 1 node */
> -	child_cnt = device_get_child_node_count(dev);
> -	if (child_cnt != 1)
> +	if (device_get_child_node_count(dev) != 1)
>   		return -EINVAL;
>   
> -	device_for_each_child_node(dev, child) {
> -		ret = fwnode_property_read_string(child, "label", &name);
> -		if (ret)
> -			snprintf(label, sizeof(label), "%s::",
> -				 chip->pdev->name);
> -		else
> -			snprintf(label, sizeof(label), "%s:%s",
> -				 chip->pdev->name, name);
> -
> -		chip->num_leds = fwnode_property_count_u32(child, "led-sources");
> -		if (chip->num_leds <= 0)
> -			return -ENODEV;
> -
> -		ret = fwnode_property_read_u32_array(child, "led-sources",
> -						     chip->led_sources,
> -						     chip->num_leds);
> -		if (ret) {
> -			dev_err(dev, "led-sources property missing\n");
> -			return ret;
> -		}
> -
> -		fwnode_property_read_string(child, "linux,default-trigger",
> -					    &chip->led_dev.default_trigger);
> +	child = device_get_next_child_node(dev, NULL);
> +
> +	ret = fwnode_property_read_string(child, "label", &name);
> +	if (ret)
> +		snprintf(label, sizeof(label), "%s::", chip->pdev->name);
> +	else
> +		snprintf(label, sizeof(label), "%s:%s", chip->pdev->name, name);
>   
> +	chip->num_leds = fwnode_property_count_u32(child, "led-sources");
> +	if (chip->num_leds <= 0)
> +		return -ENODEV;
> +
> +	ret = fwnode_property_read_u32_array(child, "led-sources",
> +					     chip->led_sources, chip->num_leds);
> +	if (ret) {
> +		dev_err(dev, "led-sources property missing\n");
> +		return ret;
>   	}
>   
> +	fwnode_property_read_string(child, "linux,default-trigger",
> +				    &chip->led_dev.default_trigger);
> +
> +	fwnode_handle_put(child);
> +
>   	chip->lmu_data.regmap = chip->regmap;
>   	chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
>   	chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;

Question is this device on a piece of hardware you are testing on?

Just wondering how you functionally tested all these changes you submitted

Reviewed-by: Dan Murphy <dmurphy@ti.com>
Marek Behún Sept. 22, 2020, 3:58 p.m. UTC | #2
On Tue, 22 Sep 2020 10:42:49 -0500
Dan Murphy <dmurphy@ti.com> wrote:

> Hello
> 
> On 9/19/20 1:02 PM, Marek Behún wrote:
> > Do not use device_for_each_child_node. Since this driver works only with
> > once child node present, use device_get_next_child_node instead.
> > This also saves one level of indentation.
> >
> > Signed-off-by: Marek Behún <marek.behun@nic.cz>
> > Cc: Dan Murphy <dmurphy@ti.com>
> > ---
> >   drivers/leds/leds-lm36274.c | 50 +++++++++++++++++--------------------
> >   1 file changed, 23 insertions(+), 27 deletions(-)
> >
> > diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
> > index 4a9f786bb9727..e0fce74a76675 100644
> > --- a/drivers/leds/leds-lm36274.c
> > +++ b/drivers/leds/leds-lm36274.c
> > @@ -72,40 +72,36 @@ static int lm36274_parse_dt(struct lm36274 *chip)
> >   	char label[LED_MAX_NAME_SIZE];
> >   	struct device *dev = &chip->pdev->dev;
> >   	const char *name;
> > -	int child_cnt;
> > -	int ret = -EINVAL;
> > +	int ret;
> >   
> >   	/* There should only be 1 node */
> > -	child_cnt = device_get_child_node_count(dev);
> > -	if (child_cnt != 1)
> > +	if (device_get_child_node_count(dev) != 1)
> >   		return -EINVAL;
> >   
> > -	device_for_each_child_node(dev, child) {
> > -		ret = fwnode_property_read_string(child, "label", &name);
> > -		if (ret)
> > -			snprintf(label, sizeof(label), "%s::",
> > -				 chip->pdev->name);
> > -		else
> > -			snprintf(label, sizeof(label), "%s:%s",
> > -				 chip->pdev->name, name);
> > -
> > -		chip->num_leds = fwnode_property_count_u32(child, "led-sources");
> > -		if (chip->num_leds <= 0)
> > -			return -ENODEV;
> > -
> > -		ret = fwnode_property_read_u32_array(child, "led-sources",
> > -						     chip->led_sources,
> > -						     chip->num_leds);
> > -		if (ret) {
> > -			dev_err(dev, "led-sources property missing\n");
> > -			return ret;
> > -		}
> > -
> > -		fwnode_property_read_string(child, "linux,default-trigger",
> > -					    &chip->led_dev.default_trigger);
> > +	child = device_get_next_child_node(dev, NULL);
> > +
> > +	ret = fwnode_property_read_string(child, "label", &name);
> > +	if (ret)
> > +		snprintf(label, sizeof(label), "%s::", chip->pdev->name);
> > +	else
> > +		snprintf(label, sizeof(label), "%s:%s", chip->pdev->name, name);
> >   
> > +	chip->num_leds = fwnode_property_count_u32(child, "led-sources");
> > +	if (chip->num_leds <= 0)
> > +		return -ENODEV;
> > +
> > +	ret = fwnode_property_read_u32_array(child, "led-sources",
> > +					     chip->led_sources, chip->num_leds);
> > +	if (ret) {
> > +		dev_err(dev, "led-sources property missing\n");
> > +		return ret;
> >   	}
> >   
> > +	fwnode_property_read_string(child, "linux,default-trigger",
> > +				    &chip->led_dev.default_trigger);
> > +
> > +	fwnode_handle_put(child);
> > +
> >   	chip->lmu_data.regmap = chip->regmap;
> >   	chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
> >   	chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;  
> 
> Question is this device on a piece of hardware you are testing on?

No, unfortunately. But this driver is rather simple, in comparison to
the others.

As Linus said:
  "If it compiles, it is good; if it boots up, it is perfect."
:D

So if someone tested it, it would be perfect.

Marek

> Just wondering how you functionally tested all these changes you submitted
> 
> Reviewed-by: Dan Murphy <dmurphy@ti.com>
>
Dan Murphy Sept. 22, 2020, 7:12 p.m. UTC | #3
Marek

On 9/22/20 10:58 AM, Marek Behun wrote:
> On Tue, 22 Sep 2020 10:42:49 -0500

> Dan Murphy <dmurphy@ti.com> wrote:

>

>> <snip>

>> Question is this device on a piece of hardware you are testing on?

> No, unfortunately. But this driver is rather simple, in comparison to

> the others.

>

> As Linus said:

>    "If it compiles, it is good; if it boots up, it is perfect."

> :D

>

> So if someone tested it, it would be perfect.


Not sure how a comment made in 1998 applies to the state of the kernel 
today.

With this much change to the driver there should have been some level of 
functional testing.

So I pulled out my hardware and gave it a whirl. Gave my TB on the 
LM36274 patches.

Dan
Linus Walleij Sept. 29, 2020, 1:17 p.m. UTC | #4
On Sat, Sep 19, 2020 at 8:03 PM Marek Behún <marek.behun@nic.cz> wrote:

> By using struct led_init_data when registering we do not need to parse
> `label` DT property. Moreover `label` is deprecated and if it is not
> present but `color` and `function` are, LED core will compose a name
> from these properties instead.
>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>
> Cc: Linus Walleij <linus.walleij@linaro.org>

Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij