提交 33bdc670 编写于 作者: A Arnd Bergmann 提交者: Zheng Zengkai

drm/amdgpu: fix warning for overflow check

stable inclusion
from stable-5.10.80
commit 375150b3aaf8cf7d01f6f0b582e264dd2fded814
bugzilla: 185821 https://gitee.com/openeuler/kernel/issues/I4L7CG

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=375150b3aaf8cf7d01f6f0b582e264dd2fded814

--------------------------------

[ Upstream commit 335aea75 ]

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: 920990cb ("drm/amdgpu: allocate the bo_list array after the list")
Reviewed-by: NChristian König <christian.koenig@amd.com>
Signed-off-by: NArnd Bergmann <arnd@arndb.de>
Signed-off-by: NAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Reviewed-by: NWeilong Chen <chenweilong@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 b9a9ddaa
...@@ -61,7 +61,7 @@ static void amdgpu_bo_list_free(struct kref *ref) ...@@ -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, int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
struct drm_amdgpu_bo_list_entry *info, 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; unsigned last_entry = 0, first_userptr = num_entries;
struct amdgpu_bo_list_entry *array; struct amdgpu_bo_list_entry *array;
......
...@@ -60,7 +60,7 @@ int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in, ...@@ -60,7 +60,7 @@ int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
int amdgpu_bo_list_create(struct amdgpu_device *adev, int amdgpu_bo_list_create(struct amdgpu_device *adev,
struct drm_file *filp, struct drm_file *filp,
struct drm_amdgpu_bo_list_entry *info, struct drm_amdgpu_bo_list_entry *info,
unsigned num_entries, size_t num_entries,
struct amdgpu_bo_list **list); struct amdgpu_bo_list **list);
static inline struct amdgpu_bo_list_entry * static inline struct amdgpu_bo_list_entry *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册