]> git.karo-electronics.de Git - linux-beck.git/commitdiff
iio: Simplify iio_map_array_unregister API
authorGuenter Roeck <linux@roeck-us.net>
Thu, 31 Jan 2013 21:43:00 +0000 (21:43 +0000)
committerJonathan Cameron <jic23@kernel.org>
Sat, 2 Feb 2013 12:02:20 +0000 (12:02 +0000)
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>
drivers/iio/adc/lp8788_adc.c
drivers/iio/adc/max1363.c
drivers/iio/inkern.c
include/linux/iio/driver.h

index d02704ce0091044ef49e6f62f439d0dee6b07ff8..763f57565ee43fe98701d3b42c9e16511031a000 100644 (file)
@@ -187,12 +187,6 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev,
        return 0;
 }
 
-static inline void lp8788_iio_map_unregister(struct iio_dev *indio_dev,
-                               struct lp8788_adc *adc)
-{
-       iio_map_array_unregister(indio_dev, adc->map);
-}
-
 static int lp8788_adc_probe(struct platform_device *pdev)
 {
        struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent);
@@ -231,7 +225,7 @@ static int lp8788_adc_probe(struct platform_device *pdev)
        return 0;
 
 err_iio_device:
-       lp8788_iio_map_unregister(indio_dev, adc);
+       iio_map_array_unregister(indio_dev);
 err_iio_map:
        iio_device_free(indio_dev);
        return ret;
@@ -240,10 +234,9 @@ err_iio_map:
 static int lp8788_adc_remove(struct platform_device *pdev)
 {
        struct iio_dev *indio_dev = platform_get_drvdata(pdev);
-       struct lp8788_adc *adc = iio_priv(indio_dev);
 
        iio_device_unregister(indio_dev);
-       lp8788_iio_map_unregister(indio_dev, adc);
+       iio_map_array_unregister(indio_dev);
        iio_device_free(indio_dev);
 
        return 0;
index 46732380566fd7b3728ad391acb8aefdfd2bcf93..ef868c9c17beed36a4b2bb767d055ca88155b48b 100644 (file)
@@ -1611,7 +1611,7 @@ error_disable_reg:
 error_put_reg:
        regulator_put(st->reg);
 error_unregister_map:
-       iio_map_array_unregister(indio_dev, client->dev.platform_data);
+       iio_map_array_unregister(indio_dev);
 error_free_device:
        iio_device_free(indio_dev);
 error_out:
@@ -1630,7 +1630,7 @@ static int max1363_remove(struct i2c_client *client)
        kfree(indio_dev->available_scan_masks);
        regulator_disable(st->reg);
        regulator_put(st->reg);
-       iio_map_array_unregister(indio_dev, client->dev.platform_data);
+       iio_map_array_unregister(indio_dev);
        iio_device_free(indio_dev);
 
        return 0;
index 58d0ffe856b6868cc587ccc05c135b2514127d6b..c42aba6817e8ba09df9e455fa8fb7ea8bc5ccfa9 100644 (file)
@@ -54,39 +54,25 @@ error_ret:
 EXPORT_SYMBOL_GPL(iio_map_array_register);
 
 
-/* Assumes the exact same array (e.g. memory locations)
- * used at unregistration as used at registration rather than
- * more complex checking of contents.
+/*
+ * Remove all map entries associated with the given iio device
  */
-int iio_map_array_unregister(struct iio_dev *indio_dev,
-                            struct iio_map *maps)
+int iio_map_array_unregister(struct iio_dev *indio_dev)
 {
-       int i = 0, ret = 0;
-       bool found_it;
+       int ret = -ENODEV;
        struct iio_map_internal *mapi;
-
-       if (maps == NULL)
-               return 0;
+       struct list_head *pos, *tmp;
 
        mutex_lock(&iio_map_list_lock);
-       while (maps[i].consumer_dev_name != NULL) {
-               found_it = false;
-               list_for_each_entry(mapi, &iio_map_list, l)
-                       if (&maps[i] == mapi->map) {
-                               list_del(&mapi->l);
-                               kfree(mapi);
-                               found_it = true;
-                               break;
-                       }
-               if (!found_it) {
-                       ret = -ENODEV;
-                       goto error_ret;
+       list_for_each_safe(pos, tmp, &iio_map_list) {
+               mapi = list_entry(pos, struct iio_map_internal, l);
+               if (indio_dev == mapi->indio_dev) {
+                       list_del(&mapi->l);
+                       kfree(mapi);
+                       ret = 0;
                }
-               i++;
        }
-error_ret:
        mutex_unlock(&iio_map_list_lock);
-
        return ret;
 }
 EXPORT_SYMBOL_GPL(iio_map_array_unregister);
index a4f8b2e05af5e4652c06bb092f7e0b5eba7b8dc1..7dfb10ee26698b7c63b3ee5733c21ed60a75bd97 100644 (file)
@@ -22,13 +22,10 @@ int iio_map_array_register(struct iio_dev *indio_dev,
                           struct iio_map *map);
 
 /**
- * iio_map_array_unregister() - tell the core to remove consumer mappings
+ * iio_map_array_unregister() - tell the core to remove consumer mappings for
+ *                             the given provider device
  * @indio_dev: provider device
- * @map:       array of mappings to remove. Note these must have same memory
- *             addresses as those originally added not just equal parameter
- *             values.
  */
-int iio_map_array_unregister(struct iio_dev *indio_dev,
-                            struct iio_map *map);
+int iio_map_array_unregister(struct iio_dev *indio_dev);
 
 #endif