Re: [PATCH 0/6] score cleanups
From: liqin . chen
Date: Mon Jun 29 2009 - 07:25:00 EST
Arnd Bergmann <arnd@xxxxxxxx> 写于 2009-06-27 22:08:12:
> Hi Liqin,
>
> I've gone over your code a bit with sparse and some clues,
> cleaning up some areas that stuck out.
>
> Please check that these make sense.
Hi Arnd,
Code updating had finished and verified.
Best Regards
Liqin
---
From 05e9377257fcb80de597409989ef2cb715e3827c Mon Sep 17 00:00:00 2001
From: Chen Liqin <liqin.chen@xxxxxxxxxxxxx>
Date: Mon, 29 Jun 2009 19:01:44 +0800
Subject: [PATCH] score: code cleanups
score: add missing #includes
score: add address space annotations
score: fix function prototypes
score: cleanups: dead code, 0 as pointer, shadowed variables
score: make irq.h definitions local
modified: arch/score/include/asm/irq.h
modified: arch/score/include/asm/uaccess.h
new file: arch/score/include/asm/ucontext.h
modified: arch/score/kernel/irq.c
modified: arch/score/kernel/module.c
modified: arch/score/kernel/process.c
modified: arch/score/kernel/ptrace.c
modified: arch/score/kernel/signal.c
modified: arch/score/kernel/sys_score.c
modified: arch/score/kernel/time.c
modified: arch/score/mm/init.c
Signed-off-by: Chen Liqin <liqin.chen@xxxxxxxxxxxxx>
Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
---
arch/score/include/asm/irq.h | 19 +++++++++--------
arch/score/include/asm/uaccess.h | 8 +++---
arch/score/include/asm/ucontext.h | 6 +++++
arch/score/kernel/irq.c | 20 +++++++++---------
arch/score/kernel/module.c | 13 ++++++-----
arch/score/kernel/process.c | 3 ++
arch/score/kernel/ptrace.c | 7 +++--
arch/score/kernel/signal.c | 39
++++++++++++++++++++----------------
arch/score/kernel/sys_score.c | 26 ++++++++----------------
arch/score/kernel/time.c | 2 +-
arch/score/mm/init.c | 35 ++++++++++----------------------
11 files changed, 87 insertions(+), 91 deletions(-)
create mode 100644 arch/score/include/asm/ucontext.h
diff --git a/arch/score/include/asm/irq.h b/arch/score/include/asm/irq.h
index 401f670..806aaf2 100644
--- a/arch/score/include/asm/irq.h
+++ b/arch/score/include/asm/irq.h
@@ -18,15 +18,16 @@
#define irq_canonicalize(irq) (irq)
-#define P_INT_PNDL 0x95F50000
-#define P_INT_PNDH 0x95F50004
-#define P_INT_PRIORITY_M 0x95F50008
-#define P_INT_PRIORITY_SG0 0x95F50010
-#define P_INT_PRIORITY_SG1 0x95F50014
-#define P_INT_PRIORITY_SG2 0x95F50018
-#define P_INT_PRIORITY_SG3 0x95F5001C
-#define P_INT_MASKL 0x95F50020
-#define P_INT_MASKH 0x95F50024
+#define INTC_BASE ((u32 __iomem __force *)0x95f50000)
+#define INT_PNDL 0 /* 0x9f5c0000 */
+#define INT_PNDH 1 /* 0x9f5c0004 */
+#define INT_PRIORITY_M 2 /* 0x9f5c0008 */
+#define INT_PRIORITY_SG0 4 /* 0x9f5c0010 */
+#define INT_PRIORITY_SG1 5 /* 0x9f5c0014 */
+#define INT_PRIORITY_SG2 6 /* 0x9f5c0018 */
+#define INT_PRIORITY_SG3 7 /* 0x9f5c001C */
+#define INT_MASKL 8 /* 0x9f5c0020 */
+#define INT_MASKH 9 /* 0x9f5c0024 */
#define IRQ_TIMER (7) /* Timer IRQ number of SPCT6600 */
diff --git a/arch/score/include/asm/uaccess.h
b/arch/score/include/asm/uaccess.h
index 43ce28a..98fdb6f 100644
--- a/arch/score/include/asm/uaccess.h
+++ b/arch/score/include/asm/uaccess.h
@@ -13,12 +13,12 @@ extern int fixup_exception(struct pt_regs *regs);
#ifndef __ASSEMBLY__
#define __range_ok(addr, size) \
- ((((unsigned long)(addr) >= 0x80000000) \
+ ((((unsigned long __force)(addr) >= 0x80000000) \
|| ((unsigned long)(size) > 0x80000000) \
- || (((unsigned long)(addr) + (unsigned long)(size)) >
0x80000000)))
+ || (((unsigned long __force)(addr) + (unsigned long)(size)) \
+ > 0x80000000)))
-#define __access_ok(addr, size) \
- (__range_ok((addr), (size)) == 0)
+#define __access_ok(addr, size) (__range_ok((addr),
(size)) == 0)
#include <asm-generic/uaccess.h>
diff --git a/arch/score/include/asm/ucontext.h
b/arch/score/include/asm/ucontext.h
new file mode 100644
index 0000000..9c5fe5b
--- /dev/null
+++ b/arch/score/include/asm/ucontext.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_UCONTEXT_H
+#define _ASM_SCORE_UCONTEXT_H
+
+#include <asm-generic/ucontext.h>
+
+#endif /* _ASM_SCORE_UCONTEXT_H */
diff --git a/arch/score/kernel/irq.c b/arch/score/kernel/irq.c
index 55474e8..3a7f155 100644
--- a/arch/score/kernel/irq.c
+++ b/arch/score/kernel/irq.c
@@ -44,11 +44,11 @@ static void score_mask(unsigned int irq_nr)
unsigned int irq_source = 63 - irq_nr;
if (irq_source < 32)
- __raw_writel((__raw_readl((void *)P_INT_MASKL) | \
- (1 << irq_source)), (void *)P_INT_MASKL);
+ __raw_writel((__raw_readl(INTC_BASE + INT_MASKL) | \
+ (1 << irq_source)), INTC_BASE + INT_MASKL);
else
- __raw_writel((__raw_readl((void *)P_INT_MASKH) | \
- (1 << (irq_source - 32))), (void *)P_INT_MASKH);
+ __raw_writel((__raw_readl(INTC_BASE + INT_MASKH) | \
+ (1 << (irq_source - 32))), INTC_BASE + INT_MASKH);
}
static void score_unmask(unsigned int irq_nr)
@@ -56,11 +56,11 @@ static void score_unmask(unsigned int irq_nr)
unsigned int irq_source = 63 - irq_nr;
if (irq_source < 32)
- __raw_writel((__raw_readl((void *)P_INT_MASKL) & \
- ~(1 << irq_source)), (void *)P_INT_MASKL);
+ __raw_writel((__raw_readl(INTC_BASE + INT_MASKL) & \
+ ~(1 << irq_source)), INTC_BASE + INT_MASKL);
else
- __raw_writel((__raw_readl((void *)P_INT_MASKH) & \
- ~(1 << (irq_source - 32))), (void *)P_INT_MASKH);
+ __raw_writel((__raw_readl(INTC_BASE + INT_MASKH) & \
+ ~(1 << (irq_source - 32))), INTC_BASE +
INT_MASKH);
}
struct irq_chip score_irq_chip = {
@@ -88,8 +88,8 @@ void __init init_IRQ(void)
memcpy((void *)target_addr, \
interrupt_exception_vector, IRQ_VECTOR_SIZE);
- __raw_writel(0xffffffff, (void *)P_INT_MASKL);
- __raw_writel(0xffffffff, (void *)P_INT_MASKH);
+ __raw_writel(0xffffffff, INTC_BASE + INT_MASKL);
+ __raw_writel(0xffffffff, INTC_BASE + INT_MASKH);
__asm__ __volatile__(
"mtcr %0, cr3\n\t"
diff --git a/arch/score/kernel/module.c b/arch/score/kernel/module.c
index 4ffce7f..4de8d47 100644
--- a/arch/score/kernel/module.c
+++ b/arch/score/kernel/module.c
@@ -23,6 +23,7 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <linux/moduleloader.h>
#include <linux/module.h>
#include <linux/vmalloc.h>
@@ -56,17 +57,17 @@ int apply_relocate(Elf_Shdr *sechdrs, const char
*strtab,
for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++, rel++) {
unsigned long loc;
Elf32_Sym *sym;
- s32 offset;
+ s32 r_offset;
- offset = ELF32_R_SYM(rel->r_info);
- if ((offset < 0) ||
- (offset > (symsec->sh_size / sizeof(Elf32_Sym)))) {
+ r_offset = ELF32_R_SYM(rel->r_info);
+ if ((r_offset < 0) ||
+ (r_offset > (symsec->sh_size / sizeof(Elf32_Sym)))) {
printk(KERN_ERR "%s: bad relocation, section %d
reloc %d\n",
me->name, relindex, i);
return -ENOEXEC;
}
- sym = ((Elf32_Sym *)symsec->sh_addr) + offset;
+ sym = ((Elf32_Sym *)symsec->sh_addr) + r_offset;
if ((rel->r_offset < 0) ||
(rel->r_offset > dstsec->sh_size - sizeof(u32))) {
@@ -151,7 +152,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char
*strtab,
/* Given an address, look for it in the module exception tables. */
const struct exception_table_entry *search_module_dbetables(unsigned long
addr)
{
- return 0;
+ return NULL;
}
/* Put in dbe list if necessary. */
diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
index d93966f..84575b2 100644
--- a/arch/score/kernel/process.c
+++ b/arch/score/kernel/process.c
@@ -23,7 +23,10 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <linux/elfcore.h>
#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/reboot.h>
void (*pm_power_off)(void);
EXPORT_SYMBOL(pm_power_off);
diff --git a/arch/score/kernel/ptrace.c b/arch/score/kernel/ptrace.c
index 19911e3..897dd7c 100644
--- a/arch/score/kernel/ptrace.c
+++ b/arch/score/kernel/ptrace.c
@@ -267,6 +267,7 @@ long
arch_ptrace(struct task_struct *child, long request, long addr, long
data)
{
int ret;
+ unsigned long __user *datap = (void __user *)data;
switch (request) {
/* Read the word at location addr in the USER area. */
@@ -316,7 +317,7 @@ arch_ptrace(struct task_struct *child, long request,
long addr, long data)
return -EIO;
}
- ret = put_user(tmp, (unsigned long *) data);
+ ret = put_user(tmp, (unsigned long *) datap);
return ret;
}
@@ -355,11 +356,11 @@ arch_ptrace(struct task_struct *child, long request,
long addr, long data)
}
case PTRACE_GETREGS:
- ret = ptrace_getregs(child, (void __user *)data);
+ ret = ptrace_getregs(child, (void __user *)datap);
break;
case PTRACE_SETREGS:
- ret = ptrace_setregs(child, (void __user *)data);
+ ret = ptrace_setregs(child, (void __user *)datap);
break;
default:
diff --git a/arch/score/kernel/signal.c b/arch/score/kernel/signal.c
index 5c00408..e351c02 100644
--- a/arch/score/kernel/signal.c
+++ b/arch/score/kernel/signal.c
@@ -27,7 +27,9 @@
#include <linux/signal.h>
#include <linux/unistd.h>
#include <linux/uaccess.h>
-#include <asm-generic/ucontext.h>
+
+#include <asm/syscalls.h>
+#include <asm/ucontext.h>
#include <asm/cacheflush.h>
@@ -40,7 +42,8 @@ struct rt_sigframe {
struct ucontext rs_uc;
};
-int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
+static int
+setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
{
int err = 0;
unsigned long reg;
@@ -74,7 +77,8 @@ int setup_sigcontext(struct pt_regs *regs, struct
sigcontext __user *sc)
return err;
}
-int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user
*sc)
+static int
+restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
{
int err = 0;
u32 reg;
@@ -116,8 +120,8 @@ int restore_sigcontext(struct pt_regs *regs, struct
sigcontext __user *sc)
/*
* Determine which stack to use..
*/
-void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
- size_t frame_size)
+static void __user *
+get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t
frame_size)
{
unsigned long sp;
@@ -129,19 +133,19 @@ void __user *get_sigframe(struct k_sigaction *ka,
struct pt_regs *regs,
if ((ka->sa.sa_flags & SA_ONSTACK) && (!on_sig_stack(sp)))
sp = current->sas_ss_sp + current->sas_ss_size;
- return (void *)((sp - frame_size) & ~7);
+ return (void __user *)((sp - frame_size) & ~7);
}
-int score_sigaltstack(struct pt_regs *regs)
+asmlinkage long score_sigaltstack(struct pt_regs *regs)
{
- const stack_t *uss = (const stack_t *) regs->regs[4];
- stack_t *uoss = (stack_t *) regs->regs[5];
+ const stack_t __user *uss = (const stack_t __user *)
regs->regs[4];
+ stack_t __user *uoss = (stack_t __user *) regs->regs[5];
unsigned long usp = regs->regs[0];
return do_sigaltstack(uss, uoss, usp);
}
-void score_rt_sigreturn(struct pt_regs *regs)
+asmlinkage long score_rt_sigreturn(struct pt_regs *regs)
{
struct rt_sigframe __user *frame;
sigset_t set;
@@ -181,12 +185,13 @@ void score_rt_sigreturn(struct pt_regs *regs)
badframe:
force_sig(SIGSEGV, current);
+ return 0;
}
-int setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
- int signr, sigset_t *set, siginfo_t *info)
+static int setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
+ int signr, sigset_t *set, siginfo_t *info)
{
- struct rt_sigframe *frame;
+ struct rt_sigframe __user *frame;
int err = 0;
frame = get_sigframe(ka, regs, sizeof(*frame));
@@ -206,8 +211,8 @@ int setup_rt_frame(struct k_sigaction *ka, struct
pt_regs *regs,
err |= copy_siginfo_to_user(&frame->rs_info, info);
err |= __put_user(0, &frame->rs_uc.uc_flags);
- err |= __put_user(0, &frame->rs_uc.uc_link);
- err |= __put_user((void *)current->sas_ss_sp,
+ err |= __put_user(NULL, &frame->rs_uc.uc_link);
+ err |= __put_user((void __user *)current->sas_ss_sp,
&frame->rs_uc.uc_stack.ss_sp);
err |= __put_user(sas_ss_flags(regs->regs[0]),
&frame->rs_uc.uc_stack.ss_flags);
@@ -236,7 +241,7 @@ give_sigsegv:
return -EFAULT;
}
-int handle_signal(unsigned long sig, siginfo_t *info,
+static int handle_signal(unsigned long sig, siginfo_t *info,
struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs)
{
int ret;
@@ -276,7 +281,7 @@ int handle_signal(unsigned long sig, siginfo_t *info,
return ret;
}
-void do_signal(struct pt_regs *regs)
+static void do_signal(struct pt_regs *regs)
{
struct k_sigaction ka;
sigset_t *oldset;
diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c
index 3318861..c5a3fbc 100644
--- a/arch/score/kernel/sys_score.c
+++ b/arch/score/kernel/sys_score.c
@@ -27,12 +27,12 @@
#include <linux/fs.h>
#include <linux/mman.h>
#include <linux/module.h>
+#include <linux/syscalls.h>
#include <linux/unistd.h>
-unsigned long shm_align_mask = PAGE_SIZE - 1;
-EXPORT_SYMBOL(shm_align_mask);
+#include <asm/syscalls.h>
-asmlinkage unsigned long
+asmlinkage long
sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
unsigned long flags, unsigned long fd, unsigned long pgoff)
{
@@ -64,7 +64,7 @@ sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot,
* Clone a task - this clones the calling program thread.
* This is called indirectly via a small wrapper
*/
-int score_clone(struct pt_regs *regs)
+asmlinkage long score_clone(struct pt_regs *regs)
{
unsigned long clone_flags;
unsigned long newsp;
@@ -85,33 +85,25 @@ int score_clone(struct pt_regs *regs)
* sys_execve() executes a new program.
* This is called indirectly via a small wrapper
*/
-int score_execve(struct pt_regs *regs)
+asmlinkage long score_execve(struct pt_regs *regs)
{
int error;
char *filename;
- filename = getname((char *) (long) regs->regs[4]);
+ filename = getname((char __user *)regs->regs[4]);
error = PTR_ERR(filename);
if (IS_ERR(filename))
return error;
- error = do_execve(filename, (char **) (long) regs->regs[5],
- (char **) (long) regs->regs[6], regs);
+ error = do_execve(filename,
+ (char __user * __user *)(long)regs->regs[5],
+ (char __user * __user *)(long)regs->regs[6],
regs);
putname(filename);
return error;
}
/*
- * If we ever come here the user sp is bad. Zap the process right away.
- * Due to the bad stack signaling wouldn't work.
- */
-void bad_stack(void)
-{
- do_exit(SIGSEGV);
-}
-
-/*
* Do a system call from kernel instead of calling sys_execve so we
* end up with proper pt_regs.
*/
diff --git a/arch/score/kernel/time.c b/arch/score/kernel/time.c
index cd66ba3..f0a43af 100644
--- a/arch/score/kernel/time.c
+++ b/arch/score/kernel/time.c
@@ -28,7 +28,7 @@
#include <asm/scoreregs.h>
-irqreturn_t timer_interrupt(int irq, void *dev_id)
+static irqreturn_t timer_interrupt(int irq, void *dev_id)
{
struct clock_event_device *evdev = dev_id;
diff --git a/arch/score/mm/init.c b/arch/score/mm/init.c
index 7780eec..e5f6f2e 100644
--- a/arch/score/mm/init.c
+++ b/arch/score/mm/init.c
@@ -32,44 +32,30 @@
#include <linux/pagemap.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>
-#include <asm-generic/sections.h>
+#include <linux/initrd.h>
+#include <asm/sections.h>
#include <asm/tlb.h>
DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
-/*
- * We have up to 8 empty zeroed pages so we can map one of the right
colour
- * when needed.
- */
-unsigned long zero_page_mask;
unsigned long empty_zero_page;
EXPORT_SYMBOL_GPL(empty_zero_page);
static struct kcore_list kcore_mem, kcore_vmalloc;
-unsigned long setup_zero_pages(void)
+static unsigned long setup_zero_page(void)
{
- unsigned int order = 0;
- unsigned long size;
struct page *page;
- empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO,
order);
+ empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, 0);
if (!empty_zero_page)
panic("Oh boy, that early out of memory?");
page = virt_to_page((void *) empty_zero_page);
- split_page(page, order);
- while (page < virt_to_page((void *) (empty_zero_page +
- (PAGE_SIZE << order)))) {
- SetPageReserved(page);
- page++;
- }
-
- size = PAGE_SIZE << order;
- zero_page_mask = (size - 1) & PAGE_MASK;
+ SetPageReserved(page);
- return 1UL << order;
+ return 1UL;
}
#ifndef CONFIG_NEED_MULTIPLE_NODES
@@ -100,7 +86,7 @@ void __init mem_init(void)
max_mapnr = max_low_pfn;
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
totalram_pages += free_all_bootmem();
- totalram_pages -= setup_zero_pages(); /* Setup zeroed pages. */
+ totalram_pages -= setup_zero_page(); /* Setup zeroed pages. */
reservedpages = 0;
for (tmp = 0; tmp < max_low_pfn; tmp++)
@@ -129,7 +115,8 @@ void __init mem_init(void)
}
#endif /* !CONFIG_NEED_MULTIPLE_NODES */
-void free_init_pages(const char *what, unsigned long begin, unsigned long
end)
+static void
+free_init_pages(const char *what, unsigned long begin, unsigned long end)
{
unsigned long pfn;
@@ -150,8 +137,8 @@ void free_init_pages(const char *what, unsigned long
begin, unsigned long end)
void free_initrd_mem(unsigned long start, unsigned long end)
{
free_init_pages("initrd memory",
- virt_to_phys((void *) start),
- virt_to_phys((void *) end));
+ virt_to_phys((void *) start),
+ virt_to_phys((void *) end));
}
#endif
--
1.6.2
Attachment:
0001-score-code-cleanups.patch
Description: Binary data