diff options
author | Benjamin Gray <bgray@linux.ibm.com> | 2023-02-03 03:39:46 +0300 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2023-02-09 15:56:45 +0300 |
commit | 5c20de57888f0962e25a0eeec1a59c98056fc42e (patch) | |
tree | 94d8ed4b5dedaeb221761e8693ff1399f2fd7af7 /tools/testing/selftests/powerpc/dscr | |
parent | d1bc05b7bf02f8635fe6c445f67d78f85234cbb7 (diff) | |
download | linux-5c20de57888f0962e25a0eeec1a59c98056fc42e.tar.xz |
selftests/powerpc: Add {read,write}_{long,ulong}
Add helper functions to read and write (unsigned) long values directly
from/to files. One of the kernel interfaces uses hex strings, so we need
to allow passing a base too.
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-5-bgray@linux.ibm.com
Diffstat (limited to 'tools/testing/selftests/powerpc/dscr')
-rw-r--r-- | tools/testing/selftests/powerpc/dscr/dscr.h | 9 | ||||
-rw-r--r-- | tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c | 14 |
2 files changed, 9 insertions, 14 deletions
diff --git a/tools/testing/selftests/powerpc/dscr/dscr.h b/tools/testing/selftests/powerpc/dscr/dscr.h index aaa2b0d89f7e..2c54998d4715 100644 --- a/tools/testing/selftests/powerpc/dscr/dscr.h +++ b/tools/testing/selftests/powerpc/dscr/dscr.h @@ -65,26 +65,21 @@ inline void set_dscr_usr(unsigned long val) unsigned long get_default_dscr(void) { int err; - char buf[16] = {0}; unsigned long val; - err = read_file(DSCR_DEFAULT, buf, sizeof(buf) - 1, NULL); + err = read_ulong(DSCR_DEFAULT, &val, 16); if (err) { perror("read() failed"); exit(1); } - sscanf(buf, "%lx", &val); return val; } void set_default_dscr(unsigned long val) { int err; - char buf[16]; - sprintf(buf, "%lx\n", val); - - err = write_file(DSCR_DEFAULT, buf, strlen(buf)); + err = write_ulong(DSCR_DEFAULT, val, 16); if (err) { perror("write() failed"); exit(1); diff --git a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c index c350f193830a..4f1fef6198fc 100644 --- a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c +++ b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c @@ -12,16 +12,16 @@ static int check_cpu_dscr_default(char *file, unsigned long val) { - char buf[10] = {0}; - int rc; + unsigned long cpu_dscr; + int err; - rc = read_file(file, buf, sizeof(buf) - 1, NULL); - if (rc) - return rc; + err = read_ulong(file, &cpu_dscr, 16); + if (err) + return err; - if (strtol(buf, NULL, 16) != val) { + if (cpu_dscr != val) { printf("DSCR match failed: %ld (system) %ld (cpu)\n", - val, strtol(buf, NULL, 16)); + val, cpu_dscr); return 1; } return 0; |