From patchwork Mon May 21 11:57:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie Yisheng X-Patchwork-Id: 10415013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 70C3C6032C for ; Mon, 21 May 2018 12:13:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 624B12843B for ; Mon, 21 May 2018 12:13:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56D40286BA; Mon, 21 May 2018 12:13:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E22222843B for ; Mon, 21 May 2018 12:13:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752934AbeEUMMj (ORCPT ); Mon, 21 May 2018 08:12:39 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7714 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752970AbeEUMJU (ORCPT ); Mon, 21 May 2018 08:09:20 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 7AB4213E7FC3C; Mon, 21 May 2018 20:09:06 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.382.0; Mon, 21 May 2018 20:08:57 +0800 From: Yisheng Xie To: CC: Yisheng Xie , Sebastian Reichel , Subject: [PATCH 18/33] power: supply: use match_string() helper Date: Mon, 21 May 2018 19:57:55 +0800 Message-ID: <1526903890-35761-19-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com> References: <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP match_string() returns the index of an array for a matching string, which can be used intead of open coded variant. Cc: Sebastian Reichel Cc: linux-pm@vger.kernel.org Signed-off-by: Yisheng Xie --- 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)