Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netdevsim: Ensure policer drop counter always increases

In case the policer drop counter is retrieved when the jiffies value is
a multiple of 64, the counter will not be incremented.

This randomly breaks a selftest [1] the reads the counter twice and
checks that it was incremented:

```
TEST: Trap policer [FAIL]
Policer drop counter was not incremented
```

Fix by always incrementing the counter by 1.

[1] tools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh

Fixes: ad188458d012 ("netdevsim: Add devlink-trap policer support")
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ido Schimmel and committed by
David S. Miller
be43224f 4629ed2e

+1 -2
+1 -2
drivers/net/netdevsim/dev.c
··· 858 858 return -EINVAL; 859 859 860 860 cnt = &nsim_dev->trap_data->trap_policers_cnt_arr[policer->id - 1]; 861 - *p_drops = *cnt; 862 - *cnt += jiffies % 64; 861 + *p_drops = (*cnt)++; 863 862 864 863 return 0; 865 864 }