* [PATCH] staging: dgnc: Replace macro with flow control statement by a function
@ 2015-07-05 18:16 Arjun Krishna Babu
2015-07-06 7:32 ` Dan Carpenter
2015-07-06 12:15 ` Ravi Teja Darbha
0 siblings, 2 replies; 7+ messages in thread
From: Arjun Krishna Babu @ 2015-07-05 18:16 UTC (permalink / raw)
To: lidza.louina, markh
Cc: gregkh, driverdev-devel, devel, linux-kernel, Arjun Krishna Babu
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 <arjunkrishnababu96@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function
2015-07-05 18:16 [PATCH] staging: dgnc: Replace macro with flow control statement by a function Arjun Krishna Babu
@ 2015-07-06 7:32 ` Dan Carpenter
2015-07-06 12:15 ` Ravi Teja Darbha
1 sibling, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2015-07-06 7:32 UTC (permalink / raw)
To: Arjun Krishna Babu
Cc: lidza.louina, markh, devel, gregkh, driverdev-devel, linux-kernel
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function
2015-07-05 18:16 [PATCH] staging: dgnc: Replace macro with flow control statement by a function Arjun Krishna Babu
2015-07-06 7:32 ` Dan Carpenter
@ 2015-07-06 12:15 ` Ravi Teja Darbha
2015-07-06 12:27 ` Sudip Mukherjee
1 sibling, 1 reply; 7+ messages in thread
From: Ravi Teja Darbha @ 2015-07-06 12:15 UTC (permalink / raw)
To: Arjun Krishna Babu
Cc: lidza.louina, markh, devel, gregkh, driverdev-devel, linux-kernel
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 <arjunkrishnababu96@gmail.com>
> ---
> 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
> devel@linuxdriverproject.org
> http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function
2015-07-06 12:15 ` Ravi Teja Darbha
@ 2015-07-06 12:27 ` Sudip Mukherjee
2015-07-06 13:20 ` Ravi Teja Darbha
2015-07-06 14:10 ` Dan Carpenter
0 siblings, 2 replies; 7+ messages in thread
From: Sudip Mukherjee @ 2015-07-06 12:27 UTC (permalink / raw)
To: Ravi Teja Darbha
Cc: Arjun Krishna Babu, devel, lidza.louina, driverdev-devel,
linux-kernel, gregkh
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function
2015-07-06 12:27 ` Sudip Mukherjee
@ 2015-07-06 13:20 ` Ravi Teja Darbha
2015-07-06 13:28 ` Valdis.Kletnieks
2015-07-06 14:10 ` Dan Carpenter
1 sibling, 1 reply; 7+ messages in thread
From: Ravi Teja Darbha @ 2015-07-06 13:20 UTC (permalink / raw)
To: Sudip Mukherjee
Cc: Arjun Krishna Babu, devel, lidza.louina, driverdev-devel,
linux-kernel, gregkh
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function
2015-07-06 13:20 ` Ravi Teja Darbha
@ 2015-07-06 13:28 ` Valdis.Kletnieks
0 siblings, 0 replies; 7+ messages in thread
From: Valdis.Kletnieks @ 2015-07-06 13:28 UTC (permalink / raw)
To: Ravi Teja Darbha
Cc: Sudip Mukherjee, Arjun Krishna Babu, devel, lidza.louina,
driverdev-devel, linux-kernel, gregkh
[-- Attachment #1: Type: text/plain, Size: 351 bytes --]
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).
[-- Attachment #2: Type: application/pgp-signature, Size: 848 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: dgnc: Replace macro with flow control statement by a function
2015-07-06 12:27 ` Sudip Mukherjee
2015-07-06 13:20 ` Ravi Teja Darbha
@ 2015-07-06 14:10 ` Dan Carpenter
1 sibling, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2015-07-06 14:10 UTC (permalink / raw)
To: Sudip Mukherjee
Cc: Ravi Teja Darbha, devel, Arjun Krishna Babu, gregkh,
driverdev-devel, linux-kernel, lidza.louina
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-07-06 14:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-05 18:16 [PATCH] staging: dgnc: Replace macro with flow control statement by a function Arjun Krishna Babu
2015-07-06 7:32 ` Dan Carpenter
2015-07-06 12:15 ` Ravi Teja Darbha
2015-07-06 12:27 ` Sudip Mukherjee
2015-07-06 13:20 ` Ravi Teja Darbha
2015-07-06 13:28 ` Valdis.Kletnieks
2015-07-06 14:10 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).