Skip to content

Commit 9b55d3f

Browse files
Felix Riemanndavem330
authored andcommitted
net: Fix unwanted sign extension in netdev_stats_to_stats64()
When converting net_device_stats to rtnl_link_stats64 sign extension is triggered on ILP32 machines as 6c1c509 changed the previous "ulong -> u64" conversion to "long -> u64" by accessing the net_device_stats fields through a (signed) atomic_long_t. This causes for example the received bytes counter to jump to 16EiB after having received 2^31 bytes. Casting the atomic value to "unsigned long" beforehand converting it into u64 avoids this. Fixes: 6c1c509 ("net: add atomic_long_t to net_device_stats fields") Signed-off-by: Felix Riemann <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c68f345 commit 9b55d3f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10375,7 +10375,7 @@ void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
1037510375

1037610376
BUILD_BUG_ON(n > sizeof(*stats64) / sizeof(u64));
1037710377
for (i = 0; i < n; i++)
10378-
dst[i] = atomic_long_read(&src[i]);
10378+
dst[i] = (unsigned long)atomic_long_read(&src[i]);
1037910379
/* zero out counters that only exist in rtnl_link_stats64 */
1038010380
memset((char *)stats64 + n * sizeof(u64), 0,
1038110381
sizeof(*stats64) - n * sizeof(u64));

0 commit comments

Comments
 (0)