On Thu, 2023-10-26 at 21:56 +0000, Justin Stitt wrote:
> Add some warnings for using ethtool_sprintf() where a simple
> ethtool_puts() would suffice.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -7011,6 +7011,25 @@ sub process {
>                            "Prefer strscpy, strscpy_pad, or __nonstring over 
> strncpy - see: https://github.com/KSPP/linux/issues/90\n"; . $herecurr);
>               }
>  
> +# ethtool_sprintf uses that should likely be ethtool_puts
> +             if ($line =~ 
> /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
> +                     if(WARN("ETHTOOL_SPRINTF",
> +                        "Prefer ethtool_puts over ethtool_sprintf with only 
> two arguments\n" . $herecurr) &&
> +         $fix) {
> +         $fixed[$fixlinenr] =~ s/ethtool_sprintf\s*\(/ethtool_puts\(/;
> +       }
> +             }
> +
> +             # use $rawline because $line loses %s via sanitization and thus 
> we can't match against it.
> +             if ($rawline =~ 
> /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*\"\%s\"\s*,\s*$FuncArg\s*\)/) {
> +                     if(WARN("ETHTOOL_SPRINTF",
> +                        "Prefer ethtool_puts over ethtool_sprintf with 
> standalone \"%s\" specifier\n" . $herecurr) &&
> +         $fix) {
> +         $fixed[$fixlinenr] =~ 
> s/ethtool_sprintf\s*\(\s*(.*?),.*?,(.*?)\)/ethtool_puts\($1,$2)/;

Thanks, but:

This fix wouldn't work if the first argument was itself a function
with multiple arguments.

And this is whitespace formatted incorrectly.

It:

o needs a space after if
o needs a space after the comma in the fix
o needs to use the appropriate amount and tabs for indentation
o needs alignment to open parentheses
o the backslashes are not required in the fix block

Do you want me to push what I wrote in the link below?
https://lore.kernel.org/lkml/7eec92d9e72d28e7b5202f41b02a383eb28ddd26.ca...@perches.com/

> +       }
> +             }
> +
> +
>  # typecasts on min/max could be min_t/max_t
>               if ($perl_version_ok &&
>                   defined $stat &&
> 


Reply via email to