diff mbox

IB/hfi1: use size_t for passing array length

Message ID 20170214212358.2730288-1-arnd@arndb.de (mailing list archive)
State Accepted
Headers show

Commit Message

Arnd Bergmann Feb. 14, 2017, 9:23 p.m. UTC
gcc-7 produces a mysterious warning about the size argument being potentially out
of range:

drivers/infiniband/hw/hfi1/verbs.c: In function 'init_cntr_names':
drivers/infiniband/hw/hfi1/verbs.c:1644:2: error: 'memcpy': specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]

This seems to refer to a the case where an 64-bit size_t gets truncated
into a negative 'int' and subsequently turned into a high 64-bit number
again.

The fix is clearly to use size_t here, which matches the type that gets
used for this value elsewhere.

Fixes: b7481944b06e ("IB/hfi1: Show statistics counters under IB stats interface")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/infiniband/hw/hfi1/verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Leon Romanovsky Feb. 15, 2017, 5:24 a.m. UTC | #1
On Tue, Feb 14, 2017 at 10:23:07PM +0100, Arnd Bergmann wrote:
> gcc-7 produces a mysterious warning about the size argument being potentially out
> of range:
>
> drivers/infiniband/hw/hfi1/verbs.c: In function 'init_cntr_names':
> drivers/infiniband/hw/hfi1/verbs.c:1644:2: error: 'memcpy': specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
>
> This seems to refer to a the case where an 64-bit size_t gets truncated
> into a negative 'int' and subsequently turned into a high 64-bit number
> again.
>
> The fix is clearly to use size_t here, which matches the type that gets
> used for this value elsewhere.
>
> Fixes: b7481944b06e ("IB/hfi1: Show statistics counters under IB stats interface")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/infiniband/hw/hfi1/verbs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Thanks,
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Doug Ledford Feb. 19, 2017, 1:56 p.m. UTC | #2
On Tue, 2017-02-14 at 22:23 +0100, Arnd Bergmann wrote:
> gcc-7 produces a mysterious warning about the size argument being
> potentially out
> of range:
> 
> drivers/infiniband/hw/hfi1/verbs.c: In function 'init_cntr_names':
> drivers/infiniband/hw/hfi1/verbs.c:1644:2: error: 'memcpy': specified
> size between 18446744071562067968 and 18446744073709551615 exceeds
> maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
> 
> This seems to refer to a the case where an 64-bit size_t gets
> truncated
> into a negative 'int' and subsequently turned into a high 64-bit
> number
> again.
> 
> The fix is clearly to use size_t here, which matches the type that
> gets
> used for this value elsewhere.
> 
> Fixes: b7481944b06e ("IB/hfi1: Show statistics counters under IB
> stats interface")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks, applied.
diff mbox

Patch

diff --git a/drivers/infiniband/hw/hfi1/verbs.c b/drivers/infiniband/hw/hfi1/verbs.c
index 95ed4d6da510..1d8ac9432742 100644
--- a/drivers/infiniband/hw/hfi1/verbs.c
+++ b/drivers/infiniband/hw/hfi1/verbs.c
@@ -1618,7 +1618,7 @@  static int cntr_names_initialized;
  * external strings.
  */
 static int init_cntr_names(const char *names_in,
-			   const int names_len,
+			   const size_t names_len,
 			   int num_extra_names,
 			   int *num_cntrs,
 			   const char ***cntr_names)