From patchwork Thu Jun 8 04:12:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13271592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 725FAC7EE23 for ; Thu, 8 Jun 2023 04:11:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=M+MT0/mk6LB7X/ywzIyzurD9rEmhEWP22crUXKvrc58=; b=166nvjRowAE7vf RUFwn1sRChWjg64Hg71tsga/6AyhdZKS4rk/1kJWGOXQ1bdpxA4mHS54TMUmmmzEK+ROa7hCYP6iW 005rFCA7kBq6ZwJJPSO2Xyt/RFGurS1+0PasXcafPeo3JTC5b6EHe/yHhmOos4/LE/5N4JwVWAHOk DuzmXUA3aLqZzkjTXpDTf62otcBdeQZyPSbkXS+O4TxUxUUJqawfz0RkZC4Rbz/lGW67cvC5k2k+E A9pHe3vg4VDl75TJ5TphoVgMnr+Yt74RXw8AZq8Hp7a7U2l131cEGqZe8Yr/LMKhOK8meKWEZ4M+x woqFRU7iMKouvlvEMYGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q76zc-0080mt-2a; Thu, 08 Jun 2023 04:11:24 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q76za-0080mR-1J for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2023 04:11:23 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 43B6E640EF; Thu, 8 Jun 2023 04:11:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B683BC433EF; Thu, 8 Jun 2023 04:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686197480; bh=DSH0+M06pJVuiYq4hobnTz4ISp38m37GUzm/tJ7iW2g=; h=Date:From:To:Cc:Subject:From; b=qdAUd4C4ylFG61+SGH///Dv9II9UFcfIYOiBVRtiXAL4ew3U1sETw5bTjGcEEjXhy rP4LZJniTKwC3BScLE6jnuRRqwN+rWXvcBQAQ4Vvr8q7ipqHzbJRZo6J09zwabGFko JFXhq++chO85GFOfsfvqUfYcn9vti/8nIFwSpgtbrjECll6jC7LX3+dRhpw9B4hgGA ok0EosExhs93H4kYdm3gfP79P4DYZEbZK9/e/+7xxOGDHfxd9vUQ4WlKMg9F20iTOC 2Q2npUvhw345cp8/uZO7x7KguoMwSRMR+NvurZYSQf7iFhc7k4y8Ffs3oq3pZLkvK0 2/MZvq8jq2K5Q== Date: Wed, 7 Jun 2023 22:12:11 -0600 From: "Gustavo A. R. Silva" To: Tony Lindgren , Russell King , Peter 'p2' De Schrijver , Kevin Hilman Cc: linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230607_211122_504255_B83B1470 X-CRM114-Status: GOOD ( 13.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If function pwrdm_read_prev_pwrst() returns -EINVAL, we will end up accessing array pwrdm->state_counter through negative index -22. This is wrong and the compiler is legitimately warning us about this potential problem. Fix this by sanity checking the value stored in variable _prev_ before accessing array pwrdm->state_counter. Address the following -Warray-bounds warning: arch/arm/mach-omap2/powerdomain.c:178:45: warning: array subscript -22 is below array bounds of 'unsigned int[4]' [-Warray-bounds] Link: https://github.com/KSPP/linux/issues/307 Fixes: ba20bb126940 ("OMAP: PM counter infrastructure.") Cc: stable@vger.kernel.org Reported-by: kernel test robot Link: https://lore.kernel.org/lkml/20230607050639.LzbPn%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva Acked-by: Ard Biesheuvel --- arch/arm/mach-omap2/powerdomain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-omap2/powerdomain.c b/arch/arm/mach-omap2/powerdomain.c index 777f9f8e7cd8..5e05dd1324e7 100644 --- a/arch/arm/mach-omap2/powerdomain.c +++ b/arch/arm/mach-omap2/powerdomain.c @@ -174,7 +174,7 @@ static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag) break; case PWRDM_STATE_PREV: prev = pwrdm_read_prev_pwrst(pwrdm); - if (pwrdm->state != prev) + if (prev >= 0 && pwrdm->state != prev) pwrdm->state_counter[prev]++; if (prev == PWRDM_POWER_RET) _update_logic_membank_counters(pwrdm);