Mesa (main): intel/tools: Stop malloc'ing device info in i965_disasm

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jul 1 00:15:51 UTC 2022


Module: Mesa
Branch: main
Commit: c0784804a1134eb33f6bb1509b568e497c23cd93
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c0784804a1134eb33f6bb1509b568e497c23cd93

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Jun 29 20:25:22 2022 -0700

intel/tools: Stop malloc'ing device info in i965_disasm

There's not really any point, a stack allocated struct works fine.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17309>

---

 src/intel/tools/i965_disasm.c | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/src/intel/tools/i965_disasm.c b/src/intel/tools/i965_disasm.c
index 593a71650a7..7a9f496b4fa 100644
--- a/src/intel/tools/i965_disasm.c
+++ b/src/intel/tools/i965_disasm.c
@@ -113,24 +113,6 @@ i965_disasm_read_binary(FILE *fp, size_t *end)
    return assembly;
 }
 
-static struct intel_device_info *
-i965_disasm_init(uint16_t pci_id)
-{
-   struct intel_device_info *devinfo;
-
-   devinfo = malloc(sizeof *devinfo);
-   if (devinfo == NULL)
-      return NULL;
-
-   if (!intel_get_device_info_from_pci_id(pci_id, devinfo)) {
-      fprintf(stderr, "can't find device information: pci_id=0x%x\n",
-              pci_id);
-      exit(EXIT_FAILURE);
-   }
-
-   return devinfo;
-}
-
 static void
 print_help(const char *progname, FILE *file)
 {
@@ -154,7 +136,6 @@ int main(int argc, char *argv[])
    size_t start = 0, end = 0;
    uint16_t pci_id = 0;
    int c;
-   struct intel_device_info *devinfo = NULL;
    int result = EXIT_FAILURE;
 
    bool help = false;
@@ -221,11 +202,10 @@ int main(int argc, char *argv[])
       exit(0);
    }
 
-   devinfo = i965_disasm_init(pci_id);
-   if (!devinfo) {
-      fprintf(stderr, "Unable to allocate memory for "
-                      "intel_device_info struct instance.\n");
-      goto end;
+   struct intel_device_info devinfo;
+   if (!intel_get_device_info_from_pci_id(pci_id, &devinfo)) {
+      fprintf(stderr, "can't find device information: pci_id=0x%x\n", pci_id);
+      exit(EXIT_FAILURE);
    }
 
    if (input_type == OPT_INPUT_BINARY)
@@ -243,7 +223,7 @@ int main(int argc, char *argv[])
    }
 
    /* Disassemble i965 instructions from buffer assembly */
-   brw_disassemble_with_labels(devinfo, assembly, start, end, stdout);
+   brw_disassemble_with_labels(&devinfo, assembly, start, end, stdout);
 
    result = EXIT_SUCCESS;
 
@@ -253,7 +233,6 @@ end:
 
    free(file_path);
    free(assembly);
-   free(devinfo);
 
    exit(result);
 }



More information about the mesa-commit mailing list