From: Gustav Wiklander <gustav.wiklander@axis.com>
To: <linux-pm@vger.kernel.org>
Cc: <rjw@rjwysocki.net>, <khilman@kernel.org>,
<ulf.hansson@linaro.org>, <len.brown@intel.com>, <pavel@ucw.cz>,
<gregkh@linuxfoundation.org>, <kernel@axis.com>,
Gustav Wiklander <gustavwi@axis.com>
Subject: [PATCH] PM / Domains: Add module ref count for each consumer
Date: Wed, 10 Jun 2020 16:39:43 +0200 [thread overview]
Message-ID: <20200610143943.12548-1-gustav.wiklander@axis.com> (raw)
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.
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 */
struct dev_pm_domain domain; /* PM domain operations */
struct list_head gpd_list_node; /* Node in the global PM domains list */
struct list_head master_links; /* Links with PM domain as a master */
--
2.11.0
next reply other threads:[~2020-06-10 14:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-10 14:39 Gustav Wiklander [this message]
2020-06-10 14:52 ` [PATCH] PM / Domains: Add module ref count for each consumer Greg KH
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=20200610143943.12548-1-gustav.wiklander@axis.com \
--to=gustav.wiklander@axis.com \
--cc=gregkh@linuxfoundation.org \
--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