cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Denis Efremov <efremov@linux.com>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: Coccinelle <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] How to match function-like macro calls, e.g. RTA_ALIGN(rta->rta_len)?
Date: Mon, 11 Jan 2021 23:49:00 +0300	[thread overview]
Message-ID: <b671db37-a57a-6ee4-5324-26658c2ec9ef@linux.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2101112135260.15982@hadrien>



On 1/11/21 11:40 PM, Julia Lawall wrote:
> 
> 
> On Mon, 11 Jan 2021, Denis Efremov wrote:
> 
>>
>>
>> On 1/11/21 11:23 PM, Julia Lawall wrote:
>>>
>>>
>>> On Mon, 11 Jan 2021, Denis Efremov wrote:
>>>
>>>> Hi,
>>>>
>>>> Let's suppose I want to match otx_cpt_aead_cbc_aes_sha_setkey() function from
>>>> drivers/crypto/marvell/octeontx/otx_cptvf_algs.c file (linux kernel).
>>>>
>>>> My pattern:
>>>> @exists@
>>>> identifier rta, param, key, keylen;
>>>> position p;
>>>> @@
>>>>
>>>> otx_cpt_aead_cbc_aes_sha_setkey(...,
>>>> 	unsigned char *key, unsigned int keylen)
>>>> {
>>>> 	...
>>>> *	if (RTA_PAYLOAD(rta) < sizeof(*param))@p
>>>> 		goto badkey;
>>>> 	...
>>>> *	key += RTA_ALIGN(rta->rta_len);
>>>> *	keylen -= RTA_ALIGN(rta->rta_len);
>>>> 	...
>>>> }
>>>>
>>>> $ spatch --no-includes --include-headers --cocci-file test.cocci drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
>>>> init_defs_builtins: /usr/lib64/coccinelle/standard.h
>>>> minus: parse error:
>>>>   File "test.cocci", line 13, column 9, charpos = 219
>>>>   around = 'RTA_ALIGN',
>>>>   whole content = *     key += RTA_ALIGN(rta->rta_len);
>>>>
>>>>
>>>> What can I do to match RTA_ALIGN(...) lines?
>>>
>>> I don't understand the problem.  I took your rule and your command line,
>>> and everything was fine.
>>
>> I use version:
>> spatch version 1.0.8-gc1dbb4f-dirty compiled with OCaml version 4.11.1
>> Flags passed to the configure script: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-python=/usr/bin/python3 --with-menhir=/usr/bin/menhir
>> OCaml scripting support: yes
>> Python scripting support: yes
>> Syntax of regular expressions: PCRE
>>
>> Maybe parsing error is fixed in new versions?
> 
> I can't imagine what would cause a parsing error here.  I don't see what
> could be special about RTA_ALIGN.  Normally Coccinelle doesn't even know
> that it is a macro.  Maybe you can try to simplify the semantic patch a
> little bit and see if there is some change that causes the problem to
> disappear?  Does the problem disappear if you use a name other than
> RTA_ALIGN?

Changing:
	key += RTA_ALIGN(rta->rta_len);
to:
	key = RTA_ALIGN(rta->rta_len);

makes the parsing error disappear.

Using aop instead of += leads to the same parsing error:
assignment operator aop;
key aop RTA_ALIGN(rta->rta_len);
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error: 
  File "test.cocci", line 14, column 10, charpos = 245
  around = 'RTA_ALIGN',
  whole content = *     key aop RTA_ALIGN(rta->rta_len);

Denis
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  reply	other threads:[~2021-01-11 20:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 20:06 [Cocci] How to match function-like macro calls, e.g. RTA_ALIGN(rta->rta_len)? Denis Efremov
2021-01-11 20:23 ` Julia Lawall
2021-01-11 20:32   ` Denis Efremov
2021-01-11 20:40     ` Julia Lawall
2021-01-11 20:49       ` Denis Efremov [this message]
2021-01-11 20:59         ` Julia Lawall
2021-01-11 21:12           ` Denis Efremov

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=b671db37-a57a-6ee4-5324-26658c2ec9ef@linux.com \
    --to=efremov@linux.com \
    --cc=cocci@systeme.lip6.fr \
    --cc=julia.lawall@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).