Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Guenter Roeck and committed by
Jonathan Cameron
6cb2afd7 ca7d98db

+18 -42
+2 -9
drivers/iio/adc/lp8788_adc.c
··· 187 187 return 0; 188 188 } 189 189 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 - 196 190 static int lp8788_adc_probe(struct platform_device *pdev) 197 191 { 198 192 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); ··· 225 231 return 0; 226 232 227 233 err_iio_device: 228 - lp8788_iio_map_unregister(indio_dev, adc); 234 + iio_map_array_unregister(indio_dev); 229 235 err_iio_map: 230 236 iio_device_free(indio_dev); 231 237 return ret; ··· 234 240 static int lp8788_adc_remove(struct platform_device *pdev) 235 241 { 236 242 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 237 - struct lp8788_adc *adc = iio_priv(indio_dev); 238 243 239 244 iio_device_unregister(indio_dev); 240 - lp8788_iio_map_unregister(indio_dev, adc); 245 + iio_map_array_unregister(indio_dev); 241 246 iio_device_free(indio_dev); 242 247 243 248 return 0;
+2 -2
drivers/iio/adc/max1363.c
··· 1611 1611 error_put_reg: 1612 1612 regulator_put(st->reg); 1613 1613 error_unregister_map: 1614 - iio_map_array_unregister(indio_dev, client->dev.platform_data); 1614 + iio_map_array_unregister(indio_dev); 1615 1615 error_free_device: 1616 1616 iio_device_free(indio_dev); 1617 1617 error_out: ··· 1630 1630 kfree(indio_dev->available_scan_masks); 1631 1631 regulator_disable(st->reg); 1632 1632 regulator_put(st->reg); 1633 - iio_map_array_unregister(indio_dev, client->dev.platform_data); 1633 + iio_map_array_unregister(indio_dev); 1634 1634 iio_device_free(indio_dev); 1635 1635 1636 1636 return 0;
+11 -25
drivers/iio/inkern.c
··· 54 54 EXPORT_SYMBOL_GPL(iio_map_array_register); 55 55 56 56 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 60 59 */ 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) 63 61 { 64 - int i = 0, ret = 0; 65 - bool found_it; 62 + int ret = -ENODEV; 66 63 struct iio_map_internal *mapi; 67 - 68 - if (maps == NULL) 69 - return 0; 64 + struct list_head *pos, *tmp; 70 65 71 66 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; 84 73 } 85 - i++; 86 74 } 87 - error_ret: 88 75 mutex_unlock(&iio_map_list_lock); 89 - 90 76 return ret; 91 77 } 92 78 EXPORT_SYMBOL_GPL(iio_map_array_unregister);
+3 -6
include/linux/iio/driver.h
··· 22 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 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 */ 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); 33 30 34 31 #endif