[lvc-project] [PATCH] drm/nouveau/clk: prevent division by zero in gt215_clk_info()
Fedor Pchelkin
pchelkin at ispras.ru
Sat Oct 5 13:57:59 MSK 2024
On Mon, 30. Sep 18:25, Igor Artemiev wrote:
> sdiv can be zero if read_vco() returns 0 or khz is greater than sclk*2.
> This value will cause a division-by-zero error in the gt215_clk_info() function.
>
> Add a check before division.
>
> Found by Linux Verification Center (linuxtesting.org) with static
> analysis tool SVACE.
>
> Signed-off-by: Igor Artemiev <Igor.A.Artemiev at mcst.ru>
> ---
Патч добавлен в LVC-5.10 и 6.1. Спасибо!
> drivers/gpu/drm/nouveau/nvkm/subdev/clk/gt215.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/gt215.c b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/gt215.c
> index b5f3969727a2..4c53442b4167 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/gt215.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/gt215.c
> @@ -206,6 +206,9 @@ gt215_clk_info(struct nvkm_clk *base, int idx, u32 khz,
> default:
> sclk = read_vco(clk, idx);
> sdiv = min((sclk * 2) / khz, (u32)65);
> + if (!sdiv)
> + return -EINVAL;
> +
> oclk = (sclk * 2) / sdiv;
> diff = ((khz + 3000) - oclk);
>
> --
> 2.39.2
More information about the lvc-project
mailing list