cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] First coccinelle script, need some help.
@ 2018-10-10 19:38 Joel Fernandes
  2018-10-10 20:23 ` Julia Lawall
  0 siblings, 1 reply; 16+ messages in thread
From: Joel Fernandes @ 2018-10-10 19:38 UTC (permalink / raw)
  To: cocci


Hi!

I am trying to determine if a function argument is used across the whole
kernel for a certain kernel function.

I mustered up enough courage to write my first coccinelle script after a few
late nights of reading up about it :)

Here is .cocci script. I am trying to find if address is used at all in any
possible definitions of pte_alloc():

$ cat ~/pte_alloc.cocci
virtual report

@pte_args depends on report@
identifier E1, E2;
type T1, T2;
position p;
@@

 pte_alloc at p(T1 E1, T2 E2)
 {
...
(
...
 E2
...
)
...
 }

@script:python depends on report@
p << pte_args.p;
@@
coccilib.report.print_report(p[0], "WARNING: found definition of
apte_alloc_one with address used in the body")

The above warning does fire on the following test.c program:

struct page *pte_alloc(struct mm_struct *mm, unsigned long address)
{
        address++;
         if (condition()) {
                return NULL;
        }
}

But, *not* if I move 'address' into the if block:

struct page *pte_alloc(struct mm_struct *mm, unsigned long address)
{
         if (condition()) {
              address++;
              return NULL;
        }
}

I could not understand why, In my view the "address" expression should be
matched across the function body even within if blocks. But if I move
"address" into the if block, then the match doesn't occur any longer.

My coccicheck command is as follow:
make coccicheck COCCI=~/pte_alloc.cocci MODE=report  M=test/test.c

What am I missing? Thanks for any help.

thanks,

 - Joel

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

end of thread, other threads:[~2018-10-11 23:54 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-10 19:38 [Cocci] First coccinelle script, need some help Joel Fernandes
2018-10-10 20:23 ` Julia Lawall
2018-10-10 20:45   ` Joel Fernandes
2018-10-10 20:51     ` Julia Lawall
2018-10-10 21:11       ` Joel Fernandes
2018-10-10 21:12         ` Julia Lawall
     [not found]         ` <93da55ff-c807-6587-7ef3-3d2af820117d@users.sourceforge.net>
2018-10-11 15:43           ` [Cocci] Searching for parameter usages of pte_alloc() Joel Fernandes
2018-10-11 15:51             ` Julia Lawall
2018-10-11 16:28               ` Joel Fernandes
2018-10-11 16:40                 ` Julia Lawall
2018-10-11 16:49                   ` Joel Fernandes
2018-10-11 16:57                     ` Julia Lawall
2018-10-11 17:06                       ` Joel Fernandes
2018-10-11 18:06                   ` Joel Fernandes
2018-10-11 18:07                   ` Joel Fernandes
     [not found]             ` <cd2eb29e-775f-9c48-b839-b2ebdc3e3c56@users.sourceforge.net>
2018-10-11 23:54               ` Joel Fernandes

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).