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

Pavel Machek
2024-08-27T12:29:17Z

[-- Attachment #1: Type: text/plain, Size: 925 bytes --]

Hi!

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]