Skip to content

Commit 28ee086

Browse files
committed
backlight: Fix external uses of backlight internal semaphore
backlight_device->sem has a very specific use as documented in the header file. The external users of this are using it for a different reason, to serialise access to the update_status() method. backlight users were supposed to implement their own internal serialisation of update_status() if needed but everyone is doing things differently and incorrectly. Therefore add a global mutex to take care of serialisation for everyone, once and for all. Locking for get_brightness remains optional since most users don't need it. Also update the lcd class in a similar way. Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
1 parent a8db3c1 commit 28ee086

15 files changed

Lines changed: 76 additions & 76 deletions

File tree

‎arch/powerpc/kernel/traps.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,10 @@ int die(const char *str, struct pt_regs *regs, long err)
107107
if (machine_is(powermac) && pmac_backlight) {
108108
struct backlight_properties *props;
109109

110-
down(&pmac_backlight->sem);
111110
props = pmac_backlight->props;
112111
props->brightness = props->max_brightness;
113112
props->power = FB_BLANK_UNBLANK;
114-
props->update_status(pmac_backlight);
115-
up(&pmac_backlight->sem);
113+
backlight_update_status(pmac_backlight);
116114
}
117115
mutex_unlock(&pmac_backlight_mutex);
118116
#endif

‎arch/powerpc/platforms/powermac/backlight.c‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ static int pmac_backlight_set_legacy_queued;
3737
*/
3838
static atomic_t kernel_backlight_disabled = ATOMIC_INIT(0);
3939

40-
/* Protect the pmac_backlight variable */
40+
/* Protect the pmac_backlight variable below.
41+
You should hold this lock when using the pmac_backlight pointer to
42+
prevent its potential removal. */
4143
DEFINE_MUTEX(pmac_backlight_mutex);
4244

4345
/* Main backlight storage
@@ -49,9 +51,6 @@ DEFINE_MUTEX(pmac_backlight_mutex);
4951
* internal display, it doesn't matter. Other backlight drivers can be used
5052
* independently.
5153
*
52-
* Lock ordering:
53-
* pmac_backlight_mutex (global, main backlight)
54-
* pmac_backlight->sem (backlight class)
5554
*/
5655
struct backlight_device *pmac_backlight;
5756

@@ -104,7 +103,6 @@ static void pmac_backlight_key_worker(struct work_struct *work)
104103
struct backlight_properties *props;
105104
int brightness;
106105

107-
down(&pmac_backlight->sem);
108106
props = pmac_backlight->props;
109107

110108
brightness = props->brightness +
@@ -117,9 +115,7 @@ static void pmac_backlight_key_worker(struct work_struct *work)
117115
brightness = props->max_brightness;
118116

119117
props->brightness = brightness;
120-
props->update_status(pmac_backlight);
121-
122-
up(&pmac_backlight->sem);
118+
backlight_update_status(pmac_backlight);
123119
}
124120
mutex_unlock(&pmac_backlight_mutex);
125121
}
@@ -145,7 +141,6 @@ static int __pmac_backlight_set_legacy_brightness(int brightness)
145141
if (pmac_backlight) {
146142
struct backlight_properties *props;
147143

148-
down(&pmac_backlight->sem);
149144
props = pmac_backlight->props;
150145
props->brightness = brightness *
151146
(props->max_brightness + 1) /
@@ -156,8 +151,7 @@ static int __pmac_backlight_set_legacy_brightness(int brightness)
156151
else if (props->brightness < 0)
157152
props->brightness = 0;
158153

159-
props->update_status(pmac_backlight);
160-
up(&pmac_backlight->sem);
154+
backlight_update_status(pmac_backlight);
161155

162156
error = 0;
163157
}
@@ -196,14 +190,11 @@ int pmac_backlight_get_legacy_brightness()
196190
if (pmac_backlight) {
197191
struct backlight_properties *props;
198192

199-
down(&pmac_backlight->sem);
200193
props = pmac_backlight->props;
201194

202195
result = props->brightness *
203196
(OLD_BACKLIGHT_MAX + 1) /
204197
(props->max_brightness + 1);
205-
206-
up(&pmac_backlight->sem);
207198
}
208199
mutex_unlock(&pmac_backlight_mutex);
209200

