lm-sensors: Fix error seen with
Hi Guenter,
Quoted 12 lines · Guenter Roeck
The following patch fixes an error seen in sensors-detect if i2c bus numbering is not sequential. Problem is that in this case, $i2c_adapters[] does not exist for all index values, causing an error message whenever one of the non-existing objects is accessed.
The error message is:
Use of uninitialized value in string eq at ./sensors-detect line 5941.Index: prog/detect/sensors-detect
=================================> --- prog/detect/sensors-detect (revision 5868)
+++ prog/detect/sensors-detect (working copy)
Review line 5944
Quoted 10 lines
(quoted diff) +3
-1@@ -5936,7 +5936,9 @@ # If we added any module option to handle aliases, we need to load all # the adapter drivers so that the numbers will be the same. If not, then # we only load the adapter drivers which are useful. - foreach $adap (@i2c_adapters) { + for (my $dev_nr = 0; $dev_nr < @i2c_adapters; $dev_nr++) { + next unless exists $i2c_adapters[$dev_nr]; + $adap = $i2c_adapters[$dev_nr]; next if $adap->{autoload}; next if $adap->{driver} eq 'UNKNOWN'; next if not defined $configfile and not $adap->{used};
Good catch, but what's wrong with foreach? I believe you can just add:
next unless defined $adap;
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 28 lines · Jean Delvare
Hi Guenter,
Quoted 12 lines · Guenter Roeck
The following patch fixes an error seen in sensors-detect if i2c bus numbering is not sequential. Problem is that in this case, $i2c_adapters[] does not exist for all index values, causing an error message whenever one of the non-existing objects is accessed.
The error message is:
Use of uninitialized value in string eq at ./sensors-detect line 5941.Index: prog/detect/sensors-detect
=================================> > --- prog/detect/sensors-detect (revision 5868)
+++ prog/detect/sensors-detect (working copy)Review line 5944
Quoted 10 lines
(quoted diff) +3
-1@@ -5936,7 +5936,9 @@ # If we added any module option to handle aliases, we need to load all # the adapter drivers so that the numbers will be the same. If not, then # we only load the adapter drivers which are useful. - foreach $adap (@i2c_adapters) { + for (my $dev_nr = 0; $dev_nr < @i2c_adapters; $dev_nr++) { + next unless exists $i2c_adapters[$dev_nr]; + $adap = $i2c_adapters[$dev_nr]; next if $adap->{autoload}; next if $adap->{driver} eq 'UNKNOWN'; next if not defined $configfile and not $adap->{used};Good catch, but what's wrong with foreach? I believe you can just add:
Quoted 2 lines
next unless defined $adap;
You are right, that works as well, and is simpler. Only reason for using for instead of foreach was that the for loop was used elsewhere already.
I'll change it and resubmit.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors