power: ab8500: convert to use match_string() helper
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 17 Mar 2016 21:22:29 +0000 (14:22 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 17 Mar 2016 22:09:34 +0000 (15:09 -0700)
The new helper returns index of the mathing string in an array.  We
would use it here.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/power/ab8500_btemp.c
drivers/power/ab8500_charger.c
drivers/power/ab8500_fg.c
drivers/power/abx500_chargalg.c

index 8f8044e1acf33910dc495d30abde319a82cd8418..bf2e5dd301e7f791736674c6ee516e4c5c5779ca 100644 (file)
@@ -906,26 +906,21 @@ static int ab8500_btemp_get_property(struct power_supply *psy,
 static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
 {
        struct power_supply *psy;
-       struct power_supply *ext;
+       struct power_supply *ext = dev_get_drvdata(dev);
+       const char **supplicants = (const char **)ext->supplied_to;
        struct ab8500_btemp *di;
        union power_supply_propval ret;
-       int i, j;
-       bool psy_found = false;
+       int j;
 
        psy = (struct power_supply *)data;
-       ext = dev_get_drvdata(dev);
        di = power_supply_get_drvdata(psy);
 
        /*
         * For all psy where the name of your driver
         * appears in any supplied_to
         */
-       for (i = 0; i < ext->num_supplicants; i++) {
-               if (!strcmp(ext->supplied_to[i], psy->desc->name))
-                       psy_found = true;
-       }
-
-       if (!psy_found)
+       j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
+       if (j < 0)
                return 0;
 
        /* Go through all properties for the psy */
index e388171f4e587e8931ec44ca32e03b08cd916a0b..30de5d42b26af95905b1a07f10b6d69cb7bd0994 100644 (file)
@@ -1929,11 +1929,11 @@ static int ab8540_charger_usb_pre_chg_enable(struct ux500_charger *charger,
 static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data)
 {
        struct power_supply *psy;
-       struct power_supply *ext;
+       struct power_supply *ext = dev_get_drvdata(dev);
+       const char **supplicants = (const char **)ext->supplied_to;
        struct ab8500_charger *di;
        union power_supply_propval ret;
-       int i, j;
-       bool psy_found = false;
+       int j;
        struct ux500_charger *usb_chg;
 
        usb_chg = (struct ux500_charger *)data;
@@ -1941,15 +1941,9 @@ static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data)
 
        di = to_ab8500_charger_usb_device_info(usb_chg);
 
-       ext = dev_get_drvdata(dev);
-
        /* For all psy where the driver name appears in any supplied_to */
-       for (i = 0; i < ext->num_supplicants; i++) {
-               if (!strcmp(ext->supplied_to[i], psy->desc->name))
-                       psy_found = true;
-       }
-
-       if (!psy_found)
+       j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
+       if (j < 0)
                return 0;
 
        /* Go through all properties for the psy */
index 3830dade5d69d145a2fe79d0630f891c4f0936d3..5a36cf88578ac18a9305b1398ed888020dbefa0c 100644 (file)
@@ -2168,26 +2168,21 @@ static int ab8500_fg_get_property(struct power_supply *psy,
 static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
 {
        struct power_supply *psy;
-       struct power_supply *ext;
+       struct power_supply *ext = dev_get_drvdata(dev);
+       const char **supplicants = (const char **)ext->supplied_to;
        struct ab8500_fg *di;
        union power_supply_propval ret;
-       int i, j;
-       bool psy_found = false;
+       int j;
 
        psy = (struct power_supply *)data;
-       ext = dev_get_drvdata(dev);
        di = power_supply_get_drvdata(psy);
 
        /*
         * For all psy where the name of your driver
         * appears in any supplied_to
         */
-       for (i = 0; i < ext->num_supplicants; i++) {
-               if (!strcmp(ext->supplied_to[i], psy->desc->name))
-                       psy_found = true;
-       }
-
-       if (!psy_found)
+       j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
+       if (j < 0)
                return 0;
 
        /* Go through all properties for the psy */
index 541f702e0451c732b7d00efed27fd53f05b03b79..d9104b1ab7cfd765ae59bd71220f68f0df3e9adb 100644 (file)
@@ -975,22 +975,18 @@ static void handle_maxim_chg_curr(struct abx500_chargalg *di)
 static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
 {
        struct power_supply *psy;
-       struct power_supply *ext;
+       struct power_supply *ext = dev_get_drvdata(dev);
+       const char **supplicants = (const char **)ext->supplied_to;
        struct abx500_chargalg *di;
        union power_supply_propval ret;
-       int i, j;
-       bool psy_found = false;
+       int j;
        bool capacity_updated = false;
 
        psy = (struct power_supply *)data;
-       ext = dev_get_drvdata(dev);
        di = power_supply_get_drvdata(psy);
        /* For all psy where the driver name appears in any supplied_to */
-       for (i = 0; i < ext->num_supplicants; i++) {
-               if (!strcmp(ext->supplied_to[i], psy->desc->name))
-                       psy_found = true;
-       }
-       if (!psy_found)
+       j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
+       if (j < 0)
                return 0;
 
        /*