Skip to content

Commit

Permalink
iio: st_sensors: remove st_sensors_deallocate_trigger() function
Browse files Browse the repository at this point in the history
This change converts the st_sensors_allocate_trigger() to use
device-managed functions.

The parent device of the IIO device object is used. This is based on the
assumption that all other devm_ calls in the ST sensors use this reference.

That makes the st_sensors_deallocate_trigger() function un-needed, so it
can be removed.

Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Alexandru Ardelean <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
commodo authored and jic23 committed Sep 14, 2021
1 parent 9f0b3e0 commit 82bcb7f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 103 deletions.
18 changes: 1 addition & 17 deletions drivers/iio/accel/st_accel_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,29 +1380,13 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
return err;
}

err = iio_device_register(indio_dev);
if (err)
goto st_accel_device_register_error;

dev_info(&indio_dev->dev, "registered accelerometer %s\n",
indio_dev->name);

return 0;

st_accel_device_register_error:
if (adata->irq > 0)
st_sensors_deallocate_trigger(indio_dev);
return err;
return iio_device_register(indio_dev);
}
EXPORT_SYMBOL(st_accel_common_probe);

void st_accel_common_remove(struct iio_dev *indio_dev)
{
struct st_sensor_data *adata = iio_priv(indio_dev);

iio_device_unregister(indio_dev);
if (adata->irq > 0)
st_sensors_deallocate_trigger(indio_dev);
}
EXPORT_SYMBOL(st_accel_common_remove);

Expand Down
45 changes: 15 additions & 30 deletions drivers/iio/common/st_sensors/st_sensors_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
const struct iio_trigger_ops *trigger_ops)
{
struct st_sensor_data *sdata = iio_priv(indio_dev);
struct device *parent = indio_dev->dev.parent;
unsigned long irq_trig;
int err;

sdata->trig = iio_trigger_alloc(sdata->dev, "%s-trigger",
indio_dev->name);
sdata->trig = devm_iio_trigger_alloc(parent, "%s-trigger",
indio_dev->name);
if (sdata->trig == NULL) {
dev_err(&indio_dev->dev, "failed to allocate iio trigger.\n");
return -ENOMEM;
Expand Down Expand Up @@ -153,7 +154,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
sdata->sensor_settings->drdy_irq.addr_ihl,
sdata->sensor_settings->drdy_irq.mask_ihl, 1);
if (err < 0)
goto iio_trigger_free;
return err;
dev_info(&indio_dev->dev,
"interrupts on the falling edge or active low level\n");
}
Expand All @@ -179,8 +180,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr) {
dev_err(&indio_dev->dev,
"edge IRQ not supported w/o stat register.\n");
err = -EOPNOTSUPP;
goto iio_trigger_free;
return -EOPNOTSUPP;
}
sdata->edge_irq = true;
} else {
Expand All @@ -205,44 +205,29 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
sdata->sensor_settings->drdy_irq.stat_drdy.addr)
irq_trig |= IRQF_SHARED;

err = request_threaded_irq(sdata->irq,
st_sensors_irq_handler,
st_sensors_irq_thread,
irq_trig,
sdata->trig->name,
sdata->trig);
err = devm_request_threaded_irq(parent,
sdata->irq,
st_sensors_irq_handler,
st_sensors_irq_thread,
irq_trig,
sdata->trig->name,
sdata->trig);
if (err) {
dev_err(&indio_dev->dev, "failed to request trigger IRQ.\n");
goto iio_trigger_free;
return err;
}

err = iio_trigger_register(sdata->trig);
err = devm_iio_trigger_register(parent, sdata->trig);
if (err < 0) {
dev_err(&indio_dev->dev, "failed to register iio trigger.\n");
goto iio_trigger_register_error;
return err;
}
indio_dev->trig = iio_trigger_get(sdata->trig);

return 0;

iio_trigger_register_error:
free_irq(sdata->irq, sdata->trig);
iio_trigger_free:
iio_trigger_free(sdata->trig);
return err;
}
EXPORT_SYMBOL(st_sensors_allocate_trigger);

