[PATCH] staging: dgnc: Warn on macro with flow control statements
Salah Triki
salah.triki at acm.org
Fri Feb 27 02:40:11 UTC 2015
This fixes the following checkpatch.pl warnings:
WARNING: Macros with flow control statements should be avoided.
Signed-off-by: Salah Triki <salah.triki at acm.org>
---
drivers/staging/dgnc/dgnc_sysfs.c | 64 ++++++++++++++++++++++++---------------
1 file changed, 39 insertions(+), 25 deletions(-)
diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c
index 2fd34ca..8e9eca4 100644
--- a/drivers/staging/dgnc/dgnc_sysfs.c
+++ b/drivers/staging/dgnc/dgnc_sysfs.c
@@ -106,18 +106,19 @@ 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 -1;
+ bd = dev_get_drvdata(p);
+ if (!bd || bd->magic != DGNC_BOARD_MAGIC)
+ return -1;
+
+ if (bd->state != BOARD_READY)
+ return -1;
+ return 0;
+}
static ssize_t dgnc_vpd_show(struct device *p, struct device_attribute *attr, char *buf)
@@ -126,8 +127,9 @@ static ssize_t dgnc_vpd_show(struct device *p, struct device_attribute *attr, ch
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
-
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
+
count += sprintf(buf + count, "\n 0 1 2 3 4 5 6 7 8 9 A B C D E F");
for (i = 0; i < 0x40 * 2; i++) {
if (!(i % 16))
@@ -145,7 +147,8 @@ static ssize_t dgnc_serial_number_show(struct device *p, struct device_attribute
struct dgnc_board *bd;
int count = 0;
- DGNC_VERIFY_BOARD(p, bd);
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
if (bd->serial_num[0] == '\0')
count += sprintf(buf + count, "<UNKNOWN>\n");
@@ -163,7 +166,8 @@ static ssize_t dgnc_ports_state_show(struct device *p, struct device_attribute *
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
count += snprintf(buf + count, PAGE_SIZE - count,
@@ -180,8 +184,9 @@ static ssize_t dgnc_ports_baud_show(struct device *p, struct device_attribute *a
struct dgnc_board *bd;
int count = 0;
int i = 0;
-
- DGNC_VERIFY_BOARD(p, bd);
+
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
count += snprintf(buf + count, PAGE_SIZE - count,
@@ -198,7 +203,8 @@ static ssize_t dgnc_ports_msignals_show(struct device *p, struct device_attribut
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
if (bd->channels[i]->ch_open_count) {
@@ -226,7 +232,8 @@ static ssize_t dgnc_ports_iflag_show(struct device *p, struct device_attribute *
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -243,7 +250,8 @@ static ssize_t dgnc_ports_cflag_show(struct device *p, struct device_attribute *
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -260,7 +268,8 @@ static ssize_t dgnc_ports_oflag_show(struct device *p, struct device_attribute *
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -277,7 +286,9 @@ static ssize_t dgnc_ports_lflag_show(struct device *p, struct device_attribute *
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
+
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -294,7 +305,8 @@ static ssize_t dgnc_ports_digi_flag_show(struct device *p, struct device_attribu
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -311,7 +323,8 @@ static ssize_t dgnc_ports_rxcount_show(struct device *p, struct device_attribute
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
@@ -328,7 +341,8 @@ static ssize_t dgnc_ports_txcount_show(struct device *p, struct device_attribute
int count = 0;
int i = 0;
- DGNC_VERIFY_BOARD(p, bd);
+ if (dgnc_verify_board(p, bd) == -1)
+ return 0;
for (i = 0; i < bd->nasync; i++) {
count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
--
1.9.1
More information about the devel
mailing list