‎drivers/macintosh/via-pmu-backlight.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,9 @@ void __init pmu_backlight_init()
166166
pmu_backlight_data.max_brightness / 15);
167167
}
168168

169-
down(&bd->sem);
170169
bd->props->brightness = level;
171170
bd->props->power = FB_BLANK_UNBLANK;
172-
bd->props->update_status(bd);
173-
up(&bd->sem);
171+
backlight_update_status(bd);
174172

175173
mutex_lock(&pmac_backlight_mutex);
176174
if (!pmac_backlight)

‎drivers/misc/asus-laptop.c‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,8 @@ static void lcd_blank(int blank)
348348
struct backlight_device *bd = asus_backlight_device;
349349

350350
if (bd) {
351-
down(&bd->sem);
352-
if (likely(bd->props)) {
353-
bd->props->power = blank;
354-
if (likely(bd->props->update_status))
355-
bd->props->update_status(bd);
356-
}
357-
up(&bd->sem);
351+
bd->props->power = blank;
352+
backlight_update_status(bd);
358353
}
359354
}
360355

@@ -1028,14 +1023,9 @@ static int asus_backlight_init(struct device *dev)
10281023

10291024
asus_backlight_device = bd;
10301025

1031-
down(&bd->sem);
1032-
if (likely(bd->props)) {
1033-
bd->props->brightness = read_brightness(NULL);
1034-
bd->props->power = FB_BLANK_UNBLANK;
1035-
if (likely(bd->props->update_status))
1036-
bd->props->update_status(bd);
1037-
}
1038-
up(&bd->sem);
1026+
bd->props->brightness = read_brightness(NULL);
1027+
bd->props->power = FB_BLANK_UNBLANK;
1028+
backlight_update_status(bd);
10391029
}
10401030
return 0;
10411031
}

‎drivers/usb/misc/appledisplay.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,9 @@ static void appledisplay_work(struct work_struct *work)
189189
container_of(work, struct appledisplay, work.work);
190190
int retval;
191191

192-
up(&pdata->bd->sem);
193192
retval = appledisplay_bl_get_brightness(pdata->bd);
194193
if (retval >= 0)
195194
pdata->bd->props->brightness = retval;
196-
down(&pdata->bd->sem);
197195

198196
/* Poll again in about 125ms if there's still a button pressed */
199197
if (pdata->button_pressed)
@@ -288,9 +286,7 @@ static int appledisplay_probe(struct usb_interface *iface,
288286
}
289287

290288
/* Try to get brightness */
291-
up(&pdata->bd->sem);
292289
brightness = appledisplay_bl_get_brightness(pdata->bd);
293-
down(&pdata->bd->sem);
294290

295291
if (brightness < 0) {
296292
retval = brightness;
@@ -299,9 +295,7 @@ static int appledisplay_probe(struct usb_interface *iface,
299295
}
300296

301297
/* Set brightness in backlight device */
302-
up(&pdata->bd->sem);
303298
pdata->bd->props->brightness = brightness;
304-
down(&pdata->bd->sem);
305299

306300
/* save our data pointer in the interface device */
307301
usb_set_intfdata(iface, pdata);

‎drivers/video/aty/aty128fb.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,10 +1807,8 @@ static void aty128_bl_set_power(struct fb_info *info, int power)
18071807
mutex_lock(&info->bl_mutex);
18081808

18091809
if (info->bl_dev) {
1810-
down(&info->bl_dev->sem);
18111810
info->bl_dev->props->power = power;
18121811
__aty128_bl_update_status(info->bl_dev);
1813-
up(&info->bl_dev->sem);
18141812
}
18151813

18161814
mutex_unlock(&info->bl_mutex);
@@ -1847,11 +1845,9 @@ static void aty128_bl_init(struct aty128fb_par *par)
18471845
219 * FB_BACKLIGHT_MAX / MAX_LEVEL);
18481846
mutex_unlock(&info->bl_mutex);
18491847

