Skip to content

Commit

Permalink
i2c: piix4: Request the SMBUS semaphore inside the mutex
Browse files Browse the repository at this point in the history
SMBSLVCNT must be protected with the piix4_mutex_sb800 in order to avoid
multiple buses accessing to the semaphore at the same time.

Fixes: 701dc20 ("i2c: piix4: Avoid race conditions with IMC")
Reported-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
  • Loading branch information
Ricardo Ribalda authored and Wolfram Sang committed Feb 9, 2017
1 parent f43128c commit bbb27fc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/i2c/busses/i2c-piix4.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
u8 port;
int retval;

mutex_lock(&piix4_mutex_sb800);

/* Request the SMBUS semaphore, avoid conflicts with the IMC */
smbslvcnt = inb_p(SMBSLVCNT);
do {
Expand All @@ -605,10 +607,10 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
usleep_range(1000, 2000);
} while (--retries);
/* SMBus is still owned by the IMC, we give up */
if (!retries)
if (!retries) {
mutex_unlock(&piix4_mutex_sb800);
return -EBUSY;

mutex_lock(&piix4_mutex_sb800);
}

outb_p(piix4_port_sel_sb800, SB800_PIIX4_SMB_IDX);
smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1);
Expand All @@ -623,11 +625,11 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,

outb_p(smba_en_lo, SB800_PIIX4_SMB_IDX + 1);

mutex_unlock(&piix4_mutex_sb800);

/* Release the semaphore */
outb_p(smbslvcnt | 0x20, SMBSLVCNT);

mutex_unlock(&piix4_mutex_sb800);

return retval;
}

Expand Down

0 comments on commit bbb27fc

Please sign in to comment.