From: David Laight <david.laight.linux@gmail.com>
To: Andreas Dilger <adilger@dilger.ca>
Cc: Amir Goldstein <amir73il@gmail.com>,
Miklos Szeredi <miklos@szeredi.hu>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Al Viro <viro@zeniv.linux.org.uk>,
Linus Torvalds <torvalds@linux-foundation.org>,
Nirmoy Das <nirmoyd@nvidia.com>,
linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] err_ptr.h: introduce ERR_PTR_SAFE()
Date: Sun, 17 May 2026 13:40:18 +0100 [thread overview]
Message-ID: <20260517134018.62901443@pumpkin> (raw)
In-Reply-To: <56380C61-04E4-403E-B721-F9B62DEA5D56@dilger.ca>
On Sun, 17 May 2026 03:13:00 -0600
Andreas Dilger <adilger@dilger.ca> wrote:
> On Thu, 14 May 2026 22:01:29 +0200 Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > The check for constants may be fairly pointless.
> > One of the static checkers may already detect the obvious fubar ERR_PTR(EINVAL).
>
>
> Actually, I just ran across an issue that checkpatch.pl does *not* detect
> this "obvious" case. It complains about "return EINVAL", but does not say
> anything for cases like "return ERR_PTR(EINVAL)" or "rc = EINVAL; return rc;".
>
> The following patch fixes checkpatch.pl to report many more such cases, and
> has very few false positives for checking common error return assignments.
Looks like there are a few too many false positives in the network stack.
Mostly because sk_err holds a positive errno.
They do all seem to be 'err = Exxx' though.
Does look more useful that some of the other things that checkpatch checks.
-- David
>
> diff --git a/contrib/scripts/checkpatch.pl b/contrib/scripts/checkpatch.pl
> index 70c78a3..e3fdedf 100755
> --- a/contrib/scripts/checkpatch.pl
> +++ b/contrib/scripts/checkpatch.pl
> @@ -5795,11 +5795,12 @@
> }
>
> # Return of what appears to be an errno should normally be negative
> - if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
> - my $name = $1;
> + if (!is_userspace($realfile) &&
> + $sline =~ /\b(?i)(return|err =|rc =|ret =|retval =|ERR_PTR)(?-i)(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
> + my $name = $2;
> if ($name ne 'EOF' && $name ne 'ERROR' && $name !~ /^EPOLL/) {
> WARN("USE_NEGATIVE_ERRNO",
> - "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
> + "return of an errno should typically be negative (ie: $1 -$2)\n" . $herecurr);
> }
> }
>
>
> Cheers, Andreas
>
>
>
>
>
next prev parent reply other threads:[~2026-05-17 12:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-14 20:01 [PATCH] err_ptr.h: introduce ERR_PTR_SAFE() Amir Goldstein
2026-05-15 12:25 ` Nirmoy Das
2026-05-15 13:15 ` Jori Koolstra
2026-05-15 18:30 ` David Laight
2026-05-15 19:26 ` Amir Goldstein
2026-05-16 8:42 ` David Laight
2026-05-16 11:39 ` Amir Goldstein
2026-05-16 12:42 ` David Laight
2026-05-16 20:39 ` Amir Goldstein
2026-05-18 9:04 ` Rasmus Villemoes
2026-05-18 9:52 ` Amir Goldstein
2026-05-18 12:48 ` David Laight
2026-05-17 9:13 ` Andreas Dilger
2026-05-17 12:40 ` David Laight [this message]
2026-05-18 12:39 ` Christian Brauner
2026-05-18 12:52 ` Amir Goldstein
2026-05-18 14:51 ` David Laight
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=20260517134018.62901443@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=adilger@dilger.ca \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=nirmoyd@nvidia.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox