dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Sasha Levin <sashal@kernel.org>,
	airlied@linux.ie, Liviu Dudau <liviu.dudau@arm.com>,
	Steven Price <steven.price@arm.com>,
	dri-devel@lists.freedesktop.org, tzimmermann@suse.de
Subject: [PATCH AUTOSEL 5.18 065/159] drm/plane: Move range check for format_count earlier
Date: Mon, 30 May 2022 09:22:50 -0400	[thread overview]
Message-ID: <20220530132425.1929512-65-sashal@kernel.org> (raw)
In-Reply-To: <20220530132425.1929512-1-sashal@kernel.org>

From: Steven Price <steven.price@arm.com>

[ Upstream commit 4b674dd69701c2e22e8e7770c1706a69f3b17269 ]

While the check for format_count > 64 in __drm_universal_plane_init()
shouldn't be hit (it's a WARN_ON), in its current position it will then
leak the plane->format_types array and fail to call
drm_mode_object_unregister() leaking the modeset identifier. Move it to
the start of the function to avoid allocating those resources in the
first place.

Signed-off-by: Steven Price <steven.price@arm.com>
Signed-off-by: Liviu Dudau <liviu.dudau@arm.com>
Link: https://lore.kernel.org/dri-devel/20211203102815.38624-1-steven.price@arm.com/
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/drm_plane.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index bf0daa8d9bbd..726f2f163c26 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -247,6 +247,13 @@ static int __drm_universal_plane_init(struct drm_device *dev,
 	if (WARN_ON(config->num_total_plane >= 32))
 		return -EINVAL;
 
+	/*
+	 * First driver to need more than 64 formats needs to fix this. Each
+	 * format is encoded as a bit and the current code only supports a u64.
+	 */
+	if (WARN_ON(format_count > 64))
+		return -EINVAL;
+
 	WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
 		(!funcs->atomic_destroy_state ||
 		 !funcs->atomic_duplicate_state));
@@ -268,13 +275,6 @@ static int __drm_universal_plane_init(struct drm_device *dev,
 		return -ENOMEM;
 	}
 
-	/*
-	 * First driver to need more than 64 formats needs to fix this. Each
-	 * format is encoded as a bit and the current code only supports a u64.
-	 */
-	if (WARN_ON(format_count > 64))
-		return -EINVAL;
-
 	if (format_modifiers) {
 		const uint64_t *temp_modifiers = format_modifiers;
 
-- 
2.35.1


  parent reply	other threads:[~2022-05-30 13:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220530132425.1929512-1-sashal@kernel.org>
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 002/159] drm/selftests: fix a shift-out-of-bounds bug Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 003/159] drm/vmwgfx: validate the screen formats Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 005/159] drm/virtio: fix NULL pointer dereference in virtio_gpu_conn_get_modes Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 017/159] fbcon: Consistently protect deferred_takeover with console_lock() Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 022/159] drm/komeda: return early if drm_universal_plane_init() fails Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 023/159] drm/amd/display: Disabling Z10 on DCN31 Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 042/159] drm/amdgpu/pm: fix the null pointer while the smu is disabled Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 043/159] drm/amd/pm: fix double free in si_parse_power_table() Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 057/159] drm/sun4i: Add support for D1 TCONs Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 059/159] drm/amdgpu/sdma: Fix incorrect calculations of the wptr of the doorbells Sasha Levin
2022-05-30 13:22 ` Sasha Levin [this message]
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 066/159] drm/amdkfd: Fix circular lock dependency warning Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 067/159] drm/amd/pm: fix the compile warning Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 070/159] drm: msm: fix error check return value of irq_of_parse_and_map() Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 082/159] drm/amdgpu/psp: move PSP memory alloc from hw_init to sw_init Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 083/159] drm/amdgpu/ucode: Remove firmware load type check in amdgpu_ucode_free_bo Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 087/159] drm/tegra: gem: Do not try to dereference ERR_PTR() Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 129/159] drm/amd/pm: update smartshift powerboost calc for smu12 Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 131/159] drm/amdgpu: Move mutex_init(&smu->message_lock) to smu_early_init() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220530132425.1929512-65-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liviu.dudau@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=steven.price@arm.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).