Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934435AbdLRTLl (ORCPT ); Mon, 18 Dec 2017 14:11:41 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:38871 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933534AbdLRTLh (ORCPT ); Mon, 18 Dec 2017 14:11:37 -0500 X-Google-Smtp-Source: ACJfBouqFkU/ztvnTK605CwlaGKBJ+n/P8jfQJmp82tDjRmn7cs/LD+9/QL28abbjh8KQA61FQMfRQ== From: Shreeya Patel To: samuel@sortiz.org, gregkh@linuxfoundation.org, netdev@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Cc: Shreeya Patel Subject: [PATCH] Staging: irda: Do not check for NOT NULL before kfree() Date: Tue, 19 Dec 2017 00:41:30 +0530 Message-Id: <1513624290-2965-1-git-send-email-shreeya.patel23498@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3051 Lines: 98 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 --- 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