linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division
@ 2018-02-23 13:15 Arnd Bergmann
  2018-02-23 13:15 ` [net-next PATCH 2/2] mlxsw: spectrum_kvdl: avoid uninitialized variable warning Arnd Bergmann
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Arnd Bergmann @ 2018-02-23 13:15 UTC (permalink / raw)
  To: Arkadi Sharshevsky, Jiri Pirko, Ido Schimmel
  Cc: Arnd Bergmann, David S. Miller, Wei Yongjun, netdev, linux-kernel

Calculating the number of entries now uses 64-bit arithmetic that
causes a link error on 32-bit architectures:

drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.o: In function `mlxsw_sp_kvdl_init':
spectrum_kvdl.c:(.text+0x51c): undefined reference to `__aeabi_uldivmod'

We could probably use a 32-bit division here as before, but since this is
not in a performance critical path, div_u64() seems cleaner here.

Fixes: 887839e6960d ("mlxsw: spectrum_kvdl: Add support for dynamic partition set")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
index d27fa57ad3c3..6fd701db90c9 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
@@ -278,7 +278,7 @@ static int mlxsw_sp_kvdl_part_init(struct mlxsw_sp *mlxsw_sp,
 		resource_size = info->end_index - info->start_index + 1;
 	}
 
-	nr_entries = resource_size / info->alloc_size;
+	nr_entries = div_u64(resource_size, info->alloc_size);
 	usage_size = BITS_TO_LONGS(nr_entries) * sizeof(unsigned long);
 	part = kzalloc(sizeof(*part) + usage_size, GFP_KERNEL);
 	if (!part)
-- 
2.9.0

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

* [net-next PATCH 2/2] mlxsw: spectrum_kvdl: avoid uninitialized variable warning
  2018-02-23 13:15 [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division Arnd Bergmann
@ 2018-02-23 13:15 ` Arnd Bergmann
  2018-02-25 10:04   ` Arkadi Sharshevsky
  2018-02-26 16:33   ` David Miller
  2018-02-25 10:04 ` [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division Arkadi Sharshevsky
  2018-02-26 16:33 ` David Miller
  2 siblings, 2 replies; 6+ messages in thread
From: Arnd Bergmann @ 2018-02-23 13:15 UTC (permalink / raw)
  To: Arkadi Sharshevsky, Jiri Pirko, Ido Schimmel
  Cc: Arnd Bergmann, David S. Miller, Wei Yongjun, netdev, linux-kernel

gcc warns that 'resource_id' is not initialized if we don't come though
any of the three 'case' statements before:

drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c: In function 'mlxsw_sp_kvdl_part_init':
drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c:275:8: error: 'resource_id' may be used uninitialized in this function [-Werror=maybe-uninitialized]

In the current code, that won't happen, but it's more robust to explicitly
handle this by returning a failure from mlxsw_sp_kvdl_part_init.

Fixes: 887839e6960d ("mlxsw: spectrum_kvdl: Add support for dynamic partition set")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
index 6fd701db90c9..059eb3214328 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
@@ -270,6 +270,8 @@ static int mlxsw_sp_kvdl_part_init(struct mlxsw_sp *mlxsw_sp,
 	case MLXSW_SP_KVDL_PART_LARGE_CHUNKS:
 		resource_id = MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS;
 		break;
+	default:
+		return -EINVAL;
 	}
 
 	err = devlink_resource_size_get(devlink, resource_id, &resource_size);
-- 
2.9.0

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

