public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi_allocate_request() reference
@ 2005-03-21 13:26 Jens Axboe
  2005-03-21 15:09 ` James Bottomley
  0 siblings, 1 reply; 6+ messages in thread
From: Jens Axboe @ 2005-03-21 13:26 UTC (permalink / raw)
  To: linux-scsi; +Cc: James Bottomley

Hi,

scsi_allocate_request() doesn't hold a reference to the device that it
points to, that is not good. This patch fixes that up.

Signed-off-by: Jens Axboe <axboe@suse.de>

===== drivers/scsi/scsi.c 1.157 vs edited =====
--- 1.157/drivers/scsi/scsi.c	2005-03-03 09:22:17 +01:00
+++ edited/drivers/scsi/scsi.c	2005-03-21 14:24:27 +01:00
@@ -132,7 +132,11 @@
 	const int offset = ALIGN(sizeof(struct scsi_request), 4);
 	const int size = offset + sizeof(struct request);
 	struct scsi_request *sreq;
-  
+
+
+	if (!get_device(&sdev->sdev_gendev))
+		return NULL;
+
 	sreq = kmalloc(size, gfp_mask);
 	if (likely(sreq != NULL)) {
 		memset(sreq, 0, size);
@@ -141,7 +145,8 @@
 		sreq->sr_host = sdev->host;
 		sreq->sr_magic = SCSI_REQ_MAGIC;
 		sreq->sr_data_direction = DMA_BIDIRECTIONAL;
-	}
+	} else
+		put_device(&sdev->sdev_gendev);
 
 	return sreq;
 }
@@ -184,6 +189,10 @@
 void scsi_release_request(struct scsi_request *sreq)
 {
 	__scsi_release_request(sreq);
+
+	if (sreq->sr_device)
+		put_device(&sreq->sr_device->sdev_gendev);
+
 	kfree(sreq);
 }
 EXPORT_SYMBOL(scsi_release_request);

-- 
Jens Axboe


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

end of thread, other threads:[~2005-03-22 15:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-21 13:26 [PATCH] scsi_allocate_request() reference Jens Axboe
2005-03-21 15:09 ` James Bottomley
2005-03-21 16:57   ` Jens Axboe
2005-03-21 23:51     ` Tejun Heo
2005-03-22 11:17       ` Jens Axboe
2005-03-22 15:34         ` James Bottomley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox