From patchwork Sun Oct 21 17:14:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 10651363 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E57514E2 for ; Sun, 21 Oct 2018 17:14:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6C66287B5 for ; Sun, 21 Oct 2018 17:14:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA172287C2; Sun, 21 Oct 2018 17:14:41 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 3753D287B5 for ; Sun, 21 Oct 2018 17:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728251AbeJVB3i (ORCPT ); Sun, 21 Oct 2018 21:29:38 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34187 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727688AbeJVB3i (ORCPT ); Sun, 21 Oct 2018 21:29:38 -0400 Received: by mail-wr1-f65.google.com with SMTP id l6-v6so41973927wrt.1; Sun, 21 Oct 2018 10:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=G4Oe/grs/sDFeXzk7keghoCO7T6jCmzsN8LvN6wwuhY=; b=gRWf59DL+s4AisZ9ktCuXqkZnNO27qnC6AL6SdllC3SkFl6wxN2rqUuuqn6gLaciZA X14ug1KsN+R6adQe+yCccR5mP2hLA9hHXCAWixoNkZ6cqrhrItoUObmye+CbhvO00oH8 Xo8fpsd5Hes3iHUrpsMMrGJM7jbA6vPnAjFzSgQ4KdijV59zpeoDrHQPtH543tVns21c fAtdYoE0FxIwwgrLWn+AMKvWsGUzw2PNf/wLZaSrrScrVtK7NBCmVjZblEm+wvpeYIzE kzoqEHd5uDJhNZCLU+5dNTxRMGAdQz5PqsjDrOROsRJzlWJj7FMr8EIeI9nH/FQCALpA m1/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G4Oe/grs/sDFeXzk7keghoCO7T6jCmzsN8LvN6wwuhY=; b=WFCBIPYRA/c6UWZYPHbMhnwclUAZBX7//XeiQ00QCsYoJ2ORskpGKtLTi6omm2m7dQ MJzPMwqDT055Fr5tSdRPH3VM1L3+K4vj8sFdZuZKhhnHdaZ70RCndbvcXLcy6XJCi0DZ mHJEwSJKevV+Yv+OPgf0AMXynm4CuHeMO3kffnkkVlFjmokrLNVmSIOZKK7naJvzGFVT hl2iRb74TDmKQdQxxIBOahtxlU8Qe49KeUEOUvpEHYJ2hVGDNRUwN9zCN35j0Kjmv+EG 9zzFxIo6TDu/fL1b+x5vr7mDCUQFoBzW5wExLaLJZl/I6pj4YP05t5ZwXKhkxENJQbl1 e3bQ== X-Gm-Message-State: ABuFfohOnfoJMco8o3u9fgA/7Tv/ka3+MXwFvPm6UAkUgXSHxRTF1zhq GHkH1GROhORE6bcF8/bwlJI= X-Google-Smtp-Source: ACcGV60RJ5cbQIXXY59mhk3w5PIlmRWUU8Gys/hVeRQwu8AFJtevD99EmqUZDshrGDbwgNdfSltABQ== X-Received: by 2002:adf:a706:: with SMTP id c6-v6mr45239758wrd.56.1540142077445; Sun, 21 Oct 2018 10:14:37 -0700 (PDT) Received: from localhost.localdomain (62.83.35.8.dyn.user.ono.com. [62.83.35.8]) by smtp.gmail.com with ESMTPSA id y16-v6sm20860113wru.18.2018.10.21.10.14.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Oct 2018 10:14:36 -0700 (PDT) From: Miguel Ojeda To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Dan Carpenter , Andreas Dilger , Masahiro Yamada , Michal Marek , Steven Rostedt , Mauro Carvalho Chehab , Olof Johansson , Konstantin Ryabitsev , "David S . Miller" , Andrey Ryabinin , Kees Cook , Thomas Gleixner , Ingo Molnar , Paul Lawrence , Sandipan Das , Andrey Konovalov , David Woodhouse , Will Deacon , Philippe Ombredanne , Paul Burton , David Rientjes , Willy Tarreau , Martin Sebor , Christopher Li , Jonathan Corbet , Theodore Ts'o , Geert Uytterhoeven , Rasmus Villemoes , Joe Perches , Arnd Bergmann , Dominique Martinet , Stefan Agner , Luc Van Oostenryck , Nick Desaulniers , Andrew Morton , Linus Torvalds , linux-doc@vger.kernel.org, linux-ext4@vger.kernel.org, linux-sparse@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: [PATCH 1/2] Compiler Attributes: add support for __fallthrough (gcc >= 7.1) Date: Sun, 21 Oct 2018 19:14:13 +0200 Message-Id: <20181021171414.22674-2-miguel.ojeda.sandonis@gmail.com> In-Reply-To: <20181021171414.22674-1-miguel.ojeda.sandonis@gmail.com> References: <20181021171414.22674-1-miguel.ojeda.sandonis@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From the GCC manual: fallthrough The fallthrough attribute with a null statement serves as a fallthrough statement. It hints to the compiler that a statement that falls through to another case label, or user-defined label in a switch statement is intentional and thus the -Wimplicit-fallthrough warning must not trigger. The fallthrough attribute may appear at most once in each attribute list, and may not be mixed with other attributes. It can only be used in a switch statement (the compiler will issue an error otherwise), after a preceding statement and before a logically succeeding case label, or user-defined label. https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html Currently, most of the kernel uses fallthrough comments to silence the -Wimplicit-fallthrough warnings (enabled by -Wextra, in W=1). However, C++17 standarized an "statement attribute" (the first of its kind) to deal with this: [[fallthrough]] is meant to be a new control keyword in the form of an extension. In C mode, GCC supports the __fallthrough__ attribute since 7.1, the same time the warning and the comment parsing were introduced. While comment parsing is a good idea to deal with old codebases that used such a comment as documentation for humans, the best solution is to use the attribute: * It is a "real" part of the AST (=> better for tooling). * It does not follow arbitrary rules for parsing (e.g. regexps for the comment parsing). * It may even become standarized in C as well: there are ongoing proposals to import some C++ standard attributes into the C standard, e.g. for fallthrough: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2268.pdf On top of that, it is also a better solution for the kernel, because: * We can actually use a #define for it like for the rest of attributes/extensions, which is not possible with a comment, so that its naming/usage is consistent across the entire kernel. * Whenever the migration from the comments to the attribute is complete, we may increase the level of the GCC warning up to 5, i.e. comments will not longer be considered for warning surpression: only the attribute must be used. This would enforce consistency by leveraging the compiler directly (instead of enforcing it with other tools). * Further into the future, we can consider moving the warning up to W=0 or even making it an error. It is worth noting that clang >= 3.2 supports the warning and the attribute, but only in C++ mode (and it is not enabled by -Wall/-Wextra/-Wpedantic like in gcc). Hopefully, they will also support it for C as well. Further, icc >= 18 does not seem to know anything about the warning; except that it accepts (i.e. ignores) [[fallthrough]] in C++17 mode (to be conformant, probably). Link: https://lore.kernel.org/lkml/20181017062255.oiu44y4zuuwilan3@mwanda/ Suggested-by: Dan Carpenter Signed-off-by: Miguel Ojeda --- include/linux/compiler_attributes.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index 6b28c1b7310c..9e2153f85462 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -32,6 +32,7 @@ # define __GCC4_has_attribute___assume_aligned__ (__GNUC_MINOR__ >= 9) # define __GCC4_has_attribute___designated_init__ 0 # define __GCC4_has_attribute___externally_visible__ 1 +# define __GCC4_has_attribute___fallthrough__ 0 # define __GCC4_has_attribute___noclone__ 1 # define __GCC4_has_attribute___optimize__ 1 # define __GCC4_has_attribute___nonstring__ 0 @@ -133,6 +134,23 @@ # define __visible #endif +/* + * Currently, most of the kernel uses fallthrough comments to silence + * the -Wimplicit-fallthrough warnings (enabled by -Wextra, in W=1). + * For new instances, please use this attribute instead. + * + * Optional: only supported since gcc >= 7.1 + * Optional: not supported by clang + * Optional: not supported by icc + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#index-fallthrough-statement-attribute + */ +#if __has_attribute(__fallthrough__) +# define __fallthrough __attribute__((__fallthrough__)) +#else +# define __fallthrough +#endif + /* * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-format-function-attribute * clang: https://clang.llvm.org/docs/AttributeReference.html#format From patchwork Sun Oct 21 17:14:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 10651369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1274014E2 for ; Sun, 21 Oct 2018 17:14:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB6A0287B5 for ; Sun, 21 Oct 2018 17:14:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF6EC287C2; Sun, 21 Oct 2018 17:14:52 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 981BF287B5 for ; Sun, 21 Oct 2018 17:14:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728255AbeJVB3m (ORCPT ); Sun, 21 Oct 2018 21:29:42 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51193 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727688AbeJVB3l (ORCPT ); Sun, 21 Oct 2018 21:29:41 -0400 Received: by mail-wm1-f67.google.com with SMTP id i8-v6so7919231wmg.0; Sun, 21 Oct 2018 10:14:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=o3HmxdElEan8PDyuuAhOtrH3RdwB6dQE/RImZWBr3E4=; b=fGMPxMD++IYRW9PSqM0Q0c5C5gDDgu/MQ3QSjFxgZVyqoOJQZLUE5qAf9Dm4a836es ffIaZIgpSJdY5hHIywrpRmJSAohsIxBz4w+bVd/j0nhRfNZIzsj8kueJA91Eou4eV2av i3w82VA1JOokFKI06KpVC0eEvexDsMZ4vqmqrSiO7BkT+PL7HHFnee89XlC/4QZOQmtr HJ1iEGGaoR5uHBZK/bYPnpXQpaiIAiH13GTqyrdsOKKTsXRvfacsazqT43gSdG3i+xXS UBb1McfLljpJEGsVFYKOa3I3sqWi9CC+t4Cj+O+fI/UxJdiaqSaZfVt0Z8QdUgs/5oRk iYQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=o3HmxdElEan8PDyuuAhOtrH3RdwB6dQE/RImZWBr3E4=; b=mPyIvorFefokQzKEu6DiRLA1QJNyz8RpkXEQa2nQ+wOiJUFk8b+CIv7wiphcVJW2f5 bwCYHLNtixZdFflbsslb27/hnRvRVkSRsPeJrbyZEBP96wLz4TJuXI8q/zF0dV5UMgQt L/sCPHbZOSsojrDRTWmEAHu5XGKzYnl1IZqXEeLTy5xz/oyAWbWeurUl0gfAfpcCENP4 E3JPIHyTpkXoffpUY3Rh4I+BXj/SSeMNBgoDUkpQRz5O1yR8uGUK5yEsTq3y3/upJZrW s6Q7/Nnon8J2j6RFCflqNMk7IlU7RN9V1haUNiD5v6JOzY5NoOuCfWEbauDkzr1lgnSZ aT8g== X-Gm-Message-State: ABuFfojeHG6ETlICy2qMwKWYrFFgZq5bVkrFKqkHD7hMXjkKvAi/zBFP sXp2o55CLZ3iZhN6twFRTPY= X-Google-Smtp-Source: ACcGV63VoEgw11BkHQDOm+FP4deKD4qzkydCrRtpNdiSmRusJKJ3+/Sz9WCZtw3XDvg+RkEuGvr75A== X-Received: by 2002:a1c:2384:: with SMTP id j126-v6mr12542954wmj.124.1540142081015; Sun, 21 Oct 2018 10:14:41 -0700 (PDT) Received: from localhost.localdomain (62.83.35.8.dyn.user.ono.com. [62.83.35.8]) by smtp.gmail.com with ESMTPSA id y16-v6sm20860113wru.18.2018.10.21.10.14.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Oct 2018 10:14:40 -0700 (PDT) From: Miguel Ojeda To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Dan Carpenter , Andreas Dilger , Masahiro Yamada , Michal Marek , Steven Rostedt , Mauro Carvalho Chehab , Olof Johansson , Konstantin Ryabitsev , "David S . Miller" , Andrey Ryabinin , Kees Cook , Thomas Gleixner , Ingo Molnar , Paul Lawrence , Sandipan Das , Andrey Konovalov , David Woodhouse , Will Deacon , Philippe Ombredanne , Paul Burton , David Rientjes , Willy Tarreau , Martin Sebor , Christopher Li , Jonathan Corbet , Theodore Ts'o , Geert Uytterhoeven , Rasmus Villemoes , Joe Perches , Arnd Bergmann , Dominique Martinet , Stefan Agner , Luc Van Oostenryck , Nick Desaulniers , Andrew Morton , Linus Torvalds , linux-doc@vger.kernel.org, linux-ext4@vger.kernel.org, linux-sparse@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: [PATCH 2/2] Compiler Attributes: auxdisplay: panel: use __fallthrough Date: Sun, 21 Oct 2018 19:14:14 +0200 Message-Id: <20181021171414.22674-3-miguel.ojeda.sandonis@gmail.com> In-Reply-To: <20181021171414.22674-1-miguel.ojeda.sandonis@gmail.com> References: <20181021171414.22674-1-miguel.ojeda.sandonis@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Let gcc know these cases are meant to fall through to the next label by annotating them with the new __fallthrough statement attribute; and remove the comment since it conveys the same information (which was also parsed by gcc to suppress the warning). Signed-off-by: Miguel Ojeda --- drivers/auxdisplay/panel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c index 21b9b2f2470a..0755034e49ba 100644 --- a/drivers/auxdisplay/panel.c +++ b/drivers/auxdisplay/panel.c @@ -1367,7 +1367,7 @@ static void panel_process_inputs(void) break; input->rise_timer = 0; input->state = INPUT_ST_RISING; - /* fall through */ + __fallthrough; case INPUT_ST_RISING: if ((phys_curr & input->mask) != input->value) { input->state = INPUT_ST_LOW; @@ -1380,11 +1380,11 @@ static void panel_process_inputs(void) } input->high_timer = 0; input->state = INPUT_ST_HIGH; - /* fall through */ + __fallthrough; case INPUT_ST_HIGH: if (input_state_high(input)) break; - /* fall through */ + __fallthrough; case INPUT_ST_FALLING: input_state_falling(input); }