Skip to contentSkip to conversation

IB/hfi1: use size_t for passing array length

PATCH Applied Arnd Bergmann 3 participants 3 messages Feb 14, 2017 – Feb 19, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IB/hfi1: use size_t for passing array length

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")
---
 drivers/infiniband/hw/hfi1/verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hfi1/verbs.c +1 -1
index 95ed4d6da510..1d8ac9432742 100644
@@ -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)
Signature · 6 lines
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Arnd Bergmann

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.

Quoted 9 lines

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")
---
 drivers/infiniband/hw/hfi1/verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks,

Applied
#2 lore raw
In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann

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.

Quoted 7 lines

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

Thanks, applied.

Signature · 4 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
   
Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD