Skip to content

Commit

Permalink
fbcon: use lock_fb_info in fbcon_open/release
Browse files Browse the repository at this point in the history
Now we get to the real motiviation, because fbmem.c insists that
that's the right lock for these.

Ofc fbcon.c has a lot more places where it probably should call
lock_fb_info(). But looking at fbmem.c at least most of these seem to
be protected by console_lock() too, which is probably what papers over
any issues.

Note that this means we're shuffling around a bit the locking sections
for some of the console takeover and unbind paths, but not all:
- console binding/unbinding from the console layer never with
lock_fb_info
- unbind (as opposed to unlink) never bother with lock_fb_info

Also the real serialization against set_par and set_pan are still
doing by wrapping the entire ioctl code in console_lock(). So this
shuffling shouldn't be worse than what we had from a "can you trigger
races?" pov, but it's at least clearer.

Acked-by: Sam Ravnborg <[email protected]>
Signed-off-by: Daniel Vetter <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: Claudio Suarez <[email protected]>
Cc: Tetsuo Handa <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Du Cheng <[email protected]>
Cc: Sam Ravnborg <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: William Kucharski <[email protected]>
Cc: Alex Deucher <[email protected]>
Cc: Zheyu Ma <[email protected]>
Cc: Zhen Lei <[email protected]>
Cc: Xiyu Yang <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
danvet committed Apr 7, 2022
1 parent d443d93 commit 04933a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 5 additions & 0 deletions drivers/video/fbdev/core/fbcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,10 @@ static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)

static void fbcon_release(struct fb_info *info)
{
lock_fb_info(info);
if (info->fbops->fb_release)
info->fbops->fb_release(info, 0);
unlock_fb_info(info);

module_put(info->fbops->owner);
}
Expand All @@ -697,11 +699,14 @@ static int fbcon_open(struct fb_info *info)
if (!try_module_get(info->fbops->owner))
return -ENODEV;

lock_fb_info(info);
if (info->fbops->fb_open &&
info->fbops->fb_open(info, 0)) {
unlock_fb_info(info);
module_put(info->fbops->owner);
return -ENODEV;
}
unlock_fb_info(info);

ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
if (!ops) {
Expand Down
4 changes: 0 additions & 4 deletions drivers/video/fbdev/core/fbmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1670,9 +1670,7 @@ static int do_register_framebuffer(struct fb_info *fb_info)
console_lock();
else
atomic_inc(&ignore_console_lock_warning);
lock_fb_info(fb_info);
ret = fbcon_fb_registered(fb_info);
unlock_fb_info(fb_info);

if (!lockless_register_fb)
console_unlock();
Expand All @@ -1689,9 +1687,7 @@ static void unbind_console(struct fb_info *fb_info)
return;

console_lock();
lock_fb_info(fb_info);
fbcon_fb_unbind(fb_info);
unlock_fb_info(fb_info);
console_unlock();
}

Expand Down

0 comments on commit 04933a2

Please sign in to comment.