Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763452AbYALBIU (ORCPT ); Fri, 11 Jan 2008 20:08:20 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1762707AbYALBIK (ORCPT ); Fri, 11 Jan 2008 20:08:10 -0500 Received: from 216-99-217-87.dsl.aracnet.com ([216.99.217.87]:53538 "EHLO sous-sol.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762843AbYALBIJ (ORCPT ); Fri, 11 Jan 2008 20:08:09 -0500 Date: Fri, 11 Jan 2008 17:06:56 -0800 From: Chris Wright To: Ingo Molnar Cc: Kevin Winchester , "H. Peter Anvin" , Thomas Gleixner , Linux Kernel Mailing List , "mboton@gmail.com" , Zach Brown Subject: [PATCH] x86: refactor ioport unification Message-ID: <20080112010656.GD3627@sequoia.sous-sol.org> References: <4786AA11.5010805@gmail.com> <4786AB1B.4030004@zytor.com> <4786AF4C.6050509@gmail.com> <4786C2CF.4070204@zytor.com> <20080110220444.4c9efdec.kjwinchester@gmail.com> <20080111140346.GA13604@elte.hu> <20080112010443.GA5476@sequoia.sous-sol.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080112010443.GA5476@sequoia.sous-sol.org> User-Agent: Mutt/1.5.16 (2007-06-09) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2511 Lines: 85 Refactor ioport unification to pull out common code. Cc: mboton@gmail.com Cc: Kevin Winchester Cc: Zach Brown Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Thomas Gleixner Signed-off-by: Chris Wright --- Applies atop the ioport unification fix for 32-bit arch/x86/kernel/ioport.c | 40 +++++++++++++++++++++------------------- 1 files changed, 21 insertions(+), 19 deletions(-) diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c index be72d80..50e5e4a 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/