Skip to content

Commit

Permalink
drm/i2c/tda998x: Fix signed overflow issue
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Daniel Vetter committed Apr 22, 2014
1 parent e0c6a73 commit 8268bd4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/gpu/drm/i2c/tda998x_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,11 @@ 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;
int sum = 0;

while (bytes--)
sum += *buf++;
return (255 - sum) + 1;
sum -= *buf++;
return sum;
}

#define HB(x) (x)
Expand Down

0 comments on commit 8268bd4

Please sign in to comment.