From 844e2d38915c025833725f704e98c7a323929096 Mon Sep 17 00:00:00 2001 From: Albert Cahalan Date: Sun, 17 Aug 2003 22:32:22 -0700 Subject: [PATCH] [PATCH] reduce diff between x86-64 & i386 This cleans up ioport.c to use BITS_PER_LONG, sizeof, and so on. This makes it easier to spot the differences that matter, and thus easier to find bugs. --- arch/i386/kernel/ioport.c | 30 +++++++++++++++--------------- arch/x86_64/kernel/ioport.c | 14 +++++++------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/arch/i386/kernel/ioport.c b/arch/i386/kernel/ioport.c index 50eddc8fa2b6f..efe24ad66c02c 100644 --- a/arch/i386/kernel/ioport.c +++ b/arch/i386/kernel/ioport.c @@ -17,32 +17,32 @@ #include /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */ -static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value) +static void set_bitmap(unsigned long *bitmap, unsigned long base, unsigned long extent, int new_value) { - int mask; - unsigned long *bitmap_base = bitmap + (base >> 5); - unsigned short low_index = base & 0x1f; + unsigned long mask; + unsigned long *bitmap_base = bitmap + (base / BITS_PER_LONG); + unsigned long low_index = base & (BITS_PER_LONG-1); int length = low_index + extent; if (low_index != 0) { - mask = (~0 << low_index); - if (length < 32) - mask &= ~(~0 << length); + mask = (~0UL << low_index); + if (length < BITS_PER_LONG) + mask &= ~(~0UL << length); if (new_value) *bitmap_base++ |= mask; else *bitmap_base++ &= ~mask; - length -= 32; + length -= BITS_PER_LONG; } - mask = (new_value ? ~0 : 0); - while (length >= 32) { + mask = (new_value ? ~0UL : 0UL); + while (length >= BITS_PER_LONG) { *bitmap_base++ = mask; - length -= 32; + length -= BITS_PER_LONG; } if (length > 0) { - mask = ~(~0 << length); + mask = ~(~0UL << length); if (new_value) *bitmap_base++ |= mask; else @@ -53,7 +53,7 @@ static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_ /* * this changes the io permissions bitmap in the current task. */ -asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int turn_on) +asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on) { struct thread_struct * t = ¤t->thread; struct tss_struct * tss; @@ -111,7 +111,7 @@ out: * code. */ -asmlinkage int sys_iopl(unsigned long unused) +asmlinkage long sys_iopl(unsigned long unused) { volatile struct pt_regs * regs = (struct pt_regs *) &unused; unsigned int level = regs->ebx; @@ -124,7 +124,7 @@ asmlinkage int sys_iopl(unsigned long unused) if (!capable(CAP_SYS_RAWIO)) return -EPERM; } - regs->eflags = (regs->eflags & 0xffffcfff) | (level << 12); + regs->eflags = (regs->eflags &~ 0x3000UL) | (level << 12); /* Make sure we return the long way (not sysenter) */ set_thread_flag(TIF_IRET); return 0; diff --git a/arch/x86_64/kernel/ioport.c b/arch/x86_64/kernel/ioport.c index 2bf838c7e3794..f7f3eb8bb9ba7 100644 --- a/arch/x86_64/kernel/ioport.c +++ b/arch/x86_64/kernel/ioport.c @@ -21,25 +21,25 @@ static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value) { unsigned long mask; - unsigned long *bitmap_base = bitmap + (base / sizeof(unsigned long)); - unsigned short low_index = base & 0x3f; + unsigned long *bitmap_base = bitmap + (base / BITS_PER_LONG); + unsigned long low_index = base & (BITS_PER_LONG-1); int length = low_index + extent; if (low_index != 0) { mask = (~0UL << low_index); - if (length < 64) + if (length < BITS_PER_LONG) mask &= ~(~0UL << length); if (new_value) *bitmap_base++ |= mask; else *bitmap_base++ &= ~mask; - length -= 64; + length -= BITS_PER_LONG; } mask = (new_value ? ~0UL : 0UL); - while (length >= 64) { + while (length >= BITS_PER_LONG) { *bitmap_base++ = mask; - length -= 64; + length -= BITS_PER_LONG; } if (length > 0) { @@ -115,7 +115,7 @@ asmlinkage long sys_iopl(unsigned int level, struct pt_regs regs) if (!capable(CAP_SYS_RAWIO)) return -EPERM; } - regs.eflags = (regs.eflags & 0xffffffffffffcfff) | (level << 12); + regs.eflags = (regs.eflags &~ 0x3000UL) | (level << 12); return 0; } -- 2.53.0