Commit de48fa1a authored by Miguel Ojeda's avatar Miguel Ojeda
Browse files

scripts: checkpatch: diagnose uses of `%pA` in the C side as errors



The `%pA` format specifier is only intended to be used from Rust.

`checkpatch.pl` already gives a warning for invalid specificers:

    WARNING: Invalid vsprintf pointer extension '%pA'

This makes it an error and introduces an explanatory message:

    ERROR: Invalid vsprintf pointer extension '%pA' - '%pA' is only intended to be used from Rust code

Suggested-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Co-developed-by: default avatarAlex Gaynor <alex.gaynor@gmail.com>
Signed-off-by: default avatarAlex Gaynor <alex.gaynor@gmail.com>
Co-developed-by: default avatarWedson Almeida Filho <wedsonaf@google.com>
Signed-off-by: default avatarWedson Almeida Filho <wedsonaf@google.com>
Co-developed-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent 787983da
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -6783,14 +6783,18 @@ sub process {
				}
				if ($bad_specifier ne "") {
					my $stat_real = get_stat_real($linenr, $lc);
					my $msg_level = \&WARN;
					my $ext_type = "Invalid";
					my $use = "";
					if ($bad_specifier =~ /p[Ff]/) {
						$use = " - use %pS instead";
						$use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
					} elsif ($bad_specifier =~ /pA/) {
						$use =  " - '%pA' is only intended to be used from Rust code";
						$msg_level = \&ERROR;
					}

					WARN("VSPRINTF_POINTER_EXTENSION",
					&{$msg_level}("VSPRINTF_POINTER_EXTENSION",
						      "$ext_type vsprintf pointer extension '$bad_specifier'$use\n" . "$here\n$stat_real\n");
				}
			}