As triggers are identified by name, two triggers must not share the same name. This is enforced at registration but must be done for renames, too. Fixes: a8df7b1ab70b ("leds: add led_trigger_rename function") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx> --- drivers/leds/led-triggers.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 431123b048a2..28e78697c63e 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -177,10 +177,21 @@ EXPORT_SYMBOL_GPL(led_trigger_set_default); void led_trigger_rename_static(const char *name, struct led_trigger *trig) { + 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); + + list_for_each_entry(_trig, &trigger_list, next_trig) { + if (!strcmp(_trig->name, name)) { + up_write(&triggers_list_lock); + pr_warning("Cannot rename trigger, new name already exists\n"); + return; + } + } + /* this assumes that trig->name was originaly allocated to * non constant storage */ strcpy((char *)trig->name, name); -- 2.17.0