[Cocci] Finding and replacing a struct inside another struct

Luca Coelho luca at coelho.fi
Wed Aug 22 11:38:30 CEST 2018


On Wed, 2018-08-22 at 12:30 +0300, Luca Coelho wrote:
> Hi,
> 
> I need some help again. :)
> 
> I have a struct (cfg80211_crypto_settings) that contains a new
> element
> that I want to substitute for a function call
> (cfg_control_port_over_nl80211).  But this struct appears inside
> another struct.
> 
> So I tried this:
> 
> First I try to find a struct that contains the struct I want (with
> the
> @parent_child@ rule):
> 
> @parent_child@
> identifier child;
> identifier parent_type;
> @@
> struct parent_type
> {
> ...
> struct cfg80211_crypto_settings child;
> ...
> }
> 
> And then I try to match usage of the parent struct that I found:
> 
> @@
> identifier parent_child.child;
> identifier parent_child.parent_type;
> identifier p;
> @@
> struct parent_type *p;
> <...
> -p.child.control_over_nl80211
> +cfg_control_port_over_nl80211(&p.child)
> ...>

Ah, I think I found the problem... I was using p.child, but I was
defining p as a pointer!

I guess I should have this instead:

@@
identifier parent_child.child;
identifier parent_child.parent_type;
ide
ntifier p;
@@
struct parent_type *p;
<...
-p->child.control_over_nl80211
+cf
g_control_port_over_nl80211(&p->child)
...>

--
Luca.



More information about the Cocci mailing list