Linux PCI subsystem development
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: "Martin Mares" <mj@ucw.cz>, "Bjorn Helgaas" <helgaas@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	linux-pci@vger.kernel.org
Subject: [PATCH pciutils] libpci: Fix intel_cleanup_io() implementations
Date: Mon, 20 Dec 2021 20:28:43 +0100	[thread overview]
Message-ID: <20211220192843.15052-1-pali@kernel.org> (raw)

Function intel_cleanup_io() should de-initialize I/O port access, e.g. by
calling iopl(0) to reset I/O privilege level to default value.

Caller of intel_cleanup_io() expects that this function returns negative
value on success and positive value on error. Error means that I/O port
access was not de-initialized and is still active. Success means that I/O
port access is not active anymore and intel_setup_io() needs to be called
again to access I/O ports.

Fix Cygwin, Haiku and Linux implementations of intel_cleanup_io() function
to correctly de-initialize I/O port access and fix return value.
---
 lib/i386-io-cygwin.h | 2 +-
 lib/i386-io-haiku.h  | 2 +-
 lib/i386-io-linux.h  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/i386-io-cygwin.h b/lib/i386-io-cygwin.h
index 16022482f268..038b02d00a94 100644
--- a/lib/i386-io-cygwin.h
+++ b/lib/i386-io-cygwin.h
@@ -17,7 +17,7 @@ intel_setup_io(struct pci_access *a UNUSED)
 static inline int
 intel_cleanup_io(struct pci_access *a UNUSED)
 {
-  iopl(3);
+  iopl(0);
   return -1;
 }
 
diff --git a/lib/i386-io-haiku.h b/lib/i386-io-haiku.h
index 2bbe592672ab..5c724b34e98a 100644
--- a/lib/i386-io-haiku.h
+++ b/lib/i386-io-haiku.h
@@ -72,7 +72,7 @@ static inline int
 intel_cleanup_io(struct pci_access *a UNUSED)
 {
   close(poke_driver_fd);
-  return 1;
+  return -1;
 }
 
 static inline u8
diff --git a/lib/i386-io-linux.h b/lib/i386-io-linux.h
index b39b4eb8267d..619f8ec11695 100644
--- a/lib/i386-io-linux.h
+++ b/lib/i386-io-linux.h
@@ -17,7 +17,7 @@ intel_setup_io(struct pci_access *a UNUSED)
 static inline int
 intel_cleanup_io(struct pci_access *a UNUSED)
 {
-  iopl(3);
+  iopl(0);
   return -1;
 }
 
-- 
2.20.1


             reply	other threads:[~2021-12-20 19:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-20 19:28 Pali Rohár [this message]
2021-12-26 22:04 ` [PATCH pciutils] libpci: Fix intel_cleanup_io() implementations Martin Mareš

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211220192843.15052-1-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=helgaas@kernel.org \
    --cc=kw@linux.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=mj@ucw.cz \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox