From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AD2F1917C4; Tue, 10 Sep 2024 10:40:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725964827; cv=none; b=ggNg7a8oJhzMfZsTnR6PgUuLMIcERK1E/muU26VJKwH5DC4fN6hpUvU8zUSaF3gRo2E/TwJdPys8CKEPbPFp+hyZDM+twiQD8eL0n2p7WDj7M3SlAz9AjjyYwo5l6ypFPioXXhmoWYP0N4QwGgaU0zPagCQELAtMxZjfdVfeoNI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725964827; c=relaxed/simple; bh=JrZoiD2azRd4Cuuj/Dc6Clt7uZb9xQZEe+aCuVYBduA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mHzq38wbaPT2RGJjRmTUveMbEFwh9IZ62lYPSIYf1gsjhnjdV5JCFSYa2WiqvVovg118iLt3jt0SsCKRrAFlBJ2xyuRnHXALCA1S4vq7vIM5Frr2R3MT0ESp0zWYYIH/3vr1Sd0TJm58b8vCMWMG1S0YO6+OINtS3Gv/lvBk11g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=R/ybfoau; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="R/ybfoau" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 932F4C4CECE; Tue, 10 Sep 2024 10:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725964827; bh=JrZoiD2azRd4Cuuj/Dc6Clt7uZb9xQZEe+aCuVYBduA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R/ybfoaueZJomAGbdKYUZfCrh1gy84HAMjmTgzVKuBADtJq04iW2R9eDVfnxi9fMs cWS1a+1+zln6P9osu2oSwfoeE1NE6ECfqZM1xu5j34c4jNsP4m6L/vdBjDDEWRJD24 I2YPiPGPKQ2JMmYTlJS6zyTjcUlmKVYyi6ForF5g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bob Zhou , Tim Huang , Alex Deucher , Sasha Levin , Mukul Sikka Subject: [PATCH 5.10 045/186] drm/amd/pm: Fix the null pointer dereference for vega10_hwmgr Date: Tue, 10 Sep 2024 11:32:20 +0200 Message-ID: <20240910092556.375156071@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092554.645718780@linuxfoundation.org> References: <20240910092554.645718780@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bob Zhou commit 50151b7f1c79a09117837eb95b76c2de76841dab upstream. Check return value and conduct null pointer handling to avoid null pointer dereference. Signed-off-by: Bob Zhou Reviewed-by: Tim Huang Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin Signed-off-by: Mukul Sikka Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c | 30 +++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c @@ -3410,13 +3410,17 @@ static int vega10_find_dpm_states_clocks const struct vega10_power_state *vega10_ps = cast_const_phw_vega10_power_state(states->pnew_state); struct vega10_single_dpm_table *sclk_table = &(data->dpm_table.gfx_table); - uint32_t sclk = vega10_ps->performance_levels - [vega10_ps->performance_level_count - 1].gfx_clock; struct vega10_single_dpm_table *mclk_table = &(data->dpm_table.mem_table); - uint32_t mclk = vega10_ps->performance_levels - [vega10_ps->performance_level_count - 1].mem_clock; + uint32_t sclk, mclk; uint32_t i; + if (vega10_ps == NULL) + return -EINVAL; + sclk = vega10_ps->performance_levels + [vega10_ps->performance_level_count - 1].gfx_clock; + mclk = vega10_ps->performance_levels + [vega10_ps->performance_level_count - 1].mem_clock; + for (i = 0; i < sclk_table->count; i++) { if (sclk == sclk_table->dpm_levels[i].value) break; @@ -3723,6 +3727,9 @@ static int vega10_generate_dpm_level_ena cast_const_phw_vega10_power_state(states->pnew_state); int i; + if (vega10_ps == NULL) + return -EINVAL; + PP_ASSERT_WITH_CODE(!vega10_trim_dpm_states(hwmgr, vega10_ps), "Attempt to Trim DPM States Failed!", return -1); @@ -4858,6 +4865,9 @@ static int vega10_check_states_equal(str psa = cast_const_phw_vega10_power_state(pstate1); psb = cast_const_phw_vega10_power_state(pstate2); + if (psa == NULL || psb == NULL) + return -EINVAL; + /* If the two states don't even have the same number of performance levels they cannot be the same state. */ if (psa->performance_level_count != psb->performance_level_count) { *equal = false; @@ -4983,6 +4993,8 @@ static int vega10_set_sclk_od(struct pp_ return -EINVAL; vega10_ps = cast_phw_vega10_power_state(&ps->hardware); + if (vega10_ps == NULL) + return -EINVAL; vega10_ps->performance_levels [vega10_ps->performance_level_count - 1].gfx_clock = @@ -5034,6 +5046,8 @@ static int vega10_set_mclk_od(struct pp_ return -EINVAL; vega10_ps = cast_phw_vega10_power_state(&ps->hardware); + if (vega10_ps == NULL) + return -EINVAL; vega10_ps->performance_levels [vega10_ps->performance_level_count - 1].mem_clock = @@ -5269,6 +5283,9 @@ static void vega10_odn_update_power_stat return; vega10_ps = cast_phw_vega10_power_state(&ps->hardware); + if (vega10_ps == NULL) + return; + max_level = vega10_ps->performance_level_count - 1; if (vega10_ps->performance_levels[max_level].gfx_clock != @@ -5291,6 +5308,9 @@ static void vega10_odn_update_power_stat ps = (struct pp_power_state *)((unsigned long)(hwmgr->ps) + hwmgr->ps_size * (hwmgr->num_ps - 1)); vega10_ps = cast_phw_vega10_power_state(&ps->hardware); + if (vega10_ps == NULL) + return; + max_level = vega10_ps->performance_level_count - 1; if (vega10_ps->performance_levels[max_level].gfx_clock != @@ -5481,6 +5501,8 @@ static int vega10_get_performance_level( return -EINVAL; ps = cast_const_phw_vega10_power_state(state); + if (ps == NULL) + return -EINVAL; i = index > ps->performance_level_count - 1 ? ps->performance_level_count - 1 : index;