]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/hwmon-smsc47b397-use-request_muxed_region-for-super-.patch
Linux 4.9.181
[thirdparty/kernel/stable-queue.git] / queue-4.4 / hwmon-smsc47b397-use-request_muxed_region-for-super-.patch
1 From 056e4008ea95bfc4da7d8efab09fe2d779d9329f Mon Sep 17 00:00:00 2001
2 From: Guenter Roeck <linux@roeck-us.net>
3 Date: Thu, 4 Apr 2019 11:22:42 -0700
4 Subject: hwmon: (smsc47b397) Use request_muxed_region for Super-IO accesses
5
6 [ Upstream commit 8c0826756744c0ac1df600a5e4cca1a341b13101 ]
7
8 Super-IO accesses may fail on a system with no or unmapped LPC bus.
9
10 Also, other drivers may attempt to access the LPC bus at the same time,
11 resulting in undefined behavior.
12
13 Use request_muxed_region() to ensure that IO access on the requested
14 address space is supported, and to ensure that access by multiple drivers
15 is synchronized.
16
17 Fixes: 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)")
18 Reported-by: Kefeng Wang <wangkefeng.wang@huawei.com>
19 Reported-by: John Garry <john.garry@huawei.com>
20 Cc: John Garry <john.garry@huawei.com>
21 Acked-by: John Garry <john.garry@huawei.com>
22 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
23 Signed-off-by: Sasha Levin <sashal@kernel.org>
24 ---
25 drivers/hwmon/smsc47b397.c | 13 +++++++++++--
26 1 file changed, 11 insertions(+), 2 deletions(-)
27
28 diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
29 index 6bd2007565603..cbdb5c4991ae3 100644
30 --- a/drivers/hwmon/smsc47b397.c
31 +++ b/drivers/hwmon/smsc47b397.c
32 @@ -72,14 +72,19 @@ static inline void superio_select(int ld)
33 superio_outb(0x07, ld);
34 }
35
36 -static inline void superio_enter(void)
37 +static inline int superio_enter(void)
38 {
39 + if (!request_muxed_region(REG, 2, DRVNAME))
40 + return -EBUSY;
41 +
42 outb(0x55, REG);
43 + return 0;
44 }
45
46 static inline void superio_exit(void)
47 {
48 outb(0xAA, REG);
49 + release_region(REG, 2);
50 }
51
52 #define SUPERIO_REG_DEVID 0x20
53 @@ -300,8 +305,12 @@ static int __init smsc47b397_find(void)
54 u8 id, rev;
55 char *name;
56 unsigned short addr;
57 + int err;
58 +
59 + err = superio_enter();
60 + if (err)
61 + return err;
62
63 - superio_enter();
64 id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
65
66 switch (id) {
67 --
68 2.20.1
69