From patchwork Mon May 18 16:55:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 11555837 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA2E014C0 for ; Mon, 18 May 2020 16:55:39 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9C7820758 for ; Mon, 18 May 2020 16:55:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AafM0h4q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9C7820758 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=o3iHjgvpdlOmX+gsuVNo0Hr5r0JWrwuXlBkQifQS9M8=; b=AafM0h4qLetmdY jrkI2rm4i0YjYG1vHH3wQS9np37JZnB1AzpZDJGUCTcYuodGJb/6+6H97JaKlAps2jxxuL4bxKEg3 sdI1vtiip5+qNr/V3mKgyp9Eu+LN3e9Dg/n67cUyI1z10ePobyqydDSFxe5sdyTo0gxP/D+uTTyGa CPaaM2eux0SUz3GKkxzP3z4lV6BcXxn/xVo+z3gNrUDFwX69UfCKMDK96kLubNWj73mVOBw2fOnKk hchk652NYdizEsTxaw1OzCcY3P6i+ThwuVEBoahLJcqpsM7CQGsFGgRejXOApYZfZ9++wm5VqUwjf 66pq5+Mx2sZADTLWuBxw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jaj3D-0003qY-HR; Mon, 18 May 2020 16:55:39 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jaj3A-0003oN-FX; Mon, 18 May 2020 16:55:38 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jaj33-0000jG-Ue; Mon, 18 May 2020 16:55:30 +0000 From: Colin King To: Matthias Brugger , Wolfram Sang , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH][next] i2c: mediatek: fix integer overflow on an integer multiplication Date: Mon, 18 May 2020 17:55:29 +0100 Message-Id: <20200518165529.57821-1-colin.king@canonical.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200518_095536_657594_6915F7E5 X-CRM114-Status: GOOD ( 11.00 ) X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-5.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [91.189.89.112 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [91.189.89.112 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Colin Ian King Currently the calculation of sample_ns is using a 32 bit integer multiplication and can potentially overflow. Fix this by making the constant a long long to use a 64 bit multiply and hence avoid an overflow. Addresses-Coverity: ("Unintentional integer overflow") Fixes: 5f1ae73d538a ("i2c: mediatek: Add i2c ac-timing adjust support") Signed-off-by: Colin Ian King --- drivers/i2c/busses/i2c-mt65xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c index 702061805925..c93492b997ce 100644 --- a/drivers/i2c/busses/i2c-mt65xx.c +++ b/drivers/i2c/busses/i2c-mt65xx.c @@ -551,7 +551,7 @@ static int mtk_i2c_check_ac_timing(struct mtk_i2c *i2c, const struct i2c_spec_values *spec; unsigned int su_sta_cnt, low_cnt, high_cnt, max_step_cnt; unsigned int sda_max, sda_min, clk_ns, max_sta_cnt = 0x3f; - long long sample_ns = (1000000000 * (sample_cnt + 1)) / clk_src; + long long sample_ns = (1000000000LL * (sample_cnt + 1)) / clk_src; if (!i2c->dev_comp->timing_adjust) return 0;