Commit 17395ce2 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron
Browse files

iio: make use of devm_iio_kfifo_buffer_setup() helper



All drivers that already call devm_iio_kfifo_allocate() &
iio_device_attach_buffer() are simple to convert to
iio_device_attach_kfifo_buffer() in a single go.

This change does that; the unwind order is preserved.
What is important, is that the devm_iio_kfifo_buffer_setup() be called
after the indio_dev->modes is assigned, to make sure that
INDIO_BUFFER_SOFTWARE flag is set and not overridden by the assignment to
indio_dev->modes.

Also, the INDIO_BUFFER_SOFTWARE has been removed from the assignments of
'indio_dev->modes' because it is set by devm_iio_kfifo_buffer_setup().

Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Reviewed-by: default avatarGwendal Grignou <gwendal@chromium.org>
Reviewed-by: default avatarMatt Ranostay <matt.ranostay@konsulko.com&gt;x>
Link: https://lore.kernel.org/r/20210215104043.91251-4-alexandru.ardelean@analog.com


Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent e36db6a0
Loading
Loading
Loading
Loading
+5 −9
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ static int ssp_accel_probe(struct platform_device *pdev)
	int ret;
	struct iio_dev *indio_dev;
	struct ssp_sensor_data *spd;
	struct iio_buffer *buffer;

	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*spd));
	if (!indio_dev)
@@ -109,18 +108,15 @@ static int ssp_accel_probe(struct platform_device *pdev)

	indio_dev->name = ssp_accel_device_name;
	indio_dev->info = &ssp_accel_iio_info;
	indio_dev->modes = INDIO_BUFFER_SOFTWARE;
	indio_dev->channels = ssp_acc_channels;
	indio_dev->num_channels = ARRAY_SIZE(ssp_acc_channels);
	indio_dev->available_scan_masks = ssp_accel_scan_mask;

	buffer = devm_iio_kfifo_allocate(&pdev->dev);
	if (!buffer)
		return -ENOMEM;

	iio_device_attach_buffer(indio_dev, buffer);

	indio_dev->setup_ops = &ssp_accel_buffer_ops;
	ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
					  INDIO_BUFFER_SOFTWARE,
					  &ssp_accel_buffer_ops);
	if (ret)
		return ret;

	platform_set_drvdata(pdev, indio_dev);

+6 −8
Original line number Diff line number Diff line
@@ -953,7 +953,6 @@ static int ina2xx_probe(struct i2c_client *client,
{
	struct ina2xx_chip_info *chip;
	struct iio_dev *indio_dev;
	struct iio_buffer *buffer;
	unsigned int val;
	enum ina2xx_ids type;
	int ret;
@@ -1017,7 +1016,7 @@ static int ina2xx_probe(struct i2c_client *client,
		return ret;
	}

	indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
	indio_dev->modes = INDIO_DIRECT_MODE;
	if (id->driver_data == ina226) {
		indio_dev->channels = ina226_channels;
		indio_dev->num_channels = ARRAY_SIZE(ina226_channels);
@@ -1028,13 +1027,12 @@ static int ina2xx_probe(struct i2c_client *client,
		indio_dev->info = &ina219_info;
	}
	indio_dev->name = id->name;
	indio_dev->setup_ops = &ina2xx_setup_ops;

	buffer = devm_iio_kfifo_allocate(&indio_dev->dev);
	if (!buffer)
		return -ENOMEM;

	iio_device_attach_buffer(indio_dev, buffer);
	ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
					  INDIO_BUFFER_SOFTWARE,
					  &ina2xx_setup_ops);
	if (ret)
		return ret;

	return iio_device_register(indio_dev);
}
+5 −13
Original line number Diff line number Diff line
@@ -385,24 +385,16 @@ static int tiadc_iio_buffered_hardware_setup(struct device *dev,
	unsigned long flags,
	const struct iio_buffer_setup_ops *setup_ops)
{
	struct iio_buffer *buffer;
	int ret;

	buffer = devm_iio_kfifo_allocate(dev);
	if (!buffer)
		return -ENOMEM;

	iio_device_attach_buffer(indio_dev, buffer);

	ret = devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
				flags, indio_dev->name, indio_dev);
	ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
					  INDIO_BUFFER_SOFTWARE,
					  setup_ops);
	if (ret)
		return ret;

	indio_dev->setup_ops = setup_ops;
	indio_dev->modes |= INDIO_BUFFER_SOFTWARE;

	return 0;
	return devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
				flags, indio_dev->name, indio_dev);
}

static const char * const chan_name_ain[] = {
+5 −8
Original line number Diff line number Diff line
@@ -334,14 +334,11 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
			 * We can not use trigger here, as events are generated
			 * as soon as sample_frequency is set.
			 */
			struct iio_buffer *buffer;

			buffer = devm_iio_kfifo_allocate(dev);
			if (!buffer)
				return -ENOMEM;

			iio_device_attach_buffer(indio_dev, buffer);
			indio_dev->modes = INDIO_BUFFER_SOFTWARE;
			ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
							  INDIO_BUFFER_SOFTWARE,
							  NULL);
			if (ret)
				return ret;

			ret = cros_ec_sensorhub_register_push_data(
					sensor_hub, sensor_platform->sensor_num,
+5 −9
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ static int ssp_gyro_probe(struct platform_device *pdev)
	int ret;
	struct iio_dev *indio_dev;
	struct ssp_sensor_data *spd;
	struct iio_buffer *buffer;

	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*spd));
	if (!indio_dev)
@@ -109,18 +108,15 @@ static int ssp_gyro_probe(struct platform_device *pdev)

	indio_dev->name = ssp_gyro_name;
	indio_dev->info = &ssp_gyro_iio_info;
	indio_dev->modes = INDIO_BUFFER_SOFTWARE;
	indio_dev->channels = ssp_gyro_channels;
	indio_dev->num_channels = ARRAY_SIZE(ssp_gyro_channels);
	indio_dev->available_scan_masks = ssp_gyro_scan_mask;

	buffer = devm_iio_kfifo_allocate(&pdev->dev);
	if (!buffer)
		return -ENOMEM;

	iio_device_attach_buffer(indio_dev, buffer);

	indio_dev->setup_ops = &ssp_gyro_buffer_ops;
	ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
					  INDIO_BUFFER_SOFTWARE,
					  &ssp_gyro_buffer_ops);
	if (ret)
		return ret;

	platform_set_drvdata(pdev, indio_dev);

Loading