All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/v3d: Fix null pointer dereference of pointer perfmon
@ 2022-04-24 18:35 Colin Ian King
  2022-04-25  7:10 ` Juan A. Suárez
  0 siblings, 1 reply; 4+ messages in thread
From: Colin Ian King @ 2022-04-24 18:35 UTC (permalink / raw)
  To: Emma Anholt, David Airlie, Daniel Vetter, Melissa Wen,
	Juan A . Suarez Romero, dri-devel
  Cc: kernel-janitors, linux-kernel

In the unlikely event that pointer perfmon is null the WARN_ON return path
occurs after the pointer has already been deferenced. Fix this by only
dereferencing perfmon after it has been null checked.

Fixes: 26a4dc29b74a ("drm/v3d: Expose performance counters to userspace")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/gpu/drm/v3d/v3d_perfmon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/v3d/v3d_perfmon.c b/drivers/gpu/drm/v3d/v3d_perfmon.c
index 0288ef063513..f6a88abccc7d 100644
--- a/drivers/gpu/drm/v3d/v3d_perfmon.c
+++ b/drivers/gpu/drm/v3d/v3d_perfmon.c
@@ -25,11 +25,12 @@ void v3d_perfmon_start(struct v3d_dev *v3d, struct v3d_perfmon *perfmon)
 {
 	unsigned int i;
 	u32 mask;
-	u8 ncounters = perfmon->ncounters;
+	u8 ncounters;
 
 	if (WARN_ON_ONCE(!perfmon || v3d->active_perfmon))
 		return;
 
+	ncounters = perfmon->ncounters;
 	mask = GENMASK(ncounters - 1, 0);
 
 	for (i = 0; i < ncounters; i++) {
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-26 12:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-24 18:35 [PATCH] drm/v3d: Fix null pointer dereference of pointer perfmon Colin Ian King
2022-04-25  7:10 ` Juan A. Suárez
2022-04-26 12:58   ` Melissa Wen
2022-04-26 12:58     ` Melissa Wen

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.