Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5640040img; Wed, 27 Mar 2019 12:14:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIQrgIg41Ldlqyx1anGNebtuqBGqNzhTSKDFENcgmXONis8BPbDjBa8BEIDvMXA7s90eFl X-Received: by 2002:a17:902:2aa6:: with SMTP id j35mr38382956plb.56.1553714078822; Wed, 27 Mar 2019 12:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714078; cv=none; d=google.com; s=arc-20160816; b=1HZkYME9pDghu7BCWz87gY+Cx2i00s4ii95V2DW/fxfhEb1OsOn5oDtt4alctU559E +DysW0gUbglD9n94mAtc6ndo2dtJJ+GQs0uAkMQGJnTp54LrXJomtmY2C/ORuCB7uI6o ldDw33LdsB1W/qQzACuDZBiquCgUxWYMMWMGEQY4yaxtdUgzZjIW1bCPMr/CqGuBg3tK wysjwx0nkN/VMVFxubrd8iz1Mpbju5Xlyroi/cfgMl5pwSIKHVbGMuGw73OqiN2xZo/2 FL+OOXZ8hMb0BL9U2S8tK6zNvsd6yMBzxqn9DZAQGQFwW2qfA+duRlOlNKTueh+JUljq EV7g== 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=UubUO0qTl4kmDWgm8pXwjOUk4pphJdgzg8SUS2u+lfk=; b=ZktN2NI4P+srNqI5oHgVN+WmsB66ToL5A0xylcxHJP1p2WLIT1w12uNfoBeDYziD+F KaDkaDBfDe2uvhlZUDAvGhvhtQsJLA3ySDQYTNWiCGvuRcfhgnq5vluvPFe7ZARWyP+5 7fSRYh2ie7CSD49oqspM5Qmlpdkq077Zn5AK9ZmTewqZt43armB2k29eTqbeXyTCpPeE KsqIFBmp7RqwSzQZYAFx1qwFNNr5vzCisJR9j/XpcdD0vXC7Y76HbGIf9vO+pgLC/MLF U7+koZBYBx6TAi+JEEkDoW4x5wP+YN+HAY1TmUKNwjiDybjMWASC4/JjpPiYI+pFfuCr lR6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OZWpmB1D; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e15si18914622pgk.488.2019.03.27.12.14.23; Wed, 27 Mar 2019 12:14:38 -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; dkim=pass header.i=@kernel.org header.s=default header.b=OZWpmB1D; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388813AbfC0TNt (ORCPT + 99 others); Wed, 27 Mar 2019 15:13:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:52036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731047AbfC0SKE (ORCPT ); Wed, 27 Mar 2019 14:10:04 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7F32B2184C; Wed, 27 Mar 2019 18:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710203; bh=01VqPdlFPIK6RNZX2Ff987mTB+xR27JBA6daZlddGLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OZWpmB1D0u9jThXdFuZtEKrWZb5ZAnlEjD7gkaM7yOz47VpNq4taxePQQjGKm++O1 aFcEq9eYA25k0SkUeJhLn0CWqdiqQX3BRHBZRmu15oDPqz1lMjlI2+0LfssXNSZ/J2 VB05hi9cPY52Q4iSjlls4BPVzoMVW2jsbC1CjH1o= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peter Wu , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.0 248/262] drm/fb-helper: fix leaks in error path of drm_fb_helper_fbdev_setup Date: Wed, 27 Mar 2019 14:01:43 -0400 Message-Id: <20190327180158.10245-248-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Wu [ Upstream commit 00eb5b0da8d27b3c944bfc959c3344d665caae26 ] 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 Reviewed-by: Noralf Trønnes Signed-off-by: Noralf Trønnes Link: https://patchwork.freedesktop.org/patch/msgid/20181223005507.28328-1-peter@lekensteyn.nl Signed-off-by: Sasha Levin --- 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 70fc8e356b18..edd8cb497f3b 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -2891,7 +2891,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.19.1