Commit fa2f478a authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Greentime Hu

nds32: use get_kernel_nofault in dump_mem

Use the proper get_kernel_nofault helper to access an unsafe kernel
pointer without faulting instead of playing with set_fs and get_user.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarNick Hu <nickhu@andestech.com>
Acked-by: default avatarGreentime Hu <green.hu@gmail.com>
Signed-off-by: default avatarGreentime Hu <green.hu@gmail.com>
parent 9d63fecf
...@@ -25,17 +25,8 @@ extern void show_pte(struct mm_struct *mm, unsigned long addr); ...@@ -25,17 +25,8 @@ extern void show_pte(struct mm_struct *mm, unsigned long addr);
void dump_mem(const char *lvl, unsigned long bottom, unsigned long top) void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
{ {
unsigned long first; unsigned long first;
mm_segment_t fs;
int i; int i;
/*
* We need to switch to kernel mode so that we can use __get_user
* to safely read from kernel space. Note that we now dump the
* code first, just in case the backtrace kills us.
*/
fs = get_fs();
set_fs(KERNEL_DS);
pr_emerg("%s(0x%08lx to 0x%08lx)\n", lvl, bottom, top); pr_emerg("%s(0x%08lx to 0x%08lx)\n", lvl, bottom, top);
for (first = bottom & ~31; first < top; first += 32) { for (first = bottom & ~31; first < top; first += 32) {
...@@ -48,7 +39,9 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top) ...@@ -48,7 +39,9 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
for (p = first, i = 0; i < 8 && p < top; i++, p += 4) { for (p = first, i = 0; i < 8 && p < top; i++, p += 4) {
if (p >= bottom && p < top) { if (p >= bottom && p < top) {
unsigned long val; unsigned long val;
if (__get_user(val, (unsigned long *)p) == 0)
if (get_kernel_nofault(val,
(unsigned long *)p) == 0)
sprintf(str + i * 9, " %08lx", val); sprintf(str + i * 9, " %08lx", val);
else else
sprintf(str + i * 9, " ????????"); sprintf(str + i * 9, " ????????");
...@@ -56,8 +49,6 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top) ...@@ -56,8 +49,6 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
} }
pr_emerg("%s%04lx:%s\n", lvl, first & 0xffff, str); pr_emerg("%s%04lx:%s\n", lvl, first & 0xffff, str);
} }
set_fs(fs);
} }
EXPORT_SYMBOL(dump_mem); EXPORT_SYMBOL(dump_mem);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment