aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAndrea Righi <righi.andrea@gmail.com>2009-04-13 17:39:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-13 18:04:28 -0400
commit513adb58685615b0b1d47a3f0d40f5352beff189 (patch)
tree80afe08d17f24bbf3d5ad48d62df2e143d00ae95 /drivers
parentb52bb3712a64c404846f30300b339cfd01e316be (diff)
fbdev: fix info->lock deadlock in fbcon_event_notify()
fb_notifier_call_chain() is called with info->lock held, i.e. in do_fb_ioctl() => FBIOPUT_VSCREENINFO => fb_set_var() and the some notifier callbacks, like fbcon_event_notify(), try to re-acquire info->lock again. Remove the lock/unlock_fb_info() in all the framebuffer notifier callbacks' and be sure to always call fb_notifier_call_chain() with info->lock held. Reported-by: Pavel Roskin <proski@gnu.org> Reported-by: Eric Miao <eric.y.miao@gmail.com> Signed-off-by: Andrea Righi <righi.andrea@gmail.com> Cc: Stefan Richter <stefanr@s5r6.in-berlin.de> Cc: Krzysztof Helt <krzysztof.h1@poczta.fm> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: "Rafael J. Wysocki" <rjw@sisk.pl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/video/backlight/backlight.c3
-rw-r--r--drivers/video/backlight/lcd.c3
-rw-r--r--drivers/video/console/fbcon.c55
-rw-r--r--drivers/video/fbmem.c19
4 files changed, 22 insertions, 58 deletions
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index dd37cbcaf8ce..157057c79ca3 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -35,8 +35,6 @@ static int fb_notifier_callback(struct notifier_block *self,
35 return 0; 35 return 0;
36 36
37 bd = container_of(self, struct backlight_device, fb_notif); 37 bd = container_of(self, struct backlight_device, fb_notif);
38 if (!lock_fb_info(evdata->info))
39 return -ENODEV;
40 mutex_lock(&bd->ops_lock); 38 mutex_lock(&bd->ops_lock);
41 if (bd->ops) 39 if (bd->ops)
42 if (!bd->ops->check_fb || 40 if (!bd->ops->check_fb ||
@@ -49,7 +47,6 @@ static int fb_notifier_callback(struct notifier_block *self,
49 backlight_update_status(bd); 47 backlight_update_status(bd);
50 } 48 }
51 mutex_unlock(&bd->ops_lock); 49 mutex_unlock(&bd->ops_lock);
52 unlock_fb_info(evdata->info);
53 return 0; 50 return 0;
54} 51}
55 52
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index 0bb13df0fa89..b6449470106c 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -40,8 +40,6 @@ static int fb_notifier_callback(struct notifier_block *self,
40 if (!ld->ops) 40 if (!ld->ops)
41 return 0; 41 return 0;
42 42
43 if (!lock_fb_info(evdata->info))
44 return -ENODEV;
45 mutex_lock(&ld->ops_lock); 43 mutex_lock(&ld->ops_lock);
46 if (!ld->ops->check_fb || ld->ops->check_fb(ld, evdata->info)) { 44 if (!ld->ops->check_fb || ld->ops->check_fb(ld, evdata->info)) {
47 if (event == FB_EVENT_BLANK) { 45 if (event == FB_EVENT_BLANK) {
@@ -53,7 +51,6 @@ static int fb_notifier_callback(struct notifier_block *self,
53 } 51 }
54 } 52 }
55 mutex_unlock(&ld->ops_lock); 53 mutex_unlock(&ld->ops_lock);
56 unlock_fb_info(evdata->info);
57 return 0; 54 return 0;
58} 55}
59 56
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 2cd500a304f2..471a9a60376a 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -2263,9 +2263,12 @@ static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2263 } 2263 }
2264 2264
2265 2265
2266 if (!lock_fb_info(info))
2267 return;
2266 event.info = info; 2268 event.info = info;
2267 event.data = &blank; 2269 event.data = &blank;
2268 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event); 2270 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2271 unlock_fb_info(info);
2269} 2272}
2270 2273
2271static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch) 2274static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
@@ -2956,8 +2959,6 @@ static int fbcon_fb_unregistered(struct fb_info *info)
2956{ 2959{
2957 int i, idx; 2960 int i, idx;
2958 2961
2959 if (!lock_fb_info(info))
2960 return -ENODEV;
2961 idx = info->node; 2962 idx = info->node;
2962 for (i = first_fb_vc; i <= last_fb_vc; i++) { 2963 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2963 if (con2fb_map[i] == idx) 2964 if (con2fb_map[i] == idx)
@@ -2985,8 +2986,6 @@ static int fbcon_fb_unregistered(struct fb_info *info)
2985 if (primary_device == idx) 2986 if (primary_device == idx)
2986 primary_device = -1; 2987 primary_device = -1;
2987 2988
2988 unlock_fb_info(info);
2989
2990 if (!num_registered_fb) 2989 if (!num_registered_fb)
2991 unregister_con_driver(&fb_con); 2990 unregister_con_driver(&fb_con);
2992 2991
@@ -3027,11 +3026,8 @@ static int fbcon_fb_registered(struct fb_info *info)
3027{ 3026{
3028 int ret = 0, i, idx; 3027 int ret = 0, i, idx;
3029 3028
3030 if (!lock_fb_info(info))
3031 return -ENODEV;
3032 idx = info->node; 3029 idx = info->node;
3033 fbcon_select_primary(info); 3030 fbcon_select_primary(info);
3034 unlock_fb_info(info);
3035 3031
3036 if (info_idx == -1) { 3032 if (info_idx == -1) {
3037 for (i = first_fb_vc; i <= last_fb_vc; i++) { 3033 for (i = first_fb_vc; i <= last_fb_vc; i++) {
@@ -3152,53 +3148,23 @@ static int fbcon_event_notify(struct notifier_block *self,
3152 3148
3153 switch(action) { 3149 switch(action) {
3154 case FB_EVENT_SUSPEND: 3150 case FB_EVENT_SUSPEND:
3155 if (!lock_fb_info(info)) {
3156 ret = -ENODEV;
3157 goto done;
3158 }
3159 fbcon_suspended(info); 3151 fbcon_suspended(info);
3160 unlock_fb_info(info);
3161 break; 3152 break;
3162 case FB_EVENT_RESUME: 3153 case FB_EVENT_RESUME:
3163 if (!lock_fb_info(info)) {
3164 ret = -ENODEV;
3165 goto done;
3166 }
3167 fbcon_resumed(info); 3154 fbcon_resumed(info);
3168 unlock_fb_info(info);
3169 break; 3155 break;
3170 case FB_EVENT_MODE_CHANGE: 3156 case FB_EVENT_MODE_CHANGE:
3171 if (!lock_fb_info(info)) {
3172 ret = -ENODEV;
3173 goto done;
3174 }
3175 fbcon_modechanged(info); 3157 fbcon_modechanged(info);
3176 unlock_fb_info(info);
3177 break; 3158 break;
3178 case FB_EVENT_MODE_CHANGE_ALL: 3159 case FB_EVENT_MODE_CHANGE_ALL:
3179 if (!lock_fb_info(info)) {
3180 ret = -ENODEV;
3181 goto done;
3182 }
3183 fbcon_set_all_vcs(info); 3160 fbcon_set_all_vcs(info);
3184 unlock_fb_info(info);
3185 break; 3161 break;
3186 case FB_EVENT_MODE_DELETE: 3162 case FB_EVENT_MODE_DELETE:
3187 mode = event->data; 3163 mode = event->data;
3188 if (!lock_fb_info(info)) {
3189 ret = -ENODEV;
3190 goto done;
3191 }
3192 ret = fbcon_mode_deleted(info, mode); 3164 ret = fbcon_mode_deleted(info, mode);
3193 unlock_fb_info(info);
3194 break; 3165 break;
3195 case FB_EVENT_FB_UNBIND: 3166 case FB_EVENT_FB_UNBIND:
3196 if (!lock_fb_info(info)) {
3197 ret = -ENODEV;
3198 goto done;
3199 }
3200 idx = info->node; 3167 idx = info->node;
3201 unlock_fb_info(info);
3202 ret = fbcon_fb_unbind(idx); 3168 ret = fbcon_fb_unbind(idx);
3203 break; 3169 break;
3204 case FB_EVENT_FB_REGISTERED: 3170 case FB_EVENT_FB_REGISTERED:
@@ -3217,29 +3183,14 @@ static int fbcon_event_notify(struct notifier_block *self,
3217 con2fb->framebuffer = con2fb_map[con2fb->console - 1]; 3183 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3218 break; 3184 break;
3219 case FB_EVENT_BLANK: 3185 case FB_EVENT_BLANK:
3220 if (!lock_fb_info(info)) {
3221 ret = -ENODEV;
3222 goto done;
3223 }
3224 fbcon_fb_blanked(info, *(int *)event->data); 3186 fbcon_fb_blanked(info, *(int *)event->data);
3225 unlock_fb_info(info);
3226 break; 3187 break;
3227 case FB_EVENT_NEW_MODELIST: 3188 case FB_EVENT_NEW_MODELIST:
3228 if (!lock_fb_info(info)) {
3229 ret = -ENODEV;
3230 goto done;
3231 }
3232 fbcon_new_modelist(info); 3189 fbcon_new_modelist(info);
3233 unlock_fb_info(info);
3234 break; 3190 break;
3235 case FB_EVENT_GET_REQ: 3191 case FB_EVENT_GET_REQ:
3236 caps = event->data; 3192 caps = event->data;
3237 if (!lock_fb_info(info)) {
3238 ret = -ENODEV;
3239 goto done;
3240 }
3241 fbcon_get_requirement(info, caps); 3193 fbcon_get_requirement(info, caps);
3242 unlock_fb_info(info);
3243 break; 3194 break;
3244 } 3195 }
3245done: 3196done:
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 2ac32e6b5953..d412a1ddc12f 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -1097,8 +1097,11 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
1097 return -EINVAL; 1097 return -EINVAL;
1098 con2fb.framebuffer = -1; 1098 con2fb.framebuffer = -1;
1099 event.data = &con2fb; 1099 event.data = &con2fb;
1100 if (!lock_fb_info(info))
1101 return -ENODEV;
1100 event.info = info; 1102 event.info = info;
1101 fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, &event); 1103 fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, &event);
1104 unlock_fb_info(info);
1102 ret = copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0; 1105 ret = copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0;
1103 break; 1106 break;
1104 case FBIOPUT_CON2FBMAP: 1107 case FBIOPUT_CON2FBMAP:
@@ -1115,8 +1118,11 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
1115 break; 1118 break;
1116 } 1119 }
1117 event.data = &con2fb; 1120 event.data = &con2fb;
1121 if (!lock_fb_info(info))
1122 return -ENODEV;
1118 event.info = info; 1123 event.info = info;
1119 ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, &event); 1124 ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, &event);
1125 unlock_fb_info(info);
1120 break; 1126 break;
1121 case FBIOBLANK: 1127 case FBIOBLANK:
1122 if (!lock_fb_info(info)) 1128 if (!lock_fb_info(info))
@@ -1521,7 +1527,10 @@ register_framebuffer(struct fb_info *fb_info)
1521 registered_fb[i] = fb_info; 1527 registered_fb[i] = fb_info;
1522 1528
1523 event.info = fb_info; 1529 event.info = fb_info;
1530 if (!lock_fb_info(fb_info))
1531 return -ENODEV;
1524 fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event); 1532 fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
1533 unlock_fb_info(fb_info);
1525 return 0; 1534 return 0;
1526} 1535}
1527 1536
@@ -1555,8 +1564,12 @@ unregister_framebuffer(struct fb_info *fb_info)
1555 goto done; 1564 goto done;
1556 } 1565 }
1557 1566
1567
1568 if (!lock_fb_info(fb_info))
1569 return -ENODEV;
1558 event.info = fb_info; 1570 event.info = fb_info;
1559 ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event); 1571 ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event);
1572 unlock_fb_info(fb_info);
1560 1573
1561 if (ret) { 1574 if (ret) {
1562 ret = -EINVAL; 1575 ret = -EINVAL;
@@ -1590,6 +1603,8 @@ void fb_set_suspend(struct fb_info *info, int state)
1590{ 1603{
1591 struct fb_event event; 1604 struct fb_event event;
1592 1605
1606 if (!lock_fb_info(info))
1607 return;
1593 event.info = info; 1608 event.info = info;
1594 if (state) { 1609 if (state) {
1595 fb_notifier_call_chain(FB_EVENT_SUSPEND, &event); 1610 fb_notifier_call_chain(FB_EVENT_SUSPEND, &event);
@@ -1598,6 +1613,7 @@ void fb_set_suspend(struct fb_info *info, int state)
1598 info->state = FBINFO_STATE_RUNNING; 1613 info->state = FBINFO_STATE_RUNNING;
1599 fb_notifier_call_chain(FB_EVENT_RESUME, &event); 1614 fb_notifier_call_chain(FB_EVENT_RESUME, &event);
1600 } 1615 }
1616 unlock_fb_info(info);
1601} 1617}
1602 1618
1603/** 1619/**
@@ -1667,8 +1683,11 @@ int fb_new_modelist(struct fb_info *info)
1667 err = 1; 1683 err = 1;
1668 1684
1669 if (!list_empty(&info->modelist)) { 1685 if (!list_empty(&info->modelist)) {
1686 if (!lock_fb_info(info))
1687 return -ENODEV;
1670 event.info = info; 1688 event.info = info;
1671 err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event); 1689 err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
1690 unlock_fb_info(info);
1672 } 1691 }
1673 1692
1674 return err; 1693 return err;