Skip to contentSkip to conversation

iio:accel:kxsd9 fix missing mutex unlock

PATCH Superseded Jonathan Cameron 2 participants 3 messages Nov 13, 2013 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

PATCH 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.

---
I have reworked this from a patch sent to me by Frank and put it into the correct format.

Frank, do you mind me adding your sign off on this. It's shorter than your patch, but the effect is the same. This approach of unlocking before checking a return value is a common kernel idiom.

Jonathan

 drivers/iio/accel/kxsd9.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/accel/kxsd9.c +1 -0
index d72118d1189c..12df91986dd2 100644
@@ -112,6 +112,7 @@ 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));
+	mutex_unlock(&st->buf_lock);
 	if (ret)
 		return ret;
 	return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 25 lines · Jonathan Cameron

From: Frank Zago <[email protected]>

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

---
I have reworked this from a patch sent to me by Frank and put it into the correct format.

Frank, do you mind me adding your sign off on this. It's shorter than your patch, but the effect is the same. This approach of unlocking before checking a return value is a common kernel idiom.

Jonathan

  drivers/iio/accel/kxsd9.c | 1 +
  1 file changed, 1 insertion(+)
drivers/iio/accel/kxsd9.c +0 -0
index d72118d1189c..12df91986dd2 100644

drivers/iio/accel/kxsd9.c static int kxsd9_read(struct iio_dev *indio_dev, u8 address) · line 118

Quoted 7 lines
drivers/iio/accel/kxsd9.c +1 -0
@@ -112,6 +112,7 @@ 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));
+	mutex_unlock(&st->buf_lock);
  	if (ret)
  		return ret;
  	return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);

I think you'll need to hold the lock until you've actually read the data from the buffer.

- Lars

author maintainer
#2 lore raw
Quoted 21 lines · Lars-Peter Clausen
Quoted 20 lines · Jonathan Cameron

From: Frank Zago <[email protected]>

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

---
I have reworked this from a patch sent to me by Frank and put it into the correct format.

Frank, do you mind me adding your sign off on this. It's shorter than your patch, but the effect is the same. This approach of unlocking before checking a return value is a common kernel idiom.

Jonathan

  drivers/iio/accel/kxsd9.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 14 lines

drivers/iio/accel/kxsd9.c static int kxsd9_read(struct iio_dev *indio_dev, u8 address) · line 118

Quoted 12 lines
drivers/iio/accel/kxsd9.c +1 -0
index d72118d1189c..12df91986dd2 100644
@@ -112,6 +112,7 @@ 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));
+    mutex_unlock(&st->buf_lock);
      if (ret)
          return ret;
      return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);

I think you'll need to hold the lock until you've actually read the data from the buffer.

Good point, I wasn't thinking through what it was actually for. Frank was in fact much more correct. I'll post his version in a sec.

Quoted 7 lines

- Lars

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html