lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1526903890-35761-19-git-send-email-xieyisheng1@huawei.com>
Date:   Mon, 21 May 2018 19:57:55 +0800
From:   Yisheng Xie <xieyisheng1@...wei.com>
To:     <linux-kernel@...r.kernel.org>
CC:     Yisheng Xie <xieyisheng1@...wei.com>,
        Sebastian Reichel <sre@...nel.org>, <linux-pm@...r.kernel.org>
Subject: [PATCH 18/33] power: supply: use match_string() helper

match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Sebastian Reichel <sre@...nel.org>
Cc: linux-pm@...r.kernel.org
Signed-off-by: Yisheng Xie <xieyisheng1@...wei.com>
---
 drivers/power/supply/power_supply_core.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index feac7b0..84da3a2 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -36,8 +36,6 @@
 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
 					 struct power_supply *supply)
 {
-	int i;
-
 	if (!supply->supplied_from && !supplier->supplied_to)
 		return false;
 
@@ -45,18 +43,16 @@ static bool __power_supply_is_supplied_by(struct power_supply *supplier,
 	if (supply->supplied_from) {
 		if (!supplier->desc->name)
 			return false;
-		for (i = 0; i < supply->num_supplies; i++)
-			if (!strcmp(supplier->desc->name, supply->supplied_from[i]))
-				return true;
+		return match_string((const char **)supply->supplied_from,
+				    supply->num_supplies,
+				    supplier->desc->name) >= 0;
 	} else {
 		if (!supply->desc->name)
 			return false;
-		for (i = 0; i < supplier->num_supplicants; i++)
-			if (!strcmp(supplier->supplied_to[i], supply->desc->name))
-				return true;
+		return match_string((const char **)supplier->supplied_to,
+				    supplier->num_supplicants,
+				    supply->desc->name) >= 0;
 	}
-
-	return false;
 }
 
 static int __power_supply_changed_work(struct device *dev, void *data)
-- 
1.7.12.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