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: Alexandru Ardelean <alexandru.ardelean@analog.com>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Matt Ranostay <matt.ranostay@konsulko.com>x
Link: https://lore.kernel.org/r/20210215104043.91251-4-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Alexandru Ardelean 2021-02-15 12:40:22 +02:00 committed by Jonathan Cameron
parent e36db6a069
commit 17395ce299
13 changed files with 74 additions and 124 deletions

View File

@ -96,7 +96,6 @@ static int ssp_accel_probe(struct platform_device *pdev)
int ret; int ret;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct ssp_sensor_data *spd; struct ssp_sensor_data *spd;
struct iio_buffer *buffer;
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*spd)); indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*spd));
if (!indio_dev) 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->name = ssp_accel_device_name;
indio_dev->info = &ssp_accel_iio_info; indio_dev->info = &ssp_accel_iio_info;
indio_dev->modes = INDIO_BUFFER_SOFTWARE;
indio_dev->channels = ssp_acc_channels; indio_dev->channels = ssp_acc_channels;
indio_dev->num_channels = ARRAY_SIZE(ssp_acc_channels); indio_dev->num_channels = ARRAY_SIZE(ssp_acc_channels);
indio_dev->available_scan_masks = ssp_accel_scan_mask; indio_dev->available_scan_masks = ssp_accel_scan_mask;
buffer = devm_iio_kfifo_allocate(&pdev->dev); ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
if (!buffer) INDIO_BUFFER_SOFTWARE,
return -ENOMEM; &ssp_accel_buffer_ops);
if (ret)
iio_device_attach_buffer(indio_dev, buffer); return ret;
indio_dev->setup_ops = &ssp_accel_buffer_ops;
platform_set_drvdata(pdev, indio_dev); platform_set_drvdata(pdev, indio_dev);

View File

@ -953,7 +953,6 @@ static int ina2xx_probe(struct i2c_client *client,
{ {
struct ina2xx_chip_info *chip; struct ina2xx_chip_info *chip;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct iio_buffer *buffer;
unsigned int val; unsigned int val;
enum ina2xx_ids type; enum ina2xx_ids type;
int ret; int ret;
@ -1017,7 +1016,7 @@ static int ina2xx_probe(struct i2c_client *client,
return ret; return ret;
} }
indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; indio_dev->modes = INDIO_DIRECT_MODE;
if (id->driver_data == ina226) { if (id->driver_data == ina226) {
indio_dev->channels = ina226_channels; indio_dev->channels = ina226_channels;
indio_dev->num_channels = ARRAY_SIZE(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->info = &ina219_info;
} }
indio_dev->name = id->name; indio_dev->name = id->name;
indio_dev->setup_ops = &ina2xx_setup_ops;
buffer = devm_iio_kfifo_allocate(&indio_dev->dev); ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
if (!buffer) INDIO_BUFFER_SOFTWARE,
return -ENOMEM; &ina2xx_setup_ops);
if (ret)
iio_device_attach_buffer(indio_dev, buffer); return ret;
return iio_device_register(indio_dev); return iio_device_register(indio_dev);
} }

View File

