Skip to contentSkip to conversation

Staging:iio:adc:Prefer using BIT macro

PATCH In review Bhumika Goyal 3 participants 6 messages Feb 8, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Staging:iio:adc:Prefer using BIT macro

This patchset replaces bit shifting on 1 with the BIT(x) macro. This was done with coccinelle:
@@ int g; @@
-(1 << g)
+BIT(g)

Bhumika Goyal (2):
Staging:iio:Prefer using BIT macro
Staging: iio: adc: Prefer using the BIT macro

 drivers/staging/iio/adc/ad7280a.c | 4 ++--
 drivers/staging/iio/adc/ad7816.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 Staging:iio:Prefer using BIT macro

This patch replaces bit shifting on 1 with the BIT(x) macro. This was done with coccinelle:
@@ int g; @@
-(1 << g)
+BIT(g)

---
 drivers/staging/iio/adc/ad7816.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/adc/ad7816.c +1 -1
index 2226051..f631012 100644
@@ -222,7 +222,7 @@ static ssize_t ad7816_show_value(struct device *dev,
 		value = (s8)((data >> AD7816_TEMP_FLOAT_OFFSET) - 103);
 		data &= AD7816_TEMP_FLOAT_MASK;
 		if (value < 0)
-			data = (1 << AD7816_TEMP_FLOAT_OFFSET) - data;
+			data = BIT(AD7816_TEMP_FLOAT_OFFSET) - data;
 		return sprintf(buf, "%d.%.2d\n", value, data * 25);
 	}
 	return sprintf(buf, "%u\n", data);
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 1/2] Staging:iio:Prefer using BIT macro

Quoted 7 lines · Bhumika Goyal

This patch replaces bit shifting on 1 with the BIT(x) macro. This was done with coccinelle:
@@ int g; @@

(quoted diff) +1 -1
-(1 << g)
+BIT(g)

Hi,

Thanks for the patch.

Quoted 9 lines
---
 drivers/staging/iio/adc/ad7816.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/adc/ad7816.c +0 -0
index 2226051..f631012 100644

drivers/staging/iio/adc/ad7816.c static ssize_t ad7816_show_value(struct device *dev, · line 225

Quoted 5 lines
drivers/staging/iio/adc/ad7816.c +1 -1
@@ -222,7 +222,7 @@ static ssize_t ad7816_show_value(struct device *dev,
 		value = (s8)((data >> AD7816_TEMP_FLOAT_OFFSET) - 103);
 		data &= AD7816_TEMP_FLOAT_MASK;
 		if (value < 0)
-			data = (1 << AD7816_TEMP_FLOAT_OFFSET) - data;
+			data = BIT(AD7816_TEMP_FLOAT_OFFSET) - data;

But in this case this is a false positive. The intended semantic meaning here is 2**... not BIT(...). Using BIT() here in my opinion only causes confusion.

Quoted 4 lines
drivers/staging/iio/adc/ad7816.c +0 -0
 		return sprintf(buf, "%d.%.2d\n", value, data * 25);
 	}
 	return sprintf(buf, "%u\n", data);
#3 lore raw

Re: [PATCH 1/2] Staging:iio:Prefer using BIT macro

Quoted 9 lines · Lars-Peter Clausen

drivers/staging/iio/adc/ad7816.c static ssize_t ad7816_show_value(struct device *dev, · line 225

Quoted 5 lines · Bhumika Goyal
              value = (s8)((data >> AD7816_TEMP_FLOAT_OFFSET) - 103);
              data &= AD7816_TEMP_FLOAT_MASK;
              if (value < 0)
drivers/staging/iio/adc/ad7816.c +1 -1
-                     data = (1 << AD7816_TEMP_FLOAT_OFFSET) - data;
+                     data = BIT(AD7816_TEMP_FLOAT_OFFSET) - data;
Quoted 3 lines

But in this case this is a false positive. The intended semantic meaning here is 2**... not BIT(...). Using BIT() here in my opinion only causes confusion.

+1. Here clearly the intention is to change sign of the value which fits less than 32/16/8 bits. 1 << OFFSET represents '-0'.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

PATCH 2/2 Staging: iio: adc: Prefer using the BIT macro

In reply to Bhumika Goyal

This patch replaces bit shifting on 1 with the BIT(x) macro.

This was done with coccinelle:

@@ int g; @@

-(1 << g)
+BIT(g)

---
 drivers/staging/iio/adc/ad7280a.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/adc/ad7280a.c +2 -2
index 0c73bce..ccf3157 100644
@@ -117,7 +117,7 @@
  */
 #define POLYNOM		0x2F
 #define POLYNOM_ORDER	8
-#define HIGHBIT		(1 << (POLYNOM_ORDER - 1))
+#define HIGHBIT		BIT((POLYNOM_ORDER - 1))
 
 struct ad7280_state {
 	struct spi_device		*spi;
@@ -388,7 +388,7 @@ static ssize_t ad7280_show_balance_sw(struct device *dev,
 
 	return sprintf(buf, "%d\n",
 		       !!(st->cb_mask[this_attr->address >> 8] &
-		       (1 << ((this_attr->address & 0xFF) + 2))));
+		       BIT(((this_attr->address & 0xFF) + 2))));
 }
 
 static ssize_t ad7280_store_balance_sw(struct device *dev,
Signature · 1 line
1.9.1
#5 lore raw

Re: [PATCH 2/2] Staging: iio: adc: Prefer using the BIT macro

Quoted 10 lines · Bhumika Goyal

This patch replaces bit shifting on 1 with the BIT(x) macro.

This was done with coccinelle:

@@ int g; @@

(quoted diff) +1 -1
-(1 << g)
+BIT(g)

Hi,

Thanks for the patch. This looks good.

Quoted 9 lines
---
 drivers/staging/iio/adc/ad7280a.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/adc/ad7280a.c +0 -0
index 0c73bce..ccf3157 100644

drivers/staging/iio/adc/ad7280a.c line 120

Quoted 5 lines
drivers/staging/iio/adc/ad7280a.c +1 -1
@@ -117,7 +117,7 @@
  */
 #define POLYNOM		0x2F
 #define POLYNOM_ORDER	8
-#define HIGHBIT		(1 << (POLYNOM_ORDER - 1))
+#define HIGHBIT		BIT((POLYNOM_ORDER - 1))

But please drop the extra brackets and resend the patch.

drivers/staging/iio/adc/ad7280a.c static ssize_t ad7280_show_balance_sw(struct device *dev, · line 391

Quoted 9 lines
drivers/staging/iio/adc/ad7280a.c +1 -1
 struct ad7280_state {
 	struct spi_device		*spi;
@@ -388,7 +388,7 @@ static ssize_t ad7280_show_balance_sw(struct device *dev,
 
 	return sprintf(buf, "%d\n",
 		       !!(st->cb_mask[this_attr->address >> 8] &
-		       (1 << ((this_attr->address & 0xFF) + 2))));
+		       BIT(((this_attr->address & 0xFF) + 2))));

Same here.