Automatically release I/O permissions on shutdown

Get_io_perms() is renamed to rget_io_perms() and automatically registers
a function to release I/O permissions on shutdown.

Actually release I/O permissions on Solaris and iopl()-supporting
operating systems like Linux.

This patch fixes quite a few programmers which forgot to release I/O
permissions on shutdown, and it simplifies the shutdown and error
handling code for all others.

Do not call exit(1) if I/O permissions are denied and return an error
instead. This part of the patch was written by Niklas Söderlund.

Corresponding to flashrom svn r1551.

Signed-off-by: Carl-Daniel Hailfinger <>
Signed-off-by: Niklas Söderlund <>
Acked-by: Michael Karcher <>
diff --git a/nic3com.c b/nic3com.c
index a137c64..f4fb6fe 100644
--- a/nic3com.c
+++ b/nic3com.c
@@ -82,13 +82,13 @@
-	release_io_perms();
 	return 0;
 int nic3com_init(void)
-	get_io_perms();
+	if (rget_io_perms())
+		return 1;
 	io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, nics_3com);