No point in allocating memory when the input parameters are bogus.
Validate all parameters before proceeding.
Suggested-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20210815211305.581789253@linutronix.de
 
                if (uaddr1 == uaddr2)
                        return -EINVAL;
 
-               /*
-                * requeue_pi requires a pi_state, try to allocate it now
-                * without any locks in case it fails.
-                */
-               if (refill_pi_state_cache())
-                       return -ENOMEM;
-
                /*
                 * futex_requeue() allows the caller to define the number
                 * of waiters to wake up via the @nr_wake argument. With
                 */
                if (nr_wake != 1)
                        return -EINVAL;
+
+               /*
+                * requeue_pi requires a pi_state, try to allocate it now
+                * without any locks in case it fails.
+                */
+               if (refill_pi_state_cache())
+                       return -ENOMEM;
        }
 
 retry: