Thread (1 message) 1 message, 1 author, 2015-08-02

Re: [PATCH 2/2] iio: proximity: add support for PulsedLight LIDAR

From: Lars-Peter Clausen <hidden>
Date: 2015-08-02 09:45:01
Also in: linux-iio

On 08/01/2015 05:58 AM, Matt Ranostay wrote:
+static int lidar_read_raw(struct iio_dev *indio_dev,
+			  struct iio_chan_spec const *chan,
+			  int *val, int *val2, long mask)
+{
+	struct lidar_data *data = iio_priv(indio_dev);
+	int ret = -EINVAL;
+
+	if (iio_buffer_enabled(indio_dev) && mask == IIO_CHAN_INFO_RAW)
+		return -EBUSY;
For this to work without race conditions you need to hold the
indio_dev->mlock while doing the check and until the conversion is done.
+
+	mutex_lock(&data->lock);
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW: {
+		u16 reg;
+
+		ret = lidar_get_measurement(data, &reg);
+		if (!ret) {
+			*val = reg / 100;
+			*val2 = (reg % 100) * 10000;
+			ret = IIO_VAL_INT_PLUS_MICRO;
+		}
+		break;
+	}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help