From patchwork Wed Jun 8 09:21:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 69618 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2390662qgf; Wed, 8 Jun 2016 02:24:30 -0700 (PDT) X-Received: by 10.98.83.6 with SMTP id h6mr4782233pfb.6.1465377870044; Wed, 08 Jun 2016 02:24:30 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id k74si425881pfb.191.2016.06.08.02.24.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jun 2016 02:24:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bAZhh-0008QQ-A8; Wed, 08 Jun 2016 09:23:13 +0000 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bAZgR-0007Ep-Ba for linux-arm-kernel@lists.infradead.org; Wed, 08 Jun 2016 09:21:57 +0000 Received: by mail-wm0-x22e.google.com with SMTP id n184so172145036wmn.1 for ; Wed, 08 Jun 2016 02:21:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uz2qbrLUspX4g+Qj0jiimi9vZi7fY1+M+c82u/n2Atk=; b=WqnwnC5uBSbhRRWoxLrLfIlJ0BhOFmLEFiytY/mdvxLoS+YyiRLtxNGUK1tajhv7II Sc205KXKi6AIjHOeWegTyey8Q63pZIKKeuepf/g49eZ+H/cfk6rSSK8omAvT1Oh9j0rd 28r2G/cLb+OKAVf7JALaAlSy22zmMYl/Cteqg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uz2qbrLUspX4g+Qj0jiimi9vZi7fY1+M+c82u/n2Atk=; b=dpJClbkSIWDFBxxngg/Db5FEuRmU1l+L9xwlPKIrdx03lB46a6u63zAGjhuOOd7UFS oINHvJ+N89FVCu8n3f/eroQHLrhFkg8w8IEtnqhjdi0Om1MSU7THe/laQ95zYb4NGfB1 XVY9RWxhKE8ZWLt1x+Q5exVKIw6OvrtznRXjQnYP67WBpWeio3IsQMOsCJ2EfEqEgLRr Z9+dxYeYzV6v1pLqpM5icg+smdFrIUEwjkMJAi6jBpbiE6sBOwklH3dRLYhZjaMNTwtz SRmrRzHiW0JI0+j5XWuzt+BvNcBZJs4tJCd2Ib5gU8dBb43q0xBrkOahKh1e8qn8JAwX kXYg== X-Gm-Message-State: ALyK8tLUo9J4JaDjk+LfQm2xHTdB2aM2qKScuFb4osyfkVM5ZyQWxt+kTIsHRT0M7o9PCy+Y X-Received: by 10.194.90.177 with SMTP id bx17mr3384293wjb.107.1465377696784; Wed, 08 Jun 2016 02:21:36 -0700 (PDT) Received: from localhost.localdomain (host81-129-171-215.range81-129.btcentralplus.com. [81.129.171.215]) by smtp.gmail.com with ESMTPSA id g192sm23694494wme.15.2016.06.08.02.21.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jun 2016 02:21:36 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 12/20] pwm: sti: Only request clock rate when you need to Date: Wed, 8 Jun 2016 10:21:27 +0100 Message-Id: <20160608092135.21184-13-lee.jones@linaro.org> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160608092135.21184-1-lee.jones@linaro.org> References: <20160608092135.21184-1-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160608_022155_732125_AB75DFE4 X-CRM114-Status: GOOD ( 15.89 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:22e listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, kernel@stlinux.com, devicetree@vger.kernel.org, patrice.chotard@st.com, robh+dt@kernel.org, thierry.reding@gmail.com, Lee Jones , maxime.coquelin@st.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org In the original code the clock rate was only obtained during initialisation; however, the rate may change between then and its use. This patch ensures the correct rate is acquired just before use. Signed-off-by: Lee Jones --- drivers/pwm/pwm-sti.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) -- 2.8.3 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c index 5fbee61..c4a34af 100644 --- a/drivers/pwm/pwm-sti.c +++ b/drivers/pwm/pwm-sti.c @@ -51,7 +51,6 @@ struct sti_pwm_compat_data { struct sti_pwm_chip { struct device *dev; - unsigned long clk_rate; struct clk *pwm_clk; struct regmap *regmap; struct sti_pwm_compat_data *cdata; @@ -86,13 +85,20 @@ static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period, unsigned int *prescale) { struct sti_pwm_compat_data *cdata = pc->cdata; + unsigned long clk_rate; unsigned long val; unsigned int ps; + clk_rate = clk_get_rate(pc->pwm_clk); + if (!clk_rate) { + dev_err(pc->dev, "failed to get clock rate\n"); + return -EINVAL; + } + /* * prescale = ((period_ns * clk_rate) / (10^9 * (max_pwm_count + 1)) - 1 */ - val = NSEC_PER_SEC / pc->clk_rate; + val = NSEC_PER_SEC / clk_rate; val *= cdata->max_pwm_cnt + 1; if (period % val) { @@ -353,12 +359,6 @@ static int sti_pwm_probe(struct platform_device *pdev) return PTR_ERR(pc->pwm_clk); } - pc->clk_rate = clk_get_rate(pc->pwm_clk); - if (!pc->clk_rate) { - dev_err(dev, "failed to get clock rate\n"); - return -EINVAL; - } - ret = clk_prepare(pc->pwm_clk); if (ret) { dev_err(dev, "failed to prepare clock\n");