From 49183bfb7918009b4ac269bde6ecb8389500e8a4 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Mon, 11 Aug 2025 16:16:19 +0200 Subject: [PATCH] pan/bi: use os_read_file-helper We already have a more robust helper for this, so let's use it rather than open-coding the same. While we're at it, return early on error for readability here. There's no need to continue the logic in those cases. CID: 1444074 Reviewed-by: Eric R. Smith Part-of: --- src/panfrost/compiler/cmdline.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/panfrost/compiler/cmdline.c b/src/panfrost/compiler/cmdline.c index 9982bfc6755..4b1955dd86a 100644 --- a/src/panfrost/compiler/cmdline.c +++ b/src/panfrost/compiler/cmdline.c @@ -31,6 +31,8 @@ #include "valhall/disassemble.h" #include "panfrost/lib/pan_props.h" +#include "util/os_file.h" + unsigned gpu_id = 0x72120000; int verbose = 0; @@ -44,18 +46,13 @@ disassemble(const char *filename) FILE *fp = fopen(filename, "rb"); assert(fp); - fseek(fp, 0, SEEK_END); - unsigned filesize = ftell(fp); - rewind(fp); - - uint32_t *code = malloc(filesize); - unsigned res = fread(code, 1, filesize, fp); - if (res != filesize) { - printf("Couldn't read full file\n"); + size_t filesize = 0; + uint32_t *code = (uint32_t *)os_read_file(filename, &filesize); + if (!code) { + fprintf(stderr, "Couldn't read full file\n"); + return; } - fclose(fp); - void *entrypoint = code; if (filesize && code[0] == BI_FOURCC('M', 'B', 'S', '2')) {