@ -385,24 +385,16 @@ static int tiadc_iio_buffered_hardware_setup(struct device *dev,
unsigned long flags, unsigned long flags,
const struct iio_buffer_setup_ops *setup_ops) const struct iio_buffer_setup_ops *setup_ops)
{ {
struct iio_buffer *buffer;
int ret; int ret;
buffer = devm_iio_kfifo_allocate(dev); ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
if (!buffer) INDIO_BUFFER_SOFTWARE,
return -ENOMEM; setup_ops);
iio_device_attach_buffer(indio_dev, buffer);
ret = devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
flags, indio_dev->name, indio_dev);
if (ret) if (ret)
return ret; return ret;
indio_dev->setup_ops = setup_ops; return devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
indio_dev->modes |= INDIO_BUFFER_SOFTWARE; flags, indio_dev->name, indio_dev);
return 0;
} }
static const char * const chan_name_ain[] = { static const char * const chan_name_ain[] = {

View File

@ -334,14 +334,11 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
* We can not use trigger here, as events are generated * We can not use trigger here, as events are generated
* as soon as sample_frequency is set. * as soon as sample_frequency is set.
*/ */
struct iio_buffer *buffer; ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
INDIO_BUFFER_SOFTWARE,
buffer = devm_iio_kfifo_allocate(dev); NULL);
if (!buffer) if (ret)
return -ENOMEM; return ret;
iio_device_attach_buffer(indio_dev, buffer);
indio_dev->modes = INDIO_BUFFER_SOFTWARE;
ret = cros_ec_sensorhub_register_push_data( ret = cros_ec_sensorhub_register_push_data(
sensor_hub, sensor_platform->sensor_num, sensor_hub, sensor_platform->sensor_num,

View File

@ -96,7 +96,6 @@ static int ssp_gyro_probe(struct platform_device *pdev)
int ret; int ret;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct ssp_sensor_data *spd; struct ssp_sensor_data *spd;
struct iio_buffer *buffer;
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*spd)); indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*spd));
if (!indio_dev) if (!indio_dev)
@ -109,18 +108,15 @@ static int ssp_gyro_probe(struct platform_device *pdev)
indio_dev->name = ssp_gyro_name; indio_dev->name = ssp_gyro_name;
indio_dev->info = &ssp_gyro_iio_info; indio_dev->info = &ssp_gyro_iio_info;
indio_dev->modes = INDIO_BUFFER_SOFTWARE;
indio_dev->channels = ssp_gyro_channels; indio_dev->channels = ssp_gyro_channels;
indio_dev->num_channels = ARRAY_SIZE(ssp_gyro_channels); indio_dev->num_channels = ARRAY_SIZE(ssp_gyro_channels);
indio_dev->available_scan_masks = ssp_gyro_scan_mask; indio_dev->available_scan_masks = ssp_gyro_scan_mask;
buffer = devm_iio_kfifo_allocate(&pdev->dev); ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
if (!buffer) INDIO_BUFFER_SOFTWARE,
return -ENOMEM; &ssp_gyro_buffer_ops);
if (ret)
iio_device_attach_buffer(indio_dev, buffer); return ret;
indio_dev->setup_ops = &ssp_gyro_buffer_ops;
platform_set_drvdata(pdev, indio_dev); platform_set_drvdata(pdev, indio_dev);

View File

@ -418,7 +418,6 @@ static int max30100_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct max30100_data *data; struct max30100_data *data;
struct iio_buffer *buffer;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
int ret; int ret;
@ -426,19 +425,18 @@ static int max30100_probe(struct i2c_client *client,
if (!indio_dev) if (!indio_dev)
return -ENOMEM; return -ENOMEM;
buffer = devm_iio_kfifo_allocate(&client->dev);
if (!buffer)
return -ENOMEM;
iio_device_attach_buffer(indio_dev, buffer);
indio_dev->name = MAX30100_DRV_NAME; indio_dev->name = MAX30100_DRV_NAME;
indio_dev->channels = max30100_channels; indio_dev->channels = max30100_channels;
indio_dev->info = &max30100_info; indio_dev->info = &max30100_info;
indio_dev->num_channels = ARRAY_SIZE(max30100_channels); indio_dev->num_channels = ARRAY_SIZE(max30100_channels);
indio_dev->available_scan_masks = max30100_scan_masks; indio_dev->available_scan_masks = max30100_scan_masks;
indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->setup_ops = &max30100_buffer_setup_ops;
ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
INDIO_BUFFER_SOFTWARE,
&max30100_buffer_setup_ops);
if (ret)
return ret;
data = iio_priv(indio_dev); data = iio_priv(indio_dev);
data->indio_dev = indio_dev; data->indio_dev = indio_dev;

View File

