linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fabio Baltieri <fabio.baltieri@gmail.com>
To: Bryan Wu <cooloney@gmail.com>
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	Richard Purdie <rpurdie@rpsys.net>,
	Kurt Van Dijck <kurt.van.dijck@eia.be>
Subject: Re: [PATCH v2 RESEND] leds: add led_trigger_rename function
Date: Wed, 14 Nov 2012 09:30:13 +0100	[thread overview]
Message-ID: <20121114083013.GA23881@gmail.com> (raw)
In-Reply-To: <CAK5ve-Jn_1Lc=FyX24_DHDz6+=VUC5xoiH4zUWLgRB=rgOiueA@mail.gmail.com>

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

  reply	other threads:[~2012-11-14  8:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-04  9:54 [PATCH v2 RESEND] leds: add led_trigger_rename function Fabio Baltieri
2012-11-14  0:33 ` Bryan Wu
2012-11-14  8:30   ` Fabio Baltieri [this message]
2012-11-15  0:13     ` Bryan Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121114083013.GA23881@gmail.com \
    --to=fabio.baltieri@gmail.com \
    --cc=cooloney@gmail.com \
    --cc=kurt.van.dijck@eia.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=rpurdie@rpsys.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).