Skip to contentSkip to conversation

gpsca: remove the risk of a division by zero

PATCH In review Luis de Bethencourt 1 participant 2 messages Feb 9, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpsca: remove the risk of a division by zero

As reported by Peter Kovar, there's a potential risk of a division by zero on calls to jpeg_set_qual() when quality is zero.

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

---
 drivers/media/usb/gspca/topro.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/usb/gspca/topro.c +3 -1
index 5fcd1ee..c70ff40 100644
@@ -969,7 +969,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;
Signature · 1 line
2.1.3
#1 lore raw
Quoted 29 lines · Luis de Bethencourt

As reported by Peter Kovar, there's a potential risk of a division by zero on calls to jpeg_set_qual() when quality is zero.

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

---
 drivers/media/usb/gspca/topro.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/usb/gspca/topro.c +3 -1
index 5fcd1ee..c70ff40 100644
@@ -969,7 +969,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;
Signature · 1 line
2.1.3

Reported here:
http://www.mail-archive.com/[email protected]/msg84989.html

Thanks :)
Luis