On Mon, 29 Jul 2019 09:43:01 +0800 Chuhong Yuan <hslester96@xxxxxxxxx> wrote: > Use device-managed APIs to simplify the code. > The remove functions are redundant now and can > be deleted. > > Signed-off-by: Chuhong Yuan <hslester96@xxxxxxxxx> Nice little patch, thanks! Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > Changes in v2: > - Split v1 into two patches. > - Use devm_iio_trigger_register in probe_trigger, > delete redundant remove_trigger. > - Return devm_iio_device_register directly as a > minor optimization. > > drivers/iio/light/si1145.c | 42 +++++--------------------------------- > 1 file changed, 5 insertions(+), 37 deletions(-) > > diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c > index 6579d2418814..982bba0c54e7 100644 > --- a/drivers/iio/light/si1145.c > +++ b/drivers/iio/light/si1145.c > @@ -1261,7 +1261,7 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev) > return ret; > } > > - ret = iio_trigger_register(trig); > + ret = devm_iio_trigger_register(&client->dev, trig); > if (ret) > return ret; > > @@ -1271,16 +1271,6 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev) > return 0; > } > > -static void si1145_remove_trigger(struct iio_dev *indio_dev) > -{ > - struct si1145_data *data = iio_priv(indio_dev); > - > - if (data->trig) { > - iio_trigger_unregister(data->trig); > - data->trig = NULL; > - } > -} > - > static int si1145_probe(struct i2c_client *client, > const struct i2c_device_id *id) > { > @@ -1332,7 +1322,8 @@ static int si1145_probe(struct i2c_client *client, > if (ret < 0) > return ret; > > - ret = iio_triggered_buffer_setup(indio_dev, NULL, > + ret = devm_iio_triggered_buffer_setup(&client->dev, > + indio_dev, NULL, > si1145_trigger_handler, &si1145_buffer_setup_ops); > if (ret < 0) > return ret; > @@ -1340,23 +1331,12 @@ static int si1145_probe(struct i2c_client *client, > if (client->irq) { > ret = si1145_probe_trigger(indio_dev); > if (ret < 0) > - goto error_free_buffer; > + return ret; > } else { > dev_info(&client->dev, "no irq, using polling\n"); > } > > - ret = iio_device_register(indio_dev); > - if (ret < 0) > - goto error_free_trigger; > - > - return 0; > - > -error_free_trigger: > - si1145_remove_trigger(indio_dev); > -error_free_buffer: > - iio_triggered_buffer_cleanup(indio_dev); > - > - return ret; > + return devm_iio_device_register(&client->dev, indio_dev); > } > > static const struct i2c_device_id si1145_ids[] = { > @@ -1371,23 +1351,11 @@ static const struct i2c_device_id si1145_ids[] = { > }; > MODULE_DEVICE_TABLE(i2c, si1145_ids); > > -static int si1145_remove(struct i2c_client *client) > -{ > - struct iio_dev *indio_dev = i2c_get_clientdata(client); > - > - iio_device_unregister(indio_dev); > - si1145_remove_trigger(indio_dev); > - iio_triggered_buffer_cleanup(indio_dev); > - > - return 0; > -} > - > static struct i2c_driver si1145_driver = { > .driver = { > .name = "si1145", > }, > .probe = si1145_probe, > - .remove = si1145_remove, > .id_table = si1145_ids, > }; >