]> Pileus Git - ~andy/linux/blobdiff - tools/power/x86/turbostat/turbostat.c
turbostat: Check return value of fscanf
[~andy/linux] / tools / power / x86 / turbostat / turbostat.c
index 51741a1b7021bde03dfce4ad389cc8ceff75f52e..4f7b88b035c34946201f8e1ca1c20f8702149200 100644 (file)
@@ -1189,7 +1189,10 @@ int cpu_is_first_sibling_in_core(int cpu)
                perror(path);
                exit(1);
        }
-       fscanf(filep, "%d", &first_cpu);
+       if (fscanf(filep, "%d", &first_cpu) != 1) {
+               perror(path);
+               exit(1);
+       }
        fclose(filep);
        return (cpu == first_cpu);
 }
@@ -1210,7 +1213,10 @@ int cpu_is_first_core_in_package(int cpu)
                perror(path);
                exit(1);
        }
-       fscanf(filep, "%d", &first_cpu);
+       if (fscanf(filep, "%d", &first_cpu) != 1) {
+               perror(path);
+               exit(1);
+       }
        fclose(filep);
        return (cpu == first_cpu);
 }
@@ -1227,7 +1233,10 @@ int get_physical_package_id(int cpu)
                perror(path);
                exit(1);
        }
-       fscanf(filep, "%d", &pkg);
+       if (fscanf(filep, "%d", &pkg) != 1) {
+               perror(path);
+               exit(1);
+       }
        fclose(filep);
        return pkg;
 }
@@ -1244,7 +1253,10 @@ int get_core_id(int cpu)
                perror(path);
                exit(1);
        }
-       fscanf(filep, "%d", &core);
+       if (fscanf(filep, "%d", &core) != 1) {
+               perror(path);
+               exit(1);
+       }
        fclose(filep);
        return core;
 }