From patchwork Fri Apr 8 10:03:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 607948 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3qhFRV4ndNz9t3q for ; Fri, 8 Apr 2016 20:04:06 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754035AbcDHKEE (ORCPT ); Fri, 8 Apr 2016 06:04:04 -0400 Received: from sauhun.de ([89.238.76.85]:55764 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753756AbcDHKED (ORCPT ); Fri, 8 Apr 2016 06:04:03 -0400 Received: from p4fe257c7.dip0.t-ipconnect.de ([79.226.87.199]:39144 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1aoTGi-000766-9e; Fri, 08 Apr 2016 12:04:00 +0200 From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Zubair Lutfullah Kakakhel , Axel Lin , Wolfram Sang Subject: [PATCH] i2c: jz4780: really prevent potential division by zero Date: Fri, 8 Apr 2016 12:03:47 +0200 Message-Id: <1460109827-3608-1-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 2.7.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Make sure that 'ret' is populated before we leave and check the variable which is actually used as a divisor. Add missing '\n' while we are here. Reported-by: Axel Lin Signed-off-by: Wolfram Sang Fixes: 34cf2acdafaa ("i2c: jz4780: prevent potential division by zero") --- drivers/i2c/busses/i2c-jz4780.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c index 597408fc6834fc..ba14a863b451f9 100644 --- a/drivers/i2c/busses/i2c-jz4780.c +++ b/drivers/i2c/busses/i2c-jz4780.c @@ -770,12 +770,17 @@ static int jz4780_i2c_probe(struct platform_device *pdev) ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", &clk_freq); - if (ret || clk_freq == 0) { - dev_err(&pdev->dev, "clock-frequency not specified in DT"); + if (ret) { + dev_err(&pdev->dev, "clock-frequency not specified in DT\n"); goto err; } i2c->speed = clk_freq / 1000; + if (i2c->speed == 0) { + ret = -EINVAL; + dev_err(&pdev->dev, "clock-frequency minimum is 1000\n"); + goto err; + } jz4780_i2c_set_speed(i2c); dev_info(&pdev->dev, "Bus frequency is %d KHz\n", i2c->speed);