Merge master.kernel.org:/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[powerpc.git] / arch / powerpc / kernel / nvram_64.c
index c0fcd29..6960f09 100644 (file)
@@ -80,80 +80,74 @@ static loff_t dev_nvram_llseek(struct file *file, loff_t offset, int origin)
 static ssize_t dev_nvram_read(struct file *file, char __user *buf,
                          size_t count, loff_t *ppos)
 {
-       ssize_t len;
-       char *tmp_buffer;
-       int size;
+       ssize_t ret;
+       char *tmp = NULL;
+       ssize_t size;
 
-       if (ppc_md.nvram_size == NULL)
-               return -ENODEV;
+       ret = -ENODEV;
+       if (!ppc_md.nvram_size)
+               goto out;
+
+       ret = 0;
        size = ppc_md.nvram_size();
+       if (*ppos >= size || size < 0)
+               goto out;
 
-       if (!access_ok(VERIFY_WRITE, buf, count))
-               return -EFAULT;
-       if (*ppos >= size)
-               return 0;
-       if (count > size) 
-               count = size;
+       count = min_t(size_t, count, size - *ppos);
+       count = min(count, PAGE_SIZE);
 
-       tmp_buffer = (char *) kmalloc(count, GFP_KERNEL);
-       if (!tmp_buffer) {
-               printk(KERN_ERR "dev_read_nvram: kmalloc failed\n");
-               return -ENOMEM;
-       }
+       ret = -ENOMEM;
+       tmp = kmalloc(count, GFP_KERNEL);
+       if (!tmp)
+               goto out;
 
-       len = ppc_md.nvram_read(tmp_buffer, count, ppos);
-       if ((long)len <= 0) {
-               kfree(tmp_buffer);
-               return len;
-       }
+       ret = ppc_md.nvram_read(tmp, count, ppos);
+       if (ret <= 0)
+               goto out;
 
-       if (copy_to_user(buf, tmp_buffer, len)) {
-               kfree(tmp_buffer);
-               return -EFAULT;
-       }
+       if (copy_to_user(buf, tmp, ret))
+               ret = -EFAULT;
 
-       kfree(tmp_buffer);
-       return len;
+out:
+       kfree(tmp);
+       return ret;
 
 }
 
 static ssize_t dev_nvram_write(struct file *file, const char __user *buf,
-                          size_t count, loff_t *ppos)
+                         size_t count, loff_t *ppos)
 {
-       ssize_t len;
-       char * tmp_buffer;
-       int size;
+       ssize_t ret;
+       char *tmp = NULL;
+       ssize_t size;
 
-       if (ppc_md.nvram_size == NULL)
-               return -ENODEV;
+       ret = -ENODEV;
+       if (!ppc_md.nvram_size)
+               goto out;
+
+       ret = 0;
        size = ppc_md.nvram_size();
+       if (*ppos >= size || size < 0)
+               goto out;
 
-       if (!access_ok(VERIFY_READ, buf, count))
-               return -EFAULT;
-       if (*ppos >= size)
-               return 0;
-       if (count > size)
-               count = size;
+       count = min_t(size_t, count, size - *ppos);
+       count = min(count, PAGE_SIZE);
 
-       tmp_buffer = (char *) kmalloc(count, GFP_KERNEL);
-       if (!tmp_buffer) {
-               printk(KERN_ERR "dev_nvram_write: kmalloc failed\n");
-               return -ENOMEM;
-       }
-       
-       if (copy_from_user(tmp_buffer, buf, count)) {
-               kfree(tmp_buffer);
-               return -EFAULT;
-       }
+       ret = -ENOMEM;
+       tmp = kmalloc(count, GFP_KERNEL);
+       if (!tmp)
+               goto out;
 
-       len = ppc_md.nvram_write(tmp_buffer, count, ppos);
-       if ((long)len <= 0) {
-               kfree(tmp_buffer);
-               return len;
-       }
+       ret = -EFAULT;
+       if (copy_from_user(tmp, buf, count))
+               goto out;
+
+       ret = ppc_md.nvram_write(tmp, count, ppos);
+
+out:
+       kfree(tmp);
+       return ret;
 
-       kfree(tmp_buffer);
-       return len;
 }
 
 static int dev_nvram_ioctl(struct inode *inode, struct file *file,
@@ -166,7 +160,7 @@ static int dev_nvram_ioctl(struct inode *inode, struct file *file,
        case IOC_NVRAM_GET_OFFSET: {
                int part, offset;
 
-               if (_machine != PLATFORM_POWERMAC)
+               if (!machine_is(powermac))
                        return -EINVAL;
                if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
                        return -EFAULT;
@@ -180,8 +174,9 @@ static int dev_nvram_ioctl(struct inode *inode, struct file *file,
                return 0;
        }
 #endif /* CONFIG_PPC_PMAC */
+       default:
+               return -EINVAL;
        }
-       return -EINVAL;
 }
 
 struct file_operations nvram_fops = {
@@ -209,7 +204,7 @@ static void nvram_print_partitions(char * label)
        printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
        list_for_each(p, &nvram_part->partition) {
                tmp_part = list_entry(p, struct nvram_partition, partition);
-               printk(KERN_WARNING "%d    \t%02x\t%02x\t%d\t%s\n",
+               printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%s\n",
                       tmp_part->index, tmp_part->header.signature,
                       tmp_part->header.checksum, tmp_part->header.length,
                       tmp_part->header.name);
@@ -449,7 +444,7 @@ static int nvram_setup_partition(void)
         * in our nvram, as Apple defined partitions use pretty much
         * all of the space
         */
-       if (_machine == PLATFORM_POWERMAC)
+       if (machine_is(powermac))
                return -ENOSPC;
 
        /* see if we have an OS partition that meets our needs.