linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* sparse annotation for error types?
@ 2020-12-05 22:32 Jakub Kicinski
  2020-12-05 23:10 ` Linus Torvalds
  2020-12-08 13:28 ` Dan Carpenter
  0 siblings, 2 replies; 6+ messages in thread
From: Jakub Kicinski @ 2020-12-05 22:32 UTC (permalink / raw)
  To: linux-sparse; +Cc: linux-kernel, edwin.peer, Zhang Changzhong

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?

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-12-19 11:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-05 22:32 sparse annotation for error types? Jakub Kicinski
2020-12-05 23:10 ` 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

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 NNTP newsgroup(s).