Skip to contentSkip to conversation

amdgpu: fix integer overflow on 32-bit architectures

PATCH In review Arnd Bergmann 3 participants 3 messages May 5, 2020

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

PATCH 1/1 amdgpu: fix integer overflow on 32-bit architectures

Multiplying 1000000000 by four overruns a 'long' variable, as clang points out:

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

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

Make this a 'long long' constant instead.

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

---
I'm not sure the ktime_get_mono_fast_ns() call is necessary here either. Is it intentional because ktime_get_ns() doesn't work during a driver suspend, or just a mistake?

---
 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..2e07e3e6b036 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 * 4LL;
 
 	while (!pm_runtime_status_suspended(&(p->dev))) {
 		if (!pm_runtime_suspend(&(p->dev)))
Signature · 6 lines
2.26.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 05.05.20 um 16:15 schrieb Arnd Bergmann:

Quoted 10 lines

Multiplying 1000000000 by four overruns a 'long' variable, as clang points out:

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

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

Make this a 'long long' constant instead.

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

---
I'm not sure the ktime_get_mono_fast_ns() call is necessary here either. Is it intentional because ktime_get_ns() doesn't work during a driver suspend, or just a mistake?

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 6f93af972b0a..2e07e3e6b036 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev) · line 4163

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -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 * 4LL;
 
  	while (!pm_runtime_status_suspended(&(p->dev))) {
  		if (!pm_runtime_suspend(&(p->dev)))

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

#2 lore raw

See also https://lore.kernel.org/lkml/CADnq5_NdtZh5_RGDWKJ9c_42XLvrncCs5DDU1YSptfZP94KXkQ@mail.gmail.com/T/#me707e09e92c6e487285e8bb382a607e4e782c249

Quoted 41 lines · Christian König

Am 05.05.20 um 16:15 schrieb Arnd Bergmann:

Quoted 10 lines

Multiplying 1000000000 by four overruns a 'long' variable, as clang points out:

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

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

Make this a 'long long' constant instead.

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

---
I'm not sure the ktime_get_mono_fast_ns() call is necessary here either. Is it intentional because ktime_get_ns() doesn't work during a driver suspend, or just a mistake?

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 6f93af972b0a..2e07e3e6b036 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev) · line 4163

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -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 * 4LL;
 
      while (!pm_runtime_status_suspended(&(p->dev))) {
              if (!pm_runtime_suspend(&(p->dev)))

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/e4a852b2-807b-bc73-7328-bcc399341085%40amd.com.

Signature · 2 lines
Thanks,
~Nick Desaulniers