1850-
down(&bd->sem);
18511848
bd->props->brightness = aty128_bl_data.max_brightness;
18521849
bd->props->power = FB_BLANK_UNBLANK;
1853-
bd->props->update_status(bd);
1854-
up(&bd->sem);
1850+
backlight_update_status(bd);
18551851

18561852
#ifdef CONFIG_PMAC_BACKLIGHT
18571853
mutex_lock(&pmac_backlight_mutex);

‎drivers/video/aty/atyfb_base.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,10 +2188,8 @@ static void aty_bl_set_power(struct fb_info *info, int power)
21882188
mutex_lock(&info->bl_mutex);
21892189

21902190
if (info->bl_dev) {
2191-
down(&info->bl_dev->sem);
21922191
info->bl_dev->props->power = power;
21932192
__aty_bl_update_status(info->bl_dev);
2194-
up(&info->bl_dev->sem);
21952193
}
21962194

21972195
mutex_unlock(&info->bl_mutex);
@@ -2224,11 +2222,9 @@ static void aty_bl_init(struct atyfb_par *par)
22242222
0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL);
22252223
mutex_unlock(&info->bl_mutex);
22262224

2227-
down(&bd->sem);
22282225
bd->props->brightness = aty_bl_data.max_brightness;
22292226
bd->props->power = FB_BLANK_UNBLANK;
2230-
bd->props->update_status(bd);
2231-
up(&bd->sem);
2227+
backlight_update_status(bd);
22322228

22332229
#ifdef CONFIG_PMAC_BACKLIGHT
22342230
mutex_lock(&pmac_backlight_mutex);

‎drivers/video/aty/radeon_backlight.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,9 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
194194
217 * FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL);
195195
mutex_unlock(&rinfo->info->bl_mutex);
196196

197-
down(&bd->sem);
198197
bd->props->brightness = radeon_bl_data.max_brightness;
199198
bd->props->power = FB_BLANK_UNBLANK;
200-
bd->props->update_status(bd);
201-
up(&bd->sem);
199+
backlight_update_status(bd);
202200

203201
#ifdef CONFIG_PMAC_BACKLIGHT
204202
mutex_lock(&pmac_backlight_mutex);

‎drivers/video/backlight/backlight.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ static int fb_notifier_callback(struct notifier_block *self,
3737
if (!bd->props->check_fb ||
3838
bd->props->check_fb(evdata->info)) {
3939
bd->props->fb_blank = *(int *)evdata->data;
40-
if (bd->props && bd->props->update_status)
41-
bd->props->update_status(bd);
40+
backlight_update_status(bd);
4241
}
4342
up(&bd->sem);
4443
return 0;
@@ -97,8 +96,7 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
9796
if (bd->props) {
9897
pr_debug("backlight: set power to %d\n", power);
9998
bd->props->power = power;
100-
if (bd->props->update_status)
101-
bd->props->update_status(bd);
99+
backlight_update_status(bd);
102100
rc = count;
103101
}
104102
up(&bd->sem);
@@ -140,8 +138,7 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
140138
pr_debug("backlight: set brightness to %d\n",
141139
brightness);
142140
bd->props->brightness = brightness;
143-
if (bd->props->update_status)
144-
bd->props->update_status(bd);
141+
backlight_update_status(bd);
145142
rc = count;
146143
}
147144
}
@@ -230,6 +227,7 @@ struct backlight_device *backlight_device_register(const char *name,
230227
if (!new_bd)
231228
return ERR_PTR(-ENOMEM);
232229

230+
mutex_init(&new_bd->update_lock);
233231
init_MUTEX(&new_bd->sem);
234232
new_bd->props = bp;
235233
memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev));

‎drivers/video/backlight/lcd.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata,
198198
return ERR_PTR(-ENOMEM);
199199

200200
init_MUTEX(&new_ld->sem);
201+
mutex_init(&new_ld->update_lock);
201202
new_ld->props = lp;
202203
memset(&new_ld->class_dev, 0, sizeof(new_ld->class_dev));
203204
new_ld->class_dev.class = &lcd_class;

0 commit comments

Comments
 (0)