From: "Christian König" <christian.koenig@amd.com>
To: Colin Ian King <colin.i.king@gmail.com>,
Alex Deucher <alexander.deucher@amd.com>,
Xinhui Pan <Xinhui.Pan@amd.com>, David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>, Leo Liu <leo.liu@amd.com>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
Advait Dhamorikar <advaitdhamorikar@gmail.com>
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] drm/amdgpu: Fix potential integer overflow on shift of a int
Date: Thu, 10 Oct 2024 15:30:34 +0200 [thread overview]
Message-ID: <a975f84c-f74b-4825-8111-0c883cc709e0@amd.com> (raw)
In-Reply-To: <20241010112204.636188-1-colin.i.king@gmail.com>
Am 10.10.24 um 13:22 schrieb Colin Ian King:
> The left shift of int 32 bit integer constant 1 is evaluated using 32 bit
> arithmetic and then assigned to and operated upon using a 64 bit unsigned
> integer. In the case where the shift is 32 or more this can lead to an
> overflow. Avoid this by shifting using the BIT_ULL macro instead.
Advait Dhamorikar already came up with a similar patch which also cleans
up some other occasions.
Regards,
Christian.
>
> Fixes: f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c
> index 95e2796919fc..136a0c8d8c7a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c
> @@ -357,14 +357,14 @@ static int amdgpu_debugfs_jpeg_sched_mask_set(void *data, u64 val)
> if (!adev)
> return -ENODEV;
>
> - mask = (1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;
> + mask = (BIT_ULL(adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;
> if ((val & mask) == 0)
> return -EINVAL;
>
> for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
> for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
> ring = &adev->jpeg.inst[i].ring_dec[j];
> - if (val & (1 << ((i * adev->jpeg.num_jpeg_rings) + j)))
> + if (val & BIT_ULL((i * adev->jpeg.num_jpeg_rings) + j))
> ring->sched.ready = true;
> else
> ring->sched.ready = false;
> @@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
> for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
> ring = &adev->jpeg.inst[i].ring_dec[j];
> if (ring->sched.ready)
> - mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
> + mask |= BIT_ULL((i * adev->jpeg.num_jpeg_rings) + j);
> }
> }
> *val = mask;
prev parent reply other threads:[~2024-10-10 13:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 11:22 Colin Ian King
2024-10-10 13:30 ` Christian König [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a975f84c-f74b-4825-8111-0c883cc709e0@amd.com \
--to=christian.koenig@amd.com \
--cc=Xinhui.Pan@amd.com \
--cc=advaitdhamorikar@gmail.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=colin.i.king@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=leo.liu@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®