[patch V3 07/20] x86/ioperm: Avoid bitmap allocation if no permissions are set

From: Thomas Gleixner
Date: Wed Nov 13 2019 - 16:03:34 EST


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 <tglx@xxxxxxxxxxxxx>
---
V3: Split out from large combo patch
---
arch/x86/kernel/ioport.c | 3 +++
1 file changed, 3 insertions(+)

--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -36,6 +36,9 @@ long ksys_ioperm(unsigned long from, uns
*/
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;