[PATCH AUTOSEL 6.1 05/61] drm/amd/pm: Fix negative array index read

Pavel Machek pavel at denx.de
Tue Aug 27 12:29:15 UTC 2024


Hi!

> From: Jesse Zhang <jesse.zhang at amd.com>
> 
> [ Upstream commit c8c19ebf7c0b202a6a2d37a52ca112432723db5f ]
> 
> Avoid using the negative values
> for clk_idex as an index into an array pptable->DpmDescriptor.
> 
> V2: fix clk_index return check (Tim Huang)

>  	dpm_desc = &pptable->DpmDescriptor[clk_index];
>  
>  	/* 0 - Fine grained DPM, 1 - Discrete DPM */
> -	return dpm_desc->SnapToDiscrete == 0;
> +	return dpm_desc->SnapToDiscrete == 0 ? 1 : 0;
>  }
>

Original code was already returning 0/1, no need for this. You could
use !!() to emphatise that, but really....

> +		if (ret) {
>  			soft_max_level = (soft_max_level >= 1 ? 1 : 0);
>  			soft_min_level = (soft_min_level >= 1 ? 1 : 0);

Same here.

Best regards,
								Pavel

-- 
DENX Software Engineering GmbH,        Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20240827/d77a056c/attachment.sig>


More information about the dri-devel mailing list