From: Vasiliy Kulikov <segooon@gmail.com>
To: kernel-janitors@vger.kernel.org
Subject: coccinelle script for correct handling of return values of
Date: Wed, 28 Jul 2010 17:04:28 +0000 [thread overview]
Message-ID: <20100728170428.GA23707@albatros> (raw)
Hi folks,
I'm currently working on this task:
http://kernelnewbies.org/KernelJanitors/Todo/ReturnCodes
I think this task can be partly done with coccinelle. The most often cases of
invalid handling is no handling :)
I am not guru of coccinelle, but I think it is very useful here. So,
I've written basic script of finding common errors, but it is not ideal.
Some trivial "metamorphisms" can be added, like this:
if (!x) ...
is equivalent in our case to
if (unlikely(!x)) ...
likely(), unlikely(), WARN(), some_driver_defined_assert(), etc.
Currently script finds ~400 patterns in linux-next, some of them are
false positive. Even if there were no false positives it is a rather
long process :)
So, I'm calling for help in raking this mess and improving the script.
// These are checks for allocation function, only comparation with 0 is ok
@@
identifier x;
identifier f ~= "request_region$\|kmalloc$\|vmalloc$\|pci_map_.*$\|get_free_pages$\|get_free_page$\|ioremap$\|create_proc_.*$";
statement S1, S2;
@@
\(
*x = f(...);
...
when != if (x) S1 else S2
when != if (x = 0) S1 else S2
when != if (x = NULL) S1 else S2
when != if (x != 0) S1 else S2
when != if (x != NULL) S1 else S2
when != if (!x) S1 else S2
when != return x;
\|
*f(...);
\)
// These are checks for functions that return 0 on success and smth <0 on error
// Result can be checked as (ret = 0), (ret < 0) and as (ret >= 0)
@@
identifier x;
identifier f ~= "request_irq$\|register_netdev$\|misc_register$\|scsi_register$\|put_user$\|get_user$\|kernel_thread$";
statement S1, S2;
@@
\(
*x = f(...);
...
when != if (x < 0) S1 else S2
when != if (x >= 0) S1 else S2
when != if (x != 0) S1 else S2
when != if (!x) S1 else S2
when != if (x = 0) S1 else S2
when != return x;
\|
*f(...);
\)
// These are function returning 0 on success and positive (!!!) result on error
// Result can be checked as (ret = 0), (ret > 0)
//
@@
identifier x;
identifier f ~= "copy_to_user$\|copy_from_user$";
statement S1, S2;
@@
\(
*x = f(...);
...
when != if (x) S1 else S2
when != if (!x) S1 else S2
when != if (x > 0) S1 else S2
when != return x;
\|
*f(...);
\)
Thanks,
Vasiliy.
reply other threads:[~2010-07-28 17:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20100728170428.GA23707@albatros \
--to=segooon@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
/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