All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH] mtd: spi-nor: handle controller driver limitations in spi_nor_read
Date: Fri, 20 Nov 2015 15:26:10 -0800	[thread overview]
Message-ID: <20151120232610.GB64635@google.com> (raw)
In-Reply-To: <5614182B.7060304@gmail.com>

Hi,

On Tue, Oct 06, 2015 at 08:51:23PM +0200, Heiner Kallweit wrote:
> Back in May there was a discussion on how to handle controller driver
> limitations like max message size (e.g. spi-fsl-espi supports
> message sizes up to 64Kb only).
> According to Brian extending the API might not be needed and a better
> handling of the returned actual_length of the message should be
> sufficient.
> 
> Following the suggestion this patch supports reading chunks.
> As long as something was read also errors (like -EMSGSIZE) are ignored.
> 
> Afterwards related hacks can be removed from affected controller drivers,
> making them work with any protocol driver.
> Currently e.g. spi-fsl-espi implicitely assumes that longer reads come
> from m25p80 protocol driver (if second transfer in message is a read and
> first transfer is a send then bytes 2-4 of the send are assumed to be a
> 3 byte address of a flash read).
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/mtd/spi-nor/spi-nor.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 4be41fb..17b5239 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -761,6 +761,7 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
>  			size_t *retlen, u_char *buf)
>  {
>  	struct spi_nor *nor = mtd_to_spi_nor(mtd);
> +	size_t bytes_read, pos = 0;
>  	int ret;
>  
>  	dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len);
> @@ -769,9 +770,21 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
>  	if (ret)
>  		return ret;
>  
> -	ret = nor->read(nor, from, len, retlen, buf);
> +	/* Consider the case that a controller driver is not able
> +	 * to read all requested bytes at once. It might return
> +	 * an error and the number of bytes read.
> +	 * Therefore ignore errors as long as something was read.
> +	 */
> +	do {
> +		bytes_read = 0;
> +		ret = nor->read(nor, from + pos, len - pos,
> +				&bytes_read, buf + pos);

As we discussed elsewhere, I don't think it's good to ignore all errors
here.

> +		pos += bytes_read;
> +	} while (pos < len && bytes_read);
>  
>  	spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
> +
> +	*retlen = pos;
>  	return ret;
>  }
>  

Brian

      parent reply	other threads:[~2015-11-20 23:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-06 18:51 [PATCH] mtd: spi-nor: handle controller driver limitations in spi_nor_read Heiner Kallweit
2015-10-20 17:38 ` Heiner Kallweit
2015-11-20 23:26 ` 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=20151120232610.GB64635@google.com \
    --to=computersforpeace@gmail.com \
    --cc=hkallweit1@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.