aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-01-31 16:43:00 -0500
committerJonathan Cameron <jic23@kernel.org>2013-02-02 07:02:20 -0500
commit6cb2afd7c0abb93bd9dc6d36b858b1e312e2407d (patch)
tree3abec8f4f092e6e594f4ce57069987c5618f67ff
parentca7d98dbd7db6aa8bc4b08e26be1249436d21af3 (diff)
iio: Simplify iio_map_array_unregister API
Instead of requiring the map to unregister, simply unregister all map entries associated with the given iio device. This simplifies map removal and also works for maps generated through devicetree. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/adc/lp8788_adc.c11
-rw-r--r--drivers/iio/adc/max1363.c4
-rw-r--r--drivers/iio/inkern.c36
-rw-r--r--include/linux/iio/driver.h9
4 files changed, 18 insertions, 42 deletions
diff --git a/drivers/iio/adc/lp8788_adc.c b/drivers/iio/adc/lp8788_adc.c
index d02704ce0091..763f57565ee4 100644
--- a/drivers/iio/adc/lp8788_adc.c
+++ b/drivers/iio/adc/lp8788_adc.c
@@ -187,12 +187,6 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev,
187 return 0; 187 return 0;
188} 188}
189 189
190static inline void lp8788_iio_map_unregister(struct iio_dev *indio_dev,
191 struct lp8788_adc *adc)
192{
193 iio_map_array_unregister(indio_dev, adc->map);
194}
195
196static int lp8788_adc_probe(struct platform_device *pdev) 190static int lp8788_adc_probe(struct platform_device *pdev)
197{ 191{
198 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); 192 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent);
@@ -231,7 +225,7 @@ static int lp8788_adc_probe(struct platform_device *pdev)
231 return 0; 225 return 0;
232 226
233err_iio_device: 227err_iio_device:
234 lp8788_iio_map_unregister(indio_dev, adc); 228 iio_map_array_unregister(indio_dev);
235err_iio_map: 229err_iio_map:
236 iio_device_free(indio_dev); 230 iio_device_free(indio_dev);
237 return ret; 231 return ret;
@@ -240,10 +234,9 @@ err_iio_map:
240static int lp8788_adc_remove(struct platform_device *pdev) 234static int lp8788_adc_remove(struct platform_device *pdev)
241{ 235{
242 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 236 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
243 struct lp8788_adc *adc = iio_priv(indio_dev);
244 237
245 iio_device_unregister(indio_dev); 238 iio_device_unregister(indio_dev);
246 lp8788_iio_map_unregister(indio_dev, adc); 239 iio_map_array_unregister(indio_dev);
247 iio_device_free(indio_dev); 240 iio_device_free(indio_dev);
248 241
249 return 0; 242 return 0;
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 46732380566f..ef868c9c17be 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -1611,7 +1611,7 @@ error_disable_reg:
1611error_put_reg: 1611error_put_reg:
1612 regulator_put(st->reg); 1612 regulator_put(st->reg);
1613error_unregister_map: 1613error_unregister_map:
1614 iio_map_array_unregister(indio_dev, client->dev.platform_data); 1614 iio_map_array_unregister(indio_dev);
1615error_free_device: 1615error_free_device:
1616 iio_device_free(indio_dev); 1616 iio_device_free(indio_dev);
1617error_out: 1617error_out:
@@ -1630,7 +1630,7 @@ static int max1363_remove(struct i2c_client *client)
1630 kfree(indio_dev->available_scan_masks); 1630 kfree(indio_dev->available_scan_masks);
1631 regulator_disable(st->reg); 1631 regulator_disable(st->reg);
1632 regulator_put(st->reg); 1632 regulator_put(st->reg);
1633 iio_map_array_unregister(indio_dev, client->dev.platform_data); 1633 iio_map_array_unregister(indio_dev);
1634 iio_device_free(indio_dev); 1634 iio_device_free(indio_dev);
1635 1635
1636 return 0; 1636 return 0;
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 58d0ffe856b6..c42aba6817e8 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);
diff --git a/include/linux/iio/driver.h b/include/linux/iio/driver.h
index a4f8b2e05af5..7dfb10ee2669 100644
--- a/include/linux/iio/driver.h
+++ b/include/linux/iio/driver.h
@@ -22,13 +22,10 @@ int iio_map_array_register(struct iio_dev *indio_dev,
22 struct iio_map *map); 22 struct iio_map *map);
23 23
24/** 24/**
25 * iio_map_array_unregister() - tell the core to remove consumer mappings 25 * iio_map_array_unregister() - tell the core to remove consumer mappings for
26 * the given provider device
26 * @indio_dev: provider device 27 * @indio_dev: provider device
27 * @map: array of mappings to remove. Note these must have same memory
28 * addresses as those originally added not just equal parameter
29 * values.
30 */ 28 */
31int iio_map_array_unregister(struct iio_dev *indio_dev, 29int iio_map_array_unregister(struct iio_dev *indio_dev);
32 struct iio_map *map);
33 30
34#endif 31#endif