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]);