Re: [PATCH v2 RESEND] leds: add led_trigger_rename function
From: Fabio Baltieri
Date: Wed Nov 14 2012 - 03:30:08 EST
Hi Bryan,
On Tue, Nov 13, 2012 at 04:33:14PM -0800, Bryan Wu wrote:
> > +void led_trigger_rename_static(const char *name, struct led_trigger *trig)
> > +{
> > + /* new name must be on a temporary string to prevent races */
> > + BUG_ON(name == trig->name);
> > +
> > + down_write(&triggers_list_lock);
> > + /* this assumes that trig->name was originaly allocated to
> > + * non constant storage */
> > + strcpy((char *)trig->name, name);
>
> Is this strcpy() safe here? Probably strncpy() or strlcpy() is safer.
Actually the LED subsystem is not aware of the string allocation size,
so I guess that strcpy is the only option here.
On the other side, the caller, who originally allocated the string,
should do the check properly, such as in:
snprintf(name, sizeof(name), "%s-tx", netdev->name);
led_trigger_rename_static(name, priv->tx_led_trig);
> > +extern void led_trigger_rename_static(const char *name,
> > + struct led_trigger *trig);
> > +
>
> Any example how to use this new API?
Sure! That was developed as part of CANBUS LED triggers to have trigger
name follow can interfaces name changes.
Original patch using this function, including the whole discussion
behind it, was posted here:
https://lkml.org/lkml/2012/9/10/544
or you can find the complete set on my github branch:
http://github.com/fabiobaltieri/linux.git can-leds-devel
Fabio
--
Fabio Baltieri
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/