Skip to contentSkip to conversation

spi: cadence-quadspi: Fix a compilation warning for 64-bit platform

PATCH In review Zhen Lei 3 participants 5 messages Jan 12, 2021 SPI

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

cover spi: cadence-quadspi: Fix a compilation warning for 64-bit platform

This patch is based on the latest linux-next. So the Fixes commit-id maybe changed when it merged int v5.12-rc1. For details about the problem analysis, see the patch description. The auxiliary information is listed here.

1) the type of size_t on 32-bit and 64-bit platforms include/uapi/asm-generic/posix_types.h:
typedef unsigned long __kernel_ulong_t;

#if __BITS_PER_LONG != 64
typedef unsigned int __kernel_size_t;
#else
typedef __kernel_ulong_t __kernel_size_t;
#endif

include/linux/types.h:
typedef __kernel_size_t size_t;

2) The compilation warning information on arm64:
In file included from ./include/linux/kernel.h:14,

                 from ./include/linux/clk.h:13,
                 from drivers/spi/spi-cadence-quadspi.c:9:

drivers/spi/spi-cadence-quadspi.c: In function ‘cqspi_direct_read_execute’:
./include/linux/minmax.h:18:28: warning: comparison of distinct pointer types lacks a cast
18 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
| ^~
./include/linux/minmax.h:32:4: note: in expansion of macro ‘__typecheck’
32 | (__typecheck(x, y) && __no_side_effects(x, y))

      |    ^~~~~~~~~~~
