Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 466B9C388F7 for ; Thu, 22 Oct 2020 14:20:34 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 801462225F for ; Thu, 22 Oct 2020 14:20:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qGVzEvPn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 801462225F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id DEAB98713E; Thu, 22 Oct 2020 14:20:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 04MKoU5Uy-6G; Thu, 22 Oct 2020 14:20:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 1163087126; Thu, 22 Oct 2020 14:20:32 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0A27EC0052; Thu, 22 Oct 2020 14:20:32 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id ACEAAC0051 for ; Thu, 22 Oct 2020 14:20:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 99A17877A0 for ; Thu, 22 Oct 2020 14:20:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c1gZPqF4nVzk for ; Thu, 22 Oct 2020 14:20:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by hemlock.osuosl.org (Postfix) with ESMTPS id 7548C8778A for ; Thu, 22 Oct 2020 14:20:29 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id l15so2466443wmi.3 for ; Thu, 22 Oct 2020 07:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=rLVePB8iLMUJ72SNR3ZlPCeku+myTqYmaQUS0QeVjq0=; b=qGVzEvPnK3wcwgWgaNo+4rBlmhp1jv4gdBGbXMv0B53z0F6ScAD58HTgyDRzCS6PNM ZedugKzkH5bjn1HvzN5GCZqhfy/QHC0TTFXii39milKUOifhSg+p2U2o3CQr6/b+pVxJ HOWbzREINxMeg18L4GiVxmH3WLBOFgve4hplJUlRKWl9c7m8ErbtqVjlHCfAL2C8grpn G42VO40j5F0pIouI1S4BWDkCja/c1r3Z6yc4quWjZt4WvmAK7HpDp0aXCezVBD5tmP0r jQRiWROBsSG8nf5dk2tGV58AWBeFxlcXEUe6h54DPfYqp8r8ESQF8E4e+j6SLIAQ6mDi W+dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=rLVePB8iLMUJ72SNR3ZlPCeku+myTqYmaQUS0QeVjq0=; b=k//VpIBxHj8ukrG1gzB4wdnuT4XwWLH1RIN0X8GnnZlLRLaZ2cHlt6RxDki3r6xSzW 9LiVPryLe7xxxEDt7X/KUjh8XvsSyVCtj7zmdjedAiubAnRpyd2/CzZJoGQvwooGQbdw baSlfxXxz5wls0S9VYWAowNvFTyPMnGhl6rXylHmO4doiDLET5+TAAY6AEwYBYbTPwVM pI+CPSt+fJmi0oOVvaMp+wd4zI0yn4GVMccUMtwWLLIVK11PUstdTBxMWRH1l3OAsofZ LEz7o55zJvDxpEF/OMCqxJomdMUAuN/WqFODi1JfE9u/9mIb/cuAmFDN0UUps/AkU3v4 TbGA== X-Gm-Message-State: AOAM530YR8ltCa7xQLFcmwRFK+SySJoTBH2V1O6qnzePYzMwfdwX9il8 uZ5RuINrpEBUHUjj77gW9e4= X-Google-Smtp-Source: ABdhPJyuBcJvdFFoGKFv9DYk7QVcqhVVMxVPW0stEop2OumWNeXCUEakJY+qlzI0ppveIjXHEriJ2w== X-Received: by 2002:a1c:5401:: with SMTP id i1mr2756779wmb.124.1603376427659; Thu, 22 Oct 2020 07:20:27 -0700 (PDT) Received: from felia ([2001:16b8:2d01:7e00:3981:87f9:70ab:e534]) by smtp.gmail.com with ESMTPSA id d20sm4199367wra.38.2020.10.22.07.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 07:20:26 -0700 (PDT) From: Lukas Bulwahn X-Google-Original-From: Lukas Bulwahn Date: Thu, 22 Oct 2020 16:20:19 +0200 (CEST) X-X-Sender: lukas@felia To: Dwaipayan Ray In-Reply-To: <20201022124741.620334-1-dwaipayanray1@gmail.com> Message-ID: References: <20201022124741.620334-1-dwaipayanray1@gmail.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Cc: linux-kernel-mentees@lists.linuxfoundation.org Subject: Re: [Linux-kernel-mentees] [PATCH RFC] checkpatch: extend attributes check to handle more patterns X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" On Thu, 22 Oct 2020, Dwaipayan Ray wrote: > It is generally preferred that the macros from > include/linux/compiler_attributes.h are used, unless there > is a reason not to. > Did you checkpatch this patch? I always thought checkpatch warns to use ./include/... as path when somebody just use include/... in a commit message. > Checkpatch currently checks __attribute__ for each of > packed, aligned, printf, scanf, and weak. Other declarations > in compiler_attributes.h are not handled. > > Add more definitions to the attribute check. > The following patterns are added: > > __alias__(#symbol) > __always_inline__ > __assume_aligned__(a, ## __VA_ARGS__) > __cold__ > __const__ > __copy__(symbol) > __designated_init__ > __externally_visible__ > __gnu_inline__ > __malloc__ > __mode__(x) > __no_caller_saved_registers__ > __noclone__ > __fallthrough__ > __noinline__ > __nonstring__ > __noreturn__ > __pure__ > __unused__ > __used__ > > Link: https://lore.kernel.org/linux-kernel-mentees/3ec15b41754b01666d94b76ce51b9832c2dd577a.camel@perches.com/ > Signed-off-by: Dwaipayan Ray > --- I guess you could add suggested-by. I am wondering if this could be refactored into a shared function and if all different warning messages each deserve to be an own type. But send it out as-is to Joe and the list and we continue the discussion there. Lukas > scripts/checkpatch.pl | 199 ++++++++++++++++++++++++++++++++++-------- > 1 file changed, 163 insertions(+), 36 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 7e505688257a..869d9b2801cd 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -6155,50 +6155,177 @@ sub process { > } > } > > -# Check for __attribute__ packed, prefer __packed > +# Check for compiler attributes > if ($realfile !~ m@\binclude/uapi/@ && > - $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { > - WARN("PREFER_PACKED", > - "__packed is preferred over __attribute__((packed))\n" . $herecurr); > - } > + $line =~ /\b__attribute__\s*\(\s*\((.*)\)\s*\)/) { > + my $attr = trim($1); > > -# Check for __attribute__ aligned, prefer __aligned > - if ($realfile !~ m@\binclude/uapi/@ && > - $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { > - WARN("PREFER_ALIGNED", > - "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); > - } > + # Check for __attribute__ alias, prefer __alias > + if ($attr =~/^_*alias_*/) { > + WARN("PREFER_ALIAS", > + "__alias(symbol) is preferred over __attribute__((alias(#symbol)))\n" . $herecurr); > + } > > -# Check for __attribute__ section, prefer __section > - if ($realfile !~ m@\binclude/uapi/@ && > - $line =~ /\b__attribute__\s*\(\s*\(.*_*section_*\s*\(\s*("[^"]*")/) { > - my $old = substr($rawline, $-[1], $+[1] - $-[1]); > - my $new = substr($old, 1, -1); > - if (WARN("PREFER_SECTION", > - "__section($new) is preferred over __attribute__((section($old)))\n" . $herecurr) && > - $fix) { > - $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*_*section_*\s*\(\s*\Q$old\E\s*\)\s*\)\s*\)/__section($new)/; > + # Check for __attribute__ aligned(size), prefer __aligned(size) > + if ($attr =~/^_*aligned_*\(/) { > + WARN("PREFER_ALIGNED", > + "__aligned(size) is preferred over __attribute__((__aligned__(size)))\n" . $herecurr); > } > - } > > -# Check for __attribute__ format(printf, prefer __printf > - if ($realfile !~ m@\binclude/uapi/@ && > - $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) { > - if (WARN("PREFER_PRINTF", > - "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) && > - $fix) { > - $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex; > + # Check for __attribute__ aligned, prefer __aligned_largest > + if ($attr =~/^_*aligned_*$/) { > + WARN("PREFER_ALIGNED_LARGEST", > + "__aligned_largest is preferred over __attribute__((__aligned__))\n" . $herecurr); > + } > > + # Check for __attribute__ always_inline, prefer __always_inline > + if ($attr =~/^_*always_inline_*/) { > + WARN("PREFER_ALWAYS_INLINE", > + "__always_inline is preferred over __attribute__((__always_inline__))\n" . $herecurr); > } > - } > > -# Check for __attribute__ format(scanf, prefer __scanf > - if ($realfile !~ m@\binclude/uapi/@ && > - $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) { > - if (WARN("PREFER_SCANF", > - "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) && > - $fix) { > - $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex; > + # Check for __attribute__ assume_aligned, prefer __assume_aligned > + if ($attr =~/^_*assume_aligned_*/) { > + WARN("PREFER_ASSUME_ALIGNED", > + "__asume_aligned(a, ...) is preferred over __attribute__((__assume_aligned__(a, ## __VA_ARGS__)))\n" . $herecurr); > + } > + > + # Check for __attribute__ cold, prefer __cold > + if ($attr =~ /^_*cold_*/) { > + WARN("PREFER_COLD", > + "__cold is preferred over __attribute__((__cold__))\n" . $herecurr); > + } > + > + # Check for __attribute__ const, prefer __attribute_const > + if ($attr =~ /^_*const_*/) { > + WARN("PREFER_CONST", > + "__attribute_const is preferred over __attribute__((__const__))\n" . $herecurr); > + } > + > + # Check for __attribute__ copy, prefer __copy > + if ($attr =~ /^_*copy_*/) { > + WARN("PREFER_COPY", > + "__copy(symbol) is preferred over __attribute__((__copy__(symbol)))\n" . $herecurr); > + } > + > + # Check for __attribute__ desginated_init, prefer __designated_init > + if ($attr =~ /^_*designated_init_*/) { > + WARN("PREFER_DESIGNATED_INIT", > + "__designated_init is preferred over __attribute__((__designated_init__))\n" . $herecurr); > + } > + > + # Check for __attribute__ externally_visible, prefer __visible > + if ($attr =~ /^_*externally_visible_*/) { > + WARN("PREFER_VISIBLE", > + "__visible is preferred over __attribute__((__externally_visible__))\n" . $herecurr); > + } > + > + # Check for __attribute__ format(printf, prefer __printf > + if ($attr =~ /^_*format_*\s*\(\s*printf/) { > + if (WARN("PREFER_PRINTF", > + "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex; > + > + } > + } > + > + # Check for __attribute__ format(scanf, prefer __scanf > + if ($attr =~ /^_*format_*\s*\(\s*scanf\b/) { > + if (WARN("PREFER_SCANF", > + "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex; > + } > + } > + > + # Check for __attribute__ gnu_inline, prefer __gnu_inline > + if ($attr =~ /^_*gnu_inline_*/) { > + WARN("PREFER_GNU_INLINE", > + "__gnu_inline is preferred over __attribute__((__gnu_inline__))\n" . $herecurr); > + } > + > + # Check for __attribute__ malloc, prefer __malloc > + if ($attr =~ /^_*malloc_*/) { > + WARN("PREFER_MALLOC", > + "__malloc is preferred over __attribute__((__malloc__))\n" . $herecurr); > + } > + > + # Check for __attribute__ mode, prefer __mode > + if ($attr =~ /^_*mode_*/) { > + WARN("PREFER_MODE", > + "__mode(x) is preferred over __attribute__((__mode__(x)))\n" . $herecurr); > + } > + > + # Check for __attribute__ no_caller_saved_registers, prefer __no_caller_saved_registers > + if ($attr =~ /^_*no_caller_saved_registers_*/) { > + WARN("PREFER_NO_CALLER_SAVED_REGISTERS", > + "__no_caller_saved_registers is preferred over __attribute__((__no_caller_saved_registers__))\n" . $herecurr); > + } > + > + # Check for __attribute__ noclone, prefer __noclone > + if ($attr =~ /^_*noclone_*/) { > + WARN("PREFER_NOCLONE", > + "__noclone is preferred over __attribute__((__noclone__))\n" . $herecurr); > + } > + > + # Check for __attribute__ fallthrough, prefer fallthrough > + if ($attr =~ /^_*fallthrough_*/) { > + WARN("PREFER_FALLTHROUGH", > + "fallthrough is preferred over __attribute__((__fallthrough__))\n" . $herecurr); > + } > + > + # Check for __attribute__ noinline, prefer noinline > + if ($attr =~ /^_*noinline_*/) { > + WARN("PREFER_NOINLINE", > + "noinline is preferred over __attribute__((__noinline__))\n" . $herecurr); > + } > + > + # Check for __attribute__ nonstring, prefer __nonstring > + if ($attr =~ /^_*nonstring_*/) { > + WARN("PREFER_NONSTRING", > + "__nonstring is preferred over __attribute__((__nonstring__))\n" . $herecurr); > + } > + > + # Check for __attribute__ noreturn, prefer __noreturn > + if ($attr =~ /^_*noreturn_*/) { > + WARN("PREFER_NORETURN", > + "__noreturn is preferred over __attribute__((__noreturn__))\n" . $herecurr); > + } > + > + # Check for __attribute__ packed, prefer __packed > + if ($attr =~ /^_*packed_*/) { > + WARN("PREFER_PACKED", > + "__packed is preferred over __attribute__((__packed__))\n" . $herecurr); > + } > + > + # Check for __attribute__ pure, prefer __pure > + if ($attr =~ /^_*pure_*/) { > + WARN("PREFER_PURE", > + "__pure is preferred over __attribute__((__pure__))\n" . $herecurr); > + } > + > + # Check for __attribute__ section, prefer __section > + if ($attr =~ /^_*section_*\s*\(\s*("[^"]*")/) { > + my $old = substr($rawline, $-[1], $+[1] - $-[1]); > + my $new = substr($old, 1, -1); > + if (WARN("PREFER_SECTION", > + "__section($new) is preferred over __attribute__((section($old)))\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*_*section_*\s*\(\s*\Q$old\E\s*\)\s*\)\s*\)/__section($new)/; > + } > + } > + > + # Check for __attribute__ unused, prefer __always_unused or __maybe_unused > + if ($attr =~ /^_*unused_*/) { > + WARN("PREFER_UNUSED", > + "__always_unused or __maybe_unused is preferred over __attribute__((__unused__))\n" . $herecurr); > + } > + > + # Check for __attribute__ used, prefer __used > + if ($attr =~ /^_*used_*/) { > + WARN("PREFER_USED", > + "__used is preferred over __attribute__((__used__))\n" . $herecurr); > } > } > > -- > 2.27.0 > > _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees