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

iio: temperature: tmp006: convert probe to device-managed

This change converts the driver to register via devm_iio_device_register().
For the tmp006_powerdown() hook, this uses a devm_add_action() hook to put
the device in powerdown mode when it's unregistered.

With these changes, the remove hook can be removed.

The i2c_set_clientdata() call is staying around as the private data is used
in the PM routines.

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

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
2bb3b8f6 3ce868bb

+15 -17
+15 -17
drivers/iio/temperature/tmp006.c
··· 193 193 return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC; 194 194 } 195 195 196 + static int tmp006_powerdown(struct tmp006_data *data) 197 + { 198 + return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, 199 + data->config & ~TMP006_CONFIG_MOD_MASK); 200 + } 201 + 202 + static void tmp006_powerdown_cleanup(void *data) 203 + { 204 + tmp006_powerdown(data); 205 + } 206 + 196 207 static int tmp006_probe(struct i2c_client *client, 197 208 const struct i2c_device_id *id) 198 209 { ··· 239 228 return ret; 240 229 data->config = ret; 241 230 242 - return iio_device_register(indio_dev); 243 - } 231 + ret = devm_add_action(&client->dev, tmp006_powerdown_cleanup, data); 232 + if (ret < 0) 233 + return ret; 244 234 245 - static int tmp006_powerdown(struct tmp006_data *data) 246 - { 247 - return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, 248 - data->config & ~TMP006_CONFIG_MOD_MASK); 249 - } 250 - 251 - static int tmp006_remove(struct i2c_client *client) 252 - { 253 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 254 - 255 - iio_device_unregister(indio_dev); 256 - tmp006_powerdown(iio_priv(indio_dev)); 257 - 258 - return 0; 235 + return devm_iio_device_register(&client->dev, indio_dev); 259 236 } 260 237 261 238 #ifdef CONFIG_PM_SLEEP ··· 276 277 .pm = &tmp006_pm_ops, 277 278 }, 278 279 .probe = tmp006_probe, 279 - .remove = tmp006_remove, 280 280 .id_table = tmp006_id, 281 281 }; 282 282 module_i2c_driver(tmp006_driver);