@@ -27,11 +27,14 @@ static ssize_t brightness_show(struct device *dev,
27
27
struct device_attribute * attr , char * buf )
28
28
{
29
29
struct led_classdev * led_cdev = dev_get_drvdata (dev );
30
+ unsigned int brightness ;
30
31
31
- /* no lock needed for this */
32
+ mutex_lock ( & led_cdev -> led_access );
32
33
led_update_brightness (led_cdev );
34
+ brightness = led_cdev -> brightness ;
35
+ mutex_unlock (& led_cdev -> led_access );
33
36
34
- return sprintf (buf , "%u\n" , led_cdev -> brightness );
37
+ return sprintf (buf , "%u\n" , brightness );
35
38
}
36
39
37
40
static ssize_t brightness_store (struct device * dev ,
@@ -68,8 +71,13 @@ static ssize_t max_brightness_show(struct device *dev,
68
71
struct device_attribute * attr , char * buf )
69
72
{
70
73
struct led_classdev * led_cdev = dev_get_drvdata (dev );
74
+ unsigned int max_brightness ;
75
+
76
+ mutex_lock (& led_cdev -> led_access );
77
+ max_brightness = led_cdev -> max_brightness ;
78
+ mutex_unlock (& led_cdev -> led_access );
71
79
72
- return sprintf (buf , "%u\n" , led_cdev -> max_brightness );
80
+ return sprintf (buf , "%u\n" , max_brightness );
73
81
}
74
82
static DEVICE_ATTR_RO (max_brightness );
75
83
0 commit comments