netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Staging: irda: Do not check for NOT NULL before kfree()
@ 2017-12-18 19:11 Shreeya Patel
  2017-12-18 19:20 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Shreeya Patel @ 2017-12-18 19:11 UTC (permalink / raw)
  To: samuel, gregkh, netdev, devel, linux-kernel; +Cc: Shreeya Patel

Do not check for NOT NULL before calling kfree because if the
pointer is NULL, no action occurs.
Done using the following semantic patch by coccinelle.

@@
expression ptr;
@@

- if (ptr != NULL) {
  kfree(ptr);
  ptr = NULL;
- }

The semantic patch has the effect of adding an assignment
of ptr to NULL in the case where ptr is NULL already.

Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
---
 drivers/staging/irda/net/irnet/irnet_irda.c | 28 ++++++++++------------------
 drivers/staging/irda/net/irnet/irnet_ppp.c  | 10 ++++------
 2 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/irda/net/irnet/irnet_irda.c b/drivers/staging/irda/net/irnet/irnet_irda.c
index e390bce..9fb79fe 100644
--- a/drivers/staging/irda/net/irnet/irnet_irda.c
+++ b/drivers/staging/irda/net/irnet/irnet_irda.c
@@ -659,13 +659,9 @@ irda_irnet_destroy(irnet_socket *	self)
       self->iriap = NULL;
     }
 
-  /* Cleanup eventual discoveries from connection attempt or control channel */
-  if(self->discoveries != NULL)
-    {
-      /* Cleanup our copy of the discovery log */
-      kfree(self->discoveries);
-      self->discoveries = NULL;
-    }
+  /* Cleanup our copy of the discovery log */
+  kfree(self->discoveries);
+  self->discoveries = NULL;
 
   /* Close our IrTTP connection */
   if(self->tsap)
@@ -874,11 +870,9 @@ irnet_connect_socket(irnet_socket *	server,
       iriap_close(new->iriap);
       new->iriap = NULL;
     }
-  if(new->discoveries != NULL)
-    {
-      kfree(new->discoveries);
-      new->discoveries = NULL;
-    }
+
+  kfree(new->discoveries);
+  new->discoveries = NULL;
 
 #ifdef CONNECT_INDIC_KICK
   /* As currently we don't block packets in ppp_irnet_send() while passive,
@@ -1605,12 +1599,10 @@ irnet_discovervalue_confirm(int		result,
   /* No more items : remove the log and signal termination */
   DEBUG(IRDA_OCB_INFO, "Cleaning up log (0x%p)\n",
 	self->discoveries);
-  if(self->discoveries != NULL)
-    {
-      /* Cleanup our copy of the discovery log */
-      kfree(self->discoveries);
-      self->discoveries = NULL;
-    }
+
+  /* Cleanup our copy of the discovery log */
+  kfree(self->discoveries);
+  self->discoveries = NULL;
   self->disco_number = -1;
 
   /* Check out what we found */
diff --git a/drivers/staging/irda/net/irnet/irnet_ppp.c b/drivers/staging/irda/net/irnet/irnet_ppp.c
index 7025dcb..855ce58 100644
--- a/drivers/staging/irda/net/irnet/irnet_ppp.c
+++ b/drivers/staging/irda/net/irnet/irnet_ppp.c
@@ -259,12 +259,10 @@ irnet_read_discovery_log(irnet_socket *ap, char *event, int buf_size)
       /* No more items : remove the log and signal termination */
       DEBUG(CTRL_INFO, "Cleaning up log (0x%p)\n",
 	    ap->discoveries);
-      if(ap->discoveries != NULL)
-	{
-	  /* Cleanup our copy of the discovery log */
-	  kfree(ap->discoveries);
-	  ap->discoveries = NULL;
-	}
+
+      /* Cleanup our copy of the discovery log */
+      kfree(ap->discoveries);
+      ap->discoveries = NULL;
       ap->disco_number = -1;
     }
 
-- 
2.7.4

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

* Re: [PATCH] Staging: irda: Do not check for NOT NULL before kfree()
  2017-12-18 19:11 [PATCH] Staging: irda: Do not check for NOT NULL before kfree() Shreeya Patel
@ 2017-12-18 19:20 ` Stephen Hemminger
  2017-12-18 19:27   ` Shreeya Patel
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2017-12-18 19:20 UTC (permalink / raw)
  To: Shreeya Patel; +Cc: devel, gregkh, samuel, linux-kernel, netdev

On Tue, 19 Dec 2017 00:41:30 +0530
Shreeya Patel <shreeya.patel23498@gmail.com> wrote:

> Do not check for NOT NULL before calling kfree because if the
> pointer is NULL, no action occurs.
> Done using the following semantic patch by coccinelle.
> 
> @@
> expression ptr;
> @@
> 
> - if (ptr != NULL) {
>   kfree(ptr);
>   ptr = NULL;
> - }
> 
> The semantic patch has the effect of adding an assignment
> of ptr to NULL in the case where ptr is NULL already.
> 
> Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>

Please read drivers/staging/irda/TODO

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

* Re: [PATCH] Staging: irda: Do not check for NOT NULL before kfree()
  2017-12-18 19:20 ` Stephen Hemminger
@ 2017-12-18 19:27   ` Shreeya Patel
  0 siblings, 0 replies; 3+ messages in thread
From: Shreeya Patel @ 2017-12-18 19:27 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: devel, gregkh, samuel, linux-kernel, netdev

On Mon, 2017-12-18 at 11:20 -0800, Stephen Hemminger wrote:
> On Tue, 19 Dec 2017 00:41:30 +0530
> Shreeya Patel <shreeya.patel23498@gmail.com> wrote:
> 
> > 
> > Do not check for NOT NULL before calling kfree because if the
> > pointer is NULL, no action occurs.
> > Done using the following semantic patch by coccinelle.
> > 
> > @@
> > expression ptr;
> > @@
> > 
> > - if (ptr != NULL) {
> >   kfree(ptr);
> >   ptr = NULL;
> > - }
> > 
> > The semantic patch has the effect of adding an assignment
> > of ptr to NULL in the case where ptr is NULL already.
> > 
> > Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
> Please read drivers/staging/irda/TODO

Oh, I was not knowing about it.

Thank you
> 
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

end of thread, other threads:[~2017-12-18 19:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-18 19:11 [PATCH] Staging: irda: Do not check for NOT NULL before kfree() Shreeya Patel
2017-12-18 19:20 ` Stephen Hemminger
2017-12-18 19:27   ` Shreeya Patel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).