Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp811766imm; Mon, 21 May 2018 14:58:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr+2eui6icHyGQ8/taeH/2XwXl4zauNFpet92SopwNVnT+FTgIVmp7+aUxvCFjA8xc8sfZW X-Received: by 2002:a63:798f:: with SMTP id u137-v6mr8989845pgc.202.1526939923060; Mon, 21 May 2018 14:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526939923; cv=none; d=google.com; s=arc-20160816; b=hjreP9WVcQwL4AM+VH+xm/BdZI7KYR/Y4NysBTW8rl7KSopHI18T1Fp2pds05K95qB W5NRh7SQfHKFeN39la6gzAouZZBZuhc7fFx3w3VqLijCwy8W5RxNFbV1VYQyE+F4pGuP E5e5Sj3p0Vd/RIVf/gBFupqa3s6FLt3uxyLroR12LCFLHLTaiU6fc3DgcTx1g23qjpUu 7BWPb0MRCpnChy5NfIdVP5DCNuIBRNHL2GKCRn1eCXOsoJoXhFq1V2iSQbm1r4MbZWwr cb7TFvtxTKuXs0eD1jLB4Wshjy0PSl1U3hnVYxtBbyl2DauC20Er4qmIDEqxRZomlo41 GMZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=diXdkzaPqQmxCbZ6hrbngBwxNiNDZT06IglilZkMiIU=; b=pItgo0YEF2xYHnUhciB9kD8BvzkrEQmvElh5+QsiFH2jgHztCmtzriSUBNqkbBzSrr N8RiDHnmFOgvr/Yoe+k9l2HEMI6UALyTDR5kboUpOJsQ48k60U0YU8YKqIuzG+pvsApR mGr0A/JuPTBQZSbQp3BMtlELNvfTvg5o01gdPhYfOdpXJH2XS4kEjH7q5gyt0IlF72G6 sw+2z2CqAdwHEcoVH5ZoX5xnjNr3PXsfeom9gswWodt1leVsynjdATCaJ9LYpYU8GDUh fmF8GkAY2k/Xkl+cYMm9Jg+p4pvxnpl0/UT+4WPikRjAl1oPOfDMs1eh2crINNlt/Xdd HwMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BHumnqGQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5-v6si11824246pgt.68.2018.05.21.14.58.28; Mon, 21 May 2018 14:58:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BHumnqGQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754230AbeEUV6U (ORCPT + 99 others); Mon, 21 May 2018 17:58:20 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:35732 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754047AbeEUV6P (ORCPT ); Mon, 21 May 2018 17:58:15 -0400 Received: by mail-qt0-f193.google.com with SMTP id f5-v6so20927025qth.2; Mon, 21 May 2018 14:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=diXdkzaPqQmxCbZ6hrbngBwxNiNDZT06IglilZkMiIU=; b=BHumnqGQFY6DvmJfidV5mow9GxqaH2MIemZTJqWFcyLSJpm+XlvEWGR9LdC4HMp1pn Y9aI9qt51SkGK7B4JdVp76vdQiN7JpVtWEFEvGzDs2CYWFvRszbbqSvZQwtZH0DOhy8H BnwUit4J/83rs4DyNeWd1XgiVgAuYFVg5sfpiCJWkjEnK64jGANOtWfXkTTgbY0e10+L fSuHtBnqkXB90tbC/bvdChsCbuG1kutQXMFfKeAvFhAepriQiNyZLZ89dmNSowMTHxFc /QVrLJSt7txLuFDrV2JCUW77b/SNRKdLvfJUkTLp+WAK2niGEy/Y66vc7dm1FrHtHx1G jLmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=diXdkzaPqQmxCbZ6hrbngBwxNiNDZT06IglilZkMiIU=; b=uegO1/9J0tUf+tGf/0mJwxzbacUopn9z4k1s48UTv9UJScyjM7J2V1mb+3tED9Ptgo yLP+3d6+sIuGJvIEleRGTg0n1MbvM4ER7/4kW2QaAS7/rF/nbOQ7kDB0cbB5vvUHIFOX d+17EOUC9Ov/+ZsNIyamRr2USZ/xZVAYGnUYXB6WQP43E54v6L7wDpoQ4cHkiuG9R55U 5RpuegCVVixJQPgyKEA4HccE7bZxua07rapQ1jDDx4oV/9WFThej4JaPvdSrdPk4I4tt 1hSzrhi1guL9ihWdcsZsH/DSrqyuIRwvCteL2WbEDV0LrLgab51tVRrti9k2L27YCECR xBZQ== X-Gm-Message-State: ALKqPweffekTHe1Lf+IOWawBObsa47d8bXxxP2A4dATnsWUPtxa0g90w OOd5NgmWYxmThwIHrpFlxzp4pQpthOJ8QFYkp7g= X-Received: by 2002:ac8:3487:: with SMTP id w7-v6mr20037090qtb.220.1526939894672; Mon, 21 May 2018 14:58:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.152.150 with HTTP; Mon, 21 May 2018 14:58:14 -0700 (PDT) In-Reply-To: <1526903890-35761-19-git-send-email-xieyisheng1@huawei.com> References: <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com> <1526903890-35761-19-git-send-email-xieyisheng1@huawei.com> From: Andy Shevchenko Date: Tue, 22 May 2018 00:58:14 +0300 Message-ID: Subject: Re: [PATCH 18/33] power: supply: use match_string() helper To: Yisheng Xie Cc: Linux Kernel Mailing List , Sebastian Reichel , Linux PM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie wrote: > match_string() returns the index of an array for a matching string, > which can be used intead of open coded variant. > This doesn't make code looks better anyhow. I even think it makes it worse to read. That's why I dropped my version of the change (and yes, I missed the type conversion which looks here just ugly). Sebastian, if my opinion makes any difference here, I would say NAK to this one. > 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) > -- > 1.7.12.4 > -- With Best Regards, Andy Shevchenko