]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
ras-mce-handler: Fix /proc/cpuinfo parser
authorMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 28 May 2013 10:47:53 +0000 (07:47 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 28 May 2013 11:06:24 +0000 (08:06 -0300)
The test for the parsing completion is wrong. Fix it.

While here, change the namespace to avoid latter
conflicts.

Reported-by: Chen Gong <gong.chen@intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
ras-mce-handler.c

index 5e7ea3f6df5febd87dfae5c54c8e6114e8ddb557..e0488d03103a1d5a77c0a856fd616c86b773f43d 100644 (file)
@@ -107,12 +107,12 @@ static int detect_cpu(struct ras_events *ras)
        char *line = NULL;
        size_t linelen = 0;
        enum {
-               VENDOR = 1,
-               FAMILY = 2,
-               MODEL = 4,
-               MHZ = 8,
-               FLAGS = 16,
-               ALL_FLAGS = 0x1f
+               CPU_VENDOR = 1,
+               CPU_FAMILY = 2,
+               CPU_MODEL = 4,
+               CPU_MHZ = 8,
+               CPU_FLAGS = 16,
+               CPU_ALL = 0x1f
        } seen = 0;
 
        mce->family = 0;
@@ -126,28 +126,33 @@ static int detect_cpu(struct ras_events *ras)
                return errno;
        }
 
-       while (getdelim(&line, &linelen, '\n', f) > 0 && seen != ALL) {
+       while (getdelim(&line, &linelen, '\n', f) > 0 && seen != CPU_ALL) {
                if (sscanf(line, "vendor_id : %63[^\n]",
                    (char *)&mce->vendor) == 1)
-                       seen |= VENDOR;
-               if (sscanf(line, "cpu family : %d", &mce->family) == 1)
-                       seen |= FAMILY;
-               if (sscanf(line, "model : %d", &mce->model) == 1)
-                       seen |= MODEL;
-               if (sscanf(line, "cpu MHz : %lf", &mce->mhz) == 1)
-                       seen |= MHZ;
-               if (!strncmp(line, "flags", 5) && isspace(line[6])) {
+                       seen |= CPU_VENDOR;
+               else if (sscanf(line, "cpu family : %d", &mce->family) == 1)
+                       seen |= CPU_FAMILY;
+               else if (sscanf(line, "model : %d", &mce->model) == 1)
+                       seen |= CPU_MODEL;
+               else if (sscanf(line, "cpu MHz : %lf", &mce->mhz) == 1)
+                       seen |= CPU_MHZ;
+               else if (!strncmp(line, "flags", 5) && isspace(line[6])) {
                        if (mce->processor_flags)
                                free(mce->processor_flags);
                        mce->processor_flags = line;
                        line = NULL;
                        linelen = 0;
-                       seen |= ALL_FLAGS;
+                       seen |= CPU_FLAGS;
                }
        }
 
-       if (!(seen == ALL)) {
-               log(ALL, LOG_INFO, "Can't parse /proc/cpuinfo\n");
+       if (seen != CPU_ALL) {
+               log(ALL, LOG_INFO, "Can't parse /proc/cpuinfo: missing%s%s%s%s%s\n",
+                       (seen & CPU_VENDOR) ? "" : " [vendor_id]",
+                       (seen & CPU_FAMILY) ? "" : " [cpu family]",
+                       (seen & CPU_MODEL)  ? "" : " [model]",
+                       (seen & CPU_MHZ)    ? "" : " [cpu MHz]",
+                       (seen & CPU_FLAGS)  ? "" : " [flags]");
                ret = EINVAL;
                goto ret;
        }