diff mbox series

[V2] drm/tegra: fix a possible null pointer dereference

Message ID 20240602084613.220931-1-qq810974084@gmail.com (mailing list archive)
State New, archived
Headers show
Series [V2] drm/tegra: fix a possible null pointer dereference | expand

Commit Message

Huai-Yuan Liu June 2, 2024, 8:46 a.m. UTC
In malidp_tegra_crtc_reset, new memory is allocated with kzalloc, but
no check is performed. Before calling __drm_atomic_helper_crtc_reset,
mw_state should be checked to prevent possible null pointer dereference.

Fixes: b7e0b04ae450 ("drm/tegra: Convert to using __drm_atomic_helper_crtc_reset() for reset.")
Signed-off-by: Huai-Yuan Liu <qq810974084@gmail.com>
---
V2:
* In patch V2, we call __drm_atomic_helper_crtc_reset(crtc, NULL) when
state is null.
  Thanks to Thierry Reding for helpful suggestion.
---
 drivers/gpu/drm/tegra/dc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Thierry Reding June 27, 2024, 7:51 a.m. UTC | #1
On Sun Jun 2, 2024 at 10:46 AM CEST, Huai-Yuan Liu wrote:
> In malidp_tegra_crtc_reset, new memory is allocated with kzalloc, but
> no check is performed. Before calling __drm_atomic_helper_crtc_reset,
> mw_state should be checked to prevent possible null pointer dereference.

The commit message here still references variables that don't exist in
this driver. Looks like copy/paste leftovers from a similar patch?

Thierry
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index be61c9d1a4f0..afa7c269c29a 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -1388,7 +1388,10 @@  static void tegra_crtc_reset(struct drm_crtc *crtc)
 	if (crtc->state)
 		tegra_crtc_atomic_destroy_state(crtc, crtc->state);
 
-	__drm_atomic_helper_crtc_reset(crtc, &state->base);
+	if (state)
+		__drm_atomic_helper_crtc_reset(crtc, &state->base);
+	else
+		__drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 static struct drm_crtc_state *