From patchwork Mon Nov 6 14:27:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Jha X-Patchwork-Id: 10043559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A5FBC603FF for ; Mon, 6 Nov 2017 14:28:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FF5328AED for ; Mon, 6 Nov 2017 14:28:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8474828B76; Mon, 6 Nov 2017 14:28:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D12D28AED for ; Mon, 6 Nov 2017 14:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752829AbdKFO2L (ORCPT ); Mon, 6 Nov 2017 09:28:11 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:52730 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752489AbdKFO2J (ORCPT ); Mon, 6 Nov 2017 09:28:09 -0500 Received: by mail-pg0-f65.google.com with SMTP id a192so8325759pge.9; Mon, 06 Nov 2017 06:28:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=68fGBnn3nloAcYr4oF96s2Wa+XW8hmmdJzAIKetBLk8=; b=HVZk8ExI8tJAHVcqpeIwWs+IlVCGTed1N0Z1nUMynKHYsN7vtTKiX6x36B1NI+CBH6 t6eXsoNb4+G9X3GQmidAnn7JVN+OziV73ottCbX/RjaxhoOjuX16lHAd+3Jn8LWYjPu/ aPvszDbxT6Oe6ECnm4Ggi/CYX6xwBcjjCi70kIiR01/M/lO/rRPqGMlrtq0rmDFM90vE gaFmYxnElvzY+xb+kuLrrWC6cJ01uWLQHpdS+JUXgsC5JLC9bD/fpiO40f4bvbbQEGHN q9L3wtmcrZ8azesCkQBEtmhlzBfBXRloGHBrJJrnggmNDEFmDO0FwzIaCEd/3F6FCeLT aq+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=68fGBnn3nloAcYr4oF96s2Wa+XW8hmmdJzAIKetBLk8=; b=FI/OANFSoJuAZ4ylYk+6gudu+INu7BRGXMH4cOELyNDLltxRMDO+EForVYMqHrnRcx f7kiQNDYioDkW2kHWha+ChBzBhXMg1xDtfffbGHu/d+BUp8aLYqSgvHzg07z65r6uqSA ORUGGY/BajK80jzpk9nssZdra5U3R6GllvZbTwj59fBOBFeRPRzfSY8umdBgM434Q5QK qRcD976jlcUZ0PvBH69yTBQNra3rsaq+3uL7v/iZn2Y2j6huG7uUj38fp91HJI5FXA1g lBoxvsz9MWIQ8K7YxYyzIQuKzszoLouNRm62byYnzbtqGlghNHrDSF+dDIT0q0+EHTP2 EWSw== X-Gm-Message-State: AMCzsaW75R9tCg1LECwiZcTXGjLiZ7iDQUBysOESftY8IUbGYDW1Dikr lTjiJW3kxr4cc0gVnvWSRRI= X-Google-Smtp-Source: ABhQp+Q42GmH8Ikv5o99tGfkV3WPKsH8RwZVSLqoKuQARE6H2LkE213sAyAaCZzb+KyXJNXe5CX9ow== X-Received: by 10.159.246.16 with SMTP id b16mr13691342pls.0.1509978489104; Mon, 06 Nov 2017 06:28:09 -0800 (PST) Received: from localhost.localdomain ([103.46.195.129]) by smtp.gmail.com with ESMTPSA id p14sm19968521pgr.51.2017.11.06.06.28.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Nov 2017 06:28:07 -0800 (PST) From: Himanshu Jha To: hare@suse.com Cc: jejb@linux.vnet.ibm.com, james.smart@broadcom.com, dick.kennedy@broadcom.com, kashyap.desai@broadcom.com, sumit.saxena@broadcom.com, QLogic-Storage-Upstream@cavium.com, qla2xxx-upstream@qlogic.com, jthumshirn@suse.de, bart.vanassche@wdc.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, megaraidlinux.pdl@broadcom.com, Himanshu Jha Subject: [PATCH] scsi: Remove null check before kfree Date: Mon, 6 Nov 2017 19:57:23 +0530 Message-Id: <1509978443-9853-1-git-send-email-himanshujha199640@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Kfree on NULL pointer is a no-op and therefore checking is redundant. Done using Coccinelle. Semantic patch used : @@ expression E; @@ - if (E != NULL) { kfree(E); } + kfree(E); @@ expression E; @@ - if (E != NULL) { kfree(E); E = NULL; } + kfree(E); + E = NULL; Signed-off-by: Himanshu Jha --- drivers/scsi/aic7xxx/aic79xx_core.c | 15 +++++---------- drivers/scsi/aic7xxx/aic7xxx_core.c | 15 +++++---------- drivers/scsi/aic94xx/aic94xx_init.c | 9 +++------ drivers/scsi/lpfc/lpfc_bsg.c | 3 +-- drivers/scsi/lpfc/lpfc_init.c | 6 ++---- drivers/scsi/megaraid/megaraid_sas_fusion.c | 3 +-- drivers/scsi/qedf/qedf_main.c | 3 +-- drivers/scsi/qla2xxx/qla_os.c | 12 ++++-------- 8 files changed, 22 insertions(+), 44 deletions(-) diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c index b560f39..7ad1df5 100644 --- a/drivers/scsi/aic7xxx/aic79xx_core.c +++ b/drivers/scsi/aic7xxx/aic79xx_core.c @@ -3681,8 +3681,7 @@ ahd_free_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel, int force) return; tstate = ahd->enabled_targets[scsi_id]; - if (tstate != NULL) - kfree(tstate); + kfree(tstate); ahd->enabled_targets[scsi_id] = NULL; } #endif @@ -6144,8 +6143,7 @@ ahd_set_unit(struct ahd_softc *ahd, int unit) void ahd_set_name(struct ahd_softc *ahd, char *name) { - if (ahd->name != NULL) - kfree(ahd->name); + kfree(ahd->name); ahd->name = name; } @@ -6212,12 +6210,9 @@ ahd_free(struct ahd_softc *ahd) kfree(ahd->black_hole); } #endif - if (ahd->name != NULL) - kfree(ahd->name); - if (ahd->seep_config != NULL) - kfree(ahd->seep_config); - if (ahd->saved_stack != NULL) - kfree(ahd->saved_stack); + kfree(ahd->name); + kfree(ahd->seep_config); + kfree(ahd->saved_stack); #ifndef __FreeBSD__ kfree(ahd); #endif diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c index 6612ff3..9c46c6d 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_core.c +++ b/drivers/scsi/aic7xxx/aic7xxx_core.c @@ -2200,8 +2200,7 @@ ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force) if (channel == 'B') scsi_id += 8; tstate = ahc->enabled_targets[scsi_id]; - if (tstate != NULL) - kfree(tstate); + kfree(tstate); ahc->enabled_targets[scsi_id] = NULL; } #endif @@ -4481,8 +4480,7 @@ ahc_set_unit(struct ahc_softc *ahc, int unit) void ahc_set_name(struct ahc_softc *ahc, char *name) { - if (ahc->name != NULL) - kfree(ahc->name); + kfree(ahc->name); ahc->name = name; } @@ -4549,10 +4547,8 @@ ahc_free(struct ahc_softc *ahc) kfree(ahc->black_hole); } #endif - if (ahc->name != NULL) - kfree(ahc->name); - if (ahc->seep_config != NULL) - kfree(ahc->seep_config); + kfree(ahc->name); + kfree(ahc->seep_config); #ifndef __FreeBSD__ kfree(ahc); #endif @@ -4957,8 +4953,7 @@ ahc_fini_scbdata(struct ahc_softc *ahc) case 0: break; } - if (scb_data->scbarray != NULL) - kfree(scb_data->scbarray); + kfree(scb_data->scbarray); } static void diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c index 6c83886..778df1a 100644 --- a/drivers/scsi/aic94xx/aic94xx_init.c +++ b/drivers/scsi/aic94xx/aic94xx_init.c @@ -584,8 +584,7 @@ static void asd_destroy_ha_caches(struct asd_ha_struct *asd_ha) if (asd_ha->hw_prof.scb_ext) asd_free_coherent(asd_ha, asd_ha->hw_prof.scb_ext); - if (asd_ha->hw_prof.ddb_bitmap) - kfree(asd_ha->hw_prof.ddb_bitmap); + kfree(asd_ha->hw_prof.ddb_bitmap); asd_ha->hw_prof.ddb_bitmap = NULL; for (i = 0; i < ASD_MAX_PHYS; i++) { @@ -597,10 +596,8 @@ static void asd_destroy_ha_caches(struct asd_ha_struct *asd_ha) asd_free_escbs(asd_ha); if (asd_ha->seq.edb_arr) asd_free_edbs(asd_ha); - if (asd_ha->hw_prof.ue.area) { - kfree(asd_ha->hw_prof.ue.area); - asd_ha->hw_prof.ue.area = NULL; - } + kfree(asd_ha->hw_prof.ue.area); + asd_ha->hw_prof.ue.area = NULL; if (asd_ha->seq.tc_index_array) { kfree(asd_ha->seq.tc_index_array); kfree(asd_ha->seq.tc_index_bitmap); diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c index d898162..3860df0 100644 --- a/drivers/scsi/lpfc/lpfc_bsg.c +++ b/drivers/scsi/lpfc/lpfc_bsg.c @@ -1275,8 +1275,7 @@ lpfc_bsg_hba_set_event(struct bsg_job *job) return 0; /* call job done later */ job_error: - if (dd_data != NULL) - kfree(dd_data); + kfree(dd_data); job->dd_data = NULL; return rc; diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 2b7ea7e..1bb9dbc 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -8388,10 +8388,8 @@ lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) static inline void lpfc_sli4_release_queue_map(uint16_t **qmap) { - if (*qmap != NULL) { - kfree(*qmap); - *qmap = NULL; - } + kfree(*qmap); + *qmap = NULL; } /** diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index 65dc4fe..ec50986 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -1642,8 +1642,7 @@ static inline void megasas_free_ioc_init_cmd(struct megasas_instance *instance) fusion->ioc_init_cmd->frame, fusion->ioc_init_cmd->frame_phys_addr); - if (fusion->ioc_init_cmd) - kfree(fusion->ioc_init_cmd); + kfree(fusion->ioc_init_cmd); } /** diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c index 7c00645..5316cba 100644 --- a/drivers/scsi/qedf/qedf_main.c +++ b/drivers/scsi/qedf/qedf_main.c @@ -2884,8 +2884,7 @@ static void qedf_free_fcoe_pf_param(struct qedf_ctx *qedf) qedf_free_global_queues(qedf); - if (qedf->global_queues) - kfree(qedf->global_queues); + kfree(qedf->global_queues); } /* diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c index 1865743..2b5b0fc 100644 --- a/drivers/scsi/qla2xxx/qla_os.c +++ b/drivers/scsi/qla2xxx/qla_os.c @@ -506,14 +506,10 @@ static void qla2x00_free_queues(struct qla_hw_data *ha) int cnt; unsigned long flags; - if (ha->queue_pair_map) { - kfree(ha->queue_pair_map); - ha->queue_pair_map = NULL; - } - if (ha->base_qpair) { - kfree(ha->base_qpair); - ha->base_qpair = NULL; - } + kfree(ha->queue_pair_map); + ha->queue_pair_map = NULL; + kfree(ha->base_qpair); + ha->base_qpair = NULL; spin_lock_irqsave(&ha->hardware_lock, flags); for (cnt = 0; cnt < ha->max_req_queues; cnt++) {