From: Greg KH <gregkh@linuxfoundation.org>
To: Gustav Wiklander <gustav.wiklander@axis.com>
Cc: linux-pm@vger.kernel.org, rjw@rjwysocki.net, khilman@kernel.org,
ulf.hansson@linaro.org, len.brown@intel.com, pavel@ucw.cz,
kernel@axis.com, Gustav Wiklander <gustavwi@axis.com>
Subject: Re: [PATCH] PM / Domains: Add module ref count for each consumer
Date: Wed, 10 Jun 2020 16:52:29 +0200 [thread overview]
Message-ID: <20200610145229.GA2101163@kroah.com> (raw)
In-Reply-To: <20200610143943.12548-1-gustav.wiklander@axis.com>
On Wed, Jun 10, 2020 at 04:39:43PM +0200, Gustav Wiklander wrote:
> From: Gustav Wiklander <gustavwi@axis.com>
>
> Currently a pm_domain can be unloaded without regard for consumers.
> This patch adds a module dependecy for every registered consumer.
> Now a power domain driver can only be unloaded if no consumers are
> registered.
What is the problem with doing this? Shouldn't when a power domain is
unregistered, the consumers are properly torn down? Some subsystems
allow you to unload a module at any point in time, and properly clean
things up. What is the problem today that you are trying to solve with
this (remember, removing modules only happens by developers, no
real-world system ever automatically onloads a module.)
>
> Signed-off-by: Gustav Wiklander <gustavwi@axis.com>
> ---
> drivers/base/power/domain.c | 11 ++++++++++-
> include/linux/pm_domain.h | 2 ++
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 0a01df608849..80723f6d5e6b 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -1499,11 +1499,18 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
> if (IS_ERR(gpd_data))
> return PTR_ERR(gpd_data);
>
> + if (!try_module_get(genpd->owner)) {
> + ret = -ENODEV;
> + goto out;
> + }
> +
> gpd_data->cpu = genpd_get_cpu(genpd, base_dev);
>
> ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0;
> - if (ret)
> + if (ret) {
> + module_put(genpd->owner);
> goto out;
> + }
>
> genpd_lock(genpd);
>
> @@ -1579,6 +1586,8 @@ static int genpd_remove_device(struct generic_pm_domain *genpd,
>
> genpd_free_dev_data(dev, gpd_data);
>
> + module_put(genpd->owner);
> +
> return 0;
>
> out:
> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
> index 9ec78ee53652..777c1b30e5af 100644
> --- a/include/linux/pm_domain.h
> +++ b/include/linux/pm_domain.h
> @@ -9,6 +9,7 @@
> #define _LINUX_PM_DOMAIN_H
>
> #include <linux/device.h>
> +#include <linux/module.h>
> #include <linux/mutex.h>
> #include <linux/pm.h>
> #include <linux/err.h>
> @@ -93,6 +94,7 @@ struct opp_table;
>
> struct generic_pm_domain {
> struct device dev;
> + struct module *owner; /* Module owner of the PM domain */
But you did not actually set the owner field anywhere :(
Make this an automatic thing, look how functions like
usb_register_driver() and friends to it so that you do not have to go
around and try to add it by hand to every driver. And then go back in a
year and fix up the remaining ones you missed. And then in another
year...
thanks,
greg k-h
next prev parent reply other threads:[~2020-06-10 14:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-10 14:39 [PATCH] PM / Domains: Add module ref count for each consumer Gustav Wiklander
2020-06-10 14:52 ` Greg KH [this message]
2020-06-10 17:24 ` Gustav Wiklander
2020-07-05 9:37 ` Greg KH
2020-06-10 14:57 ` Rafael J. Wysocki
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=20200610145229.GA2101163@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=gustav.wiklander@axis.com \
--cc=gustavwi@axis.com \
--cc=kernel@axis.com \
--cc=khilman@kernel.org \
--cc=len.brown@intel.com \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rjw@rjwysocki.net \
--cc=ulf.hansson@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