lkml.org 
[lkml]   [2020]   [Dec]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectsparse annotation for error types?
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?

\
 
 \ /
  Last update: 2020-12-05 23:35    [W:0.063 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site