aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i2c
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2014-04-05 12:24:29 -0400
committerDaniel Vetter <daniel.vetter@ffwll.ch>2014-04-22 09:39:41 -0400
commit8268bd48af9aae5e079d3ba8403ae459ff06cbcb (patch)
tree32c78eb6aad59e7976efa2d2c8ec0e17abedfd39 /drivers/gpu/drm/i2c
parente0c6a73fb191daad6d4ea808a89c6e22ac1b2733 (diff)
drm/i2c/tda998x: Fix signed overflow issue
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. No we need to add up an awful lot of bytes to actually make it overflow. But I guess the real risk is gcc spotting this and going bananas. Fix this by simply using unsigned in to force all computations to use the well-defined unsigned behaviour. Spotted by coverity. v2: Simplify the entire computation as suggested by Jean. Cc: Russell King <rmk+kernel@arm.linux.org.uk> Cc: Rob Clark <robdclark@gmail.com> Cc: Jean-Francois Moine <moinejf@free.fr> Reviewed-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers/gpu/drm/i2c')
-rw-r--r--drivers/gpu/drm/i2c/tda998x_drv.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c
index 48af5cac1902..240c331405b9 100644
--- a/drivers/gpu/drm/i2c/tda998x_drv.c
+++ b/drivers/gpu/drm/i2c/tda998x_drv.c
@@ -568,11 +568,11 @@ static irqreturn_t tda998x_irq_thread(int irq, void *data)
568 568
569static uint8_t tda998x_cksum(uint8_t *buf, size_t bytes) 569static uint8_t tda998x_cksum(uint8_t *buf, size_t bytes)
570{ 570{
571 uint8_t sum = 0; 571 int sum = 0;
572 572
573 while (bytes--) 573 while (bytes--)
574 sum += *buf++; 574 sum -= *buf++;
575 return (255 - sum) + 1; 575 return sum;
576} 576}
577 577
578#define HB(x) (x) 578#define HB(x) (x)