Skip to contentSkip to conversation

spi: cf_qspi: fix clamp macro type check compilation warnings

PATCH Superseded Angelo Dureghello 2 participants 6 messages Jun 21, 2015 – Jul 1, 2015 SPI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 spi: cf_qspi: fix clamp macro type check compilation warnings

Fix compilation warnings for redefined 'clamp' macro and non-uniform clamp macro types.

---
 drivers/spi/cf_qspi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +1 -2
index 834c5bd..e57e63e 100644
@@ -19,7 +19,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define clamp(x, low, high) (min(max(low, x), high))
 #define to_cf_qspi_slave(s) container_of(s, struct cf_qspi_slave, slave)
 
 struct cf_qspi_slave {
@@ -120,7 +119,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 		dev->qmr = 2u;
 	else /* Get the closest baud rate */
 		dev->qmr = clamp(((gd->bus_clk >> 2) + max_hz - 1)/max_hz,
-					2u, 255u);
+					2lu, 255lu);
 
 	/* Map mode to QMR[CPOL] and QMR[CPHA] */
 	if (mode & SPI_CPOL)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/1 spi: cf_qspi: fix clamp macro type check compilation warnings

Quoted 21 lines · Angelo Dureghello

Fix compilation warnings for redefined 'clamp' macro and non-uniform clamp macro types.

---
 drivers/spi/cf_qspi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +0 -1
index 834c5bd..e57e63e 100644
@@ -19,7 +19,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define clamp(x, low, high) (min(max(low, x), high))
 #define to_cf_qspi_slave(s) container_of(s, struct cf_qspi_slave, slave)
 
 struct cf_qspi_slave {

drivers/spi/cf_qspi.c struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, · line 122

Quoted 5 lines
drivers/spi/cf_qspi.c +1 -1
@@ -120,7 +119,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                dev->qmr = 2u;
        else /* Get the closest baud rate */
                dev->qmr = clamp(((gd->bus_clk >> 2) + max_hz - 1)/max_hz,
-                                       2u, 255u);
+                                       2lu, 255lu);

Any Tested-by ?

Quoted 6 lines
drivers/spi/cf_qspi.c +0 -1
        /* Map mode to QMR[CPOL] and QMR[CPHA] */
        if (mode & SPI_CPOL)
--

2.1.4

thanks!

Signature · 1 line
Jagan | openedev.
#2 lore raw

PATCH v2 1/1 spi: cf_qspi: fix clamp macro type check compilation warnings

Quoted 20 lines · Jagan Teki
Quoted 19 lines · Angelo Dureghello

Fix compilation warnings for redefined 'clamp' macro and non-uniform clamp macro types.

---
  drivers/spi/cf_qspi.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +0 -1
index 834c5bd..e57e63e 100644
@@ -19,7 +19,6 @@
 
  DECLARE_GLOBAL_DATA_PTR;
 
-#define clamp(x, low, high) (min(max(low, x), high))
  #define to_cf_qspi_slave(s) container_of(s, struct cf_qspi_slave, slave)
 
Quoted 10 lines

drivers/spi/cf_qspi.c struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, · line 122

Quoted 7 lines
drivers/spi/cf_qspi.c +1 -1
  struct cf_qspi_slave {
@@ -120,7 +119,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                 dev->qmr = 2u;
         else /* Get the closest baud rate */
                 dev->qmr = clamp(((gd->bus_clk >> 2) + max_hz - 1)/max_hz,
-                                       2u, 255u);
+                                       2lu, 255lu);

Any Tested-by ?

Hi Jagan,

i am supposing there are no issues here, since 2 and 255 are inside the 8-bit range, and they was unsigned int instead of unsigned long so the change gives no effect to the clamp.

I am still waiting the hardware here for proper mcf / qspi-testing. Will test it then.

Best regards,
Angelo Durgehello

#3 lore raw

PATCH v2 1/1 spi: cf_qspi: fix clamp macro type check compilation warnings

Quoted 26 lines · Angelo Dureghello
Quoted 23 lines · Jagan Teki
Quoted 21 lines · Angelo Dureghello

Fix compilation warnings for redefined 'clamp' macro and non-uniform clamp macro types.

---
  drivers/spi/cf_qspi.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +0 -1
index 834c5bd..e57e63e 100644
@@ -19,7 +19,6 @@
 
  DECLARE_GLOBAL_DATA_PTR;
 
-#define clamp(x, low, high) (min(max(low, x), high))
  #define to_cf_qspi_slave(s) container_of(s, struct cf_qspi_slave,
 slave)
 
Quoted 9 lines
Quoted 9 lines

