Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp212140ybi; Thu, 13 Jun 2019 14:32:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiAWH/sXUECFOopZBsrdyUSdxvtURuHHQO+n89TtA6hhGo+nh5p2g14Bq8P//LgaXKqOQI X-Received: by 2002:a62:6083:: with SMTP id u125mr18096993pfb.208.1560461549351; Thu, 13 Jun 2019 14:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560461549; cv=none; d=google.com; s=arc-20160816; b=h7ud/JPfcWEH98JSs9Z716UbszGfQ+MUe41bXMjvJwWRIW8V0Wc1G9iwz5k5JAQi19 XbmrT+uB+27D3Ct3zV/nh9wLje540nGn8RFc0jyohMOjcJkW7C86G0tZoHLlA1gP6Ntr o4GHafJOkso2CYDflozTAysXpuj5V2doZdMu0N1KYtBPdEwwrIpleTOPetX9MTUT4eYJ wuN3R+PPUPaLIu9WPt8ZAUPuibkMDCze0XL7spp6uYka1Rw9m5hL98T80TGF+UVzICC2 nFhjLZwDCKLCLHlGBs8/Xl2Gan+z5bkWhPT9O3H65JyLlycY09oC4UEIuo02KguDP5eN 973w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ymOhlE+xa8t9JEEo9mNLV0I7BKApQL/CgsnjJcqWwnw=; b=KNPap2t789whMtsdsmYDFTQ7Z+pCpw3dYJLsgEAOWApKN/m9wuq/UPI0RIb16otLzX ZfFkL3BOR4IheZxmxFxdDR+emuVSc9SaiSVpgOKCI3gMLQNXu0C32uhYj2v1ZFk4ltVP d6+GVWSqvJ/R1KJX8UC0FcnoQUzqdkjLqwQbGzYw+Hyp335qGRatKGffgCpfUnWbe+JC 54EoK87O7TrWQDq273DsQpANpAL5Bckq6ET30W2DLPEamAljt5XHoWarFRaUJZYNaPEk F77GscYl/SMROFH/BqJ3WKiEMHmB6WhOMPkdpHh7Jae0F0kQtBfNzX9BFLmEtGqlb4+H IaFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W7F7meZm; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d62si639319pga.447.2019.06.13.14.32.14; Thu, 13 Jun 2019 14:32:29 -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=@linaro.org header.s=google header.b=W7F7meZm; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727066AbfFMVcE (ORCPT + 99 others); Thu, 13 Jun 2019 17:32:04 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40883 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbfFMVcE (ORCPT ); Thu, 13 Jun 2019 17:32:04 -0400 Received: by mail-pf1-f195.google.com with SMTP id p184so57519pfp.7 for ; Thu, 13 Jun 2019 14:32:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ymOhlE+xa8t9JEEo9mNLV0I7BKApQL/CgsnjJcqWwnw=; b=W7F7meZmql+xmtsD6F8SeYXfmxj4ZMwphRvRIL3/3538NCpxSWiZbIScibSMYMBClF 9ZGzcXlTIwjfTBg1NNgdVmrxiYNF1mDviKz8tX5gCGLknHfBAAjIjMngemnFdqAyFK0B Qe+6JV19LSXJFv4BG/z5tqga5W5pCLU1LddMNWJ4WkSkhuf4Xe2UvdM08TY4hrOCQbyq DGM8YDtQnyx2mUWyloVjyrMlita6lJzKoRW7Zeos5GwWM5i5dkC9CopLZE+vRxpGUKY8 7x28RrnXLWlKu+Re0A+TdMVOpqmFma0pRY4uJUHSDhXgY8SNQUyP8xhoIRWLP5K231yj DHUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ymOhlE+xa8t9JEEo9mNLV0I7BKApQL/CgsnjJcqWwnw=; b=Ou1lCf3q4FFwdj6+38Z6i4jy8YunqmaWRxlew5XrqB/IhCA8uXESXVYOZuvjxwHQ4M m9ZXPwP3ohGf5jspkFWemE2KVXohJF0ZqogfC66gqXAheswhXAjuE2kYqxCYBG51o5kf a1uIeh0Vg0TXC8ulO02IrymKTSZEIjt20a98KCwTEoSP4Mizj7KJ6ZPJeMegkMQZbCJ1 704PbudFXMVSt/SFx+5vZUfSjKvFERDlaL1/49hMUBALvUslycCfwGbmIfi/R2VmTHpL zAz/moNY57FSfBfW979q+S98LKP+rhPao35e/jexh/J3r9WQ0RsiZPjudFsFfZ/UyAGe oSqw== X-Gm-Message-State: APjAAAX6OayG05J+MNGxGuOY3aRsYOPQDC5Ecii1cD3NJklVAv14yOvu l50NlHMOMF2inri5gIgC/aQTKw== X-Received: by 2002:a63:5207:: with SMTP id g7mr31497760pgb.356.1560461522867; Thu, 13 Jun 2019 14:32:02 -0700 (PDT) Received: from minitux (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id 23sm574395pfn.176.2019.06.13.14.32.01 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 13 Jun 2019 14:32:02 -0700 (PDT) Date: Thu, 13 Jun 2019 14:32:00 -0700 From: Bjorn Andersson To: Jeffrey Hugo Cc: lgirdwood@gmail.com, broonie@kernel.org, agross@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v4 2/7] regulator: qcom_spmi: Refactor get_mode/set_mode Message-ID: <20190613213200.GC4814@minitux> References: <20190613212436.6940-1-jeffrey.l.hugo@gmail.com> <20190613212531.10452-1-jeffrey.l.hugo@gmail.com> <20190613212531.10452-2-jeffrey.l.hugo@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190613212531.10452-2-jeffrey.l.hugo@gmail.com> User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 13 Jun 14:25 PDT 2019, Jeffrey Hugo wrote: > spmi_regulator_common_get_mode and spmi_regulator_common_set_mode use > multi-level ifs which mirror a switch statement. Refactor to use a switch > statement to make the code flow more clear. > Reviewed-by: Bjorn Andersson > Signed-off-by: Jeffrey Hugo > --- > drivers/regulator/qcom_spmi-regulator.c | 26 +++++++++++++++++-------- > 1 file changed, 18 insertions(+), 8 deletions(-) > > diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c > index 42c429d50743..1b3383a24c9d 100644 > --- a/drivers/regulator/qcom_spmi-regulator.c > +++ b/drivers/regulator/qcom_spmi-regulator.c > @@ -911,13 +911,16 @@ static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev) > > spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, ®, 1); > > - if (reg & SPMI_COMMON_MODE_HPM_MASK) > - return REGULATOR_MODE_NORMAL; > + reg &= SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; > > - if (reg & SPMI_COMMON_MODE_AUTO_MASK) > + switch (reg) { > + case SPMI_COMMON_MODE_HPM_MASK: > + return REGULATOR_MODE_NORMAL; > + case SPMI_COMMON_MODE_AUTO_MASK: > return REGULATOR_MODE_FAST; > - > - return REGULATOR_MODE_IDLE; > + default: > + return REGULATOR_MODE_IDLE; > + } > } > > static int > @@ -925,12 +928,19 @@ spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode) > { > struct spmi_regulator *vreg = rdev_get_drvdata(rdev); > u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; > - u8 val = 0; > + u8 val; > > - if (mode == REGULATOR_MODE_NORMAL) > + switch (mode) { > + case REGULATOR_MODE_NORMAL: > val = SPMI_COMMON_MODE_HPM_MASK; > - else if (mode == REGULATOR_MODE_FAST) > + break; > + case REGULATOR_MODE_FAST: > val = SPMI_COMMON_MODE_AUTO_MASK; > + break; > + default: > + val = 0; > + break; > + } > > return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); > } > -- > 2.17.1 >