diff options
-rw-r--r-- | drivers/iio/industrialio-core.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 8f7b6c9f92dc..8e84cd522e49 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c | |||
@@ -848,8 +848,6 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev) | |||
848 | static void iio_dev_release(struct device *device) | 848 | static void iio_dev_release(struct device *device) |
849 | { | 849 | { |
850 | struct iio_dev *indio_dev = dev_to_iio_dev(device); | 850 | struct iio_dev *indio_dev = dev_to_iio_dev(device); |
851 | if (indio_dev->chrdev.dev) | ||
852 | cdev_del(&indio_dev->chrdev); | ||
853 | if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) | 851 | if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) |
854 | iio_device_unregister_trigger_consumer(indio_dev); | 852 | iio_device_unregister_trigger_consumer(indio_dev); |
855 | iio_device_unregister_eventset(indio_dev); | 853 | iio_device_unregister_eventset(indio_dev); |
@@ -1056,18 +1054,20 @@ int iio_device_register(struct iio_dev *indio_dev) | |||
1056 | indio_dev->setup_ops == NULL) | 1054 | indio_dev->setup_ops == NULL) |
1057 | indio_dev->setup_ops = &noop_ring_setup_ops; | 1055 | indio_dev->setup_ops = &noop_ring_setup_ops; |
1058 | 1056 | ||
1059 | ret = device_add(&indio_dev->dev); | ||
1060 | if (ret < 0) | ||
1061 | goto error_unreg_eventset; | ||
1062 | cdev_init(&indio_dev->chrdev, &iio_buffer_fileops); | 1057 | cdev_init(&indio_dev->chrdev, &iio_buffer_fileops); |
1063 | indio_dev->chrdev.owner = indio_dev->info->driver_module; | 1058 | indio_dev->chrdev.owner = indio_dev->info->driver_module; |
1059 | indio_dev->chrdev.kobj.parent = &indio_dev->dev.kobj; | ||
1064 | ret = cdev_add(&indio_dev->chrdev, indio_dev->dev.devt, 1); | 1060 | ret = cdev_add(&indio_dev->chrdev, indio_dev->dev.devt, 1); |
1065 | if (ret < 0) | 1061 | if (ret < 0) |
1066 | goto error_del_device; | 1062 | goto error_unreg_eventset; |
1067 | return 0; | ||
1068 | 1063 | ||
1069 | error_del_device: | 1064 | ret = device_add(&indio_dev->dev); |
1070 | device_del(&indio_dev->dev); | 1065 | if (ret < 0) |
1066 | goto error_cdev_del; | ||
1067 | |||
1068 | return 0; | ||
1069 | error_cdev_del: | ||
1070 | cdev_del(&indio_dev->chrdev); | ||
1071 | error_unreg_eventset: | 1071 | error_unreg_eventset: |
1072 | iio_device_unregister_eventset(indio_dev); | 1072 | iio_device_unregister_eventset(indio_dev); |
1073 | error_free_sysfs: | 1073 | error_free_sysfs: |
@@ -1085,6 +1085,9 @@ void iio_device_unregister(struct iio_dev *indio_dev) | |||
1085 | 1085 | ||
1086 | device_del(&indio_dev->dev); | 1086 | device_del(&indio_dev->dev); |
1087 | 1087 | ||
1088 | if (indio_dev->chrdev.dev) | ||
1089 | cdev_del(&indio_dev->chrdev); | ||
1090 | |||
1088 | iio_disable_all_buffers(indio_dev); | 1091 | iio_disable_all_buffers(indio_dev); |
1089 | 1092 | ||
1090 | indio_dev->info = NULL; | 1093 | indio_dev->info = NULL; |