selftests/powerpc: Parse long/unsigned long value safely
authorBenjamin Gray <bgray@linux.ibm.com>
Fri, 3 Feb 2023 00:39:45 +0000 (11:39 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 9 Feb 2023 12:56:45 +0000 (23:56 +1100)
commitd1bc05b7bf02f8635fe6c445f67d78f85234cbb7
tree85d9bd4f50840b97852992c69db196f6120e51f0
parent121d340be9a17ed89d523c56203908c01e09a306
selftests/powerpc: Parse long/unsigned long value safely

Often a file is expected to hold an integral value. Existing functions
will use a C stdlib function like atoi or strtol to parse the file.
These operations are error prone, with complicated error conditions
(atoi returns 0 if not a number, and is undefined behaviour if not in
range. strtol returns 0 if not a number, and LONG_MIN/MAX if not in
range + sets errno to ERANGE).

Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230203003947.38033-4-bgray@linux.ibm.com
tools/testing/selftests/powerpc/include/utils.h
tools/testing/selftests/powerpc/pmu/lib.c
tools/testing/selftests/powerpc/utils.c