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

iio: temperature: tmp007: use device-managed functions in probe

This change converts the driver to use device-managed functions in the
probe function. The power-down call is handled now via a
devm_add_action_or_reset() hook, and then devm_iio_device_register() can be
used to register the IIO device.

The final aim here would be for IIO to export only the device-managed
functions of it's API. That's a long way to go and this a small step in
that direction.

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

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
70da6415 218bc53d

+15 -21
+15 -21
drivers/iio/temperature/tmp007.c
··· 439 439 return (manf_id == TMP007_MANUFACTURER_MAGIC && dev_id == TMP007_DEVICE_MAGIC); 440 440 } 441 441 442 + static void tmp007_powerdown_action_cb(void *priv) 443 + { 444 + struct tmp007_data *data = priv; 445 + 446 + tmp007_powerdown(data); 447 + } 448 + 442 449 static int tmp007_probe(struct i2c_client *client, 443 450 const struct i2c_device_id *tmp007_id) 444 451 { ··· 496 489 if (ret < 0) 497 490 return ret; 498 491 492 + ret = devm_add_action_or_reset(&client->dev, tmp007_powerdown_action_cb, data); 493 + if (ret) 494 + return ret; 495 + 499 496 /* 500 497 * Only the following flags can activate ALERT pin. Data conversion/validity flags 501 498 * flags can still be polled for getting temperature data ··· 513 502 514 503 ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS_MASK); 515 504 if (ret < 0) 516 - goto error_powerdown; 505 + return ret; 517 506 518 507 data->status_mask = ret; 519 508 data->status_mask |= (TMP007_STATUS_OHF | TMP007_STATUS_OLF ··· 521 510 522 511 ret = i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, data->status_mask); 523 512 if (ret < 0) 524 - goto error_powerdown; 513 + return ret; 525 514 526 515 if (client->irq) { 527 516 ret = devm_request_threaded_irq(&client->dev, client->irq, ··· 530 519 tmp007_id->name, indio_dev); 531 520 if (ret) { 532 521 dev_err(&client->dev, "irq request error %d\n", -ret); 533 - goto error_powerdown; 522 + return ret; 534 523 } 535 524 } 536 525 537 - return iio_device_register(indio_dev); 538 - 539 - error_powerdown: 540 - tmp007_powerdown(data); 541 - 542 - return ret; 543 - } 544 - 545 - static int tmp007_remove(struct i2c_client *client) 546 - { 547 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 548 - struct tmp007_data *data = iio_priv(indio_dev); 549 - 550 - iio_device_unregister(indio_dev); 551 - tmp007_powerdown(data); 552 - 553 - return 0; 526 + return devm_iio_device_register(&client->dev, indio_dev); 554 527 } 555 528 556 529 #ifdef CONFIG_PM_SLEEP ··· 577 582 .pm = &tmp007_pm_ops, 578 583 }, 579 584 .probe = tmp007_probe, 580 - .remove = tmp007_remove, 581 585 .id_table = tmp007_id, 582 586 }; 583 587 module_i2c_driver(tmp007_driver);