x86/fpu: Fix the init_fpstate size check with the actual size
[linux-2.6-microblaze.git] / arch / x86 / kernel / fpu / xstate.c
index f0ce106..f5ef786 100644 (file)
@@ -678,20 +678,6 @@ static unsigned int __init get_xsave_size_user(void)
        return ebx;
 }
 
-/*
- * Will the runtime-enumerated 'xstate_size' fit in the init
- * task's statically-allocated buffer?
- */
-static bool __init is_supported_xstate_size(unsigned int test_xstate_size)
-{
-       if (test_xstate_size <= sizeof(init_fpstate.regs))
-               return true;
-
-       pr_warn("x86/fpu: xstate buffer too small (%zu < %d), disabling xsave\n",
-                       sizeof(init_fpstate.regs), test_xstate_size);
-       return false;
-}
-
 static int __init init_xstate_size(void)
 {
        /* Recompute the context size for enabled features: */
@@ -717,10 +703,6 @@ static int __init init_xstate_size(void)
        kernel_default_size =
                xstate_calculate_size(fpu_kernel_cfg.default_features, compacted);
 
-       /* Ensure we have the space to store all default enabled features. */
-       if (!is_supported_xstate_size(kernel_default_size))
-               return -EINVAL;
-
        if (!paranoid_xstate_size_valid(kernel_size))
                return -EINVAL;
 
@@ -879,6 +861,12 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
        init_fpstate.size               = fpu_kernel_cfg.max_size;
        init_fpstate.xfeatures          = fpu_kernel_cfg.max_features;
 
+       if (init_fpstate.size > sizeof(init_fpstate.regs)) {
+               pr_warn("x86/fpu: init_fpstate buffer too small (%zu < %d), disabling XSAVE\n",
+                       sizeof(init_fpstate.regs), init_fpstate.size);
+               goto out_disable;
+       }
+
        setup_init_fpu_buf();
 
        /*