Backports Archive on lore.kernel.org
 help / Atom feed
* Finding and replacing a struct inside another struct
@ 2018-08-22  9:30 Luca Coelho
  2018-08-22  9:38 ` Luca Coelho
  2018-08-22 10:52 ` Julia Lawall
  0 siblings, 2 replies; 5+ messages in thread
From: Luca Coelho @ 2018-08-22  9:30 UTC (permalink / raw)
  To: cocci; +Cc: backports

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


But I'm getting some cryptic errors:

struct parent_type*
warning: line 715: req, previously declared as a metavariable, is used as an identifier
warning: line 732: req, previously declared as a metavariable, is used as an identifier
warning: line 740: req, previously declared as a metavariable, is used as an identifier
warning: line 912: should name_assign_type be a metavariable?
warning: line 918: params, previously declared as a metavariable, is used as an identifier
warning: line 933: params, previously declared as a metavariable, is used as an identifier
warning: line 941: should reqid be a metavariable?
line 1175: non-structure type in field ref
struct parent_type*
warning: line 715: req, previously declared as a metavariable, is used as an identifier
warning: line 732: req, previously declared as a metavariable, is used as an identifier
warning: line 740: req, previously declared as a metavariable, is used as an identifier
warning: line 912: should name_assign_type be a metavariable?
warning: line 918: params, previously declared as a metavariable, is used as an identifier
warning: line 933: params, previously declared as a metavariable, is used as an identifier
warning: line 941: should reqid be a metavariable?
line 1175: non-structure type in field ref


Does anyone know if there is a proper way to do is?

--
Cheers,
Luca.

--
To unsubscribe from this list: send the line "unsubscribe backports" in

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

* Re: Finding and replacing a struct inside another struct
  2018-08-22  9:30 Finding and replacing a struct inside another struct Luca Coelho
@ 2018-08-22  9:38 ` Luca Coelho
  2018-08-22 10:20   ` Luca Coelho
  2018-08-22 10:52 ` Julia Lawall
  1 sibling, 1 reply; 5+ messages in thread
From: Luca Coelho @ 2018-08-22  9:38 UTC (permalink / raw)
  To: cocci; +Cc: backports

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.

--
To unsubscribe from this list: send the line "unsubscribe backports" in

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

* Re: Finding and replacing a struct inside another struct
  2018-08-22  9:38 ` Luca Coelho
@ 2018-08-22 10:20   ` Luca Coelho
  2018-08-22 10:54     ` [Cocci] " Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Luca Coelho @ 2018-08-22 10:20 UTC (permalink / raw)
  To: cocci; +Cc: backports

On Wed, 2018-08-22 at 12:38 +0300, Luca Coelho wrote:
> 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;
> > ...
> > }

Unfortunately it seems that the parent struct doesn't really match with
this.  I guess I'll have to hardcode the parent struct as well.

--
Luca.

--
To unsubscribe from this list: send the line "unsubscribe backports" in

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

* Re: [Cocci] Finding and replacing a struct inside another struct
  2018-08-22  9:30 Finding and replacing a struct inside another struct Luca Coelho
  2018-08-22  9:38 ` Luca Coelho
@ 2018-08-22 10:52 ` Julia Lawall
  1 sibling, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2018-08-22 10:52 UTC (permalink / raw)
  To: Luca Coelho; +Cc: cocci, backports



On Wed, 22 Aug 2018, 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_nl80211F
> +cfg_control_port_over_nl80211(&p.child)
> ...>
>
>
> But I'm getting some cryptic errors:
>
> struct parent_type*
> warning: line 715: req, previously declared as a metavariable, is used as an identifier
> warning: line 732: req, previously declared as a metavariable, is used as an identifier
> warning: line 740: req, previously declared as a metavariable, is used as an identifier
> warning: line 912: should name_assign_type be a metavariable?
> warning: line 918: params, previously declared as a metavariable, is used as an identifier
> warning: line 933: params, previously declared as a metavariable, is used as an identifier
> warning: line 941: should reqid be a metavariable?
> line 1175: non-structure type in field ref
> struct parent_type*
> warning: line 715: req, previously declared as a metavariable, is used as an identifier
> warning: line 732: req, previously declared as a metavariable, is used as an identifier
> warning: line 740: req, previously declared as a metavariable, is used as an identifier
> warning: line 912: should name_assign_type be a metavariable?
> warning: line 918: params, previously declared as a metavariable, is used as an identifier
> warning: line 933: params, previously declared as a metavariable, is used as an identifier
> warning: line 941: should reqid be a metavariable?
> line 1175: non-structure type in field ref
>
>
> Does anyone know if there is a proper way to do is?

You already found the solution for the actual errors.  But it is good to
pay attention to the warnings too.  For "should name_assign_type be a
metavariable?" is it concerned because an explicit identifier name is used
as something other than the name of a function or the name of a field.  If
you really want to only match assign_type, then you can make a
metavariable-like declaration symbol assign_type; that basically means
that you know what you are doing and don't want to see the warning any
more.

julia
--
To unsubscribe from this list: send the line "unsubscribe backports" in

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

* Re: [Cocci] Finding and replacing a struct inside another struct
  2018-08-22 10:20   ` Luca Coelho
@ 2018-08-22 10:54     ` " Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2018-08-22 10:54 UTC (permalink / raw)
  To: Luca Coelho; +Cc: cocci, backports



On Wed, 22 Aug 2018, Luca Coelho wrote:

> On Wed, 2018-08-22 at 12:38 +0300, Luca Coelho wrote:
> > 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;
> > > ...
> > > }
>
> Unfortunately it seems that the parent struct doesn't really match with
> this.  I guess I'll have to hardcode the parent struct as well.

Is this a Coccinelle problem, or is the code just not organized as you
would like.  If it is a Coccinelle problem, please send the source code as
well.

thanks,
julia
--
To unsubscribe from this list: send the line "unsubscribe backports" in

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-22  9:30 Finding and replacing a struct inside another struct Luca Coelho
2018-08-22  9:38 ` Luca Coelho
2018-08-22 10:20   ` Luca Coelho
2018-08-22 10:54     ` [Cocci] " Julia Lawall
2018-08-22 10:52 ` Julia Lawall

Backports Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/backports/0 backports/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 backports backports/ https://lore.kernel.org/backports \
		backports@vger.kernel.org backports@archiver.kernel.org
	public-inbox-index backports


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.backports


AGPL code for this site: git clone https://public-inbox.org/ public-inbox