Commit ee4a77fc authored by Thierry Vignaud's avatar Thierry Vignaud Committed by Linus Torvalds

[PATCH] checksatck.pl fixes

- "\<" and "\>" can be safely replaced with "<" and ">"

- "$var =~ /^string$/" is better written "$var eq 'string'"

- $i is better written without the double quotes

- it's not safe to use for without "my"ing the iteration variable

- "print foreach @array" is better written "print @array"

- declare variables

- ".*" is useless at the end of a regexp

- "$a[@A] = $foo" is a rather obfuscated syntax for "push @A, $foo"...
  let's not opencoding language basic operators...

- ignoring return value from a regexp is very bad: this can results in
  working on previous value of $1, $2, ...
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent a68a29d9
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# $1 (first bracket) matches the size of the stack growth # $1 (first bracket) matches the size of the stack growth
# #
# use anything else and feel the pain ;) # use anything else and feel the pain ;)
my (@stack, $re, $x, $xs);
{ {
my $arch = shift; my $arch = shift;
if ($arch eq "") { if ($arch eq "") {
...@@ -31,25 +32,25 @@ ...@@ -31,25 +32,25 @@
$x = "[0-9a-f]"; # hex character $x = "[0-9a-f]"; # hex character
$xs = "[0-9a-f ]"; # hex character or space $xs = "[0-9a-f ]"; # hex character or space
if ($arch =~ /^arm$/) { if ($arch eq 'arm') {
#c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
$re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o; $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
} elsif ($arch =~ /^i[3456]86$/) { } elsif ($arch =~ /^i[3456]86$/) {
#c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
$re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o; $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;
} elsif ($arch =~ /^ia64$/) { } elsif ($arch eq 'ia64') {
#e0000000044011fc: 01 0f fc 8c adds r12=-384,r12 #e0000000044011fc: 01 0f fc 8c adds r12=-384,r12
$re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o; $re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o;
} elsif ($arch =~ /^mips64$/) { } elsif ($arch eq 'mips64') {
#8800402c: 67bdfff0 daddiu sp,sp,-16 #8800402c: 67bdfff0 daddiu sp,sp,-16
$re = qr/.*daddiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o; $re = qr/.*daddiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
} elsif ($arch =~ /^mips$/) { } elsif ($arch eq 'mips') {
#88003254: 27bdffe0 addiu sp,sp,-32 #88003254: 27bdffe0 addiu sp,sp,-32
$re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o; $re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
} elsif ($arch =~ /^ppc$/) { } elsif ($arch eq 'ppc') {
#c00029f4: 94 21 ff 30 stwu r1,-208(r1) #c00029f4: 94 21 ff 30 stwu r1,-208(r1)
$re = qr/.*stwu.*r1,-($x{1,8})\(r1\)/o; $re = qr/.*stwu.*r1,-($x{1,8})\(r1\)/o;
} elsif ($arch =~ /^ppc64$/) { } elsif ($arch eq 'ppc64') {
#XXX #XXX
$re = qr/.*stdu.*r1,-($x{1,8})\(r1\)/o; $re = qr/.*stdu.*r1,-($x{1,8})\(r1\)/o;
} elsif ($arch =~ /^s390x?$/) { } elsif ($arch =~ /^s390x?$/) {
...@@ -62,6 +63,7 @@ ...@@ -62,6 +63,7 @@
} }
sub bysize($) { sub bysize($) {
my ($asize, $bsize);
($asize = $a) =~ s/.* +(.*)$/$1/; ($asize = $a) =~ s/.* +(.*)$/$1/;
($bsize = $b) =~ s/.* +(.*)$/$1/; ($bsize = $b) =~ s/.* +(.*)$/$1/;
$bsize <=> $asize $bsize <=> $asize
...@@ -70,8 +72,9 @@ sub bysize($) { ...@@ -70,8 +72,9 @@ sub bysize($) {
# #
# main() # main()
# #
$funcre = qr/^$x* \<(.*)\>:$/; my $funcre = qr/^$x* <(.*)>:$/;
while ($line = <STDIN>) { my $func;
while (my $line = <STDIN>) {
if ($line =~ m/$funcre/) { if ($line =~ m/$funcre/) {
$func = $1; $func = $1;
} }
...@@ -85,7 +88,7 @@ while ($line = <STDIN>) { ...@@ -85,7 +88,7 @@ while ($line = <STDIN>) {
$size += 0x80000000; $size += 0x80000000;
} }
$line =~ m/^($xs*).*/; next if $line !~ m/^($xs*)/;
my $addr = $1; my $addr = $1;
$addr =~ s/ /0/g; $addr =~ s/ /0/g;
$addr = "0x$addr"; $addr = "0x$addr";
...@@ -97,12 +100,8 @@ while ($line = <STDIN>) { ...@@ -97,12 +100,8 @@ while ($line = <STDIN>) {
$padlen -= 8; $padlen -= 8;
} }
next if ($size < 100); next if ($size < 100);
$stack[@stack] = "$intro$size\n"; push @stack, "$intro$size\n";
} }
} }
@sortedstack = sort bysize @stack; print sort bysize @stack;
foreach $i (@sortedstack) {
print("$i");
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment