[Linux-kernel-mentees] [PATCH] checkpatch: add fix option for CONSIDER_KSTRTO

Lukas Bulwahn lukas.bulwahn at gmail.com
Mon Dec 7 12:54:32 UTC 2020


On Mon, Dec 7, 2020 at 1:43 PM Aditya Srivastava <yashsri421 at gmail.com> wrote:
>
> Checkpatch recommends the usage of kstrto* over simple_strto* and
> strict_strto*, as these are obsolete.
>
> E.g., running checkpatch on commit f79b3f338564 ("ftrace: Allow
> enabling of filters via index of available_filter_functions") reports
> this warning:
>
> WARNING: simple_strtoul is obsolete, use kstrtoul instead
> +       long index = simple_strtoul(func_g->search, NULL, 0);
>
> Provide a fix by replacing simple_strto* and strict_strto* with kstrto*
>
> Signed-off-by: Aditya Srivastava <yashsri421 at gmail.com>
> ---
>  scripts/checkpatch.pl | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7b086d1cd6c2..ca5bb5a3f8f6 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6980,8 +6980,12 @@ sub process {
>
>  # recommend kstrto* over simple_strto* and strict_strto*
>                 if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
> -                       WARN("CONSIDER_KSTRTO",
> -                            "$1 is obsolete, use k$3 instead\n" . $herecurr);
> +                       if (WARN("CONSIDER_KSTRTO",
> +                                "$1 is obsolete, use k$3 instead\n" . $herecurr) &&
> +                           $fix) {
> +                               my $kstrto = "k$3";
> +                               $fixed[$fixlinenr] =~ s/$1/$kstrto/;
> +                       }
>                 }
>

Does this only warn on added lines?

The fix looks good; I just do not know if the rule is applicable in
full generality.

You might want to check a few instances if that rule actually makes
sense and is accepted.

Lukas

>  # check for __initcall(), use device_initcall() explicitly or more appropriate function please
> --
> 2.17.1
>


More information about the Linux-kernel-mentees mailing list