From patchwork Wed Sep 6 15:47:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9941027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0E84E60216 for ; Wed, 6 Sep 2017 15:48:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAB1128B83 for ; Wed, 6 Sep 2017 15:48:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEEF228B98; Wed, 6 Sep 2017 15:48:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51AE228B83 for ; Wed, 6 Sep 2017 15:48:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754146AbdIFPsR (ORCPT ); Wed, 6 Sep 2017 11:48:17 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:64115 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754134AbdIFPsQ (ORCPT ); Wed, 6 Sep 2017 11:48:16 -0400 Received: from wuerfel.lan ([95.208.190.237]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0M57sc-1dXets3V66-00zHBF; Wed, 06 Sep 2017 17:47:59 +0200 From: Arnd Bergmann To: Mika Westerberg , Andy Shevchenko , Linus Walleij Cc: Arnd Bergmann , Dmitry Torokhov , Hans de Goede , Wei Yongjun , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] gpio: acpi: work around false-positive -Wstring-overflow warning Date: Wed, 6 Sep 2017 17:47:45 +0200 Message-Id: <20170906154756.2133726-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:MFngi/Bev4gwQuN65nCysQqGLG+6pHk1nJEjwdW/vW9ir6pdbxC kX4466z3lRUhwevjYRaDIywFp+wX8bm0G9daqw1M2B5V3mm5Wn/8Au5VTztW8vpwtb4MC98 NWkUlxUbMNEwiYNBhV+2+wJDEb37A7+h49/gZse9+vwliusGVauaOSFRWxPQ8ugtmjC5zWW R8LsFTxGeGGklbhaTIKKA== X-UI-Out-Filterresults: notjunk:1; V01:K0:GmvlcOniEo0=:5pqHrDHrfIDXYMcVwN4ziG zfWWgIToJLOQW6zQybNj6yOhU6n2I2FVeyVr/vhlhDWQpZbfnlVFuUpi5EyDwSVVkbPECn/kj yAG6fEcfs7GBeCsMLt+s2tkv0XECeyq0PVSPBS8BvIhYJd8aHT6kl9+EoJBNgCfchTQhmuJd0 TNwu9oRj5oXpXvzfJqbz2ahdlmHgixgtNA77zf2fIoBU66mI+rRGd1t9gdfvP8kkBsLqb57kj fkMt1ShUv5/o0mEp7UGez5oufuUo0bXDOMh4Klg2l9yVdgK0pjat0YT/YF0eSqJwgUocgJeXR qyoDCpeI8sDYMPOfqCvWiFhd2iVOhqGaJAJdB92sjH3oBtmsqMgmWRINCTkTFfYNsmbzukURE oSSrwd/sIVU0glmFUTzkhBME9b629Gn2OeijdyzQOUjQdWeeG4sDH6xZ2IpLguaymqNASd7e+ gB+DnlHWBmT1DWrKzak45PYFN5JhrseLhKvutGo7ayWrhaOmODqHxO3aCOoq87nt+qzKs3j8v /5rswIL0DucRh4iIj7MwRP4aTAhRZj5qU7EMUvQUJavvDeSBR6zc9/63MzZlFo5JOyFRI4Y3Y PfpQym6iQzgJTXmEydeU8edPBBswUDXfpGKdv/eEHjOxddl+KRL+p+z4pBCKd4XkVtJUpkcTB BGi7BQJn9HId4ztzVjDY2CesNlLWEMw8UW9bwnDW62AI+gaKsl9vdJMOW615LavxI8GGreDbB Nl4Koqe1PNsjH8/aDPFXGHSUOyrvrqSpeC04rQ== Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Fixes: 0d1c28a449c6 ("gpiolib-acpi: Add ACPI5 event model support to gpio.") Cc: Andy Shevchenko Link: https://patchwork.kernel.org/patch/9840801/ Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82123 Signed-off-by: Arnd Bergmann Acked-by: Mika Westerberg --- drivers/gpio/gpiolib-acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 4d2113530735..eb4528c87c0b 100644 --- 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)))