Skip to contentSkip to conversation

drm/amdgpu: fix clang out-of-range warning

PATCH In review Arnd Bergmann 3 participants 3 messages Sep 27, 2021 – Sep 28, 2021

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

PATCH 1/1 drm/amdgpu: fix clang out-of-range warning

From: Arnd Bergmann <[email protected]>

clang-14 points out that comparing an 'unsigned int' against a large 64-bit constantn is pointless:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1206:18: error: result of comparison of constant 4294967296 with expression of type 'resource_size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

                    res->start > 0x100000000ull)

Rephrase the comparison using the upper_32_bits() macro, which should keep it legible while avoiding the warning.

Fixes 31b8adab3247 ("drm/amdgpu: require a root bus window above 4GB for BAR resize")
---
 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 ab3794c42d36..741a55031ca1 100644
@@ -1203,7 +1203,7 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
 
 	pci_bus_for_each_resource(root, res, i) {
 		if (res && res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
-		    res->start > 0x100000000ull)
+		    upper_32_bits(res->start) != 0)
 			break;
 	}
 
Signature · 1 line
2.29.2
maintainer
#1 lore raw

In general that change looks good. But what configuration is that?

Background is that it doesn't make much sense to compile the amdgpu driver on systems where resource_size_t is only 32bit.

Christian.

Am 27.09.21 um 14:19 schrieb Arnd Bergmann:

Quoted 30 lines

From: Arnd Bergmann <[email protected]>

clang-14 points out that comparing an 'unsigned int' against a large 64-bit constantn is pointless:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1206:18: error: result of comparison of constant 4294967296 with expression of type 'resource_size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

                     res->start > 0x100000000ull)

Rephrase the comparison using the upper_32_bits() macro, which should keep it legible while avoiding the warning.

Fixes 31b8adab3247 ("drm/amdgpu: require a root bus window above 4GB for BAR resize")
---
  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 ab3794c42d36..741a55031ca1 100644
@@ -1203,7 +1203,7 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
 
  	pci_bus_for_each_resource(root, res, i) {
  		if (res && res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
-		    res->start > 0x100000000ull)
+		    upper_32_bits(res->start) != 0)
  			break;
  	}
 
#2 lore raw
In reply to Arnd Bergmann
Quoted 22 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

clang-14 points out that comparing an 'unsigned int' against a large 64-bit constantn is pointless:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1206:18: error: result of comparison of constant 4294967296 with expression of type 'resource_size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

                    res->start > 0x100000000ull)

Rephrase the comparison using the upper_32_bits() macro, which should keep it legible while avoiding the warning.

Fixes 31b8adab3247 ("drm/amdgpu: require a root bus window above 4GB for BAR resize")
---
 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 ab3794c42d36..741a55031ca1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev) · line 1206

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -1203,7 +1203,7 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
 
 	pci_bus_for_each_resource(root, res, i) {
 		if (res && res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
-		    res->start > 0x100000000ull)
+		    upper_32_bits(res->start) != 0)

New code matches 1ull << 32, old code didn't. If this difference matters, this would break if res->start is 64 bits?

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer