Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2824683imu; Sun, 23 Dec 2018 08:36:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN44v4vnOS0xp+HnmCSjnhLu48SiYqUHDtTGtzpAZ+NTgETeiMsYcNMKcVkzjeXujr6shM5U X-Received: by 2002:a17:902:a601:: with SMTP id u1mr10077652plq.77.1545582995251; Sun, 23 Dec 2018 08:36:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545582995; cv=none; d=google.com; s=arc-20160816; b=PxtW4VxcIZu3n4R1RPBVjM8EQQpJ2dwUMUUrmR+FNmB4eJo74yGbdX7f6JZoYJ5c3t 8N6iOgPSt/93i/j4IDq/+92nKKDNSuYR/Mn4hlh7ZBwNrLm904E2cpvSK4z16VgEmGYG o4m4lSZwlgmbBbNNuGPqlHrBsbbpslRsbOYfTAsblx70uRPNML0JwSa+R6SGL85QYJBx W1WMlRlqqiWswGJDSdnB60kG20UqooOHK42+Mkozf3TpvRJdq9ZMOakwW0F6BoTsHShJ ZFthWH3ZSw74lW/eEFtEjDSBqp0bYIBB6kVqWYUMAjmtFwwIP0nGkSdyqbefBrSBDnWS zT7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5uUnM+MaNN9iLp3gnOrWEqvYAk+XSVGQm6uYqpP+lpE=; b=dbqy0hyuQPzfw96Rxlu8JuMx7sUieIOVZZx/05UCQA1lK7MktPXRmpwugaiq4uLyS8 tTEezglhUPoCnYRiN/iypB3QH/JjNpZGjAsc9SCae40W18Si04n45bJvw8CcGrimkZlU Kbc6hbaCHEqSDP7fSh1v5k9nFRy3rv7syuXcJuzkAHi300CJes2syP0U8iid/Xr2BJLI kJ45vJntg2azWTxZAPZrhpIxo4bCLi2blZO3eU8UX+e10ZEaOOAUjL2PxL0x1tI/6upw /T91xwtjX7MGfd2KUZqCJWNzZ8uXAkyIZSURW1ib5dSoTfqalbeTVcO/HvPg7bSe3YfY F9tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lekensteyn.nl header.s=s2048-2015-q1 header.b="Zrdy/8Yl"; 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 g187si25935137pfc.43.2018.12.23.08.36.19; Sun, 23 Dec 2018 08:36:35 -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; dkim=pass header.i=@lekensteyn.nl header.s=s2048-2015-q1 header.b="Zrdy/8Yl"; 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 S2404323AbeLWAzQ (ORCPT + 99 others); Sat, 22 Dec 2018 19:55:16 -0500 Received: from lekensteyn.nl ([178.21.112.251]:45979 "EHLO lekensteyn.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387711AbeLWAzQ (ORCPT ); Sat, 22 Dec 2018 19:55:16 -0500 X-Greylist: delayed 705 seconds by postgrey-1.27 at vger.kernel.org; Sat, 22 Dec 2018 19:55:14 EST DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2015-q1; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=5uUnM+MaNN9iLp3gnOrWEqvYAk+XSVGQm6uYqpP+lpE=; b=Zrdy/8YlHSjSuNkk0XYZjcNY643JH9lYM5YIPhMzX2LOycdjcZRsi4BCZrKuKX/awvv5w+o5OV565zS6QhcJLSehwUP13TCt3NUMQ4wBApcKh3YOA9IKbbTDFx5BEomiZZCMAbaJtSOlZjNz4QbcxdUHNbq5BeLwl6HA7rP8hyYpjWJtGLxht+q7JFVSu1Wq+TpGLBFCcioKPduqktWCcE3I6kM6wrMVQQtybIqf5LZp2yrFQpNUB4gCEiSq1ALGg7Qj8z2AaSBd758kyPcnUMkjjvfgNG85gMRPfpP6cnxYeMwKKzOY2r3RihovHiPvTBDxtg6zG0F0fhhJaHrk1g==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1gas2u-0004I9-V9; Sun, 23 Dec 2018 01:55:09 +0100 From: Peter Wu To: dri-devel@lists.freedesktop.org Cc: Linus Torvalds , rong.a.chen@intel.com, kraxel@redhat.com, Daniel Vetter , Linux List Kernel Mailing , lkp@01.org, =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= Subject: [PATCH] drm/fb-helper: fix leaks in error path of drm_fb_helper_fbdev_setup Date: Sun, 23 Dec 2018 01:55:07 +0100 Message-Id: <20181223005507.28328-1-peter@lekensteyn.nl> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181223004315.GA11455@al> References: <20181223004315.GA11455@al> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Spam-Status: No, hits=-0.0 required=5.0 tests=NO_RELAYS=-0.001 autolearn=no autolearn_force=no Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After drm_fb_helper_fbdev_setup calls drm_fb_helper_init, "dev->fb_helper" will be initialized (and thus drm_fb_helper_fini will have some effect). After that, drm_fb_helper_initial_config is called which may call the "fb_probe" driver callback. This driver callback may call drm_fb_helper_defio_init (as is done by drm_fb_helper_generic_probe) or set a framebuffer (as is done by bochs) as documented. These are normally cleaned up on exit by drm_fb_helper_fbdev_teardown which also calls drm_fb_helper_fini. If an error occurs after "fb_probe", but before setup is complete, then calling just drm_fb_helper_fini will leak resources. This was triggered by df2052cc922 ("bochs: convert to drm_fb_helper_fbdev_setup/teardown"): [ 50.008030] bochsdrmfb: enable CONFIG_FB_LITTLE_ENDIAN to support this framebuffer [ 50.009436] bochs-drm 0000:00:02.0: [drm:drm_fb_helper_fbdev_setup] *ERROR* fbdev: Failed to set configuration (ret=-38) [ 50.011456] [drm] Initialized bochs-drm 1.0.0 20130925 for 0000:00:02.0 on minor 2 [ 50.013604] WARNING: CPU: 1 PID: 1 at drivers/gpu/drm/drm_mode_config.c:477 drm_mode_config_cleanup+0x280/0x2a0 [ 50.016175] CPU: 1 PID: 1 Comm: swapper/0 Tainted: G T 4.20.0-rc7 #1 [ 50.017732] EIP: drm_mode_config_cleanup+0x280/0x2a0 ... [ 50.023155] Call Trace: [ 50.023155] ? bochs_kms_fini+0x1e/0x30 [ 50.023155] ? bochs_unload+0x18/0x40 This can be reproduced with QEMU and CONFIG_FB_LITTLE_ENDIAN=n. Link: https://lkml.kernel.org/r/20181221083226.GI23332@shao2-debian Link: https://lkml.kernel.org/r/20181223004315.GA11455@al Fixes: 8741216396b2 ("drm/fb-helper: Add drm_fb_helper_fbdev_setup/teardown()") Reported-by: kernel test robot Cc: Noralf Trønnes Signed-off-by: Peter Wu --- drivers/gpu/drm/drm_fb_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 9d64f874f965..432e0f3b9267 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -2860,7 +2860,7 @@ int drm_fb_helper_fbdev_setup(struct drm_device *dev, return 0; err_drm_fb_helper_fini: - drm_fb_helper_fini(fb_helper); + drm_fb_helper_fbdev_teardown(dev); return ret; } -- 2.20.0