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 <[EMAIL PROTECTED]>

===== 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

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to