From patchwork Mon Feb 9 10:16:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis de Bethencourt X-Patchwork-Id: 5800401 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0FCD59F336 for ; Mon, 9 Feb 2015 10:19:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 56DA52010F for ; Mon, 9 Feb 2015 10:18:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83A8920121 for ; Mon, 9 Feb 2015 10:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759683AbbBIKS1 (ORCPT ); Mon, 9 Feb 2015 05:18:27 -0500 Received: from mail-wg0-f50.google.com ([74.125.82.50]:47118 "EHLO mail-wg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759473AbbBIKS0 (ORCPT ); Mon, 9 Feb 2015 05:18:26 -0500 Received: by mail-wg0-f50.google.com with SMTP id l18so9826169wgh.9; Mon, 09 Feb 2015 02:18:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:date:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=P8QZvOacvbCIHWMUbJiy+9Ejx5xNmSZWSKm+EJUW59s=; b=kl5UIkWc8qFT4zcTz9xnddUa4hq0eIOQyYLUGoSQxhLpJVPkhQvJAa+3Nf3s9sLYW7 aelLNpawUloXmvvDS5FZ05ydQm7hiWJc/nVGXbv8LPAFUJNlAHJ7v4vVqmT4jJ2lZzs+ FcemPn7bL8QVW9Z/0/TAv2fewTWjIDcn3qpRxrn+P2nycPlRd26tkwEu4WjCO+VXfZbC g+KhF1RLz6WYebhej080jne3Ptva1D+33SQW2vpR0Y6Z1v7A/jR1sLMbUQWeTrdavG9E XJTopZUyOmhavnErtO1XkjFJyG9whjiQ1V1Yud82+ShCSs2+63VGHwhPeJHeoX4zydHb 15dA== X-Received: by 10.195.13.104 with SMTP id ex8mr39472630wjd.12.1423477105027; Mon, 09 Feb 2015 02:18:25 -0800 (PST) Received: from localhost ([212.250.200.210]) by mx.google.com with ESMTPSA id n3sm15671693wja.36.2015.02.09.02.18.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Feb 2015 02:18:24 -0800 (PST) From: Luis de Bethencourt X-Google-Original-From: Luis de Bethencourt Date: Mon, 9 Feb 2015 10:16:25 +0000 To: linux-media@vger.kernel.org Cc: mchehab@osg.samsung.com, hdegoede@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH] gpsca: remove the risk of a division by zero Message-ID: <20150209101625.GA28331@biggie> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Luis de Bethencourt --- drivers/media/usb/gspca/topro.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/gspca/topro.c b/drivers/media/usb/gspca/topro.c index 5fcd1ee..c70ff40 100644 --- a/drivers/media/usb/gspca/topro.c +++ b/drivers/media/usb/gspca/topro.c @@ -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;