Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1689971 > unrolled thread

[PATCH 3/3] Staging: iio: adc: ad7280a.c: Fixed Macro argument reuse

Started byJaya Durga <rjdurga@gmail.com>
First post2017-07-18 12:00 +0200
Last post2017-07-18 12:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 3/3] Staging: iio: adc: ad7280a.c: Fixed Macro argument reuse Jaya Durga <rjdurga@gmail.com> - 2017-07-18 12:00 +0200
    Re: [PATCH 3/3] Staging: iio: adc: ad7280a.c: Fixed Macro argument  reuse Dan Carpenter <dan.carpenter@oracle.com> - 2017-07-18 12:10 +0200

#1689971 — [PATCH 3/3] Staging: iio: adc: ad7280a.c: Fixed Macro argument reuse

FromJaya Durga <rjdurga@gmail.com>
Date2017-07-18 12:00 +0200
Subject[PATCH 3/3] Staging: iio: adc: ad7280a.c: Fixed Macro argument reuse
Message-ID<u4xsm-Lp-15@gated-at.bofh.it>
CHECK: Macro argument reuse 'addr' - possible side-effects?

convert AD7280A_DEVADDR to inline function to fix checkpath check

Signed-off-by: Jaya Durga <rjdurga@gmail.com>
---
 drivers/staging/iio/adc/ad7280a.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index d5ab83f..cb94b7f 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -99,9 +99,12 @@
 #define AD7280A_DEVADDR_MASTER		0
 #define AD7280A_DEVADDR_ALL		0x1F
 /* 5-bit device address is sent LSB first */
-#define AD7280A_DEVADDR(addr)	(((addr & 0x1) << 4) | ((addr & 0x2) << 3) | \
-				(addr & 0x4) | ((addr & 0x8) >> 3) | \
-				((addr & 0x10) >> 4))
+static inline unsigned int AD7280A_DEVADDR(unsigned int addr)
+{
+	return ((((addr & 0x1) << 4) | ((addr & 0x2) << 3) |
+		  (addr & 0x4) | ((addr & 0x8) >> 3) |
+		  ((addr & 0x10) >> 4)));
+}
 
 /* During a read a valid write is mandatory.
  * So writing to the highest available address (Address 0x1F)
-- 
1.9.1

[toc] | [next] | [standalone]


#1690007 — Re: [PATCH 3/3] Staging: iio: adc: ad7280a.c: Fixed Macro argument reuse

FromDan Carpenter <dan.carpenter@oracle.com>
Date2017-07-18 12:10 +0200
SubjectRe: [PATCH 3/3] Staging: iio: adc: ad7280a.c: Fixed Macro argument reuse
Message-ID<u4xC3-146-53@gated-at.bofh.it>
In reply to#1689971
On Tue, Jul 18, 2017 at 03:17:52PM +0530, Jaya Durga wrote:
> diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
> index d5ab83f..cb94b7f 100644
> --- a/drivers/staging/iio/adc/ad7280a.c
> +++ b/drivers/staging/iio/adc/ad7280a.c
> @@ -99,9 +99,12 @@
>  #define AD7280A_DEVADDR_MASTER		0
>  #define AD7280A_DEVADDR_ALL		0x1F
>  /* 5-bit device address is sent LSB first */
> -#define AD7280A_DEVADDR(addr)	(((addr & 0x1) << 4) | ((addr & 0x2) << 3) | \
> -				(addr & 0x4) | ((addr & 0x8) >> 3) | \
> -				((addr & 0x10) >> 4))
> +static inline unsigned int AD7280A_DEVADDR(unsigned int addr)

Don't make this inline.  GCC is going to ignore the inline anyway, and
make up its own mind about what to do.  Change the name to not be all
caps.  Generally, all caps means it's a macro.

> +{
> +	return ((((addr & 0x1) << 4) | ((addr & 0x2) << 3) |
> +		  (addr & 0x4) | ((addr & 0x8) >> 3) |
> +		  ((addr & 0x10) >> 4)));

We don't need all the parens.

	return ((addr & 0x1) << 4) |
	       ((addr & 0x2) << 3) |
		(addr & 0x4)       |
	       ((addr & 0x8) >> 3) |
	       ((addr & 0x10) >> 4);

regards,
dan carpenter

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web