From da26563a83961e2aa738141b4e0140d7796fc78c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 12 Jan 2023 12:20:30 +0100 Subject: [PATCH] cpu: clean up Change read_file to spa_cpu_read_file and remove static because it might not be used for some cpus. Use spa_cpu_read_file in arm cpu detection. --- spa/plugins/support/cpu-arm.c | 27 ++------------------------- spa/plugins/support/cpu.c | 4 ++-- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/spa/plugins/support/cpu-arm.c b/spa/plugins/support/cpu-arm.c index fe6222f7c..cfc54272c 100644 --- a/spa/plugins/support/cpu-arm.c +++ b/spa/plugins/support/cpu-arm.c @@ -49,37 +49,14 @@ static char *get_cpuinfo_line(char *cpuinfo, const char *tag) return strndup(colon, end - colon); } -static char *get_cpuinfo(void) -{ - char *cpuinfo; - int n, fd; - - cpuinfo = malloc(MAX_BUFFER); - - if ((fd = open("/proc/cpuinfo", O_RDONLY | O_CLOEXEC, 0)) < 0) { - free(cpuinfo); - return NULL; - } - - if ((n = read(fd, cpuinfo, MAX_BUFFER-1)) < 0) { - free(cpuinfo); - close(fd); - return NULL; - } - cpuinfo[n] = 0; - close(fd); - - return cpuinfo; -} - static int arm_init(struct impl *impl) { uint32_t flags = 0; - char *cpuinfo, *line; + char *cpuinfo, *line, buffer[MAX_BUFFER]; int arch; - if (!(cpuinfo = get_cpuinfo())) { + if (!(cpuinfo = spa_cpu_read_file("/proc/cpuinfo", buffer, sizeof(buffer)))) { spa_log_warn(impl->log, "%p: Can't read cpuinfo", impl); return 1; } diff --git a/spa/plugins/support/cpu.c b/spa/plugins/support/cpu.c index 3e6bb85dd..fc13c1615 100644 --- a/spa/plugins/support/cpu.c +++ b/spa/plugins/support/cpu.c @@ -59,7 +59,7 @@ struct impl { uint32_t vm_type; }; -static char *read_file(const char *name, char *buffer, size_t len) +char *spa_cpu_read_file(const char *name, char *buffer, size_t len) { int n, fd; @@ -175,7 +175,7 @@ impl_cpu_get_vm_type(void *object) SPA_FOR_EACH_ELEMENT_VAR(dmi_vendors, dv) { char buffer[256], *s; - if ((s = read_file(*dv, buffer, sizeof(buffer))) == NULL) + if ((s = spa_cpu_read_file(*dv, buffer, sizeof(buffer))) == NULL) continue; SPA_FOR_EACH_ELEMENT_VAR(dmi_vendor_table, t) {