Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: accel: da311: convert probe to device-managed functions

This is another simple conversion to device-managed functions, requiring
the use of devm_iio_device_register() and moving the disabling of the
device on a devm_add_action_or_reset() hook.

The i2c_set_clientdata() can be removed, as the PM functions can work with
just the device object, to obtain the i2c_client object.

Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210630120338.482426-1-aardelean@deviqon.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
074e1ddb 689f584b

+9 -17
+9 -17
drivers/iio/accel/da311.c
··· 212 212 .read_raw = da311_read_raw, 213 213 }; 214 214 215 + static void da311_disable(void *client) 216 + { 217 + da311_enable(client, false); 218 + } 219 + 215 220 static int da311_probe(struct i2c_client *client, 216 221 const struct i2c_device_id *id) 217 222 { ··· 234 229 235 230 data = iio_priv(indio_dev); 236 231 data->client = client; 237 - i2c_set_clientdata(client, indio_dev); 238 232 239 233 indio_dev->info = &da311_info; 240 234 indio_dev->name = "da311"; ··· 249 245 if (ret < 0) 250 246 return ret; 251 247 252 - ret = iio_device_register(indio_dev); 253 - if (ret < 0) { 254 - dev_err(&client->dev, "device_register failed\n"); 255 - da311_enable(client, false); 256 - } 248 + ret = devm_add_action_or_reset(&client->dev, da311_disable, client); 249 + if (ret) 250 + return ret; 257 251 258 - return ret; 259 - } 260 - 261 - static int da311_remove(struct i2c_client *client) 262 - { 263 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 264 - 265 - iio_device_unregister(indio_dev); 266 - 267 - return da311_enable(client, false); 252 + return devm_iio_device_register(&client->dev, indio_dev); 268 253 } 269 254 270 255 #ifdef CONFIG_PM_SLEEP ··· 282 289 .pm = &da311_pm_ops, 283 290 }, 284 291 .probe = da311_probe, 285 - .remove = da311_remove, 286 292 .id_table = da311_i2c_id, 287 293 }; 288 294