[lkml]   [2015]   [Mar]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH v3] led/led-class: Handle LEDs with the same name
Hello Geert:

Thanks for your comments!

On Mon, Mar 30, 2015 at 9:59 AM, Geert Uytterhoeven
<> wrote:
> What's the maximum length of init_name?

It is "driver defined", this is why the initial patch used kasprintf,
but the Maintainer preferred to avoid the memory handling.

> strncpy() is _not_ guaranteed to zero-terminate the destination buffer.

Good catch. I will fix this.

> There are two ways to fix this:
> 1. Use strlcpy() instead of strncpy(),
> 2. Explicitly set name[len-1] to 0 after the call to strncpy().
> As we don't need the "security" feature of strncpy() that fills the remaining
> part of the buffer with zeroes, I think using strlcpy() is the best solution.
>> + while (class_find_device(leds_class, NULL, name, match_name))
>> + snprintf(name, len, "%s_%d", init_name, ++i);
> This will become an infinite loop once the resulting string no longer fits in
> the target buffer. Hence the loop should be terminated, and an error code
> should be returned, once snprintf() returns a value >= len.

Will send a patch right away. Thanks

>> +
>> + return i;
>> +}
> Gr{oetje,eeting}s,
> Geert
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 --
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds

Ricardo Ribalda

 \ /
  Last update: 2015-03-30 11:01    [W:0.271 / U:0.476 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site