From: Nishanth Menon <nm@ti.com>
To: Inderpal Singh <inderpal.s@samsung.com>,
<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <rjw@rjwysocki.net>, <pavel@ucw.cz>, <viresh.kumar@linaro.org>
Subject: Re: [PATCH] PM / OPP: Implement free_opp_table function
Date: Mon, 19 May 2014 08:13:34 -0500 [thread overview]
Message-ID: <537A037E.8000800@ti.com> (raw)
In-Reply-To: <1400231366-1221-1-git-send-email-inderpal.s@samsung.com>
On 05/16/2014 04:09 AM, Inderpal Singh wrote:
> At the driver unloading time the associated opp table may need
> to be deleted. Otherwise it amounts to memory leak. The existing
> OPP library does not have provison to do so.
>
> Hence this patch implements the function to free the opp table.
>
> Signed-off-by: Inderpal Singh <inderpal.s@samsung.com>
> ---
> drivers/base/power/opp.c | 41 +++++++++++++++++++++++++++++++++++++++++
> include/linux/pm_opp.h | 6 ++++++
> 2 files changed, 47 insertions(+)
>
> diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
> index d9e376a..d45ffd5 100644
> --- a/drivers/base/power/opp.c
> +++ b/drivers/base/power/opp.c
> @@ -654,4 +654,45 @@ int of_init_opp_table(struct device *dev)
> return 0;
> }
> EXPORT_SYMBOL_GPL(of_init_opp_table);
> +
> +/**
> + * dev_pm_opp_free_opp_table() - free the opp table
> + * @dev: device for which we do this operation
> + *
> + * Free up the allocated opp table
> + *
> + * Locking: The internal device_opp and opp structures are RCU protected.
> + * Hence this function internally uses RCU updater strategy with mutex locks to
> + * keep the integrity of the internal data structures. Callers should ensure
> + * that this function is *NOT* called under RCU protection or in contexts where
> + * mutex locking or synchronize_rcu() blocking calls cannot be used.
> + */
> +void dev_pm_opp_free_opp_table(struct device *dev)
> +{
> + struct device_opp *dev_opp = NULL;
> + struct dev_pm_opp *opp;
> +
if (!dev)
return;
> + /* Hold our list modification lock here */
> + mutex_lock(&dev_opp_list_lock);
> +
> + /* Check for existing list for 'dev' */
> + dev_opp = find_device_opp(dev);
> + if (IS_ERR(dev_opp)) {
> + mutex_unlock(&dev_opp_list_lock);
> + return;
> + }
> +
> + while (!list_empty(&dev_opp->opp_list)) {
> + opp = list_entry_rcu(dev_opp->opp_list.next,
> + struct dev_pm_opp, node);
> + list_del_rcu(&opp->node);
> + kfree_rcu(opp, head);
> + }
How about the OPP notifiers? should'nt we add a new event
OPP_EVENT_REMOVE?
To maintain non-dt behavior coherency, should'nt we rather add a
opp_remove or an opp_del function?
> +
> + list_del_rcu(&dev_opp->node);
> + mutex_unlock(&dev_opp_list_lock);
> + synchronize_rcu();
> + kfree(dev_opp);
> +}
> +EXPORT_SYMBOL_GPL(dev_pm_opp_free_opp_table);
> #endif
> diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
> index 0330217..3c29620 100644
> --- a/include/linux/pm_opp.h
> +++ b/include/linux/pm_opp.h
> @@ -50,6 +50,8 @@ int dev_pm_opp_enable(struct device *dev, unsigned long freq);
> int dev_pm_opp_disable(struct device *dev, unsigned long freq);
>
> struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev);
> +
> +void dev_pm_opp_free_opp_table(struct device *dev);
> #else
> static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
> {
> @@ -105,6 +107,10 @@ static inline struct srcu_notifier_head *dev_pm_opp_get_notifier(
> {
> return ERR_PTR(-EINVAL);
> }
> +
> +void dev_pm_opp_free_opp_table(struct device *dev)
> +{
> +}
> #endif /* CONFIG_PM_OPP */
>
> #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
>
--
Regards,
Nishanth Menon
next prev parent reply other threads:[~2014-05-19 13:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 9:09 [PATCH] PM / OPP: Implement free_opp_table function Inderpal Singh
2014-05-16 10:06 ` Viresh Kumar
2014-05-16 17:08 ` Inderpal Singh
2014-05-16 17:11 ` Viresh Kumar
2014-05-16 17:24 ` Inderpal Singh
2014-05-16 17:26 ` Viresh Kumar
2014-05-19 13:13 ` Nishanth Menon [this message]
2014-05-19 18:08 ` Inderpal Singh
2014-05-19 18:34 ` Nishanth Menon
2014-05-20 5:36 ` Inderpal Singh
2014-05-20 11:25 ` Nishanth Menon
2014-05-21 5:51 ` [PATCH v2] PM / OPP: Implement opp_remove and free_opp_table functions Inderpal Singh
2014-05-21 7:55 ` Viresh Kumar
2014-05-21 8:06 ` Inderpal Singh
2014-05-21 8:13 ` Viresh Kumar
2014-05-30 1:00 ` Nishanth Menon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=537A037E.8000800@ti.com \
--to=nm@ti.com \
--cc=inderpal.s@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rjw@rjwysocki.net \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox