Skip to content

Commit 249040d

Browse files
committed
backlight: Convert semaphore -> mutex
Convert internal semaphore to a mutex Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
1 parent 28ee086 commit 249040d

4 files changed

Lines changed: 37 additions & 37 deletions

File tree

‎drivers/video/backlight/backlight.c‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ static int fb_notifier_callback(struct notifier_block *self,
3232
return 0;
3333

3434
bd = container_of(self, struct backlight_device, fb_notif);
35-
down(&bd->sem);
35+
mutex_lock(&bd->props_lock);
3636
if (bd->props)
3737
if (!bd->props->check_fb ||
3838
bd->props->check_fb(evdata->info)) {
3939
bd->props->fb_blank = *(int *)evdata->data;
4040
backlight_update_status(bd);
4141
}
42-
up(&bd->sem);
42+
mutex_unlock(&bd->props_lock);
4343
return 0;
4444
}
4545

@@ -71,10 +71,10 @@ static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
7171
int rc = -ENXIO;
7272
struct backlight_device *bd = to_backlight_device(cdev);
7373

74-
down(&bd->sem);
74+
mutex_lock(&bd->props_lock);
7575
if (bd->props)
7676
rc = sprintf(buf, "%d\n", bd->props->power);
77-
up(&bd->sem);
77+
mutex_unlock(&bd->props_lock);
7878

7979
return rc;
8080
}
@@ -92,14 +92,14 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
9292
if (size != count)
9393
return -EINVAL;
9494

95-
down(&bd->sem);
95+
mutex_lock(&bd->props_lock);
9696
if (bd->props) {
9797
pr_debug("backlight: set power to %d\n", power);
9898
bd->props->power = power;
9999
backlight_update_status(bd);
100100
rc = count;
101101
}
102-
up(&bd->sem);
102+
mutex_unlock(&bd->props_lock);
103103

104104
return rc;
105105
}
@@ -109,10 +109,10 @@ static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
109109
int rc = -ENXIO;
110110
struct backlight_device *bd = to_backlight_device(cdev);
111111

112-
down(&bd->sem);
112+
mutex_lock(&bd->props_lock);
113113
if (bd->props)
114114
rc = sprintf(buf, "%d\n", bd->props->brightness);
115-
up(&bd->sem);
115+
mutex_unlock(&bd->props_lock);
116116

117117
return rc;
118118
}
@@ -130,7 +130,7 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
130130
if (size != count)
131131
return -EINVAL;
132132

133-
down(&bd->sem);
133+
mutex_lock(&bd->props_lock);
134134
if (bd->props) {
135135
if (brightness > bd->props->max_brightness)
136136
rc = -EINVAL;
@@ -142,7 +142,7 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
142142
rc = count;
143143
}
144144
}
145-
up(&bd->sem);
145+
mutex_unlock(&bd->props_lock);
146146

147147
return rc;
148148
}
@@ -152,10 +152,10 @@ static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *bu
152152
int rc = -ENXIO;
153153
struct backlight_device *bd = to_backlight_device(cdev);
154154

155-
down(&bd->sem);
155+
mutex_lock(&bd->props_lock);
156156
if (bd->props)
157157
rc = sprintf(buf, "%d\n", bd->props->max_brightness);
158-
up(&bd->sem);
158+
mutex_unlock(&bd->props_lock);
159159

160160
return rc;
161161
}
@@ -166,10 +166,10 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
166166
int rc = -ENXIO;
167167
struct backlight_device *bd = to_backlight_device(cdev);
168168

169-
down(&bd->sem);
169+
mutex_lock(&bd->props_lock);
170170
if (bd->props && bd->props->get_brightness)
171171
rc = sprintf(buf, "%d\n", bd->props->get_brightness(bd));
172-
up(&bd->sem);
172+
mutex_unlock(&bd->props_lock);
173173

174174
return rc;
175175
}
@@ -228,7 +228,7 @@ struct backlight_device *backlight_device_register(const char *name,
228228
return ERR_PTR(-ENOMEM);
229229

230230
mutex_init(&new_bd->update_lock);
231-
init_MUTEX(&new_bd->sem);
231+
mutex_init(&new_bd->props_lock);
232232
new_bd->props = bp;
233233
memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev));
234234
new_bd->class_dev.class = &backlight_class;
@@ -285,9 +285,9 @@ void backlight_device_unregister(struct backlight_device *bd)
285285
class_device_remove_file(&bd->class_dev,
286286
&bl_class_device_attributes[i]);
287287

288-
down(&bd->sem);
288+
mutex_lock(&bd->props_lock);
289289
bd->props = NULL;
290-
up(&bd->sem);
290+
mutex_unlock(&bd->props_lock);
291291

292292
backlight_unregister_fb(bd);
293293

‎drivers/video/backlight/lcd.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ static int fb_notifier_callback(struct notifier_block *self,
3131
return 0;
3232

3333
ld = container_of(self, struct lcd_device, fb_notif);
34-
down(&ld->sem);
34+
mutex_lock(&ld->props_lock);
3535
if (ld->props)
3636
if (!ld->props->check_fb || ld->props->check_fb(evdata->info))
3737
ld->props->set_power(ld, *(int *)evdata->data);
38-
up(&ld->sem);
38+
mutex_unlock(&ld->props_lock);
3939
return 0;
4040
}
4141

