Blob Blame History Raw
From: Dave Airlie <airlied@redhat.com>
Date: Tue, 7 Nov 2017 05:21:18 +1000
Subject: amdgpu/dc: handle allocation failures in dc_commit_planes_to_stream.
Git-commit: f7dbc385c15084d6e11192e8a5dd901eb96dbec2
Patch-mainline: v4.15-rc1
References: FATE#326289 FATE#326079 FATE#326049 FATE#322398 FATE#326166

Reported-by smatch:
drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc.c:966 dc_commit_planes_to_stream() error: potential null dereference 'flip_addr'.  (kcalloc returns null)
drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc.c:968 dc_commit_planes_to_stream() error: potential null dereference 'plane_info'.  (kcalloc returns null)
drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc.c:978 dc_commit_planes_to_stream() error: potential null dereference 'scaling_info'.  (kcalloc returns null)

Reviewed-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Petr Tesarik <ptesarik@suse.com>
---
 drivers/gpu/drm/amd/display/dc/core/dc.c |    8 ++++++++
 1 file changed, 8 insertions(+)

--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -952,6 +952,14 @@ bool dc_commit_planes_to_stream(
 	scaling_info = kcalloc(MAX_SURFACES, sizeof(struct dc_scaling_info),
 			       GFP_KERNEL);
 
+	if (!flip_addr || !plane_info || !scaling_info) {
+		kfree(flip_addr);
+		kfree(plane_info);
+		kfree(scaling_info);
+		kfree(stream_update);
+		return false;
+	}
+
 	memset(updates, 0, sizeof(updates));
 
 	stream_update->src = dc_stream->src;