LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: fix warning for overflow check
@ 2021-09-27 12:58 Arnd Bergmann
  2021-09-27 13:07 ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2021-09-27 12:58 UTC (permalink / raw)
  To: Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
	Daniel Vetter, Chunming Zhou
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, amd-gfx,
	dri-devel, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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 15c45b2a3983..714178f1b6c6 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 c905a4cfc173..044b41f0bfd9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
@@ -61,7 +61,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.29.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: fix warning for overflow check
  2021-09-27 12:58 [PATCH] drm/amdgpu: fix warning for overflow check Arnd Bergmann
@ 2021-09-27 13:07 ` Christian König
  2021-09-27 19:20   ` Alex Deucher
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2021-09-27 13:07 UTC (permalink / raw)
  To: Arnd Bergmann, Alex Deucher, Pan, Xinhui, David Airlie,
	Daniel Vetter, Chunming Zhou
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, amd-gfx,
	dri-devel, linux-kernel, llvm

Am 27.09.21 um 14:58 schrieb Arnd Bergmann:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   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 15c45b2a3983..714178f1b6c6 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 c905a4cfc173..044b41f0bfd9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> @@ -61,7 +61,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 *


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: fix warning for overflow check
  2021-09-27 13:07 ` Christian König
@ 2021-09-27 19:20   ` Alex Deucher
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2021-09-27 19:20 UTC (permalink / raw)
  To: Christian König
  Cc: Arnd Bergmann, Alex Deucher, Pan, Xinhui, David Airlie,
	Daniel Vetter, Chunming Zhou, Arnd Bergmann, Nathan Chancellor,
	Nick Desaulniers, amd-gfx list, Maling list - DRI developers,
	LKML, llvm

Applied.  Thanks!

On Mon, Sep 27, 2021 at 9:07 AM Christian König
<christian.koenig@amd.com> wrote:
>
> Am 27.09.21 um 14:58 schrieb Arnd Bergmann:
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > 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")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> > ---
> >   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 15c45b2a3983..714178f1b6c6 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 c905a4cfc173..044b41f0bfd9 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> > @@ -61,7 +61,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 *
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-27 19:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 12:58 [PATCH] drm/amdgpu: fix warning for overflow check Arnd Bergmann
2021-09-27 13:07 ` Christian König
2021-09-27 19:20   ` Alex Deucher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).