All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Staging: media: Use !x in place of NULL comparision
@ 2019-03-21  9:35 Bhanusree Pola
  2019-03-22  6:40 ` [Outreachy kernel] " Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Bhanusree Pola @ 2019-03-21  9:35 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Greg Kroah-Hartman, Mauro Carvalho Chehab

Test for NULL as !x instead of NULL comparisions for
functions that return NULL on failure.
Issue found using coccinelle
Semantic patch used to solve the problem is as follows

// <smpl>
@@
expression x;
statement S;
@@

x = (\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|
usb_alloc_urb\|alloc_netdev\|dev_alloc_skb\)(...));

-if(x==NULL)
+if(!x)
// </smpl>

Signed-off-by: Bhanusree Pola <bhanusreemahesh@gmail.com>
---
 drivers/staging/media/zoran/zoran_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/zoran/zoran_driver.c b/drivers/staging/media/zoran/zoran_driver.c
index 04f88f9d6bb4..0a99e16e5bd5 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -332,7 +332,7 @@ static int jpg_fbuffer_alloc(struct zoran_fh *fh)
 
 		if (fh->buffers.need_contiguous) {
 			mem = kmalloc(fh->buffers.buffer_size, GFP_KERNEL);
-			if (mem == NULL) {
+			if (!mem) {
 				dprintk(1,
 					KERN_ERR
 					"%s: %s - kmalloc failed for buffer %d\n",
-- 
2.17.1



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

* Re: [Outreachy kernel] [PATCH] Staging: media: Use !x in place of NULL comparision
  2019-03-21  9:35 [PATCH] Staging: media: Use !x in place of NULL comparision Bhanusree Pola
@ 2019-03-22  6:40 ` Julia Lawall
  2019-03-22  6:45   ` Bhanusree Mahesh
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2019-03-22  6:40 UTC (permalink / raw)
  To: Bhanusree Pola
  Cc: outreachy-kernel, Greg Kroah-Hartman, Mauro Carvalho Chehab



On Thu, 21 Mar 2019, Bhanusree Pola wrote:

> Test for NULL as !x instead of NULL comparisions for
> functions that return NULL on failure.
> Issue found using coccinelle
> Semantic patch used to solve the problem is as follows
>
> // <smpl>
> @@
> expression x;
> statement S;
> @@
>
> x = (\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|
> usb_alloc_urb\|alloc_netdev\|dev_alloc_skb\)(...));
>
> -if(x==NULL)
> +if(!x)

This may have been accepted already, in which case don't worry about it,
but the semantic patch is not correct.  You need to use the S metavariable
that you declared.  Coccinelle paterns should be complete syntactic units,
so an if needs at least a then branch.

julia

> // </smpl>
>
> Signed-off-by: Bhanusree Pola <bhanusreemahesh@gmail.com>
> ---
>  drivers/staging/media/zoran/zoran_driver.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/media/zoran/zoran_driver.c b/drivers/staging/media/zoran/zoran_driver.c
> index 04f88f9d6bb4..0a99e16e5bd5 100644
> --- a/drivers/staging/media/zoran/zoran_driver.c
> +++ b/drivers/staging/media/zoran/zoran_driver.c
> @@ -332,7 +332,7 @@ static int jpg_fbuffer_alloc(struct zoran_fh *fh)
>
>  		if (fh->buffers.need_contiguous) {
>  			mem = kmalloc(fh->buffers.buffer_size, GFP_KERNEL);
> -			if (mem == NULL) {
> +			if (!mem) {
>  				dprintk(1,
>  					KERN_ERR
>  					"%s: %s - kmalloc failed for buffer %d\n",
> --
> 2.17.1
>
> --
> 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/20190321093527.8167-1-bhanusreemahesh%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>


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

* Re: [Outreachy kernel] [PATCH] Staging: media: Use !x in place of NULL comparision
  2019-03-22  6:40 ` [Outreachy kernel] " Julia Lawall
@ 2019-03-22  6:45   ` Bhanusree Mahesh
  0 siblings, 0 replies; 3+ messages in thread
From: Bhanusree Mahesh @ 2019-03-22  6:45 UTC (permalink / raw)
  To: Julia Lawall; +Cc: outreachy-kernel, Greg Kroah-Hartman, Mauro Carvalho Chehab

On Fri, 22 Mar 2019 at 12:10, Julia Lawall <julia.lawall@lip6.fr> wrote:
>
>
>
> On Thu, 21 Mar 2019, Bhanusree Pola wrote:
>
> > Test for NULL as !x instead of NULL comparisions for
> > functions that return NULL on failure.
> > Issue found using coccinelle
> > Semantic patch used to solve the problem is as follows
> >
> > // <smpl>
> > @@
> > expression x;
> > statement S;
> > @@
> >
> > x = (\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|
> > usb_alloc_urb\|alloc_netdev\|dev_alloc_skb\)(...));
> >
> > -if(x==NULL)
> > +if(!x)
>
> This may have been accepted already, in which case don't worry about it,
> but the semantic patch is not correct.  You need to use the S metavariable
> that you declared.  Coccinelle paterns should be complete syntactic units,
> so an if needs at least a then branch.

ok. I understand that. I'll take care of it.

Bhanusree
>
> julia
>
> > // </smpl>
> >
> > Signed-off-by: Bhanusree Pola <bhanusreemahesh@gmail.com>
> > ---
> >  drivers/staging/media/zoran/zoran_driver.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/media/zoran/zoran_driver.c b/drivers/staging/media/zoran/zoran_driver.c
> > index 04f88f9d6bb4..0a99e16e5bd5 100644
> > --- a/drivers/staging/media/zoran/zoran_driver.c
> > +++ b/drivers/staging/media/zoran/zoran_driver.c
> > @@ -332,7 +332,7 @@ static int jpg_fbuffer_alloc(struct zoran_fh *fh)
> >
> >               if (fh->buffers.need_contiguous) {
> >                       mem = kmalloc(fh->buffers.buffer_size, GFP_KERNEL);
> > -                     if (mem == NULL) {
> > +                     if (!mem) {
> >                               dprintk(1,
> >                                       KERN_ERR
> >                                       "%s: %s - kmalloc failed for buffer %d\n",
> > --
> > 2.17.1
> >
> > --
> > 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/20190321093527.8167-1-bhanusreemahesh%40gmail.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 visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1903220739080.2621%40hadrien.
> For more options, visit https://groups.google.com/d/optout.


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

end of thread, other threads:[~2019-03-22  6:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-21  9:35 [PATCH] Staging: media: Use !x in place of NULL comparision Bhanusree Pola
2019-03-22  6:40 ` [Outreachy kernel] " Julia Lawall
2019-03-22  6:45   ` Bhanusree Mahesh

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.