From: Javier Carrasco Date: Sun, 29 Sep 2024 20:38:46 +0000 (+0200) Subject: iio: light: veml6070: add action for i2c_unregister_device X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7501bff87c3ec6b3d0ec2c75ca0109d70521f7d5;p=users%2Fjedix%2Flinux-maple.git iio: light: veml6070: add action for i2c_unregister_device Simplify the code by adding an action to call i2c_unregister_device(), which removes the need for a 'fail' label, gotos to it, and an explicit call in veml6070_remove(). Signed-off-by: Javier Carrasco Link: https://patch.msgid.link/20240929-veml6070-cleanup-v1-1-a9350341a646@gmail.com Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/light/veml6070.c b/drivers/iio/light/veml6070.c index f8321d346d775..3c476b6f61220 100644 --- a/drivers/iio/light/veml6070.c +++ b/drivers/iio/light/veml6070.c @@ -135,6 +135,13 @@ static const struct iio_info veml6070_info = { .read_raw = veml6070_read_raw, }; +static void veml6070_i2c_unreg(void *p) +{ + struct veml6070_data *data = p; + + i2c_unregister_device(data->client2); +} + static int veml6070_probe(struct i2c_client *client) { struct veml6070_data *data; @@ -166,17 +173,13 @@ static int veml6070_probe(struct i2c_client *client) VEML6070_COMMAND_SD; ret = i2c_smbus_write_byte(data->client1, data->config); if (ret < 0) - goto fail; + return ret; - ret = iio_device_register(indio_dev); + ret = devm_add_action_or_reset(&client->dev, veml6070_i2c_unreg, data); if (ret < 0) - goto fail; + return ret; - return ret; - -fail: - i2c_unregister_device(data->client2); - return ret; + return iio_device_register(indio_dev); } static void veml6070_remove(struct i2c_client *client) @@ -185,7 +188,6 @@ static void veml6070_remove(struct i2c_client *client) struct veml6070_data *data = iio_priv(indio_dev); iio_device_unregister(indio_dev); - i2c_unregister_device(data->client2); } static const struct i2c_device_id veml6070_id[] = {