From cebcb35d94d4542cf21f0d4f7338f028f0eb67db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Fri, 27 Apr 2012 21:19:40 +0200 Subject: [PATCH] dmidecode: ignore CPU frequency if 10>GHz Closes: #633 --- lib/FusionInventory/Agent/Tools/Generic.pm | 21 ++++++++++++++------- t/tools/generic.t | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/FusionInventory/Agent/Tools/Generic.pm b/lib/FusionInventory/Agent/Tools/Generic.pm index 25ac7ba8d0..825b70a1f4 100644 --- a/lib/FusionInventory/Agent/Tools/Generic.pm +++ b/lib/FusionInventory/Agent/Tools/Generic.pm @@ -99,13 +99,20 @@ sub getCpusFromDmidecode { $cpu->{SPEED} = $1 * 1000; } } - if (!$cpu->{SPEED}) { - if ($info->{'Max Speed'}) { - if ($info->{'Max Speed'} =~ /^\s*(\d+)\s*Mhz/i) { - $cpu->{SPEED} = $1; - } elsif ($info->{'Max Speed'} =~ /^\s*(\d+)\s*Ghz/i) { - $cpu->{SPEED} = $1 * 1000; - } + if (!$cpu->{SPEED} && $info->{'Max Speed'}) { + # We only look for 3 digit Mhz frequency to avoid abvious bad + # value like 30000 (#633) + if ($info->{'Max Speed'} =~ /^\s*(\d{3,4})\s*Mhz/i) { + $cpu->{SPEED} = $1; + } elsif ($info->{'Max Speed'} =~ /^\s*(\d+)\s*Ghz/i) { + $cpu->{SPEED} = $1 * 1000; + } + } + if (!$cpu->{SPEED} && $info->{'Current Speed'}) { + if ($info->{'Current Speed'} =~ /^\s*(\d{3,4})\s*Mhz/i) { + $cpu->{SPEED} = $1; + } elsif ($info->{'Current Speed'} =~ /^\s*(\d+)\s*Ghz/i) { + $cpu->{SPEED} = $1 * 1000; } } diff --git a/t/tools/generic.t b/t/tools/generic.t index 42f4c6d73c..16f053e67a 100755 --- a/t/tools/generic.t +++ b/t/tools/generic.t @@ -5894,7 +5894,7 @@ my %cpu_tests = ( { ID => '42 0F 10 00 FF FB 8B 07', NAME => undef, - SPEED => '30000', + SPEED => '2300', THREAD => undef, SERIAL => undef, MANUFACTURER => 'AuthenticAMD',