[PATCH 1/7] drm/xe: Add null pointer check for xe_migrate_copy

Zhanjun Dong zhanjun.dong at intel.com
Tue Sep 17 17:43:18 UTC 2024


Add null pointer check for parameter src.

Signed-off-by: Zhanjun Dong <zhanjun.dong at intel.com>
---
 drivers/gpu/drm/xe/xe_migrate.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index cfd31ae49cc1..45bba0d731ec 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -774,14 +774,22 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m,
 	u64 src_L0, dst_L0;
 	int pass = 0;
 	int err;
-	bool src_is_pltt = src->mem_type == XE_PL_TT;
-	bool dst_is_pltt = dst->mem_type == XE_PL_TT;
-	bool src_is_vram = mem_type_is_vram(src->mem_type);
-	bool dst_is_vram = mem_type_is_vram(dst->mem_type);
-	bool copy_ccs = xe_device_has_flat_ccs(xe) &&
-		xe_bo_needs_ccs_pages(src_bo) && xe_bo_needs_ccs_pages(dst_bo);
-	bool copy_system_ccs = copy_ccs && (!src_is_vram || !dst_is_vram);
-	bool use_comp_pat = xe_device_has_flat_ccs(xe) &&
+	bool src_is_pltt, dst_is_pltt;
+	bool src_is_vram, dst_is_vram;
+	bool copy_ccs, copy_system_ccs;
+	bool use_comp_pat;
+
+	if (!src)
+		return ERR_PTR(-EINVAL);
+
+	src_is_pltt = src->mem_type == XE_PL_TT;
+	dst_is_pltt = dst->mem_type == XE_PL_TT;
+	src_is_vram = mem_type_is_vram(src->mem_type);
+	dst_is_vram = mem_type_is_vram(dst->mem_type);
+	copy_ccs = xe_device_has_flat_ccs(xe) && xe_bo_needs_ccs_pages(src_bo) &&
+		xe_bo_needs_ccs_pages(dst_bo);
+	copy_system_ccs = copy_ccs && (!src_is_vram || !dst_is_vram);
+	use_comp_pat = xe_device_has_flat_ccs(xe) &&
 		GRAPHICS_VER(xe) >= 20 && src_is_vram && !dst_is_vram;
 
 	/* Copying CCS between two different BOs is not supported yet. */
-- 
2.34.1



More information about the Intel-xe mailing list