All of lore.kernel.org
 help / color / mirror / Atom feed
* Coccinelle Challenge Problem 3
@ 2017-02-23 18:29 Gargi Sharma
  2017-02-23 19:57 ` [Outreachy kernel] " Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Gargi Sharma @ 2017-02-23 18:29 UTC (permalink / raw)
  To: outreachy-kernel

[-- Attachment #1: Type: text/plain, Size: 405 bytes --]

Hi,

Here's my Coccinelle script to handle NULL tests for the following
functions kmalloc, devm_kzalloc, kmalloc_array, devm_ioremap,
usb_alloc_urb, alloc_netdev, dev_alloc_skb.

@@
expression ptr;
position p;
statement s0;
@@

ptr@p =
\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|usb_alloc_urb\|alloc_netdev\|dev_alloc_skb\)(...)
... when != ptr

if (
(
+ !
ptr
- == NULL
)
 ) s0

Thanks,
Gargi

[-- Attachment #2: Type: text/html, Size: 523 bytes --]

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

* Re: [Outreachy kernel] Coccinelle Challenge Problem 3
  2017-02-23 18:29 Coccinelle Challenge Problem 3 Gargi Sharma
@ 2017-02-23 19:57 ` Julia Lawall
  2017-02-23 20:43   ` Gargi Sharma
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2017-02-23 19:57 UTC (permalink / raw)
  To: Gargi Sharma; +Cc: outreachy-kernel

[-- Attachment #1: Type: text/plain, Size: 1270 bytes --]



On Thu, 23 Feb 2017, Gargi Sharma wrote:

> Hi,
>
> Here's my Coccinelle script to handle NULL tests for the following functions
> kmalloc, devm_kzalloc, kmalloc_array, devm_ioremap, usb_alloc_urb,
> alloc_netdev, dev_alloc_skb.
>
> @@
> expression ptr;
> position p;
> statement s0;
> @@
>
> ptr@p =\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|usb_alloc_urb\|alloc_
> netdev\|dev_alloc_skb\)(...)
> ... when != ptr
>
> if (
> (
> + !
> ptr
> - == NULL
> )
>  ) s0

This looks fine.  To be a bit more general, you can put "else s1".  If
there is an else that is just a metavariable that is not used elsewhere,
then it will also match the case where the else is completely absent.

julia

> Thanks,
> Gargi
>
> --
> 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 visithttps://groups.google.com/d/msgid/outreachy-kernel/CAOCi2DE66sqkwAAQiZKNYcY
> 5tWxg30n%2Bqmrq3Yqb2-L1uPHqBA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

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

* Re: [Outreachy kernel] Coccinelle Challenge Problem 3
  2017-02-23 19:57 ` [Outreachy kernel] " Julia Lawall
@ 2017-02-23 20:43   ` Gargi Sharma
  2017-02-23 20:46     ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Gargi Sharma @ 2017-02-23 20:43 UTC (permalink / raw)
  To: Julia Lawall; +Cc: outreachy-kernel

[-- Attachment #1: Type: text/plain, Size: 1730 bytes --]

On Fri, Feb 24, 2017 at 1:27 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>
>
>
> On Thu, 23 Feb 2017, Gargi Sharma wrote:
>
> > Hi,
> >
> > Here's my Coccinelle script to handle NULL tests for the following
functions
> > kmalloc, devm_kzalloc, kmalloc_array, devm_ioremap, usb_alloc_urb,
> > alloc_netdev, dev_alloc_skb.
> >
> > @@
> > expression ptr;
> > position p;
> > statement s0;
> > @@
> >
> > ptr@p
=\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|usb_alloc_urb\|alloc_
> > netdev\|dev_alloc_skb\)(...)
> > ... when != ptr
> >
> > if (
> > (
> > + !
> > ptr
> > - == NULL
> > )
> >  ) s0
>
> This looks fine.  To be a bit more general, you can put "else s1".  If
> there is an else that is just a metavariable that is not used elsewhere,
> then it will also match the case where the else is completely absent.

I did make the changes you suggested to my coccinelle script. I have a
confusion
though, when running this script on a directory, the script does not handle
all .c files
for some reason. For example wlan-ng staging driver has 12 .c files but the
script says
that only 4 files match.

gargi
>
> julia
>
> > Thanks,
> > Gargi
> >
> > --
> > 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 visithttps://
groups.google.com/d/msgid/outreachy-kernel/CAOCi2DE66sqkwAAQiZKNYcY
> > 5tWxg30n%2Bqmrq3Yqb2-L1uPHqBA%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> >

[-- Attachment #2: Type: text/html, Size: 2556 bytes --]

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

* Re: [Outreachy kernel] Coccinelle Challenge Problem 3
  2017-02-23 20:43   ` Gargi Sharma
@ 2017-02-23 20:46     ` Julia Lawall
  2017-02-24  5:57       ` Gargi Sharma
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2017-02-23 20:46 UTC (permalink / raw)
  To: Gargi Sharma; +Cc: outreachy-kernel

