+static int cpu_states_grow (void)
+{
+ void *tmp;
+ int size;
+ int i;
+
+ size = cpu_count * CPU_SUBMIT_MAX; /* always alloc for all states */
+
+ if (size <= 0)
+ return 0;
+
+ if (percents_cells >= size)
+ return 0;
+
+ if (percents == NULL) {
+ percents = malloc(size * sizeof(*percents));
+ if (percents == NULL)
+ return -1;
+ for (i = 0; i < size; i++)
+ memset(&percents[i], 0, sizeof(*percents));
+ percents_cells = size;
+ return 0;
+ }
+
+ tmp = realloc(percents, size * sizeof(*percents));
+
+ if (tmp == NULL) {
+ ERROR ("cpu plugin: could not reserve enough space to hold states");
+ percents = NULL;
+ return -1;
+ }
+
+ percents = tmp;
+
+ for (i = percents_cells ; i < size; i++)
+ memset(&percents[i], 0, sizeof(*percents));
+
+ percents_cells = size;
+ return 0;
+} /* cpu_states_grow */
+
+