Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2979664imu; Sun, 9 Dec 2018 14:10:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/VSJdz3ecNiyXFIFYwHyPBLvXjyLNQWi3+yAjXzJFJ05wtZ/sN+apcIyJj10HtSoEXu66Vf X-Received: by 2002:a63:1d59:: with SMTP id d25mr8986242pgm.180.1544393456569; Sun, 09 Dec 2018 14:10:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544393456; cv=none; d=google.com; s=arc-20160816; b=KPLioPKFTEaeTUg8A0/dumkj2RM8CK8tvLXBvnsVRXfrUfWqg09w/eMfg0PQdJJqXG K844IZKndpdQBFkXSWY2cYaqnVm1IeVqKhz05BmTcOveeDcTuLEuyvFu6lmfd0qubX73 ZyA/K9ksPIlacKOLbfAVsyOo/qBVfO2knLTtrtzfFcfJIGj2QUWGNHeqizABvMrEseIw 4AJIZ7SHx585eot3TSA7OKXW590JqKpjIVtXYRJxuFketmVRpf56fASqhGwBGKkaO3NZ +STVZPXfMT67UKRjcl1x7Cti9/wk9q8BikHFCC9z0IgKKx3NJA7ZjZkBC5PYrkV3yWFX Kr3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=lkdqec7J3gZiy/Qq7+VEn0wgVf4oqk93092uQH8RiTM=; b=js7Z7PeVgGjLNqmqGwIwPO3KGvU6TTnHnfJxFQIPya8/c+8+/X2ZcWjF0lXi4W5kLk yJH274nP5daPJky870e9gFqQ9giev//QOOcuFayum/iSS4fvFSevNIfzDEqeAQQDXU6P qRLj0REjK7NWvbwH5dq2e74XO3eqx1cNhXFpwcDcsCWxRLs8gYks3CJAW/hJCMrVLoHd KOtO6RoFT4H7aau7L+PELyGyy/OGvZMzrHPNP5wK0HHAI87ZqNODIEByzPSuN+gwYBwz QBppSF7qihZNkdRqg4fcQuaKcUpIPwpWFeKg8VmCITwOAh9Y5eaA9Tqxeo5fSfkvCzxW 56oQ== 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 g124si7814948pgc.568.2018.12.09.14.10.41; Sun, 09 Dec 2018 14:10:56 -0800 (PST) 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 S1727716AbeLIWJR (ORCPT + 99 others); Sun, 9 Dec 2018 17:09:17 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:37408 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728075AbeLIWJN (ORCPT ); Sun, 9 Dec 2018 17:09:13 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW73O-0002ik-KP; Sun, 09 Dec 2018 21:55:58 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72a-0003GW-1W; Sun, 09 Dec 2018 21:55:08 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Bernie Thompson" , "Bartlomiej Zolnierkiewicz" , "Dave Airlie" , "Ladislav Michl" , "Mikulas Patocka" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 055/328] fb: fix lost console when the user unplugs a USB adapter In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 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 [b.zolnierkie: preserve old behavior for do_unregister_framebuffer()] Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: Ben Hutchings --- 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);