Re: linux-next: Tree for Apr 9 [cpufreq: NULL pointer deref]

From: Dirk Brandewie
Date: Mon Apr 15 2013 - 14:01:37 EST

On 04/15/2013 10:51 AM, Sedat Dilek wrote:
On Mon, Apr 15, 2013 at 7:22 PM, Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
On 15 April 2013 21:37, Dirk Brandewie <dirk.brandewie@xxxxxxxxx> wrote:
If the intel_pstate driver is being used __cpufreq_governor() should NOT be
called intel_pstate does not implement the target() callback.

Nathan's commit 5800043b2 changed the fence around the call to
__cpufreq_governor() in __cpufreq_remove_dev() here is the relevant hunk.

No it isn't.

+ if (has_target)
__cpufreq_governor(data, CPUFREQ_GOV_STOP);

As it has taken care of this limitation.

BUT some of my earlier patches haven't. :(
Here is the fix (Sedat please try this and give your tested-by, use the attached
patch as gmail might break what i am copying in mail)..

Sorry for being late in fixing this issue, i am still down with Tonsil infection
and fever.. Today only i got some power to fix it after seeing Dirk's mail.

Your tested-by may help me to recover quickly :)

Me myself and I was today chez-mon-docteur... Let's see the results on Thursday.
Again, get well soon.

Tested against...

"BROKEN" Linux-Next (next-20130411) with attached patchset (incl.
your cpufreq-next-fixes).



root# echo 0 > /sys/devices/system/cpu/cpu3/online

Tested-by: Sedat Dilek <sedat.dilek@xxxxxxxxx>

...did not test on-reboot-case.

( Dirk promised to test as well... )

Tested with:
while true
echo 0 > online
echo 1 > online
For several minutes and rebooting several times seems to have fixed the

Nathan, Sorry for calling out your patch erroneously I should have paid closer

Viresh you can add my Tested-by:

- Sedat -

@Rafael: I will probably be down for one more week and so not doing any
reviews for now... I do check important mails sent directly to me though.


From: Viresh Kumar <viresh.kumar@xxxxxxxxxx>
Date: Mon, 15 Apr 2013 22:43:57 +0530
Subject: [PATCH] cpufreq: Don't call __cpufreq_governor() for drivers without

Some cpufreq drivers implement their own governor and so don't need us to call
generic governors interface via __cpufreq_governor(). Few recent commits haven't
obeyed this law well and we saw some regressions.

This patch tries to fix this issue.

Signed-off-by: Viresh Kumar <viresh.kumar@xxxxxxxxxx>
drivers/cpufreq/cpufreq.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 3564947..a6f6595 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -858,13 +858,18 @@ static int cpufreq_add_policy_cpu(unsigned int
cpu, unsigned int sibling,
struct device *dev)
struct cpufreq_policy *policy;
- int ret = 0;
+ int ret = 0, has_target = 0;
unsigned long flags;

policy = cpufreq_cpu_get(sibling);

- __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
+ rcu_read_lock();
+ has_target = !!rcu_dereference(cpufreq_driver)->target;
+ rcu_read_unlock();
+ if (has_target)
+ __cpufreq_governor(policy, CPUFREQ_GOV_STOP);


@@ -877,8 +882,10 @@ static int cpufreq_add_policy_cpu(unsigned int
cpu, unsigned int sibling,


- __cpufreq_governor(policy, CPUFREQ_GOV_START);
- __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
+ if (has_target) {
+ __cpufreq_governor(policy, CPUFREQ_GOV_START);
+ __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
+ }

ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq");
if (ret) {
@@ -1146,7 +1153,8 @@ static int __cpufreq_remove_dev(struct device
*dev, struct subsys_interface *sif

/* If cpu is last user of policy, free policy */
if (cpus == 1) {
- __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT);
+ if (has_target)
+ __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT);

kobj = &data->kobj;

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at