From patchwork Wed Apr 18 03:31:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10347345 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 7B9D860365 for ; Wed, 18 Apr 2018 03:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63BD5284D4 for ; Wed, 18 Apr 2018 03:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58342284E4; Wed, 18 Apr 2018 03:31:59 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 43534284D4 for ; Wed, 18 Apr 2018 03:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753165AbeDRDb4 (ORCPT ); Tue, 17 Apr 2018 23:31:56 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37920 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753031AbeDRDb4 (ORCPT ); Tue, 17 Apr 2018 23:31:56 -0400 Received: by mail-pg0-f67.google.com with SMTP id b5so195071pgv.5 for ; Tue, 17 Apr 2018 20:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=Hrt8paZPoUWZTQ9C2QnZ3nhsFm8X2DcnYI3biPoyuig=; b=mPVz1H87YFfNjEZIOcE4SQZ3fTSst9NYy3u0bxJagurX2awf0Q1UJeNwfwHppV+GRH ADFTa/rXDtEy68+bdkJHvNzE0Z5gTlBaeEDWuaoRe1siefHoBcYQAM4DiccQSacXyO3s w6TiwB6QJsGOuG7Rgi5guuPrAVBloNgHTdwOM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Hrt8paZPoUWZTQ9C2QnZ3nhsFm8X2DcnYI3biPoyuig=; b=SvitAgwWfAv9FWn+HEoxuJ/TcnPvDLk8ZJzrUsJeFYQRLoWOt1BkJv3ssmf1kNeGP8 OlmOjx7tdjtozqMP2JQQI2vNZANVigv5XRkBMXTua7V8KAaxjBUVHExh/RCi63qCLPdq lymTp4jjkXV0hwQzi1pdvIg0TjWCvaEqJV5BTJAzrKEdlBu9VilsB25WdbFBafjPummC NGLY8tN9NR4gSrhzHrotzlmU7SyaksP7FL2PK80qcpey5w3MDDQe1BKGDyb9pg1g4Mei zfNgilNGzl18Rawc3VhfeHMCBaHrp1iLYo3kTNEnsbBV1hzc1v9cPVolPU94Lc7TnbD5 52Zg== X-Gm-Message-State: ALQs6tBsAtQNfwcuHRjtpkj19sQsAEvpDeqYaZ2jfA5Ryp3rV4WIycPP gG+VT1GLk01ph1S/SZr9oS6blw== X-Google-Smtp-Source: AIpwx4+MbDaEJk+KQqoVCTn6GcHxRzJr/RTa1tdP6xvKIj//21xm2wiCus1u/KrLkzznkHcSjzbG5A== X-Received: by 10.98.236.4 with SMTP id k4mr426053pfh.240.1524022315534; Tue, 17 Apr 2018 20:31:55 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:0:1000:1511:bde7:107f:fd5:44c8]) by smtp.gmail.com with ESMTPSA id b17sm313921pgu.63.2018.04.17.20.31.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 20:31:54 -0700 (PDT) From: Douglas Anderson To: broonie@kernel.org Cc: David Collins , Javier Martinez Canillas , evgreen@chromium.org, swboyd@chromium.org, Douglas Anderson , linux-omap@vger.kernel.org, Liam Girdwood , Tony Lindgren , linux-kernel@vger.kernel.org Subject: [PATCH v2] regulator: Don't return or expect -errno from of_map_mode() Date: Tue, 17 Apr 2018 20:31:43 -0700 Message-Id: <20180418033143.208986-1-dianders@chromium.org> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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 Reviewed-by: Javier Martinez Canillas --- 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); + + 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); + if (mode == REGULATOR_MODE_INVALID) pr_err("%s: invalid mode %u\n", np->name, pval); else - suspend_state->mode = ret; + suspend_state->mode = mode; } else { pr_warn("%s: mapping for mode %d not defined\n", np->name, pval); diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index a4456db5849d..884c7505ed91 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c @@ -274,7 +274,7 @@ static inline unsigned int twl4030reg_map_mode(unsigned int mode) case RES_STATE_SLEEP: return REGULATOR_MODE_STANDBY; default: - return -EINVAL; + return REGULATOR_MODE_INVALID; } } diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index df176d7c2b87..25602afd4844 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -80,6 +80,7 @@ struct regmap; * These modes can be OR'ed together to make up a mask of valid register modes. */ +#define REGULATOR_MODE_INVALID 0x0 #define REGULATOR_MODE_FAST 0x1 #define REGULATOR_MODE_NORMAL 0x2 #define REGULATOR_MODE_IDLE 0x4