i2c: designware-baytrail: Fix race when resetting the semaphore
diff mbox

Message ID 20170101113022.6791-2-hdegoede@redhat.com
State Superseded
Headers show

Commit Message

Hans de Goede Jan. 1, 2017, 11:30 a.m. UTC
Use iosf_mbi_modify instead of iosf_mbi_read + iosf_mbi_write so that
we keep the iosf_mbi_lock locked during the read-modify-write done to
reset the semaphore.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/i2c/busses/i2c-designware-baytrail.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Patch
diff mbox

diff --git a/drivers/i2c/busses/i2c-designware-baytrail.c b/drivers/i2c/busses/i2c-designware-baytrail.c
index 9481411..9634544 100644
--- a/drivers/i2c/busses/i2c-designware-baytrail.c
+++ b/drivers/i2c/busses/i2c-designware-baytrail.c
@@ -64,18 +64,16 @@  static int get_sem(struct dw_i2c_dev *dev, u32 *sem)
 
 static void reset_semaphore(struct dw_i2c_dev *dev)
 {
-	u32 addr = get_sem_addr(dev);
-	u32 data;
+	int ret;
 
-	if (iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, addr, &data)) {
-		dev_err(dev->dev, "iosf failed to reset punit semaphore during read\n");
+	ret = iosf_mbi_modify(BT_MBI_UNIT_PMC, MBI_REG_READ, get_sem_addr(dev),
+			      0, PUNIT_SEMAPHORE_BIT);
+	if (ret) {
+		dev_err(dev->dev, "iosf failed to reset punit semaphore: %d\n",
+			ret);
 		return;
 	}
 
-	data &= ~PUNIT_SEMAPHORE_BIT;
-	if (iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, addr, data))
-		dev_err(dev->dev, "iosf failed to reset punit semaphore during write\n");
-
 	pm_qos_update_request(&dev->pm_qos, PM_QOS_DEFAULT_VALUE);
 }