drivers/spi/cf_qspi.c struct spi_slave *spi_setup_slave(unsigned int bus, · line 124

Quoted 9 lines
  struct cf_qspi_slave {
drivers/spi/cf_qspi.c +1 -1
@@ -120,7 +119,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus,
 unsigned int cs,
                 dev->qmr = 2u;
         else /* Get the closest baud rate */
                 dev->qmr = clamp(((gd->bus_clk >> 2) + max_hz -
 1)/max_hz,
-                                       2u, 255u);
+                                       2lu, 255lu);

replacing u with lu - any reason?

Quoted 5 lines
Quoted 4 lines

Any Tested-by ?

Quoted 8 lines

Hi Jagan,

i am supposing there are no issues here, since 2 and 255 are inside the 8-bit range, and they was unsigned int instead of unsigned long so the change gives no effect to the clamp.

I am still waiting the hardware here for proper mcf / qspi-testing. Will test it then.

thanks!

Signature · 1 line
Jagan | openedev.
#4 lore raw

PATCH v2 1/1 spi: cf_qspi: fix clamp macro type check compilation warnings

Hi Jagan,

Quoted 27 lines · Jagan Teki
Quoted 26 lines · Angelo Dureghello
Quoted 23 lines · Jagan Teki
Quoted 21 lines · Angelo Dureghello

Fix compilation warnings for redefined 'clamp' macro and non-uniform clamp macro types.

---
   drivers/spi/cf_qspi.c | 3 +--
   1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +0 -1
index 834c5bd..e57e63e 100644
@@ -19,7 +19,6 @@
 
   DECLARE_GLOBAL_DATA_PTR;
 
-#define clamp(x, low, high) (min(max(low, x), high))
   #define to_cf_qspi_slave(s) container_of(s, struct cf_qspi_slave,
 slave)
 
Quoted 11 lines
Quoted 9 lines
Quoted 9 lines

drivers/spi/cf_qspi.c struct spi_slave *spi_setup_slave(unsigned int bus, · line 124

Quoted 9 lines
   struct cf_qspi_slave {
drivers/spi/cf_qspi.c +1 -1
@@ -120,7 +119,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus,
 unsigned int cs,
                  dev->qmr = 2u;
          else /* Get the closest baud rate */
                  dev->qmr = clamp(((gd->bus_clk >> 2) + max_hz -
 1)/max_hz,
-                                       2u, 255u);
+                                       2lu, 255lu);

replacing u with lu - any reason?

Compiling this file you will get compilation warnings. The reason is that the "unnecessary type check" throws the warnings since clamp (and so included min max) uses different types.

u is unsigned int
lu uniforms types to gd->bus_clk, that is unsigned long.

Best regards
Angelo Dureghello

Quoted 17 lines
Quoted 6 lines
Quoted 5 lines

Any Tested-by ?

Quoted 8 lines

Hi Jagan,

i am supposing there are no issues here, since 2 and 255 are inside the 8-bit range, and they was unsigned int instead of unsigned long so the change gives no effect to the clamp.

I am still waiting the hardware here for proper mcf / qspi-testing. Will test it then.

thanks!

#5 lore raw

PATCH v2 1/1 spi: cf_qspi: fix clamp macro type check compilation warnings

Quoted 49 lines · Angelo Dureghello

Hi Jagan,

Quoted 31 lines · Jagan Teki
Quoted 29 lines · Angelo Dureghello
Quoted 25 lines · Jagan Teki
Quoted 22 lines · Angelo Dureghello

Fix compilation warnings for redefined 'clamp' macro and non-uniform clamp macro types.

---
   drivers/spi/cf_qspi.c | 3 +--
   1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +0 -1
index 834c5bd..e57e63e 100644
@@ -19,7 +19,6 @@
 
   DECLARE_GLOBAL_DATA_PTR;
 
-#define clamp(x, low, high) (min(max(low, x), high))
   #define to_cf_qspi_slave(s) container_of(s, struct cf_qspi_slave,
 slave)
 
Quoted 12 lines
Quoted 9 lines
Quoted 9 lines

drivers/spi/cf_qspi.c struct spi_slave *spi_setup_slave(unsigned int bus, · line 124

Quoted 9 lines
   struct cf_qspi_slave {
drivers/spi/cf_qspi.c +1 -1
@@ -120,7 +119,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus,
 unsigned int cs,
                  dev->qmr = 2u;
          else /* Get the closest baud rate */
                  dev->qmr = clamp(((gd->bus_clk >> 2) + max_hz -
 1)/max_hz,
-                                       2u, 255u);
+                                       2lu, 255lu);

replacing u with lu - any reason?

Quoted 6 lines

Compiling this file you will get compilation warnings.
The reason is that the "unnecessary type check" throws the warnings since clamp (and so included min max) uses different types.

u is unsigned int
lu uniforms types to gd->bus_clk, that is unsigned long.

Applied to u-boot-spi/master

thanks!

Signature · 1 line
Jagan | openedev.