aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/inkern.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/inkern.c')
-rw-r--r--drivers/iio/inkern.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index d55e98fb300e..b289915b8469 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -54,39 +54,25 @@ error_ret:
54EXPORT_SYMBOL_GPL(iio_map_array_register); 54EXPORT_SYMBOL_GPL(iio_map_array_register);
55 55
56 56
57/* Assumes the exact same array (e.g. memory locations) 57/*
58 * used at unregistration as used at registration rather than 58 * Remove all map entries associated with the given iio device
59 * more complex checking of contents.
60 */ 59 */
61int iio_map_array_unregister(struct iio_dev *indio_dev, 60int iio_map_array_unregister(struct iio_dev *indio_dev)
62 struct iio_map *maps)
63{ 61{
64 int i = 0, ret = 0; 62 int ret = -ENODEV;
65 bool found_it;
66 struct iio_map_internal *mapi; 63 struct iio_map_internal *mapi;
67 64 struct list_head *pos, *tmp;
68 if (maps == NULL)
69 return 0;
70 65
71 mutex_lock(&iio_map_list_lock); 66 mutex_lock(&iio_map_list_lock);
72 while (maps[i].consumer_dev_name != NULL) { 67 list_for_each_safe(pos, tmp, &iio_map_list) {
73 found_it = false; 68 mapi = list_entry(pos, struct iio_map_internal, l);
74 list_for_each_entry(mapi, &iio_map_list, l) 69 if (indio_dev == mapi->indio_dev) {
75 if (&maps[i] == mapi->map) { 70 list_del(&mapi->l);
76 list_del(&mapi->l); 71 kfree(mapi);
77 kfree(mapi); 72 ret = 0;
78 found_it = true;
79 break;
80 }
81 if (!found_it) {
82 ret = -ENODEV;
83 goto error_ret;
84 } 73 }
85 i++;
86 } 74 }
87error_ret:
88 mutex_unlock(&iio_map_list_lock); 75 mutex_unlock(&iio_map_list_lock);
89
90 return ret; 76 return ret;
91} 77}
92EXPORT_SYMBOL_GPL(iio_map_array_unregister); 78EXPORT_SYMBOL_GPL(iio_map_array_unregister);
@@ -107,7 +93,8 @@ static const struct iio_chan_spec
107} 93}
108 94
109 95
110struct iio_channel *iio_channel_get(const char *name, const char *channel_name) 96static struct iio_channel *iio_channel_get_sys(const char *name,
97 const char *channel_name)
111{ 98{
112 struct iio_map_internal *c_i = NULL, *c = NULL; 99 struct iio_map_internal *c_i = NULL, *c = NULL;
113 struct iio_channel *channel; 100 struct iio_channel *channel;
@@ -158,6 +145,14 @@ error_no_mem:
158 iio_device_put(c->indio_dev); 145 iio_device_put(c->indio_dev);
159 return ERR_PTR(err); 146 return ERR_PTR(err);
160} 147}
148
149struct iio_channel *iio_channel_get(struct device *dev,
150 const char *channel_name)
151{
152 const char *name = dev ? dev_name(dev) : NULL;
153
154 return iio_channel_get_sys(name, channel_name);
155}
161EXPORT_SYMBOL_GPL(iio_channel_get); 156EXPORT_SYMBOL_GPL(iio_channel_get);
162 157
163void iio_channel_release(struct iio_channel *channel) 158void iio_channel_release(struct iio_channel *channel)
@@ -167,16 +162,18 @@ void iio_channel_release(struct iio_channel *channel)
167} 162}
168EXPORT_SYMBOL_GPL(iio_channel_release); 163EXPORT_SYMBOL_GPL(iio_channel_release);
169 164
170struct iio_channel *iio_channel_get_all(const char *name) 165struct iio_channel *iio_channel_get_all(struct device *dev)
171{ 166{
167 const char *name;
172 struct iio_channel *chans; 168 struct iio_channel *chans;
173 struct iio_map_internal *c = NULL; 169 struct iio_map_internal *c = NULL;
174 int nummaps = 0; 170 int nummaps = 0;
175 int mapind = 0; 171 int mapind = 0;
176 int i, ret; 172 int i, ret;
177 173
178 if (name == NULL) 174 if (dev == NULL)
179 return ERR_PTR(-EINVAL); 175 return ERR_PTR(-EINVAL);
176 name = dev_name(dev);
180 177
181 mutex_lock(&iio_map_list_lock); 178 mutex_lock(&iio_map_list_lock);
182 /* first count the matching maps */ 179 /* first count the matching maps */