[PATCH][next] drm/xe/guc: Fix dereference before Null check
From: Everest K.C.
Date: Wed Oct 09 2024 - 14:51:29 EST
The pointer list->list was derefrenced before the Null check
resulting in possibility of Null pointer derefrencing.
This patch moves the Null check outside the for loop, so that
the check is performed before the derefrencing.
This issue was reported by Coverity Scan.
Signed-off-by: Everest K.C. <everestkc@xxxxxxxxxxxxxxxx>
---
drivers/gpu/drm/xe/xe_guc_capture.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_guc_capture.c b/drivers/gpu/drm/xe/xe_guc_capture.c
index 41262bda20ed..de63c622747d 100644
--- a/drivers/gpu/drm/xe/xe_guc_capture.c
+++ b/drivers/gpu/drm/xe/xe_guc_capture.c
@@ -1537,13 +1537,13 @@ read_reg_to_node(struct xe_hw_engine *hwe, const struct __guc_mmio_reg_descr_gro
if (!regs)
return;
+ if (!list->list)
+ return;
+
for (i = 0; i < list->num_regs; i++) {
struct __guc_mmio_reg_descr desc = list->list[i];
u32 value;
- if (!list->list)
- return;
-
if (list->type == GUC_STATE_CAPTURE_TYPE_ENGINE_INSTANCE) {
value = xe_hw_engine_mmio_read32(hwe, desc.reg);
} else {
--
2.43.0