From 52c47742f79d9240f90af9a6722fe8bb3fa8c0f9 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 27 Aug 2012 09:31:49 +0800 Subject: [PATCH] leds: triggers: send uevent when changing triggers Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files. A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found. (bryan.wu@canonical.com: rename trigger to trig to fix the build error) Signed-off-by: Colin Cross Acked-by: Greg Kroah-Hartman Acked-by: Henrique de Moraes Holschuh Signed-off-by: Bryan Wu --- drivers/leds/led-triggers.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index b53bf54023f6..262eb4193710 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -102,6 +102,12 @@ EXPORT_SYMBOL_GPL(led_trigger_show); void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) { unsigned long flags; + char *event = NULL; + char *envp[2]; + const char *name; + + name = trig ? trig->name : "none"; + event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name); /* Remove any existing trigger */ if (led_cdev->trigger) { @@ -124,6 +130,13 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) if (trig->activate) trig->activate(led_cdev); } + + if (event) { + envp[0] = event; + envp[1] = NULL; + kobject_uevent_env(&led_cdev->dev->kobj, KOBJ_CHANGE, envp); + kfree(event); + } } EXPORT_SYMBOL_GPL(led_trigger_set);