Commit 73dad3ec authored by Jonathan Cameron's avatar Jonathan Cameron
Browse files

iio: dummy: Stop using iio_device_claim_direct_scoped()



This complex cleanup.h use case of conditional guards has proved
to be more trouble that it is worth in terms of false positive compiler
warnings and hard to read code.

Move directly to the new claim/release_direct() that allow sparse
to check for unbalanced context. Introduce two new utility functions
to allow for direct returns with claim and release of direct mode
in the caller.

Reviewed-by: default avatarDavid Lechner <dlechner@baylibre.com>
Reviewed-by: default avatarNuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20250209180624.701140-25-jic23@kernel.org


Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 41a316c8
Loading
Loading
Loading
Loading
+70 −49
Original line number Diff line number Diff line
@@ -267,26 +267,12 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
	},
};

/**
 * iio_dummy_read_raw() - data read function.
 * @indio_dev:	the struct iio_dev associated with this device instance
 * @chan:	the channel whose data is to be read
 * @val:	first element of returned value (typically INT)
 * @val2:	second element of returned value (typically MICRO)
 * @mask:	what we actually want to read as per the info_mask_*
 *		in iio_chan_spec.
 */
static int iio_dummy_read_raw(struct iio_dev *indio_dev,
static int __iio_dummy_read_raw(struct iio_dev *indio_dev,
				struct iio_chan_spec const *chan,
			      int *val,
			      int *val2,
			      long mask)
				int *val)
{
	struct iio_dummy_state *st = iio_priv(indio_dev);

	switch (mask) {
	case IIO_CHAN_INFO_RAW: /* magic value - channel value read */
		iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
	guard(mutex)(&st->lock);
	switch (chan->type) {
	case IIO_VOLTAGE:
@@ -312,9 +298,13 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
		return -EINVAL;
	}
}
		unreachable();
	case IIO_CHAN_INFO_PROCESSED:
		iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {

static int __iio_dummy_read_processed(struct iio_dev *indio_dev,
				      struct iio_chan_spec const *chan,
				      int *val)
{
	struct iio_dummy_state *st = iio_priv(indio_dev);

	guard(mutex)(&st->lock);
	switch (chan->type) {
	case IIO_STEPS:
@@ -335,7 +325,38 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
		return -EINVAL;
	}
}
		unreachable();

/**
 * iio_dummy_read_raw() - data read function.
 * @indio_dev:	the struct iio_dev associated with this device instance
 * @chan:	the channel whose data is to be read
 * @val:	first element of returned value (typically INT)
 * @val2:	second element of returned value (typically MICRO)
 * @mask:	what we actually want to read as per the info_mask_*
 *		in iio_chan_spec.
 */
static int iio_dummy_read_raw(struct iio_dev *indio_dev,
			      struct iio_chan_spec const *chan,
			      int *val,
			      int *val2,
			      long mask)
{
	struct iio_dummy_state *st = iio_priv(indio_dev);
	int ret;

	switch (mask) {
	case IIO_CHAN_INFO_RAW: /* magic value - channel value read */
		if (!iio_device_claim_direct(indio_dev))
			return -EBUSY;
		ret = __iio_dummy_read_raw(indio_dev, chan, val);
		iio_device_release_direct(indio_dev);
		return ret;
	case IIO_CHAN_INFO_PROCESSED:
		if (!iio_device_claim_direct(indio_dev))
			return -EBUSY;
		ret = __iio_dummy_read_processed(indio_dev, chan, val);
		iio_device_release_direct(indio_dev);
		return ret;
	case IIO_CHAN_INFO_OFFSET:
		/* only single ended adc -> 7 */
		*val = 7;