From: Brian Norris <computersforpeace@gmail.com>
To: Fabio Estevam <festevam@gmail.com>
Cc: linux-mtd@lists.infradead.org,
Fabio Estevam <fabio.estevam@freescale.com>
Subject: Re: [PATCH v2] mtd: spi-nor: Check the return value from read_sr()
Date: Wed, 9 Dec 2015 18:17:41 -0800 [thread overview]
Message-ID: <20151210021741.GF144338@google.com> (raw)
In-Reply-To: <1448043971-20230-1-git-send-email-festevam@gmail.com>
On Fri, Nov 20, 2015 at 04:26:11PM -0200, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
>
> We should better check the return value from read_sr() and
> propagate it in the case of error.
>
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---
> Changes since v1:
> - Change status_old and status_new to int (Brian).
>
> drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 16c9f55..b5e505d 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -459,11 +459,13 @@ static int stm_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len,
> static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
> {
> struct mtd_info *mtd = &nor->mtd;
> - u8 status_old, status_new;
> + int status_old, status_new;
> u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
> u8 shift = ffs(mask) - 1, pow, val;
>
> status_old = read_sr(nor);
> + if (status_old < 0)
> + return status_old;
This wasn't exactly what I was imagining (I figured have an 'int ret'
just for th error code, but still keep 'u8 status_{old,new}'), but still
looks good to me. Applied to l2-mtd.git. Thanks!
Brian
>
> /* SPI NOR always locks to the end */
> if (ofs + len != mtd->size) {
> @@ -509,11 +511,13 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
> static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
> {
> struct mtd_info *mtd = &nor->mtd;
> - uint8_t status_old, status_new;
> + int status_old, status_new;
> u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
> u8 shift = ffs(mask) - 1, pow, val;
>
> status_old = read_sr(nor);
> + if (status_old < 0)
> + return status_old;
>
> /* Cannot unlock; would unlock larger region than requested */
> if (stm_is_locked_sr(nor, status_old, ofs - mtd->erasesize,
> @@ -1013,6 +1017,8 @@ static int macronix_quad_enable(struct spi_nor *nor)
> int ret, val;
>
> val = read_sr(nor);
> + if (val < 0)
> + return val;
> write_enable(nor);
>
> write_sr(nor, val | SR_QUAD_EN_MX);
> --
> 1.9.1
>
prev parent reply other threads:[~2015-12-10 2:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-20 18:26 [PATCH v2] mtd: spi-nor: Check the return value from read_sr() Fabio Estevam
2015-12-10 2:17 ` Brian Norris [this message]
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=20151210021741.GF144338@google.com \
--to=computersforpeace@gmail.com \
--cc=fabio.estevam@freescale.com \
--cc=festevam@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 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).