]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
cpufreq: Init policy->rwsem before it may be possibly used
authorLifeng Zheng <zhenglifeng1@huawei.com>
Wed, 9 Jul 2025 10:41:43 +0000 (18:41 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 14 Jul 2025 17:38:10 +0000 (19:38 +0200)
In cpufreq_policy_put_kobj(), policy->rwsem is used. But in
cpufreq_policy_alloc(), if freq_qos_add_notifier() returns an error, error
path via err_kobj_remove or err_min_qos_notifier will be reached and
cpufreq_policy_put_kobj() will be called before policy->rwsem is
initialized. Thus, the calling of init_rwsem() should be moved to where
before these two error paths can be reached.

Fixes: 67d874c3b2c6 ("cpufreq: Register notifiers with the PM QoS framework")
Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
Link: https://patch.msgid.link/20250709104145.2348017-3-zhenglifeng1@huawei.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c

index eb713d116c34ef67455926b0ff1f026691f2a569..2175d2df95b64957c75d37af82942f41a7d1c93a 100644 (file)
@@ -1281,6 +1281,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
                goto err_free_real_cpus;
        }
 
+       init_rwsem(&policy->rwsem);
+
        freq_constraints_init(&policy->constraints);
 
        policy->nb_min.notifier_call = cpufreq_notifier_min;
@@ -1303,7 +1305,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
        }
 
        INIT_LIST_HEAD(&policy->policy_list);
-       init_rwsem(&policy->rwsem);
        spin_lock_init(&policy->transition_lock);
        init_waitqueue_head(&policy->transition_wait);
        INIT_WORK(&policy->update, handle_update);