From 32f3bf67ee78332f2caec0984cb9d412cd0a3c23 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Tue, 12 Nov 2019 19:56:19 +0100 Subject: [PATCH] x86/ioperm: Avoid bitmap allocation if no permissions are set If ioperm() is invoked the first time and the @turn_on argument is 0, then there is no point to allocate a bitmap just to clear permissions which are not set. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/ioport.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c index ca6aa1e33c97..80fa36be2670 100644 --- a/arch/x86/kernel/ioport.c +++ b/arch/x86/kernel/ioport.c @@ -36,6 +36,9 @@ long ksys_ioperm(unsigned long from, unsigned long num, int turn_on) */ bitmap = t->io_bitmap_ptr; if (!bitmap) { + /* No point to allocate a bitmap just to clear permissions */ + if (!turn_on) + return 0; bitmap = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL); if (!bitmap) return -ENOMEM; -- 2.20.1