]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
mtd: cfi_cmdset_0002: Split do_write_oneword() op_done goto statement
authorTokunori Ikegami <ikegami.t@gmail.com>
Mon, 5 Aug 2019 19:03:21 +0000 (04:03 +0900)
committerVignesh Raghavendra <vigneshr@ti.com>
Tue, 27 Aug 2019 12:25:53 +0000 (17:55 +0530)
To reduce function size and to remove the goto statement, split the
op_done goto statement part into do_write_oneword_done(). Also
split the start part into do_write_oneword_start() to be symmetrical.

Cc: Fabio Bettoni <fbettoni@gmail.com>
Co: Hauke Mehrtens <hauke@hauke-m.de>
Cc: Chris Packham <chris.packham@alliedtelesis.co.nz>
Cc: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
Cc: linux-mtd@lists.infradead.org
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
[vigneshr@ti.com: Reword commit message]
Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
drivers/mtd/chips/cfi_cmdset_0002.c

index 63d69fab4b3299655b41324a8fd47c55be3cbb50..d7e7a1a8cbdf48c863b83842ee9e0c0a4fdeba39 100644 (file)
@@ -1705,6 +1705,40 @@ static int __xipram do_write_oneword_once(struct map_info *map,
        return ret;
 }
 
+static int __xipram do_write_oneword_start(struct map_info *map,
+                                          struct flchip *chip,
+                                          unsigned long adr, int mode)
+{
+       int ret = 0;
+
+       mutex_lock(&chip->mutex);
+
+       ret = get_chip(map, chip, adr, mode);
+       if (ret) {
+               mutex_unlock(&chip->mutex);
+               return ret;
+       }
+
+       if (mode == FL_OTP_WRITE)
+               otp_enter(map, chip, adr, map_bankwidth(map));
+
+       return ret;
+}
+
+static void __xipram do_write_oneword_done(struct map_info *map,
+                                          struct flchip *chip,
+                                          unsigned long adr, int mode)
+{
+       if (mode == FL_OTP_WRITE)
+               otp_exit(map, chip, adr, map_bankwidth(map));
+
+       chip->state = FL_READY;
+       DISABLE_VPP(map);
+       put_chip(map, chip, adr);
+
+       mutex_unlock(&chip->mutex);
+}
+
 static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
                                     unsigned long adr, map_word datum,
                                     int mode)
@@ -1716,19 +1750,14 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
 
        adr += chip->start;
 
-       mutex_lock(&chip->mutex);
-       ret = get_chip(map, chip, adr, mode);
+       pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", __func__, adr,
+                datum.x[0]);
+
+       ret = do_write_oneword_start(map, chip, adr, mode);
        if (ret) {
-               mutex_unlock(&chip->mutex);
                return ret;
        }
 
-       pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n",
-                __func__, adr, datum.x[0]);
-
-       if (mode == FL_OTP_WRITE)
-               otp_enter(map, chip, adr, map_bankwidth(map));
-
        /*
         * Check for a NOP for the case when the datum to write is already
         * present - it saves time and works around buggy chips that corrupt
@@ -1737,9 +1766,9 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
         */
        oldd = map_read(map, adr);
        if (map_word_equal(map, oldd, datum)) {
-               pr_debug("MTD %s(): NOP\n",
-                        __func__);
-               goto op_done;
+               pr_debug("MTD %s(): NOP\n", __func__);
+               do_write_oneword_done(map, chip, adr, mode);
+               return ret;
        }
 
        XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map));
@@ -1760,13 +1789,8 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
                }
        }
        xip_enable(map, chip, adr);
- op_done:
-       if (mode == FL_OTP_WRITE)
-               otp_exit(map, chip, adr, map_bankwidth(map));
-       chip->state = FL_READY;
-       DISABLE_VPP(map);
-       put_chip(map, chip, adr);
-       mutex_unlock(&chip->mutex);
+
+       do_write_oneword_done(map, chip, adr, mode);
 
        return ret;
 }