To represent 'cpu' case in '/proc/stat' which has summation for all
cpus, the number of cpu is set to -1, but data type of number is
unsigned int. This corrects data type and change the name of member
from 'cpu' to 'id' for understanding meaning easily.
In addition, since 'id' is used as index of cpu stat array, it also
checks that the index is in the proper range.
Change-Id: I7e368176257c695d59420e7b4906d5bdb6d8aadf
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
struct cpu_stat {
char name[10];
- unsigned int cpu;
+ int id;
int64_t user;
int64_t system;
int64_t nice;
goto err;
} else if (strlen(data->name) > 3) {
/* In case of 'cpu%u' string */
- ret = sscanf(data->name, "cpu%4u", &data->cpu);
+ ret = sscanf(data->name, "cpu%4d", &data->id);
if (ret < 1) {
ret = -EINVAL;
goto err;
}
} else {
/* In case of 'cpu' string */
- data->cpu = -1;
+ data->id = -1;
}
return 0;
if (__get_cpu_stat(fp, &cpu) < 0)
continue;
- if (cpu.cpu < 0) {
+ if (cpu.id < 0 || cpu.id > num_possible_cpus - 1) {
ret = -EINVAL;
goto err;
}
- memcpy(&cpus[cpu.cpu], &cpu, sizeof(struct cpu_stat));
+ memcpy(&cpus[cpu.id], &cpu, sizeof(struct cpu_stat));
count++;
}