Coccinelle Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: peter@hurleysoftware.com (Peter Hurley)
To: cocci@systeme.lip6.fr
Subject: [Cocci] how to find missing initializer
Date: Fri, 4 Dec 2015 06:54:50 -0500	[thread overview]
Message-ID: <56617F0A.50000@hurleysoftware.com> (raw)
In-Reply-To: <56608E06.9060003@metafoo.de>

On 12/03/2015 01:46 PM, Lars-Peter Clausen wrote:
> On 12/03/2015 02:04 PM, Peter Hurley wrote:
>> Hi all,
>>
>> I'm struggling with the grammar necessary to find struct definitions
>> missing an initializer.
>>
>> The background is that many tty interfaces include a method/operations
>> table (named fields of function ptrs). For example, given a declaration
>> like,
>>
>>     struct tty_operations {
>>             int (*install)( /* ... */ );
>>             int (*remove)( /* ... */ );
>>             void (*cleanup)( /* ... * );
>>     ...
>>     };
>>
>> a tty driver might define its method table like,
>>
>>     static const struct tty_operations ops = {
>>             .install = uart_install,
>> 	    .remove = uart_remove,
>>             .cleanup = uart_cleanup,
>>     ...
>>     };
>>
>>
>> (actually, this is a common pattern throughout the kernel)
>>
>> Many operations are optional; a NULL method is simply not executed.
>> For example,
>>
>>     if (tty->ops->cleanup)
>>             tty->ops->cleanup(tty);
>>
>> So trying to find those in-tree drivers which _do not_ define a cleanup
>> method with coccinelle, led to this fragment which has a parse error.
>>
>> Apologies if my question is obvious or trivial; I'm still learning
>> coccinelle.
> 
> Usually you'd do something like first find all that have the initializer and
> then match all that where not matched before using a position metavariable. E.g.
> 
> @r1@
> identifier fops;
> identifier fn;
> position p;
> @@
> struct tty_operations fops at p = {
>     ...,
>     .cleanup = fn,
>     ...
> };
> 
> @@
> identifier fops;
> identifier fn;
> position p != r1.p;
> @@
> *struct tty_operations fops at p = {
>     ...
> };
> 

I appreciate the quick response. Thanks all.

Regards,
Peter Hurley

  parent reply	other threads:[~2015-12-04 11:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-03 13:04 [Cocci] how to find missing initializer Peter Hurley
2015-12-03 18:46 ` Lars-Peter Clausen
2015-12-03 22:12   ` Julia Lawall
2015-12-03 23:48     ` Luis R. Rodriguez
2015-12-04 13:55       ` [Cocci] Searching with SmPL for missing clean-up settings in designated initialisers SF Markus Elfring
2015-12-04 14:44         ` Julia Lawall
2015-12-04 15:42           ` SF Markus Elfring
2015-12-04 11:31     ` [Cocci] how to find missing initializer SF Markus Elfring
2015-12-04 13:18       ` Julia Lawall
2015-12-04 11:54   ` Peter Hurley [this message]
2015-12-03 19:26 ` Luis R. Rodriguez
2015-12-04  8:55 ` SF Markus Elfring

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=56617F0A.50000@hurleysoftware.com \
    --to=peter@hurleysoftware.com \
    --cc=cocci@systeme.lip6.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