]> www.infradead.org Git - users/mchehab/edactool.git/commitdiff
edactool: fix read logic
authorMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 26 Feb 2013 14:51:13 +0000 (11:51 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 26 Feb 2013 17:36:22 +0000 (14:36 -0300)
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
edactool.c

index 2d94e9142fbbc810d93f877a13d00bd546faba85..046221566cd2a9e2362a758339c10d52f5b6259c 100644 (file)
@@ -108,21 +108,28 @@ static void parse_ras_data(struct pevent *pevent, struct kbuffer *kbuf, void *da
 
 static int read_ras_event(int fd, struct pevent *pevent, struct kbuffer *kbuf, void *page)
 {
+       unsigned size;
        unsigned long long time_stamp;
        void *data;
 
-       if (read(fd, page, PAGE_SIZE) <= 0)
-               return -1;
-
-       kbuffer_load_subbuffer(kbuf, page);
-
-       while ((data = kbuffer_read_event(kbuf, &time_stamp)))
-               parse_ras_data(pevent, kbuf, data, time_stamp);
-
-       /* increment to read next event */
-       kbuffer_next_event(kbuf, NULL);
-
-       return 0;
+       do {
+               size = read(fd, page, PAGE_SIZE);
+               if (size < 0) {
+                       perror ("read");
+                       return -1;
+               } else if (size > 0) {
+                       kbuffer_load_subbuffer(kbuf, page);
+
+                       while ((data = kbuffer_read_event(kbuf, &time_stamp))) {
+                               parse_ras_data(pevent, kbuf, data, time_stamp);
+
+                               /* increment to read next event */
+                               kbuffer_next_event(kbuf, NULL);
+                       }
+               } else {
+                       printf("read size = 0\n");
+               }
+       } while (1);
 }
 
 static int get_num_cpus(void)