Received: by 10.223.164.202 with SMTP id h10csp275851wrb; Mon, 6 Nov 2017 06:29:15 -0800 (PST) X-Google-Smtp-Source: ABhQp+S1OJyMbtP+jOCkL/kGliPFK5IxX3SergJ98kzjJapmRMb7jKmLgDpuNZKAINIZMjAKWWgI X-Received: by 10.99.116.22 with SMTP id p22mr15458469pgc.372.1509978555499; Mon, 06 Nov 2017 06:29:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509978555; cv=none; d=google.com; s=arc-20160816; b=oGGHJiis2zjrRTwxUO7XdLqLhNlNqn6O+1iFJ17SVVAd4qpx7d14fCYFWQscT9SOn/ rMryiTPVpn3l6WIwURFV07f1aD1GZlzijJ+OJ1c2JQOzJtRRzFqjqM2MLMloRrzkYiVe ezKw2ZhXsBdJilKj0WaMW5/O6SmoPUqsuIOOyhr0Lxdty2ig94PWWJP/gVvvXkD/Dl3i 2JJMfvkyjtBdbSt+xsC4faHGV3LlxaDc5XlOyfpYU83fkxdnv2ratqb9ZUP9FbzWLWBc wkDUzBBam0TWi+AMIyWI2FcKy9OYJmDfjn5CQS8pZfFGrpuPj8m+9KmcylueJM00O3HW 4n+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=68fGBnn3nloAcYr4oF96s2Wa+XW8hmmdJzAIKetBLk8=; b=cNBzb2JpPfqjyx3hvJMdt+fHuCgcV2ECoDWtVDdSFMPKkieU2hj8C2ORKwDaxvu16d ImM8pCh6pMCFDsaLTPEc9BK4l/gpTpns4a2O7+DQnIaGT6IcbkR2AO6fYqlcSH9wL9GG dvvofIs4sS5ljC/Qi+KkwMEeLgAEE4QToIDxeBoYxsWk/Sge6etwALuAmHB5EnI76bY+ gmRESAvlq6cUGqWlEmAFVWzDkjzP1sZpLPc+b3Zz0AkHIRWYPCOYzBp6Mkvmt87y7T6K +2wcCqYbEmtgC6gaoos6YLG4jup4zM0bjHjtIFXk9C3dlzRFIDEcjsRI1L4+Fo3KzMSb zKSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HVZk8ExI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k67si11505801pga.110.2017.11.06.06.29.01; Mon, 06 Nov 2017 06:29:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HVZk8ExI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932205AbdKFO2L (ORCPT + 97 others); 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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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++) { -- 2.7.4 From 1583072248440300332@xxx Fri Nov 03 18:55:44 +0000 2017 X-GM-THRID: 1583072248440300332 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread