From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Joe Perches <joe@perches.com>,
rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com,
Dan Carpenter <error27@gmail.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] kernel: power: swap: mark a function as __init to save some memory
Date: Mon, 1 Jun 2020 19:17:54 +0200 [thread overview]
Message-ID: <71346705-6882-d2ca-3c53-1a5b23d66bbf@wanadoo.fr> (raw)
In-Reply-To: <effe3cde7b1f188427c42c476f5a96251d837416.camel@perches.com>
Le 01/06/2020 à 00:11, Joe Perches a écrit :
> (adding Dan Carpenter)
>
> On Sun, 2020-05-31 at 23:00 +0200, Christophe JAILLET wrote:
>> 'swsusp_header_init()' is only called via 'core_initcall'.
>> It can be marked as __init to save a few bytes of memory.
>
> Hey Dan
>
> smatch has a full function calling tree right?
>
> Can smatch find unmarked functions called only by __init
> functions so those unmarked functions can be appropriately
> marked with __init like the below?
>
Hi, in case of interest for anyone, I actually find such things as follow:
- grep to spot xxx_initcall macro (see comments in the perl script
below)
- a perl script which tries to spot missing __init
The false positive rate is low.
Feel free to use and propose patches based on it.
CJ
________________________________________________
#!/usr/bin/perl
use warnings;
use strict;
# grep -r --include=*.c -E
'^[[:space:]]*(early|core|postcore|arch|subsys|fs|device|late)_initcall\(.*\)'
* > tmp.txt
my $tmp="tmp.txt";
open(my $fh, "<", $tmp);
while (my $line = <$fh>) {
# Each line looks like:
# net/mac80211/main.c:subsys_initcall(ieee80211_init);
if ($line =~ /^(.*):.*\((.*)\)/) {
system("grep -E '$2\\(void' $1 | grep -v -E '__.*init'");
}
}
close($fh)
>> ---
>> kernel/power/swap.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
>> index ca0fcb5ced71..01e2858b5fe3 100644
>> --- a/kernel/power/swap.c
>> +++ b/kernel/power/swap.c
>> @@ -1590,7 +1590,7 @@ int swsusp_unmark(void)
>> }
>> #endif
>>
>> -static int swsusp_header_init(void)
>> +static int __init swsusp_header_init(void)
>> {
>> swsusp_header = (struct swsusp_header*) __get_free_page(GFP_KERNEL);
>> if (!swsusp_header)
>
>
next prev parent reply other threads:[~2020-06-01 17:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-31 21:00 Christophe JAILLET
2020-05-31 22:11 ` Joe Perches
2020-06-01 17:17 ` Christophe JAILLET [this message]
2020-06-08 11:22 ` Dan Carpenter
2020-06-08 11:34 ` Julia Lawall
2020-06-05 11:56 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=71346705-6882-d2ca-3c53-1a5b23d66bbf@wanadoo.fr \
--to=christophe.jaillet@wanadoo.fr \
--cc=error27@gmail.com \
--cc=joe@perches.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rjw@rjwysocki.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®