* [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API
@ 2018-08-20 12:43 Chuanhua Han
2018-08-20 13:01 ` David Laight
0 siblings, 1 reply; 7+ messages in thread
From: Chuanhua Han @ 2018-08-20 12:43 UTC (permalink / raw)
To: broonie, boris.brezillon
Cc: linux-spi, linux-kernel, stable, jiafei.pan, zhiqiang.hou, Chuanhua Han
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")
---
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;
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;
+
+ op->data.nbytes = min3((unsigned long)(op->data.nbytes),
+ spi_max_transfer_size(mem->spi),
+ spi_max_message_size(mem->spi) -
+ opcode_addr_dummy_sum);
+ }
+
return 0;
}
EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size);
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* RE: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API
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
0 siblings, 1 reply; 7+ messages in thread
From: David Laight @ 2018-08-20 13:01 UTC (permalink / raw)
To: 'Chuanhua Han', broonie, boris.brezillon
Cc: linux-spi, linux-kernel, stable, jiafei.pan, zhiqiang.hou
From: Chuanhua Han
> Sent: 20 August 2018 13:44
>
> 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")
> ---
> 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;
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.
> +
> + op->data.nbytes = min3((unsigned long)(op->data.nbytes),
> + spi_max_transfer_size(mem->spi),
> + spi_max_message_size(mem->spi) -
> + opcode_addr_dummy_sum);
That looks like a strange limit...
> + }
> +
> 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)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API
2018-08-20 13:01 ` David Laight
@ 2018-08-20 13:54 ` Boris Brezillon
0 siblings, 0 replies; 7+ messages in thread
From: Boris Brezillon @ 2018-08-20 13:54 UTC (permalink / raw)
To: David Laight
Cc: 'Chuanhua Han',
broonie, linux-spi, linux-kernel, stable, jiafei.pan,
zhiqiang.hou
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)
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API
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
2 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2018-08-20 17:13 UTC (permalink / raw)
To: Chuanhua Han
Cc: broonie, boris.brezillon, linux-spi, linux-kernel, stable,
jiafei.pan, zhiqiang.hou
On Mon, Aug 20, 2018 at 05:43:26PM +0800, Chuanhua Han wrote:
> Signed-off-by: Chuanhua Han <chuanhua.han@nxp.com>
> ---
> Changes in v2:
> - Place the adjusted transfer bytes code in spi_mem_adjust_op_size()
> and check spi_max_message_size(mem->spi) value before subtracting
> opcode, addr and dummy bytes.
> *fixes:
> spi: Extend the core to ease integration of SPI memory controllers
> ---
> drivers/spi/spi-mem.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API
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
2 siblings, 0 replies; 7+ messages in thread
From: kbuild test robot @ 2018-08-20 10:23 UTC (permalink / raw)
To: Chuanhua Han
Cc: kbuild-all, broonie, boris.brezillon, linux-spi, linux-kernel,
stable, jiafei.pan, zhiqiang.hou, Chuanhua Han
[-- Attachment #1: Type: text/plain, Size: 21440 bytes --]
Hi Chuanhua,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on spi/for-next]
[also build test WARNING on v4.18 next-20180817]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Chuanhua-Han/mtd-m25p80-consider-max-message-size-when-use-the-spi_mem_xx-API/20180820-174451
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
config: i386-randconfig-x076-201833 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All warnings (new ones prefixed by >>):
In file included from include/linux/list.h:9:0,
from include/linux/kobject.h:19,
from include/linux/device.h:16,
from include/linux/dmaengine.h:20,
from drivers/spi/spi-mem.c:8:
drivers/spi/spi-mem.c: In function 'spi_mem_adjust_op_size':
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
>> drivers/spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:820:48: note: in definition of macro '__is_constexpr'
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
^
include/linux/kernel.h:826:25: note: in expansion of macro '__no_side_effects'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
>> drivers/spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:828:27: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
>> drivers/spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:828:40: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
>> drivers/spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:831:10: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
>> drivers/spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:831:25: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
>> drivers/spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
--
In file included from include/linux/list.h:9:0,
from include/linux/kobject.h:19,
from include/linux/device.h:16,
from include/linux/dmaengine.h:20,
from drivers//spi/spi-mem.c:8:
drivers//spi/spi-mem.c: In function 'spi_mem_adjust_op_size':
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
drivers//spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:820:48: note: in definition of macro '__is_constexpr'
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
^
include/linux/kernel.h:826:25: note: in expansion of macro '__no_side_effects'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
drivers//spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:828:27: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
drivers//spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:828:40: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
drivers//spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:831:10: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
drivers//spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
include/linux/kernel.h:812:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:831:25: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:860:23: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
include/linux/kernel.h:826:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:836:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:845:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
include/linux/kernel.h:860:38: note: in expansion of macro 'min'
#define min3(x, y, z) min((typeof(x))min(x, y), z)
^~~
drivers//spi/spi-mem.c:360:21: note: in expansion of macro 'min3'
op->data.nbytes = min3((unsigned long)op->data.nbytes,
^~~~
vim +/min3 +360 drivers/spi/spi-mem.c
330
331 /**
332 * spi_mem_adjust_op_size() - Adjust the data size of a SPI mem operation to
333 * match controller limitations
334 * @mem: the SPI memory
335 * @op: the operation to adjust
336 *
337 * Some controllers have FIFO limitations and must split a data transfer
338 * operation into multiple ones, others require a specific alignment for
339 * optimized accesses. This function allows SPI mem drivers to split a single
340 * operation into multiple sub-operations when required.
341 *
342 * Return: a negative error code if the controller can't properly adjust @op,
343 * 0 otherwise. Note that @op->data.nbytes will be updated if @op
344 * can't be handled in a single step.
345 */
346 int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
347 {
348 struct spi_controller *ctlr = mem->spi->controller;
349 unsigned long val = sizeof(op->cmd.opcode) +
350 op->addr.nbytes +
351 op->dummy.nbytes;
352
353 if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size)
354 return ctlr->mem_ops->adjust_op_size(mem, op);
355
356 if (spi_max_message_size(mem->spi) < val)
357 return -EINVAL;
358
359 if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op)
> 360 op->data.nbytes = min3((unsigned long)op->data.nbytes,
361 spi_max_transfer_size(mem->spi),
362 spi_max_message_size(mem->spi) - val);
363
364 return 0;
365 }
366 EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size);
367
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 26025 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API
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
2 siblings, 0 replies; 7+ messages in thread
From: Boris Brezillon @ 2018-08-20 10:15 UTC (permalink / raw)
To: Chuanhua Han
Cc: broonie, linux-spi, linux-kernel, stable, jiafei.pan, zhiqiang.hou
Hi Chuanhua,
On Mon, 20 Aug 2018 17:43:26 +0800
Chuanhua Han <chuanhua.han@nxp.com> wrote:
Subject prefix should be "spi: spi-mem: " not "mtd: m25p80: ", and you
need a commit message explaining what this patch does and why it's
needed.
> Signed-off-by: Chuanhua Han <chuanhua.han@nxp.com>
Fixes: c36ff266dc82 ("spi: Extend the core to ease integration of SPI memory controllers")
Cc: <stable@vger.kernel.org>
> ---
> Changes in v2:
> - Place the adjusted transfer bytes code in spi_mem_adjust_op_size()
> and check spi_max_message_size(mem->spi) value before subtracting
> opcode, addr and dummy bytes.
> *fixes:
> spi: Extend the core to ease integration of SPI memory controllers
> ---
> drivers/spi/spi-mem.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index 990770d..f5e75d1 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -328,10 +328,21 @@ 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 val = sizeof(op->cmd.opcode) +
> + op->addr.nbytes +
> + op->dummy.nbytes;
Not properly aligned, and you should find a better name for this variable.
>
> if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size)
> return ctlr->mem_ops->adjust_op_size(mem, op);
>
> + if (spi_max_message_size(mem->spi) < val)
> + return -EINVAL;
This should be enclosed in the if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op)
block and you should check that spi_max_transfer_size(mem->spi) >= val too.
> +
> + if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op)
> + op->data.nbytes = min3((unsigned long)op->data.nbytes,
> + spi_max_transfer_size(mem->spi),
> + spi_max_message_size(mem->spi) - val);
> +
> return 0;
> }
> EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size);
Regards,
Boris
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API
@ 2018-08-20 9:43 Chuanhua Han
2018-08-20 10:15 ` Boris Brezillon
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Chuanhua Han @ 2018-08-20 9:43 UTC (permalink / raw)
To: broonie, boris.brezillon
Cc: linux-spi, linux-kernel, stable, jiafei.pan, zhiqiang.hou, Chuanhua Han
Signed-off-by: Chuanhua Han <chuanhua.han@nxp.com>
---
Changes in v2:
- Place the adjusted transfer bytes code in spi_mem_adjust_op_size()
and check spi_max_message_size(mem->spi) value before subtracting
opcode, addr and dummy bytes.
*fixes:
spi: Extend the core to ease integration of SPI memory controllers
---
drivers/spi/spi-mem.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 990770d..f5e75d1 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -328,10 +328,21 @@ 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 val = 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 (spi_max_message_size(mem->spi) < val)
+ return -EINVAL;
+
+ if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op)
+ op->data.nbytes = min3((unsigned long)op->data.nbytes,
+ spi_max_transfer_size(mem->spi),
+ spi_max_message_size(mem->spi) - val);
+
return 0;
}
EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size);
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-08-20 17:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
-- 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
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.