All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Bulwahn <lukas.bulwahn@gmail.com>
To: Aditya Srivastava <yashsri421@gmail.com>
Cc: linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [Linux-kernel-mentees] [PATCH] checkpatch: add fix option and improve msg for BOOL_COMPARISON
Date: Wed, 9 Dec 2020 12:47:49 +0100	[thread overview]
Message-ID: <CAKXUXMx_ypzYSCHLzQKY0Uq=M35V4kSd6aivCYBa8coR6jM0yw@mail.gmail.com> (raw)
In-Reply-To: <20201209105833.9066-1-yashsri421@gmail.com>

On Wed, Dec 9, 2020 at 11:58 AM Aditya Srivastava <yashsri421@gmail.com> wrote:
>
> Currently, checkpatch warns if the user compares expression with boolean.
>
> E.g., running checkpatch on commit 3b3a1a0b7824 ("staging: rtl8723bs:
> hal: Modify comparison to constant in rtl8723bs_xmit.c") reports:
>
> CHECK: Using comparison to true is error prone
> +       if (ret == true)
>
> Provide a fix by replacing the expression with preferred expression. i.e.,
>
> 1) If the check is for a 'true' or 'not false' expression, the operand
> will get replaced with empty string.
>
> 2) Else, the operand gets replaced with '!', and the arguments follow.
>

Can you show the test cases you used to test this?

Can you show all findings of this rule on the current rc or linux-next?

Lukas

> Suggested-by: Joe Perches <joe@perches.com>
> Signed-off-by: Aditya Srivastava <yashsri421@gmail.com>
> ---
> This fix is actually inspired from the comment mentioned in the script by Joe. I have added the Suggested-by line correspondingly.
>
>  scripts/checkpatch.pl | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 8bd8e4518f7f..abd5a3d2e913 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6973,8 +6973,11 @@ sub process {
>                                         $op = "";
>                                 }
>
> -                               CHK("BOOL_COMPARISON",
> -                                   "Using comparison to $otype is error prone\n" . $herecurr);
> +                               if (CHK("BOOL_COMPARISON",
> +                                       "Using comparison to '$otype' is error prone. Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr) &&
> +                                   $fix) {
> +                                       $fixed[$fixlinenr] =~ s/\b(?:true|false|$Lval)\s*(?:==|\!=)\s*(?:true|false|$Lval)\b/$op$arg/;
> +                               }
>
>  ## maybe suggesting a correct construct would better
>  ##                                 "Using comparison to $otype is error prone.  Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
> --
> 2.17.1
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2020-12-09 11:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-09 10:58 [Linux-kernel-mentees] [PATCH] checkpatch: add fix option and improve msg for BOOL_COMPARISON Aditya Srivastava
2020-12-09 11:47 ` Lukas Bulwahn [this message]
2020-12-09 15:59   ` Aditya
2020-12-09 17:09     ` Lukas Bulwahn
2020-12-12  9:13       ` Aditya
2020-12-13  8:03         ` Lukas Bulwahn
2021-02-06 14:05           ` Aditya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKXUXMx_ypzYSCHLzQKY0Uq=M35V4kSd6aivCYBa8coR6jM0yw@mail.gmail.com' \
    --to=lukas.bulwahn@gmail.com \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=yashsri421@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.