Staging: greybus: Cleanup in header file control.h
PATCH 1/1 Staging: greybus: Cleanup in header file control.h
Fix a blank line after function/struct/union/enum declarations. Also, convert to_gb_control() macro into an inline function in order to maintain Linux kernel coding style based on which the inline function is preferable over the macro.
--- drivers/staging/greybus/control.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/staging/greybus/control.h +5 -1
@@ -24,7 +24,11 @@ struct gb_control {char *vendor_string;char *product_string; }; -#define to_gb_control (d) container_of(d, struct gb_control, dev) + +static inline struct gb_control *to_gb_control (struct device *d) +{ + return container_of(d, struct gb_control, dev); +}struct gb_control *gb_control_create (struct gb_interface *intf);int gb_control_enable (struct gb_control *control);
Signature · 1 line
2.17.1
Johan Hovold
maintainerQuoted 4 lines · Madhumitha Prabakaran
Fix a blank line after function/struct/union/enum declarations. Also, convert
to_gb_control()macro into an inline function in order to maintain Linux kernel coding style based on which the inline function is preferable over the macro.
There are about 1200 macros wrapping container_of() in the kernel, so this is a common pattern which does not need to be changed (by contrast, only a handful container_of are wrapped by functions).
Quoted 10 lines
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/greybus/control.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/staging/greybus/control.h +0
-0
drivers/staging/greybus/control.h struct gb_control { · line 27
Quoted 5 lines
drivers/staging/greybus/control.h +1
-1@@ -24,7 +24,11 @@ struct gb_control {char *vendor_string;char *product_string; }; -#define to_gb_control (d) container_of(d, struct gb_control, dev) +
No need for a blank line either as the macro is closely related to the preceding struct declaration.
drivers/staging/greybus/control.h struct gb_control { · line 31
Quoted 4 lines
drivers/staging/greybus/control.h +4
-0+static inline struct gb_control *to_gb_control (struct device *d) +{ + return container_of(d, struct gb_control, dev); +}
Johan
Quoted 10 lines · Johan Hovold
Quoted 4 lines · Madhumitha Prabakaran
Fix a blank line after function/struct/union/enum declarations. Also, convert
to_gb_control()macro into an inline function in order to maintain Linux kernel coding style based on which the inline function is preferable over the macro.There are about 1200 macros wrapping
container_of()in the kernel, so this is a common pattern which does not need to be changed (by contrast, only a handfulcontainer_ofare wrapped by functions).
A handful?
$ git grep "return container_of" | wc -l 1856
I'm like Donald Trump because I must have really small hands compared to the rest of y'all.
I would prefer to apply these sorts of patches unless it causes an issue... Functions *are* better than macros. It's a minor improvement, but this is staging and we make tons minor style changes. It's part of the blessing and curse of being in staging...
regards,
dan carpenter
Johan Hovold
maintainerQuoted 12 lines · Dan Carpenter
Quoted 10 lines · Johan Hovold
Quoted 4 lines · Madhumitha Prabakaran
Fix a blank line after function/struct/union/enum declarations. Also, convert
to_gb_control()macro into an inline function in order to maintain Linux kernel coding style based on which the inline function is preferable over the macro.There are about 1200 macros wrapping
container_of()in the kernel, so this is a common pattern which does not need to be changed (by contrast, only a handfulcontainer_ofare wrapped by functions).
Quoted 7 lines
A handful?
$ git grep "return container_of" | wc -l 1856I'm like Donald Trump because I must have really small hands compared to the rest of y'all.
Heh, you're right, my grep-fu failed me.
Ok, so both styles are roughly as common (and a non-trivial portion of those 1800 also are not simple wrappers).
Quoted 4 lines
I would prefer to apply these sorts of patches unless it causes an issue... Functions *are* better than macros. It's a minor improvement, but this is staging and we make tons minor style changes. It's part of the blessing and curse of being in staging...
While I agree functions are generally preferred, container_of() is special as it includes type checking.
And again, using container_of() like this is a common pattern in the kernel.
Johan
What I'm saying is that if we just apply it then we avoid the long discussion forever. The macro is OK, sure, but it's not like anyone is going to come back later and argue that macros are better or preferred.
regards,
dan carpenter
Johan Hovold
maintainerQuoted 3 lines · Dan Carpenter
What I'm saying is that if we just apply it then we avoid the long discussion forever. The macro is OK, sure, but it's not like anyone is going to come back later and argue that macros are better or preferred.
That may be a valid argument, at least with respect to staging currently (even if checkpatch isn't entirely too blame for this particular "cleanup").
But then all eight or so instances should be replaced in one go, to maintain consistency.
Johan
Quoted 2 lines · Johan Hovold
But then all eight or so instances should be replaced in one go, to maintain consistency.
Yeah, that's fair enough, I suppose.
regards,
dan carepenter