From patchwork Sun Nov 12 15:30:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 837197 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yZd611Nqzz9s9Y for ; Mon, 13 Nov 2017 02:31:19 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 67A88C21DDF; Sun, 12 Nov 2017 15:31:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 78245C21D55; Sun, 12 Nov 2017 15:31:10 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E8FF4C21D55; Sun, 12 Nov 2017 15:31:08 +0000 (UTC) Received: from mx.tkos.co.il (guitar.tcltek.co.il [192.115.133.116]) by lists.denx.de (Postfix) with ESMTPS id 78308C21C51 for ; Sun, 12 Nov 2017 15:31:08 +0000 (UTC) Received: from sapphire.lan (unknown [10.0.4.3]) by mx.tkos.co.il (Postfix) with ESMTPA id 3C54144059D; Sun, 12 Nov 2017 17:31:07 +0200 (IST) From: Baruch Siach To: Jagan Teki Date: Sun, 12 Nov 2017 17:30:57 +0200 Message-Id: X-Mailer: git-send-email 2.15.0 Cc: u-boot@lists.denx.de, Baruch Siach Subject: [U-Boot] [PATCH v2] spi: kirkwood: avoid divide by zero crash X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Calling .set_speed with zero speed is definitely a bug. Instead of crashing, set hz to 1 so that we get the lowest possible frequency rate. Signed-off-by: Baruch Siach --- v2: Don't fail; set lowest rate (Jagan) --- drivers/spi/kirkwood_spi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c index 0c6bd295cde9..5744849a5ad9 100644 --- a/drivers/spi/kirkwood_spi.c +++ b/drivers/spi/kirkwood_spi.c @@ -257,6 +257,9 @@ static int mvebu_spi_set_speed(struct udevice *bus, uint hz) struct kwspi_registers *reg = plat->spireg; u32 data; + /* Avoid divide by zero; instead, set the lowest possible speed */ + if (hz == 0) + hz = 1; /* calculate spi clock prescaller using max_hz */ data = ((CONFIG_SYS_TCLK / 2) / hz) + 0x10; data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data;