Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1141998imm; Wed, 1 Aug 2018 10:53:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfqoLVbWBI50Zx71KGodXUvlzrO+8hwDQn1iBLZIAYa0AlVuM9G3JHWEFptQAI+tX2Y+nfY X-Received: by 2002:a17:902:864b:: with SMTP id y11-v6mr26062758plt.335.1533145995867; Wed, 01 Aug 2018 10:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533145995; cv=none; d=google.com; s=arc-20160816; b=IHtHUiXqzsME/i7Imk3hhxCncWB/0pDX9AXregkG/VlEcIYa9iHCdrYlCt4N9p9kj8 POkT/I6UtXXFR0qwKBbLju4tX0mNcnqmJdDVXNyREmQ/xxRb4O6+jh6MmHrE7prk/+e1 smiXhWsRzyox6Ar2Sh7fQyperl+G/KAMRBepSjM9Y7tEqFXNL6NpDwHA50g00RNhLsLk gk5YoY1WwK03rLZ0GNL40h3ZA62MumlsXHi32e3jLjUlAz7YWtjWLvjmhPfk7d09bJh2 d8TnfE6idc0iodEJMWYhGmVd56UR/u9wDmqPhMap8xf/CsfGEv+ZR9Z1RBxA9WLUu7yZ O5zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=aKgLvMWDV5Ih1pbGXVWYTLi1fCXXasWDTyrTtnqInFs=; b=XopfmeDA+DhXEDGk87zlnnS8FmEdYnvAHUBpY5FVXW3XtmlUVwdq9UyW9azvutoB9U HBl5Mqazn9Od980Yysb+w4iMlE77HuPqyVeTVauUGgFi6o+5cJlHgioI+tn1BwqP0Oqs fTRHLaLxCg1orN9d2GRUESDmdnkRJdOLWn5CVCf3flMs9S6OXFT1t6RfZ/eWjfJ4bPNZ +TPgea2ujV4q/1V/m/oYTYX0lFi27yjDMfSa5o8zmpFF1Eq1Lnf8uaJRo+Ozb/tSNEoC 88K6rCYCE7ilr2VcK7GuhEffuSsYv4GckcX33vyilVq/QvbqlzZBA/1Bo8v1Y3B9wr7M YaVg== ARC-Authentication-Results: i=1; mx.google.com; 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 a18-v6si16444386plm.122.2018.08.01.10.53.00; Wed, 01 Aug 2018 10:53:15 -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; 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 S2390464AbeHATi2 (ORCPT + 99 others); Wed, 1 Aug 2018 15:38:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50216 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406046AbeHATIl (ORCPT ); Wed, 1 Aug 2018 15:08:41 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BCCB3D2F; Wed, 1 Aug 2018 17:21:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Javier Martinez Canillas , Douglas Anderson , Mark Brown , Sasha Levin Subject: [PATCH 4.14 203/246] regulator: Dont return or expect -errno from of_map_mode() Date: Wed, 1 Aug 2018 18:51:53 +0200 Message-Id: <20180801165021.441105529@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Douglas Anderson [ Upstream commit 02f3703934a42417021405ef336fe45add13c3d1 ] 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 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. Fixes: 5e5e3a42c653 ("regulator: of: Add support for parsing initial and suspend modes") Suggested-by: Javier Martinez Canillas Signed-off-by: Douglas Anderson Reviewed-by: Javier Martinez Canillas Signed-off-by: Mark Brown Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/regulator/cpcap-regulator.c | 2 +- drivers/regulator/of_regulator.c | 13 +++++++------ drivers/regulator/twl-regulator.c | 2 +- include/linux/regulator/consumer.h | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) --- a/drivers/regulator/cpcap-regulator.c +++ b/drivers/regulator/cpcap-regulator.c @@ -222,7 +222,7 @@ static unsigned int cpcap_map_mode(unsig case CPCAP_BIT_AUDIO_LOW_PWR: return REGULATOR_MODE_STANDBY; default: - return -EINVAL; + return REGULATOR_MODE_INVALID; } } --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -31,6 +31,7 @@ static void of_get_regulation_constraint struct regulation_constraints *constraints = &(*init_data)->constraints; struct regulator_state *suspend_state; struct device_node *suspend_np; + unsigned int mode; int ret, i; u32 pval; @@ -124,11 +125,11 @@ static void of_get_regulation_constraint 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) + 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,12 @@ static void of_get_regulation_constraint 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) + 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); --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c @@ -274,7 +274,7 @@ static inline unsigned int twl4030reg_ma case RES_STATE_SLEEP: return REGULATOR_MODE_STANDBY; default: - return -EINVAL; + return REGULATOR_MODE_INVALID; } } --- 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