Skip to contentSkip to conversation

staging: greybus: loopback: Fix Coding Style Error

PATCH In review Husni Faiz 3 participants 5 messages Feb 17, 2022 – Mar 2, 2022

Subsystems (3)
lore
Share & tools
lore

Husni Faiz

author
#0 lore raw

PATCH 1/1 staging: greybus: loopback: Fix Coding Style Error

Macros with multiple statements should be enclosed in a do - while block.

---
 drivers/staging/greybus/loopback.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/staging/greybus/loopback.c +6 -4
index 2471448ba42a..33666a49e0a8 100644
@@ -162,10 +162,12 @@ static ssize_t name##_avg_show(struct device *dev,		\
 }									\
 static DEVICE_ATTR_RO(name##_avg)
 
-#define gb_loopback_stats_attrs(field)				\
-	gb_loopback_ro_stats_attr(field, min, u);		\
-	gb_loopback_ro_stats_attr(field, max, u);		\
-	gb_loopback_ro_avg_attr(field)
+#define gb_loopback_stats_attrs(field)					\
+	do {												\
+		gb_loopback_ro_stats_attr(field, min, u);		\
+		gb_loopback_ro_stats_attr(field, max, u);		\
+		gb_loopback_ro_avg_attr(field)					\
+	} while (0)
 
 #define gb_loopback_attr(field, type)					\
 static ssize_t field##_show(struct device *dev,				\
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 33 lines · Husni Faiz

Macros with multiple statements should be enclosed in a do - while block.

---
 drivers/staging/greybus/loopback.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/staging/greybus/loopback.c +6 -4
index 2471448ba42a..33666a49e0a8 100644
@@ -162,10 +162,12 @@ static ssize_t name##_avg_show(struct device *dev,		\
 }									\
 static DEVICE_ATTR_RO(name##_avg)
 
-#define gb_loopback_stats_attrs(field)				\
-	gb_loopback_ro_stats_attr(field, min, u);		\
-	gb_loopback_ro_stats_attr(field, max, u);		\
-	gb_loopback_ro_avg_attr(field)
+#define gb_loopback_stats_attrs(field)					\
+	do {												\
+		gb_loopback_ro_stats_attr(field, min, u);		\
+		gb_loopback_ro_stats_attr(field, max, u);		\
+		gb_loopback_ro_avg_attr(field)					\
+	} while (0)
 
 #define gb_loopback_attr(field, type)					\
 static ssize_t field##_show(struct device *dev,				\
Signature · 1 line
2.25.1

Did you try to build this change?

#2 lore raw

Hi Greg,

Quoted 1 line · Greg KH

Did you try to build this change?

I am a newbie kernel dev and trying to understand how things work. I did not build this change by the time I sent you this, thinking this is just a style change.
I should have tested the build. I am sorry.

Now I built the changes by setting the following configurations. CONFIG_GREYBUS
CONFIG_STAGING
CONFIG_GREYBUS_LOOPBACK

My change introduces the following error.
''''
drivers/staging/greybus/loopback.c:166:2: error: expected identifier or ‘(’ before ‘do’

  166 |  do {            \
      |  ^~

''''
I could not fix or find the reason for this error. Please guide me in this regard.

Thanks,
Husni.

maintainer
#3 lore raw
Quoted 9 lines · Ahamed Husni

Hi Greg,

Quoted 1 line · Greg KH

Did you try to build this change?

I am a newbie kernel dev and trying to understand how things work. I did not build this change by the time I sent you this, thinking this is just a style change.
I should have tested the build. I am sorry.

You always have to build-test your changes, as you have found out.

Quoted 9 lines

Now I built the changes by setting the following configurations. CONFIG_GREYBUS
CONFIG_STAGING
CONFIG_GREYBUS_LOOPBACK

My change introduces the following error.
''''
drivers/staging/greybus/loopback.c:166:2: error: expected identifier or ‘(’ before ‘do’

Quoted 5 lines
  166 |  do {            \
      |  ^~

''''
I could not fix or find the reason for this error. Please guide me in this regard.

There is nothing wrong with the original code here. Remember that checkpatch is a perl script that gives good advice, but it is not always correct. You must always manually check it based on your knowledge of the C language.

I recommend learning a bit more C before working on kernel code.

Best of luck!

greg k-h

#4 lore raw
In reply to Ahamed Husni
Quoted 19 lines · Ahamed Husni

Hi Greg,

Quoted 1 line · Greg KH

Did you try to build this change?

I am a newbie kernel dev and trying to understand how things work. I did not build this change by the time I sent you this, thinking this is just a style change.
I should have tested the build. I am sorry.

Now I built the changes by setting the following configurations. CONFIG_GREYBUS
CONFIG_STAGING
CONFIG_GREYBUS_LOOPBACK

My change introduces the following error.
''''
drivers/staging/greybus/loopback.c:166:2: error: expected identifier or ‘(’ before ‘do’

Quoted 5 lines
   166 |  do {            \
       |  ^~

''''
I could not fix or find the reason for this error. Please guide me in this regard.

You should understand that you cannot contribute to the Linux kernel if you don't understand details of the C language well. And you really must test your changes (certainly a build test) before you send them for review.

To answer your question, the macro you changed does not expand into code that is itself incorporated in an executable block. The macro is used to generate entire functions in a unified way.

-Alex

Quoted 6 lines

Thanks,
Husni.
_______________________________________________
greybus-dev mailing list -- [email protected] To unsubscribe send an email to [email protected]