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

From: Pavel Machek
Date: Tue Aug 27 2024 - 08:29:50 EST


Hi!

> From: Jesse Zhang <jesse.zhang@xxxxxxx>
>
> [ 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

Attachment: signature.asc
Description: PGP signature