*
**************************************************************************/
-#if HAVE_GALLIUM_EXTRA_HUD
+#ifdef HAVE_GALLIUM_EXTRA_HUD
/* Purpose:
* Reading /sys/devices/system/cpu/cpu?/cpufreq/scaling_???_freq
#include "hud/hud_private.h"
#include "util/list.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
#include "os/os_thread.h"
#include "util/u_memory.h"
#include <stdio.h>
static int gcpufreq_count = 0;
static struct list_head gcpufreq_list;
-pipe_static_mutex(gcpufreq_mutex);
+static mtx_t gcpufreq_mutex = _MTX_INITIALIZER_NP;
static struct cpufreq_info *
find_cfi_by_index(int cpu_index, int mode)
}
static void
-query_cfi_load(struct hud_graph *gr)
+query_cfi_load(struct hud_graph *gr, struct pipe_context *pipe)
{
struct cpufreq_info *cfi = gr->query_data;
break;
case CPUFREQ_MAXIMUM:
snprintf(gr->name, sizeof(gr->name), "%s-Max", cfi->name);
+ break;
default:
+ free(gr);
return;
}
int cpu_index;
/* Return the number of CPU metrics we support. */
- pipe_mutex_lock(gcpufreq_mutex);
+ mtx_lock(&gcpufreq_mutex);
if (gcpufreq_count) {
- pipe_mutex_unlock(gcpufreq_mutex);
+ mtx_unlock(&gcpufreq_mutex);
return gcpufreq_count;
}
list_inithead(&gcpufreq_list);
DIR *dir = opendir("/sys/devices/system/cpu");
if (!dir) {
- pipe_mutex_unlock(gcpufreq_mutex);
+ mtx_unlock(&gcpufreq_mutex);
return 0;
}
while ((dp = readdir(dir)) != NULL) {
- /* Avoid 'lo' and '..' and '.' */
- if (strlen(dp->d_name) <= 2)
+ size_t d_name_len = strlen(dp->d_name);
+
+ /* Avoid 'lo' and '..' and '.', and avoid overlong names that
+ * would result in a buffer overflow in add_object.
+ */
+ if (d_name_len <= 2 || d_name_len > 15)
continue;
if (sscanf(dp->d_name, "cpu%d\n", &cpu_index) != 1)
}
}
- pipe_mutex_unlock(gcpufreq_mutex);
+ mtx_unlock(&gcpufreq_mutex);
return gcpufreq_count;
}