selftests/resctrl: Fix checking for < 0 for unsigned values
authorFenghua Yu <fenghua.yu@intel.com>
Wed, 17 Mar 2021 02:22:54 +0000 (02:22 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 2 Apr 2021 19:58:37 +0000 (13:58 -0600)
commit1205b688c92558a04d8dd4cbc2b213e0fceba5db
tree7fb102a5a1927899dd66f8e6ac11b97e762ae2e5
parentd81343b5eedf84be71a4313e8fd073d0c510afcf
selftests/resctrl: Fix checking for < 0 for unsigned values

Dan reported following static checker warnings

tools/testing/selftests/resctrl/resctrl_val.c:545 measure_vals()
warn: 'bw_imc' unsigned <= 0

tools/testing/selftests/resctrl/resctrl_val.c:549 measure_vals()
warn: 'bw_resc_end' unsigned <= 0

These warnings are reported because
1. measure_vals() declares 'bw_imc' and 'bw_resc_end' as unsigned long
   variables
2. Return value of get_mem_bw_imc() and get_mem_bw_resctrl() are assigned
   to 'bw_imc' and 'bw_resc_end' respectively
3. The returned values are checked for <= 0 to see if the calls failed

Checking for < 0 for an unsigned value doesn't make any sense.

Fix this issue by changing the implementation of get_mem_bw_imc() and
get_mem_bw_resctrl() such that they now accept reference to a variable
and set the variable appropriately upon success and return 0, else return
< 0 on error.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/resctrl_val.c