From patchwork Fri Jun 21 07:10:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 2760561 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C0AFDC0AB1 for ; Fri, 21 Jun 2013 07:13:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E5F97201C6 for ; Fri, 21 Jun 2013 07:13:35 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9E5072016A for ; Fri, 21 Jun 2013 07:13:33 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UpvVs-0008Qi-R8; Fri, 21 Jun 2013 07:12:05 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UpvVY-0001za-Pp; Fri, 21 Jun 2013 07:11:44 +0000 Received: from moutng.kundenserver.de ([212.227.17.8]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UpvV2-0001vl-0I for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2013 07:11:17 +0000 Received: from axis700.grange (dslb-084-061-108-118.pools.arcor-ip.net [84.61.108.118]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0Mh8wH-1UcMoT190r-00Mqyu; Fri, 21 Jun 2013 09:10:40 +0200 Received: from 6a.grange (6a.grange [192.168.1.11]) by axis700.grange (Postfix) with ESMTPS id B0ACD40BB5; Fri, 21 Jun 2013 09:10:39 +0200 (CEST) Received: from lyakh by 6a.grange with local (Exim 4.72) (envelope-from ) id 1UpvUU-0002kK-BF; Fri, 21 Jun 2013 09:10:38 +0200 From: Guennadi Liakhovetski To: linux-sh@vger.kernel.org Subject: [PATCH 1/4] ARM: shmobile: r8a73a4: safeguard against wrong clk_set_rate() uses Date: Fri, 21 Jun 2013 09:10:35 +0200 Message-Id: <1371798638-10530-2-git-send-email-g.liakhovetski@gmx.de> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1371798638-10530-1-git-send-email-g.liakhovetski@gmx.de> References: <1371798638-10530-1-git-send-email-g.liakhovetski@gmx.de> X-Provags-ID: V02:K0:142y5rtEYFz8M7d8vkUaVXrQsKOXdpMKjOMcHyQL1S4 BNQNQT/qKSLGEKTwdqz/V2DLu04jnQoWhw2Z8XeD435dt8HzFD ekli+hTiNx+xvbVZSRfe96tSE6vanPIRpqIsC7UuW6s+xxpbAb fk7pxrz4+Ee/cqI9YHBmwXTFaHJzPbk1MRop+59FpTEI75hGzy 4iVd77fccBHb7+Xu0oRI6D5dcyyrbASsiUq12K1Fun0w4JC3Xa bEOUz0KkDmBRaIlQhZ2XSKVcMLVH3VLKfEoXaHUDcqWhcnPBap b9QXDeF9YY1yQhoG61cTZVZdRRqT+OGkAdlVeLalCRWrG/ZTEY Tn7s+RAn1qgMGaphRSRcH4jHR8AsVhfqxNCWL9Ci6Ajb0btcuE KJOE3CB0JCOHA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130621_031112_330460_C4CF48B2 X-CRM114-Status: GOOD ( 13.10 ) X-Spam-Score: -3.2 (---) Cc: Guennadi Liakhovetski , Simon Horman , Magnus Damm , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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.7 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 clk_set_rate() should only be called with exact rates, returned by clk_round_rate(). However, it is still good to verify, that the value, passed to clock's .set_rate() method is at least valid. This patch adds such a check for the Z-clock on r8a73a4. Signed-off-by: Guennadi Liakhovetski --- arch/arm/mach-shmobile/clock-r8a73a4.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/arch/arm/mach-shmobile/clock-r8a73a4.c b/arch/arm/mach-shmobile/clock-r8a73a4.c index eb42740..cbf9852 100644 --- a/arch/arm/mach-shmobile/clock-r8a73a4.c +++ b/arch/arm/mach-shmobile/clock-r8a73a4.c @@ -225,16 +225,28 @@ static int zclk_set_rate(struct clk *clk, unsigned long rate) goto done; } - frqcrc = clk->mapped_reg + (FRQCRC - (u32)clk->enable_reg); + /* + * Users are supposed to first call clk_set_rate() only with + * clk_round_rate() results. So, we don't fix wrong rates here, but + * guard against them anyway + */ p_rate = clk_get_rate(clk->parent); if (rate == p_rate) { val = 0; } else { step = DIV_ROUND_CLOSEST(p_rate, 32); + + if (rate > p_rate || rate < step) { + ret = -EINVAL; + goto done; + } + val = 32 - rate / step; } + frqcrc = clk->mapped_reg + (FRQCRC - (u32)clk->enable_reg); + iowrite32((ioread32(frqcrc) & ~(clk->div_mask << clk->enable_bit)) | (val << clk->enable_bit), frqcrc);