Skip to contentSkip to conversation

Call slave_destroy in scsi_alloc_sdev error path

PATCH New Martin Hicks 1 participant 1 message Jan 9, 2004 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Call slave_destroy in scsi_alloc_sdev error path

Hello,

This patch fixes a potential memory leak in scsi_alloc_sdev.

If slave_alloc kmallocs memory and the get_device() (around line 245) fails then we goto the error path. The error path never calls slave_destroy.

This patch fixes this problem.
mh

Signature · 2 lines
Martin Hicks                Wild Open Source Inc.
[email protected]     613-266-2296

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1491 -> 1.1492
# drivers/scsi/scsi_scan.c 1.114 -> 1.115
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/01/09 [email protected] 1.1492
# We should call slave_destroy on the error path if slave_alloc

# has already been called and has succeeded in scsi_alloc_sdev()
# --------------------------------------------
#
diff -Nru a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
--- a/drivers/scsi/scsi_scan.c	Fri Jan  9 10:20:43 2004
+++ b/drivers/scsi/scsi_scan.c	Fri Jan  9 10:20:43 2004
@@ -254,7 +254,7 @@
 			 "%d:%d:%d:%d", sdev->host->host_no,
 			 sdev->channel, sdev->id, sdev->lun);
 	} else
-		goto out_free_queue;
+		goto out_cleanup_slave;

/*
* If there are any same target siblings, add this to the
@@ -283,6 +283,9 @@
spin_unlock_irqrestore(shost->host_lock, flags); return sdev;

+out_cleanup_slave:
+ if (shost->hostt->slave_destroy)
+ shost->hostt->slave_destroy(sdev);
out_free_queue:
scsi_free_queue(sdev->request_queue);
out_free_dev: