[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1513624290-2965-1-git-send-email-shreeya.patel23498@gmail.com>
Date: Tue, 19 Dec 2017 00:41:30 +0530
From: Shreeya Patel <shreeya.patel23498@...il.com>
To: samuel@...tiz.org, gregkh@...uxfoundation.org,
netdev@...r.kernel.org, devel@...verdev.osuosl.org,
linux-kernel@...r.kernel.org
Cc: Shreeya Patel <shreeya.patel23498@...il.com>
Subject: [PATCH] Staging: irda: Do not check for NOT NULL before kfree()
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@...il.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
Powered by blists - more mailing lists