]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rcuscale: Do a proper cleanup if kfree_scale_init() fails
authorUladzislau Rezki (Sony) <urezki@gmail.com>
Wed, 13 Nov 2024 11:00:08 +0000 (12:00 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2024 12:52:53 +0000 (13:52 +0100)
[ Upstream commit 812a1c3b9f7c36d9255f0d29d0a3d324e2f52321 ]

A static analyzer for C, Smatch, reports and triggers below
warnings:

   kernel/rcu/rcuscale.c:1215 rcu_scale_init()
   warn: inconsistent returns 'global &fullstop_mutex'.

The checker complains about, we do not unlock the "fullstop_mutex"
mutex, in case of hitting below error path:

<snip>
...
    if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
        pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
        WARN_ON_ONCE(1);
        return -1;
        ^^^^^^^^^^
...
<snip>

it happens because "-1" is returned right away instead of
doing a proper unwinding.

Fix it by jumping to "unwind" label instead of returning -1.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Reviewed-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
Closes: https://lore.kernel.org/rcu/ZxfTrHuEGtgnOYWp@pc636/T/
Fixes: 084e04fff160 ("rcuscale: Add laziness and kfree tests")
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/rcu/rcuscale.c

index f88c75b3cea3b816703b261d09125e88071ee2ad..31d480b533033db7842754841cf31c5156b43461 100644 (file)
@@ -781,13 +781,15 @@ kfree_scale_init(void)
                if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
                        pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
                        WARN_ON_ONCE(1);
-                       return -1;
+                       firsterr = -1;
+                       goto unwind;
                }
 
                if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
                        pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
                        WARN_ON_ONCE(1);
-                       return -1;
+                       firsterr = -1;
+                       goto unwind;
                }
        }