Mesa (master): freedreno/afuc: Replace readfile with os_read_file.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 6 18:19:18 UTC 2021


Module: Mesa
Branch: master
Commit: 03999595e7cdb65a64af84ed6b61785cf2be0f49
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=03999595e7cdb65a64af84ed6b61785cf2be0f49

Author: Vinson Lee <vlee at freedesktop.org>
Date:   Thu Dec 31 18:29:04 2020 -0800

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 <robdclark at chromium.org>
Signed-off-by: Vinson Lee <vlee at freedesktop.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8290>

---

 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 <assert.h>
 #include <getopt.h>
 
+#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]);



More information about the mesa-commit mailing list