From patchwork Sat Apr 5 11:29:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Francois Moine X-Patchwork-Id: 3942071 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 56BC09F369 for ; Sat, 5 Apr 2014 11:28:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 590BA20398 for ; Sat, 5 Apr 2014 11:28:31 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3552820377 for ; Sat, 5 Apr 2014 11:28:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B45BF6E218; Sat, 5 Apr 2014 04:28:27 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp3-g21.free.fr (smtp3-g21.free.fr [212.27.42.3]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D2A56E218 for ; Sat, 5 Apr 2014 04:28:24 -0700 (PDT) Received: from armhf (unknown [IPv6:2a01:e35:2f5c:9de0:212:bfff:fe1e:9ce4]) by smtp3-g21.free.fr (Postfix) with ESMTP id 82DA0A6133; Sat, 5 Apr 2014 13:28:13 +0200 (CEST) Date: Sat, 5 Apr 2014 13:29:32 +0200 From: Jean-Francois Moine To: Daniel Vetter Subject: Re: [PATCH 12/13] drm/i2c/tda998x: Fix signed overflow issue Message-ID: <20140405132932.6f3fc0fc@armhf> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.22; arm-unknown-linux-gnueabihf) MIME-Version: 1.0 Cc: Russell King , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Sat Apr 5 02:45:01 PDT 2014, Daniel Vetter wrote: > This is C standard hair-splitting, but afaict > - sum will be promoted to signed int in computation since > uint8_t fits > - signed overflow is undefined. [snip] > drivers/gpu/drm/i2c/tda998x_drv.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c > index 48af5cac1902..ae2754760d77 100644 > --- a/drivers/gpu/drm/i2c/tda998x_drv.c > +++ b/drivers/gpu/drm/i2c/tda998x_drv.c > @@ -568,7 +568,7 @@ static irqreturn_t tda998x_irq_thread(int irq, void *data) > > static uint8_t tda998x_cksum(uint8_t *buf, size_t bytes) > { > - uint8_t sum = 0; > + unsigned sum = 0; > > while (bytes--) > sum += *buf++; This function may be simplified by: --- tda998x_drv.c~ +++ tda998x_drv.c @@ -568,11 +568,11 @@ static uint8_t tda998x_cksum(uint8_t *buf, size_t bytes) { - uint8_t sum = 0; + int sum = 0; while (bytes--) - sum += *buf++; - return (255 - sum) + 1; + sum -= *buf++; + return sum; } #define HB(x) (x) and the same may be done in hdmi.c: diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c index 9e758a8..b6c9030 100644 --- a/drivers/video/hdmi.c +++ b/drivers/video/hdmi.c @@ -31,14 +31,14 @@ static void hdmi_infoframe_checksum(void *buffer, size_t size) { u8 *ptr = buffer; - u8 csum = 0; + int csum = 0; size_t i; /* compute checksum */ for (i = 0; i < size; i++) - csum += ptr[i]; + csum -= ptr[i]; - ptr[3] = 256 - csum; + ptr[3] = csum; } /**