Re: [PATCH 7/9] infiniband: uverbs: avoid out-of-range warnings

Justin Stitt
2024-03-28T22:13:03Z

On Thu, Mar 28, 2024 at 7:32 AM Arnd Bergmann <arnd@kernel.org> wrote:
> Add a cast to u32 in both cases, so it never warns about this.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Justin Stitt <justinstitt@google.com>

> ---
> drivers/infiniband/core/uverbs_ioctl.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c
> index f80da6a67e24..e0cc3ddae71b 100644
> --- a/drivers/infiniband/core/uverbs_ioctl.c
> +++ b/drivers/infiniband/core/uverbs_ioctl.c
> @@ -90,7 +90,7 @@ void uapi_compute_bundle_size(struct uverbs_api_ioctl_method *method_elm,
> ALIGN(bundle_size + 256, sizeof(*pbundle->internal_buffer));
>
> /* Do not want order-2 allocations for this. */
> - WARN_ON_ONCE(method_elm->bundle_size > PAGE_SIZE);
> + WARN_ON_ONCE((u32)method_elm->bundle_size > PAGE_SIZE);
> }
>
> /**
> @@ -636,7 +636,7 @@ long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
> if (err)
> return -EFAULT;
>
> - if (hdr.length > PAGE_SIZE ||
> + if ((u32)hdr.length > PAGE_SIZE ||
> hdr.length != struct_size(&hdr, attrs, hdr.num_attrs))
> return -EINVAL;
>
> --
> 2.39.2
>