Skip to contentSkip to conversation

spi: cf_qspi: fix clamp macro type check compilation warnings

PATCH New Angelo Dureghello 2 participants 4 messages Jun 4, 2015 – Jun 21, 2015 SPI

lore
Share & tools
lore
#0 lore raw

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

Fix clamp macro redefined warning, and clamp type check warnings.

---
 drivers/spi/cf_qspi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +1 -2
index 834c5bd..c4bafe0 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 {
@@ -119,7 +118,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	if (max_hz == 0) /* Go as fast as possible */
 		dev->qmr = 2u;
 	else /* Get the closest baud rate */
-		dev->qmr = clamp(((gd->bus_clk >> 2) + max_hz - 1)/max_hz,
+		dev->qmr = clamp_val(((gd->bus_clk >> 2) + max_hz - 1)/max_hz,
 					2u, 255u);
 
 	/* Map mode to QMR[CPOL] and QMR[CPHA] */
Signature · 1 line
2.1.4
#1 lore raw

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

Quoted 20 lines · Angelo Dureghello

Fix clamp macro redefined warning, and clamp type check warnings.

---
 drivers/spi/cf_qspi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +0 -1
index 834c5bd..c4bafe0 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 121

Quoted 5 lines
drivers/spi/cf_qspi.c +1 -1
@@ -119,7 +118,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
        if (max_hz == 0) /* Go as fast as possible */
                dev->qmr = 2u;
        else /* Get the closest baud rate */
-               dev->qmr = clamp(((gd->bus_clk >> 2) + max_hz - 1)/max_hz,
+               dev->qmr = clamp_val(((gd->bus_clk >> 2) + max_hz - 1)/max_hz,

Yes, there is a common macro in include/linux - can you check this clamp or clamp_val and
test it accordingly.

Quoted 6 lines
drivers/spi/cf_qspi.c +0 -1
                                        2u, 255u);
 
        /* Map mode to QMR[CPOL] and QMR[CPHA] */
--

2.1.4

thanks!

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

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

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

Fix clamp macro redefined warning, and clamp type check warnings.

---
  drivers/spi/cf_qspi.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +0 -1
index 834c5bd..c4bafe0 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

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

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

Yes, there is a common macro in include/linux - can you check this clamp or clamp_val and
test it accordingly.

Hi Jagan,

i realized the warnings was correctly generated from the "unnecessary" pointer comparison used from the clamp/min/max macros.

More correct solution here is to set 2u, 255u to 2lu, 255lu, and types are compliant to the comparison, so warnings are not thrown anymore.

The clamp macro defined in this file seems anyway still not needed (redefine warning) since it is exactly the same in the commonly used include/linux/kernel.h clamp macro.

So i post a v2 version of the patch with these 2 changes. Ok ?

Best regards
Angelo Dureghello

#3 lore raw

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

Quoted 47 lines · Angelo Dureghello
Quoted 22 lines · Jagan Teki
Quoted 20 lines · Angelo Dureghello

Fix clamp macro redefined warning, and clamp type check warnings.

---
  drivers/spi/cf_qspi.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/cf_qspi.c +0 -1
index 834c5bd..c4bafe0 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 16 lines

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

Quoted 10 lines
  struct cf_qspi_slave {
drivers/spi/cf_qspi.c +1 -1
@@ -119,7 +118,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus,
 unsigned int cs,
         if (max_hz == 0) /* Go as fast as possible */
                 dev->qmr = 2u;
         else /* Get the closest baud rate */
-               dev->qmr = clamp(((gd->bus_clk >> 2) + max_hz -
 1)/max_hz,
+               dev->qmr = clamp_val(((gd->bus_clk >> 2) + max_hz -
 1)/max_hz,

Yes, there is a common macro in include/linux - can you check this clamp or clamp_val and
test it accordingly.

Hi Jagan,

i realized the warnings was correctly generated from the "unnecessary" pointer comparison used from the clamp/min/max macros.

Quoted 8 lines

More correct solution here is to set 2u, 255u to 2lu, 255lu, and types are compliant to the comparison, so warnings are not thrown anymore.

The clamp macro defined in this file seems anyway still not needed (redefine warning) since it is exactly the same in the commonly used include/linux/kernel.h clamp macro.

So i post a v2 version of the patch with these 2 changes. Ok ?

Yes, please.

thanks!

Signature · 1 line
Jagan | openedev.