mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-25 00:52:45 -04:00
selftests/powerpc: Add generic read/write file util
File read/write is reimplemented in about 5 different ways in the various PowerPC selftests. This indicates it should be a common util. Add a common read_file / write_file implementation and convert users to it where (easily) possible. 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-2-bgray@linux.ibm.com
This commit is contained in:
committed by
Michael Ellerman
parent
b505063910
commit
a974f0c131
@@ -12,24 +12,13 @@
|
||||
|
||||
static int check_cpu_dscr_default(char *file, unsigned long val)
|
||||
{
|
||||
char buf[10];
|
||||
int fd, rc;
|
||||
char buf[10] = {0};
|
||||
int rc;
|
||||
|
||||
fd = open(file, O_RDWR);
|
||||
if (fd == -1) {
|
||||
perror("open() failed");
|
||||
return 1;
|
||||
}
|
||||
rc = read_file(file, buf, sizeof(buf) - 1, NULL);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
rc = read(fd, buf, sizeof(buf));
|
||||
if (rc == -1) {
|
||||
perror("read() failed");
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
buf[rc] = '\0';
|
||||
if (strtol(buf, NULL, 16) != val) {
|
||||
printf("DSCR match failed: %ld (system) %ld (cpu)\n",
|
||||
val, strtol(buf, NULL, 16));
|
||||
|
||||
Reference in New Issue
Block a user