leds: Fix trigger registration race
Fix a race during trigger registration where we could try and use a lock
before it was initialised.
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 5db86c2..6c4a326 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -110,6 +110,9 @@
if (rc)
goto err_out;
+#ifdef CONFIG_LEDS_TRIGGERS
+ init_rwsem(&led_cdev->trigger_lock);
+#endif
/* add to the list of leds */
down_write(&leds_list_lock);
list_add_tail(&led_cdev->node, &leds_list);
@@ -118,8 +121,6 @@
led_update_brightness(led_cdev);
#ifdef CONFIG_LEDS_TRIGGERS
- init_rwsem(&led_cdev->trigger_lock);
-
rc = device_create_file(led_cdev->dev, &dev_attr_trigger);
if (rc)
goto err_out_led_list;