staging: dgnc: Replace macro with flow control statement by a function
PATCH 1/1 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.
--- drivers/staging/dgnc/dgnc_sysfs.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/staging/dgnc/dgnc_sysfs.c +10 -12
@@ -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)
Signature · 1 line
1.9.1
Quoted 7 lines · 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.
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
Quoted 53 lines · 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 <[email protected]>--- drivers/staging/dgnc/dgnc_sysfs.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)drivers/staging/dgnc/dgnc_sysfs.c +10
-12@@ -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)Signature · 6 lines
1.9.1 _______________________________________________ devel mailing list [email protected] http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Quoted 1 line · Ravi Teja Darbha
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
Quoted 1 line · Sudip Mukherjee
That is why the macro is there, to avoid the duplication of code.
Quoted 1 line · Ravi Teja Darbha
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