Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 274940
b: refs/heads/master
c: e99d8b0
h: refs/heads/master
v: v3
  • Loading branch information
Brian Norris authored and Artem Bityutskiy committed Sep 11, 2011
1 parent caa5477 commit ddccd01
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: beb133fc165e1289c858d8f952b982b7d0b313cd
refs/heads/master: e99d8b089a6c6fd72f022168e3bf8f22d4e5e137
56 changes: 56 additions & 0 deletions trunk/drivers/mtd/mtdchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,55 @@ static int mtd_blkpg_ioctl(struct mtd_info *mtd,
}
}

static int mtd_write_ioctl(struct mtd_info *mtd,
struct mtd_write_req __user *argp)
{
struct mtd_write_req req;
struct mtd_oob_ops ops;
void __user *usr_data, *usr_oob;
int ret;

if (copy_from_user(&req, argp, sizeof(req)) ||
!access_ok(VERIFY_READ, req.usr_data, req.len) ||
!access_ok(VERIFY_READ, req.usr_oob, req.ooblen))
return -EFAULT;
if (!mtd->write_oob)
return -EOPNOTSUPP;

ops.mode = req.mode;
ops.len = (size_t)req.len;
ops.ooblen = (size_t)req.ooblen;
ops.ooboffs = 0;

usr_data = (void __user *)(uintptr_t)req.usr_data;
usr_oob = (void __user *)(uintptr_t)req.usr_oob;

if (req.usr_data) {
ops.datbuf = memdup_user(usr_data, ops.len);
if (IS_ERR(ops.datbuf))
return PTR_ERR(ops.datbuf);
} else {
ops.datbuf = NULL;
}

if (req.usr_oob) {
ops.oobbuf = memdup_user(usr_oob, ops.ooblen);
if (IS_ERR(ops.oobbuf)) {
kfree(ops.datbuf);
return PTR_ERR(ops.oobbuf);
}
} else {
ops.oobbuf = NULL;
}

ret = mtd->write_oob(mtd, (loff_t)req.start, &ops);

kfree(ops.datbuf);
kfree(ops.oobbuf);

return ret;
}

static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
{
struct mtd_file_info *mfi = file->private_data;
Expand Down Expand Up @@ -753,6 +802,13 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
break;
}

case MEMWRITE:
{
ret = mtd_write_ioctl(mtd,
(struct mtd_write_req __user *)arg);
break;
}

case MEMLOCK:
{
struct erase_info_user einfo;
Expand Down
11 changes: 11 additions & 0 deletions trunk/include/mtd/mtd-abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ enum {
MTD_OPS_RAW = 2,
};

struct mtd_write_req {
__u64 start;
__u64 len;
__u64 ooblen;
__u64 usr_data;
__u64 usr_oob;
__u8 mode;
__u8 padding[7];
};

#define MTD_ABSENT 0
#define MTD_RAM 1
#define MTD_ROM 2
Expand Down Expand Up @@ -147,6 +157,7 @@ struct otp_info {
#define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64)
#define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64)
#define MEMISLOCKED _IOR('M', 23, struct erase_info_user)
#define MEMWRITE _IOWR('M', 24, struct mtd_write_req)

/*
* Obsolete legacy interface. Keep it in order not to break userspace
Expand Down

0 comments on commit ddccd01

Please sign in to comment.