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
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
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
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
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.
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).
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