Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3958004pxb; Mon, 27 Sep 2021 06:30:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxIdTI53VySUjgTdnefgBsMSpVhx+yhWEs2d7tiy9ZERoyFaDlqWhA8AZvmD34QCX9YFAE X-Received: by 2002:a17:906:6d55:: with SMTP id a21mr27003634ejt.509.1632749422464; Mon, 27 Sep 2021 06:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632749422; cv=none; d=google.com; s=arc-20160816; b=DwDqNNeByy79ilZgzdO2cx85p411mMnE1XAk7TBsQ+D7oZF88tSB7dR+t1RRAj2jKI Q/kkGNJEYJnjLXSpyrs363fb9Zsfyet8TXw/hqvOcoTStem/i2EmT+L4IhcCpjb9AtwK lyP37PmonAzo4goW7BYz2XVhbHYe3HxpyhMvW1P3vU5oTCpQuH77R1FssE9fTnqIL1jt MtNftL+KENTHN/29GSc4mvpWJpiI5J/1q2twbSCP0HsKdn9dV2bGL+lApAPpE0stjXVH BuUwqVFkHpb477kmGluxvc6+NKZcttrFCEoemAUTla6RNft8Ye5niR9lxZndkypuMV9E pWMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=D69+WMYjsBza4pCHXiDUwD0y0AQnmhzf6CDyMOe/EuU=; b=Dr2ap/lad4ldJCkcquv0BBDUC8VqmOAB/6+IkZVgg8bjDSScsl+e3rxOYHbW3ibH5o /B9PZvf1ADh4CkuAAUc+7qElv9xxCX7srt4DRriXcwVWiSkzd9HUT3ulFJZm+UBw/784 m4SbYBX3ymfhIW2Rke241o5IOZdOSqugj9C0MYaqUbVZPW816SyVyCVoWh1YfV9behXJ lK0UgeH2QAzuNyCR0Uyx7iE+CS6Gj0+lPaEbLLvrIKXLAUhJeaBZM28jiFDF7XFTH5k2 ek+Zpw/amflOzQVfHjxEUu1JfBKgwWsMYMclxQtjjCcNv4AAFx+Sr/SBqNPJJgI7Ptza 6I9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=ikyBuHzw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l22si6669551edw.535.2021.09.27.06.29.58; Mon, 27 Sep 2021 06:30:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=ikyBuHzw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234403AbhI0N2N (ORCPT + 99 others); Mon, 27 Sep 2021 09:28:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234058AbhI0N2L (ORCPT ); Mon, 27 Sep 2021 09:28:11 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBE0BC061575; Mon, 27 Sep 2021 06:26:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding: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=D69+WMYjsBza4pCHXiDUwD0y0AQnmhzf6CDyMOe/EuU=; b=ikyBuHzwSU4yHkTXEHatgY0pCC D5KLVQhHXayUMSj5wV+7RwDYy1+H5DALN1ZCI5xMUjd0wMfjEapDwmXWXNlLv3RKP1XojtQtcQ3Xb CxOPoSKq7GFCdK3iuMsGzCpSgtg+qj8g2sQxGwH9OyQMyWnzRy0QDNNK+2rSiNmuI3cgkK//mdEls Y32ZTSJkShqGTQUtOAOjhQEpPLLwbywE0ql9Jwty2ID5sHS+HUYiEgUiCo3LmVOc/rUqwwb+W4o20 8NSNIaD/vLJIIKFkdfyL+nLmdEE0yoTnqEk7tq+GZodm/0E5lK2A42yqn8rYodDNfZ6dohUj9KK4T 1jBUGbQg==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:54812) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mUqe4-0008RG-2Z; Mon, 27 Sep 2021 14:26:12 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1mUqdy-0000mU-U4; Mon, 27 Sep 2021 14:26:06 +0100 Date: Mon, 27 Sep 2021 14:26:06 +0100 From: "Russell King (Oracle)" To: Arnd Bergmann Cc: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Voon Weifeng , Ong Boon Leong , Arnd Bergmann , kernel test robot , Dan Carpenter , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] [RESEND] net: stmmac: fix gcc-10 -Wrestrict warning Message-ID: References: <20210927100336.1334028-1-arnd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210927100336.1334028-1-arnd@kernel.org> Sender: Russell King (Oracle) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 27, 2021 at 12:02:44PM +0200, Arnd Bergmann wrote: > 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; This looks rather weird. rx_irq[] is defined as: int rx_irq[MTL_MAX_RX_QUEUES]; If "i" were to become MTL_MAX_RX_QUEUES, then the above code overlows the array. So while this may stop gcc-10 complaining, I'd argue that making the new test ">=" rather than ">" would have also made it look correct. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!