@ -506,7 +506,6 @@ static int max30102_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct max30102_data *data; struct max30102_data *data;
struct iio_buffer *buffer;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
int ret; int ret;
unsigned int reg; unsigned int reg;
@ -515,16 +514,9 @@ static int max30102_probe(struct i2c_client *client,
if (!indio_dev) if (!indio_dev)
return -ENOMEM; return -ENOMEM;
buffer = devm_iio_kfifo_allocate(&client->dev);
if (!buffer)
return -ENOMEM;
iio_device_attach_buffer(indio_dev, buffer);
indio_dev->name = MAX30102_DRV_NAME; indio_dev->name = MAX30102_DRV_NAME;
indio_dev->info = &max30102_info; indio_dev->info = &max30102_info;
indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->setup_ops = &max30102_buffer_setup_ops;
data = iio_priv(indio_dev); data = iio_priv(indio_dev);
data->indio_dev = indio_dev; data->indio_dev = indio_dev;
@ -549,6 +541,12 @@ static int max30102_probe(struct i2c_client *client,
return -ENODEV; return -ENODEV;
} }
ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
INDIO_BUFFER_SOFTWARE,
&max30102_buffer_setup_ops);
if (ret)
return ret;
data->regmap = devm_regmap_init_i2c(client, &max30102_regmap_config); data->regmap = devm_regmap_init_i2c(client, &max30102_regmap_config);
if (IS_ERR(data->regmap)) { if (IS_ERR(data->regmap)) {
dev_err(&client->dev, "regmap initialization failed\n"); dev_err(&client->dev, "regmap initialization failed\n");

View File

@ -709,7 +709,6 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st)
const char *name; const char *name;
struct inv_icm42600_timestamp *ts; struct inv_icm42600_timestamp *ts;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct iio_buffer *buffer;
int ret; int ret;
name = devm_kasprintf(dev, GFP_KERNEL, "%s-accel", st->name); name = devm_kasprintf(dev, GFP_KERNEL, "%s-accel", st->name);
@ -720,23 +719,22 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st)
if (!indio_dev) if (!indio_dev)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
buffer = devm_iio_kfifo_allocate(dev);
if (!buffer)
return ERR_PTR(-ENOMEM);
ts = iio_priv(indio_dev); ts = iio_priv(indio_dev);
inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.accel.odr)); inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.accel.odr));
iio_device_set_drvdata(indio_dev, st); iio_device_set_drvdata(indio_dev, st);
indio_dev->name = name; indio_dev->name = name;
indio_dev->info = &inv_icm42600_accel_info; indio_dev->info = &inv_icm42600_accel_info;
indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = inv_icm42600_accel_channels; indio_dev->channels = inv_icm42600_accel_channels;
indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_accel_channels); indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_accel_channels);
indio_dev->available_scan_masks = inv_icm42600_accel_scan_masks; indio_dev->available_scan_masks = inv_icm42600_accel_scan_masks;
indio_dev->setup_ops = &inv_icm42600_buffer_ops;
iio_device_attach_buffer(indio_dev, buffer); ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
INDIO_BUFFER_SOFTWARE,
&inv_icm42600_buffer_ops);
if (ret)
return ERR_PTR(ret);
ret = devm_iio_device_register(dev, indio_dev); ret = devm_iio_device_register(dev, indio_dev);
if (ret) if (ret)

View File

@ -720,7 +720,6 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st)
const char *name; const char *name;
struct inv_icm42600_timestamp *ts; struct inv_icm42600_timestamp *ts;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct iio_buffer *buffer;
int ret; int ret;
name = devm_kasprintf(dev, GFP_KERNEL, "%s-gyro", st->name); name = devm_kasprintf(dev, GFP_KERNEL, "%s-gyro", st->name);
@ -731,23 +730,23 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st)
if (!indio_dev) if (!indio_dev)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
buffer = devm_iio_kfifo_allocate(dev);
if (!buffer)
return ERR_PTR(-ENOMEM);
ts = iio_priv(indio_dev); ts = iio_priv(indio_dev);
inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.gyro.odr)); inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.gyro.odr));
iio_device_set_drvdata(indio_dev, st); iio_device_set_drvdata(indio_dev, st);
indio_dev->name = name; indio_dev->name = name;
indio_dev->info = &inv_icm42600_gyro_info; indio_dev->info = &inv_icm42600_gyro_info;
indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = inv_icm42600_gyro_channels; indio_dev->channels = inv_icm42600_gyro_channels;
indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_gyro_channels); indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_gyro_channels);
indio_dev->available_scan_masks = inv_icm42600_gyro_scan_masks; indio_dev->available_scan_masks = inv_icm42600_gyro_scan_masks;
indio_dev->setup_ops = &inv_icm42600_buffer_ops; indio_dev->setup_ops = &inv_icm42600_buffer_ops;
iio_device_attach_buffer(indio_dev, buffer); ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
INDIO_BUFFER_SOFTWARE,
&inv_icm42600_buffer_ops);
if (ret)
return ERR_PTR(ret);
ret = devm_iio_device_register(dev, indio_dev); ret = devm_iio_device_register(dev, indio_dev);
if (ret) if (ret)

View File

@ -739,20 +739,17 @@ static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = {
int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw) int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
{ {
struct iio_buffer *buffer; int i, ret;
int i;
for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
if (!hw->iio_devs[i]) if (!hw->iio_devs[i])
continue; continue;
buffer = devm_iio_kfifo_allocate(hw->dev); ret = devm_iio_kfifo_buffer_setup(hw->dev, hw->iio_devs[i],
if (!buffer) INDIO_BUFFER_SOFTWARE,
return -ENOMEM; &st_lsm6dsx_buffer_ops);
if (ret)
iio_device_attach_buffer(hw->iio_devs[i], buffer); return ret;
hw->iio_devs[i]->modes |= INDIO_BUFFER_SOFTWARE;
hw->iio_devs[i]->setup_ops = &st_lsm6dsx_buffer_ops;
} }
return 0; return 0;

