From patchwork Thu Sep 4 12:01:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 36696 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f199.google.com (mail-yk0-f199.google.com [209.85.160.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8F7B6202E4 for ; Thu, 4 Sep 2014 12:03:13 +0000 (UTC) Received: by mail-yk0-f199.google.com with SMTP id 20sf15151579yks.2 for ; Thu, 04 Sep 2014 05:03:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=vvMnm79Lv6ndu9n06EmSUXJBDNCJcWQ1QswFQDqKRac=; b=TQ5mX7wH6MyuTA9Wx+5MKsbis7UA6ajne3xClt+pMHITODa0xVB92R7TXeyd3kE9ct tlH02EDmNDvPwqujTgGRfqGLLebnUmL+5TpB74Hq0Iu+U3pvq55oAj+8ZNgD7CvhChYO 1EFXg1x5XVC9zQIzqmSmnWZ8UeouyHyGoVN9f1XlLnGEKqkdiSlag1PS67VSOTj7t/7/ JOUj/jAIoODlml6y5ruL5aZ6bh2qx0i48w+1Qi42Xj9ysPTJz040qSi2OAskw9jAIqn9 IWkhVUBipfXwv1ks4gmimlwcrCEpr9ATJ1FEBPmARuF0vUmisaHi1hIoFyUZiUawyf8M uiWw== X-Gm-Message-State: ALoCoQlM8x5o7hwOLl0aKL1P85Zli3J4L6aiKoFawQ8421zoKwgIulbl90/SS8CjYP1TWmJNzWoF X-Received: by 10.236.118.195 with SMTP id l43mr2097928yhh.52.1409832193417; Thu, 04 Sep 2014 05:03:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.131 with SMTP id m3ls239729qge.93.gmail; Thu, 04 Sep 2014 05:03:13 -0700 (PDT) X-Received: by 10.52.51.203 with SMTP id m11mr384616vdo.72.1409832193342; Thu, 04 Sep 2014 05:03:13 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id yv8si5476961vcb.5.2014.09.04.05.03.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Sep 2014 05:03:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id im17so10554136vcb.13 for ; Thu, 04 Sep 2014 05:03:13 -0700 (PDT) X-Received: by 10.220.77.65 with SMTP id f1mr482863vck.48.1409832193268; Thu, 04 Sep 2014 05:03:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp824351vcb; Thu, 4 Sep 2014 05:03:12 -0700 (PDT) X-Received: by 10.66.121.137 with SMTP id lk9mr8112547pab.86.1409832192407; Thu, 04 Sep 2014 05:03:12 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lp3si3076549pab.230.2014.09.04.05.03.07 for ; Thu, 04 Sep 2014 05:03:08 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753920AbaIDMCx (ORCPT + 15 others); Thu, 4 Sep 2014 08:02:53 -0400 Received: from mail-pd0-f178.google.com ([209.85.192.178]:46517 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753774AbaIDMCw (ORCPT ); Thu, 4 Sep 2014 08:02:52 -0400 Received: by mail-pd0-f178.google.com with SMTP id y13so13421498pdi.23 for ; Thu, 04 Sep 2014 05:02:49 -0700 (PDT) X-Received: by 10.66.249.34 with SMTP id yr2mr7508957pac.149.1409832168713; Thu, 04 Sep 2014 05:02:48 -0700 (PDT) Received: from localhost ([122.167.123.172]) by mx.google.com with ESMTPSA id h4sm1572893pat.11.2014.09.04.05.02.47 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 04 Sep 2014 05:02:48 -0700 (PDT) From: Viresh Kumar To: sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, anton@enomsg.org Cc: linux-pm@vger.kernel.org, linaro-kernel@lists.linaro.org, Viresh Kumar Subject: [PATCH 09/15] power-supply: Don't return -EINVAL from __power_supply_find_supply_from_node() Date: Thu, 4 Sep 2014 17:31:30 +0530 Message-Id: X-Mailer: git-send-email 2.0.3.693.g996b0fd In-Reply-To: <2eacd908a8094887cc1796f75ae0513be8a3e36d.1409831636.git.viresh.kumar@linaro.org> References: <2eacd908a8094887cc1796f75ae0513be8a3e36d.1409831636.git.viresh.kumar@linaro.org> In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , We need to stop 'class_for_each_device' loop when a supply matches with the of-node. In order to achieve this we currently return -EINVAL from __power_supply_populate_supplied_from() on successful match. class_for_each_device() is free to return similar errors in other cases as well and so the choice of return value here isn't particularly great. This commit isn't removing the Hack but making it more elegant by returning '1' instead. Also power_supply_find_supply_from_node() can return errors other than -EPROBE_DEFER now if class_for_each_device() fails. Signed-off-by: Viresh Kumar --- drivers/power/power_supply_core.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index ab1cf8b..55140eb 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -161,9 +161,9 @@ static int __power_supply_find_supply_from_node(struct device *dev, struct device_node *np = data; struct power_supply *epsy = dev_get_drvdata(dev); - /* return error breaks out of class_for_each_device loop */ + /* returning non-zero breaks out of class_for_each_device loop */ if (epsy->of_node == np) - return -EINVAL; + return 1; return 0; } @@ -186,15 +186,19 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node) return -EPROBE_DEFER; /* - * We have to treat the return value as inverted, because if - * we return error on not found, then it won't continue looking. - * So we trick it by returning error on success to stop looking - * once the matching device is found. + * class_for_each_device() either returns its own errors or values + * returned by __power_supply_find_supply_from_node(). + * + * __power_supply_find_supply_from_node() will return 0 (no match) + * or 1 (match). + * + * We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if + * it returned 0, or error as returned by it. */ error = class_for_each_device(power_supply_class, NULL, supply_node, __power_supply_find_supply_from_node); - return error ? 0 : -EPROBE_DEFER; + return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER; } static int power_supply_check_supplies(struct power_supply *psy)