]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
drm/amdgpu: fix warning for overflow check
authorArnd Bergmann <arnd@arndb.de>
Mon, 27 Sep 2021 12:58:10 +0000 (14:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Nov 2021 10:36:08 +0000 (11:36 +0100)
[ Upstream commit 335aea75b0d95518951cad7c4c676e6f1c02c150 ]

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")
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h

index ce7f18c5ccb26e861ef625aed1434ef0941e17ab..fda8d68a87fd6087d9490e339effc6ab809eb4b1 100644 (file)
@@ -57,7 +57,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;
index 61b089768e1ce73bb65229b3e8fce8800c5f49b8..64c8195426ac8eb6a2d7f6a13def6a40eb017fec 100644 (file)
@@ -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 *