From: js07.lee@gmail.com (Jungseung Lee)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: mm: Refine set_memory_* functions
Date: Mon, 20 Oct 2014 19:24:38 +0900 [thread overview]
Message-ID: <1413800678-6794-1-git-send-email-js07.lee@gmail.com> (raw)
set_memory_* functions have same implementation
without memory attribute.
This is a change to reduce code size and enhance
the readability
Signed-off-by: Jungseung Lee <js07.lee@gmail.com>
---
arch/arm/mm/mmu.c | 70 ++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 48 insertions(+), 22 deletions(-)
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index 9f98cec..34a64b3 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -364,33 +364,59 @@ static int pte_set_##_name(pte_t *ptep, pgtable_t token, unsigned long addr, \
return 0; \
} \
-#define SET_MEMORY_FN(_name, callback) \
-int set_memory_##_name(unsigned long addr, int numpages) \
-{ \
- unsigned long start = addr; \
- unsigned long size = PAGE_SIZE*numpages; \
- unsigned end = start + size; \
-\
- if (start < MODULES_VADDR || start >= MODULES_END) \
- return -EINVAL;\
-\
- if (end < MODULES_VADDR || end >= MODULES_END) \
- return -EINVAL; \
-\
- apply_to_page_range(&init_mm, start, size, callback, NULL); \
- flush_tlb_kernel_range(start, end); \
- return 0;\
-}
-
PTE_SET_FN(ro, pte_wrprotect)
PTE_SET_FN(rw, pte_mkwrite)
PTE_SET_FN(x, pte_mkexec)
PTE_SET_FN(nx, pte_mknexec)
-SET_MEMORY_FN(ro, pte_set_ro)
-SET_MEMORY_FN(rw, pte_set_rw)
-SET_MEMORY_FN(x, pte_set_x)
-SET_MEMORY_FN(nx, pte_set_nx)
+static int set_memory_attr(unsigned long addr, pte_fn_t fn, int numpages)
+{
+ unsigned long start = addr;
+ unsigned long size = PAGE_SIZE*numpages;
+ unsigned end = start + size;
+
+ if (start < MODULES_VADDR || start >= MODULES_END)
+ return -EINVAL;
+
+ if (end < MODULES_VADDR || end >= MODULES_END)
+ return -EINVAL;
+
+ apply_to_page_range(&init_mm, start, size, fn, NULL);
+ flush_tlb_kernel_range(start, end);
+ return 0;
+}
+
+int set_memory_ro(unsigned long addr, int numpages)
+{
+ int ret;
+
+ ret = set_memory_attr(addr, pte_set_ro, numpages);
+ return ret;
+}
+
+int set_memory_rw(unsigned long addr, int numpages)
+{
+ int ret;
+
+ ret = set_memory_attr(addr, pte_set_rw, numpages);
+ return ret;
+}
+
+int set_memory_x(unsigned long addr, int numpages)
+{
+ int ret;
+
+ ret = set_memory_attr(addr, pte_set_x, numpages);
+ return ret;
+}
+
+int set_memory_nx(unsigned long addr, int numpages)
+{
+ int ret;
+
+ ret = set_memory_attr(addr, pte_set_nx, numpages);
+ return ret;
+}
/*
* Adjust the PMD section entries according to the CPU in use.
--
1.9.1
next reply other threads:[~2014-10-20 10:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-20 10:24 Jungseung Lee [this message]
2014-10-20 12:30 ` [PATCH] ARM: mm: Refine set_memory_* functions Laura Abbott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1413800678-6794-1-git-send-email-js07.lee@gmail.com \
--to=js07.lee@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.