• R
    cpufreq: Do not hold driver module references for additional policy CPUs · 71c3461e
    Rafael J. Wysocki 提交于
    The cpufreq core is a little inconsistent in the way it uses the
    driver module refcount.
    
    Namely, if __cpufreq_add_dev() is called for a CPU that doesn't
    share the policy object with any other CPUs, the driver module
    refcount it grabs to start with will be dropped by it before
    returning and will be equal to whatever it had been before that
    function was invoked.
    
    However, if the given CPU does share the policy object with other
    CPUs, either cpufreq_add_policy_cpu() is called to link the new CPU
    to the existing policy, or cpufreq_add_dev_symlink() is used to link
    the other CPUs sharing the policy with it to the just created policy
    object.  In that case, because both cpufreq_add_policy_cpu() and
    cpufreq_add_dev_symlink() call cpufreq_cpu_get() for the given
    policy (the latter possibly many times) without the balancing
    cpufreq_cpu_put() (unless there is an error), the driver module
    refcount will be left by __cpufreq_add_dev() with a nonzero value
    (different from the initial one).
    
    To remove that inconsistency make cpufreq_add_policy_cpu() execute
    cpufreq_cpu_put() for the given policy before returning, which
    decrements the driver module refcount so that it will be equal to its
    initial value after __cpufreq_add_dev() returns.  Also remove the
    cpufreq_cpu_get() call from cpufreq_add_dev_symlink(), since both the
    policy refcount and the driver module refcount are nonzero when it is
    called and they don't need to be bumped up by it.
    
    Accordingly, drop the cpufreq_cpu_put() from __cpufreq_remove_dev(),
    since it is only necessary to balance the cpufreq_cpu_get() called
    by cpufreq_add_policy_cpu() or cpufreq_add_dev_symlink().
    Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
    Reviewed-by: NSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
    Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
    71c3461e
cpufreq.c 54.6 KB