From: Jakub Kicinski <kuba@kernel.org>
To: linux-sparse@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, edwin.peer@broadcom.com,
Zhang Changzhong <zhangchangzhong@huawei.com>
Subject: sparse annotation for error types?
Date: Sat, 5 Dec 2020 14:32:50 -0800 [thread overview]
Message-ID: <20201205143250.2378b9f9@kicinski-fedora-pc1c0hjn.DHCP.thefacebook.com> (raw)
Hi!
Recently we've been getting a steady stream of patches from Changzhong
to fix missing assignment to error variables before jumping to error
cases.
I wonder if for new code it'd make sense to add an annotation for a type
which has to be returned non-zero?
What I have in mind is the following common flow:
int do_a_thing(struct my_obj *obj, int param)
{
int err;
err = first_step(obj, 1);
if (err)
return err;
if (some_check(obj)) {
err = -EINVAL; /* need explicit error set! */
goto err_undo_1s;
}
err = second_step(obj, param);
if (err)
goto err_undo_1s;
err = third_step(obj, 0);
if (err)
goto err_undo_2s;
return 0;
err_undo_2s:
second_undo(obj);
err_undo_1s:
first_undo(obj);
return err;
}
The variable err should never be returned when it's equal to 0.
So if we annotate it, let's say as:
int __nzret err;
could sparse then warn if we forgot to assign it after
"if (some_check(obj))"?
Am I the only one who thinks this would be a good idea?
next reply other threads:[~2020-12-05 22:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-05 22:32 Jakub Kicinski [this message]
2020-12-05 23:10 ` sparse annotation for error types? Linus Torvalds
2020-12-06 0:13 ` Luc Van Oostenryck
2020-12-08 13:28 ` Dan Carpenter
2020-12-09 2:53 ` Zhang Changzhong
2020-12-19 11:55 ` Dan Carpenter
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=20201205143250.2378b9f9@kicinski-fedora-pc1c0hjn.DHCP.thefacebook.com \
--to=kuba@kernel.org \
--cc=edwin.peer@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=zhangchangzhong@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).