From patchwork Fri Feb 2 09:22:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 10196419 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 C86DF60388 for ; Fri, 2 Feb 2018 09:23:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8E2A28E03 for ; Fri, 2 Feb 2018 09:23:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADAA628E13; Fri, 2 Feb 2018 09:23:05 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 020B328E03 for ; Fri, 2 Feb 2018 09:23:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751221AbeBBJXC (ORCPT ); Fri, 2 Feb 2018 04:23:02 -0500 Received: from nblzone-211-213.nblnetworks.fi ([83.145.211.213]:55582 "EHLO hillosipuli.retiisi.org.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750799AbeBBJXA (ORCPT ); Fri, 2 Feb 2018 04:23:00 -0500 Received: from valkosipuli.localdomain (valkosipuli.retiisi.org.uk [IPv6:2001:1bc8:1a6:d3d5::80:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by hillosipuli.retiisi.org.uk (Postfix) with ESMTPS id 59486600F6; Fri, 2 Feb 2018 11:22:58 +0200 (EET) Received: from sakke by valkosipuli.localdomain with local (Exim 4.89) (envelope-from ) id 1ehXYf-00014X-QJ; Fri, 02 Feb 2018 11:22:57 +0200 Date: Fri, 2 Feb 2018 11:22:57 +0200 From: Sakari Ailus To: "Gustavo A. R. Silva" Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: Re: [PATCH 4/8] i2c: ov9650: fix potential integer overflow in __ov965x_set_frame_interval Message-ID: <20180202092257.xknpdvc4bcrg4dyi@valkosipuli.retiisi.org.uk> References: <8ccf6acf10745fd1b9f33a7cacd5365e125633bf.1517268668.git.gustavo@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <8ccf6acf10745fd1b9f33a7cacd5365e125633bf.1517268668.git.gustavo@embeddedor.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Jan 29, 2018 at 06:32:01PM -0600, Gustavo A. R. Silva wrote: > Cast fi->interval.numerator to u64 in order to avoid a potential integer > overflow. This variable is being used in a context that expects an > expression of type u64. > > Addresses-Coverity-ID: 1324146 ("Unintentional integer overflow") > Signed-off-by: Gustavo A. R. Silva > --- > drivers/media/i2c/ov9650.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c > index e519f27..c674a49 100644 > --- a/drivers/media/i2c/ov9650.c > +++ b/drivers/media/i2c/ov9650.c > @@ -1130,7 +1130,7 @@ static int __ov965x_set_frame_interval(struct ov965x *ov965x, > if (fi->interval.denominator == 0) > return -EINVAL; > > - req_int = (u64)(fi->interval.numerator * 10000) / > + req_int = (u64)fi->interval.numerator * 10000 / > fi->interval.denominator; This requires do_div(). I've applied the patch with this change: > > for (i = 0; i < ARRAY_SIZE(ov965x_intervals); i++) { > -- > 2.7.4 > diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c index 88276dba828d..5bea31cd41aa 100644 --- a/drivers/media/i2c/ov9650.c +++ b/drivers/media/i2c/ov9650.c @@ -1136,8 +1136,8 @@ static int __ov965x_set_frame_interval(struct ov965x *ov965x, if (fi->interval.denominator == 0) return -EINVAL; - req_int = (u64)fi->interval.numerator * 10000 / - fi->interval.denominator; + req_int = (u64)fi->interval.numerator * 10000; + do_div(req_int, fi->interval.denominator); for (i = 0; i < ARRAY_SIZE(ov965x_intervals); i++) { const struct ov965x_interval *iv = &ov965x_intervals[i];