mtd: mtdoops: do not use mtd->panic_write directly
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Wed, 28 Dec 2011 15:27:18 +0000 (17:27 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 9 Jan 2012 18:26:13 +0000 (18:26 +0000)
Instead of checking if 'mtd->panic_write' is defined, call 'mtd_panic_write()'
and check the error code - '-EOPNOTSUPP' will be returned if the function is
not defined.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/mtdoops.c
include/linux/mtd/mtd.h

index 69532a34e563f83df36eb58bb3a0864b17ea78c1..c8540b8a7fc6cf4f987cf4045ca35a62db2d060c 100644 (file)
@@ -221,10 +221,14 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic)
        hdr[0] = cxt->nextcount;
        hdr[1] = MTDOOPS_KERNMSG_MAGIC;
 
-       if (panic)
+       if (panic) {
                ret = mtd_panic_write(mtd, cxt->nextpage * record_size,
                                      record_size, &retlen, cxt->oops_buf);
-       else
+               if (ret == -EOPNOTSUPP) {
+                       printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n");
+                       return;
+               }
+       } else
                ret = mtd_write(mtd, cxt->nextpage * record_size,
                                record_size, &retlen, cxt->oops_buf);
 
@@ -330,13 +334,8 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper,
        memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy);
 
        /* Panics must be written immediately */
-       if (reason != KMSG_DUMP_OOPS) {
-               if (!cxt->mtd->panic_write)
-                       printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n");
-               else
-                       mtdoops_write(cxt, 1);
-               return;
-       }
+       if (reason != KMSG_DUMP_OOPS)
+               mtdoops_write(cxt, 1);
 
        /* For other cases, schedule work to write it "nicely" */
        schedule_work(&cxt->work_write);
index 2c2a92247e5a93dae465ffbe23a12015ea3880e2..b72964049cdc165a199f409a84343f123cd5a03f 100644 (file)
@@ -311,6 +311,8 @@ static inline int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
                                  size_t *retlen, const u_char *buf)
 {
        *retlen = 0;
+       if (!mtd->panic_write)
+               return -EOPNOTSUPP;
        return mtd->panic_write(mtd, to, len, retlen, buf);
 }