[SCSI] SCSI core kmalloc2kzalloc
[safe/jmp/linux-2.6] / drivers / scsi / scsi_ioctl.c
index 5f399c9..36e9300 100644 (file)
 
 #define MAX_BUF PAGE_SIZE
 
-/*
- * If we are told to probe a host, we will return 0 if  the host is not
- * present, 1 if the host is present, and will return an identifying
- * string at *arg, if arg is non null, filling to the length stored at
- * (int *) arg
+/**
+ * ioctl_probe  --  return host identification
+ * @host:      host to identify
+ * @buffer:    userspace buffer for identification
+ *
+ * Return an identifying string at @buffer, if @buffer is non-NULL, filling
+ * to the length stored at * (int *) @buffer.
  */
-
 static int ioctl_probe(struct Scsi_Host *host, void __user *buffer)
 {
        unsigned int len, slen;
        const char *string;
-       int temp = host->hostt->present;
 
-       if (temp && buffer) {
+       if (buffer) {
                if (get_user(len, (unsigned int __user *) buffer))
                        return -EFAULT;
 
@@ -59,7 +59,7 @@ static int ioctl_probe(struct Scsi_Host *host, void __user *buffer)
                                return -EFAULT;
                }
        }
-       return temp;
+       return 1;
 }
 
 /*
@@ -90,19 +90,16 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
 {
        int result;
        struct scsi_sense_hdr sshdr;
-       char sense[SCSI_SENSE_BUFFERSIZE];
 
        SCSI_LOG_IOCTL(1, printk("Trying ioctl with scsi command %d\n", *cmd));
 
-
-       memset(sense, 0, sizeof(*sense));
        result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0,
-                                 sense, timeout, retries);
+                                 &sshdr, timeout, retries);
 
        SCSI_LOG_IOCTL(2, printk("Ioctl returned  0x%x\n", result));
 
        if ((driver_byte(result) & DRIVER_SENSE) &&
-           (scsi_normalize_sense(sense, sizeof(*sense), &sshdr))) {
+           (scsi_sense_valid(&sshdr))) {
                switch (sshdr.sense_key) {
                case ILLEGAL_REQUEST:
                        if (cmd[0] == ALLOW_MEDIUM_REMOVAL)
@@ -125,14 +122,10 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
                                break;
                        }
                default:        /* Fall through for non-removable media */
-                       printk(KERN_INFO "ioctl_internal_command: <%d %d %d "
-                              "%d> return code = %x\n",
-                              sdev->host->host_no,
-                              sdev->channel,
-                              sdev->id,
-                              sdev->lun,
-                              result);
-                       __scsi_print_sense("   ", sense, sizeof(*sense));
+                       sdev_printk(KERN_INFO, sdev,
+                                   "ioctl_internal_command return code = %x\n",
+                                   result);
+                       scsi_print_sense_hdr("   ", &sshdr);
                        break;
                }
        }
@@ -208,7 +201,8 @@ int scsi_ioctl_send_command(struct scsi_device *sdev,
        unsigned int inlen, outlen, cmdlen;
        unsigned int needed, buf_needed;
        int timeout, retries, result;
-       int data_direction, gfp_mask = GFP_KERNEL;
+       int data_direction;
+       gfp_t gfp_mask = GFP_KERNEL;
 
        if (!sic)
                return -EINVAL;
@@ -247,10 +241,9 @@ int scsi_ioctl_send_command(struct scsi_device *sdev,
                buf_needed = (buf_needed + 511) & ~511;
                if (buf_needed > MAX_BUF)
                        buf_needed = MAX_BUF;
-               buf = kmalloc(buf_needed, gfp_mask);
+               buf = kzalloc(buf_needed, gfp_mask);
                if (!buf)
                        return -ENOMEM;
-               memset(buf, 0, buf_needed);
                if (inlen == 0) {
                        data_direction = DMA_FROM_DEVICE;
                } else if (outlen == 0 ) {
@@ -284,7 +277,7 @@ int scsi_ioctl_send_command(struct scsi_device *sdev,
         * Obtain the data to be sent to the device (if any).
         */
 
-       if(copy_from_user(buf, cmd_in + cmdlen, inlen))
+       if(inlen && copy_from_user(buf, cmd_in + cmdlen, inlen))
                goto error;
 
        switch (opcode) {
@@ -315,9 +308,9 @@ int scsi_ioctl_send_command(struct scsi_device *sdev,
                break;
        }
 
-       result = scsi_execute_req(sdev, cmd, data_direction, buf, needed,
-                                 sense, timeout, retries);
-                                 
+       result = scsi_execute(sdev, cmd, data_direction, buf, needed,
+                             sense, timeout, retries, 0);
+
        /* 
         * If there was an error condition, pass the info back to the user. 
         */
@@ -328,7 +321,7 @@ int scsi_ioctl_send_command(struct scsi_device *sdev,
                if (copy_to_user(cmd_in, sense, sb_len))
                        result = -EFAULT;
        } else {
-               if (copy_to_user(cmd_in, buf, outlen))
+               if (outlen && copy_to_user(cmd_in, buf, outlen))
                        result = -EFAULT;
        }       
 
@@ -461,7 +454,7 @@ int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd,
         * error processing, as long as the device was opened
         * non-blocking */
        if (filp && filp->f_flags & O_NONBLOCK) {
-               if (sdev->host->shost_state == SHOST_RECOVERY)
+               if (scsi_host_in_recovery(sdev->host))
                        return -ENODEV;
        } else if (!scsi_block_when_processing_errors(sdev))
                return -ENODEV;