]> www.infradead.org Git - mtd-utils.git/commitdiff
nandtest: Move the "read and compare" code to a function
authorEzequiel Garcia <ezequiel@vanguardiasur.com.ar>
Mon, 28 Apr 2014 13:14:18 +0000 (10:14 -0300)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Mon, 5 May 2014 07:32:33 +0000 (10:32 +0300)
This commit makes no functionality change, and simply moves the
read and compare code into a separate read_and_compare() function.

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
nandtest.c

index fd78b9568253c4e1432caf8a9b7338c5e1b6c31e..31301d68b4d909a8f4394876a7d35fe6dfa25d0b 100644 (file)
@@ -37,46 +37,11 @@ int fd;
 int markbad=0;
 int seed;
 
-int erase_and_write(loff_t ofs, unsigned char *data, unsigned char *rbuf)
+void read_and_compare(loff_t ofs, unsigned char *data, unsigned char *rbuf)
 {
-       struct erase_info_user er;
        ssize_t len;
        int i;
 
-       printf("\r%08x: erasing... ", (unsigned)ofs);
-       fflush(stdout);
-
-       er.start = ofs;
-       er.length = meminfo.erasesize;
-
-       if (ioctl(fd, MEMERASE, &er)) {
-               perror("MEMERASE");
-               if (markbad) {
-                       printf("Mark block bad at %08lx\n", (long)ofs);
-                       ioctl(fd, MEMSETBADBLOCK, &ofs);
-               }
-               return 1;
-       }
-
-       printf("\r%08x: writing...", (unsigned)ofs);
-       fflush(stdout);
-
-       len = pwrite(fd, data, meminfo.erasesize, ofs);
-       if (len < 0) {
-               printf("\n");
-               perror("write");
-               if (markbad) {
-                       printf("Mark block bad at %08lx\n", (long)ofs);
-                       ioctl(fd, MEMSETBADBLOCK, &ofs);
-               }
-               return 1;
-       }
-       if (len < meminfo.erasesize) {
-               printf("\n");
-               fprintf(stderr, "Short write (%zd bytes)\n", len);
-               exit(1);
-       }
-
        printf("\r%08x: reading...", (unsigned)ofs);
        fflush(stdout);
 
@@ -121,6 +86,48 @@ int erase_and_write(loff_t ofs, unsigned char *data, unsigned char *rbuf)
                }
                exit(1);
        }
+}
+
+int erase_and_write(loff_t ofs, unsigned char *data, unsigned char *rbuf)
+{
+       struct erase_info_user er;
+       ssize_t len;
+
+       printf("\r%08x: erasing... ", (unsigned)ofs);
+       fflush(stdout);
+
+       er.start = ofs;
+       er.length = meminfo.erasesize;
+
+       if (ioctl(fd, MEMERASE, &er)) {
+               perror("MEMERASE");
+               if (markbad) {
+                       printf("Mark block bad at %08lx\n", (long)ofs);
+                       ioctl(fd, MEMSETBADBLOCK, &ofs);
+               }
+               return 1;
+       }
+
+       printf("\r%08x: writing...", (unsigned)ofs);
+       fflush(stdout);
+
+       len = pwrite(fd, data, meminfo.erasesize, ofs);
+       if (len < 0) {
+               printf("\n");
+               perror("write");
+               if (markbad) {
+                       printf("Mark block bad at %08lx\n", (long)ofs);
+                       ioctl(fd, MEMSETBADBLOCK, &ofs);
+               }
+               return 1;
+       }
+       if (len < meminfo.erasesize) {
+               printf("\n");
+               fprintf(stderr, "Short write (%zd bytes)\n", len);
+               exit(1);
+       }
+
+       read_and_compare(ofs, data, rbuf);
        return 0;
 }