* Coccinelle Constification
@ 2016-10-16 2:21 Elizabeth Ferdman
2016-10-16 3:04 ` [Outreachy kernel] " Eva Rachel Retuya
2016-10-16 5:33 ` Bhumika Goyal
0 siblings, 2 replies; 5+ messages in thread
From: Elizabeth Ferdman @ 2016-10-16 2:21 UTC (permalink / raw)
To: outreachy-kernel
I'd like to try doing constification using Coccinelle but I'm having
trouble starting on this task. Bhumika Goyal has submitted lots of these
and I've looked at the scripts she uses but I'm very confused about the
process.
Do you identify the structs that
need to be const first, then write the cocci script? If not, then what
is a basic script to use to find structs that need to be const? I can't
find any specific documentation that pertains to constification and
coccinelle.
Thanks,
Liz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Outreachy kernel] Coccinelle Constification
2016-10-16 2:21 Coccinelle Constification Elizabeth Ferdman
@ 2016-10-16 3:04 ` Eva Rachel Retuya
2016-10-16 18:39 ` Elizabeth Ferdman
2016-10-16 5:33 ` Bhumika Goyal
1 sibling, 1 reply; 5+ messages in thread
From: Eva Rachel Retuya @ 2016-10-16 3:04 UTC (permalink / raw)
To: Elizabeth Ferdman; +Cc: outreachy-kernel
Hello Liz,
I'm a fellow applicant so I might be wrong on some things but let me
share my experience so far with coccinelle usage.
On Sat, Oct 15, 2016 at 07:21:46PM -0700, Elizabeth Ferdman wrote:
> I'd like to try doing constification using Coccinelle but I'm having
> trouble starting on this task. Bhumika Goyal has submitted lots of these
> and I've looked at the scripts she uses but I'm very confused about the
> process.
>
> Do you identify the structs that
> need to be const first, then write the cocci script? If not, then what
> is a basic script to use to find structs that need to be const? I can't
> find any specific documentation that pertains to constification and
> coccinelle.
>
It depends on your approach. Sure you can manually identify by code
tracing if the struct qualifies to be made const then make a script to
write the changes esp. if there are lots of places to be changed.
You can also define a set of properties/situations where declaring the
structure const is justified like this:
https://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/commit/drivers/staging?h=staging-testing&id=1c099ed63f8363228a0b075a25511c9feb90e03f
and from there write your script so that it'll detect instances where
the criteria you previously defined is met. Now that covers detection,
for making the changes I suggest you write another one to cater
specifically to a specific driver and also include the transformation
that needs to be done.
About the basic script, I suggest you try to match any struct
declaration first using the disable optional_qualifier isomorphism
stated on the project's small task 1. Start small then build your way
up.
Once you get your basic script running, coordinate the rest with Julia.
Bhumika's patches are great reference, just observe the 'criteria' at
which structures can be deemed 'const'.
I hope I clear some of your confusion,
Eva
> Thanks,
> Liz
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20161016022145.GA2215%40localhost.
> For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Coccinelle Constification
2016-10-16 2:21 Coccinelle Constification Elizabeth Ferdman
2016-10-16 3:04 ` [Outreachy kernel] " Eva Rachel Retuya
@ 2016-10-16 5:33 ` Bhumika Goyal
2016-10-16 18:54 ` [Outreachy kernel] " Elizabeth Ferdman
1 sibling, 1 reply; 5+ messages in thread
From: Bhumika Goyal @ 2016-10-16 5:33 UTC (permalink / raw)
To: outreachy-kernel
[-- Attachment #1.1: Type: text/plain, Size: 1413 bytes --]
Hey Liz,
Eva has already explained the process well but I would like to
share my approach :
1. Firstly, I find all structures of the form static struct s i ={...};
by using the script:
@r disable optional_qualifier@
identifier s,i;
@@
* static struct s i ={...};
disable optional_qualifier is used here as we want to look only for
the non-const structures.
2. Now pick a structure instance from a file and look how it is used
in that file.
If the structure's fields are not getting modified => it can be
declared as const.
You will have to analyze the usage carefully so that nothing is missed.
Also, you can do a grep to be sure that all the referenced are covered.
3. After this you can write a Coccinelle script to constify all the
instances that follows this particular pattern of usage.
Make a rule in the script which matches the structure's reference that
is justified for const declaration and stores the reference position.
Look for the @ok@ rule in my scripts.
Now make another rule which looks for any other reference other
than the above one and stores this position as well.
Look for @bad@ rule for this step.
Next, add another rule @depends on !bad disable optional_qualifier@
that declares the structure as const.
4. After doing the changes compile the affected drivers and run
size <affected_file_name> to get the size details of the affected
file.
I hope this helps :)
Thanks,
Bhumika
[-- Attachment #1.2: Type: text/html, Size: 1577 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Outreachy kernel] Coccinelle Constification
2016-10-16 3:04 ` [Outreachy kernel] " Eva Rachel Retuya
@ 2016-10-16 18:39 ` Elizabeth Ferdman
0 siblings, 0 replies; 5+ messages in thread
From: Elizabeth Ferdman @ 2016-10-16 18:39 UTC (permalink / raw)
To: outreachy-kernel; +Cc: eraretuya
On Sun, Oct 16, 2016 at 11:04:20AM +0800, Eva Rachel Retuya wrote:
> Hello Liz,
>
> I'm a fellow applicant so I might be wrong on some things but let me
> share my experience so far with coccinelle usage.
>
> On Sat, Oct 15, 2016 at 07:21:46PM -0700, Elizabeth Ferdman wrote:
> > I'd like to try doing constification using Coccinelle but I'm having
> > trouble starting on this task. Bhumika Goyal has submitted lots of these
> > and I've looked at the scripts she uses but I'm very confused about the
> > process.
> >
> > Do you identify the structs that
> > need to be const first, then write the cocci script? If not, then what
> > is a basic script to use to find structs that need to be const? I can't
> > find any specific documentation that pertains to constification and
> > coccinelle.
> >
>
> It depends on your approach. Sure you can manually identify by code
> tracing if the struct qualifies to be made const then make a script to
> write the changes esp. if there are lots of places to be changed.
>
> You can also define a set of properties/situations where declaring the
> structure const is justified like this:
> https://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/commit/drivers/staging?h=staging-testing&id=1c099ed63f8363228a0b075a25511c9feb90e03f
>
Hey Eva,
Thanks so much for your reply and thanks for this link. That criteria is
very helpful esp because I'm a beginner in C and that clears up more of
what was going on in the long cocci script. It's a good idea to search
in greg's staging tree-- I had just been searching inside the
outreachy mailing list for the most part.
Liz
> and from there write your script so that it'll detect instances where
> the criteria you previously defined is met. Now that covers detection,
> for making the changes I suggest you write another one to cater
> specifically to a specific driver and also include the transformation
> that needs to be done.
>
> About the basic script, I suggest you try to match any struct
> declaration first using the disable optional_qualifier isomorphism
> stated on the project's small task 1. Start small then build your way
> up.
>
> Once you get your basic script running, coordinate the rest with Julia.
> Bhumika's patches are great reference, just observe the 'criteria' at
> which structures can be deemed 'const'.
>
> I hope I clear some of your confusion,
> Eva
>
> > Thanks,
> > Liz
> >
> > --
> > You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> > To post to this group, send email to outreachy-kernel@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20161016022145.GA2215%40localhost.
> > For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Outreachy kernel] Re: Coccinelle Constification
2016-10-16 5:33 ` Bhumika Goyal
@ 2016-10-16 18:54 ` Elizabeth Ferdman
0 siblings, 0 replies; 5+ messages in thread
From: Elizabeth Ferdman @ 2016-10-16 18:54 UTC (permalink / raw)
To: Bhumika Goyal; +Cc: outreachy-kernel
On Sat, Oct 15, 2016 at 10:33:11PM -0700, Bhumika Goyal wrote:
>
> Hey Liz,
>
> Eva has already explained the process well but I would like to
> share my approach :
>
> 1. Firstly, I find all structures of the form static struct s i ={...};
> by using the script:
> @r disable optional_qualifier@
> identifier s,i;
> @@
> * static struct s i ={...};
> disable optional_qualifier is used here as we want to look only for
> the non-const structures.
>
> 2. Now pick a structure instance from a file and look how it is used
> in that file.
> If the structure's fields are not getting modified => it can be
> declared as const.
> You will have to analyze the usage carefully so that nothing is missed.
> Also, you can do a grep to be sure that all the referenced are covered.
>
> 3. After this you can write a Coccinelle script to constify all the
> instances that follows this particular pattern of usage.
>
> Make a rule in the script which matches the structure's reference that
> is justified for const declaration and stores the reference position.
> Look for the @ok@ rule in my scripts.
> Now make another rule which looks for any other reference other
> than the above one and stores this position as well.
> Look for @bad@ rule for this step.
> Next, add another rule @depends on !bad disable optional_qualifier@
> that declares the structure as const.
>
> 4. After doing the changes compile the affected drivers and run
> size <affected_file_name> to get the size details of the affected
> file.
>
Hey Bhumika,
Thanks for your reply and all the advice. I understand a little
bit more about what's going on in those scripts now and I will give it a
try...
Liz
> I hope this helps :)
>
> Thanks,
> Bhumika
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/d11cf10a-059c-48ae-a33f-7950190831f5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-10-16 18:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-16 2:21 Coccinelle Constification Elizabeth Ferdman
2016-10-16 3:04 ` [Outreachy kernel] " Eva Rachel Retuya
2016-10-16 18:39 ` Elizabeth Ferdman
2016-10-16 5:33 ` Bhumika Goyal
2016-10-16 18:54 ` [Outreachy kernel] " Elizabeth Ferdman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.