clk, ti, LLVMLinux: Move __init outside of type definition
Subsystems (2)
PATCH 1/1 clk, ti, LLVMLinux: Move __init outside of type definition
As written, the __init for ti_clk_get_div_table is in the middle of the return type.
The gcc documentation indicates that section attributes should be added to the end of the function declaration:
extern void foobar (void) __attribute__ ((section ("bar")));
However gcc seems to be very permissive with where attributes can be placed. clang on the other hand isn't so permissive, and fails if you put the section definition in the middle of the return type:
drivers/clk/ti/divider.c:298:28: error: expected ';' after struct static struct clk_div_table
^
;drivers/clk/ti/divider.c:298:1: warning: 'static' ignored on this
declaration [-Wmissing-declarations]
static struct clk_div_table
^drivers/clk/ti/divider.c:299:9: error: type specifier missing,
defaults to 'int' [-Werror,-Wimplicit-int]__init *ti_clk_get_div_table(struct device_node *node) ~~~~~~ ^drivers/clk/ti/divider.c:345:9: warning: incompatible pointer types
returning 'struct clk_div_table *' from a function with result type 'int *' [-Wincompatible-pointer-types]
return table;
^~~~~
drivers/clk/ti/divider.c:419:9: warning: incompatible pointer types
assigning to 'const struct clk_div_table *' from 'int *' [-Wincompatible-pointer-types]
*table = ti_clk_get_div_table(node);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~3 warnings and 2 errors generated.
By convention, most of the kernel code puts section attributes between the return type and function name. In the case where the return type is a pointer, it's important to place the '*' on left of the __init.
This updated code works for both gcc and clang.
--- drivers/clk/ti/divider.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/ti/divider.c +2 -2
@@ -300,8 +300,8 @@ static struct clk *_register_divider(struct device *dev, const char *name,return clk; } -static struct clk_div_table -__init *ti_clk_get_div_table (struct device_node *node) +static struct clk_div_table * +__init ti_clk_get_div_table (struct device_node *node) {struct clk_div_table *table;const __be32 *divspec;
Signature · 1 line
1.9.1
Quoted 34 lines · Behan Webster
As written, the
__initforti_clk_get_div_tableis in the middle of the return type.The gcc documentation indicates that section attributes should be added to the end of the function declaration:
extern void foobar (void)
__attribute__((section ("bar")));However gcc seems to be very permissive with where attributes can be placed. clang on the other hand isn't so permissive, and fails if you put the section definition in the middle of the return type:
drivers/clk/ti/divider.c:298:28: error: expected ';' after struct static structclk_div_table^ ;
drivers/clk/ti/divider.c:298:1: warning: 'static' ignored on this
declaration [-Wmissing-declarations]
static structclk_div_table
^drivers/clk/ti/divider.c:299:9: error: type specifier missing,
defaults to 'int' [-Werror,-Wimplicit-int]__init*ti_clk_get_div_table(structdevice_node*node) ~~~~~~ ^drivers/clk/ti/divider.c:345:9: warning: incompatible pointer typesreturning 'struct clk_div_table *' from a function with result type 'int *' [-Wincompatible-pointer-types] return table; ^~~~~ drivers/clk/ti/divider.c:419:9: warning: incompatible pointer types assigning to 'const struct clk_div_table *' from 'int *' [-Wincompatible-pointer-types] *table = ti_clk_get_div_table(node); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~3 warnings and 2 errors generated.
Quoted 8 lines
By convention, most of the kernel code puts section attributes between the return type and function name. In the case where the return type is a pointer, it's important to place the '*' on left of the
__init.This updated code works for both gcc and clang.
Signed-off-by Behan Webster <[email protected]>Reviewed-by Mark Charlebois <[email protected]>
makes sense to me:
I wonder if we should add this a Sparse or Coccinelle rule.
Signature · 1 line
balbi
Quoted 39 lines · Felipe Balbi
Quoted 38 lines · Behan Webster
As written, the
__initforti_clk_get_div_tableis in the middle of the return type.The gcc documentation indicates that section attributes should be added to the end of the function declaration:
extern void foobar (void) __attribute__ ((section ("bar")));However gcc seems to be very permissive with where attributes can be placed. clang on the other hand isn't so permissive, and fails if you put the section definition in the middle of the return type:
drivers/clk/ti/divider.c:298:28: error: expected ';' after struct static structclk_div_table^ ;
drivers/clk/ti/divider.c:298:1: warning: 'static' ignored on this
declaration [-Wmissing-declarations]
static structclk_div_table
^drivers/clk/ti/divider.c:299:9: error: type specifier missing,
defaults to 'int' [-Werror,-Wimplicit-int]__init*ti_clk_get_div_table(structdevice_node*node) ~~~~~~ ^drivers/clk/ti/divider.c:345:9: warning: incompatible pointer typesreturning 'struct clk_div_table *' from a function with result type 'int *' [-Wincompatible-pointer-types] return table; ^~~~~ drivers/clk/ti/divider.c:419:9: warning: incompatible pointer types assigning to 'const struct clk_div_table *' from 'int *' [-Wincompatible-pointer-types] *table = ti_clk_get_div_table(node); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~3 warnings and 2 errors generated.
By convention, most of the kernel code puts section attributes between the return type and function name. In the case where the return type is a pointer, it's important to place the '*' on left of the
__init.
Quoted 7 lines
Quoted 4 lines
This updated code works for both gcc and clang.
Signed-off-by Behan Webster <[email protected]>Reviewed-by Mark Charlebois <[email protected]>makes sense to me:
Reviewed-by Felipe Balbi <[email protected]>
Thank you.
Quoted 1 line
I wonder if we should add this a Sparse or Coccinelle rule.
+1
I'm hoping it can be added to checkpatch as well.
Behan
Signature · 2 lines
Behan Webster [email protected]
Quoted 55 lines · Behan Webster
Quoted 47 lines · Felipe Balbi
Quoted 46 lines · Behan Webster
As written, the
__initforti_clk_get_div_tableis in the middle of the return
type.The gcc documentation indicates that section attributes should be added to the
end of the function declaration:extern void foobar (void) __attribute__ ((section ("bar")));However gcc seems to be very permissive with where attributes can be placed.
clang on the other hand isn't so permissive, and fails if you put the section
definition in the middle of the return type:
drivers/clk/ti/divider.c:298:28: error: expected ';' after struct static structclk_div_table^ ;
drivers/clk/ti/divider.c:298:1: warning: 'static' ignored on this
declaration [-Wmissing-declarations]
static structclk_div_table
^drivers/clk/ti/divider.c:299:9: error: type specifier missing,
defaults to 'int' [-Werror,-Wimplicit-int]__init*ti_clk_get_div_table(structdevice_node*node) ~~~~~~ ^drivers/clk/ti/divider.c:345:9: warning: incompatible pointer types
returning 'structclk_div_table*' from a function with result
type 'int *' [-Wincompatible-pointer-types]return table; ^~~~~ drivers/clk/ti/divider.c:419:9: warning: incompatible pointer types assigning to 'const struct clk_div_table *' from 'int *' [-Wincompatible-pointer-types] *table = ti_clk_get_div_table(node); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~3 warnings and 2 errors generated.
By convention, most of the kernel code puts section attributes between the
return type and function name. In the case where the return type is a pointer,
it's important to place the '*' on left of the__init.Quoted 7 lines
Quoted 4 lines
This updated code works for both gcc and clang.
Signed-off-by Behan Webster <[email protected]>Reviewed-by Mark Charlebois <[email protected]>makes sense to me:
Reviewed-by Felipe Balbi <[email protected]>
Quoted 9 lines
Thank you.
Quoted 1 line
I wonder if we should add this a Sparse or Coccinelle rule.
+1
I'm hoping it can be added to checkpatch as well.
Behan
Thanks, patch applied to for-v3.18/ti-clk-drv.
-Tero