Skip to content

Commit

Permalink
mtd: nand: nandsim: convert to memalloc_noreclaim_*()
Browse files Browse the repository at this point in the history
Nandsim has own functions set_memalloc() and clear_memalloc() for robust
setting and clearing of PF_MEMALLOC.  Replace them by the new generic
helpers.  No functional change.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Vlastimil Babka <[email protected]>
Cc: Boris Brezillon <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Cc: Chris Leech <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Josef Bacik <[email protected]>
Cc: Lee Duncan <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Adrian Hunter <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
tehcaster authored and torvalds committed May 9, 2017
1 parent f108304 commit dcbe821
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions drivers/mtd/nand/nandsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <linux/list.h>
#include <linux/random.h>
#include <linux/sched.h>
#include <linux/sched/mm.h>
#include <linux/fs.h>
#include <linux/pagemap.h>
#include <linux/seq_file.h>
Expand Down Expand Up @@ -1368,46 +1369,34 @@ static int get_pages(struct nandsim *ns, struct file *file, size_t count, loff_t
return 0;
}

static int set_memalloc(void)
{
if (current->flags & PF_MEMALLOC)
return 0;
current->flags |= PF_MEMALLOC;
return 1;
}

static void clear_memalloc(int memalloc)
{
if (memalloc)
current->flags &= ~PF_MEMALLOC;
}

static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos)
{
ssize_t tx;
int err, memalloc;
int err;
unsigned int noreclaim_flag;

err = get_pages(ns, file, count, pos);
if (err)
return err;
memalloc = set_memalloc();
noreclaim_flag = memalloc_noreclaim_save();
tx = kernel_read(file, pos, buf, count);
clear_memalloc(memalloc);
memalloc_noreclaim_restore(noreclaim_flag);
put_pages(ns);
return tx;
}

static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos)
{
ssize_t tx;
int err, memalloc;
int err;
unsigned int noreclaim_flag;

err = get_pages(ns, file, count, pos);
if (err)
return err;
memalloc = set_memalloc();
noreclaim_flag = memalloc_noreclaim_save();
tx = kernel_write(file, buf, count, pos);
clear_memalloc(memalloc);
memalloc_noreclaim_restore(noreclaim_flag);
put_pages(ns);
return tx;
}
Expand Down

0 comments on commit dcbe821

Please sign in to comment.