[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20240930152551.1581766-1-Igor.A.Artemiev@mcst.ru>
Date: Mon, 30 Sep 2024 18:25:51 +0300
From: Igor Artemiev <Igor.A.Artemiev@...t.ru>
To: Karol Herbst <kherbst@...hat.com>
Cc: Igor Artemiev <Igor.A.Artemiev@...t.ru>, Lyude Paul <lyude@...hat.com>,
Danilo Krummrich <dakr@...hat.com>, David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>, dri-devel@...ts.freedesktop.org,
nouveau@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
lvc-project@...uxtesting.org
Subject: [PATCH] drm/nouveau/clk: prevent division by zero in gt215_clk_info()
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@...t.ru>
---
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
Powered by blists - more mailing lists