All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: 'Chuanhua Han' <chuanhua.han@nxp.com>,
	"broonie@kernel.org" <broonie@kernel.org>,
	"linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	"jiafei.pan@nxp.com" <jiafei.pan@nxp.com>,
	"zhiqiang.hou@nxp.com" <zhiqiang.hou@nxp.com>
Subject: Re: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API
Date: Mon, 20 Aug 2018 15:54:51 +0200	[thread overview]
Message-ID: <20180820155451.03d770eb@bbrezillon> (raw)
In-Reply-To: <109aeb2622924f20b29743746bb77ce2@AcuMS.aculab.com>

On Mon, 20 Aug 2018 13:01:13 +0000
David Laight <David.Laight@ACULAB.COM> wrote:

> From: Chuanhua Han
> > Sent: 20 August 2018 13:44
> > 

Still no message here, and the subject prefix is still wrong.


Fixes and Cc-stable tags should be placed here...

> > Signed-off-by: Chuanhua Han <chuanhua.han@nxp.com>
> > ---
> > Changes in v3:
> >     Rename variable name "val" to "opcode_addr_dummy_sum".
> >     Place the legitimacy of the transfer size(i.e., "pi_max_message_size(mem->spi)" and
> > "opcode_addr_dummy_sum") into "if (! ctlr - > mem_ops | |! ctlr-> mem_ops->exec_op) {"
> > structure and add "spi_max_transfer_size(mem->spi) and opcode_addr_dummy_sum".
> >     Adjust the formatting alignment of your code.
> >     "(unsigned long)op->data.nbytes" was modified to "(unsigned long)(op->data.nbytes)".
> > 
> > Fixes: c36ff266dc82 ("spi: Extend the core to ease integration of SPI memory controllers")

... not here.

The changelog should also contain a "Changes in v2" section.

> > ---
> >  drivers/spi/spi-mem.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> > index 990770d..5ec2bc9 100644
> > --- a/drivers/spi/spi-mem.c
> > +++ b/drivers/spi/spi-mem.c
> > @@ -328,10 +328,24 @@ EXPORT_SYMBOL_GPL(spi_mem_exec_op);
> >  int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
> >  {
> >  	struct spi_controller *ctlr = mem->spi->controller;
> > +	unsigned long opcode_addr_dummy_sum = sizeof(op->cmd.opcode) +
> > +					      op->addr.nbytes +
> > +					      op->dummy.nbytes;  
> 

Yep, the var name is definitely too long.

> I'd split that (and shorten the variable name) to avoid line wrap. Maybe:
> 
> 	unsigned long len;
> 
> 	len = sizeof(op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes;
> > 
> >  	if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size)
> >  		return ctlr->mem_ops->adjust_op_size(mem, op);
> > 
> > +	if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) {
> > +		if (spi_max_message_size(mem->spi) < opcode_addr_dummy_sum ||
> > +		    spi_max_transfer_size(mem->spi) < opcode_addr_dummy_sum)
> > +			return -EINVAL;  
> 
> Those comparisons are lexically backwards, you want 'value op constant'.
> So:
> 		if (len > spi_max_message_size(mem->spi) ||
> 		    len > spi_max_transfer_size(mem->spi))
> 			return -EINVAL.
> Although I'm surprised you need to do both comparisons.

Indeed, spi_max_transfer_size() is enough since it already does a min()
with spi_max_message_size().

> 
> > +
> > +		op->data.nbytes = min3((unsigned long)(op->data.nbytes),

Hm, you should have a cast of size_t, I guess that's what kbuild robots
reported.

> > +				       spi_max_transfer_size(mem->spi),
> > +				       spi_max_message_size(mem->spi) -
> > +				       opcode_addr_dummy_sum);  
> 
> That looks like a strange limit...

We need that to adjust the len of the 2nd transfer (called data in
spi-mem) if it's too long to fit in a SPI message or SPI transfer.

> 
> > +	}
> > +
> >  	return 0;
> >  }
> >  EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size);
> > --
> > 2.7.4  
> 
> 	David
> 
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> 

  reply	other threads:[~2018-08-20 13:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-20 12:43 [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API Chuanhua Han
2018-08-20 13:01 ` David Laight
2018-08-20 13:54   ` Boris Brezillon [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-08-20  9:43 Chuanhua Han
2018-08-20 10:15 ` Boris Brezillon
2018-08-20 10:23 ` kbuild test robot
2018-08-20 17:13 ` Greg KH

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=20180820155451.03d770eb@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=broonie@kernel.org \
    --cc=chuanhua.han@nxp.com \
    --cc=jiafei.pan@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zhiqiang.hou@nxp.com \
    /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.