From: Chris Wright Date: Wed, 30 Jan 2008 12:33:10 +0000 (+0100) Subject: x86: refactor ioport unification X-Git-Tag: v2.6.25-rc1~1143^2~300 X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=a1bf250a6f31afb8caac166ae50dc7b89c38084c;p=linux-2.6-omap-h63xx.git x86: refactor ioport unification Refactor ioport unification to pull out common code. Cc: mboton@gmail.com Cc: Kevin Winchester Cc: Zach Brown Cc: "H. Peter Anvin" Signed-off-by: Chris Wright Signed-off-by: Ingo Molnar Signed-off-by: Thomas Gleixner --- diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c index be72d809bce..50e5e4a31c8 100644 --- a/arch/x86/kernel/ioport.c +++ b/arch/x86/kernel/ioport.c @@ -113,13 +113,9 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on) * on system-call entry - see also fork() and the signal handling * code. */ -#ifdef CONFIG_X86_32 -asmlinkage long sys_iopl(unsigned long regsp) +static int do_iopl(unsigned int level, struct pt_regs *regs) { - struct pt_regs *regs = (struct pt_regs *)®sp; - unsigned int level = regs->bx; unsigned int old = (regs->flags >> 12) & 3; - struct thread_struct *t = ¤t->thread; if (level > 3) return -EINVAL; @@ -128,25 +124,31 @@ asmlinkage long sys_iopl(unsigned long regsp) if (!capable(CAP_SYS_RAWIO)) return -EPERM; } - t->iopl = level << 12; regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12); - set_iopl_mask(t->iopl); + return 0; } -#else -asmlinkage long sys_iopl(unsigned int level, struct pt_regs *regs) + +#ifdef CONFIG_X86_32 +asmlinkage long sys_iopl(unsigned long regsp) { - unsigned int old = (regs->flags >> 12) & 3; + struct pt_regs *regs = (struct pt_regs *)®sp; + unsigned int level = regs->bx; + struct thread_struct *t = ¤t->thread; + int rc; - if (level > 3) - return -EINVAL; - /* Trying to gain more privileges? */ - if (level > old) { - if (!capable(CAP_SYS_RAWIO)) - return -EPERM; - } - regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12); + rc = do_iopl(level, regs); + if (rc < 0) + goto out; - return 0; + t->iopl = level << 12; + set_iopl_mask(t->iopl); +out: + return rc; +} +#else +asmlinkage long sys_iopl(unsigned int level, struct pt_regs *regs) +{ + return do_iopl(level, regs); } #endif