Skip to contentSkip to conversation

drm/vc4: perfmon: Fix variable dereferenced before check

PATCH Applied Maxime Ripard 2 participants 3 messages Jun 22, 2022 – Jun 27, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vc4: perfmon: Fix variable dereferenced before check

Commit 30f8c74ca9b7 ("drm/vc4: Warn if some v3d code is run on BCM2711") introduced a check in vc4_perfmon_get() that dereferences a pointer before we checked whether that pointer is valid or not.

Let's rework that function a bit to do things in the proper order.

Fixes 30f8c74ca9b7 ("drm/vc4: Warn if some v3d code is run on BCM2711")
---
 drivers/gpu/drm/vc4/vc4_perfmon.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/vc4/vc4_perfmon.c +6 -3
index c7f5adb6bcf8..79a74184d732 100644
@@ -17,13 +17,16 @@
 
 void vc4_perfmon_get(struct vc4_perfmon *perfmon)
 {
-	struct vc4_dev *vc4 = perfmon->dev;
+	struct vc4_dev *vc4;
 
+	if (!perfmon)
+		return;
+
+	vc4 = perfmon->dev;
 	if (WARN_ON_ONCE(vc4->is_vc5))
 		return;
 
-	if (perfmon)
-		refcount_inc(&perfmon->refcnt);
+	refcount_inc(&perfmon->refcnt);
 }
 
 void vc4_perfmon_put(struct vc4_perfmon *perfmon)
Signature · 1 line
2.36.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Maxime Ripard

Commit 30f8c74ca9b7 ("drm/vc4: Warn if some v3d code is run on BCM2711") introduced a check in vc4_perfmon_get() that dereferences a pointer before we checked whether that pointer is valid or not.

Let's rework that function a bit to do things in the proper order.

Fixes 30f8c74ca9b7 ("drm/vc4: Warn if some v3d code is run on BCM2711")

I was about to send the same patch because Coverity reported this issue today, but you already found and fixed it :D

Best wishes,
José Expósito

author Applied
#2 lore raw

Re: (subset) [PATCH] drm/vc4: perfmon: Fix variable dereferenced before check

In reply to Maxime Ripard
Quoted 8 lines · Maxime Ripard

Commit 30f8c74ca9b7 ("drm/vc4: Warn if some v3d code is run on BCM2711") introduced a check in vc4_perfmon_get() that dereferences a pointer before we checked whether that pointer is valid or not.

Let's rework that function a bit to do things in the proper order.

[...]

Applied to drm/drm-misc (drm-misc-fixes).

Thanks!
Maxime