Skip to content

Commit 53d22d8

Browse files
committed
Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/staging
* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/staging: hwmon: f71882fg: use a muxed resource lock for the Super I/O port
2 parents 5a4bbd0 + cadb865 commit 53d22d8

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

drivers/hwmon/f71882fg.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static struct platform_device *f71882fg_pdev;
111111
/* Super-I/O Function prototypes */
112112
static inline int superio_inb(int base, int reg);
113113
static inline int superio_inw(int base, int reg);
114-
static inline void superio_enter(int base);
114+
static inline int superio_enter(int base);
115115
static inline void superio_select(int base, int ld);
116116
static inline void superio_exit(int base);
117117

@@ -861,11 +861,20 @@ static int superio_inw(int base, int reg)
861861
return val;
862862
}
863863

864-
static inline void superio_enter(int base)
864+
static inline int superio_enter(int base)
865865
{
866+
/* Don't step on other drivers' I/O space by accident */
867+
if (!request_muxed_region(base, 2, DRVNAME)) {
868+
printk(KERN_ERR DRVNAME ": I/O address 0x%04x already in use\n",
869+
base);
870+
return -EBUSY;
871+
}
872+
866873
/* according to the datasheet the key must be send twice! */
867874
outb(SIO_UNLOCK_KEY, base);
868875
outb(SIO_UNLOCK_KEY, base);
876+
877+
return 0;
869878
}
870879

871880
static inline void superio_select(int base, int ld)
@@ -877,6 +886,7 @@ static inline void superio_select(int base, int ld)
877886
static inline void superio_exit(int base)
878887
{
879888
outb(SIO_LOCK_KEY, base);
889+
release_region(base, 2);
880890
}
881891

882892
static inline int fan_from_reg(u16 reg)
@@ -2175,21 +2185,15 @@ static int f71882fg_remove(struct platform_device *pdev)
21752185
static int __init f71882fg_find(int sioaddr, unsigned short *address,
21762186
struct f71882fg_sio_data *sio_data)
21772187
{
2178-
int err = -ENODEV;
21792188
u16 devid;
2180-
2181-
/* Don't step on other drivers' I/O space by accident */
2182-
if (!request_region(sioaddr, 2, DRVNAME)) {
2183-
printk(KERN_ERR DRVNAME ": I/O address 0x%04x already in use\n",
2184-
(int)sioaddr);
2185-
return -EBUSY;
2186-
}
2187-
2188-
superio_enter(sioaddr);
2189+
int err = superio_enter(sioaddr);
2190+
if (err)
2191+
return err;
21892192

21902193
devid = superio_inw(sioaddr, SIO_REG_MANID);
21912194
if (devid != SIO_FINTEK_ID) {
21922195
pr_debug(DRVNAME ": Not a Fintek device\n");
2196+
err = -ENODEV;
21932197
goto exit;
21942198
}
21952199

@@ -2213,6 +2217,7 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
22132217
default:
22142218
printk(KERN_INFO DRVNAME ": Unsupported Fintek device: %04x\n",
22152219
(unsigned int)devid);
2220+
err = -ENODEV;
22162221
goto exit;
22172222
}
22182223

@@ -2223,12 +2228,14 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
22232228

22242229
if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
22252230
printk(KERN_WARNING DRVNAME ": Device not activated\n");
2231+
err = -ENODEV;
22262232
goto exit;
22272233
}
22282234

22292235
*address = superio_inw(sioaddr, SIO_REG_ADDR);
22302236
if (*address == 0) {
22312237
printk(KERN_WARNING DRVNAME ": Base address not set\n");
2238+
err = -ENODEV;
22322239
goto exit;
22332240
}
22342241
*address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
@@ -2239,7 +2246,6 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
22392246
(int)superio_inb(sioaddr, SIO_REG_DEVREV));
22402247
exit:
22412248
superio_exit(sioaddr);
2242-
release_region(sioaddr, 2);
22432249
return err;
22442250
}
22452251

0 commit comments

Comments
 (0)