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

iio: adc: lp8788_adc: convert probe to full-device managed

This change converts the probe of this driver to use device-managed
functions only, which means that the remove hook can be removed.
The remove hook has only 2 calls to iio_device_unregister() and
iio_map_array_unregister(). Both these can now be done via devm register
functions, now that there's also a devm_iio_map_array_register() function.

The platform_set_drvdata() can also be removed now.

This change also removes the error print for when the iio_device_register()
call fails. This isn't required now.

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

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
9c22f459 298fdedc

+5 -26
+5 -26
drivers/iio/adc/lp8788_adc.c
··· 163 163 { } 164 164 }; 165 165 166 - static int lp8788_iio_map_register(struct iio_dev *indio_dev, 166 + static int lp8788_iio_map_register(struct device *dev, 167 + struct iio_dev *indio_dev, 167 168 struct lp8788_platform_data *pdata, 168 169 struct lp8788_adc *adc) 169 170 { ··· 174 173 map = (!pdata || !pdata->adc_pdata) ? 175 174 lp8788_default_iio_maps : pdata->adc_pdata; 176 175 177 - ret = iio_map_array_register(indio_dev, map); 176 + ret = devm_iio_map_array_register(dev, indio_dev, map); 178 177 if (ret) { 179 178 dev_err(&indio_dev->dev, "iio map err: %d\n", ret); 180 179 return ret; ··· 197 196 198 197 adc = iio_priv(indio_dev); 199 198 adc->lp = lp; 200 - platform_set_drvdata(pdev, indio_dev); 201 199 202 - ret = lp8788_iio_map_register(indio_dev, lp->pdata, adc); 200 + ret = lp8788_iio_map_register(&pdev->dev, indio_dev, lp->pdata, adc); 203 201 if (ret) 204 202 return ret; 205 203 ··· 210 210 indio_dev->channels = lp8788_adc_channels; 211 211 indio_dev->num_channels = ARRAY_SIZE(lp8788_adc_channels); 212 212 213 - ret = iio_device_register(indio_dev); 214 - if (ret) { 215 - dev_err(&pdev->dev, "iio dev register err: %d\n", ret); 216 - goto err_iio_device; 217 - } 218 - 219 - return 0; 220 - 221 - err_iio_device: 222 - iio_map_array_unregister(indio_dev); 223 - return ret; 224 - } 225 - 226 - static int lp8788_adc_remove(struct platform_device *pdev) 227 - { 228 - struct iio_dev *indio_dev = platform_get_drvdata(pdev); 229 - 230 - iio_device_unregister(indio_dev); 231 - iio_map_array_unregister(indio_dev); 232 - 233 - return 0; 213 + return devm_iio_device_register(&pdev->dev, indio_dev); 234 214 } 235 215 236 216 static struct platform_driver lp8788_adc_driver = { 237 217 .probe = lp8788_adc_probe, 238 - .remove = lp8788_adc_remove, 239 218 .driver = { 240 219 .name = LP8788_DEV_ADC, 241 220 },