[v2] leds: pca955x: Allow platform datato set full name

Message ID 20210603081841.208639-1-joel@jms.id.au
State New
Headers show
Series
  • [v2] leds: pca955x: Allow platform datato set full name
Related show

Commit Message

Joel Stanley June 3, 2021, 8:18 a.m.
The PCA955x driver since it was merged has added a "pca955x:" prefix to
LED names. This meanas platform data (such as the device tree) cannot
fully control the name. Here's what this produces using the example in
the device tree bindings:

 # ls /sys/class/leds/
 pca955x:green:power/
 pca955x:pca9552:white/
 pca955x:pca9552:yellow/
 pca955x:red:power/

Instead use the platform data when provided to name the LED device.

Signed-off-by: Joel Stanley <joel@jms.id.au>

---
v2: Drop kconfig option, per Pavel's review:

 > No. Config option is not acceptable for this.

 >

 > Just delete the prefix and fix the breakage.


 drivers/leds/leds-pca955x.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

-- 
2.30.2

Comments

Andy Shevchenko June 3, 2021, 8:33 a.m. | #1
On Thu, Jun 3, 2021 at 11:20 AM Joel Stanley <joel@jms.id.au> wrote:
>

> The PCA955x driver since it was merged has added a "pca955x:" prefix to

> LED names. This meanas platform data (such as the device tree) cannot


means

(Also missed space in the subject line)

> fully control the name.


So, it controls the main part of it.

> Here's what this produces using the example in

> the device tree bindings:

>

>  # ls /sys/class/leds/

>  pca955x:green:power/

>  pca955x:pca9552:white/

>  pca955x:pca9552:yellow/

>  pca955x:red:power/


So, it means that example is broken, right?

> Instead use the platform data when provided to name the LED device.

>

> Signed-off-by: Joel Stanley <joel@jms.id.au>

> ---

> v2: Drop kconfig option, per Pavel's review:

>

>  > No. Config option is not acceptable for this.

>  >

>  > Just delete the prefix and fix the breakage.


I do not think we have a breakage here, rather a documentation issue.

...

> -                       snprintf(pca955x_led->name,

> -                               sizeof(pca955x_led->name), "pca955x:%s",

> -                               pdata->leds[i].name);

> +                       strscpy(pca955x_led->name,

> +                               pdata->leds[i].name,

> +                               sizeof(pca955x_led->name));


Changing to strspy() will become inconsistent with what's done in
pca955x_get_pdata().

-- 
With Best Regards,
Andy Shevchenko

Patch

diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
index 7087ca4592fc..4c5cc62c107a 100644
--- a/drivers/leds/leds-pca955x.c
+++ b/drivers/leds/leds-pca955x.c
@@ -503,9 +503,9 @@  static int pca955x_probe(struct i2c_client *client,
 				snprintf(pdata->leds[i].name,
 					sizeof(pdata->leds[i].name), "%d", i);
 
-			snprintf(pca955x_led->name,
-				sizeof(pca955x_led->name), "pca955x:%s",
-				pdata->leds[i].name);
+			strscpy(pca955x_led->name,
+				pdata->leds[i].name,
+				sizeof(pca955x_led->name));
 
 			if (pdata->leds[i].default_trigger)
 				pca955x_led->led_cdev.default_trigger =