From: Heiner Kallweit <hkallweit1@gmail.com>
To: Brian Norris <computersforpeace@gmail.com>
Cc: linux-mtd@lists.infradead.org
Subject: [PATCH 1/3] mtd: m25p80: add error handling to m25p80_read
Date: Tue, 17 Nov 2015 20:18:24 +0100 [thread overview]
Message-ID: <564B7D80.7060005@gmail.com> (raw)
So far m25p80_read always returns 0, even if the spi_sync call fails.
Handle the case this call fails and also handle the case
m.actual_length < cmd_len properly.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/mtd/devices/m25p80.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 4b5d7a4..634b0c4 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -126,10 +126,11 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
struct spi_device *spi = flash->spi;
struct spi_transfer t[2];
struct spi_message m;
- unsigned int dummy = nor->read_dummy;
+ unsigned int cmd_len;
+ int ret;
/* convert the dummy cycles to the number of bytes */
- dummy /= 8;
+ cmd_len = m25p_cmdsz(nor) + nor->read_dummy / 8;
spi_message_init(&m);
memset(t, 0, (sizeof t));
@@ -138,7 +139,7 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
m25p_addr2cmd(nor, from, flash->command);
t[0].tx_buf = flash->command;
- t[0].len = m25p_cmdsz(nor) + dummy;
+ t[0].len = cmd_len;
spi_message_add_tail(&t[0], &m);
t[1].rx_buf = buf;
@@ -146,10 +147,17 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
t[1].len = len;
spi_message_add_tail(&t[1], &m);
- spi_sync(spi, &m);
+ ret = spi_sync(spi, &m);
- *retlen = m.actual_length - m25p_cmdsz(nor) - dummy;
- return 0;
+ if (m.actual_length >= cmd_len)
+ *retlen = m.actual_length - cmd_len;
+ else
+ /* not even the command may have been
+ * transferred completely
+ */
+ *retlen = 0;
+
+ return ret;
}
static int m25p80_erase(struct spi_nor *nor, loff_t offset)
--
2.6.2
reply other threads:[~2015-11-17 19:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=564B7D80.7060005@gmail.com \
--to=hkallweit1@gmail.com \
--cc=computersforpeace@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.