* Re: [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division
  2018-02-23 13:15 [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division Arnd Bergmann
  2018-02-23 13:15 ` [net-next PATCH 2/2] mlxsw: spectrum_kvdl: avoid uninitialized variable warning Arnd Bergmann
@ 2018-02-25 10:04 ` Arkadi Sharshevsky
  2018-02-26 16:33 ` David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-25 10:04 UTC (permalink / raw)
  To: Arnd Bergmann, Jiri Pirko, Ido Schimmel
  Cc: David S. Miller, Wei Yongjun, netdev, linux-kernel



On 02/23/2018 03:15 PM, Arnd Bergmann wrote:
> Calculating the number of entries now uses 64-bit arithmetic that
> causes a link error on 32-bit architectures:
> 
> drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.o: In function `mlxsw_sp_kvdl_init':
> spectrum_kvdl.c:(.text+0x51c): undefined reference to `__aeabi_uldivmod'
> 
> We could probably use a 32-bit division here as before, but since this is
> not in a performance critical path, div_u64() seems cleaner here.
> 
> Fixes: 887839e6960d ("mlxsw: spectrum_kvdl: Add support for dynamic partition set")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
> index d27fa57ad3c3..6fd701db90c9 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
> @@ -278,7 +278,7 @@ static int mlxsw_sp_kvdl_part_init(struct mlxsw_sp *mlxsw_sp,
>  		resource_size = info->end_index - info->start_index + 1;
>  	}
>  
> -	nr_entries = resource_size / info->alloc_size;
> +	nr_entries = div_u64(resource_size, info->alloc_size);
>  	usage_size = BITS_TO_LONGS(nr_entries) * sizeof(unsigned long);
>  	part = kzalloc(sizeof(*part) + usage_size, GFP_KERNEL);
>  	if (!part)
> 

Acked-by: Arkadi Sharshevsky <arkadis@mellanox.com>

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

* Re: [net-next PATCH 2/2] mlxsw: spectrum_kvdl: avoid uninitialized variable warning
  2018-02-23 13:15 ` [net-next PATCH 2/2] mlxsw: spectrum_kvdl: avoid uninitialized variable warning Arnd Bergmann
@ 2018-02-25 10:04   ` Arkadi Sharshevsky
  2018-02-26 16:33   ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-25 10:04 UTC (permalink / raw)
  To: Arnd Bergmann, Jiri Pirko, Ido Schimmel
  Cc: David S. Miller, Wei Yongjun, netdev, linux-kernel



On 02/23/2018 03:15 PM, Arnd Bergmann wrote:
> gcc warns that 'resource_id' is not initialized if we don't come though
> any of the three 'case' statements before:
> 
> drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c: In function 'mlxsw_sp_kvdl_part_init':
> drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c:275:8: error: 'resource_id' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> In the current code, that won't happen, but it's more robust to explicitly
> handle this by returning a failure from mlxsw_sp_kvdl_part_init.
> 
> Fixes: 887839e6960d ("mlxsw: spectrum_kvdl: Add support for dynamic partition set")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
> index 6fd701db90c9..059eb3214328 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
> @@ -270,6 +270,8 @@ static int mlxsw_sp_kvdl_part_init(struct mlxsw_sp *mlxsw_sp,
>  	case MLXSW_SP_KVDL_PART_LARGE_CHUNKS:
>  		resource_id = MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS;
>  		break;
> +	default:
> +		return -EINVAL;
>  	}
>  
>  	err = devlink_resource_size_get(devlink, resource_id, &resource_size);
> 
Acked-by: Arkadi Sharshevsky <arkadis@mellanox.com>

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

* Re: [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division
  2018-02-23 13:15 [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division Arnd Bergmann
  2018-02-23 13:15 ` [net-next PATCH 2/2] mlxsw: spectrum_kvdl: avoid uninitialized variable warning Arnd Bergmann
  2018-02-25 10:04 ` [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division Arkadi Sharshevsky
@ 2018-02-26 16:33 ` David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2018-02-26 16:33 UTC (permalink / raw)
  To: arnd; +Cc: arkadis, jiri, idosch, weiyongjun1, netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 23 Feb 2018 14:15:31 +0100

> Calculating the number of entries now uses 64-bit arithmetic that
> causes a link error on 32-bit architectures:
> 
> drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.o: In function `mlxsw_sp_kvdl_init':
> spectrum_kvdl.c:(.text+0x51c): undefined reference to `__aeabi_uldivmod'
> 
> We could probably use a 32-bit division here as before, but since this is
> not in a performance critical path, div_u64() seems cleaner here.
> 
> Fixes: 887839e6960d ("mlxsw: spectrum_kvdl: Add support for dynamic partition set")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied.

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

* Re: [net-next PATCH 2/2] mlxsw: spectrum_kvdl: avoid uninitialized variable warning
  2018-02-23 13:15 ` [net-next PATCH 2/2] mlxsw: spectrum_kvdl: avoid uninitialized variable warning Arnd Bergmann
  2018-02-25 10:04   ` Arkadi Sharshevsky
@ 2018-02-26 16:33   ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2018-02-26 16:33 UTC (permalink / raw)
  To: arnd; +Cc: arkadis, jiri, idosch, weiyongjun1, netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 23 Feb 2018 14:15:32 +0100

> gcc warns that 'resource_id' is not initialized if we don't come though
> any of the three 'case' statements before:
> 
> drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c: In function 'mlxsw_sp_kvdl_part_init':
> drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c:275:8: error: 'resource_id' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> In the current code, that won't happen, but it's more robust to explicitly
> handle this by returning a failure from mlxsw_sp_kvdl_part_init.
> 
> Fixes: 887839e6960d ("mlxsw: spectrum_kvdl: Add support for dynamic partition set")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied.

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

end of thread, other threads:[~2018-02-26 16:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-23 13:15 [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division Arnd Bergmann
2018-02-23 13:15 ` [net-next PATCH 2/2] mlxsw: spectrum_kvdl: avoid uninitialized variable warning Arnd Bergmann
2018-02-25 10:04   ` Arkadi Sharshevsky
2018-02-26 16:33   ` David Miller
2018-02-25 10:04 ` [net-next PATCH 1/2] mlxsw: spectrum_kvdl: use div_u64() for 64-bit division Arkadi Sharshevsky
2018-02-26 16:33 ` David Miller

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).