From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751664AbbCUVXA (ORCPT ); Sat, 21 Mar 2015 17:23:00 -0400 Received: from 200.180.216.87.static.jazztel.es ([87.216.180.200]:34399 "HELO mail.sysvalve.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751426AbbCUVW5 (ORCPT ); Sat, 21 Mar 2015 17:22:57 -0400 X-Greylist: delayed 401 seconds by postgrey-1.27 at vger.kernel.org; Sat, 21 Mar 2015 17:22:57 EDT From: =?UTF-8?q?L=2E=20Alberto=20Gim=C3=A9nez?= To: linux-kernel@vger.kernel.org Cc: Andy Whitcroft , Joe Perches Subject: [PATCH] checkpatch.pl: Add warning for harmful goto labels Date: Sat, 21 Mar 2015 22:16:14 +0100 Message-Id: <1426972574-12199-1-git-send-email-agimenez@sysvalve.es> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Issue a warning for too broad goto labels that may make the code to follow the wrong exit path, thus causing hard to debug bugs. Signed-off-by: L. Alberto Giménez --- scripts/checkpatch.pl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d124359..e8ce220 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -444,6 +444,11 @@ our $allowed_asm_includes = qr{(?x: )}; # memory.h: ARM has a custom one +our @goto_harmful_labels = qw( + out + fail + ); + # Load common spelling mistakes and build regular expression list. my $misspellings; my %spelling_fix; @@ -2702,6 +2707,14 @@ sub process { } } + if ($sline =~ /goto (.*);/) { + my $label = $1; + if (grep { /^$label$/ } @goto_harmful_labels) { + WARN("HARMFUL_GOTO_LABEL", + "Goto label '$label' is considered harmful\n" . $herecurr); + } + } + # discourage the addition of CONFIG_EXPERIMENTAL in #if(def). if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_EXPERIMENTAL\b/) { WARN("CONFIG_EXPERIMENTAL", -- 2.1.4