2015-07-05 18:17:12

by Arjun Krishna Babu

[permalink] [raw]
Subject: [PATCH] staging: dgnc: Replace macro with flow control statement by a function

This patch fixes the checkpatch.pl warning:

WARNING: Macros with flow control statements should be avoided

Replace the macro with a function doing the exact same task as the
macro.

Signed-off-by: Arjun Krishna Babu <[email protected]>
---
drivers/staging/dgnc/dgnc_sysfs.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c
index 44db870..8ab0922 100644
--- a/drivers/staging/dgnc/dgnc_sysfs.c
+++ b/drivers/staging/dgnc/dgnc_sysfs.c
@@ -92,19 +92,17 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
}


-#define DGNC_VERIFY_BOARD(p, bd) \
- do { \
- if (!p) \
- return 0; \
- \
- bd = dev_get_drvdata(p); \
- if (!bd || bd->magic != DGNC_BOARD_MAGIC) \
- return 0; \
- if (bd->state != BOARD_READY) \
- return 0; \
- } while (0)
-
+static int DGNC_VERIFY_BOARD(struct device *p, struct dgnc_board *bd)
+{
+ if (!p)
+ return 0;

+ bd = dev_get_drvdata(p);
+ if (!bd || bd->magic != DGNC_BOARD_MAGIC)
+ return 0;
+ if (bd->state != BOARD_READY)
+ return 0;
+}

static ssize_t dgnc_vpd_show(struct device *p, struct device_attribute *attr,
char *buf)
--
1.9.1


2015-07-06 07:33:45

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function

On Sun, Jul 05, 2015 at 11:46:28PM +0530, Arjun Krishna Babu wrote:
> This patch fixes the checkpatch.pl warning:
>
> WARNING: Macros with flow control statements should be avoided
>
> Replace the macro with a function doing the exact same task as the
> macro.
>

No. You haven't understood what DGNC_VERIFY_BOARD() does and have you
even tried to compile this? Surely the compiler will complain that some
paths don't have a return value?

regards,
dan carpenter

2015-07-06 12:15:33

by Ravi Teja Darbha

[permalink] [raw]
Subject: Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function

What you need to do is to replace all DGNC_VERIFY_BOARD() macro calls with its definition.

Regards,
Ravi Teja

On Sun, Jul 05, 2015 at 11:46:28PM +0530, Arjun Krishna Babu wrote:
> This patch fixes the checkpatch.pl warning:
>
> WARNING: Macros with flow control statements should be avoided
>
> Replace the macro with a function doing the exact same task as the
> macro.
>
> Signed-off-by: Arjun Krishna Babu <[email protected]>
> ---
> drivers/staging/dgnc/dgnc_sysfs.c | 22 ++++++++++------------
> 1 file changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c
> index 44db870..8ab0922 100644
> --- a/drivers/staging/dgnc/dgnc_sysfs.c
> +++ b/drivers/staging/dgnc/dgnc_sysfs.c
> @@ -92,19 +92,17 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
> }
>
>
> -#define DGNC_VERIFY_BOARD(p, bd) \
> - do { \
> - if (!p) \
> - return 0; \
> - \
> - bd = dev_get_drvdata(p); \
> - if (!bd || bd->magic != DGNC_BOARD_MAGIC) \
> - return 0; \
> - if (bd->state != BOARD_READY) \
> - return 0; \
> - } while (0)
> -
> +static int DGNC_VERIFY_BOARD(struct device *p, struct dgnc_board *bd)
> +{
> + if (!p)
> + return 0;
>
> + bd = dev_get_drvdata(p);
> + if (!bd || bd->magic != DGNC_BOARD_MAGIC)
> + return 0;
> + if (bd->state != BOARD_READY)
> + return 0;
> +}
>
> static ssize_t dgnc_vpd_show(struct device *p, struct device_attribute *attr,
> char *buf)
> --
> 1.9.1
>
> _______________________________________________
> devel mailing list
> [email protected]
> http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

2015-07-06 12:32:45

by Sudip Mukherjee

[permalink] [raw]
Subject: Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function

On Mon, Jul 06, 2015 at 05:45:24PM +0530, Ravi Teja Darbha wrote:
> What you need to do is to replace all DGNC_VERIFY_BOARD() macro calls with its definition.
And repeating the same code 12 times??
That is why the macro is there, to avoid the duplication of code.

regards
sudip

2015-07-06 13:20:30

by Ravi Teja Darbha

[permalink] [raw]
Subject: Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function

Why would you use a macro to avoid code duplication?

Regards,
Ravi Teja

On Mon, Jul 06, 2015 at 05:57:06PM +0530, Sudip Mukherjee wrote:
> That is why the macro is there, to avoid the duplication of code.

2015-07-06 13:29:07

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function

On Mon, 06 Jul 2015 18:50:12 +0530, Ravi Teja Darbha said:
> Why would you use a macro to avoid code duplication?

The macro does end up putting code in each place it's used.
However, the actual code is in one place rather than open-coded
in multiple places that can diverge over time (somebody patching 2 of
3 instances, and missing 1, for example).


Attachments:
(No filename) (848.00 B)

2015-07-06 14:10:45

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function

Since this is turning into a long thread, the correct thing is to copy
3eb141511bd5 ('staging: dgap: get rid of nasty DGAP_VERIFY_BOARD macro').

regards,
dan carpenter