aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2010-07-08 04:16:17 -0400
committerJens Axboe <jaxboe@fusionio.com>2010-08-07 12:24:28 -0400
commit610a63498f7f366031a6327eaaa9963ffa110b2b (patch)
tree8ea7f0c9e1e2f41ee09677909a3491adeee31799 /drivers/scsi
parent9e094383b60066996fbc3b53891324e5d2ec858d (diff)
scsi: fix discard page leak
We leak a page allocated for discard on some error conditions (e.g. scsi_prep_state_check returns BLKPREP_DEFER in scsi_setup_blk_pc_cmnd). We unprep on requests that weren't prepped in the error path of scsi_init_io. It makes the error path to clean up scsi commands messy. Let's strictly apply the rule that we can't unprep on a request that wasn't prepped. Calling just scsi_put_command() in the error path of scsi_init_io() is enough. We don't set REQ_DONTPREP yet. scsi_setup_discard_cmnd can safely free a page on the error case with the above rule. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/scsi_lib.c7
-rw-r--r--drivers/scsi/sd.c10
2 files changed, 10 insertions, 7 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ee836193f531..b8de389636f8 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1011,11 +1011,8 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
1011 1011
1012err_exit: 1012err_exit:
1013 scsi_release_buffers(cmd); 1013 scsi_release_buffers(cmd);
1014 if (error == BLKPREP_KILL) 1014 scsi_put_command(cmd);
1015 scsi_put_command(cmd); 1015 cmd->request->special = NULL;
1016 else /* BLKPREP_DEFER */
1017 scsi_unprep_request(cmd->request);
1018
1019 return error; 1016 return error;
1020} 1017}
1021EXPORT_SYMBOL(scsi_init_io); 1018EXPORT_SYMBOL(scsi_init_io);
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 0994ab63b598..1d0c4b7c3b69 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -468,6 +468,10 @@ static int scsi_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
468 blk_add_request_payload(rq, page, len); 468 blk_add_request_payload(rq, page, len);
469 ret = scsi_setup_blk_pc_cmnd(sdp, rq); 469 ret = scsi_setup_blk_pc_cmnd(sdp, rq);
470 rq->buffer = page_address(page); 470 rq->buffer = page_address(page);
471 if (ret != BLKPREP_OK) {
472 __free_page(page);
473 rq->buffer = NULL;
474 }
471 return ret; 475 return ret;
472} 476}
473 477
@@ -485,8 +489,10 @@ static int scsi_setup_flush_cmnd(struct scsi_device *sdp, struct request *rq)
485 489
486static void sd_unprep_fn(struct request_queue *q, struct request *rq) 490static void sd_unprep_fn(struct request_queue *q, struct request *rq)
487{ 491{
488 if (rq->cmd_flags & REQ_DISCARD) 492 if (rq->cmd_flags & REQ_DISCARD) {
489 __free_page(virt_to_page(rq->buffer)); 493 free_page((unsigned long)rq->buffer);
494 rq->buffer = NULL;
495 }
490} 496}
491 497
492/** 498/**