Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2204545imm; Mon, 28 May 2018 03:54:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJoQosTVJSLay3GqZjfBuDV5Fzlp9kXesGForJ/dEGokYkv1V7nPG5JAyFlxcK4H64sWtiY X-Received: by 2002:a17:902:7898:: with SMTP id q24-v6mr1856423pll.254.1527504884940; Mon, 28 May 2018 03:54:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527504884; cv=none; d=google.com; s=arc-20160816; b=aW6R0MYSobwVvW3PRnN40cWmQYKiDEZkxM+lknTWoLTC3592e5zm942Kh+ceramR1S aj5tN06vIkjwY4j3VuZMOACMd2BGRQ0oSz+ut/M6tV2Aa1kVtpsYRSW5E6Ne9BPOX8XP 6w+vOyio7ET7uUTWJe+L38anX9GwqUOASRQgRL8ar0A2DuzmwMJqmFt9F2mhW5ZcpoT3 3YvhS+jy3kfkMPNJpWehzufyCKQqD7RKq8f1sSsbQllDrx8CfaST3HLokvpaJpfkKiVk eHCpL+uookhXkjj/kQZojiUDC/oNx9uBx1k5l8Wcd897FqWL5/IPWRUJIoSVTlndn7+8 U/0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=TICvDVvo3CcU6vo0WXdb3zGdo1r9kJL3hpRMLiMX21Y=; b=u+qsUumjP69G9qfJVNaTpn+SCnkBkCsCigst297bbnKk+erydvI1kzzWCvMgj3Fmbq 19GKfZQ8RkDMdtYYxXjW7suDJplAGOKklfgU5KGYDJKRMJIbpQ7Ktq7Tv7wmlqf7nFMQ kK9u4YAGCH9RKlgKfvuMpT6MebItSyA7fkKmcHEyLzr5wUDBVbB1hdb6tuP+hAtzLAV5 ktgg2YuWyXmyx4bSv+vgqT1Si1FRyo/iT0VI99YvakcCMSzIfwaoo1FCVnaG2SDE/cJY 303Ahj8ZwMnr5bAUV0B8+Q5xhhGUXiG5/qHDxWe3nDOHPw2iqjAtEmEx3AuZUtcLvx3M eXHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UmMKv6Iu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 98-v6si32828987pls.180.2018.05.28.03.54.30; Mon, 28 May 2018 03:54:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UmMKv6Iu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1164262AbeE1KyQ (ORCPT + 99 others); Mon, 28 May 2018 06:54:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:43078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164244AbeE1KyD (ORCPT ); Mon, 28 May 2018 06:54:03 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4E51620845; Mon, 28 May 2018 10:54:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504842; bh=ZhA9VbSW4/5U8J47+2Nuax8D1Gc65teJ+G7sh1qmArY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UmMKv6IuugWA2Uzv1lCdrJ5WMQLaEgoiM0VBeGcVMGLEJn2avtn8y0QLXd4+9ocLv 2WG5otl8zwiswGWvmo2wvafLeqpnll6W+w6xNFpyADtNmvLPZ3ZFpx8Prv9GsbxL75 Zmhb/h0+H/pic9xUpMgCIZqCYxzeAfpSSaMTKq+s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Philipp Zabel , Sasha Levin Subject: [PATCH 4.14 250/496] gpu: ipu-v3: prg: avoid possible array underflow Date: Mon, 28 May 2018 12:00:35 +0200 Message-Id: <20180528100330.420599863@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnd Bergmann [ Upstream commit 746d024c3211813946b319411aeb2b47767f8fb0 ] gcc-8 reports that we access an array with a negative index in an error case: drivers/gpu/ipu-v3/ipu-prg.c: In function 'ipu_prg_channel_disable': drivers/gpu/ipu-v3/ipu-prg.c:252:43: error: array subscript -22 is below array bounds of 'struct ipu_prg_channel[3]' [-Werror=array-bounds] This moves the range check in front of the first time that variable gets used. Signed-off-by: Arnd Bergmann Signed-off-by: Philipp Zabel Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/ipu-v3/ipu-prg.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/drivers/gpu/ipu-v3/ipu-prg.c +++ b/drivers/gpu/ipu-v3/ipu-prg.c @@ -252,10 +252,14 @@ void ipu_prg_channel_disable(struct ipuv { int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num); struct ipu_prg *prg = ipu_chan->ipu->prg_priv; - struct ipu_prg_channel *chan = &prg->chan[prg_chan]; + struct ipu_prg_channel *chan; u32 val; - if (!chan->enabled || prg_chan < 0) + if (prg_chan < 0) + return; + + chan = &prg->chan[prg_chan]; + if (!chan->enabled) return; clk_prepare_enable(prg->clk_ipg); @@ -282,13 +286,15 @@ int ipu_prg_channel_configure(struct ipu { int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num); struct ipu_prg *prg = ipu_chan->ipu->prg_priv; - struct ipu_prg_channel *chan = &prg->chan[prg_chan]; + struct ipu_prg_channel *chan; u32 val; int ret; if (prg_chan < 0) return prg_chan; + chan = &prg->chan[prg_chan]; + if (chan->enabled) { ipu_pre_update(prg->pres[chan->used_pre], *eba); return 0;