[PATCH v2 10/16] iio:core: utilize new cdev_device_add helper function

Logan Gunthorpe
2017-02-26T06:38:11Z

Replace the open coded registration of the cdev and dev with the
new device_add_cdev() helper. The helper replaces a common pattern by
taking the proper reference against the parent device and adding both
the cdev and the device.

In doing so we have to remove a guard statement from cdev_del,
but this doesn't appear to be required in any way.

Signed-off-by: Logan Gunthorpe <logang-OTvnGxWRz7hWk0Htik3J/w@public.gmane.org>
---
drivers/iio/industrialio-core.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index aaca428..f9ac301 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1718,18 +1718,13 @@ int iio_device_register(struct iio_dev *indio_dev)

cdev_init(&indio_dev->chrdev, &iio_buffer_fileops);
indio_dev->chrdev.owner = indio_dev->info->driver_module;
- indio_dev->chrdev.kobj.parent = &indio_dev->dev.kobj;
- ret = cdev_add(&indio_dev->chrdev, indio_dev->dev.devt, 1);
- if (ret < 0)
- goto error_unreg_eventset;

- ret = device_add(&indio_dev->dev);
+ ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev);
if (ret < 0)
- goto error_cdev_del;
+ goto error_unreg_eventset;

return 0;
-error_cdev_del:
- cdev_del(&indio_dev->chrdev);
+
error_unreg_eventset:
iio_device_unregister_eventset(indio_dev);
error_free_sysfs:
@@ -1750,10 +1745,8 @@ void iio_device_unregister(struct iio_dev *indio_dev)
{
mutex_lock(&indio_dev->info_exist_lock);

- device_del(&indio_dev->dev);
+ cdev_device_del(&indio_dev->chrdev, &indio_dev->dev);

- if (indio_dev->chrdev.dev)
- cdev_del(&indio_dev->chrdev);
iio_device_unregister_debugfs(indio_dev);

iio_disable_all_buffers(indio_dev);
--
2.1.4