mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Subject: [PATCH v3 3/8] i2c: max2175: use 64-bit arithmetic instead of 32-bit
Date: Tue, 6 Feb 2018 10:47:37 -0600	[thread overview]
Message-ID: <fdeffeff7451f52fd903e4773c6b10fe21f707e4.1517929336.git.gustavo@embeddedor.com> (raw)
In-Reply-To: <cover.1517929336.git.gustavo@embeddedor.com>

Add suffix LL to constant 2 in order to give the compiler complete
information about the proper arithmetic to use. Notice that this
constant is used in a context that expects an expression of type
s64 (64 bits, signed).

The expression 2 * (clock_rate - abs_nco_freq) is currently being
evaluated using 32-bit arithmetic.

Addresses-Coverity-ID: 1446589 ("Unintentional integer overflow")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
Changes in v2:
 - Update subject and changelog to better reflect the proposed code changes.
 - Add suffix LL to constant instead of casting a variable.

Changes in v3:
 - Mention the specific Coverity report in the commit message.

 drivers/media/i2c/max2175.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/max2175.c b/drivers/media/i2c/max2175.c
index 2f1966b..87cba15 100644
--- a/drivers/media/i2c/max2175.c
+++ b/drivers/media/i2c/max2175.c
@@ -643,7 +643,7 @@ static int max2175_set_nco_freq(struct max2175 *ctx, s32 nco_freq)
 	if (abs_nco_freq < clock_rate / 2) {
 		nco_val_desired = 2 * nco_freq;
 	} else {
-		nco_val_desired = 2 * (clock_rate - abs_nco_freq);
+		nco_val_desired = 2LL * (clock_rate - abs_nco_freq);
 		if (nco_freq < 0)
 			nco_val_desired = -nco_val_desired;
 	}
-- 
2.7.4

  parent reply	other threads:[~2018-02-06 16:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-06 16:46 [PATCH v3 0/8] " Gustavo A. R. Silva
2018-02-06 16:46 ` [PATCH v3 1/8] rtl2832: use 64-bit arithmetic instead of 32-bit in rtl2832_set_frontend Gustavo A. R. Silva
2018-02-06 16:47 ` [PATCH v3 2/8] dvb-frontends: ves1820: use 64-bit arithmetic instead of 32-bit Gustavo A. R. Silva
2018-02-06 16:47 ` Gustavo A. R. Silva [this message]
2018-02-06 16:47 ` [PATCH v3 4/8] i2c: ov9650: " Gustavo A. R. Silva
2018-02-07 21:59   ` Sakari Ailus
2018-02-08 16:39     ` Gustavo A. R. Silva
2018-02-15 13:52       ` Hans Verkuil
2018-02-15 16:12         ` Gustavo A. R. Silva
2018-02-06 16:49 ` [PATCH v3 5/8] pci: cx88-input: " Gustavo A. R. Silva
2018-02-06 16:51 ` [PATCH v3 6/8] rockchip/rga: " Gustavo A. R. Silva
2018-02-06 16:52 ` [PATCH v3 7/8] platform: sh_veu: " Gustavo A. R. Silva
2018-02-06 16:53 ` [PATCH v3 8/8] platform: vivid-cec: " Gustavo A. R. Silva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fdeffeff7451f52fd903e4773c6b10fe21f707e4.1517929336.git.gustavo@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=garsilva@embeddedor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ramesh.shanmugasundaram@bp.renesas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®