linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Cano" <ccano@interfaceconcept.com>
To: linux-mtd@lists.infradead.org
Subject: [PATCH 1/2] drivers/mtd/devices/m25p80.c: Fix return code of read/write mtd callbacks
Date: Mon, 03 Sep 2012 17:58:13 +0200	[thread overview]
Message-ID: <5044D395.9050607@ic.fr> (raw)

From: Cédric Cano <ccano@interfaceconcept.com>

For SPI Flash devices, MTD read and write functions returns "1" if Flash 
is busy (this status is returned by "wait_till_ready" fnuction). This 
return code is not an error code: if device is busy, MTD read or write 
are successful with 1 byte length.

This patch fixes code returned by "wait_till_ready", "m25p80_erase", 
"m25p80_read", "m25p80_write" and "sst_write" functions: the error code 
is -EBUSY now.

C. Cano

Signed-off-by: Cédric Cano <ccano@interfaceconcept.com>

---
--- linux-3.5.3/drivers/mtd/devices/m25p80.c    2012-08-26 
04:32:13.000000000 +0200
+++ linux-3.5.3/drivers/mtd/devices/m25p80.c    2012-09-03 
17:35:16.159741656 +0200
@@ -199,7 +199,7 @@

      } while (!time_after_eq(jiffies, deadline));

-    return 1;
+    return -EBUSY;
  }

  /*
@@ -209,12 +209,15 @@
   */
  static int erase_chip(struct m25p *flash)
  {
+    int    ret;
+
      pr_debug("%s: %s %lldKiB\n", dev_name(&flash->spi->dev), __func__,
              (long long)(flash->mtd.size >> 10));

      /* Wait until finished previous write command. */
-    if (wait_till_ready(flash))
-        return 1;
+    ret = wait_till_ready(flash);
+    if (ret)
+        return ret;

      /* Send write enable, then erase commands. */
      write_enable(flash);
@@ -249,12 +252,15 @@
   */
  static int erase_sector(struct m25p *flash, u32 offset)
  {
+    int    ret;
+
      pr_debug("%s: %s %dKiB at 0x%08x\n", dev_name(&flash->spi->dev),
              __func__, flash->mtd.erasesize / 1024, offset);

      /* Wait until finished previous write command. */
-    if (wait_till_ready(flash))
-        return 1;
+    ret = wait_till_ready(flash);
+    if (ret)
+        return ret;

      /* Send write enable, then erase commands. */
      write_enable(flash);
@@ -283,6 +289,7 @@
      struct m25p *flash = mtd_to_m25p(mtd);
      u32 addr,len;
      uint32_t rem;
+    int ret;

      pr_debug("%s: %s at 0x%llx, len %lld\n", dev_name(&flash->spi->dev),
              __func__, (long long)instr->addr,
@@ -299,10 +306,11 @@

      /* whole-chip erase? */
      if (len == flash->mtd.size) {
-        if (erase_chip(flash)) {
+        ret = erase_chip(flash);
+        if (ret) {
              instr->state = MTD_ERASE_FAILED;
              mutex_unlock(&flash->lock);
-            return -EIO;
+            return ret;
          }

      /* REVISIT in some cases we could speed up erasing large regions
@@ -313,10 +321,11 @@
      /* "sector"-at-a-time erase */
      } else {
          while (len) {
-            if (erase_sector(flash, addr)) {
+            ret = erase_sector(flash, addr);
+            if (ret) {
                  instr->state = MTD_ERASE_FAILED;
                  mutex_unlock(&flash->lock);
-                return -EIO;
+                return ret;
              }

              addr += mtd->erasesize;
@@ -339,6 +348,7 @@
  static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
      size_t *retlen, u_char *buf)
  {
+    int ret;
      struct m25p *flash = mtd_to_m25p(mtd);
      struct spi_transfer t[2];
      struct spi_message m;
@@ -364,10 +374,11 @@
      mutex_lock(&flash->lock);

      /* Wait till previous write/erase is done. */
-    if (wait_till_ready(flash)) {
+    ret = wait_till_ready(flash);
+    if (ret) {
          /* REVISIT status return?? */
          mutex_unlock(&flash->lock);
-        return 1;
+        return ret;
      }

      /* FIXME switch to OPCODE_FAST_READ.  It's required for higher
@@ -396,6 +407,7 @@
  static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
      size_t *retlen, const u_char *buf)
  {
+    int ret;
      struct m25p *flash = mtd_to_m25p(mtd);
      u32 page_offset, page_size;
      struct spi_transfer t[2];
@@ -417,9 +429,10 @@
      mutex_lock(&flash->lock);

      /* Wait until finished previous write command. */
-    if (wait_till_ready(flash)) {
+    ret = wait_till_ready(flash);
+    if (ret) {
          mutex_unlock(&flash->lock);
-        return 1;
+        return ret;
      }

      write_enable(flash);
---

             reply	other threads:[~2012-09-03 15:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-03 15:58 Cédric Cano [this message]
2012-09-03 18:26 ` [PATCH 1/2] drivers/mtd/devices/m25p80.c: Fix return code of read/write mtd callbacks Kevin Cernekee
2012-09-04  7:54   ` Cédric Cano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5044D395.9050607@ic.fr \
    --to=ccano@interfaceconcept.com \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).