Add __init attribute on a function that is only called from other __init
functions and that is not inlined.
The complete semantic patch used to detect the need for this change is
below. This semantic patch checks for local static non-init functions that
are called from an __init function and are not called from any other
function.
<smpl>
@initialize:ocaml@
@@
let itbl = Hashtbl.create 101
let ltbl = Hashtbl.create 101
let thefile = ref ""
let hashadd t k =
let cell =
try Hashtbl.find t k
with Not_found ->
let cell = ref 0 in
Hashtbl.add t k cell;
cell in
cell := !cell + 1
let hashget t k = try !(Hashtbl.find t k) with Not_found -> 0
let seen = ref []
@script:ocaml@
@@
(let file = List.hd (Coccilib.files()) in
thefile := file;
let file =
try List.hd(List.tl (Str.split (Str.regexp "/linux-next/") file))
with _ -> file in
let ofile = "/var/julia/linux-next/" ^
(Filename.chop_extension file) ^ ".o" in
if not(Sys.file_exists ofile)
then Coccilib.exit());
Hashtbl.clear itbl;
Hashtbl.clear ltbl;
seen := []
@r@
identifier f;
@@
__init f(...) { ... }
@script:ocaml@
f << r.f;
@@
Hashtbl.add itbl f ()
@s disable optional_attributes@
identifier f;
@@
static f(...) { ... }
@script:ocaml@
f << s.f;
@@
Hashtbl.add ltbl f ()
@t exists@
identifier f,g;
position p;
@@
__init f(...) { ... when any
g@p(...)
... when any
}
@script:ocaml@
g << t.g;
_p << t.p;
@@
if not (Hashtbl.mem ltbl g) || Hashtbl.mem itbl g
then Coccilib.include_match false
@ok1 disable optional_attributes exists@
identifier f,t.g;
@@
f(...) { ... when any
g
... when any
}
@ok2 disable optional_attributes exists@
identifier i,j,fld,t.g;
@@
struct i j = { .fld = g, };
@ok3 disable optional_attributes exists@
identifier t.g;
declarer d;
@@
d(...,g,...);
@ok4 disable optional_attributes exists@
identifier t.g;
expression e;
@@
(
e(...,g,...)
|
e(...,&g,...)
|
e = &g
|
e = g
)
@script:ocaml depends on !ok1 && !ok2 && !ok3 && !ok4@
g << t.g;
@@
let file = !thefile in
let file =
try List.hd(List.tl (Str.split (Str.regexp "/linux-next/") file))
with _ -> file in
if not(List.mem (g,file) !seen)
then
begin
seen := (g,file) :: !seen;
let ofile = "/var/julia/linux-next/" ^
(Filename.chop_extension file) ^ ".o" in
if Sys.file_exists ofile
then
let l =
Common.cmd_to_list
(Printf.sprintf
"objdump -x %s | grep -w %s | grep -w F | grep .text.unlikely"
ofile g) in
match l with
[] -> Coccilib.include_match false
| _ ->
Printf.printf "Info for %s %s\n" file g;
List.iter
(function l -> Printf.printf "%s\n" l)
l;
Printf.printf "\n"; flush stdout
else Coccilib.include_match false
end
else Coccilib.include_match false
@depends on !ok1 && !ok2 && !ok3 && !ok4@
identifier t.g;
@@
- g
+__init g
(...) { ... }
</smpl>
---
drivers/mtd/maps/ck804xrom.c | 4 ++--
drivers/mtd/maps/esb2rom.c | 4 ++--
drivers/mtd/maps/ichxrom.c | 4 ++--
drivers/thermal/of-thermal.c | 4 ++--
drivers/mtd/devices/pmc551.c | 2 +-
drivers/mtd/nand/nandsim.c | 6 +++---
Add __init attribute on functions that are only called from other __init
functions and that are not inlined, at least with gcc version 4.8.4 on an
x86 machine with allyesconfig. Currently, the functions are put in the
.text.unlikely segment. Declaring them as __init will cause them to be
put in the .init.text and to disappear after initialization.
The result of objdump -x on the functions before the change is as follows:
00000000000001bc l F .text.unlikely 00000000000006a2 ck804xrom_init_one.isra.1
00000000000001aa l F .text.unlikely 0000000000000764 esb2rom_init_one.isra.1
00000000000001db l F .text.unlikely 0000000000000716 ichxrom_init_one.isra.1
And after the change it is as follows:
0000000000000000 l F .init.text 000000000000069d ck804xrom_init_one.isra.1
0000000000000000 l F .init.text 000000000000075f esb2rom_init_one.isra.1
0000000000000000 l F .init.text 0000000000000711 ichxrom_init_one.isra.1
Done with the help of Coccinelle. The semantic patch checks for local
static non-init functions that are called from an __init function and are
not called from any other function.
Note that in each case, the function is stored in the probe field of a
pci_driver structure, but this code is under an #if 0. The #if 0s have
been unchanged since 2009 at the latest.
Signed-off-by: Julia Lawall <[email protected]>
---
drivers/mtd/maps/ck804xrom.c | 4 ++--
drivers/mtd/maps/esb2rom.c | 4 ++--
drivers/mtd/maps/ichxrom.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index 0455166..4f206a9 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -112,8 +112,8 @@ static void ck804xrom_cleanup(struct ck804xrom_window *window)
}
-static int ck804xrom_init_one(struct pci_dev *pdev,
- const struct pci_device_id *ent)
+static int __init ck804xrom_init_one(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
{
static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
u8 byte;
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
index 76ed651..9646b07 100644
--- a/drivers/mtd/maps/esb2rom.c
+++ b/drivers/mtd/maps/esb2rom.c
@@ -144,8 +144,8 @@ static void esb2rom_cleanup(struct esb2rom_window *window)
pci_dev_put(window->pdev);
}
-static int esb2rom_init_one(struct pci_dev *pdev,
- const struct pci_device_id *ent)
+static int __init esb2rom_init_one(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
{
static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
struct esb2rom_window *window = &esb2rom_window;
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c
index 8636bba..e17d02a 100644
--- a/drivers/mtd/maps/ichxrom.c
+++ b/drivers/mtd/maps/ichxrom.c
@@ -84,8 +84,8 @@ static void ichxrom_cleanup(struct ichxrom_window *window)
}
-static int ichxrom_init_one(struct pci_dev *pdev,
- const struct pci_device_id *ent)
+static int __init ichxrom_init_one(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
{
static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
struct ichxrom_window *window = &ichxrom_window;
Add __init attribute on a function that is only called from other __init
functions and that is not inlined, at least with gcc version 4.8.4 on an
x86 machine with allyesconfig. Currently, the function is put in the
.text.unlikely segment. Declaring it as __init will cause it to be put in
the .init.text and to disappear after initialization.
The result of objdump -x on the function before the change is as follows:
0000000000000086 l F .text.unlikely 0000000000000739 thermal_of_build_thermal_zone
And after the change it is as follows:
0000000000000000 l F .init.text 0000000000000734 thermal_of_build_thermal_zone
Done with the help of Coccinelle. The semantic patch checks for local
static non-init functions that are called from an __init function and are
not called from any other function.
Signed-off-by: Julia Lawall <[email protected]>
---
drivers/thermal/of-thermal.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index 8528802..b8e509c 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -811,8 +811,8 @@ static int thermal_of_populate_trip(struct device_node *np,
* otherwise, it returns a corresponding ERR_PTR(). Caller must
* check the return value with help of IS_ERR() helper.
*/
-static struct __thermal_zone *
-thermal_of_build_thermal_zone(struct device_node *np)
+static struct __thermal_zone
+__init *thermal_of_build_thermal_zone(struct device_node *np)
{
struct device_node *child = NULL, *gchild;
struct __thermal_zone *tz;
Add __init attribute on functions that are only called from other __init
functions and that are not inlined, at least with gcc version 4.8.4 on an
x86 machine with allyesconfig. Currently, the functions are put in the
.text.unlikely segment. Declaring them as __init will cause them to be
put in the .init.text and to disappear after initialization.
The result of objdump -x on the functions before the change is as follows:
000000000000059a l F .text.unlikely 0000000000000239 alloc_device
000000000000034e l F .text.unlikely 000000000000002e get_partition_name
00000000000007d3 l F .text.unlikely 00000000000005da init_nandsim
And after the change it is as follows:
0000000000000029 l F .init.text 0000000000000234 alloc_device
0000000000000000 l F .init.text 0000000000000029 get_partition_name
000000000000025d l F .init.text 00000000000005d5 init_nandsim
Done with the help of Coccinelle. The semantic patch checks for local
static non-init functions that are called from an __init function and are
not called from any other function.
Signed-off-by: Julia Lawall <[email protected]>
---
drivers/mtd/nand/nandsim.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 1439459..527d23e 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -569,7 +569,7 @@ static void nandsim_debugfs_remove(struct nandsim *ns)
*
* RETURNS: 0 if success, -ENOMEM if memory alloc fails.
*/
-static int alloc_device(struct nandsim *ns)
+static int __init alloc_device(struct nandsim *ns)
{
struct file *cfile;
int i, err;
@@ -654,7 +654,7 @@ static void free_device(struct nandsim *ns)
}
}
-static char *get_partition_name(int i)
+static char __init *get_partition_name(int i)
{
return kasprintf(GFP_KERNEL, "NAND simulator partition %d", i);
}
@@ -664,7 +664,7 @@ static char *get_partition_name(int i)
*
* RETURNS: 0 if success, -ERRNO if failure.
*/
-static int init_nandsim(struct mtd_info *mtd)
+static int __init init_nandsim(struct mtd_info *mtd)
{
struct nand_chip *chip = mtd_to_nand(mtd);
struct nandsim *ns = nand_get_controller_data(chip);
Add __init attribute on a function that is only called from other __init
functions and that is not inlined, at least with gcc version 4.8.4 on an
x86 machine with allyesconfig. Currently, the function is put in the
.text.unlikely segment. Declaring it as __init will cause it to be put in
the .init.text and to disappear after initialization.
The result of objdump -x on the function before the change is as follows:
00000000000000c6 l F .text.unlikely 000000000000091c fixup_pmc551
And after the change it is as follows:
0000000000000000 l F .init.text 0000000000000917 fixup_pmc551
Done with the help of Coccinelle. The semantic patch checks for local
static non-init functions that are called from an __init function and are
not called from any other function.
Signed-off-by: Julia Lawall <[email protected]>
---
drivers/mtd/devices/pmc551.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/devices/pmc551.c b/drivers/mtd/devices/pmc551.c
index 708b7e8..220f920 100644
--- a/drivers/mtd/devices/pmc551.c
+++ b/drivers/mtd/devices/pmc551.c
@@ -353,7 +353,7 @@ static int pmc551_write(struct mtd_info *mtd, loff_t to, size_t len,
* mechanism
* returns the size of the memory region found.
*/
-static int fixup_pmc551(struct pci_dev *dev)
+static int __init fixup_pmc551(struct pci_dev *dev)
{
#ifdef CONFIG_MTD_PMC551_BUGFIX
u32 dram_data;
On Tue, 19 Apr 2016 14:33:35 +0200
Julia Lawall <[email protected]> wrote:
> Add __init attribute on functions that are only called from other __init
> functions and that are not inlined, at least with gcc version 4.8.4 on an
> x86 machine with allyesconfig. Currently, the functions are put in the
> .text.unlikely segment. Declaring them as __init will cause them to be
> put in the .init.text and to disappear after initialization.
>
> The result of objdump -x on the functions before the change is as follows:
>
> 000000000000059a l F .text.unlikely 0000000000000239 alloc_device
> 000000000000034e l F .text.unlikely 000000000000002e get_partition_name
> 00000000000007d3 l F .text.unlikely 00000000000005da init_nandsim
>
> And after the change it is as follows:
>
> 0000000000000029 l F .init.text 0000000000000234 alloc_device
> 0000000000000000 l F .init.text 0000000000000029 get_partition_name
> 000000000000025d l F .init.text 00000000000005d5 init_nandsim
>
> Done with the help of Coccinelle. The semantic patch checks for local
> static non-init functions that are called from an __init function and are
> not called from any other function.
>
> Signed-off-by: Julia Lawall <[email protected]>
>
> ---
> drivers/mtd/nand/nandsim.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Applied, thanks.
Boris
--
Boris Brezillon, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
On Tue, Apr 19, 2016 at 02:33:33PM +0200, Julia Lawall wrote:
> Add __init attribute on functions that are only called from other __init
> functions and that are not inlined, at least with gcc version 4.8.4 on an
> x86 machine with allyesconfig. Currently, the functions are put in the
> .text.unlikely segment. Declaring them as __init will cause them to be
> put in the .init.text and to disappear after initialization.
>
> The result of objdump -x on the functions before the change is as follows:
>
> 00000000000001bc l F .text.unlikely 00000000000006a2 ck804xrom_init_one.isra.1
> 00000000000001aa l F .text.unlikely 0000000000000764 esb2rom_init_one.isra.1
> 00000000000001db l F .text.unlikely 0000000000000716 ichxrom_init_one.isra.1
>
> And after the change it is as follows:
>
> 0000000000000000 l F .init.text 000000000000069d ck804xrom_init_one.isra.1
> 0000000000000000 l F .init.text 000000000000075f esb2rom_init_one.isra.1
> 0000000000000000 l F .init.text 0000000000000711 ichxrom_init_one.isra.1
>
> Done with the help of Coccinelle. The semantic patch checks for local
> static non-init functions that are called from an __init function and are
> not called from any other function.
>
> Note that in each case, the function is stored in the probe field of a
> pci_driver structure, but this code is under an #if 0. The #if 0s have
> been unchanged since 2009 at the latest.
>
> Signed-off-by: Julia Lawall <[email protected]>
Applied patches 2 and 3 to l2-mtd.git