staging: greybus: Enclose multi-statement macro in do-while loop
Subsystems (3)
PATCH 1/1 staging: greybus: Enclose multi-statement macro in do-while loop
The macro gb_loopback_stats_attrs in the Greybus loopback driver contains multiple statements, which should be enclosed in a do-while loop to ensure proper execution and adhere to coding standards.
This patch modifies the gb_loopback_stats_attrs macro to enclose its statements in a do-while loop, addressing the style error flagged by checkpatch.pl.
--- drivers/staging/greybus/loopback.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/staging/greybus/loopback.c +5 -3
@@ -163,9 +163,11 @@ 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) + 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.45.2
Greg KH
maintainerQuoted 22 lines · Juan José Arboleda
The macro
gb_loopback_stats_attrsin the Greybus loopback driver contains multiple statements, which should be enclosed in a do-while loop to ensure proper execution and adhere to coding standards.This patch modifies the
gb_loopback_stats_attrsmacro to enclose its statements in a do-while loop, addressing the style error flagged by checkpatch.pl.Signed-off-by Juan José Arboleda <[email protected]>--- drivers/staging/greybus/loopback.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/staging/greybus/loopback.c +0
-1@@ -163,9 +163,11 @@ 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); \
drivers/staging/greybus/loopback.c static ssize_t name##_avg_show(struct device *dev, \ · line 173
Quoted 10 lines
drivers/staging/greybus/loopback.c +5
-2-gb_loopback_ro_stats_attr (field, max, u); \ - gb_loopback_ro_avg_attr(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, \
Are you sure you test-built this change?
thanks,
greg k-h
Quoted 31 lines · Greg KH
Quoted 30 lines · Juan José Arboleda
The macro
gb_loopback_stats_attrsin the Greybus loopback driver contains multiple statements, which should be enclosed in a do-while loop to ensure proper execution and adhere to coding standards.This patch modifies the
gb_loopback_stats_attrsmacro to enclose its statements in a do-while loop, addressing the style error flagged by checkpatch.pl.Signed-off-by Juan José Arboleda <[email protected]>--- drivers/staging/greybus/loopback.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/staging/greybus/loopback.c +5
-3@@ -163,9 +163,11 @@ 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) + 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 )
Quoted 8 lines
drivers/staging/greybus/loopback.c static ssize_t name##_avg_show(struct device *dev, \ · line 173
Quoted 2 lines
drivers/staging/greybus/loopback.c +0
-0#define gb_loopback_attr (field, type) \ static ssize_t field##_show(struct device *dev, \Are you sure you test-built this change?
thanks,
greg k-h
Yes! I build and clean and build and clean and build again, everything seems fine from the compiler side and posttest task as well. Everything seems ok.
Thanks,
- Juan José
Greg KH
maintainerQuoted 37 lines · Juan José Arboleda
Quoted 36 lines · Greg KH
Quoted 22 lines · Juan José Arboleda
The macro
gb_loopback_stats_attrsin the Greybus loopback driver contains multiple statements, which should be enclosed in a do-while loop to ensure proper execution and adhere to coding standards.This patch modifies the
gb_loopback_stats_attrsmacro to enclose its statements in a do-while loop, addressing the style error flagged by checkpatch.pl.Signed-off-by Juan José Arboleda <[email protected]>--- drivers/staging/greybus/loopback.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/staging/greybus/loopback.c +0
-1@@ -163,9 +163,11 @@ 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); \drivers/staging/greybus/loopback.c static ssize_t name##_avg_show(struct device *dev, \ · line 173
Quoted 10 lines
drivers/staging/greybus/loopback.c +5
-2-gb_loopback_ro_stats_attr (field, max, u); \ - gb_loopback_ro_avg_attr(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, \Are you sure you test-built this change?
Quoted 6 lines
Quoted 3 lines
thanks,
greg k-h
Yes! I build and clean and build and clean and build again, everything seems fine from the compiler side and posttest task as well. Everything seems ok.
You did not actually build this file that you modified :(
Always test-build your changes.
thanks,
greg k-h
PATCH v2 1/1 staging: greybus: break multi statement macro into multiple lines
The macro gb_loopback_stats_attrs in the Greybus loopback driver contains multiple statements, which should be enclosed in a do-while loop to ensure proper execution and adhere to coding standards.
The latter is not possible as the macro expansion will create invalid C syntax. Theres is not such thing like inner function definition inside a global scope do-while in C.
This patch nukes the gb_loopback_stats_attrs macro to enclose, addressing the style error flagged by checkpatch.pl.
---
Notes:
This new version uses a bit different approach so the commit message will be a bit different as well.
P.S: Thanks for being that patience and apologies for that false positive of building the non-included driver. Now it is tested-built.
drivers/staging/greybus/loopback.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/staging/greybus/loopback.c +19 -10
@@ -162,11 +162,6 @@ 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_attr (field, type) \ static ssize_t field##_show(struct device *dev, \ struct device_attribute *attr, \
@@ -268,15 +263,29 @@ static void gb_loopback_check_attr(struct gb_loopback *gb) }/* Time to send and receive one message */ -gb_loopback_stats_attrs (latency); +gb_loopback_ro_stats_attr (latency, min, u); +gb_loopback_ro_stats_attr (latency, max, u); +gb_loopback_ro_avg_attr (latency); +/* Number of requests sent per second on this cport */ -gb_loopback_stats_attrs (requests_per_second); +gb_loopback_ro_stats_attr (requests_per_second, min, u); +gb_loopback_ro_stats_attr (requests_per_second, max, u); +gb_loopback_ro_avg_attr (requests_per_second); +/* Quantity of data sent and received on this cport */ -gb_loopback_stats_attrs (throughput); +gb_loopback_ro_stats_attr (throughput, min, u); +gb_loopback_ro_stats_attr (throughput, max, u); +gb_loopback_ro_avg_attr (throughput); +/* Latency across the UniPro link from APBridge's perspective */ -gb_loopback_stats_attrs (apbridge_unipro_latency); +gb_loopback_ro_stats_attr (apbridge_unipro_latency, min, u); +gb_loopback_ro_stats_attr (apbridge_unipro_latency, max, u); +gb_loopback_ro_avg_attr (apbridge_unipro_latency); +/* Firmware induced overhead in the GPBridge */ -gb_loopback_stats_attrs (gbphy_firmware_latency); +gb_loopback_ro_stats_attr (gbphy_firmware_latency, min, u); +gb_loopback_ro_stats_attr (gbphy_firmware_latency, max, u); +gb_loopback_ro_avg_attr (gbphy_firmware_latency);/* Number of errors encountered during loop */ gb_loopback_ro_attr (error);
Signature · 1 line
2.45.2
Greg KH
maintainerRe: [PATCH v2] staging: greybus: break multi statement macro into multiple lines
Quoted 10 lines · Juan José Arboleda
The macro
gb_loopback_stats_attrsin the Greybus loopback driver contains multiple statements, which should be enclosed in a do-while loop to ensure proper execution and adhere to coding standards.The latter is not possible as the macro expansion will create invalid C syntax. Theres is not such thing like inner function definition inside a global scope do-while in C.
This patch nukes the
gb_loopback_stats_attrsmacro to enclose, addressing the style error flagged by checkpatch.pl.
The style error here is just wrong, the original code is fine. Remember, checkpatch provides hints, it isn't always correct, and many times, like this one, it's completely incorrect.
Quoted 31 lines
Signed-off-by Juan José Arboleda <[email protected]>---
Notes:This new version uses a bit different approach so the commit message will be a bit different as well.
P.S: Thanks for being that patience and apologies for that false positive of building the non-included driver. Now it is tested-built.drivers/staging/greybus/loopback.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)drivers/staging/greybus/loopback.c +0
-5@@ -162,11 +162,6 @@ 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_attr (field, type) \ static ssize_t field##_show(struct device *dev, \ struct device_attribute *attr, \
drivers/staging/greybus/loopback.c static void gb_loopback_check_attr(struct gb_loopback *gb) · line 268
Quoted 7 lines
drivers/staging/greybus/loopback.c +3
-1@@ -268,15 +263,29 @@ static void gb_loopback_check_attr(struct gb_loopback *gb) }/* Time to send and receive one message */ -gb_loopback_stats_attrs (latency); +gb_loopback_ro_stats_attr (latency, min, u); +gb_loopback_ro_stats_attr (latency, max, u); +gb_loopback_ro_avg_attr (latency);
Unrolling the macro like this does fix the warning, but at the expense of more code size and manual work. We write code first for us to understand, and second for the compiler. The original code is just fine, no need for a change at all.
sorry,
greg k-h
Re: [PATCH v2] staging: greybus: break multi statement macro into multiple lines
In reply to Juan José ArboledaQuoted 8 lines · Juan José Arboleda
The macro
gb_loopback_stats_attrsin the Greybus loopback driver contains multiple statements, which should be enclosed in a do-while loop to ensure proper execution and adhere to coding standards.The latter is not possible as the macro expansion will create invalid C syntax. Theres is not such thing like inner function definition inside a global scope do-while in C.
Quoted 5 lines
This patch nukes the
gb_loopback_stats_attrsmacro to enclose, addressing the style error flagged by checkpatch.pl.Signed-off-by Juan José Arboleda <[email protected]>---
Sorry, it's not really important to follow checkpatch. Checkpatch is just a Perl script and sometimes it gets things wrong. It's a tool not a king.
regards,
dan carpenter