Received: by 10.192.165.156 with SMTP id m28csp920726imm; Wed, 18 Apr 2018 00:17:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx49XPzrwuKbkhhlILHavw6YDWrl3OXfVy4UsUYDTVx56QsjojXsOQMr7qdGohu8vL/EjjG7b X-Received: by 10.98.198.7 with SMTP id m7mr977834pfg.66.1524035835060; Wed, 18 Apr 2018 00:17:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524035835; cv=none; d=google.com; s=arc-20160816; b=prhVLvjoXcFerf3uE9p9NHTHw9dixmO2Ecu/6Y79tMbOuBuX39pW7Hg7XsaimIDOnD FLuGuM6W4LZzRgH4yHoJXtW7wFXPSPu8XFUh7stGIIBjKcEbzAFMs+CPkieCKBvt972U vMROyAUtatP/iI83kTVdBuzxuNLUrK2cFiV3S5GcrUgW3hDIpyF+yTcRyQpUp9qdfSsy YfAoN0LjZjfjCvwIJk6T4NS6Aqw7+kd6Q2os0uTjApUppsICbC4gRCerXKqhRzlVjSED U0jT9O5H2ZAbGebTnezTQ3eMM+W3Gvx9mIo3htDR13BaEXg1zCRbvLpT/467ohWfGKtE eS9Q== 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=MTeZ9uXD88bOvoI4DdaXxnKvPKF7G2P3o1o0suQbzlw=; b=R2xpFGet+y/8UjsCFolubqmlY4fkLg6TyIjqjC5E+86hISDA/ldWofgieP82ovnrOL 3srewlbuzVEgkDA+ZGJQC/+F2JQTpba0Fiq41MLUMKnLtV8JDJh/G4ud3Waeep/5Zfhl ZiCz0n+H6kqHZuZaVrvAvAetPCX97hMM2GiUa8VhFa1CX4nF/Vjkyxa5vLNt+IehNz2S 9Lwo1OPAqdS7b7RzqJkLgOomb2e8ObmMdxIDeGPrJoJsmxEyM1JJ+imCNp2d9dgohDUs TukJjvw3k/mYgdMwttu0YIDddTTZq4z76/LiTwhKE4y+x3Tvlz3DofU24Si78LDGAkQ9 vWZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dowhile0-org.20150623.gappssmtp.com header.s=20150623 header.b=EM5fu8ww; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j13si600129pgt.402.2018.04.18.00.17.01; Wed, 18 Apr 2018 00:17:14 -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=@dowhile0-org.20150623.gappssmtp.com header.s=20150623 header.b=EM5fu8ww; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753469AbeDRHPh (ORCPT + 99 others); Wed, 18 Apr 2018 03:15:37 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:51910 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752705AbeDRHPe (ORCPT ); Wed, 18 Apr 2018 03:15:34 -0400 Received: by mail-it0-f68.google.com with SMTP id z125-v6so249408itc.1 for ; Wed, 18 Apr 2018 00:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dowhile0-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=MTeZ9uXD88bOvoI4DdaXxnKvPKF7G2P3o1o0suQbzlw=; b=EM5fu8wwvKSiQGc4+7sYnq5VfZZxS2abeyeLyX8drR5aLIEtWiEHctwIrEJdu9ceQh z1Nl96hqYiJFFdCSYSFpXsfxyL46noBd6tyZ1wVpH7SsBAd/Ip9FFPPi4wMrmyReZYAm Q2SyjOEJN3pNwCr+v2rjNzebEJ6kMYimLv+qZagL2ZJnADv3RnsqgkUtxhsblARwas6T Q+gj5mTASTWPk3wLDV6miNmCO4rRQX54/5Q2YL/JETq7sEMWjLjyPnbiLN3COjJdc4Cq vFDGzqGFyBYe73eXAniVmvsat4W2+9ivczDpLN/p0sfYGS9mtR6xVHi1PH6lStU9oT5M 6z6g== 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=MTeZ9uXD88bOvoI4DdaXxnKvPKF7G2P3o1o0suQbzlw=; b=uQb6vfDexwWlrkGXayTXgrNWbgwbdb1hgdiY86/g4MA9hZU33sjzC3s44Ot/cVF6sx pZzc0jZrLzq54w1XKZ0GRxGDrtgsFLQbTCFFGlbChclNbts4vbWt1A6FJES8IO8s/ngH FfBpg5wfq5oH3OBUDwzQRJLx4aN6U+j2UrOfQvQayquh64isLzMGV/ZDmGSFdMVaRviM KGJMts3IS0iJiXSl4i0FDehkdC6lXURc4GHrX8/XIGg001qDfGj9bBqOpK3cDLfdcvtO 0WiHqxIcSgkpHRvs3tpqR+NhyEvzpXVzN3VFdjtwsn8cqQf7DB96IEaiBsadcHac6BZN ARAg== X-Gm-Message-State: ALQs6tDE/8ehhtvik3y/iecgztg1SjuB7zQtsq6YOOMrtIAC7ZuxjYtP 0fR3WYan3GR1uATSJUFF5EFiqbX7RDjMvuXueLo2GQ== X-Received: by 2002:a24:64c3:: with SMTP id t186-v6mr1125847itc.57.1524035733879; Wed, 18 Apr 2018 00:15:33 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:c70c:0:0:0:0:0 with HTTP; Wed, 18 Apr 2018 00:15:33 -0700 (PDT) X-Originating-IP: [90.77.100.34] In-Reply-To: <20180418033143.208986-1-dianders@chromium.org> References: <20180418033143.208986-1-dianders@chromium.org> From: Javier Martinez Canillas Date: Wed, 18 Apr 2018 09:15:33 +0200 Message-ID: Subject: Re: [PATCH v2] regulator: Don't return or expect -errno from of_map_mode() To: Douglas Anderson Cc: Mark Brown , David Collins , evgreen@chromium.org, swboyd@chromium.org, linux-omap@vger.kernel.org, Liam Girdwood , Tony Lindgren , Linux Kernel 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 Hi Doug, Patch looks good to me, I just have some minor comments. On Wed, Apr 18, 2018 at 5:31 AM, Douglas Anderson wrote: > In of_get_regulation_constraints() we were taking the result of > of_map_mode() (an unsigned int) and assigning it to an int. We were > then checking whether this value was -EINVAL. Some implementers of > of_map_mode() were returning -EINVAL (even though the return type of > their function needed to be unsigned int) because they needed to to s/to to/to > signal an error back to of_get_regulation_constraints(). > > In general in the regulator framework the mode is always referred to > as an unsigned int. While we could fix this to be a signed int (the > highest value we store in there right now is 0x8), it's actually > pretty clean to just define the regulator mode 0x0 (the lack of any > bits set) as an invalid mode. Let's do that. > > Suggested-by: Javier Martinez Canillas > Fixes: 5e5e3a42c653 ("regulator: of: Add support for parsing initial and suspend modes") > Signed-off-by: Douglas Anderson > --- > > Changes in v2: > - Use Javier's suggestion of defining 0x0 as invalid > > drivers/regulator/cpcap-regulator.c | 2 +- > drivers/regulator/of_regulator.c | 15 +++++++++------ > drivers/regulator/twl-regulator.c | 2 +- > include/linux/regulator/consumer.h | 1 + > 4 files changed, 12 insertions(+), 8 deletions(-) > > diff --git a/drivers/regulator/cpcap-regulator.c b/drivers/regulator/cpcap-regulator.c > index f541b80f1b54..bd910fe123d9 100644 > --- a/drivers/regulator/cpcap-regulator.c > +++ b/drivers/regulator/cpcap-regulator.c > @@ -222,7 +222,7 @@ static unsigned int cpcap_map_mode(unsigned int mode) > case CPCAP_BIT_AUDIO_LOW_PWR: > return REGULATOR_MODE_STANDBY; > default: > - return -EINVAL; > + return REGULATOR_MODE_INVALID; > } > } > > diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c > index f47264fa1940..22c02b7a338b 100644 > --- a/drivers/regulator/of_regulator.c > +++ b/drivers/regulator/of_regulator.c > @@ -124,11 +124,12 @@ static void of_get_regulation_constraints(struct device_node *np, > > if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) { > if (desc && desc->of_map_mode) { > - ret = desc->of_map_mode(pval); > - if (ret == -EINVAL) > + unsigned int mode = desc->of_map_mode(pval); I think the convention is to always declare local variables at the start of the function? Although I couldn't find anything in the coding style document... > + > + if (mode == REGULATOR_MODE_INVALID) > pr_err("%s: invalid mode %u\n", np->name, pval); > else > - constraints->initial_mode = ret; > + constraints->initial_mode = mode; > } else { > pr_warn("%s: mapping for mode %d not defined\n", > np->name, pval); > @@ -163,12 +164,14 @@ static void of_get_regulation_constraints(struct device_node *np, > if (!of_property_read_u32(suspend_np, "regulator-mode", > &pval)) { > if (desc && desc->of_map_mode) { > - ret = desc->of_map_mode(pval); > - if (ret == -EINVAL) > + unsigned int mode = desc->of_map_mode(pval); > + > + mode = desc->of_map_mode(pval); You are calling .of_map_mode and assigning the return value twice here. If you post a new version, feel free to add: Reviewed-by: Javier Martinez Canillas Best regards, Javier