./include/linux/minmax.h:42:24: note: in expansion of macro ‘__safe_cmp’
   42 |  __builtin_choose_expr(__safe_cmp(x, y), \
      |                        ^~~~~~~~~~
./include/linux/minmax.h:58:19: note: in expansion of macro ‘__careful_cmp’
   58 | #define max(x, y) __careful_cmp(x, y, >)
      |                   ^~~~~~~~~~~~~

drivers/spi/spi-cadence-quadspi.c:1153:24: note: in expansion of macro ‘max’
1153 | msecs_to_jiffies(max(len, 500U)))) {
| ^~~

Zhen Lei (1):
spi: cadence-quadspi: Fix a compilation warning for 64-bit platform

 drivers/spi/spi-cadence-quadspi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
1.8.3
author
#1 lore raw

PATCH 1/1 spi: cadence-quadspi: Fix a compilation warning for 64-bit platform

The __typecheck() requires that the two arguments of max() must be of the same type. For the current max(), the type of the first parameter "len" is size_t. But the type of size_t is not fixed, it's "unsigned int" on 32-bit platforms and "unsigned long" on 64-bit platforms. So both the suffix "U" and "UL" are not appropriate for the second constant parameter. Therefore, forcible type conversion is used.

Fixes 8728a81b8f10 ("spi: Fix distinct pointer types warning for ARCH=mips")
Fixes 0920a32cf6f2 ("spi: cadence-quadspi: Wait at least 500 ms for direct reads")
---
 drivers/spi/spi-cadence-quadspi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-cadence-quadspi.c +1 -1
index 576610ba11184c6..eb40b8d46b56b0c 100644
@@ -1150,7 +1150,7 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata,
 
 	dma_async_issue_pending(cqspi->rx_chan);
 	if (!wait_for_completion_timeout(&cqspi->rx_dma_complete,
-					 msecs_to_jiffies(max(len, 500U)))) {
+				 msecs_to_jiffies(max_t(size_t, len, 500)))) {
 		dmaengine_terminate_sync(cqspi->rx_chan);
 		dev_err(dev, "DMA wait_for_completion_timeout\n");
 		ret = -ETIMEDOUT;

--
1.8.3

#2 lore raw

Hi Zhen,

Quoted 19 lines · Zhen Lei

The __typecheck() requires that the two arguments of max() must be of the same type. For the current max(), the type of the first parameter "len" is size_t. But the type of size_t is not fixed, it's "unsigned int" on 32-bit platforms and "unsigned long" on 64-bit platforms. So both the suffix "U" and "UL" are not appropriate for the second constant parameter. Therefore, forcible type conversion is used.

Fixes 8728a81b8f10 ("spi: Fix distinct pointer types warning for ARCH=mips")
Fixes 0920a32cf6f2 ("spi: cadence-quadspi: Wait at least 500 ms for direct reads")
---
 drivers/spi/spi-cadence-quadspi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-cadence-quadspi.c +0 -0
index 576610ba11184c6..eb40b8d46b56b0c 100644

drivers/spi/spi-cadence-quadspi.c static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata, · line 1153

Quoted 5 lines
drivers/spi/spi-cadence-quadspi.c +1 -1
@@ -1150,7 +1150,7 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata,
 
 	dma_async_issue_pending(cqspi->rx_chan);
 	if (!wait_for_completion_timeout(&cqspi->rx_dma_complete,
-					 msecs_to_jiffies(max(len, 500U)))) {
+				 msecs_to_jiffies(max_t(size_t, len, 500)))) {

I sent a patch with this exact fix already [0]. It has made it in Mark's for-next branch.

[0] https://lore.kernel.org/linux-spi/[email protected]/

Quoted 7 lines
drivers/spi/spi-cadence-quadspi.c +0 -1
 		dmaengine_terminate_sync(cqspi->rx_chan);
 		dev_err(dev, "DMA wait_for_completion_timeout\n");
 		ret = -ETIMEDOUT;
--

1.8.3

Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments India
#3 lore raw
Quoted 23 lines · Pratyush Yadav

Hi Zhen,

Quoted 20 lines · Zhen Lei

The __typecheck() requires that the two arguments of max() must be of the same type. For the current max(), the type of the first parameter "len" is size_t. But the type of size_t is not fixed, it's "unsigned int" on 32-bit platforms and "unsigned long" on 64-bit platforms. So both the suffix "U" and "UL" are not appropriate for the second constant parameter. Therefore, forcible type conversion is used.

Fixes 8728a81b8f10 ("spi: Fix distinct pointer types warning for ARCH=mips")
Fixes 0920a32cf6f2 ("spi: cadence-quadspi: Wait at least 500 ms for direct reads")
---
 drivers/spi/spi-cadence-quadspi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-cadence-quadspi.c +0 -0
index 576610ba11184c6..eb40b8d46b56b0c 100644
@@ -1150,7 +1150,7 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata,
 
Quoted 7 lines

drivers/spi/spi-cadence-quadspi.c static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata, · line 1153

Quoted 4 lines
drivers/spi/spi-cadence-quadspi.c +1 -1
 	dma_async_issue_pending(cqspi->rx_chan);
 	if (!wait_for_completion_timeout(&cqspi->rx_dma_complete,
-					 msecs_to_jiffies(max(len, 500U)))) {
+				 msecs_to_jiffies(max_t(size_t, len, 500)))) {

I sent a patch with this exact fix already [0]. It has made it in Mark's for-next branch.

OK,I don't known it.

Quoted 11 lines

[0] https://lore.kernel.org/linux-spi/[email protected]/

Quoted 7 lines
drivers/spi/spi-cadence-quadspi.c +0 -1
 		dmaengine_terminate_sync(cqspi->rx_chan);
 		dev_err(dev, "DMA wait_for_completion_timeout\n");
 		ret = -ETIMEDOUT;
--

1.8.3

maintainer
#4 lore raw
In reply to Zhen Lei
Quoted 3 lines · Zhen Lei

This patch is based on the latest linux-next. So the Fixes commit-id maybe changed when it merged int v5.12-rc1. For details about the problem analysis, see the patch description. The auxiliary information is listed here.

Please don't send cover letters for single patches, if there is anything that needs saying put it in the changelog of the patch or after the --- if it's administrative stuff. This reduces mail volume and ensures that any important information is recorded in the changelog rather than being lost.