All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] leds: start numerating duplicated devices from 2
@ 2015-03-26 14:59 Jacek Anaszewski
  2015-03-26 18:15 ` Bryan Wu
  0 siblings, 1 reply; 4+ messages in thread
From: Jacek Anaszewski @ 2015-03-26 14:59 UTC (permalink / raw)
  To: linux-leds
  Cc: Jacek Anaszewski, Bryan Wu, Richard Purdie,
	Ricardo Ribalda Delgado, Sakari Ailus

Duplicated devices are currently given numerical suffixes
starting from 1. Since duplication means that one instance
of a device already exists in the system, then it is more
intuitive for the next device to get the suffix "_2".

Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Bryan Wu <cooloney@gmail.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/leds/led-class.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 4ca37b8..07fcb35 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -222,14 +222,14 @@ static int match_name(struct device *dev, const void *data)
 static int led_classdev_next_name(const char *init_name, char *name,
 				  size_t len)
 {
-	int i = 0;
+	int i = 1;
 
 	strncpy(name, init_name, len);
 
 	while (class_find_device(leds_class, NULL, name, match_name))
 		snprintf(name, len, "%s_%d", init_name, ++i);
 
-	return i;
+	return i > 1 ? i : 0;
 }
 
 /**
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] leds: start numerating duplicated devices from 2
  2015-03-26 14:59 [PATCH v2] leds: start numerating duplicated devices from 2 Jacek Anaszewski
@ 2015-03-26 18:15 ` Bryan Wu
  2015-03-27  7:51   ` Ricardo Ribalda Delgado
  2015-03-27  8:01   ` Jacek Anaszewski
  0 siblings, 2 replies; 4+ messages in thread
From: Bryan Wu @ 2015-03-26 18:15 UTC (permalink / raw)
  To: Jacek Anaszewski
  Cc: Linux LED Subsystem, Richard Purdie, Ricardo Ribalda Delgado,
	Sakari Ailus

On Thu, Mar 26, 2015 at 7:59 AM, Jacek Anaszewski
<j.anaszewski@samsung.com> wrote:
> Duplicated devices are currently given numerical suffixes
> starting from 1. Since duplication means that one instance
> of a device already exists in the system, then it is more
> intuitive for the next device to get the suffix "_2".
>

No, I prefer to "_1" since normally we treat the first one "_0" or
empty. But I suggest we add the "_0" for the first new device then the
second one will be "_1"

Thanks,
-Bryan

> Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
> Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Bryan Wu <cooloney@gmail.com>
> Cc: Richard Purdie <rpurdie@rpsys.net>
> Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> Cc: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/leds/led-class.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index 4ca37b8..07fcb35 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -222,14 +222,14 @@ static int match_name(struct device *dev, const void *data)
>  static int led_classdev_next_name(const char *init_name, char *name,
>                                   size_t len)
>  {
> -       int i = 0;
> +       int i = 1;
>
>         strncpy(name, init_name, len);
>
>         while (class_find_device(leds_class, NULL, name, match_name))
>                 snprintf(name, len, "%s_%d", init_name, ++i);
>
> -       return i;
> +       return i > 1 ? i : 0;
>  }
>
>  /**
> --
> 1.7.9.5
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] leds: start numerating duplicated devices from 2
  2015-03-26 18:15 ` Bryan Wu
@ 2015-03-27  7:51   ` Ricardo Ribalda Delgado
  2015-03-27  8:01   ` Jacek Anaszewski
  1 sibling, 0 replies; 4+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-03-27  7:51 UTC (permalink / raw)
  To: Bryan Wu
  Cc: Jacek Anaszewski, Linux LED Subsystem, Richard Purdie, Sakari Ailus

Hello Bryan

On Thu, Mar 26, 2015 at 7:15 PM, Bryan Wu <cooloney@gmail.com> wrote:
> No, I prefer to "_1" since normally we treat the first one "_0" or
> empty. But I suggest we add the "_0" for the first new device then the
> second one will be "_1"

Wouldn't that break the userspace API? perhaps there is a script/app
is using the legacy name.

What about leaving the legacy file, but adding a symbolic link from
name_0 to name?

Regards!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] leds: start numerating duplicated devices from 2
  2015-03-26 18:15 ` Bryan Wu
  2015-03-27  7:51   ` Ricardo Ribalda Delgado
@ 2015-03-27  8:01   ` Jacek Anaszewski
  1 sibling, 0 replies; 4+ messages in thread
From: Jacek Anaszewski @ 2015-03-27  8:01 UTC (permalink / raw)
  To: Bryan Wu
  Cc: Linux LED Subsystem, Richard Purdie, Ricardo Ribalda Delgado,
	Sakari Ailus

On 03/26/2015 07:15 PM, Bryan Wu wrote:
> On Thu, Mar 26, 2015 at 7:59 AM, Jacek Anaszewski
> <j.anaszewski@samsung.com> wrote:
>> Duplicated devices are currently given numerical suffixes
>> starting from 1. Since duplication means that one instance
>> of a device already exists in the system, then it is more
>> intuitive for the next device to get the suffix "_2".
>>
>
> No, I prefer to "_1" since normally we treat the first one "_0" or
> empty.

OK, I can live with that :)

> But I suggest we add the "_0" for the first new device then the
> second one will be "_1"

If we changed naming for the device probed as the first one, then
we could break some existing user space applications.

I think that most of time there won't be any device with automagically
added numerical suffix in the LED subsystem, provided that the user
will get acquainted with the DT common leds documentation and will
define labels with different names.

The only case when adding the suffix can't be avoided is the one with
DT overlays.

Adding the suffix should be considered rather a countermeasure than
a convention.


>> Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
>> Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
>> Cc: Bryan Wu <cooloney@gmail.com>
>> Cc: Richard Purdie <rpurdie@rpsys.net>
>> Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
>> Cc: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>   drivers/leds/led-class.c |    4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
>> index 4ca37b8..07fcb35 100644
>> --- a/drivers/leds/led-class.c
>> +++ b/drivers/leds/led-class.c
>> @@ -222,14 +222,14 @@ static int match_name(struct device *dev, const void *data)
>>   static int led_classdev_next_name(const char *init_name, char *name,
>>                                    size_t len)
>>   {
>> -       int i = 0;
>> +       int i = 1;
>>
>>          strncpy(name, init_name, len);
>>
>>          while (class_find_device(leds_class, NULL, name, match_name))
>>                  snprintf(name, len, "%s_%d", init_name, ++i);
>>
>> -       return i;
>> +       return i > 1 ? i : 0;
>>   }
>>
>>   /**
>> --
>> 1.7.9.5
>>
>


-- 
Best Regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-03-27  8:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26 14:59 [PATCH v2] leds: start numerating duplicated devices from 2 Jacek Anaszewski
2015-03-26 18:15 ` Bryan Wu
2015-03-27  7:51   ` Ricardo Ribalda Delgado
2015-03-27  8:01   ` Jacek Anaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.