From 03999595e7cdb65a64af84ed6b61785cf2be0f49 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 31 Dec 2020 18:29:04 -0800 Subject: [PATCH] freedreno/afuc: Replace readfile with os_read_file. Tested afuc-disasm produced same output. $ ./builddir/src/freedreno/afuc/afuc-disasm -g 6 src/freedreno/.gitlab-ci/reference/afuc_test.fw > /tmp/afuc_test.asm $ diff ./src/freedreno/.gitlab-ci/reference/afuc_test.asm /tmp/afuc_test.asm $ echo $? 0 Suggested-by: Rob Clark Signed-off-by: Vinson Lee Part-of: --- src/freedreno/afuc/disasm.c | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/src/freedreno/afuc/disasm.c b/src/freedreno/afuc/disasm.c index ef28b6a4ba9..0a62ba7dcb1 100644 --- a/src/freedreno/afuc/disasm.c +++ b/src/freedreno/afuc/disasm.c @@ -33,6 +33,8 @@ #include #include +#include "util/os_file.h" + #include "afuc.h" #include "rnn.h" #include "rnndec.h" @@ -773,36 +775,6 @@ static void disasm(uint32_t *buf, int sizedwords) } } -#define CHUNKSIZE 4096 - -static char * readfile(const char *path, int *sz) -{ - char *buf = NULL; - int fd, ret, n = 0; - - fd = open(path, O_RDONLY); - if (fd < 0) { - *sz = 0; - return NULL; - } - - while (1) { - buf = realloc(buf, n + CHUNKSIZE); - ret = read(fd, buf + n, CHUNKSIZE); - if (ret < 0) { - free(buf); - *sz = 0; - return NULL; - } else if (ret < CHUNKSIZE) { - n += ret; - *sz = n; - return buf; - } else { - n += CHUNKSIZE; - } - } -} - static void usage(void) { fprintf(stderr, "Usage:\n" @@ -819,7 +791,8 @@ int main(int argc, char **argv) uint32_t *buf; char *file, *control_reg_name; bool colors = false; - int sz, c; + size_t sz; + int c; /* Argument parsing: */ while ((c = getopt (argc, argv, "g:vc")) != -1) { @@ -886,7 +859,7 @@ int main(int argc, char **argv) rnndec_varadd(ctx, "chip", variant); - buf = (uint32_t *)readfile(file, &sz); + buf = (uint32_t *)os_read_file(file, &sz); printf("; Disassembling microcode: %s\n", file); printf("; Version: %08x\n\n", buf[1]);