Skip to contentSkip to conversation

staging: dgnc: Replace macro with flow control statement by a function

PATCH In review Arjun Krishna Babu 5 participants 7 messages Jul 5, 2015 – Jul 6, 2015 Staging

lore
Share & tools
lore
#0 lore raw

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
index 44db870..8ab0922 100644
@@ -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
#1 lore raw
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

#2 lore raw
In reply to Arjun Krishna Babu

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.

---
 drivers/staging/dgnc/dgnc_sysfs.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/staging/dgnc/dgnc_sysfs.c +10 -12
index 44db870..8ab0922 100644
@@ -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
#3 lore raw
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

#4 lore raw

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.

#5 lore raw
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).