Skip to content

Commit 8c5b044

Browse files
Mikulas Patockabzolnier
authored andcommitted
fb: fix lost console when the user unplugs a USB adapter
I have a USB display adapter using the udlfb driver and I use it on an ARM board that doesn't have any graphics card. When I plug the adapter in, the console is properly displayed, however when I unplug and re-plug the adapter, the console is not displayed and I can't access it until I reboot the board. The reason is this: When the adapter is unplugged, dlfb_usb_disconnect calls unlink_framebuffer, then it waits until the reference count drops to zero and then it deallocates the framebuffer. However, the console that is attached to the framebuffer device keeps the reference count non-zero, so the framebuffer device is never destroyed. When the USB adapter is plugged again, it creates a new device /dev/fb1 and the console is not attached to it. This patch fixes the bug by unbinding the console from unlink_framebuffer. The code to unbind the console is moved from do_unregister_framebuffer to a function unbind_console. When the console is unbound, the reference count drops to zero and the udlfb driver frees the framebuffer. When the adapter is plugged back, a new framebuffer is created and the console is attached to it. Signed-off-by: Mikulas Patocka <[email protected]> Cc: Dave Airlie <[email protected]> Cc: Bernie Thompson <[email protected]> Cc: Ladislav Michl <[email protected]> Cc: [email protected] [b.zolnierkie: preserve old behavior for do_unregister_framebuffer()] Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
1 parent 88fe4ce commit 8c5b044

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

drivers/video/fbdev/core/fbmem.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,12 +1703,12 @@ static int do_register_framebuffer(struct fb_info *fb_info)
17031703
return 0;
17041704
}
17051705

1706-
static int do_unregister_framebuffer(struct fb_info *fb_info)
1706+
static int unbind_console(struct fb_info *fb_info)
17071707
{
17081708
struct fb_event event;
1709-
int i, ret = 0;
1709+
int ret;
1710+
int i = fb_info->node;
17101711

1711-
i = fb_info->node;
17121712
if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info)
17131713
return -EINVAL;
17141714

@@ -1723,17 +1723,29 @@ static int do_unregister_framebuffer(struct fb_info *fb_info)
17231723
unlock_fb_info(fb_info);
17241724
console_unlock();
17251725

1726+
return ret;
1727+
}
1728+
1729+
static int __unlink_framebuffer(struct fb_info *fb_info);
1730+
1731+
static int do_unregister_framebuffer(struct fb_info *fb_info)
1732+
{
1733+
struct fb_event event;
1734+
int ret;
1735+
1736+
ret = unbind_console(fb_info);
1737+
17261738
if (ret)
17271739
return -EINVAL;
17281740

17291741
pm_vt_switch_unregister(fb_info->dev);
17301742

1731-
unlink_framebuffer(fb_info);
1743+
__unlink_framebuffer(fb_info);
17321744
if (fb_info->pixmap.addr &&
17331745
(fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
17341746
kfree(fb_info->pixmap.addr);
17351747
fb_destroy_modelist(&fb_info->modelist);
1736-
registered_fb[i] = NULL;
1748+
registered_fb[fb_info->node] = NULL;
17371749
num_registered_fb--;
17381750
fb_cleanup_device(fb_info);
17391751
event.info = fb_info;
@@ -1746,7 +1758,7 @@ static int do_unregister_framebuffer(struct fb_info *fb_info)
17461758
return 0;
17471759
}
17481760

1749-
int unlink_framebuffer(struct fb_info *fb_info)
1761+
static int __unlink_framebuffer(struct fb_info *fb_info)
17501762
{
17511763
int i;
17521764

@@ -1758,6 +1770,20 @@ int unlink_framebuffer(struct fb_info *fb_info)
17581770
device_destroy(fb_class, MKDEV(FB_MAJOR, i));
17591771
fb_info->dev = NULL;
17601772
}
1773+
1774+
return 0;
1775+
}
1776+
1777+
int unlink_framebuffer(struct fb_info *fb_info)
1778+
{
1779+
int ret;
1780+
1781+
ret = __unlink_framebuffer(fb_info);
1782+
if (ret)
1783+
return ret;
1784+
1785+
unbind_console(fb_info);
1786+
17611787
return 0;
17621788
}
17631789
EXPORT_SYMBOL(unlink_framebuffer);

0 commit comments

Comments
 (0)