diff mbox series

mlx5: avoid integer overflow warning for large page size

Message ID 20230622101525.3321642-1-arnd@kernel.org (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series mlx5: avoid integer overflow warning for large page size | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers success CCed 15 of 15 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning CHECK: Logical continuations should be on the previous line WARNING: Comparisons should place the constant on the right side of the test
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Arnd Bergmann June 22, 2023, 10:15 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

Build testing with 'make LLVM=1 W=1' shows a warning about a
condition that is always true on configurations with 64KB
pages:

drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:32:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

Change the condition in a way that lets clang know this
is intentional.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Maxim Mikityanskiy June 22, 2023, 11:23 a.m. UTC | #1
On Thu, 22 Jun 2023 at 12:15:02 +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Build testing with 'make LLVM=1 W=1' shows a warning about a
> condition that is always true on configurations with 64KB
> pages:
> 
> drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:32:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> 
> Change the condition in a way that lets clang know this
> is intentional.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
> index 36826b5824847..b9f62e531bd4c 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
> @@ -29,7 +29,8 @@ bool mlx5e_validate_xsk_param(struct mlx5e_params *params,
>  			      struct mlx5_core_dev *mdev)
>  {
>  	/* AF_XDP doesn't support frames larger than PAGE_SIZE. */
> -	if (xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
> +	if ((PAGE_SIZE < U16_MAX && xsk->chunk_size > PAGE_SIZE)
> +	    || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {

I recall you already sent a fix to silence this warning before:

https://lore.kernel.org/netdev/20211015152056.2434853-1-arnd@kernel.org/

I prefer that old one, as it's more future-proof to cast to size_t here
in place (chunk_size won't be bigger than size_t for sure). With your
new patch, if chunk_size is ever changed from u16 to u32, it's likely
that this place will be unnoticed, and a bug will be introduced.

>  		mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
>  			      MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);
>  		return false;
> -- 
> 2.39.2
>
Arnd Bergmann June 22, 2023, 11:28 a.m. UTC | #2
On Thu, Jun 22, 2023, at 13:23, Maxim Mikityanskiy wrote:
> On Thu, 22 Jun 2023 at 12:15:02 +0200, Arnd Bergmann wrote:
>
> I recall you already sent a fix to silence this warning before:
>
> https://lore.kernel.org/netdev/20211015152056.2434853-1-arnd@kernel.org/
>
> I prefer that old one, as it's more future-proof to cast to size_t here
> in place (chunk_size won't be bigger than size_t for sure). With your
> new patch, if chunk_size is ever changed from u16 to u32, it's likely
> that this place will be unnoticed, and a bug will be introduced.
>
>>  		mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
>>  			      MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);

Indeed, I don't know why I no longer had the old patch in my randconfig
tree, I completely forgot about that. The old patch is also ok.

   Arnd
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
index 36826b5824847..b9f62e531bd4c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
@@ -29,7 +29,8 @@  bool mlx5e_validate_xsk_param(struct mlx5e_params *params,
 			      struct mlx5_core_dev *mdev)
 {
 	/* AF_XDP doesn't support frames larger than PAGE_SIZE. */
-	if (xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
+	if ((PAGE_SIZE < U16_MAX && xsk->chunk_size > PAGE_SIZE)
+	    || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
 		mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
 			      MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);
 		return false;