From d798d611f8ce74aee1376ed69bc7f042b530ef1b Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Thu, 27 Nov 2008 18:27:20 +0000 Subject: [PATCH] Reindent and cleanup I/O port access functions. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5447 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/detect/sensors-detect | 40 +++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index a7b9b84b..d7066bd3 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -2067,44 +2067,40 @@ sub any_list_match } ################### -# I/O port access # +# I/O PORT ACCESS # ################### sub initialize_ioports { - sysopen(IOPORTS, "/dev/port", O_RDWR) - or die "/dev/port: $!\n"; - binmode(IOPORTS); + sysopen(IOPORTS, "/dev/port", O_RDWR) + or die "/dev/port: $!\n"; + binmode(IOPORTS); } sub close_ioports { - close(IOPORTS) - or print "Warning: $!\n"; + close(IOPORTS); } # $_[0]: port to read # Returns: -1 on failure, read value on success. sub inb { - my ($res, $nrchars); - sysseek(IOPORTS, $_[0], 0) or return -1; - $nrchars = sysread(IOPORTS, $res, 1); - return -1 if not defined $nrchars or $nrchars != 1; - $res = unpack("C", $res); - return $res; + my ($res, $nrchars); + sysseek(IOPORTS, $_[0], 0) or return -1; + $nrchars = sysread(IOPORTS, $res, 1); + return -1 if not defined $nrchars or $nrchars != 1; + $res = unpack("C", $res); + return $res; } # $_[0]: port to write # $_[1]: value to write -# Returns: -1 on failure, 0 on success. +# We assume this can't fail. sub outb { - my $towrite = pack("C", $_[1]); - sysseek(IOPORTS, $_[0], 0) or return -1; - my $nrchars = syswrite(IOPORTS, $towrite, 1); - return -1 if not defined $nrchars or $nrchars != 1; - return 0; + sysseek(IOPORTS, $_[0], 0); + syswrite(IOPORTS, pack("C", $_[1]), 1); } # $_[0]: Address register @@ -2113,8 +2109,8 @@ sub outb # Returns: read value sub isa_read_byte { - outb($_[0], $_[2]); - return inb($_[1]); + outb($_[0], $_[2]); + return inb($_[1]); } # $_[0]: Base address @@ -2124,8 +2120,8 @@ sub isa_read_byte # offset 5 and data register at offset 6. sub isa_read_i5d6 { - my ($addr, $reg) = @_; - return isa_read_byte($addr + 5, $addr + 6, $reg); + my ($addr, $reg) = @_; + return isa_read_byte($addr + 5, $addr + 6, $reg); } #################