[-- Attachment #1: Type: text/plain, Size: 2882 bytes --]



On Fri, 24 Feb 2017, Gargi Sharma wrote:

> On Fri, Feb 24, 2017 at 1:27 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> >
> >
> >
> > On Thu, 23 Feb 2017, Gargi Sharma wrote:
> >
> > > Hi,
> > >
> > > Here's my Coccinelle script to handle NULL tests for the following
> functions
> > > kmalloc, devm_kzalloc, kmalloc_array, devm_ioremap, usb_alloc_urb,
> > > alloc_netdev, dev_alloc_skb.
> > >
> > > @@
> > > expression ptr;
> > > position p;
> > > statement s0;
> > > @@
> > >
> > > ptr@p=\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|usb_alloc_urb\|alloc
> _
> > > netdev\|dev_alloc_skb\)(...)
> > > ... when != ptr
> > >
> > > if (
> > > (
> > > + !
> > > ptr
> > > - == NULL
> > > )
> > >  ) s0
> >
> > This looks fine.  To be a bit more general, you can put "else s1".  If
> > there is an else that is just a metavariable that is not used elsewhere,
> > then it will also match the case where the else is completely absent.
>
> I did make the changes you suggested to my coccinelle script. I have a
> confusion
> though, when running this script on a directory, the script does not handle
> all .c files
> for some reason. For example wlan-ng staging driver has 12 .c files but the
> script says
> that only 4 files match.

Coccinelle analyzes your semantic patch to find the important words.  In
this case, they would be kmalloc etc.  I guess the other files don't
contain these important words.  Since there is no chance that the rule
will match, Coccinelle doesn't bother parsing them.  Coccinelle parsing
is often slow, particularly if it can't interpret something, in which
case is retries, so this gives a big time savings in practice.

julia


>
> gargi
> >
> > julia
> >
> > > Thanks,
> > > Gargi
> > >
> > > --
> > > 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 webvisithttps://groups.google.com/d/msgid/outreachy-kernel/CAOCi2DE66sqkwAAQiZ
> KNYcY
> > > 5tWxg30n%2Bqmrq3Yqb2-L1uPHqBA%40mail.gmail.com.
> > > For more options, visit https://groups.google.com/d/optout.
> > >
> > >
>
> --
> 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 visithttps://groups.google.com/d/msgid/outreachy-kernel/CAOCi2DFbaEUW4Nrwkq-AeaX
> T28xJyX5D0SRkoAyUNDfrijujkw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

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

* Re: [Outreachy kernel] Coccinelle Challenge Problem 3
  2017-02-23 20:46     ` Julia Lawall
@ 2017-02-24  5:57       ` Gargi Sharma
  0 siblings, 0 replies; 5+ messages in thread
From: Gargi Sharma @ 2017-02-24  5:57 UTC (permalink / raw)
  To: Julia Lawall; +Cc: outreachy-kernel

[-- Attachment #1: Type: text/plain, Size: 3280 bytes --]

On Fri, Feb 24, 2017 at 2:16 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>
>
>
> On Fri, 24 Feb 2017, Gargi Sharma wrote:
>
> > On Fri, Feb 24, 2017 at 1:27 AM, Julia Lawall <julia.lawall@lip6.fr>
wrote:
> > >
> > >
> > >
> > > On Thu, 23 Feb 2017, Gargi Sharma wrote:
> > >
> > > > Hi,
> > > >
> > > > Here's my Coccinelle script to handle NULL tests for the following
> > functions
> > > > kmalloc, devm_kzalloc, kmalloc_array, devm_ioremap, usb_alloc_urb,
> > > > alloc_netdev, dev_alloc_skb.
> > > >
> > > > @@
> > > > expression ptr;
> > > > position p;
> > > > statement s0;
> > > > @@
> > > >
> > > > ptr@p
=\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|usb_alloc_urb\|alloc
> > _
> > > > netdev\|dev_alloc_skb\)(...)
> > > > ... when != ptr
> > > >
> > > > if (
> > > > (
> > > > + !
> > > > ptr
> > > > - == NULL
> > > > )
> > > >  ) s0
> > >
> > > This looks fine.  To be a bit more general, you can put "else s1".  If
> > > there is an else that is just a metavariable that is not used
elsewhere,
> > > then it will also match the case where the else is completely absent.
> >
> > I did make the changes you suggested to my coccinelle script. I have a
> > confusion
> > though, when running this script on a directory, the script does not
handle
> > all .c files
> > for some reason. For example wlan-ng staging driver has 12 .c files but
the
> > script says
> > that only 4 files match.
>
> Coccinelle analyzes your semantic patch to find the important words.  In
> this case, they would be kmalloc etc.  I guess the other files don't
> contain these important words.  Since there is no chance that the rule
> will match, Coccinelle doesn't bother parsing them.  Coccinelle parsing
> is often slow, particularly if it can't interpret something, in which
> case is retries, so this gives a big time savings in practice.

That makes a lot of sense. I checked the other files in the driver and they
did not contain the important words as you said.

Thanks,
Gargi

>
> julia
>
>
> >
> > gargi
> > >
> > > julia
> > >
> > > > Thanks,
> > > > Gargi
> > > >
> > > > --
> > > > 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 webvisithttps://
groups.google.com/d/msgid/outreachy-kernel/CAOCi2DE66sqkwAAQiZ
> > KNYcY
> > > > 5tWxg30n%2Bqmrq3Yqb2-L1uPHqBA%40mail.gmail.com.
> > > > For more options, visit https://groups.google.com/d/optout.
> > > >
> > > >
> >
> > --
> > 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 visithttps://
groups.google.com/d/msgid/outreachy-kernel/CAOCi2DFbaEUW4Nrwkq-AeaX
> > T28xJyX5D0SRkoAyUNDfrijujkw%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> >

[-- Attachment #2: Type: text/html, Size: 5168 bytes --]

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

end of thread, other threads:[~2017-02-24  5:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-23 18:29 Coccinelle Challenge Problem 3 Gargi Sharma
2017-02-23 19:57 ` [Outreachy kernel] " Julia Lawall
2017-02-23 20:43   ` Gargi Sharma
2017-02-23 20:46     ` Julia Lawall
2017-02-24  5:57       ` Gargi Sharma

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.