Skip to content

Commit 6cb2afd

Browse files
groeckjic23
authored andcommitted
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>
1 parent ca7d98d commit 6cb2afd

4 files changed

Lines changed: 18 additions & 42 deletions

File tree

‎drivers/iio/adc/lp8788_adc.c‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,6 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev,
187187
return 0;
188188
}
189189

190-
static 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-
196190
static int lp8788_adc_probe(struct platform_device *pdev)
197191
{
198192
struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent);
@@ -231,7 +225,7 @@ static int lp8788_adc_probe(struct platform_device *pdev)
231225
return 0;
232226

233227
err_iio_device:
234-
lp8788_iio_map_unregister(indio_dev, adc);
228+
iio_map_array_unregister(indio_dev);
235229
err_iio_map:
236230
iio_device_free(indio_dev);
237231
return ret;
@@ -240,10 +234,9 @@ static int lp8788_adc_probe(struct platform_device *pdev)
240234
static int lp8788_adc_remove(struct platform_device *pdev)
241235
{
242236
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
243-
struct lp8788_adc *adc = iio_priv(indio_dev);
244237

245238
iio_device_unregister(indio_dev);
246-
lp8788_iio_map_unregister(indio_dev, adc);
239+
iio_map_array_unregister(indio_dev);
247240
iio_device_free(indio_dev);
248241

249242
return 0;

‎drivers/iio/adc/max1363.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ static int max1363_probe(struct i2c_client *client,
16111611
error_put_reg:
16121612
regulator_put(st->reg);
16131613
error_unregister_map:
1614-
iio_map_array_unregister(indio_dev, client->dev.platform_data);
1614+
iio_map_array_unregister(indio_dev);
16151615
error_free_device:
16161616
iio_device_free(indio_dev);
16171617
error_out:
@@ -1630,7 +1630,7 @@ static int max1363_remove(struct i2c_client *client)
16301630
kfree(indio_dev->available_scan_masks);
16311631
regulator_disable(st->reg);
16321632
regulator_put(st->reg);
1633-
iio_map_array_unregister(indio_dev, client->dev.platform_data);
1633+
iio_map_array_unregister(indio_dev);
16341634
iio_device_free(indio_dev);
16351635

16361636
return 0;

‎drivers/iio/inkern.c‎

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,25 @@ int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
5454
EXPORT_SYMBOL_GPL(iio_map_array_register);
5555

5656

57-
/* Assumes the exact same array (e.g. memory locations)
58-
* used at unregistration as used at registration rather than
59-
* more complex checking of contents.
57+
/*
58+
* Remove all map entries associated with the given iio device
6059
*/
61-
int iio_map_array_unregister(struct iio_dev *indio_dev,
62-
struct iio_map *maps)
60+
int iio_map_array_unregister(struct iio_dev *indio_dev)
6361
{
64-
int i = 0, ret = 0;
65-
bool found_it;
62+
int ret = -ENODEV;
6663
struct iio_map_internal *mapi;
67-
68-
if (maps == NULL)
69-
return 0;
64+
struct list_head *pos, *tmp;
7065

7166
mutex_lock(&iio_map_list_lock);
72-
while (maps[i].consumer_dev_name != NULL) {
73-
found_it = false;
74-
list_for_each_entry(mapi, &iio_map_list, l)
75-
if (&maps[i] == mapi->map) {
76-
list_del(&mapi->l);
77-
kfree(mapi);
78-
found_it = true;
79-
break;
80-
}
81-
if (!found_it) {
82-
ret = -ENODEV;
83-
goto error_ret;
67+
list_for_each_safe(pos, tmp, &iio_map_list) {
68+
mapi = list_entry(pos, struct iio_map_internal, l);
69+
if (indio_dev == mapi->indio_dev) {
70+
list_del(&mapi->l);
71+
kfree(mapi);
72+
ret = 0;
8473
}
85-
i++;
8674
}
87-
error_ret:
8875
mutex_unlock(&iio_map_list_lock);
89-
9076
return ret;
9177
}
9278
EXPORT_SYMBOL_GPL(iio_map_array_unregister);

‎include/linux/iio/driver.h‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ int iio_map_array_register(struct iio_dev *indio_dev,
2222
struct iio_map *map);
2323

2424
/**
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
2627
* @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.
3028
*/
31-
int iio_map_array_unregister(struct iio_dev *indio_dev,
32-
struct iio_map *map);
29+
int iio_map_array_unregister(struct iio_dev *indio_dev);
3330

3431
#endif

0 commit comments

Comments
 (0)