Skip to contentSkip to conversation

iio:accel:kxsd9 fix missing mutex unlock

PATCH In review Jonathan Cameron 2 participants 3 messages Nov 13, 2013 – Nov 17, 2013 IIO

lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

PATCH v2 1/1 iio:accel:kxsd9 fix missing mutex unlock

From: Frank Zago <[email protected]>

This will leave a lock held after reading from the device, preventing any further reads.

---

This is Frank's original patch. As Lars-Peter pointed out, I really didn't think my way through my shortened (and incorrect version).

Oops!

Frank, just to check, are you fine signing off on this?

 drivers/iio/accel/kxsd9.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iio/accel/kxsd9.c +4 -3
index d72118d1189c..98ba761cbb9c 100644
@@ -112,9 +112,10 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
 	mutex_lock(&st->buf_lock);
 	st->tx[0] = KXSD9_READ(address);
 	ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
-	if (ret)
-		return ret;
-	return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
+	if (!ret)
+		ret = (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
+	mutex_unlock(&st->buf_lock);
+	return ret;
 }
 
 static IIO_CONST_ATTR(accel_scale_available,
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 7 lines · Jonathan Cameron

From: Frank Zago <[email protected]>

This will leave a lock held after reading from the device, preventing any further reads.

Quoted 8 lines

---

This is Frank's original patch. As Lars-Peter pointed out, I really didn't think my way through my shortened (and incorrect version).

Oops!

Frank, just to check, are you fine signing off on this?

Yes. It's good.

Frank.

Quoted 23 lines
 drivers/iio/accel/kxsd9.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iio/accel/kxsd9.c +4 -3
index d72118d1189c..98ba761cbb9c 100644
@@ -112,9 +112,10 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
 	mutex_lock(&st->buf_lock);
 	st->tx[0] = KXSD9_READ(address);
 	ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
-	if (ret)
-		return ret;
-	return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
+	if (!ret)
+		ret = (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
+	mutex_unlock(&st->buf_lock);
+	return ret;
 }
 
 static IIO_CONST_ATTR(accel_scale_available,
author maintainer Applied
#2 lore raw
Quoted 10 lines · Frank Zago
Quoted 9 lines · Jonathan Cameron

From: Frank Zago <[email protected]>

This will leave a lock held after reading from the device, preventing any further reads.

---

Quoted 9 lines
Quoted 6 lines

This is Frank's original patch. As Lars-Peter pointed out, I really didn't think my way through my shortened (and incorrect version).

Oops!

Frank, just to check, are you fine signing off on this?

Yes. It's good.

Applied to the fixes-togreg branch of iio.git
Also marked this as for stable.

Thanks,

Quoted 26 lines

Frank.

Quoted 23 lines
 drivers/iio/accel/kxsd9.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iio/accel/kxsd9.c +4 -3
index d72118d1189c..98ba761cbb9c 100644
@@ -112,9 +112,10 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
 	mutex_lock(&st->buf_lock);
 	st->tx[0] = KXSD9_READ(address);
 	ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
-	if (ret)
-		return ret;
-	return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
+	if (!ret)
+		ret = (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
+	mutex_unlock(&st->buf_lock);
+	return ret;
 }
 
 static IIO_CONST_ATTR(accel_scale_available,