Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 27734
b: refs/heads/master
c: b802c07
h: refs/heads/master
v: v3
  • Loading branch information
Thago Galesi authored and David Woodhouse committed Apr 17, 2006
1 parent 45eb6be commit 747bfd0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 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: cd2866faaa0efd9af18fe4a86d129cbd99240796
refs/heads/master: b802c0741103aa92251d536c115874d51f802ec8
34 changes: 21 additions & 13 deletions trunk/drivers/mtd/mtdchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,22 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t

/* FIXME: Use kiovec in 2.5 to lock down the user's buffers
and pass them directly to the MTD functions */

if (count > MAX_KMALLOC_SIZE)
kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL);
else
kbuf=kmalloc(count, GFP_KERNEL);

if (!kbuf)
return -ENOMEM;

while (count) {

if (count > MAX_KMALLOC_SIZE)
len = MAX_KMALLOC_SIZE;
else
len = count;

kbuf=kmalloc(len,GFP_KERNEL);
if (!kbuf)
return -ENOMEM;

switch (MTD_MODE(file)) {
case MTD_MODE_OTP_FACT:
ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf);
Expand Down Expand Up @@ -215,9 +221,9 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
return ret;
}

kfree(kbuf);
}

kfree(kbuf);
return total_retlen;
} /* mtd_read */

Expand All @@ -241,18 +247,21 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
if (!count)
return 0;

if (count > MAX_KMALLOC_SIZE)
kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL);
else
kbuf=kmalloc(count, GFP_KERNEL);

if (!kbuf)
return -ENOMEM;

while (count) {

if (count > MAX_KMALLOC_SIZE)
len = MAX_KMALLOC_SIZE;
else
len = count;

kbuf=kmalloc(len,GFP_KERNEL);
if (!kbuf) {
printk("kmalloc is null\n");
return -ENOMEM;
}

if (copy_from_user(kbuf, buf, len)) {
kfree(kbuf);
return -EFAULT;
Expand Down Expand Up @@ -282,10 +291,9 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
kfree(kbuf);
return ret;
}

kfree(kbuf);
}

kfree(kbuf);
return total_retlen;
} /* mtd_write */

Expand Down

0 comments on commit 747bfd0

Please sign in to comment.