lkml.org 
[lkml]   [2021]   [Nov]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.4 194/355] drm/amdgpu: fix warning for overflow check
    Date
    From: Arnd Bergmann <arnd@arndb.de>

    [ 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 | 2 +-
    drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 2 +-
    2 files changed, 2 insertions(+), 2 deletions(-)

    diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
    index 85b0515c0fdcf..e0d2f79571ef5 100644
    --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
    +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
    @@ -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;
    diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
    index a130e766cbdbe..529d52a204cf4 100644
    --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
    +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
    @@ -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,
    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 *
    --
    2.33.0


    \
     
     \ /
      Last update: 2021-11-15 18:52    [W:4.242 / U:0.032 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site