View File

@ -165,7 +165,7 @@ static int acpi_als_add(struct acpi_device *device)
{ {
struct acpi_als *als; struct acpi_als *als;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct iio_buffer *buffer; int ret;
indio_dev = devm_iio_device_alloc(&device->dev, sizeof(*als)); indio_dev = devm_iio_device_alloc(&device->dev, sizeof(*als));
if (!indio_dev) if (!indio_dev)
@ -179,15 +179,13 @@ static int acpi_als_add(struct acpi_device *device)
indio_dev->name = ACPI_ALS_DEVICE_NAME; indio_dev->name = ACPI_ALS_DEVICE_NAME;
indio_dev->info = &acpi_als_info; indio_dev->info = &acpi_als_info;
indio_dev->modes = INDIO_BUFFER_SOFTWARE;
indio_dev->channels = acpi_als_channels; indio_dev->channels = acpi_als_channels;
indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels); indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels);
buffer = devm_iio_kfifo_allocate(&device->dev); ret = devm_iio_kfifo_buffer_setup(&device->dev, indio_dev,
if (!buffer) INDIO_BUFFER_SOFTWARE, NULL);
return -ENOMEM; if (ret)
return ret;
iio_device_attach_buffer(indio_dev, buffer);
return devm_iio_device_register(&device->dev, indio_dev); return devm_iio_device_register(&device->dev, indio_dev);
} }

View File

@ -988,7 +988,6 @@ static int apds9960_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct apds9960_data *data; struct apds9960_data *data;
struct iio_buffer *buffer;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
int ret; int ret;
@ -996,19 +995,18 @@ static int apds9960_probe(struct i2c_client *client,
if (!indio_dev) if (!indio_dev)
return -ENOMEM; return -ENOMEM;
buffer = devm_iio_kfifo_allocate(&client->dev);
if (!buffer)
return -ENOMEM;
iio_device_attach_buffer(indio_dev, buffer);
indio_dev->info = &apds9960_info; indio_dev->info = &apds9960_info;
indio_dev->name = APDS9960_DRV_NAME; indio_dev->name = APDS9960_DRV_NAME;
indio_dev->channels = apds9960_channels; indio_dev->channels = apds9960_channels;
indio_dev->num_channels = ARRAY_SIZE(apds9960_channels); indio_dev->num_channels = ARRAY_SIZE(apds9960_channels);
indio_dev->available_scan_masks = apds9960_scan_masks; indio_dev->available_scan_masks = apds9960_scan_masks;
indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->setup_ops = &apds9960_buffer_setup_ops;
ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
INDIO_BUFFER_SOFTWARE,
&apds9960_buffer_setup_ops);
if (ret)
return ret;
data = iio_priv(indio_dev); data = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev); i2c_set_clientdata(client, indio_dev);

View File

@ -602,23 +602,6 @@ static const struct iio_buffer_setup_ops ad5933_ring_setup_ops = {
.postdisable = ad5933_ring_postdisable, .postdisable = ad5933_ring_postdisable,
}; };
static int ad5933_register_ring_funcs_and_init(struct device *dev,
struct iio_dev *indio_dev)
{
struct iio_buffer *buffer;
buffer = devm_iio_kfifo_allocate(dev);
if (!buffer)
return -ENOMEM;
iio_device_attach_buffer(indio_dev, buffer);
/* Ring buffer functions - here trigger setup related */
indio_dev->setup_ops = &ad5933_ring_setup_ops;
return 0;
}
static void ad5933_work(struct work_struct *work) static void ad5933_work(struct work_struct *work)
{ {
struct ad5933_state *st = container_of(work, struct ad5933_state *st = container_of(work,
@ -761,11 +744,13 @@ static int ad5933_probe(struct i2c_client *client,
indio_dev->info = &ad5933_info; indio_dev->info = &ad5933_info;
indio_dev->name = id->name; indio_dev->name = id->name;
indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = ad5933_channels; indio_dev->channels = ad5933_channels;
indio_dev->num_channels = ARRAY_SIZE(ad5933_channels); indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
ret = ad5933_register_ring_funcs_and_init(&client->dev, indio_dev); ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
INDIO_BUFFER_SOFTWARE,
&ad5933_ring_setup_ops);
if (ret) if (ret)
return ret; return ret;