[RFC 2/2] sd: free discard page in unprep function

James Bottomley
2010-06-30T17:11:01Z

This isn't a proper patch, but really just an illustration how freeing
should be done ... it still needs to be paired correctly with the
allocation (and error handling on the allocation path).

James

---

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 8802e48..7907be8 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -461,6 +461,12 @@ static int sd_prepare_discard(struct request *rq)
return BLKPREP_OK;
}

+static void sd_unprep_fn(struct request_queue *q, struct request *rq)
+{
+ if (rq->cmd_flags & REQ_DISCARD)
+ __free_page(bio_page(rq->bio));
+}
+
/**
* sd_init_command - build a scsi (read or write) command from
* information in the request structure.
@@ -2226,6 +2232,7 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
sd_revalidate_disk(gd);

blk_queue_prep_rq(sdp->request_queue, sd_prep_fn);
+ blk_queue_unprep_rq(sdp->request_queue, sd_unprep_fn);

gd->driverfs_dev = &sdp->sdev_gendev;
gd->flags = GENHD_FL_EXT_DEVT;