void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
{
struct st_sensor_data *sdata = iio_priv(indio_dev);

iio_trigger_unregister(sdata->trig);
free_irq(sdata->irq, sdata->trig);
iio_trigger_free(sdata->trig);
}
EXPORT_SYMBOL(st_sensors_deallocate_trigger);

int st_sensors_validate_device(struct iio_trigger *trig,
struct iio_dev *indio_dev)
{
Expand Down
18 changes: 1 addition & 17 deletions drivers/iio/gyro/st_gyro_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,29 +515,13 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
return err;
}

err = iio_device_register(indio_dev);
if (err)
goto st_gyro_device_register_error;

dev_info(&indio_dev->dev, "registered gyroscope %s\n",
indio_dev->name);

return 0;

st_gyro_device_register_error:
if (gdata->irq > 0)
st_sensors_deallocate_trigger(indio_dev);
return err;
return iio_device_register(indio_dev);
}
EXPORT_SYMBOL(st_gyro_common_probe);

void st_gyro_common_remove(struct iio_dev *indio_dev)
{
struct st_sensor_data *gdata = iio_priv(indio_dev);

iio_device_unregister(indio_dev);
if (gdata->irq > 0)
st_sensors_deallocate_trigger(indio_dev);
}
EXPORT_SYMBOL(st_gyro_common_remove);

Expand Down
18 changes: 1 addition & 17 deletions drivers/iio/magnetometer/st_magn_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,29 +650,13 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
return err;
}

err = iio_device_register(indio_dev);
if (err)
goto st_magn_device_register_error;

dev_info(&indio_dev->dev, "registered magnetometer %s\n",
indio_dev->name);

return 0;

st_magn_device_register_error:
if (mdata->irq > 0)
st_sensors_deallocate_trigger(indio_dev);
return err;
return iio_device_register(indio_dev);
}
EXPORT_SYMBOL(st_magn_common_probe);

void st_magn_common_remove(struct iio_dev *indio_dev)
{
struct st_sensor_data *mdata = iio_priv(indio_dev);

iio_device_unregister(indio_dev);
if (mdata->irq > 0)
st_sensors_deallocate_trigger(indio_dev);
}
EXPORT_SYMBOL(st_magn_common_remove);

Expand Down
18 changes: 1 addition & 17 deletions drivers/iio/pressure/st_pressure_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,29 +721,13 @@ int st_press_common_probe(struct iio_dev *indio_dev)
return err;
}

err = iio_device_register(indio_dev);
if (err)
goto st_press_device_register_error;

dev_info(&indio_dev->dev, "registered pressure sensor %s\n",
indio_dev->name);

return err;

st_press_device_register_error:
if (press_data->irq > 0)
st_sensors_deallocate_trigger(indio_dev);
return err;
return iio_device_register(indio_dev);
}
EXPORT_SYMBOL(st_press_common_probe);

void st_press_common_remove(struct iio_dev *indio_dev)
{
struct st_sensor_data *press_data = iio_priv(indio_dev);

iio_device_unregister(indio_dev);
if (press_data->irq > 0)
st_sensors_deallocate_trigger(indio_dev);
}
EXPORT_SYMBOL(st_press_common_remove);

Expand Down
5 changes: 0 additions & 5 deletions include/linux/iio/common/st_sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ irqreturn_t st_sensors_trigger_handler(int irq, void *p);
int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
const struct iio_trigger_ops *trigger_ops);

void st_sensors_deallocate_trigger(struct iio_dev *indio_dev);
int st_sensors_validate_device(struct iio_trigger *trig,
struct iio_dev *indio_dev);
#else
Expand All @@ -282,10 +281,6 @@ static inline int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
{
return 0;
}
static inline void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
{
return;
}
#define st_sensors_validate_device NULL
#endif

Expand Down

0 comments on commit 82bcb7f

Please sign in to comment.