Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 349466
b: refs/heads/master
c: cab9609
h: refs/heads/master
v: v3
  • Loading branch information
Nicholas Bellinger committed Jan 29, 2013
1 parent be64392 commit 3e0b06f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 49df9fc9b9fd41e5749c5a9be2d2076328f75fc7
refs/heads/master: cab9609b449ae5a6875d7d4cef32a814527a3baa
35 changes: 7 additions & 28 deletions trunk/drivers/target/target_core_spc.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
{
struct se_device *dev = cmd->se_dev;
char *cdb = cmd->t_task_cdb;
unsigned char *buf, *map_buf;
unsigned char buf[SE_MODE_PAGE_BUF], *rbuf;
int type = dev->transport->get_device_type(dev);
int ten = (cmd->t_task_cdb[0] == MODE_SENSE_10);
bool dbd = !!(cdb[1] & 0x08);
Expand All @@ -862,26 +862,8 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
int ret;
int i;

map_buf = transport_kmap_data_sg(cmd);
if (!map_buf)
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
/*
* If SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC is not set, then we
* know we actually allocated a full page. Otherwise, if the
* data buffer is too small, allocate a temporary buffer so we
* don't have to worry about overruns in all our INQUIRY
* emulation handling.
*/
if (cmd->data_length < SE_MODE_PAGE_BUF &&
(cmd->se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC)) {
buf = kzalloc(SE_MODE_PAGE_BUF, GFP_KERNEL);
if (!buf) {
transport_kunmap_data_sg(cmd);
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
}
} else {
buf = map_buf;
}
memset(buf, 0, SE_MODE_PAGE_BUF);

/*
* Skip over MODE DATA LENGTH + MEDIUM TYPE fields to byte 3 for
* MODE_SENSE_10 and byte 2 for MODE_SENSE (6).
Expand Down Expand Up @@ -933,8 +915,6 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
if (page == 0x3f) {
if (subpage != 0x00 && subpage != 0xff) {
pr_warn("MODE_SENSE: Invalid subpage code: 0x%02x\n", subpage);
kfree(buf);
transport_kunmap_data_sg(cmd);
return TCM_INVALID_CDB_FIELD;
}

Expand Down Expand Up @@ -971,7 +951,6 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
pr_err("MODE SENSE: unimplemented page/subpage: 0x%02x/0x%02x\n",
page, subpage);

transport_kunmap_data_sg(cmd);
return TCM_UNKNOWN_MODE_PAGE;

set_length:
Expand All @@ -980,12 +959,12 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
else
buf[0] = length - 1;

if (buf != map_buf) {
memcpy(map_buf, buf, cmd->data_length);
kfree(buf);
rbuf = transport_kmap_data_sg(cmd);
if (rbuf) {
memcpy(rbuf, buf, min_t(u32, SE_MODE_PAGE_BUF, cmd->data_length));
transport_kunmap_data_sg(cmd);
}

transport_kunmap_data_sg(cmd);
target_complete_cmd(cmd, GOOD);
return 0;
}
Expand Down

0 comments on commit 3e0b06f

Please sign in to comment.