From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755095AbdIFPxB (ORCPT ); Wed, 6 Sep 2017 11:53:01 -0400 Received: from smtprelay0191.hostedemail.com ([216.40.44.191]:55629 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753169AbdIFPw7 (ORCPT ); Wed, 6 Sep 2017 11:52:59 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:1801:2393:2559:2562:2828:2890:2902:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3874:4042:4321:4605:5007:7903:8603:9707:10004:10400:10848:11026:11232:11473:11658:11914:12043:12048:12295:12296:12438:12555:12683:12740:12760:12895:13069:13161:13229:13311:13357:13439:14659:14721:21067:21080:21450:21451:21627:30001:30012:30034:30054:30070:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: twist63_198305eba2826 X-Filterd-Recvd-Size: 2716 Message-ID: <1504713173.7546.3.camel@perches.com> Subject: Re: [PATCH] gpio: acpi: work around false-positive -Wstring-overflow warning From: Joe Perches To: Arnd Bergmann , Mika Westerberg , Andy Shevchenko , Linus Walleij Cc: Dmitry Torokhov , Hans de Goede , Wei Yongjun , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 06 Sep 2017 08:52:53 -0700 In-Reply-To: <20170906154756.2133726-1-arnd@arndb.de> References: <20170906154756.2133726-1-arnd@arndb.de> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2017-09-06 at 17:47 +0200, Arnd Bergmann wrote: > gcc-7 notices that the pin_table is an array of 16-bit numbers, > but fails to take the following range check into account: > > drivers/gpio/gpiolib-acpi.c: In function 'acpi_gpiochip_request_interrupt': > drivers/gpio/gpiolib-acpi.c:206:24: warning: '%02X' directive writing between 2 and 4 bytes into a region of size 3 [-Wformat-overflow=] > sprintf(ev_name, "_%c%02X", > ^~~~ > drivers/gpio/gpiolib-acpi.c:206:20: note: directive argument in the range [0, 65535] > sprintf(ev_name, "_%c%02X", > ^~~~~~~~~ > drivers/gpio/gpiolib-acpi.c:206:3: note: 'sprintf' output between 5 and 7 bytes into a destination of size 5 > sprintf(ev_name, "_%c%02X", > ^~~~~~~~~~~~~~~~~~~~~~~~~~~ > agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L', > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > pin); > ~~~~ > > As suggested by Andy, this changes the format string to have a fixed length. > Since modifying the range check did not help, I also opened a bug against > gcc, see link below. The code has int pin does changing pin to unsigned int matter? > diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c [] > @@ -203,7 +203,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares, > > if (pin <= 255) { > char ev_name[5]; > - sprintf(ev_name, "_%c%02X", > + sprintf(ev_name, "_%c%02hhX", > agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L', > pin); > if (ACPI_SUCCESS(acpi_get_handle(handle, ev_name, &evt_handle)))