missing_error_code2: warn about return ret where ret is zero
commit79b24d375920932f21d06a21f5c4f64f413def09
authorDan Carpenter <error27@gmail.com>
Fri, 25 Nov 2022 08:30:01 +0000 (25 11:30 +0300)
committerDan Carpenter <error27@gmail.com>
Fri, 25 Nov 2022 08:30:52 +0000 (25 11:30 +0300)
treece2ac1b83cf5e4fcf0cf081861cf461fd4e3b39b
parent50f54aebb9629872d07a30f5d8f9a3b9a0820aab
missing_error_code2: warn about return ret where ret is zero

This is for code like:

ret = frob();
if (ret)
return ret;

if (len != 10)
return ret;

Sometimes (quite often maybe?) the code really is supposed to return 0 but
often it's supposed to return an error code.  Even if zero is intended it's
more readable to return a literal zero instead of "ret".

This will not warn about code like:

ret = frob();
if (!ret)
return ret;

I have an unpublished check for code like that.  Those are normally
intentional but the canonical bug for that type of code is a reversed if
statement where the "!" was unintentional.  I feel like "return 0;" is
much better code in these cases as well, but I don't like getting into
draining style debates when there are so many real bugs which I don't
have time to fix.

Signed-off-by: Dan Carpenter <error27@gmail.com>
check_list.h
check_missing_error_code2.c [new file with mode: 0644]