Skip to contentSkip to conversation

virtio_blk: don't blindly derefence req->rq_disk

PATCH In review Christoph Hellwig 2 participants 2 messages May 11, 2009 – May 12, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio_blk: don't blindly derefence req->rq_disk

request->rq_disk is only set for FS requests or BLOCK_PC requests originating from the generic block layer scsi ioctls. It's not set for requests origination from other soures or internal cache flush commands implemented by the patch I'll send after this.

So instead of using it to get at the private data in do_virtblk_request setup queue->queuedata and use it.

drivers/block/virtio_blk.c +2 -2
Index: xfs/drivers/block/virtio_blk.c
===================================================================
@@ -153,12 +153,11 @@ static bool do_req(struct request_queue 
 
 static void do_virtblk_request(struct request_queue *q)
 {
-	struct virtio_blk *vblk = NULL;
+	struct virtio_blk *vblk = q->queuedata;
 	struct request *req;
 	unsigned int issued = 0;
 
 	while ((req = elv_next_request(q)) != NULL) {
-		vblk = req->rq_disk->private_data;
 		BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
 
 		/* If this request fails, stop queue and wait for something to
@@ -286,6 +285,7 @@ static int virtblk_probe(struct virtio_d
 		goto out_put_disk;
 	}
 
+	vblk->disk->queue->queuedata = vblk;
 	queue_flag_set_unlocked(QUEUE_FLAG_VIRT, vblk->disk->queue);
 
 	if (index < 26) {
#1 lore raw
Quoted 7 lines · Christoph Hellwig

request->rq_disk is only set for FS requests or BLOCK_PC requests originating from the generic block layer scsi ioctls. It's not set for requests origination from other soures or internal cache flush commands implemented by the patch I'll send after this.

So instead of using it to get at the private data in do_virtblk_request setup queue->queuedata and use it.

OK, shows how little I know about the block layer, seems fine.

Applied thanks,
Rusty.
(For those paying attention: we still need disk->private_data for get_geo).