mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shreeya Patel <shreeya.patel23498@gmail.com>
To: samuel@sortiz.org, gregkh@linuxfoundation.org,
	netdev@vger.kernel.org, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org
Cc: Shreeya Patel <shreeya.patel23498@gmail.com>
Subject: [PATCH] Staging: irda: Do not check for NOT NULL before kfree()
Date: Tue, 19 Dec 2017 00:41:30 +0530	[thread overview]
Message-ID: <1513624290-2965-1-git-send-email-shreeya.patel23498@gmail.com> (raw)

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

             reply	other threads:[~2017-12-18 19:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-18 19:11 Shreeya Patel [this message]
2017-12-18 19:20 ` Stephen Hemminger
2017-12-18 19:27   ` Shreeya Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513624290-2965-1-git-send-email-shreeya.patel23498@gmail.com \
    --to=shreeya.patel23498@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=samuel@sortiz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®