From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14A63C433B4 for ; Wed, 21 Apr 2021 14:38:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D343561454 for ; Wed, 21 Apr 2021 14:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236146AbhDUOjI convert rfc822-to-8bit (ORCPT ); Wed, 21 Apr 2021 10:39:08 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]:39737 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234914AbhDUOjE (ORCPT ); Wed, 21 Apr 2021 10:39:04 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-279-E_LjFz9SPlSA_JZbVKloyw-1; Wed, 21 Apr 2021 15:38:28 +0100 X-MC-Unique: E_LjFz9SPlSA_JZbVKloyw-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Apr 2021 15:38:27 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.015; Wed, 21 Apr 2021 15:38:27 +0100 From: David Laight To: 'Arnd Bergmann' , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski CC: Arnd Bergmann , Maxime Coquelin , Ong Boon Leong , "Voon Weifeng" , Joakim Zhang , Fugang Duan , Thierry Reding , "Song, Yoong Siang" , "netdev@vger.kernel.org" , "linux-stm32@st-md-mailman.stormreply.com" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] [net-next] net: stmmac: fix gcc-10 -Wrestrict warning Thread-Topic: [PATCH] [net-next] net: stmmac: fix gcc-10 -Wrestrict warning Thread-Index: AQHXNrT6fDpLRbOb4EudX81jJF2zvaq/CRyw Date: Wed, 21 Apr 2021 14:38:27 +0000 Message-ID: References: <20210421134743.3260921-1-arnd@kernel.org> In-Reply-To: <20210421134743.3260921-1-arnd@kernel.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arnd Bergmann > Sent: 21 April 2021 14:47 > > 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") > 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 d1ca07c846e6..aadac783687b 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > @@ -3498,6 +3498,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; It might be best to do: num_queues = min(priv->plat->rx_queues_to_use, MTL_MAX_RX_QUEUES); if (i = 0; i < num_queues; i++) { ... Or just give up - if rx_queues_to_use is too big it's all gone horribly wrong already. The compile must be smoking weed again. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)