diff options
Diffstat (limited to 'drivers/iio/industrialio-core.c')
-rw-r--r-- | drivers/iio/industrialio-core.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 97f0297b120f..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); |
@@ -970,6 +968,8 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp) | |||
970 | if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags)) | 968 | if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags)) |
971 | return -EBUSY; | 969 | return -EBUSY; |
972 | 970 | ||
971 | iio_device_get(indio_dev); | ||
972 | |||
973 | filp->private_data = indio_dev; | 973 | filp->private_data = indio_dev; |
974 | 974 | ||
975 | return 0; | 975 | return 0; |
@@ -983,6 +983,8 @@ static int iio_chrdev_release(struct inode *inode, struct file *filp) | |||
983 | struct iio_dev *indio_dev = container_of(inode->i_cdev, | 983 | struct iio_dev *indio_dev = container_of(inode->i_cdev, |
984 | struct iio_dev, chrdev); | 984 | struct iio_dev, chrdev); |
985 | clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags); | 985 | clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags); |
986 | iio_device_put(indio_dev); | ||
987 | |||
986 | return 0; | 988 | return 0; |
987 | } | 989 | } |
988 | 990 | ||
@@ -1052,18 +1054,20 @@ int iio_device_register(struct iio_dev *indio_dev) | |||
1052 | indio_dev->setup_ops == NULL) | 1054 | indio_dev->setup_ops == NULL) |
1053 | indio_dev->setup_ops = &noop_ring_setup_ops; | 1055 | indio_dev->setup_ops = &noop_ring_setup_ops; |
1054 | 1056 | ||
1055 | ret = device_add(&indio_dev->dev); | ||
1056 | if (ret < 0) | ||
1057 | goto error_unreg_eventset; | ||
1058 | cdev_init(&indio_dev->chrdev, &iio_buffer_fileops); | 1057 | cdev_init(&indio_dev->chrdev, &iio_buffer_fileops); |
1059 | 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; | ||
1060 | ret = cdev_add(&indio_dev->chrdev, indio_dev->dev.devt, 1); | 1060 | ret = cdev_add(&indio_dev->chrdev, indio_dev->dev.devt, 1); |
1061 | if (ret < 0) | 1061 | if (ret < 0) |
1062 | goto error_del_device; | 1062 | goto error_unreg_eventset; |
1063 | return 0; | ||
1064 | 1063 | ||
1065 | error_del_device: | 1064 | ret = device_add(&indio_dev->dev); |
1066 | 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); | ||
1067 | error_unreg_eventset: | 1071 | error_unreg_eventset: |
1068 | iio_device_unregister_eventset(indio_dev); | 1072 | iio_device_unregister_eventset(indio_dev); |
1069 | error_free_sysfs: | 1073 | error_free_sysfs: |
@@ -1078,9 +1082,16 @@ EXPORT_SYMBOL(iio_device_register); | |||
1078 | void iio_device_unregister(struct iio_dev *indio_dev) | 1082 | void iio_device_unregister(struct iio_dev *indio_dev) |
1079 | { | 1083 | { |
1080 | mutex_lock(&indio_dev->info_exist_lock); | 1084 | mutex_lock(&indio_dev->info_exist_lock); |
1085 | |||
1086 | device_del(&indio_dev->dev); | ||
1087 | |||
1088 | if (indio_dev->chrdev.dev) | ||
1089 | cdev_del(&indio_dev->chrdev); | ||
1090 | |||
1091 | iio_disable_all_buffers(indio_dev); | ||
1092 | |||
1081 | indio_dev->info = NULL; | 1093 | indio_dev->info = NULL; |
1082 | mutex_unlock(&indio_dev->info_exist_lock); | 1094 | mutex_unlock(&indio_dev->info_exist_lock); |
1083 | device_del(&indio_dev->dev); | ||
1084 | } | 1095 | } |
1085 | EXPORT_SYMBOL(iio_device_unregister); | 1096 | EXPORT_SYMBOL(iio_device_unregister); |
1086 | subsys_initcall(iio_init); | 1097 | subsys_initcall(iio_init); |