From patchwork Fri Apr 22 10:18:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 8908921 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 78BE29F1D3 for ; Fri, 22 Apr 2016 10:21:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 524BF20254 for ; Fri, 22 Apr 2016 10:21:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 76D8C2024F for ; Fri, 22 Apr 2016 10:21:28 +0000 (UTC) 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 1atYBg-0001DY-Ak; Fri, 22 Apr 2016 10:19:48 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1atYAh-00008K-5g for linux-arm-kernel@lists.infradead.org; Fri, 22 Apr 2016 10:18:49 +0000 Received: by mail-wm0-x232.google.com with SMTP id u206so19368562wme.1 for ; Fri, 22 Apr 2016 03:18:26 -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=6V8OYBiVXUiHXvQcO7deYXY5F8XNq+HEa3BBbL/+4Wg=; b=hsXn+0vVpv2A+JLc75No15pSsw1NHVNtwk5c2/z9rOo/YGJ6U9BO3/CHik5fvUH2XV LOFWgzVsbBe+BRNdLUmmO2DD2VOKDgLi11HpbUM43e/ADYZgxefHVcT0pno9k2Jy3UwY 3qFPWp37aCG6z6AyDtxwfkqgV7lo3EfyPM+QE= 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=6V8OYBiVXUiHXvQcO7deYXY5F8XNq+HEa3BBbL/+4Wg=; b=UD3ORPVLIQcgoWrGfICUrb6VV4WepQgvmLj2VFcS2P9x9xO9xFcAeIdtmafjIWYbAf r6PblpwUMXFdEN6z0Hi2Lf7d0tokDCWDVUtvF2XvN29lsMTnz66bCOoVUthSNZZHNEXR d3/UDj5+8HqwU+92grCakNJTH9C5YhW6CoujN/O9Ej3/ll1LSEr0GcJhEW8r+7ggs/T3 3ARQY9CmbukJWChiz0HJ9df+id0xIe/QlWfVcBISTMmo0IkIQl+LvpfxvqQA8pMhZZdd Wg8TCXFTDKSsbP10/aBct8mDhTeAhoz288kM5Hd2JD619Q2w48O/dOxDDN+xPoOnuEs9 vdZQ== X-Gm-Message-State: AOPr4FVhX1kqSorQbV+EBarfvA+6zBcgjYbVxk1+NyqV5Dnal2vFGBnqxI4zD7PMtJGlcOUd X-Received: by 10.28.165.216 with SMTP id o207mr2770042wme.31.1461320305406; Fri, 22 Apr 2016 03:18:25 -0700 (PDT) Received: from dell.localdomain (host81-129-172-5.range81-129.btcentralplus.com. [81.129.172.5]) by smtp.gmail.com with ESMTPSA id a1sm7316345wje.43.2016.04.22.03.18.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2016 03:18:24 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [[PATCH v2] 05/11] pwm: sti: Only request clock rate when you need to Date: Fri, 22 Apr 2016 11:18:09 +0100 Message-Id: <1461320295-20414-6-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1461320295-20414-1-git-send-email-lee.jones@linaro.org> References: <1461320295-20414-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160422_031847_506335_1EF5C18D X-CRM114-Status: GOOD ( 14.71 ) X-Spam-Score: -2.7 (--) 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, ajitpal.singh@st.com, thierry.reding@gmail.com, Lee Jones , maxime.coquelin@st.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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");