Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 'uninitialized value $ucode_vars{"AVAIL"}' from AMD ucode #226

Merged
merged 4 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions perl/lib/NeedRestart/uCode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ our @EXPORT = qw(

my $LOGPREF = '[ucode]';

sub compare_ucode_versions {
my ($debug, $processor, %vars) = @_;

unless ( exists( $vars{CURRENT} ) && exists( $vars{AVAIL} ) ) {
print STDERR
"$LOGPREF #$processor did not get current microcode version\n"
if ( $debug && !exists( $vars{CURRENT} ) );
print STDERR
"$LOGPREF #$processor did not get available microcode version\n"
if ( $debug && !exists( $vars{AVAIL} ) );

return NRM_UNKNOWN;
}

if ( hex( $vars{CURRENT} ) >= hex( $vars{AVAIL} ) ) {
return NRM_CURRENT;
}

return NRM_OBSOLETE;
}

sub nr_ucode_check {
my $debug = shift;
my $ui = shift;
Expand Down Expand Up @@ -118,13 +139,13 @@ sub nr_ucode_check {

# call ucode modules
foreach my $pkg (@PKGS) {
my ( $nstate, @nvars ) = (NRM_UNKNOWN);
eval
"(\$nstate, \@nvars) = ${pkg}::nr_ucode_check_real(\$debug, \$ui, \$processors{\$pid});";
my ( $processor, @nvars) = ('?');
eval "(\$processor, \@nvars) = ${pkg}::nr_ucode_check_real(\$debug, \$ui, \$processors{\$pid});";
print STDERR $@
if ( $@ && $debug );
$ui->progress_step;

my $nstate = compare_ucode_versions( $debug, $processor, @nvars );
if ( $nstate > $state ) {
( $state, @vars ) = ( $nstate, @nvars );
}
Expand Down
26 changes: 10 additions & 16 deletions perl/lib/NeedRestart/uCode/AMD.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ sub _scan_ucodes {

if ( $pkg_cpuid > 0 ) {
$_ucodes->{cpuid}->{$pkg_cpuid} = $pkg_prid;
printf STDERR
"$LOGPREF cpuid 0x%08x: found processor id 0x%08x\n", $pkg_cpuid, $pkg_prid
if ($debug);
}
}

Expand All @@ -99,6 +102,9 @@ sub _scan_ucodes {
) = unpack( 'VVvCCVVVv', $buf );

$_ucodes->{prid}->{$pat_prid} = $pat_pid;
printf STDERR
"$LOGPREF processor id 0x%08x: available ucode 0x%08x\n", $pat_prid, $pat_pid
if ($debug);
}
}
}
Expand Down Expand Up @@ -170,7 +176,7 @@ sub nr_ucode_check_real {
printf( STDERR "$LOGPREF #$info->{processor} running ucode 0x%08x\n", $ucode ) if ($debug);

unless ( defined($_ucodes) ) {
_scan_ucodes();
_scan_ucodes( $debug );
}

my %vars = ( CURRENT => sprintf( "0x%08x", $ucode ), );
Expand All @@ -180,23 +186,11 @@ sub nr_ucode_check_real {
my $prid = $_ucodes->{cpuid}->{$cpuid};
if ( exists( $_ucodes->{prid}->{$prid} ) ) {
$vars{AVAIL} = sprintf( "0x%08x", $_ucodes->{prid}->{$prid} ),

print STDERR "$LOGPREF #$info->{processor} found ucode $vars{AVAIL}\n" if ($debug);
if ( $_ucodes->{prid}->{$prid} > $ucode ) {
return ( NRM_OBSOLETE, %vars );
}
}
else {
print STDERR "$LOGPREF #$info->{processor} no ucode updates available\n" if ($debug);
}
return ( NRM_CURRENT, %vars );
}
else {
print STDERR "$LOGPREF #$info->{processor} no ucode updates available\n" if ($debug);
return ( NRM_CURRENT, %vars );
print STDERR "$LOGPREF #$info->{processor} found ucode $vars{AVAIL}\n" if ($debug);
}
}

return ( NRM_UNKNOWN, %vars );
return ( $info->{processor}, %vars );
}

1;
17 changes: 1 addition & 16 deletions perl/lib/NeedRestart/uCode/Intel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,7 @@ sub nr_ucode_check_real {
}
$vars{AVAIL} = $_avail if ( defined($_avail) );

unless ( exists( $vars{CURRENT} ) && exists( $vars{AVAIL} ) ) {
print STDERR
"$LOGPREF #$info->{processor} did not get current microcode version\n"
if ( $debug && !exists( $vars{CURRENT} ) );
print STDERR
"$LOGPREF #$info->{processor} did not get available microcode version\n"
if ( $debug && !exists( $vars{AVAIL} ) );

return ( NRM_UNKNOWN, %vars );
}

if ( hex( $vars{CURRENT} ) >= hex( $vars{AVAIL} ) ) {
return ( NRM_CURRENT, %vars );
}

return ( NRM_OBSOLETE, %vars );
return ( $info->{processor}, %vars );
}

1;