Skip to contentSkip to conversation

drm/amd/pm: Prevent divide by zero

PATCH In review Yefim Barashkin 3 participants 3 messages Jul 12, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/pm: Prevent divide by zero

divide error: 0000 [#1] SMP PTI

CPU: 3 PID: 78925 Comm: tee Not tainted 5.15.50-1-lts #1
Hardware name: MSI MS-7A59/Z270 SLI PLUS (MS-7A59), BIOS 1.90 01/30/2018
RIP: 0010:smu_v11_0_set_fan_speed_rpm+0x11/0x110 [amdgpu]

Speed is user-configurable through a file.
I accidentally set it to zero, and the driver crashed.

---
 drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c +4 -0
index 5f8809f6990d..69cebdb58c04 100644
@@ -1236,6 +1236,10 @@ int smu_v11_0_set_fan_speed_rpm(struct smu_context *smu,
 	 * - For some Sienna Cichlid SKU, the fan speed cannot be set
 	 *   lower than 500 RPM.
 	 */
+
+	if (speed == 0)
+		return -EINVAL;
+
 	tach_period = 60 * crystal_clock_freq * 10000 / (8 * speed);
 	WREG32_SOC15(THM, 0, mmCG_TACH_CTRL,
 		     REG_SET_FIELD(RREG32_SOC15(THM, 0, mmCG_TACH_CTRL),

--
2.36.1

Sorry about the mess with my name and formatting. It should be fixed now, hopefully.

#1 lore raw

[AMD Official Use Only - General]

Thanks for the fix! Patch is reviewed-by: Evan Quan <[email protected]>

BR
Evan

Quoted 44 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Yefim Barashkin
Sent: Tuesday, July 12, 2022 10:01 AM
To: [email protected]
Cc: Yefim Barashkin <[email protected]>
Subject: [PATCH] drm/amd/pm: Prevent divide by zero

divide error: 0000 [#1] SMP PTI

CPU: 3 PID: 78925 Comm: tee Not tainted 5.15.50-1-lts #1 Hardware name:
MSI MS-7A59/Z270 SLI PLUS (MS-7A59), BIOS 1.90 01/30/2018
RIP: 0010:smu_v11_0_set_fan_speed_rpm+0x11/0x110 [amdgpu]

Speed is user-configurable through a file.
I accidentally set it to zero, and the driver crashed.

---
 drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c +4 -0
index 5f8809f6990d..69cebdb58c04 100644
@@ -1236,6 +1236,10 @@ int smu_v11_0_set_fan_speed_rpm(struct
 smu_context *smu,
 	 * - For some Sienna Cichlid SKU, the fan speed cannot be set
 	 *   lower than 500 RPM.
 	 */
+
+	if (speed == 0)
+		return -EINVAL;
+
 	tach_period = 60 * crystal_clock_freq * 10000 / (8 * speed);
 	WREG32_SOC15(THM, 0, mmCG_TACH_CTRL,

REG_SET_FIELD(RREG32_SOC15(THM, 0,
mmCG_TACH_CTRL),
--
2.36.1

Sorry about the mess with my name and formatting. It should be fixed now, hopefully.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Yefim Barashkin

Às 23:01 de 11/07/22, Yefim Barashkin escreveu:

Quoted 10 lines

divide error: 0000 [#1] SMP PTI

CPU: 3 PID: 78925 Comm: tee Not tainted 5.15.50-1-lts #1
Hardware name: MSI MS-7A59/Z270 SLI PLUS (MS-7A59), BIOS 1.90 01/30/2018
RIP: 0010:smu_v11_0_set_fan_speed_rpm+0x11/0x110 [amdgpu]

Speed is user-configurable through a file.
I accidentally set it to zero, and the driver crashed.

---

Minor nit, I would write this commit message like this:

Speed is user-configurable through a file. I accidentally set it to zero, and the driver crashed:

divide error: 0000 [#1] SMP PTI

CPU: 3 PID: 78925 Comm: tee Not tainted 5.15.50-1-lts #1
Hardware name: MSI MS-7A59/Z270 SLI PLUS (MS-7A59), BIOS 1.90 01/30/2018
RIP: 0010:smu_v11_0_set_fan_speed_rpm+0x11/0x110 [amdgpu]

Fix that by checking user input value.