Commit a8df7b1ab70bfd6f261fa5e96985fca638299acc

Authored by Fabio Baltieri
Committed by Bryan Wu
1 parent 5cce0105c8

leds: add led_trigger_rename function

Implements a "led_trigger_rename" function to rename a trigger with
proper locking.

This assumes that led name was originally allocated in non-constant
storage.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
Cc: Kurt Van Dijck <kurt.van.dijck@eia.be>
Signed-off-by: Bryan Wu <cooloney@gmail.com>

Showing 2 changed files with 31 additions and 0 deletions Side-by-side Diff

drivers/leds/led-triggers.c
... ... @@ -166,6 +166,19 @@
166 166 }
167 167 EXPORT_SYMBOL_GPL(led_trigger_set_default);
168 168  
  169 +void led_trigger_rename_static(const char *name, struct led_trigger *trig)
  170 +{
  171 + /* new name must be on a temporary string to prevent races */
  172 + BUG_ON(name == trig->name);
  173 +
  174 + down_write(&triggers_list_lock);
  175 + /* this assumes that trig->name was originaly allocated to
  176 + * non constant storage */
  177 + strcpy((char *)trig->name, name);
  178 + up_write(&triggers_list_lock);
  179 +}
  180 +EXPORT_SYMBOL_GPL(led_trigger_rename_static);
  181 +
169 182 /* LED Trigger Interface */
170 183  
171 184 int led_trigger_register(struct led_trigger *trig)
include/linux/leds.h
... ... @@ -139,6 +139,24 @@
139 139 extern void led_set_brightness(struct led_classdev *led_cdev,
140 140 enum led_brightness brightness);
141 141  
  142 +/**
  143 + * led_trigger_rename_static - rename a trigger
  144 + * @name: the new trigger name
  145 + * @trig: the LED trigger to rename
  146 + *
  147 + * Change a LED trigger name by copying the string passed in
  148 + * name into current trigger name, which MUST be large
  149 + * enough for the new string.
  150 + *
  151 + * Note that name must NOT point to the same string used
  152 + * during LED registration, as that could lead to races.
  153 + *
  154 + * This is meant to be used on triggers with statically
  155 + * allocated name.
  156 + */
  157 +extern void led_trigger_rename_static(const char *name,
  158 + struct led_trigger *trig);
  159 +
142 160 /*
143 161 * LED Triggers
144 162 */