diff options
Diffstat (limited to 'drivers/scsi/scsi_ioctl.c')
-rw-r--r-- | drivers/scsi/scsi_ioctl.c | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c index 946c31fa6466..b7fddac81347 100644 --- a/drivers/scsi/scsi_ioctl.c +++ b/drivers/scsi/scsi_ioctl.c | |||
@@ -88,25 +88,18 @@ static int ioctl_probe(struct Scsi_Host *host, void __user *buffer) | |||
88 | static int ioctl_internal_command(struct scsi_device *sdev, char *cmd, | 88 | static int ioctl_internal_command(struct scsi_device *sdev, char *cmd, |
89 | int timeout, int retries) | 89 | int timeout, int retries) |
90 | { | 90 | { |
91 | struct scsi_request *sreq; | ||
92 | int result; | 91 | int result; |
93 | struct scsi_sense_hdr sshdr; | 92 | struct scsi_sense_hdr sshdr; |
94 | 93 | ||
95 | SCSI_LOG_IOCTL(1, printk("Trying ioctl with scsi command %d\n", *cmd)); | 94 | SCSI_LOG_IOCTL(1, printk("Trying ioctl with scsi command %d\n", *cmd)); |
96 | 95 | ||
97 | sreq = scsi_allocate_request(sdev, GFP_KERNEL); | 96 | result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, |
98 | if (!sreq) { | 97 | &sshdr, timeout, retries); |
99 | printk(KERN_WARNING "SCSI internal ioctl failed, no memory\n"); | ||
100 | return -ENOMEM; | ||
101 | } | ||
102 | |||
103 | sreq->sr_data_direction = DMA_NONE; | ||
104 | scsi_wait_req(sreq, cmd, NULL, 0, timeout, retries); | ||
105 | 98 | ||
106 | SCSI_LOG_IOCTL(2, printk("Ioctl returned 0x%x\n", sreq->sr_result)); | 99 | SCSI_LOG_IOCTL(2, printk("Ioctl returned 0x%x\n", result)); |
107 | 100 | ||
108 | if ((driver_byte(sreq->sr_result) & DRIVER_SENSE) && | 101 | if ((driver_byte(result) & DRIVER_SENSE) && |
109 | (scsi_request_normalize_sense(sreq, &sshdr))) { | 102 | (scsi_sense_valid(&sshdr))) { |
110 | switch (sshdr.sense_key) { | 103 | switch (sshdr.sense_key) { |
111 | case ILLEGAL_REQUEST: | 104 | case ILLEGAL_REQUEST: |
112 | if (cmd[0] == ALLOW_MEDIUM_REMOVAL) | 105 | if (cmd[0] == ALLOW_MEDIUM_REMOVAL) |
@@ -125,7 +118,7 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd, | |||
125 | case UNIT_ATTENTION: | 118 | case UNIT_ATTENTION: |
126 | if (sdev->removable) { | 119 | if (sdev->removable) { |
127 | sdev->changed = 1; | 120 | sdev->changed = 1; |
128 | sreq->sr_result = 0; /* This is no longer considered an error */ | 121 | result = 0; /* This is no longer considered an error */ |
129 | break; | 122 | break; |
130 | } | 123 | } |
131 | default: /* Fall through for non-removable media */ | 124 | default: /* Fall through for non-removable media */ |
@@ -135,15 +128,13 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd, | |||
135 | sdev->channel, | 128 | sdev->channel, |
136 | sdev->id, | 129 | sdev->id, |
137 | sdev->lun, | 130 | sdev->lun, |
138 | sreq->sr_result); | 131 | result); |
139 | scsi_print_req_sense(" ", sreq); | 132 | scsi_print_sense_hdr(" ", &sshdr); |
140 | break; | 133 | break; |
141 | } | 134 | } |
142 | } | 135 | } |
143 | 136 | ||
144 | result = sreq->sr_result; | ||
145 | SCSI_LOG_IOCTL(2, printk("IOCTL Releasing command\n")); | 137 | SCSI_LOG_IOCTL(2, printk("IOCTL Releasing command\n")); |
146 | scsi_release_request(sreq); | ||
147 | return result; | 138 | return result; |
148 | } | 139 | } |
149 | 140 | ||
@@ -208,8 +199,8 @@ int scsi_ioctl_send_command(struct scsi_device *sdev, | |||
208 | { | 199 | { |
209 | char *buf; | 200 | char *buf; |
210 | unsigned char cmd[MAX_COMMAND_SIZE]; | 201 | unsigned char cmd[MAX_COMMAND_SIZE]; |
202 | unsigned char sense[SCSI_SENSE_BUFFERSIZE]; | ||
211 | char __user *cmd_in; | 203 | char __user *cmd_in; |
212 | struct scsi_request *sreq; | ||
213 | unsigned char opcode; | 204 | unsigned char opcode; |
214 | unsigned int inlen, outlen, cmdlen; | 205 | unsigned int inlen, outlen, cmdlen; |
215 | unsigned int needed, buf_needed; | 206 | unsigned int needed, buf_needed; |
@@ -321,31 +312,23 @@ int scsi_ioctl_send_command(struct scsi_device *sdev, | |||
321 | break; | 312 | break; |
322 | } | 313 | } |
323 | 314 | ||
324 | sreq = scsi_allocate_request(sdev, GFP_KERNEL); | 315 | result = scsi_execute(sdev, cmd, data_direction, buf, needed, |
325 | if (!sreq) { | 316 | sense, timeout, retries, 0); |
326 | result = -EINTR; | ||
327 | goto error; | ||
328 | } | ||
329 | |||
330 | sreq->sr_data_direction = data_direction; | ||
331 | scsi_wait_req(sreq, cmd, buf, needed, timeout, retries); | ||
332 | 317 | ||
333 | /* | 318 | /* |
334 | * If there was an error condition, pass the info back to the user. | 319 | * If there was an error condition, pass the info back to the user. |
335 | */ | 320 | */ |
336 | result = sreq->sr_result; | ||
337 | if (result) { | 321 | if (result) { |
338 | int sb_len = sizeof(sreq->sr_sense_buffer); | 322 | int sb_len = sizeof(*sense); |
339 | 323 | ||
340 | sb_len = (sb_len > OMAX_SB_LEN) ? OMAX_SB_LEN : sb_len; | 324 | sb_len = (sb_len > OMAX_SB_LEN) ? OMAX_SB_LEN : sb_len; |
341 | if (copy_to_user(cmd_in, sreq->sr_sense_buffer, sb_len)) | 325 | if (copy_to_user(cmd_in, sense, sb_len)) |
342 | result = -EFAULT; | 326 | result = -EFAULT; |
343 | } else { | 327 | } else { |
344 | if (copy_to_user(cmd_in, buf, outlen)) | 328 | if (copy_to_user(cmd_in, buf, outlen)) |
345 | result = -EFAULT; | 329 | result = -EFAULT; |
346 | } | 330 | } |
347 | 331 | ||
348 | scsi_release_request(sreq); | ||
349 | error: | 332 | error: |
350 | kfree(buf); | 333 | kfree(buf); |
351 | return result; | 334 | return result; |