Message ID | 1540830201-2947-1-git-send-email-daniel.lezcano@linaro.org |
---|---|
State | New |
Headers | show |
Series | [1/4] base/drivers/arch_topology: Remove useless check | expand |
On Mon, Oct 29, 2018 at 9:56 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: Would have been better if I was cc'd on all the patches since I was looking at this stuff actively this week :) > The function 'register_cpufreq_notifier' registers the > init_cpu_capacity_notifier() only if raw_capacity is not NULL. > > Hence init_cpu_capacity_notifier() can not be called with raw_capacity > set to NULL, it is pointless to check it. It isn't entirely pointless though. It is possible for init_cpu_capacity_notifier() to get called after free_raw_capacity() is called from it as the notifier unregistration happens from a workqueue.
On 30/10/2018 06:50, Viresh Kumar wrote: > On Mon, Oct 29, 2018 at 9:56 PM Daniel Lezcano > <daniel.lezcano@linaro.org> wrote: > > Would have been better if I was cc'd on all the patches since I was > looking at this > stuff actively this week :) ah, yes. Sorry for that. >> The function 'register_cpufreq_notifier' registers the >> init_cpu_capacity_notifier() only if raw_capacity is not NULL. >> >> Hence init_cpu_capacity_notifier() can not be called with raw_capacity >> set to NULL, it is pointless to check it. > > It isn't entirely pointless though. > > It is possible for init_cpu_capacity_notifier() to get called after > free_raw_capacity() > is called from it as the notifier unregistration happens from a workqueue. The workqueue is called from init_cpu_capacity_callback(). This one is called in the notifier callback. IOW the notification callback unregisters itself. But if it is not registered, it won't unregister, hence it won't call the workqueue and init_cpu_capacity_notifier() is not called. -- <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
On 30-10-18, 08:55, Daniel Lezcano wrote: > The workqueue is called from init_cpu_capacity_callback(). This one is > called in the notifier callback. IOW the notification callback > unregisters itself. But if it is not registered, it won't unregister, > hence it won't call the workqueue and init_cpu_capacity_notifier() is > not called. Sorry, couldn't understand most of your reply :) Though let me try to explain the problem I was trying to show you.. cpufreq-notifier-callback -> init_cpu_capacity_callback() -> free raw capacity -> queue_work() to unregister the notifier -> return ->init_cpu_capacity_callback() called again before work was processed. -> If we don't check raw_capacity, we may end up using NULL pointer, as the notifier isn't unregistered yet. -- viresh
On 30/10/2018 09:33, Viresh Kumar wrote: > On 30-10-18, 08:55, Daniel Lezcano wrote: >> The workqueue is called from init_cpu_capacity_callback(). This one is >> called in the notifier callback. IOW the notification callback >> unregisters itself. But if it is not registered, it won't unregister, >> hence it won't call the workqueue and init_cpu_capacity_notifier() is >> not called. > > Sorry, couldn't understand most of your reply :) Logical, I didn't understand your initial comment :) > Though let me try to explain the problem I was trying to show you.. > > cpufreq-notifier-callback > -> init_cpu_capacity_callback() > -> free raw capacity > -> queue_work() to unregister the notifier > -> return > > ->init_cpu_capacity_callback() called again before work was processed. > -> If we don't check raw_capacity, we may end up using > NULL pointer, as the notifier isn't unregistered yet. Oh, nice catch. I'm wondering if having a statically per_cpu variable, even if it is not free at the end, isn't worth regarding the twisted code we end up with an allocation. -- <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
On 30-10-18, 14:35, Daniel Lezcano wrote: > I'm wondering if having a statically per_cpu variable, even if it is not > free at the end, isn't worth regarding the twisted code we end up with > an allocation. Maybe yeah. -- viresh
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index e7cb0c6..204ed10 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -181,9 +181,6 @@ init_cpu_capacity_callback(struct notifier_block *nb, struct cpufreq_policy *policy = data; int cpu; - if (!raw_capacity) - return 0; - if (val != CPUFREQ_NOTIFY) return 0;
The function 'register_cpufreq_notifier' registers the init_cpu_capacity_notifier() only if raw_capacity is not NULL. Hence init_cpu_capacity_notifier() can not be called with raw_capacity set to NULL, it is pointless to check it. Remove the check. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> --- drivers/base/arch_topology.c | 3 --- 1 file changed, 3 deletions(-) -- 2.7.4