Skip to contentSkip to conversation

drm/amdgpu: Avoid integer overflow in amdgpu_device_suspend_display_audio

PATCH Applied Nathan Chancellor 2 participants 2 messages May 2, 2020 – May 5, 2020

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

PATCH 1/1 drm/amdgpu: Avoid integer overflow in amdgpu_device_suspend_display_audio

When building with Clang:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:4160:53: warning: overflow in expression; result is -294967296 with type 'long' [-Winteger-overflow]

                expires = ktime_get_mono_fast_ns() + NSEC_PER_SEC * 4L;
                                                                  ^

1 warning generated.

Multiplication happens first due to order of operations and both NSEC_PER_SEC and 4 are long literals so the expression overflows. To avoid this, make 4 an unsigned long long literal, which matches the type of expires (u64).

Fixes 3f12acc8d6d4 ("drm/amdgpu: put the audio codec into suspend state before gpu reset V3")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index 6f93af972b0a..caa38e7d502e 100644
@@ -4157,7 +4157,7 @@ static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
 		 * the audio controller default autosuspend delay setting.
 		 * 4S used here is guaranteed to cover that.
 		 */
-		expires = ktime_get_mono_fast_ns() + NSEC_PER_SEC * 4L;
+		expires = ktime_get_mono_fast_ns() + NSEC_PER_SEC * 4ULL;
 
 	while (!pm_runtime_status_suspended(&(p->dev))) {
 		if (!pm_runtime_suspend(&(p->dev)))

base-commit: fb9d670f57e3f6478602328bbbf71138be06ca4f

Signature · 1 line
2.26.2
Applied
#1 lore raw
Quoted 9 lines · Nathan Chancellor

When building with Clang:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:4160:53: warning: overflow in expression; result is -294967296 with type 'long' [-Winteger-overflow]

                expires = ktime_get_mono_fast_ns() + NSEC_PER_SEC * 4L;
                                                                  ^

1 warning generated.

Quoted 8 lines

Multiplication happens first due to order of operations and both NSEC_PER_SEC and 4 are long literals so the expression overflows. To avoid this, make 4 an unsigned long long literal, which matches the type of expires (u64).

Fixes 3f12acc8d6d4 ("drm/amdgpu: put the audio codec into suspend state before gpu reset V3")

Applied. Thanks!

Alex

Quoted 18 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index 6f93af972b0a..caa38e7d502e 100644
@@ -4157,7 +4157,7 @@ static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
                 * the audio controller default autosuspend delay setting.
                 * 4S used here is guaranteed to cover that.
                 */
-               expires = ktime_get_mono_fast_ns() + NSEC_PER_SEC * 4L;
+               expires = ktime_get_mono_fast_ns() + NSEC_PER_SEC * 4ULL;
 
        while (!pm_runtime_status_suspended(&(p->dev))) {
                if (!pm_runtime_suspend(&(p->dev)))
Quoted 8 lines

base-commit: fb9d670f57e3f6478602328bbbf71138be06ca4f --
2.26.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx