Re: [PATCH] removing redundant ifdefs

From: Jiri Olsa
Date: Fri May 07 2010 - 04:01:11 EST


On Thu, May 06, 2010 at 10:43:43AM -0700, Randy Dunlap wrote:
> On Thu, 6 May 2010 19:36:04 +0200 Jiri Olsa wrote:
>
> > removing redundant ifdefs.
> >
> > the pattern is
> >
> > #ifdef DEF1
> > ...
> > #ifdef DEF1
> > ...
> > #endif
> > ...
> > #endif
> >
> > and removing the inner ifdef.
> >
> > I found them using script all over the kernel so
> > I haven't even compile-tested some of them.
>
> what script, please?
>
> ---
> ~Randy
> *** Remember to use Documentation/SubmitChecklist when testing your code ***

I made one after I spot one place like that.. it's simple
perl script, which spits many false warnings (attached).
I took what I thought was right. I did not want to spend
much time with that. ;)

wbr,
jirka

---
#!/usr/bin/perl

my @ifdefs;
my $lnb = 0;
my $file = $ARGV[0];

open FILE, $file or die $!;

while($line = <FILE>) {
chop $line;
$lnb++;

if ($line =~ /^#[ ]*ifdef|^#[ ]*if/) {
my @ifdef = split(/\s/, $line);
my $def = $ifdef[1];

foreach $d(@ifdefs) {
next if ($d ne $def);
print "$file: [$line]\n";
print "$file: got duplicate $def, line $lnb\n";
}

push(@ifdefs, $def);
}

if ($line =~ /^#[ ]*endif/) {
pop(@ifdefs);
}
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/