drm/i2c/tda998x: Fix signed overflow issue
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Sat, 5 Apr 2014 16:24:29 +0000 (18:24 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 22 Apr 2014 13:39:41 +0000 (15:39 +0200)
commit8268bd48af9aae5e079d3ba8403ae459ff06cbcb
tree32c78eb6aad59e7976efa2d2c8ec0e17abedfd39
parente0c6a73fb191daad6d4ea808a89c6e22ac1b2733
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>
drivers/gpu/drm/i2c/tda998x_drv.c