From patchwork Mon Sep 27 10:02:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12519519 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7D45C433EF for ; Mon, 27 Sep 2021 10:05:46 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AECBC60F6C for ; Mon, 27 Sep 2021 10:05:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AECBC60F6C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:Date:Subject:Cc :To:From: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=yqQMWzMlHXBeQBLDdPDpLEfzNJEI3mOkLnD+ebuGwoc=; b=CdnnAVjfTSd7qL D2Av6FvTVd1UqNCqBDY4QlXLtryEHrmHhwS/aaFUFHN01/MLDtxE6r7B2meOUQtqMTlFOq/Wgo2oO la0COhEIl4jLd7a0cFzvtmfWdonXtT7Dx8DsecNfNYvSW3C+S0fCgbJmJqUf7NoX7RTHmKqgXvWbv lT+6Kgk66bTuqsAQTEZlt/dquaDuwQh22Ho1FJnTbhXersXfGfxb8U2xtJtjaUbhNxLN6JpQdbniA askups8wmNWoc4vUCH9GpB1ydnX5Hgk0m7JRch/E6dHytGq9esDCtFM92qR4MT2Zyt1fWIhfqt1j/ /NBekVK4CfNMcEUlMKXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUnU9-002FMA-By; Mon, 27 Sep 2021 10:03:45 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUnU5-002FLN-R7 for linux-arm-kernel@lists.infradead.org; Mon, 27 Sep 2021 10:03:43 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3C5A560F6C; Mon, 27 Sep 2021 10:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632737021; bh=rdXEK8Ftq/XptLnhBL3SXrY8D4WMnjNMPHUHRwbRgVY=; h=From:To:Cc:Subject:Date:From; b=lRoH0ZoBzJ+dFVQrfB+JzPVFwMBUuxUbjt9Ws5BWiRAAHSlQIqwV36x2NyaH1uOQr 3VS28YFgaFOugTBeM9bR8I2dXzFhuEBi4KbEfVhzh1U0SpTVRCqqGQQ7xvGoC1z6tA fyDq/m8eohx7JtqGN6G5OnHM52e1ecNsQopFexcqFUULQEsQ/+qxOkDISnB5qN2a4y +iH8uBehRs5HnZ2C+dZlwkQcYwr/k3OzLP84PGKqpKxjze1Mr0VyK0DzWOO7q4cGfv XtmuQCDwBQpGnr/gbD9vy+WoOZ10TlZw4HoE1M3Uc6OOQiupHFMVLYSohLCtHJQHmU givK5WhsYGcbQ== From: Arnd Bergmann To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Voon Weifeng , Ong Boon Leong Cc: Arnd Bergmann , kernel test robot , Dan Carpenter , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] [RESEND] net: stmmac: fix gcc-10 -Wrestrict warning Date: Mon, 27 Sep 2021 12:02:44 +0200 Message-Id: <20210927100336.1334028-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210927_030341_919807_183F3D14 X-CRM114-Status: GOOD ( 12.28 ) 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 From: Arnd Bergmann gcc-10 and later warn about a theoretical array overrun when accessing priv->int_name_rx_irq[i] with an out of bounds value of 'i': drivers/net/ethernet/stmicro/stmmac/stmmac_main.c: In function 'stmmac_request_irq_multi_msi': drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3528:17: error: 'snprintf' argument 4 may overlap destination object 'dev' [-Werror=restrict] 3528 | snprintf(int_name, int_name_len, "%s:%s-%d", dev->name, "tx", i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3404:60: note: destination object referenced by 'restrict'-qualified argument 1 was declared here 3404 | static int stmmac_request_irq_multi_msi(struct net_device *dev) | ~~~~~~~~~~~~~~~~~~~^~~ The warning is a bit strange since it's not actually about the array bounds but rather about possible string operations with overlapping arguments, but it's not technically wrong. Avoid the warning by adding an extra bounds check. Fixes: 8532f613bc78 ("net: stmmac: introduce MSI Interrupt routines for mac, safety, RX & TX") Link: https://lore.kernel.org/all/20210421134743.3260921-1-arnd@kernel.org/ Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Arnd Bergmann --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 553c4403258a..640c0ffdff3d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3502,6 +3502,8 @@ static int stmmac_request_irq_multi_msi(struct net_device *dev) /* Request Rx MSI irq */ for (i = 0; i < priv->plat->rx_queues_to_use; i++) { + if (i > MTL_MAX_RX_QUEUES) + break; if (priv->rx_irq[i] == 0) continue; @@ -3525,6 +3527,8 @@ static int stmmac_request_irq_multi_msi(struct net_device *dev) /* Request Tx MSI irq */ for (i = 0; i < priv->plat->tx_queues_to_use; i++) { + if (i > MTL_MAX_TX_QUEUES) + break; if (priv->tx_irq[i] == 0) continue;