[PATCH] drm/amdgpu: fix overflowed array index read warning

Huang, Tim Tim.Huang at amd.com
Thu Apr 25 06:56:24 UTC 2024


[AMD Official Use Only - General]

-----Original Message-----
From: Koenig, Christian <Christian.Koenig at amd.com>
Sent: Thursday, April 25, 2024 2:45 PM
To: Huang, Tim <Tim.Huang at amd.com>; amd-gfx at lists.freedesktop.org
Cc: Deucher, Alexander <Alexander.Deucher at amd.com>
Subject: Re: [PATCH] drm/amdgpu: fix overflowed array index read warning

Am 25.04.24 um 07:27 schrieb Tim Huang:
> From: Tim Huang <Tim.Huang at amd.com>
>
> Clear warning that cast operation might have overflowed.
>
> Signed-off-by: Tim Huang <Tim.Huang at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> index 06f0a6534a94..6dfcd62e83ae 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> @@ -473,7 +473,7 @@ static ssize_t amdgpu_debugfs_ring_read(struct file *f, char __user *buf,
>                                       size_t size, loff_t *pos)
>   {
>       struct amdgpu_ring *ring = file_inode(f)->i_private;
> -     int r, i;
> +     int r;
>       uint32_t value, result, early[3];

> While at it please declare "int r;" last, e.g. keep reverse xmas tree order here.

Yes, it is better. Will adjust the order and send out v2, thanks.

Tim.

>Apart from that looks good to me.

>Regards,
>Christian.

>
>       if (*pos & 3 || size & 3)
> @@ -485,7 +485,7 @@ static ssize_t amdgpu_debugfs_ring_read(struct file *f, char __user *buf,
>               early[0] = amdgpu_ring_get_rptr(ring) & ring->buf_mask;
>               early[1] = amdgpu_ring_get_wptr(ring) & ring->buf_mask;
>               early[2] = ring->wptr & ring->buf_mask;
> -             for (i = *pos / 4; i < 3 && size; i++) {
> +             for (loff_t i = *pos / 4; i < 3 && size; i++) {
>                       r = put_user(early[i], (uint32_t *)buf);
>                       if (r)
>                               return r;



More information about the amd-gfx mailing list