All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zeng Jingxiang <zengjx95@gmail.com>
To: anitha.chrisanthus@intel.com, edmund.j.dea@intel.com,
	airlied@linux.ie, daniel@ffwll.ch, tzimmermann@suse.de,
	laurent.pinchart@ideasonboard.com, maxime@cerno.tech,
	ville.syrjala@linux.intel.com
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Zeng Jingxiang <linuszeng@tencent.com>
Subject: [PATCH] drm/kmb: fix dereference before NULL check in kmb_plane_atomic_update()
Date: Fri, 29 Jul 2022 11:07:11 +0800	[thread overview]
Message-ID: <20220729030711.2117849-1-zengjx95@gmail.com> (raw)

From: Zeng Jingxiang <linuszeng@tencent.com>

The "plane" pointer was access before checking if it was NULL.

The drm_atomic_get_old_plane_state() function will dereference
the pointer "plane".
345	struct drm_plane_state *old_plane_state =
		drm_atomic_get_old_plane_state(state, plane);
346	struct drm_plane_state *new_plane_state =
		drm_atomic_get_new_plane_state(state, plane);

A NULL check for "plane" indicates that it may be NULL
363	if (!plane || !new_plane_state || !old_plane_state)

Fixes: 977697e20b3d ("drm/atomic: Pass the full state to planes atomic disable and update")
Fixes: 37418bf14c13 ("drm: Use state helper instead of the plane state pointer")
Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
---
 drivers/gpu/drm/kmb/kmb_plane.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/kmb/kmb_plane.c b/drivers/gpu/drm/kmb/kmb_plane.c
index 2735b8eb3537..d2bc998b65ce 100644
--- a/drivers/gpu/drm/kmb/kmb_plane.c
+++ b/drivers/gpu/drm/kmb/kmb_plane.c
@@ -342,10 +342,7 @@ static void kmb_plane_set_alpha(struct kmb_drm_private *kmb,
 static void kmb_plane_atomic_update(struct drm_plane *plane,
 				    struct drm_atomic_state *state)
 {
-	struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state,
-										 plane);
-	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
-										 plane);
+	struct drm_plane_state *old_plane_state, *new_plane_state;
 	struct drm_framebuffer *fb;
 	struct kmb_drm_private *kmb;
 	unsigned int width;
@@ -360,7 +357,13 @@ static void kmb_plane_atomic_update(struct drm_plane *plane,
 	static dma_addr_t addr[MAX_SUB_PLANES];
 	struct disp_cfg *init_disp_cfg;
 
-	if (!plane || !new_plane_state || !old_plane_state)
+	if (!plane)
+		return;
+
+	old_plane_state = drm_atomic_get_old_plane_state(state, plane);
+	new_plane_state = drm_atomic_get_new_plane_state(state, plane);
+
+	if (!new_plane_state || !old_plane_state)
 		return;
 
 	fb = new_plane_state->fb;
-- 
2.27.0


WARNING: multiple messages have this Message-ID (diff)
From: Zeng Jingxiang <zengjx95@gmail.com>
To: anitha.chrisanthus@intel.com, edmund.j.dea@intel.com,
	airlied@linux.ie, daniel@ffwll.ch, tzimmermann@suse.de,
	laurent.pinchart@ideasonboard.com, maxime@cerno.tech,
	ville.syrjala@linux.intel.com
Cc: Zeng Jingxiang <linuszeng@tencent.com>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: [PATCH] drm/kmb: fix dereference before NULL check in kmb_plane_atomic_update()
Date: Fri, 29 Jul 2022 11:07:11 +0800	[thread overview]
Message-ID: <20220729030711.2117849-1-zengjx95@gmail.com> (raw)

From: Zeng Jingxiang <linuszeng@tencent.com>

The "plane" pointer was access before checking if it was NULL.

The drm_atomic_get_old_plane_state() function will dereference
the pointer "plane".
345	struct drm_plane_state *old_plane_state =
		drm_atomic_get_old_plane_state(state, plane);
346	struct drm_plane_state *new_plane_state =
		drm_atomic_get_new_plane_state(state, plane);

A NULL check for "plane" indicates that it may be NULL
363	if (!plane || !new_plane_state || !old_plane_state)

Fixes: 977697e20b3d ("drm/atomic: Pass the full state to planes atomic disable and update")
Fixes: 37418bf14c13 ("drm: Use state helper instead of the plane state pointer")
Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
---
 drivers/gpu/drm/kmb/kmb_plane.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/kmb/kmb_plane.c b/drivers/gpu/drm/kmb/kmb_plane.c
index 2735b8eb3537..d2bc998b65ce 100644
--- a/drivers/gpu/drm/kmb/kmb_plane.c
+++ b/drivers/gpu/drm/kmb/kmb_plane.c
@@ -342,10 +342,7 @@ static void kmb_plane_set_alpha(struct kmb_drm_private *kmb,
 static void kmb_plane_atomic_update(struct drm_plane *plane,
 				    struct drm_atomic_state *state)
 {
-	struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state,
-										 plane);
-	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
-										 plane);
+	struct drm_plane_state *old_plane_state, *new_plane_state;
 	struct drm_framebuffer *fb;
 	struct kmb_drm_private *kmb;
 	unsigned int width;
@@ -360,7 +357,13 @@ static void kmb_plane_atomic_update(struct drm_plane *plane,
 	static dma_addr_t addr[MAX_SUB_PLANES];
 	struct disp_cfg *init_disp_cfg;
 
-	if (!plane || !new_plane_state || !old_plane_state)
+	if (!plane)
+		return;
+
+	old_plane_state = drm_atomic_get_old_plane_state(state, plane);
+	new_plane_state = drm_atomic_get_new_plane_state(state, plane);
+
+	if (!new_plane_state || !old_plane_state)
 		return;
 
 	fb = new_plane_state->fb;
-- 
2.27.0


             reply	other threads:[~2022-07-29  3:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-29  3:07 Zeng Jingxiang [this message]
2022-07-29  3:07 ` [PATCH] drm/kmb: fix dereference before NULL check in kmb_plane_atomic_update() Zeng Jingxiang
2022-07-29 14:23 ` Thomas Zimmermann
2022-07-29 14:23   ` Thomas Zimmermann
2022-07-29 14:25   ` Thomas Zimmermann
2022-07-29 16:40     ` Chrisanthus, Anitha
2022-08-01 10:27       ` Thomas Zimmermann

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=20220729030711.2117849-1-zengjx95@gmail.com \
    --to=zengjx95@gmail.com \
    --cc=airlied@linux.ie \
    --cc=anitha.chrisanthus@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=edmund.j.dea@intel.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linuszeng@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime@cerno.tech \
    --cc=tzimmermann@suse.de \
    --cc=ville.syrjala@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.