From patchwork Thu Aug 22 19:39:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 11109981 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4950114DE for ; Thu, 22 Aug 2019 19:39:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F5BA2341A for ; Thu, 22 Aug 2019 19:39:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566502782; bh=/fBE5dJY522R/VsqlV1fmQnnItqbJ1M3pIviRhRb9Hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=LUiXQ7LWLYBZfVdyW73nw5g4qMiA36IrwkHzR1bbS8+jQltM0R0R9WfT3QnMkO0ma EL74/97bBsUF6wt0NuvQhKl1i/5wjJ4Kb24ofCbZ2TdX9XRLb0GaKVPGjAfdZMXACK oDEHskpatQldFzL/tmjvQmnVhhTW1N4divC5PwjE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390447AbfHVTjl (ORCPT ); Thu, 22 Aug 2019 15:39:41 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59194 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387622AbfHVTjk (ORCPT ); Thu, 22 Aug 2019 15:39:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LI0giQyXKlJYUsm6Oe8BstHkrhYsyBvRHUhzPolmrYg=; b=TWGhHWnZ9SBAItNektQ6pwyZUC AsvvjR+kOdKXPlGUeH8SuJIa+Sb8mcB7/9Cl13nSTHzyoKzIdhXuo8WxQBN2Zz3d6ce9KdT4eR2vw +73NC9aigOb1v+JidH/Pf3PRth+5/ndBQ5ZR+fWwEu+aXTq2aF9mO2w5JyelrEcjgVWcgQSMPXVk9 90/Riab1RgE47olyRx4JGtC8wTyK38cW2SWpZG29PiY87HA58ADR6hke226ZN8oPp8s60kud84XmX eMqEQwtyIDqbVFqKUdbJc1mph1FEcAXyBYp3kS0T0rkWmrO2BJkFACN1xwQocvayRbT6tJmrFfUnn jHMH+S1g==; Received: from [177.133.63.56] (helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i0svr-0002lY-LE; Thu, 22 Aug 2019 19:39:39 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1i0svo-0007IR-GC; Thu, 22 Aug 2019 16:39:36 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Sakari Ailus , Akinobu Mita , Sylwester Nawrocki Subject: [PATCH 4/7] media: ov9650: add a sanity check Date: Thu, 22 Aug 2019 16:39:31 -0300 Message-Id: <2868a99c83f1cfef93058f7e49aefa4b104b644f.1566502743.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <4a411ba155eb062b6575aba0824123c840806c0b.1566502743.git.mchehab+samsung@kernel.org> References: <4a411ba155eb062b6575aba0824123c840806c0b.1566502743.git.mchehab+samsung@kernel.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org As pointed by cppcheck: [drivers/media/i2c/ov9650.c:706]: (error) Shifting by a negative value is undefined behaviour [drivers/media/i2c/ov9650.c:707]: (error) Shifting by a negative value is undefined behaviour [drivers/media/i2c/ov9650.c:721]: (error) Shifting by a negative value is undefined behaviour Prevent mangling with gains with invalid values Signed-off-by: Mauro Carvalho Chehab Reviewed-by: Sylwester Nawrocki --- drivers/media/i2c/ov9650.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c index 8b56011446a9..cb49fda902fd 100644 --- a/drivers/media/i2c/ov9650.c +++ b/drivers/media/i2c/ov9650.c @@ -703,6 +703,11 @@ static int ov965x_set_gain(struct ov965x *ov965x, int auto_gain) for (m = 6; m >= 0; m--) if (gain >= (1 << m) * 16) break; + + /* Sanity check: don't adjust the gain with a negative val */ + if (m < 0) + return -EINVAL; + rgain = (gain - ((1 << m) * 16)) / (1 << m); rgain |= (((1 << m) - 1) << 4);