]>
Commit | Line | Data |
---|---|---|
1143c684 SL |
1 | From 8c20e729f900e90d3b7bfbbb6d585e6e792a11b5 Mon Sep 17 00:00:00 2001 |
2 | From: Guenter Roeck <linux@roeck-us.net> | |
3 | Date: Thu, 4 Apr 2019 10:52:43 -0700 | |
4 | Subject: hwmon: (f71805f) Use request_muxed_region for Super-IO accesses | |
5 | ||
6 | [ Upstream commit 73e6ff71a7ea924fb7121d576a2d41e3be3fc6b5 ] | |
7 | ||
8 | Super-IO accesses may fail on a system with no or unmapped LPC bus. | |
9 | ||
10 | Unable to handle kernel paging request at virtual address ffffffbffee0002e | |
11 | pgd = ffffffc1d68d4000 | |
12 | [ffffffbffee0002e] *pgd=0000000000000000, *pud=0000000000000000 | |
13 | Internal error: Oops: 94000046 [#1] PREEMPT SMP | |
14 | Modules linked in: f71805f(+) hwmon | |
15 | CPU: 3 PID: 1659 Comm: insmod Not tainted 4.5.0+ #88 | |
16 | Hardware name: linux,dummy-virt (DT) | |
17 | task: ffffffc1f6665400 ti: ffffffc1d6418000 task.ti: ffffffc1d6418000 | |
18 | PC is at f71805f_find+0x6c/0x358 [f71805f] | |
19 | ||
20 | Also, other drivers may attempt to access the LPC bus at the same time, | |
21 | resulting in undefined behavior. | |
22 | ||
23 | Use request_muxed_region() to ensure that IO access on the requested | |
24 | address space is supported, and to ensure that access by multiple | |
25 | drivers is synchronized. | |
26 | ||
27 | Fixes: e53004e20a58e ("hwmon: New f71805f driver") | |
28 | Reported-by: Kefeng Wang <wangkefeng.wang@huawei.com> | |
29 | Reported-by: John Garry <john.garry@huawei.com> | |
30 | Cc: John Garry <john.garry@huawei.com> | |
31 | Acked-by: John Garry <john.garry@huawei.com> | |
32 | Signed-off-by: Guenter Roeck <linux@roeck-us.net> | |
33 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
34 | --- | |
35 | drivers/hwmon/f71805f.c | 15 ++++++++++++--- | |
36 | 1 file changed, 12 insertions(+), 3 deletions(-) | |
37 | ||
38 | diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c | |
39 | index facd05cda26da..e8c0898864277 100644 | |
40 | --- a/drivers/hwmon/f71805f.c | |
41 | +++ b/drivers/hwmon/f71805f.c | |
42 | @@ -96,17 +96,23 @@ superio_select(int base, int ld) | |
43 | outb(ld, base + 1); | |
44 | } | |
45 | ||
46 | -static inline void | |
47 | +static inline int | |
48 | superio_enter(int base) | |
49 | { | |
50 | + if (!request_muxed_region(base, 2, DRVNAME)) | |
51 | + return -EBUSY; | |
52 | + | |
53 | outb(0x87, base); | |
54 | outb(0x87, base); | |
55 | + | |
56 | + return 0; | |
57 | } | |
58 | ||
59 | static inline void | |
60 | superio_exit(int base) | |
61 | { | |
62 | outb(0xaa, base); | |
63 | + release_region(base, 2); | |
64 | } | |
65 | ||
66 | /* | |
67 | @@ -1561,7 +1567,7 @@ static int __init f71805f_device_add(unsigned short address, | |
68 | static int __init f71805f_find(int sioaddr, unsigned short *address, | |
69 | struct f71805f_sio_data *sio_data) | |
70 | { | |
71 | - int err = -ENODEV; | |
72 | + int err; | |
73 | u16 devid; | |
74 | ||
75 | static const char * const names[] = { | |
76 | @@ -1569,8 +1575,11 @@ static int __init f71805f_find(int sioaddr, unsigned short *address, | |
77 | "F71872F/FG or F71806F/FG", | |
78 | }; | |
79 | ||
80 | - superio_enter(sioaddr); | |
81 | + err = superio_enter(sioaddr); | |
82 | + if (err) | |
83 | + return err; | |
84 | ||
85 | + err = -ENODEV; | |
86 | devid = superio_inw(sioaddr, SIO_REG_MANID); | |
87 | if (devid != SIO_FINTEK_ID) | |
88 | goto exit; | |
89 | -- | |
90 | 2.20.1 | |
91 |