Skip to contentSkip to conversation

i2c: piix4: Request the SMBUS semaphore inside the mutex

PATCH Applied Ricardo Ribalda Delgado 3 participants 6 messages Feb 2, 2017 – Feb 9, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: piix4: Request the SMBUS semaphore inside the mutex

SMBSLVCNT must be protected with the piix4_mutex_sb800 in order to avoid multiple buses accessing to the semaphore at the same time.

---
 drivers/i2c/busses/i2c-piix4.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-piix4.c +7 -5
index 73cc6799cc59..c21ca7bf2efe 100644
@@ -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 {
@@ -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);
@@ -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;
 }
 
Signature · 1 line
2.11.0
#1 lore raw

Hi Ricardo,

Quoted 40 lines · Ricardo Ribalda Delgado

SMBSLVCNT must be protected with the piix4_mutex_sb800 in order to avoid multiple buses accessing to the semaphore at the same time.

---
 drivers/i2c/busses/i2c-piix4.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-piix4.c +5 -3
index 73cc6799cc59..c21ca7bf2efe 100644
@@ -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 {
@@ -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);
@@ -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);
 

drivers/i2c/busses/i2c-piix4.c static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr, · line 635

Quoted 10 lines
drivers/i2c/busses/i2c-piix4.c +2 -2
-	mutex_unlock(&piix4_mutex_sb800);
-
 	/* Release the semaphore */
 	outb_p(smbslvcnt | 0x20, SMBSLVCNT);
 
+	mutex_unlock(&piix4_mutex_sb800);
+
 	return retval;
 }
 

Thanks for the quick fix.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
#3 lore raw

Hi Wolfram,

Quoted 5 lines · Wolfram Sang
Quoted 3 lines

Thanks for the quick fix.

I wonder: why do you use Signed-off instead of Reviewed-by recently?

I use Signed-off-by for drivers I maintain, and Reviewed-by for the rest.

But I can use whatever you prefer if that's a problem, I don't really care.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
#4 lore raw
Quoted 3 lines

I use Signed-off-by for drivers I maintain, and Reviewed-by for the rest.

I see. I never noticed so far :)

Quoted 2 lines

But I can use whatever you prefer if that's a problem, I don't really care.

Patchwork collects Rev-by tags from threads and shows the number of tags in a list. This is helpful for me because I want to process already reviewed patches earlier.

So, Rev-by would in deed be much appreciated for a better workflow.

Thanks!