Skip to contentSkip to conversation

drm/amdgpu: fix warning for overflow check

PATCH Applied Arnd Bergmann 3 participants 3 messages Sep 27, 2021

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

PATCH 1/1 drm/amdgpu: fix warning for overflow check

From: Arnd Bergmann <[email protected]>

The overflow check in amdgpu_bo_list_create() causes a warning with clang-14 on 64-bit architectures, since the limit can never be exceeded.

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c:74:18: error: result of comparison of constant 256204778801521549 with expression of type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The check remains useful for 32-bit architectures, so just avoid the warning by using size_t as the type for the count.

Fixes 920990cb080a ("drm/amdgpu: allocate the bo_list array after the list")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1 -1
index 15c45b2a3983..714178f1b6c6 100644
@@ -61,7 +61,7 @@ static void amdgpu_bo_list_free(struct kref *ref)
 
 int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
 			  struct drm_amdgpu_bo_list_entry *info,
-			  unsigned num_entries, struct amdgpu_bo_list **result)
+			  size_t num_entries, struct amdgpu_bo_list **result)
 {
 	unsigned last_entry = 0, first_userptr = num_entries;
 	struct amdgpu_bo_list_entry *array;
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h +1 -1
index c905a4cfc173..044b41f0bfd9 100644
@@ -61,7 +61,7 @@ int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
 int amdgpu_bo_list_create(struct amdgpu_device *adev,
 				 struct drm_file *filp,
 				 struct drm_amdgpu_bo_list_entry *info,
-				 unsigned num_entries,
+				 size_t num_entries,
 				 struct amdgpu_bo_list **list);
 
 static inline struct amdgpu_bo_list_entry *
Signature · 1 line
2.29.2
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 27.09.21 um 14:58 schrieb Arnd Bergmann:

Quoted 10 lines

From: Arnd Bergmann <[email protected]>

The overflow check in amdgpu_bo_list_create() causes a warning with clang-14 on 64-bit architectures, since the limit can never be exceeded.

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c:74:18: error: result of comparison of constant 256204778801521549 with expression of type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 5 lines

The check remains useful for 32-bit architectures, so just avoid the warning by using size_t as the type for the count.

Fixes 920990cb080a ("drm/amdgpu: allocate the bo_list array after the list")
Quoted 31 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1 -1
index 15c45b2a3983..714178f1b6c6 100644
@@ -61,7 +61,7 @@ static void amdgpu_bo_list_free(struct kref *ref)
 
  int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
  			  struct drm_amdgpu_bo_list_entry *info,
-			  unsigned num_entries, struct amdgpu_bo_list **result)
+			  size_t num_entries, struct amdgpu_bo_list **result)
  {
  	unsigned last_entry = 0, first_userptr = num_entries;
  	struct amdgpu_bo_list_entry *array;
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h +1 -1
index c905a4cfc173..044b41f0bfd9 100644
@@ -61,7 +61,7 @@ int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
  int amdgpu_bo_list_create(struct amdgpu_device *adev,
  				 struct drm_file *filp,
  				 struct drm_amdgpu_bo_list_entry *info,
-				 unsigned num_entries,
+				 size_t num_entries,
  				 struct amdgpu_bo_list **list);
 
  static inline struct amdgpu_bo_list_entry *
Applied
#2 lore raw

Applied. Thanks!

Quoted 52 lines · Christian König

Am 27.09.21 um 14:58 schrieb Arnd Bergmann:

Quoted 10 lines

From: Arnd Bergmann <[email protected]>

The overflow check in amdgpu_bo_list_create() causes a warning with clang-14 on 64-bit architectures, since the limit can never be exceeded.

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c:74:18: error: result of comparison of constant 256204778801521549 with expression of type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 5 lines

The check remains useful for 32-bit architectures, so just avoid the warning by using size_t as the type for the count.

Fixes 920990cb080a ("drm/amdgpu: allocate the bo_list array after the list")
Quoted 31 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1 -1
index 15c45b2a3983..714178f1b6c6 100644
@@ -61,7 +61,7 @@ static void amdgpu_bo_list_free(struct kref *ref)
 
  int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
                        struct drm_amdgpu_bo_list_entry *info,
-                       unsigned num_entries, struct amdgpu_bo_list **result)
+                       size_t num_entries, struct amdgpu_bo_list **result)
  {
      unsigned last_entry = 0, first_userptr = num_entries;
      struct amdgpu_bo_list_entry *array;
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h +1 -1
index c905a4cfc173..044b41f0bfd9 100644
@@ -61,7 +61,7 @@ int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
  int amdgpu_bo_list_create(struct amdgpu_device *adev,
                               struct drm_file *filp,
                               struct drm_amdgpu_bo_list_entry *info,
-                              unsigned num_entries,
+                              size_t num_entries,
                               struct amdgpu_bo_list **list);
 
  static inline struct amdgpu_bo_list_entry *