@@ -66,12 +66,12 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf)
6666
int rc;
6767
struct lcd_device *ld = to_lcd_device(cdev);
6868

69-
down(&ld->sem);
69+
mutex_lock(&ld->props_lock);
7070
if (ld->props && ld->props->get_power)
7171
rc = sprintf(buf, "%d\n", ld->props->get_power(ld));
7272
else
7373
rc = -ENXIO;
74-
up(&ld->sem);
74+
mutex_unlock(&ld->props_lock);
7575

7676
return rc;
7777
}
@@ -89,13 +89,13 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_
8989
if (size != count)
9090
return -EINVAL;
9191

92-
down(&ld->sem);
92+
mutex_lock(&ld->props_lock);
9393
if (ld->props && ld->props->set_power) {
9494
pr_debug("lcd: set power to %d\n", power);
9595
ld->props->set_power(ld, power);
9696
rc = count;
9797
}
98-
up(&ld->sem);
98+
mutex_unlock(&ld->props_lock);
9999

100100
return rc;
101101
}
@@ -105,10 +105,10 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf)
105105
int rc = -ENXIO;
106106
struct lcd_device *ld = to_lcd_device(cdev);
107107

108-
down(&ld->sem);
108+
mutex_lock(&ld->props_lock);
109109
if (ld->props && ld->props->get_contrast)
110110
rc = sprintf(buf, "%d\n", ld->props->get_contrast(ld));
111-
up(&ld->sem);
111+
mutex_unlock(&ld->props_lock);
112112

113113
return rc;
114114
}
@@ -126,13 +126,13 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si
126126
if (size != count)
127127
return -EINVAL;
128128

129-
down(&ld->sem);
129+
mutex_lock(&ld->props_lock);
130130
if (ld->props && ld->props->set_contrast) {
131131
pr_debug("lcd: set contrast to %d\n", contrast);
132132
ld->props->set_contrast(ld, contrast);
133133
rc = count;
134134
}
135-
up(&ld->sem);
135+
mutex_unlock(&ld->props_lock);
136136

137137
return rc;
138138
}
@@ -142,10 +142,10 @@ static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf)
142142
int rc = -ENXIO;
143143
struct lcd_device *ld = to_lcd_device(cdev);
144144

145-
down(&ld->sem);
145+
mutex_lock(&ld->props_lock);
146146
if (ld->props)
147147
rc = sprintf(buf, "%d\n", ld->props->max_contrast);
148-
up(&ld->sem);
148+
mutex_unlock(&ld->props_lock);
149149

150150
return rc;
151151
}
@@ -197,7 +197,7 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata,
197197
if (!new_ld)
198198
return ERR_PTR(-ENOMEM);
199199

200-
init_MUTEX(&new_ld->sem);
200+
mutex_init(&new_ld->props_lock);
201201
mutex_init(&new_ld->update_lock);
202202
new_ld->props = lp;
203203
memset(&new_ld->class_dev, 0, sizeof(new_ld->class_dev));
@@ -253,9 +253,9 @@ void lcd_device_unregister(struct lcd_device *ld)
253253
class_device_remove_file(&ld->class_dev,
254254
&lcd_class_device_attributes[i]);
255255

256-
down(&ld->sem);
256+
mutex_lock(&ld->props_lock);
257257
ld->props = NULL;
258-
up(&ld->sem);
258+
mutex_unlock(&ld->props_lock);
259259
lcd_unregister_fb(ld);
260260
class_device_unregister(&ld->class_dev);
261261
}

‎include/linux/backlight.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
/* Notes on locking:
1616
*
17-
* backlight_device->sem is an internal backlight lock protecting the props
18-
* field and no code outside the core should need to touch it.
17+
* backlight_device->props_lock is an internal backlight lock protecting the
18+
* props field and no code outside the core should need to touch it.
1919
*
2020
* Access to update_status() is serialised by the update_lock mutex since
2121
* most drivers seem to need this and historically get it wrong.
@@ -57,7 +57,7 @@ struct backlight_device {
5757
/* This protects the 'props' field. If 'props' is NULL, the driver that
5858
registered this device has been unloaded, and if class_get_devdata()
5959
points to something in the body of that driver, it is also invalid. */
60-
struct semaphore sem;
60+
struct mutex props_lock;
6161
/* If this is NULL, the backing module is unloaded */
6262
struct backlight_properties *props;
6363
/* Serialise access to update_status method */

‎include/linux/lcd.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/* Notes on locking:
1616
*
17-
* lcd_device->sem is an internal backlight lock protecting the props
17+
* lcd_device->props_lock is an internal backlight lock protecting the props
1818
* field and no code outside the core should need to touch it.
1919
*
2020
* Access to set_power() is serialised by the update_lock mutex since
@@ -52,7 +52,7 @@ struct lcd_device {
5252
/* This protects the 'props' field. If 'props' is NULL, the driver that
5353
registered this device has been unloaded, and if class_get_devdata()
5454
points to something in the body of that driver, it is also invalid. */
55-
struct semaphore sem;
55+
struct mutex props_lock;
5656
/* If this is NULL, the backing module is unloaded */
5757
struct lcd_properties *props;
5858
/* Serialise access to set_power method */

0 commit comments

Comments
 (0)