lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 14 Apr 2011 14:38:16 -0700
From:	Nat Gurumoorthy <natg@...gle.com>
To:	Jean Delvare <khali@...ux-fr.org>,
	Guenter Roeck <guenter.roeck@...csson.com>,
	Wim Van Sebroeck <wim@...ana.be>
Cc:	Mike Waychison <mikew@...gle.com>, lm-sensors@...sensors.org,
	linux-kernel@...r.kernel.org, linux-watchdog@...r.kernel.org,
	Nat Gurumoorthy <natg@...gle.com>
Subject: [PATCH v6 2/2] Use "request_muxed_region" in it87 hwmon drivers

02 - Chages to hwmon it87 driver to use "request_muxed_region"
Serialize access to the hardware by using "request_muxed_region" macro defined
by Alan Cox. Call to this macro will hold off the requestor if the resource is
currently busy. The first call to request_muxed_region will attempt 10 times 
to reserve the region before it gives up. This will typically get called from
the driver init routines. If this succeeds then subsequent calls wait forever
for the resource to be available.

Signed-off-by: Nat Gurumoorthy <natg@...gle.com>
---

diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 316b648..2c349be 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -108,13 +108,34 @@ superio_select(int ldn)
 	outb(ldn, VAL);
 }
 
-static inline void
-superio_enter(void)
-{
+static inline int
+try_superio_enter(void)
+{
+	int num_tries = 10;
+	/*
+	 * Try to reserve REG and REG + 1 for exclusive access.
+	 * Give up after 10 attempts.
+	 */
+	while (num_tries--) {
+		if (!request_muxed_region(REG, 2, DRVNAME)) {
+			if (num_tries)
+				continue;
+
+			/*
+			 * Someone is holding the region. Give up.
+			 */
+			pr_err("I/O address 0x%04x already in use\n", REG);
+			return -EBUSY;
+		}
+
+		break;
+	}
+
 	outb(0x87, REG);
 	outb(0x01, REG);
 	outb(0x55, REG);
 	outb(0x55, REG);
+	return 0;
 }
 
 static inline void
@@ -122,6 +143,7 @@ superio_exit(void)
 {
 	outb(0x02, REG);
 	outb(0x02, VAL);
+	release_region(REG, 2);
 }
 
 /* Logical device 4 registers */
@@ -1546,7 +1568,9 @@ static int __init it87_find(unsigned short *address,
 	u16 chip_type;
 	const char *board_vendor, *board_name;
 
-	superio_enter();
+	if (try_superio_enter())
+		return -EBUSY;
+
 	chip_type = force_id ? force_id : superio_inw(DEVID);
 
 	switch (chip_type) {
-- 
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