leds: Fix trigger registration race
authorRichard Purdie <rpurdie@linux.intel.com>
Mon, 20 Oct 2008 22:16:17 +0000 (23:16 +0100)
committerRichard Purdie <rpurdie@linux.intel.com>
Mon, 20 Oct 2008 22:21:08 +0000 (23:21 +0100)
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>
drivers/leds/led-class.c

index 5db86c29fe6125cdfd35be17f85af403479c8f97..6c4a326176d7be57d724d994a7ff5e971f50dc93 100644 (file)
@@ -110,6 +110,9 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
        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 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
        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;