[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20121114083013.GA23881@gmail.com>
Date: Wed, 14 Nov 2012 09:30:13 +0100
From: Fabio Baltieri <fabio.baltieri@...il.com>
To: Bryan Wu <cooloney@...il.com>
Cc: linux-leds@...r.kernel.org, linux-kernel@...r.kernel.org,
Richard Purdie <rpurdie@...ys.net>,
Kurt Van Dijck <kurt.van.dijck@....be>
Subject: Re: [PATCH v2 RESEND] leds: add led_trigger_rename function
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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists