diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/target/target_core_transport.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 7ddb0c33f644..4403477882b3 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c | |||
@@ -2190,7 +2190,6 @@ void *transport_kmap_data_sg(struct se_cmd *cmd) | |||
2190 | struct page **pages; | 2190 | struct page **pages; |
2191 | int i; | 2191 | int i; |
2192 | 2192 | ||
2193 | BUG_ON(!sg); | ||
2194 | /* | 2193 | /* |
2195 | * We need to take into account a possible offset here for fabrics like | 2194 | * We need to take into account a possible offset here for fabrics like |
2196 | * tcm_loop who may be using a contig buffer from the SCSI midlayer for | 2195 | * tcm_loop who may be using a contig buffer from the SCSI midlayer for |
@@ -2198,13 +2197,17 @@ void *transport_kmap_data_sg(struct se_cmd *cmd) | |||
2198 | */ | 2197 | */ |
2199 | if (!cmd->t_data_nents) | 2198 | if (!cmd->t_data_nents) |
2200 | return NULL; | 2199 | return NULL; |
2201 | else if (cmd->t_data_nents == 1) | 2200 | |
2201 | BUG_ON(!sg); | ||
2202 | if (cmd->t_data_nents == 1) | ||
2202 | return kmap(sg_page(sg)) + sg->offset; | 2203 | return kmap(sg_page(sg)) + sg->offset; |
2203 | 2204 | ||
2204 | /* >1 page. use vmap */ | 2205 | /* >1 page. use vmap */ |
2205 | pages = kmalloc(sizeof(*pages) * cmd->t_data_nents, GFP_KERNEL); | 2206 | pages = kmalloc(sizeof(*pages) * cmd->t_data_nents, GFP_KERNEL); |
2206 | if (!pages) | 2207 | if (!pages) { |
2208 | cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; | ||
2207 | return NULL; | 2209 | return NULL; |
2210 | } | ||
2208 | 2211 | ||
2209 | /* convert sg[] to pages[] */ | 2212 | /* convert sg[] to pages[] */ |
2210 | for_each_sg(cmd->t_data_sg, sg, cmd->t_data_nents, i) { | 2213 | for_each_sg(cmd->t_data_sg, sg, cmd->t_data_nents, i) { |
@@ -2213,8 +2216,10 @@ void *transport_kmap_data_sg(struct se_cmd *cmd) | |||
2213 | 2216 | ||
2214 | cmd->t_data_vmap = vmap(pages, cmd->t_data_nents, VM_MAP, PAGE_KERNEL); | 2217 | cmd->t_data_vmap = vmap(pages, cmd->t_data_nents, VM_MAP, PAGE_KERNEL); |
2215 | kfree(pages); | 2218 | kfree(pages); |
2216 | if (!cmd->t_data_vmap) | 2219 | if (!cmd->t_data_vmap) { |
2220 | cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; | ||
2217 | return NULL; | 2221 | return NULL; |
2222 | } | ||
2218 | 2223 | ||
2219 | return cmd->t_data_vmap + cmd->t_data_sg[0].offset; | 2224 | return cmd->t_data_vmap + cmd->t_data_sg[0].offset; |
2220 | } | 2225 | } |