Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2329664imm; Fri, 7 Sep 2018 14:46:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZERupW1uk/XGY3is+2Vzp/9H7zqci9i3j2mIJDm688ybA2R/IuauB42+dh6DrD4Q9oIFox X-Received: by 2002:a17:902:6f16:: with SMTP id w22-v6mr10168950plk.127.1536356812885; Fri, 07 Sep 2018 14:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536356812; cv=none; d=google.com; s=arc-20160816; b=KXPtZsCS9BitRWiyAYmCBgicZ/5mHIpbD7x/Et4e9orsOTLOYxEh6R9kShkjio2K4U kDiR95RszsGurpfjgvZ3df95s1kGEFYSv7vk+6uJ6cUaTd0K2Q05MvjspDOIH4bMvPj5 Qq6i3Y5wdZNxsvnulkZhoFc1p9hw76hTyCVBfS+qyp5qJcsIj5LFA3Rgmc+mGRampu6u +OozIn2oH30aeRguwVk6vIncHGhRd0HJoSeTtc34jw5ZxhDOhAGwV9/AIpH6xK1hSwyO zAWVUI2w86Hj7CaD5r/fQBD7nc01PoDS4fz5CuD2PmTmX+u+BVZicK5srb90MQpSS38H HmNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from; bh=G4M5057c2tIEUcmOKnYtSbJt81tpDkTv/v6r09tzmp8=; b=WcrNChtXqSVsbv2OzctE1W6QlcOybwxPbEIpEGa9dGFnTBm6Vs651DUt9A14CKF78V yseTzyFkLctF5Dv8MeswSBD1gl9+UZrKQ9njDBbSM6LVIIV+CF3fvD8L2+sUePexiG6Q CKUYdz2Lt/5SHuyiGIDjKQVi09x1kmaBGfLRLHRnmbgqnqiZDlCZtFHYafb5gEeIc1MC rbJEZ325KrULX58TiChkMPmVb5Bx0Ma4Np8ViDq+u7UlkXZ3CXYJ3NNN/E1mZ2sTAwEo EzG+OUXxeoweEHwrnbxxNpxW+myYbOm0mhWC9OlJTwsp/9VI7w+ZcaXOMRsaK2dDyOJP ZzEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g21-v6si10050067pgk.232.2018.09.07.14.46.37; Fri, 07 Sep 2018 14:46:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731005AbeIHC1f (ORCPT + 99 others); Fri, 7 Sep 2018 22:27:35 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57802 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726568AbeIHC1e (ORCPT ); Fri, 7 Sep 2018 22:27:34 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 74703F36; Fri, 7 Sep 2018 21:44:38 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Dave Airlie , Bernie Thompson , Ladislav Michl , Bartlomiej Zolnierkiewicz Subject: [PATCH 3.18 26/29] fb: fix lost console when the user unplugs a USB adapter Date: Fri, 7 Sep 2018 23:10:47 +0200 Message-Id: <20180907210911.254533577@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907210909.523240901@linuxfoundation.org> References: <20180907210909.523240901@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikulas Patocka commit 8c5b044299951acd91e830a688dd920477ea1eda upstream. 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 Cc: Dave Airlie Cc: Bernie Thompson Cc: Ladislav Michl Cc: stable@vger.kernel.org [b.zolnierkie: preserve old behavior for do_unregister_framebuffer()] Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/core/fbmem.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1687,12 +1687,12 @@ static int do_register_framebuffer(struc return 0; } -static int do_unregister_framebuffer(struct fb_info *fb_info) +static int unbind_console(struct fb_info *fb_info) { struct fb_event event; - int i, ret = 0; + int ret; + int i = fb_info->node; - i = fb_info->node; if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info) return -EINVAL; @@ -1707,17 +1707,29 @@ static int do_unregister_framebuffer(str unlock_fb_info(fb_info); console_unlock(); + return ret; +} + +static int __unlink_framebuffer(struct fb_info *fb_info); + +static int do_unregister_framebuffer(struct fb_info *fb_info) +{ + struct fb_event event; + int ret; + + ret = unbind_console(fb_info); + if (ret) return -EINVAL; pm_vt_switch_unregister(fb_info->dev); - unlink_framebuffer(fb_info); + __unlink_framebuffer(fb_info); if (fb_info->pixmap.addr && (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT)) kfree(fb_info->pixmap.addr); fb_destroy_modelist(&fb_info->modelist); - registered_fb[i] = NULL; + registered_fb[fb_info->node] = NULL; num_registered_fb--; fb_cleanup_device(fb_info); event.info = fb_info; @@ -1730,7 +1742,7 @@ static int do_unregister_framebuffer(str return 0; } -int unlink_framebuffer(struct fb_info *fb_info) +static int __unlink_framebuffer(struct fb_info *fb_info) { int i; @@ -1742,6 +1754,20 @@ int unlink_framebuffer(struct fb_info *f device_destroy(fb_class, MKDEV(FB_MAJOR, i)); fb_info->dev = NULL; } + + return 0; +} + +int unlink_framebuffer(struct fb_info *fb_info) +{ + int ret; + + ret = __unlink_framebuffer(fb_info); + if (ret) + return ret; + + unbind_console(fb_info); + return 0; } EXPORT_SYMBOL(unlink_framebuffer);