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

iio: light: tcs3414: convert probe to device-managed routines

This change converts the driver to use only device-managed init routines in
the probe function of the driver.

This way, we no longer need the tcs3414_remove() hook.
We still need to keep the i2c_set_clientdata() call, as that's being used
for the PM routines.

And lastly, a devm_add_action_or_reset() hook is added to call the
powerdown handler when the chip is uninitialized or the probe fails.

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

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
9ae8da91 d272e0ab

+19 -29
+19 -29
drivers/iio/light/tcs3414.c
··· 267 267 .predisable = tcs3414_buffer_predisable, 268 268 }; 269 269 270 + static int tcs3414_powerdown(struct tcs3414_data *data) 271 + { 272 + return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL, 273 + data->control & ~(TCS3414_CONTROL_POWER | 274 + TCS3414_CONTROL_ADC_EN)); 275 + } 276 + 277 + static void tcs3414_powerdown_cleanup(void *data) 278 + { 279 + tcs3414_powerdown(data); 280 + } 281 + 270 282 static int tcs3414_probe(struct i2c_client *client, 271 283 const struct i2c_device_id *id) 272 284 { ··· 321 309 if (ret < 0) 322 310 return ret; 323 311 312 + ret = devm_add_action_or_reset(&client->dev, tcs3414_powerdown_cleanup, 313 + data); 314 + if (ret < 0) 315 + return ret; 316 + 324 317 data->timing = TCS3414_INTEG_12MS; /* free running */ 325 318 ret = i2c_smbus_write_byte_data(data->client, TCS3414_TIMING, 326 319 data->timing); ··· 337 320 return ret; 338 321 data->gain = ret; 339 322 340 - ret = iio_triggered_buffer_setup(indio_dev, NULL, 323 + ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, 341 324 tcs3414_trigger_handler, &tcs3414_buffer_setup_ops); 342 325 if (ret < 0) 343 326 return ret; 344 327 345 - ret = iio_device_register(indio_dev); 346 - if (ret < 0) 347 - goto buffer_cleanup; 348 - 349 - return 0; 350 - 351 - buffer_cleanup: 352 - iio_triggered_buffer_cleanup(indio_dev); 353 - return ret; 354 - } 355 - 356 - static int tcs3414_powerdown(struct tcs3414_data *data) 357 - { 358 - return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL, 359 - data->control & ~(TCS3414_CONTROL_POWER | 360 - TCS3414_CONTROL_ADC_EN)); 361 - } 362 - 363 - static int tcs3414_remove(struct i2c_client *client) 364 - { 365 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 366 - 367 - iio_device_unregister(indio_dev); 368 - iio_triggered_buffer_cleanup(indio_dev); 369 - tcs3414_powerdown(iio_priv(indio_dev)); 370 - 371 - return 0; 328 + return devm_iio_device_register(&client->dev, indio_dev); 372 329 } 373 330 374 331 #ifdef CONFIG_PM_SLEEP ··· 376 385 .pm = &tcs3414_pm_ops, 377 386 }, 378 387 .probe = tcs3414_probe, 379 - .remove = tcs3414_remove, 380 388 .id_table = tcs3414_id, 381 389 }; 382 390 module_i2c_driver(tcs3414_driver);