From patchwork Thu Feb 8 12:37:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Zhandarovich X-Patchwork-Id: 198377 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp133149dyd; Thu, 8 Feb 2024 04:37:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4Gijq847M5R6T3bzTOMIqkOqf6X1VRf/YR0LMee8YUBJbysTnFcFl9phVeDWCyFoWohDl X-Received: by 2002:a05:6402:3183:b0:561:123d:ed73 with SMTP id di3-20020a056402318300b00561123ded73mr1003324edb.31.1707395863909; Thu, 08 Feb 2024 04:37:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707395863; cv=pass; d=google.com; s=arc-20160816; b=ZHcbo8LW44kLgS3i0GBZbLcxKSX5Afq+nv3jhs20jVjWaHs9+vxlJt4e3DP/gfBHlU do1FkdZX/nginvUTkI4Mt71YIVjIT+k5wQqqoKfWTBuf/BD6EPi3BxnkahGGjQd5czou nT/UzuDtvjhodQb535e4Wqlo6nnuazSAAzv65z/D2E1PRPMlnJkgYGjUQF5rMKnuORZC mxyiiIMXH/2wDTza8Cnbty4ipC/PGEFvzyHbeME6s7nqiSb/djYySZhZ18e/wnSSgWFi NMcsCcVr7DM5te8FDXbLxtJV25jsKhdjQoEZ1bfqiAAOkrmyYGkotIM6EdC12Q+TjGnr JBqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=a6n23J90H73uvSPoqHR6vZBsbQOBpnp/BJSxjanELLw=; fh=/D3EwO+UAFifJK+WbcRxrKer3NSN+51kTaao5ZtfsY0=; b=x00TEF+VJUzd5tasK58cU+EDeLlZeK2yYkPu+mpxfdAIBGsLRAa5qN/zWoktGQn/Ri FhcSkK3hrCtm8RHI5PxilcFdKzeMX2Q/HBjL7jIdSbZfpvf1plOJuwnSIUoS+SNMuJ9K dS1/9fDSuF9qwVEtZv8klZTUqYrcPLm43jwbpU5LRmeylU/gJqFAzQV8u95y+BqZ4vcY YtZt1Kr6/zs3C/RfSWO0s1XYxpo6tmKe0lqUvoBcG373Hd8yPcZITsqIHYI/+dBb4NSD SDzIGiRepfQzh3Zw5jSjmAX3bUytgho4LHR4KVpbZXU/TXvKWpA9KnmHZPJ7w9uuIxqi nUpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=fintech.ru); spf=pass (google.com: domain of linux-kernel+bounces-58065-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58065-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCW/816nPJmp+1zV4ha4bfzC1Wb/+ntlbdHMVwnKHKo15d61HOeH1G+5CMJPpqGgoxBZA05uujIrd9sT/wjT/TMcs0c4Zw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dh9-20020a0564021d2900b00560e03ed12esi824673edb.173.2024.02.08.04.37.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:37:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58065-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=fintech.ru); spf=pass (google.com: domain of linux-kernel+bounces-58065-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58065-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 85C821F22DEC for ; Thu, 8 Feb 2024 12:37:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56E7B762D8; Thu, 8 Feb 2024 12:37:30 +0000 (UTC) Received: from exchange.fintech.ru (exchange.fintech.ru [195.54.195.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E07C46F079 for ; Thu, 8 Feb 2024 12:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.54.195.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707395848; cv=none; b=X4nD47W8WQ/J+AKEit/CfZCtJ6Hy2UHxar7Z5roBF5v+tuVD2mYdR9MheeIgYinPeBvL2Z0OGkaltrUcPDmnL94Q6tP0K0dNuRghtBur1gm7drwd1i47mG1idE4rPz8SG+W4zp3DqtYWToxL5YKhp+92cdrhUKp4U4cJfZlY4Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707395848; c=relaxed/simple; bh=SMxSSIouZobaeMXDonh6APoF96Mk6tvwC3mgcseiygE=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Q8hJkcjFhGc9AnINL+KrQ1nJY7OTRd15ZD7eJelPSQ88nwEu0GMfpccHHCm00baeNtzVS3LI0dOa4j7WXaGLpAj6yua68GV/lLwDJ9opRYKyrOZbYZKVUYkyHTK+/lD9U6cfLZaXVfQ5zPCE06lPCDnuxE8gdGmntRMHIuk2oeo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fintech.ru; spf=pass smtp.mailfrom=fintech.ru; arc=none smtp.client-ip=195.54.195.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fintech.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fintech.ru Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Thu, 8 Feb 2024 15:37:15 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Thu, 8 Feb 2024 15:37:15 +0300 From: Nikita Zhandarovich To: Harry Wentland CC: Nikita Zhandarovich , Leo Li , Rodrigo Siqueira , "Alex Deucher" , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Leon Huang , , , , Subject: [PATCH] drm/amd/display: Fix missing NULL check in dcn21_set_backlight_level() Date: Thu, 8 Feb 2024 04:37:11 -0800 Message-ID: <20240208123711.52333-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790334325370920834 X-GMAIL-MSGID: 1790334325370920834 On the off chance 'panel_cntl' ends up being not properly initialized, dcn21_set_backlight_level() may hit NULL pointer dereference while changing embedded panel backlight levels. Prevent this issue by using some of the existing checks for the similar purpose. At the same time clean up redundant tests for NULL in 'abm'. Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE. Fixes: 6f0ef80a00ad ("drm/amd/display: Fix ABM pipe/backlight issues when change backlight") Signed-off-by: Nikita Zhandarovich --- drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c b/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c index 8e88dcaf88f5..2b1b580541a8 100644 --- a/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c +++ b/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c @@ -247,7 +247,7 @@ bool dcn21_set_backlight_level(struct pipe_ctx *pipe_ctx, if (abm != NULL) { uint32_t otg_inst = pipe_ctx->stream_res.tg->inst; - if (abm && panel_cntl) { + if (panel_cntl) { if (abm->funcs && abm->funcs->set_pipe_ex) { abm->funcs->set_pipe_ex(abm, otg_inst, @@ -261,15 +261,16 @@ bool dcn21_set_backlight_level(struct pipe_ctx *pipe_ctx, panel_cntl->inst, panel_cntl->pwrseq_inst); } + + if (abm->funcs && abm->funcs->set_backlight_level_pwm) + abm->funcs->set_backlight_level_pwm(abm, backlight_pwm_u16_16, + frame_ramp, 0, panel_cntl->inst); + else + dmub_abm_set_backlight(dc, backlight_pwm_u16_16, frame_ramp, + panel_cntl->inst); } } - if (abm && abm->funcs && abm->funcs->set_backlight_level_pwm) - abm->funcs->set_backlight_level_pwm(abm, backlight_pwm_u16_16, - frame_ramp, 0, panel_cntl->inst); - else - dmub_abm_set_backlight(dc, backlight_pwm_u16_16, frame_ramp, panel_cntl->inst); - return true; }