From patchwork Fri Jul 28 13:22:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 9868767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AED8160382 for ; Fri, 28 Jul 2017 13:16:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A4D2288DC for ; Fri, 28 Jul 2017 13:16:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D2DA288FC; Fri, 28 Jul 2017 13:16:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7E8E288CB for ; Fri, 28 Jul 2017 13:16:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=VmKQynl8EwCRYFg1wZAZsulMZqCe9NZ6BlajDIl4gYs=; b=qh6 DruxwCJwerDpvCGUVY0YCnH+XnJtg9mxNfRFyEP9aZtdYDtQpbaYEAYVr1EozOH1qusNWYVxoVMJC 38ZIlfNxZqLtx3fJfqnNdfDLlt8XPqsFA6tNb77RE+q4YnNveaOJ0TjmsLn67R64s7fCw0XBnSfiX vOfGSGKH3DsheMaPw/ok6JO/C6j1kvsodhK6DTa9Tznovh7AjTvBucsdzo+GFgwBQbuOWmkvejQVM oA3X2ECgseMN1t9Yi+HI9cJjFHezUcouRZJXjnYpHM/RDp/IuNbPTh/O+n3qfmpY6/41WKz07XkjP v7Sfjitnjgtz9r7QsbQGxHwmjKwO1CA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1db58P-0003AA-C4; Fri, 28 Jul 2017 13:16:53 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1db58J-0002sX-VU for linux-arm-kernel@lists.infradead.org; Fri, 28 Jul 2017 13:16:51 +0000 Received: by mail-wm0-x234.google.com with SMTP id m85so21783030wma.0 for ; Fri, 28 Jul 2017 06:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexus-software-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=rpwL2jCrQkuTPYQXgXP7bJVenuqDd05VqZh0u/tdD3Y=; b=tb3ehTqhyxDn3Qs4tFzxPLoUCfyvldfd4omMUlq7+9ci/Xew/JXOMbS3TdDuFNvW8U iNZI3xAA3N9v5RLXobtnp9kxfC9nuMuKVFKEiYCUydUs8r8aqBQqTqscbfAqQ1v/u7iB +ahIuqJxNICUpIpAUzOm2mgtpreLd83HJH2n+7FVSUnHttZIzKGeREmBnQ8CHjkCoLAx Q1LBZfHVHiyTAGlHrGsHa4P2dYQLhbo2EtW+H9WvytQCeog4BjPhzxLn1VepdP6VY9rT dCU1AcXapMDBXghN9a0d6/9ZRcWJ+/hyqhbi3gPLfz9ThzTxT5/e0VfiJXxjrVau4vHB Q98Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rpwL2jCrQkuTPYQXgXP7bJVenuqDd05VqZh0u/tdD3Y=; b=BjtUbu2bP2AAtb/7tm6FfLDWzv59b1QtfoF4dPNtRAtRaHMR68U6dQtFngKR7zSaI6 vS5Om1r5/1s1F+0aPtHzUMvrNcVGcAx/5C6JZFhlm2QloMra4IN72iVR6ajJqrb9sWUu Ddu6hrvxp++9huvgYKmB23qrDAsxh8+ieriFp3qF4o+L6vDJfjeL8CAeGUoyhwx5M86D aAFyAa9yd1CapIvGXGDqFKkCaDVp6mVsqkSgVZWJ11ZFY1tchNk6j2TYKLEK7XAFevWe 8tP6MnAI3mN7aBwSvQqtQIpr7mxSijNIKWPnecANUcWTGEn1CZLmyASlitdKn+jvyTfL 6cSg== X-Gm-Message-State: AIVw110908lW5oY03nCLXx//uHL395lofw3uX7clpcLkkyCHlaGMGtSK uiB74e/3KwVqLyPL X-Received: by 10.80.137.131 with SMTP id g3mr6821395edg.125.1501247783848; Fri, 28 Jul 2017 06:16:23 -0700 (PDT) Received: from localhost.localdomain ([176.61.103.53]) by smtp.gmail.com with ESMTPSA id m59sm8170138ede.94.2017.07.28.06.16.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Jul 2017 06:16:23 -0700 (PDT) From: Bryan O'Donoghue To: boris.brezillon@free-electrons.com Subject: [PATCH] mtd: nand: sunxi: fix potential divide-by-zero error Date: Fri, 28 Jul 2017 14:22:57 +0100 Message-Id: <1501248177-575-1-git-send-email-pure.logic@nexus-software.ie> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170728_061648_228105_6BCAAE34 X-CRM114-Status: UNSURE ( 9.98 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, linux-kernel@vger.kernel.org, marek.vasut@gmail.com, wens@csie.org, linux-mtd@lists.infradead.org, cyrille.pitchen@wedev4u.fr, Bryan O'Donoghue , maxime.ripard@free-electrons.com, computersforpeace@gmail.com, dwmw2@infradead.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP clk_round_rate() can return <= 0. Currently the value returned by clk_round_rate() is used directly for a division. This patch introduces a guard to ensure a divide-by-zero or a divide by a negative number for that matter can't happen by bugging out returning -EINVAL if clk_round_rate() returns <= 0. Fixes: 2d43457f79e4 ("mtd: nand: sunxi: fix EDO mode selection") Signed-off-by: Bryan O'Donoghue --- drivers/mtd/nand/sunxi_nand.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c index d0b6f8f..6abd142 100644 --- a/drivers/mtd/nand/sunxi_nand.c +++ b/drivers/mtd/nand/sunxi_nand.c @@ -1728,6 +1728,10 @@ static int sunxi_nfc_setup_data_interface(struct mtd_info *mtd, int csline, */ chip->clk_rate = NSEC_PER_SEC / min_clk_period; real_clk_rate = clk_round_rate(nfc->mod_clk, chip->clk_rate); + if (real_clk_rate <= 0) { + dev_err(nfc->dev, "Unable to round clk %lu\n", chip->clk_rate); + return -EINVAL; + } /* * ONFI specification 3.1, paragraph 4.15.2 dictates that EDO data