diff options
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r-- | drivers/scsi/scsi_lib.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index cf5b99e1f12b..887045ae5d10 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -1120,7 +1120,8 @@ int scsi_init_io(struct scsi_cmnd *cmd) | |||
1120 | bool is_mq = (rq->mq_ctx != NULL); | 1120 | bool is_mq = (rq->mq_ctx != NULL); |
1121 | int error; | 1121 | int error; |
1122 | 1122 | ||
1123 | BUG_ON(!rq->nr_phys_segments); | 1123 | if (WARN_ON_ONCE(!rq->nr_phys_segments)) |
1124 | return -EINVAL; | ||
1124 | 1125 | ||
1125 | error = scsi_init_sgtable(rq, &cmd->sdb); | 1126 | error = scsi_init_sgtable(rq, &cmd->sdb); |
1126 | if (error) | 1127 | if (error) |
@@ -2214,6 +2215,29 @@ void scsi_mq_destroy_tags(struct Scsi_Host *shost) | |||
2214 | blk_mq_free_tag_set(&shost->tag_set); | 2215 | blk_mq_free_tag_set(&shost->tag_set); |
2215 | } | 2216 | } |
2216 | 2217 | ||
2218 | /** | ||
2219 | * scsi_device_from_queue - return sdev associated with a request_queue | ||
2220 | * @q: The request queue to return the sdev from | ||
2221 | * | ||
2222 | * Return the sdev associated with a request queue or NULL if the | ||
2223 | * request_queue does not reference a SCSI device. | ||
2224 | */ | ||
2225 | struct scsi_device *scsi_device_from_queue(struct request_queue *q) | ||
2226 | { | ||
2227 | struct scsi_device *sdev = NULL; | ||
2228 | |||
2229 | if (q->mq_ops) { | ||
2230 | if (q->mq_ops == &scsi_mq_ops) | ||
2231 | sdev = q->queuedata; | ||
2232 | } else if (q->request_fn == scsi_request_fn) | ||
2233 | sdev = q->queuedata; | ||
2234 | if (!sdev || !get_device(&sdev->sdev_gendev)) | ||
2235 | sdev = NULL; | ||
2236 | |||
2237 | return sdev; | ||
2238 | } | ||
2239 | EXPORT_SYMBOL_GPL(scsi_device_from_queue); | ||
2240 | |||
2217 | /* | 2241 | /* |
2218 | * Function: scsi_block_requests() | 2242 | * Function: scsi_block_requests() |
2219 | * | 2243 | * |