Skip to content

Commit

Permalink
[media] gpsca: remove the risk of a division by zero
Browse files Browse the repository at this point in the history
As reported by Coverity, there's a potential risk of a division
by zero on some calls to jpeg_set_qual(), if quality is zero.

As quality can't be 0 or lower than that, adds an extra clause
to cover this special case.

Coverity reports: CID#11922280, CID#11922293, CID#11922295

Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
mchehab committed Apr 8, 2014
1 parent 9b2c06a commit 32654fb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/media/usb/gspca/jpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ static void jpeg_set_qual(u8 *jpeg_hdr,
{
int i, sc;

if (quality < 50)
if (quality <= 0)
sc = 5000;
else if (quality < 50)
sc = 5000 / quality;
else
sc = 200 - quality * 2;
Expand Down

0 comments on commit 32654fb

Please sign in to comment.