All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: dgnc: replace DGNC_VERIFY_BOARD macro with dgnc_verify_board function.
@ 2016-10-10  4:38 Elise Lennion
  2016-10-10  6:39 ` [Outreachy kernel] " Julia Lawall
  2016-10-10  8:19 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Elise Lennion @ 2016-10-10  4:38 UTC (permalink / raw)
  To: lidza.louina, markh, gregkh, outreachy-kernel

Fix checkpatch warning:

WARNING: Macros with flow control statements should be avoided

Macros with flow control statements should be avoided; they break the flow of the calling function and make it harder to test the code.

Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
---
 drivers/staging/dgnc/dgnc_sysfs.c | 74 +++++++++++++++++++++++++++------------
 1 file changed, 51 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c
index 290bf6e..687d67a 100644
--- a/drivers/staging/dgnc/dgnc_sysfs.c
+++ b/drivers/staging/dgnc/dgnc_sysfs.c
@@ -90,17 +90,21 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
 	driver_remove_file(driverfs, &driver_attr_pollrate);
 }
 
-#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 struct dgnc_board *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;
+
+	return bd;
+}
 
 static ssize_t vpd_show(struct device *p, struct device_attribute *attr,
 			char *buf)
@@ -109,7 +113,9 @@ static ssize_t vpd_show(struct device *p, struct device_attribute *attr,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	count += sprintf(buf + count,
 		"\n      0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F");
@@ -130,7 +136,9 @@ static ssize_t serial_number_show(struct device *p,
 	struct dgnc_board *bd;
 	int count = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	if (bd->serial_num[0] == '\0')
 		count += sprintf(buf + count, "<UNKNOWN>\n");
@@ -148,7 +156,9 @@ static ssize_t ports_state_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		count += snprintf(buf + count, PAGE_SIZE - count,
@@ -166,7 +176,9 @@ static ssize_t ports_baud_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		count +=  snprintf(buf + count, PAGE_SIZE - count,
@@ -184,7 +196,9 @@ static ssize_t ports_msignals_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		struct channel_t *ch = bd->channels[i];
@@ -215,7 +229,9 @@ static ssize_t ports_iflag_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -233,7 +249,9 @@ static ssize_t ports_cflag_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -251,7 +269,9 @@ static ssize_t ports_oflag_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -269,7 +289,9 @@ static ssize_t ports_lflag_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -287,7 +309,9 @@ static ssize_t ports_digi_flag_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
@@ -305,7 +329,9 @@ static ssize_t ports_rxcount_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
@@ -323,7 +349,9 @@ static ssize_t ports_txcount_show(struct device *p,
 	int count = 0;
 	int i = 0;
 
-	DGNC_VERIFY_BOARD(p, bd);
+	bd = dgnc_verify_board(p);
+	if (!bd)
+		return 0;
 
 	for (i = 0; i < bd->nasync; i++) {
 		count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Outreachy kernel] [PATCH] staging: dgnc: replace DGNC_VERIFY_BOARD macro with dgnc_verify_board function.
  2016-10-10  4:38 [PATCH] staging: dgnc: replace DGNC_VERIFY_BOARD macro with dgnc_verify_board function Elise Lennion
@ 2016-10-10  6:39 ` Julia Lawall
  2016-10-10  8:19 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2016-10-10  6:39 UTC (permalink / raw)
  To: Elise Lennion; +Cc: lidza.louina, markh, gregkh, outreachy-kernel



On Mon, 10 Oct 2016, Elise Lennion wrote:

> Fix checkpatch warning:
>
> WARNING: Macros with flow control statements should be avoided
>
> Macros with flow control statements should be avoided; they break the flow of the calling function and make it harder to test the code.
>
> Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
> ---
>  drivers/staging/dgnc/dgnc_sysfs.c | 74 +++++++++++++++++++++++++++------------
>  1 file changed, 51 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c
> index 290bf6e..687d67a 100644
> --- a/drivers/staging/dgnc/dgnc_sysfs.c
> +++ b/drivers/staging/dgnc/dgnc_sysfs.c
> @@ -90,17 +90,21 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
>  	driver_remove_file(driverfs, &driver_attr_pollrate);
>  }
>
> -#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 struct dgnc_board *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;
> +
> +	return bd;
> +}

This looks like a really nice effort!

However, since the return type is a pointer, it would be better to return
NULL.  The return 0 looks quite odd, because usually 0 is a success value
(while NULL is a failure value).

julia

>
>  static ssize_t vpd_show(struct device *p, struct device_attribute *attr,
>  			char *buf)
> @@ -109,7 +113,9 @@ static ssize_t vpd_show(struct device *p, struct device_attribute *attr,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	count += sprintf(buf + count,
>  		"\n      0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F");
> @@ -130,7 +136,9 @@ static ssize_t serial_number_show(struct device *p,
>  	struct dgnc_board *bd;
>  	int count = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	if (bd->serial_num[0] == '\0')
>  		count += sprintf(buf + count, "<UNKNOWN>\n");
> @@ -148,7 +156,9 @@ static ssize_t ports_state_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		count += snprintf(buf + count, PAGE_SIZE - count,
> @@ -166,7 +176,9 @@ static ssize_t ports_baud_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		count +=  snprintf(buf + count, PAGE_SIZE - count,
> @@ -184,7 +196,9 @@ static ssize_t ports_msignals_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		struct channel_t *ch = bd->channels[i];
> @@ -215,7 +229,9 @@ static ssize_t ports_iflag_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
> @@ -233,7 +249,9 @@ static ssize_t ports_cflag_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
> @@ -251,7 +269,9 @@ static ssize_t ports_oflag_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
> @@ -269,7 +289,9 @@ static ssize_t ports_lflag_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
> @@ -287,7 +309,9 @@ static ssize_t ports_digi_flag_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
> @@ -305,7 +329,9 @@ static ssize_t ports_rxcount_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
> @@ -323,7 +349,9 @@ static ssize_t ports_txcount_show(struct device *p,
>  	int count = 0;
>  	int i = 0;
>
> -	DGNC_VERIFY_BOARD(p, bd);
> +	bd = dgnc_verify_board(p);
> +	if (!bd)
> +		return 0;
>
>  	for (i = 0; i < bd->nasync; i++) {
>  		count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
> --
> 2.7.4
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20161010043825.GA5438%40lennorien.com.
> For more options, visit https://groups.google.com/d/optout.
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: dgnc: replace DGNC_VERIFY_BOARD macro with dgnc_verify_board function.
  2016-10-10  4:38 [PATCH] staging: dgnc: replace DGNC_VERIFY_BOARD macro with dgnc_verify_board function Elise Lennion
  2016-10-10  6:39 ` [Outreachy kernel] " Julia Lawall
@ 2016-10-10  8:19 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2016-10-10  8:19 UTC (permalink / raw)
  To: Elise Lennion; +Cc: lidza.louina, markh, outreachy-kernel

On Mon, Oct 10, 2016 at 01:38:25AM -0300, Elise Lennion wrote:
> Fix checkpatch warning:
> 
> WARNING: Macros with flow control statements should be avoided
> 
> Macros with flow control statements should be avoided; they break the flow of the calling function and make it harder to test the code.

Please always wrap your changelog comments at 72 columns.

thanks,

greg k-h


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-10-10  8:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-10  4:38 [PATCH] staging: dgnc: replace DGNC_VERIFY_BOARD macro with dgnc_verify_board function Elise Lennion
2016-10-10  6:39 ` [Outreachy kernel] " Julia Lawall
2016-10-10  8:19 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.