From patchwork Tue Jul 11 07:44:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 118301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp312059vqm; Tue, 11 Jul 2023 00:59:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlH9aAZAa44dxFR4Nc1Ky4cFkJ/pDsVFgA+AJ4Gr/nycXyCHWe2WT2KjYl3JdpG/YDUlHzEi X-Received: by 2002:a17:906:7691:b0:988:f2ad:73e9 with SMTP id o17-20020a170906769100b00988f2ad73e9mr15162497ejm.52.1689062378533; Tue, 11 Jul 2023 00:59:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689062378; cv=none; d=google.com; s=arc-20160816; b=D1Y0RYzdepwETFr1Iwi08MKJgaPHphuynOGRi3duhxQDBR0uykH6gzEaoqUp7DiGSk J1HyMHKzlaKmkPaRb4Kp+MM2BytyUmaNR8OsiMYPuGSiAS/sHa6GykMY0xyYl0A8SR6+ KxlNrKxo5S7SbsAA+tXU77k1gfh1gTd2QCojQd2q/uSLXPqXr2cpSDif7in3MQZfHRZq vd+tj3biO/RkR9hp6fDtPCtlT4qAyL37jvNB1LbcP3XAWeIs6GfscTN5UMaUNPXuVvfE 0R6PvApFDtyhK5kJ3rFh+C5SqG2wXPtdYFHOGKzDWeH4fL1nmHxVORttK/gEd7rnOz1i UHbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=HQfE1ZZr+v1emGAH2Qulv7iQSM3kBJc1UJPVvLzwMCw=; fh=6PxFVRAKCCxbIieRv/fsy9TANWK9wU9dX5r/fYqAV8M=; b=0OlHhjJOi8VD843k/ozHiB1yZybZ6yR/avnIkb2VIbeh+PnRGBnFxtIIYb6WQqcO9f E+oOSaabVfxmwNBohnLztRD/HRHeZiUwYshEVeQz4AIhxPlHmxOliL50I51mN4IACvWb y3RbmkAq+lJaZnCDz0Xc/9pVkI8hbexmuevKFZrlh/EWHtrTlOPHFzDsiaWuxuuxfqUA 1F8MSwUSWLR2QF7qFrV5lSUg74So+2WyISXd/PlKWzoPmi3l5/2wMbdO05Ic0LNGbb4r uh/CzI+S2KIy8O9hk5afJZYx2rpJOmIAFW9TkhrysS51vAPV2EB6vZQ9hF6wORXk5CH6 m7rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vUbepeoe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a17090640cc00b00992ca767e00si1498124ejk.86.2023.07.11.00.59.15; Tue, 11 Jul 2023 00:59:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vUbepeoe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbjGKHor (ORCPT + 99 others); Tue, 11 Jul 2023 03:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbjGKHop (ORCPT ); Tue, 11 Jul 2023 03:44:45 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2D981A2 for ; Tue, 11 Jul 2023 00:44:43 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4fb94b1423eso7971849e87.1 for ; Tue, 11 Jul 2023 00:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689061482; x=1691653482; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=HQfE1ZZr+v1emGAH2Qulv7iQSM3kBJc1UJPVvLzwMCw=; b=vUbepeoe1uw7SJNzr8Cu/EYsqowD8uIxcqNpxLYznEu+9V8T/ZSKpfMwhNqbBWEkQs 9meQ0S1a2/HYDIuVOikJgXWc+LvUH4CGETD+yqKgwTiAvzQ7boWZ9F7VRG2fAoKXizgg weSVBhmdaEBTP+0bSag6/MMBx0jpMaMhPS6VFq5pyZwnZ90ksXulxzt1rCGs2UAbL6Nv NhFvei2Hy/QlnLBRpK8yisM0lyD+XDK9Lutb0K/Opqucksei9bCVMnNs24iKZsWlN7Da TcDJuTV7F4iBbgsAig4mCxYBv+OrdpDYhZ6Wpj1Jnf0udmf2Yi4+9+H/o6qjn5ppQXd/ GoTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689061482; x=1691653482; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HQfE1ZZr+v1emGAH2Qulv7iQSM3kBJc1UJPVvLzwMCw=; b=bXMy/kvRTF3pmqd2kon9nRICab4rH7+ZxnzdxnVpfsHu+5tBqIn7qn4VleqLSi5J7Q 3pZVKkBFRCuPU06zEQrp508KOxGp2lEr7Wpkb9TVTJz+BxYQNepoBvrqz54GUxDE2dy8 gLTQWuMrR/z/pHYhiy66CvrLXNRM+B2rPeu8uzouJfps19+PI0rXl28LkArupF3iGRQc wVDzVIUK940QGr3WNeNhtS6kPkuHoJ+kiPCy830nNqpwTWKHClU9XHB9gxAWBszA0Gnm 1uDL1u8uoP2iGRDaKIJ5pP9qvZpuMOM8nPNP0dUPepWVDNz4Rgzbr/TIxAL0yjlOyj7q fwMg== X-Gm-Message-State: ABy/qLaYIRdz+ReDFg4SbptQUWAzGL2oQgy66brMYv4b9g2V58sMwsVl tgxfYD07PAfkhe8iWDNLlR0X8Q== X-Received: by 2002:a05:6512:3090:b0:4f8:4512:c844 with SMTP id z16-20020a056512309000b004f84512c844mr14669521lfd.48.1689061481839; Tue, 11 Jul 2023 00:44:41 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id k24-20020a05600c0b5800b003fc01189b0dsm1703609wmr.42.2023.07.11.00.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 00:44:39 -0700 (PDT) Date: Tue, 11 Jul 2023 10:44:35 +0300 From: Dan Carpenter To: Thorsten Leemhuis , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Arnd Bergmann , Kees Cook , Sasha Levin , Tom Gall , kernel-janitors@vger.kernel.org Subject: [PATCH v3] checkpatch: check for missing Fixes tags Message-ID: <756970eb-6204-415a-a997-d67a14ba6584@moroto.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771110272873167567 X-GMAIL-MSGID: 1771110272873167567 This check looks for common words that probably indicate a patch is a fix. For now the regex is: (?:(?:BUG: K.|UB)SAN: |Call Trace:|stable\@|syzkaller)/) Why are stable patches encouraged to have a fixes tag? Some people mark their stable patches as "# 5.10" etc. This is useful but a Fixes tag is still a good idea. For example, the Fixes tag helps in review. It helps people to not cherry-pick buggy patches without also cherry-picking the fix. Also if a bug affects the 5.7 kernel some people will round it up to 5.10+ because 5.7 is not supported on kernel.org. It's possible the Bad Binder bug was caused by this sort of gap where companies outside of kernel.org are supporting different kernels from kernel.org. Should it be counted as a Fix when a patch just silences harmless WARN_ON() stack trace. Yes. Definitely. Is silencing compiler warnings a fix? It seems unfair to the original authors, but we use -Werror now, and warnings break the build so let's just add Fixes tags. I tell people that silencing static checker warnings is not a fix but the rules on this vary by subsystem. Is fixing a minor LTP issue (Linux Test Project) a fix? Probably? It's hard to know what to do if the LTP test has technically always been broken. One clear false positive from this check is when someone updated their debug output and included before and after Call Traces. Or when crashes are introduced deliberately for testing. In those cases, you should just ignore checkpatch. Signed-off-by: Dan Carpenter --- v3: Add UBSAN to the regex as Kees suggested. v2: I fixed the formatting issues Joe pointed out. I also silenced the warning if the commit was a Revert because revert patches already include the hash. scripts/checkpatch.pl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 880fde13d9b8..4d4f2d12cd25 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -28,6 +28,7 @@ my %verbose_messages = (); my %verbose_emitted = (); my $tree = 1; my $chk_signoff = 1; +my $chk_fixes_tag = 1; my $chk_patch = 1; my $tst_only; my $emacs = 0; @@ -86,6 +87,7 @@ Options: -v, --verbose verbose mode --no-tree run without a kernel tree --no-signoff do not check for 'Signed-off-by' line + --no-fixes-tag do not check for 'Fixes:' tag --patch treat FILE as patchfile (default) --emacs emacs compile window format --terse one line per report @@ -293,6 +295,7 @@ GetOptions( 'v|verbose!' => \$verbose, 'tree!' => \$tree, 'signoff!' => \$chk_signoff, + 'fixes-tag!' => \$chk_fixes_tag, 'patch!' => \$chk_patch, 'emacs!' => \$emacs, 'terse!' => \$terse, @@ -1254,6 +1257,7 @@ sub git_commit_info { } $chk_signoff = 0 if ($file); +$chk_fixes_tag = 0 if ($file); my @rawlines = (); my @lines = (); @@ -2633,6 +2637,9 @@ sub process { our $clean = 1; my $signoff = 0; + my $fixes_tag = 0; + my $is_revert = 0; + my $needs_fixes_tag = 0; my $author = ''; my $authorsignoff = 0; my $author_sob = ''; @@ -3186,6 +3193,16 @@ sub process { } } +# These indicate a bug fix + if (!$in_header_lines && !$is_patch && + $line =~ /^This reverts commit/) { + $is_revert = 1; + } + + if (!$in_header_lines && !$is_patch && + $line =~ /(?:(?:BUG: K.|UB)SAN: |Call Trace:|stable\@|syzkaller)/) { + $needs_fixes_tag = 1; + } # Check Fixes: styles is correct if (!$in_header_lines && @@ -3198,6 +3215,7 @@ sub process { my $id_length = 1; my $id_case = 1; my $title_has_quotes = 0; + $fixes_tag = 1; if ($line =~ /(\s*fixes:?)\s+([0-9a-f]{5,})\s+($balanced_parens)/i) { my $tag = $1; @@ -7636,6 +7654,12 @@ sub process { ERROR("NOT_UNIFIED_DIFF", "Does not appear to be a unified-diff format patch\n"); } + if ($is_patch && $has_commit_log && $chk_fixes_tag) { + if ($needs_fixes_tag && !$is_revert && !$fixes_tag) { + WARN("MISSING_FIXES_TAG", + "This looks like a fix but there is no Fixes: tag\n"); + } + } if ($is_patch && $has_commit_log && $chk_signoff) { if ($signoff == 0) { ERROR("MISSING_SIGN_OFF",