linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: aic7xxx: Remove unnecessary NULL checks before kfree
@ 2020-04-03 16:47 Alex Dewar
  2020-04-24 16:49 ` Martin K. Petersen
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Dewar @ 2020-04-03 16:47 UTC (permalink / raw)
  To: alex.dewar
  Cc: Hannes Reinecke, James E.J. Bottomley, Martin K. Petersen,
	linux-scsi, linux-kernel

There are a number of places in the aic7xxx driver where a NULL check is
performed before a kfree(). However, kfree() already performs NULL checks
so this is unnecessary. Remove the checks.

Issue identified with Coccinelle.

Signed-off-by: Alex Dewar <alex.dewar@gmx.co.uk>
---
 drivers/scsi/aic7xxx/aic79xx_core.c | 15 +++++----------
 drivers/scsi/aic7xxx/aic7xxx_core.c | 15 +++++----------
 2 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
index a336a458c978..72eaad4aef9c 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -3662,8 +3662,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
@@ -6120,8 +6119,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;
 }

@@ -6182,12 +6180,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);
 	kfree(ahd);
 	return;
 }
diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
index 84fc499cb1e6..5a10feea17fe 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -2178,8 +2178,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
@@ -4453,8 +4452,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;
 }

@@ -4515,10 +4513,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);
 	kfree(ahc);
 	return;
 }
@@ -4927,8 +4923,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
--
2.26.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: aic7xxx: Remove unnecessary NULL checks before kfree
  2020-04-03 16:47 [PATCH] scsi: aic7xxx: Remove unnecessary NULL checks before kfree Alex Dewar
@ 2020-04-24 16:49 ` Martin K. Petersen
  0 siblings, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2020-04-24 16:49 UTC (permalink / raw)
  To: Alex Dewar
  Cc: Hannes Reinecke, James E.J. Bottomley, Martin K. Petersen,
	linux-scsi, linux-kernel


Alex,

> There are a number of places in the aic7xxx driver where a NULL check
> is performed before a kfree(). However, kfree() already performs NULL
> checks so this is unnecessary. Remove the checks.
>
> Issue identified with Coccinelle.

Applied to 5.8/scsi-queue, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: aic7xxx: Remove unnecessary NULL checks before kfree
@ 2020-04-04  9:00 Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2020-04-04  9:00 UTC (permalink / raw)
  To: Alex Dewar, Hannes Reinecke, James E. J. Bottomley,
	Martin K. Petersen, linux-scsi
  Cc: linux-kernel

> There are a number of places in the aic7xxx driver where a NULL check is
> performed before a kfree(). However, kfree() already performs NULL checks
> so this is unnecessary. Remove the checks.

I suggest to reconsider the distribution of recipients also for this patch
according to the fields “Cc” and “To”.


Do you find a previous update suggestion like “SCSI-aic7...: Delete unnecessary
checks before the function call "kfree"” interesting?
https://lore.kernel.org/linux-scsi/54D3E057.9030600@users.sourceforge.net/
https://lore.kernel.org/patchwork/patch/540593/
https://lkml.org/lkml/2015/2/5/650

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-24 16:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-03 16:47 [PATCH] scsi: aic7xxx: Remove unnecessary NULL checks before kfree Alex Dewar
2020-04-24 16:49 ` Martin K. Petersen
2020-04-04  9:00 Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).