Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 17192
b: refs/heads/master
c: f9ce299
h: refs/heads/master
v: v3
  • Loading branch information
Arnd Bergmann authored and Paul Mackerras committed Jan 9, 2006
1 parent c5d3369 commit 0098ba1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 57 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: d52771fce4e774fa786097d34412a057d487c697
refs/heads/master: f9ce299fc629d5c899a2e56b00e21f5da05cf590
106 changes: 50 additions & 56 deletions trunk/arch/powerpc/kernel/nvram_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0098ba1

Please sign in to comment.