diff options
author | Joe Lawrence <joe.lawrence@stratus.com> | 2014-08-28 10:15:21 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-08-28 12:03:46 -0400 |
commit | a492f075450f3ba87de36e5ffe92a9d0c7af9723 (patch) | |
tree | 61960a71c7fde0eee3d77cda460154d2f7715d2f /drivers | |
parent | eb571eeade2598635f813b3284d02c13a380301e (diff) |
block,scsi: fixup blk_get_request dead queue scenarios
The blk_get_request function may fail in low-memory conditions or during
device removal (even if __GFP_WAIT is set). To distinguish between these
errors, modify the blk_get_request call stack to return the appropriate
ERR_PTR. Verify that all callers check the return status and consider
IS_ERR instead of a simple NULL pointer check.
For consistency, make a similar change to the blk_mq_alloc_request leg
of blk_get_request. It may fail if the queue is dead, or the caller was
unwilling to wait.
Signed-off-by: Joe Lawrence <joe.lawrence@stratus.com>
Acked-by: Jiri Kosina <jkosina@suse.cz> [for pktdvd]
Acked-by: Boaz Harrosh <bharrosh@panasas.com> [for osd]
Reviewed-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/paride/pd.c | 4 | ||||
-rw-r--r-- | drivers/block/pktcdvd.c | 4 | ||||
-rw-r--r-- | drivers/block/sx8.c | 2 | ||||
-rw-r--r-- | drivers/cdrom/cdrom.c | 4 | ||||
-rw-r--r-- | drivers/ide/ide-park.c | 2 | ||||
-rw-r--r-- | drivers/scsi/device_handler/scsi_dh_alua.c | 2 | ||||
-rw-r--r-- | drivers/scsi/device_handler/scsi_dh_emc.c | 2 | ||||
-rw-r--r-- | drivers/scsi/device_handler/scsi_dh_hp_sw.c | 4 | ||||
-rw-r--r-- | drivers/scsi/device_handler/scsi_dh_rdac.c | 2 | ||||
-rw-r--r-- | drivers/scsi/osd/osd_initiator.c | 4 | ||||
-rw-r--r-- | drivers/scsi/osst.c | 2 | ||||
-rw-r--r-- | drivers/scsi/scsi_error.c | 2 | ||||
-rw-r--r-- | drivers/scsi/scsi_lib.c | 2 | ||||
-rw-r--r-- | drivers/scsi/sg.c | 4 | ||||
-rw-r--r-- | drivers/scsi/st.c | 2 | ||||
-rw-r--r-- | drivers/target/target_core_pscsi.c | 2 |
16 files changed, 22 insertions, 22 deletions
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c index ca831f741d89..d48715b287e6 100644 --- a/drivers/block/paride/pd.c +++ b/drivers/block/paride/pd.c | |||
@@ -722,8 +722,8 @@ static int pd_special_command(struct pd_unit *disk, | |||
722 | int err = 0; | 722 | int err = 0; |
723 | 723 | ||
724 | rq = blk_get_request(disk->gd->queue, READ, __GFP_WAIT); | 724 | rq = blk_get_request(disk->gd->queue, READ, __GFP_WAIT); |
725 | if (!rq) | 725 | if (IS_ERR(rq)) |
726 | return -ENODEV; | 726 | return PTR_ERR(rq); |
727 | 727 | ||
728 | rq->cmd_type = REQ_TYPE_SPECIAL; | 728 | rq->cmd_type = REQ_TYPE_SPECIAL; |
729 | rq->special = func; | 729 | rq->special = func; |
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 7fa8c80e8982..09e628dafd9d 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c | |||
@@ -704,8 +704,8 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command * | |||
704 | 704 | ||
705 | rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ? | 705 | rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ? |
706 | WRITE : READ, __GFP_WAIT); | 706 | WRITE : READ, __GFP_WAIT); |
707 | if (!rq) | 707 | if (IS_ERR(rq)) |
708 | return -ENODEV; | 708 | return PTR_ERR(rq); |
709 | blk_rq_set_block_pc(rq); | 709 | blk_rq_set_block_pc(rq); |
710 | 710 | ||
711 | if (cgc->buflen) { | 711 | if (cgc->buflen) { |
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c index d5e2d12b9d9e..5d552857de41 100644 --- a/drivers/block/sx8.c +++ b/drivers/block/sx8.c | |||
@@ -568,7 +568,7 @@ static struct carm_request *carm_get_special(struct carm_host *host) | |||
568 | return NULL; | 568 | return NULL; |
569 | 569 | ||
570 | rq = blk_get_request(host->oob_q, WRITE /* bogus */, GFP_KERNEL); | 570 | rq = blk_get_request(host->oob_q, WRITE /* bogus */, GFP_KERNEL); |
571 | if (!rq) { | 571 | if (IS_ERR(rq)) { |
572 | spin_lock_irqsave(&host->lock, flags); | 572 | spin_lock_irqsave(&host->lock, flags); |
573 | carm_put_request(host, crq); | 573 | carm_put_request(host, crq); |
574 | spin_unlock_irqrestore(&host->lock, flags); | 574 | spin_unlock_irqrestore(&host->lock, flags); |
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 898b84bba28a..5d28a45d2960 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c | |||
@@ -2180,8 +2180,8 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf, | |||
2180 | len = nr * CD_FRAMESIZE_RAW; | 2180 | len = nr * CD_FRAMESIZE_RAW; |
2181 | 2181 | ||
2182 | rq = blk_get_request(q, READ, GFP_KERNEL); | 2182 | rq = blk_get_request(q, READ, GFP_KERNEL); |
2183 | if (!rq) { | 2183 | if (IS_ERR(rq)) { |
2184 | ret = -ENOMEM; | 2184 | ret = PTR_ERR(rq); |
2185 | break; | 2185 | break; |
2186 | } | 2186 | } |
2187 | blk_rq_set_block_pc(rq); | 2187 | blk_rq_set_block_pc(rq); |
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c index f41558a0bcd1..ca958604cda2 100644 --- a/drivers/ide/ide-park.c +++ b/drivers/ide/ide-park.c | |||
@@ -46,7 +46,7 @@ static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout) | |||
46 | * timeout has expired, so power management will be reenabled. | 46 | * timeout has expired, so power management will be reenabled. |
47 | */ | 47 | */ |
48 | rq = blk_get_request(q, READ, GFP_NOWAIT); | 48 | rq = blk_get_request(q, READ, GFP_NOWAIT); |
49 | if (unlikely(!rq)) | 49 | if (IS_ERR(rq)) |
50 | goto out; | 50 | goto out; |
51 | 51 | ||
52 | rq->cmd[0] = REQ_UNPARK_HEADS; | 52 | rq->cmd[0] = REQ_UNPARK_HEADS; |
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c index 7bcf67eec921..e99507ed0e3c 100644 --- a/drivers/scsi/device_handler/scsi_dh_alua.c +++ b/drivers/scsi/device_handler/scsi_dh_alua.c | |||
@@ -115,7 +115,7 @@ static struct request *get_alua_req(struct scsi_device *sdev, | |||
115 | 115 | ||
116 | rq = blk_get_request(q, rw, GFP_NOIO); | 116 | rq = blk_get_request(q, rw, GFP_NOIO); |
117 | 117 | ||
118 | if (!rq) { | 118 | if (IS_ERR(rq)) { |
119 | sdev_printk(KERN_INFO, sdev, | 119 | sdev_printk(KERN_INFO, sdev, |
120 | "%s: blk_get_request failed\n", __func__); | 120 | "%s: blk_get_request failed\n", __func__); |
121 | return NULL; | 121 | return NULL; |
diff --git a/drivers/scsi/device_handler/scsi_dh_emc.c b/drivers/scsi/device_handler/scsi_dh_emc.c index 6f07f7fe3aa1..84765384c47c 100644 --- a/drivers/scsi/device_handler/scsi_dh_emc.c +++ b/drivers/scsi/device_handler/scsi_dh_emc.c | |||
@@ -275,7 +275,7 @@ static struct request *get_req(struct scsi_device *sdev, int cmd, | |||
275 | 275 | ||
276 | rq = blk_get_request(sdev->request_queue, | 276 | rq = blk_get_request(sdev->request_queue, |
277 | (cmd != INQUIRY) ? WRITE : READ, GFP_NOIO); | 277 | (cmd != INQUIRY) ? WRITE : READ, GFP_NOIO); |
278 | if (!rq) { | 278 | if (IS_ERR(rq)) { |
279 | sdev_printk(KERN_INFO, sdev, "get_req: blk_get_request failed"); | 279 | sdev_printk(KERN_INFO, sdev, "get_req: blk_get_request failed"); |
280 | return NULL; | 280 | return NULL; |
281 | } | 281 | } |
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c b/drivers/scsi/device_handler/scsi_dh_hp_sw.c index e9d9fea9e272..4ee2759f5299 100644 --- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c +++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c | |||
@@ -117,7 +117,7 @@ static int hp_sw_tur(struct scsi_device *sdev, struct hp_sw_dh_data *h) | |||
117 | 117 | ||
118 | retry: | 118 | retry: |
119 | req = blk_get_request(sdev->request_queue, WRITE, GFP_NOIO); | 119 | req = blk_get_request(sdev->request_queue, WRITE, GFP_NOIO); |
120 | if (!req) | 120 | if (IS_ERR(req)) |
121 | return SCSI_DH_RES_TEMP_UNAVAIL; | 121 | return SCSI_DH_RES_TEMP_UNAVAIL; |
122 | 122 | ||
123 | blk_rq_set_block_pc(req); | 123 | blk_rq_set_block_pc(req); |
@@ -247,7 +247,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *h) | |||
247 | struct request *req; | 247 | struct request *req; |
248 | 248 | ||
249 | req = blk_get_request(h->sdev->request_queue, WRITE, GFP_ATOMIC); | 249 | req = blk_get_request(h->sdev->request_queue, WRITE, GFP_ATOMIC); |
250 | if (!req) | 250 | if (IS_ERR(req)) |
251 | return SCSI_DH_RES_TEMP_UNAVAIL; | 251 | return SCSI_DH_RES_TEMP_UNAVAIL; |
252 | 252 | ||
253 | blk_rq_set_block_pc(req); | 253 | blk_rq_set_block_pc(req); |
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c index 826069db9848..1b5bc9293e37 100644 --- a/drivers/scsi/device_handler/scsi_dh_rdac.c +++ b/drivers/scsi/device_handler/scsi_dh_rdac.c | |||
@@ -274,7 +274,7 @@ static struct request *get_rdac_req(struct scsi_device *sdev, | |||
274 | 274 | ||
275 | rq = blk_get_request(q, rw, GFP_NOIO); | 275 | rq = blk_get_request(q, rw, GFP_NOIO); |
276 | 276 | ||
277 | if (!rq) { | 277 | if (IS_ERR(rq)) { |
278 | sdev_printk(KERN_INFO, sdev, | 278 | sdev_printk(KERN_INFO, sdev, |
279 | "get_rdac_req: blk_get_request failed.\n"); | 279 | "get_rdac_req: blk_get_request failed.\n"); |
280 | return NULL; | 280 | return NULL; |
diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c index 5f4cbf0c4759..fd19fd8468ac 100644 --- a/drivers/scsi/osd/osd_initiator.c +++ b/drivers/scsi/osd/osd_initiator.c | |||
@@ -1567,8 +1567,8 @@ static struct request *_make_request(struct request_queue *q, bool has_write, | |||
1567 | struct request *req; | 1567 | struct request *req; |
1568 | 1568 | ||
1569 | req = blk_get_request(q, has_write ? WRITE : READ, flags); | 1569 | req = blk_get_request(q, has_write ? WRITE : READ, flags); |
1570 | if (unlikely(!req)) | 1570 | if (IS_ERR(req)) |
1571 | return ERR_PTR(-ENOMEM); | 1571 | return req; |
1572 | 1572 | ||
1573 | blk_rq_set_block_pc(req); | 1573 | blk_rq_set_block_pc(req); |
1574 | return req; | 1574 | return req; |
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c index 0727ea7cc387..dff37a250d79 100644 --- a/drivers/scsi/osst.c +++ b/drivers/scsi/osst.c | |||
@@ -362,7 +362,7 @@ static int osst_execute(struct osst_request *SRpnt, const unsigned char *cmd, | |||
362 | int write = (data_direction == DMA_TO_DEVICE); | 362 | int write = (data_direction == DMA_TO_DEVICE); |
363 | 363 | ||
364 | req = blk_get_request(SRpnt->stp->device->request_queue, write, GFP_KERNEL); | 364 | req = blk_get_request(SRpnt->stp->device->request_queue, write, GFP_KERNEL); |
365 | if (!req) | 365 | if (IS_ERR(req)) |
366 | return DRIVER_ERROR << 24; | 366 | return DRIVER_ERROR << 24; |
367 | 367 | ||
368 | blk_rq_set_block_pc(req); | 368 | blk_rq_set_block_pc(req); |
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 4c433bf47a06..a2c3d3d255a1 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c | |||
@@ -1960,7 +1960,7 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) | |||
1960 | * request becomes available | 1960 | * request becomes available |
1961 | */ | 1961 | */ |
1962 | req = blk_get_request(sdev->request_queue, READ, GFP_KERNEL); | 1962 | req = blk_get_request(sdev->request_queue, READ, GFP_KERNEL); |
1963 | if (!req) | 1963 | if (IS_ERR(req)) |
1964 | return; | 1964 | return; |
1965 | 1965 | ||
1966 | blk_rq_set_block_pc(req); | 1966 | blk_rq_set_block_pc(req); |
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index ce62e8798cc8..972d0a8adf2e 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -221,7 +221,7 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, | |||
221 | int ret = DRIVER_ERROR << 24; | 221 | int ret = DRIVER_ERROR << 24; |
222 | 222 | ||
223 | req = blk_get_request(sdev->request_queue, write, __GFP_WAIT); | 223 | req = blk_get_request(sdev->request_queue, write, __GFP_WAIT); |
224 | if (!req) | 224 | if (IS_ERR(req)) |
225 | return ret; | 225 | return ret; |
226 | blk_rq_set_block_pc(req); | 226 | blk_rq_set_block_pc(req); |
227 | 227 | ||
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 01cf88888797..60354449d9ed 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c | |||
@@ -1711,9 +1711,9 @@ sg_start_req(Sg_request *srp, unsigned char *cmd) | |||
1711 | } | 1711 | } |
1712 | 1712 | ||
1713 | rq = blk_get_request(q, rw, GFP_ATOMIC); | 1713 | rq = blk_get_request(q, rw, GFP_ATOMIC); |
1714 | if (!rq) { | 1714 | if (IS_ERR(rq)) { |
1715 | kfree(long_cmdp); | 1715 | kfree(long_cmdp); |
1716 | return -ENOMEM; | 1716 | return PTR_ERR(rq); |
1717 | } | 1717 | } |
1718 | 1718 | ||
1719 | blk_rq_set_block_pc(rq); | 1719 | blk_rq_set_block_pc(rq); |
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index aff9689de0f7..59db5bfc11db 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c | |||
@@ -490,7 +490,7 @@ static int st_scsi_execute(struct st_request *SRpnt, const unsigned char *cmd, | |||
490 | 490 | ||
491 | req = blk_get_request(SRpnt->stp->device->request_queue, write, | 491 | req = blk_get_request(SRpnt->stp->device->request_queue, write, |
492 | GFP_KERNEL); | 492 | GFP_KERNEL); |
493 | if (!req) | 493 | if (IS_ERR(req)) |
494 | return DRIVER_ERROR << 24; | 494 | return DRIVER_ERROR << 24; |
495 | 495 | ||
496 | blk_rq_set_block_pc(req); | 496 | blk_rq_set_block_pc(req); |
diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index 943b1dbe859a..70d9f6dabba0 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c | |||
@@ -1050,7 +1050,7 @@ pscsi_execute_cmd(struct se_cmd *cmd) | |||
1050 | req = blk_get_request(pdv->pdv_sd->request_queue, | 1050 | req = blk_get_request(pdv->pdv_sd->request_queue, |
1051 | (data_direction == DMA_TO_DEVICE), | 1051 | (data_direction == DMA_TO_DEVICE), |
1052 | GFP_KERNEL); | 1052 | GFP_KERNEL); |
1053 | if (!req) { | 1053 | if (IS_ERR(req)) { |
1054 | pr_err("PSCSI: blk_get_request() failed\n"); | 1054 | pr_err("PSCSI: blk_get_request() failed\n"); |
1055 | ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; | 1055 | ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
1056 | goto fail; | 1056 | goto fail; |