Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1304527

[PATCH v3 5/9] power: charger_manager: convert to use match_string() helper

From Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Newsgroups linux.kernel
Subject [PATCH v3 5/9] power: charger_manager: convert to use match_string() helper
Date 2016-01-08 14:20 +0100
Message-ID <qOF7s-7eQ-37@gated-at.bofh.it> (permalink)
References <qOEXL-7an-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---
 drivers/power/charger-manager.c | 27 ++++-----------------------
 1 file changed, 4 insertions(+), 23 deletions(-)

diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index 1ea5d1a..e664ca7 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -2020,27 +2020,6 @@ static void __exit charger_manager_cleanup(void)
 module_exit(charger_manager_cleanup);
 
 /**
- * find_power_supply - find the associated power_supply of charger
- * @cm: the Charger Manager representing the battery
- * @psy: pointer to instance of charger's power_supply
- */
-static bool find_power_supply(struct charger_manager *cm,
-			struct power_supply *psy)
-{
-	int i;
-	bool found = false;
-
-	for (i = 0; cm->desc->psy_charger_stat[i]; i++) {
-		if (!strcmp(psy->desc->name, cm->desc->psy_charger_stat[i])) {
-			found = true;
-			break;
-		}
-	}
-
-	return found;
-}
-
-/**
  * cm_notify_event - charger driver notify Charger Manager of charger event
  * @psy: pointer to instance of charger's power_supply
  * @type: type of charger event
@@ -2057,9 +2036,11 @@ void cm_notify_event(struct power_supply *psy, enum cm_event_types type,
 
 	mutex_lock(&cm_list_mtx);
 	list_for_each_entry(cm, &cm_list, entry) {
-		found_power_supply = find_power_supply(cm, psy);
-		if (found_power_supply)
+		if (match_string(cm->desc->psy_charger_stat, -1,
+				 psy->desc->name) >= 0) {
+			found_power_supply = true;
 			break;
+		}
 	}
 	mutex_unlock(&cm_list_mtx);
 
-- 
2.6.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 0/9] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-08 14:20 +0100
  [PATCH v3 5/9] power: charger_manager: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-08 14:20 +0100
  [PATCH v3 6/9] power: ab8500: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-08 14:20 +0100
  Re: [PATCH v3 0/9] lib/string: introduce match_string() helper Al Viro <viro@ZenIV.linux.org.uk> - 2016-01-08 14:20 +0100
    Re: [PATCH v3 0/9] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-08 15:20 +0100

csiph-web