[next] drm/amd/display: don't release dc->current_state if it is null

Submitted by Colin King on June 29, 2019, 12:27 p.m.

Details

Message ID 20190629122750.12219-1-colin.king@canonical.com
State New
Headers show
Series "drm/amd/display: don't release dc->current_state if it is null" ( rev: 1 ) in DRI devel

Not browsing as part of any series.

Commit Message

Colin King June 29, 2019, 12:27 p.m.
From: Colin Ian King <colin.king@canonical.com>

Currently function construct calls destruct if the allocation of
dc->current_state fails, however, the destruct function will
attempt dereference dc->current_state when calling dc_release_state.
Avoid this null pointer dereference by checking if the pointer is
not null before calling dc_release_state.

Addresses-Coverity: ("Dereference after null check")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c
index 18c775a950cc..0e1f132ae310 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -608,8 +608,10 @@  const struct dc_link_settings *dc_link_get_link_cap(
 
 static void destruct(struct dc *dc)
 {
-	dc_release_state(dc->current_state);
-	dc->current_state = NULL;
+	if (dc->current_state) {
+		dc_release_state(dc->current_state);
+		dc->current_state = NULL;
+	}
 
 	destroy_links(dc);