]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/hwmon-pc87427-use-request_muxed_region-for-super-io-.patch
Linux 4.9.181
[thirdparty/kernel/stable-queue.git] / queue-4.4 / hwmon-pc87427-use-request_muxed_region-for-super-io-.patch
1 From 85770069abc314bc8c98380d9851da23b3857a46 Mon Sep 17 00:00:00 2001
2 From: Guenter Roeck <linux@roeck-us.net>
3 Date: Thu, 4 Apr 2019 11:16:20 -0700
4 Subject: hwmon: (pc87427) Use request_muxed_region for Super-IO accesses
5
6 [ Upstream commit 755a9b0f8aaa5639ba5671ca50080852babb89ce ]
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: ba224e2c4f0a7 ("hwmon: New PC87427 hardware monitoring driver")
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/pc87427.c | 14 +++++++++++++-
26 1 file changed, 13 insertions(+), 1 deletion(-)
27
28 diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
29 index cb9fdd37bd0d9..2b5b8c3de8fce 100644
30 --- a/drivers/hwmon/pc87427.c
31 +++ b/drivers/hwmon/pc87427.c
32 @@ -106,6 +106,13 @@ static const char *logdev_str[2] = { DRVNAME " FMC", DRVNAME " HMC" };
33 #define LD_IN 1
34 #define LD_TEMP 1
35
36 +static inline int superio_enter(int sioaddr)
37 +{
38 + if (!request_muxed_region(sioaddr, 2, DRVNAME))
39 + return -EBUSY;
40 + return 0;
41 +}
42 +
43 static inline void superio_outb(int sioaddr, int reg, int val)
44 {
45 outb(reg, sioaddr);
46 @@ -122,6 +129,7 @@ static inline void superio_exit(int sioaddr)
47 {
48 outb(0x02, sioaddr);
49 outb(0x02, sioaddr + 1);
50 + release_region(sioaddr, 2);
51 }
52
53 /*
54 @@ -1220,7 +1228,11 @@ static int __init pc87427_find(int sioaddr, struct pc87427_sio_data *sio_data)
55 {
56 u16 val;
57 u8 cfg, cfg_b;
58 - int i, err = 0;
59 + int i, err;
60 +
61 + err = superio_enter(sioaddr);
62 + if (err)
63 + return err;
64
65 /* Identify device */
66 val = force_id ? force_id : superio_inb(sioaddr, SIOREG_DEVID);
67 --
68 2.20.1
69