aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2013-02-23 14:51:48 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2013-02-26 02:46:11 -0500
commit7bb307e894d51308aa0582a8c4cc5875bbc645b9 (patch)
tree8b8434fe4674fb47236c0d7ca2256e7afc29f208 /drivers/mtd
parent94e07a7590ae855bae0536c42b3086fadc7c83a8 (diff)
export kernel_write(), convert open-coded instances
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/nand/nandsim.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 818b65c85d12..8f30d385bfa3 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -1408,40 +1408,32 @@ static void clear_memalloc(int memalloc)
1408 current->flags &= ~PF_MEMALLOC; 1408 current->flags &= ~PF_MEMALLOC;
1409} 1409}
1410 1410
1411static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t *pos) 1411static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos)
1412{ 1412{
1413 mm_segment_t old_fs;
1414 ssize_t tx; 1413 ssize_t tx;
1415 int err, memalloc; 1414 int err, memalloc;
1416 1415
1417 err = get_pages(ns, file, count, *pos); 1416 err = get_pages(ns, file, count, pos);
1418 if (err) 1417 if (err)
1419 return err; 1418 return err;
1420 old_fs = get_fs();
1421 set_fs(get_ds());
1422 memalloc = set_memalloc(); 1419 memalloc = set_memalloc();
1423 tx = vfs_read(file, (char __user *)buf, count, pos); 1420 tx = kernel_read(file, pos, buf, count);
1424 clear_memalloc(memalloc); 1421 clear_memalloc(memalloc);
1425 set_fs(old_fs);
1426 put_pages(ns); 1422 put_pages(ns);
1427 return tx; 1423 return tx;
1428} 1424}
1429 1425
1430static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t *pos) 1426static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos)
1431{ 1427{
1432 mm_segment_t old_fs;
1433 ssize_t tx; 1428 ssize_t tx;
1434 int err, memalloc; 1429 int err, memalloc;
1435 1430
1436 err = get_pages(ns, file, count, *pos); 1431 err = get_pages(ns, file, count, pos);
1437 if (err) 1432 if (err)
1438 return err; 1433 return err;
1439 old_fs = get_fs();
1440 set_fs(get_ds());
1441 memalloc = set_memalloc(); 1434 memalloc = set_memalloc();
1442 tx = vfs_write(file, (char __user *)buf, count, pos); 1435 tx = kernel_write(file, buf, count, pos);
1443 clear_memalloc(memalloc); 1436 clear_memalloc(memalloc);
1444 set_fs(old_fs);
1445 put_pages(ns); 1437 put_pages(ns);
1446 return tx; 1438 return tx;
1447} 1439}
@@ -1511,7 +1503,7 @@ static void read_page(struct nandsim *ns, int num)
1511 if (do_read_error(ns, num)) 1503 if (do_read_error(ns, num))
1512 return; 1504 return;
1513 pos = (loff_t)ns->regs.row * ns->geom.pgszoob + ns->regs.column + ns->regs.off; 1505 pos = (loff_t)ns->regs.row * ns->geom.pgszoob + ns->regs.column + ns->regs.off;
1514 tx = read_file(ns, ns->cfile, ns->buf.byte, num, &pos); 1506 tx = read_file(ns, ns->cfile, ns->buf.byte, num, pos);
1515 if (tx != num) { 1507 if (tx != num) {
1516 NS_ERR("read_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx); 1508 NS_ERR("read_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx);
1517 return; 1509 return;
@@ -1573,7 +1565,7 @@ static int prog_page(struct nandsim *ns, int num)
1573 u_char *pg_off; 1565 u_char *pg_off;
1574 1566
1575 if (ns->cfile) { 1567 if (ns->cfile) {
1576 loff_t off, pos; 1568 loff_t off;
1577 ssize_t tx; 1569 ssize_t tx;
1578 int all; 1570 int all;
1579 1571
@@ -1585,8 +1577,7 @@ static int prog_page(struct nandsim *ns, int num)
1585 memset(ns->file_buf, 0xff, ns->geom.pgszoob); 1577 memset(ns->file_buf, 0xff, ns->geom.pgszoob);
1586 } else { 1578 } else {
1587 all = 0; 1579 all = 0;
1588 pos = off; 1580 tx = read_file(ns, ns->cfile, pg_off, num, off);
1589 tx = read_file(ns, ns->cfile, pg_off, num, &pos);
1590 if (tx != num) { 1581 if (tx != num) {
1591 NS_ERR("prog_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx); 1582 NS_ERR("prog_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx);
1592 return -1; 1583 return -1;
@@ -1595,16 +1586,15 @@ static int prog_page(struct nandsim *ns, int num)
1595 for (i = 0; i < num; i++) 1586 for (i = 0; i < num; i++)
1596 pg_off[i] &= ns->buf.byte[i]; 1587 pg_off[i] &= ns->buf.byte[i];
1597 if (all) { 1588 if (all) {
1598 pos = (loff_t)ns->regs.row * ns->geom.pgszoob; 1589 loff_t pos = (loff_t)ns->regs.row * ns->geom.pgszoob;
1599 tx = write_file(ns, ns->cfile, ns->file_buf, ns->geom.pgszoob, &pos); 1590 tx = write_file(ns, ns->cfile, ns->file_buf, ns->geom.pgszoob, pos);
1600 if (tx != ns->geom.pgszoob) { 1591 if (tx != ns->geom.pgszoob) {
1601 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx); 1592 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx);
1602 return -1; 1593 return -1;
1603 } 1594 }
1604 ns->pages_written[ns->regs.row] = 1; 1595 ns->pages_written[ns->regs.row] = 1;
1605 } else { 1596 } else {
1606 pos = off; 1597 tx = write_file(ns, ns->cfile, pg_off, num, off);
1607 tx = write_file(ns, ns->cfile, pg_off, num, &pos);
1608 if (tx != num) { 1598 if (tx != num) {
1609 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx); 1599 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx);
1610 return -1; 1600 return -1;