]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PM: domains: add device managed version of dev_pm_domain_attach|detach_list()
authorDikshita Agarwal <quic_dikshita@quicinc.com>
Mon, 19 Aug 2024 10:29:09 +0000 (15:59 +0530)
committerUlf Hansson <ulf.hansson@linaro.org>
Tue, 20 Aug 2024 09:19:49 +0000 (11:19 +0200)
Add the devres-enabled version of dev_pm_domain_attach|detach_list.
If client drivers use devm_pm_domain_attach_list() to attach the PM domains,
devm_pm_domain_detach_list() will be invoked implicitly during remove phase.

Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
Link: https://lore.kernel.org/r/1724063350-11993-2-git-send-email-quic_dikshita@quicinc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/base/power/common.c
include/linux/pm_domain.h

index 327d168dd37a808939087cbc76c2f6f70ed66aae..8c34ae1cd8d554d5e9e8deb86a2d49688d82ad22 100644 (file)
@@ -276,6 +276,51 @@ err_attach:
 }
 EXPORT_SYMBOL_GPL(dev_pm_domain_attach_list);
 
+/**
+ * devm_pm_domain_detach_list - devres-enabled version of dev_pm_domain_detach_list.
+ * @_list: The list of PM domains to detach.
+ *
+ * This function reverse the actions from devm_pm_domain_attach_list().
+ * it will be invoked during the remove phase from drivers implicitly if driver
+ * uses devm_pm_domain_attach_list() to attach the PM domains.
+ */
+static void devm_pm_domain_detach_list(void *_list)
+{
+       struct dev_pm_domain_list *list = _list;
+
+       dev_pm_domain_detach_list(list);
+}
+
+/**
+ * devm_pm_domain_attach_list - devres-enabled version of dev_pm_domain_attach_list
+ * @dev: The device used to lookup the PM domains for.
+ * @data: The data used for attaching to the PM domains.
+ * @list: An out-parameter with an allocated list of attached PM domains.
+ *
+ * NOTE: this will also handle calling devm_pm_domain_detach_list() for
+ * you during remove phase.
+ *
+ * Returns the number of attached PM domains or a negative error code in case of
+ * a failure.
+ */
+int devm_pm_domain_attach_list(struct device *dev,
+                              const struct dev_pm_domain_attach_data *data,
+                              struct dev_pm_domain_list **list)
+{
+       int ret, num_pds;
+
+       num_pds = dev_pm_domain_attach_list(dev, data, list);
+       if (num_pds <= 0)
+               return num_pds;
+
+       ret = devm_add_action_or_reset(dev, devm_pm_domain_detach_list, *list);
+       if (ret)
+               return ret;
+
+       return num_pds;
+}
+EXPORT_SYMBOL_GPL(devm_pm_domain_attach_list);
+
 /**
  * dev_pm_domain_detach - Detach a device from its PM domain.
  * @dev: Device to detach.
index b86bb52858ac563200b3bd5eefaed9dbedc762b5..b637ec14025f9dcb0bb70522a342c831bafb08bb 100644 (file)
@@ -476,6 +476,9 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev,
 int dev_pm_domain_attach_list(struct device *dev,
                              const struct dev_pm_domain_attach_data *data,
                              struct dev_pm_domain_list **list);
+int devm_pm_domain_attach_list(struct device *dev,
+                              const struct dev_pm_domain_attach_data *data,
+                              struct dev_pm_domain_list **list);
 void dev_pm_domain_detach(struct device *dev, bool power_off);
 void dev_pm_domain_detach_list(struct dev_pm_domain_list *list);
 int dev_pm_domain_start(struct device *dev);
@@ -502,6 +505,14 @@ static inline int dev_pm_domain_attach_list(struct device *dev,
 {
        return 0;
 }
+
+static inline int devm_pm_domain_attach_list(struct device *dev,
+                                            const struct dev_pm_domain_attach_data *data,
+                                            struct dev_pm_domain_list **list)
+{
+       return 0;
+}
+
 static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
 static inline void dev_pm_domain_detach_list(struct dev_pm_domain_list *list) {}
 static inline int dev_pm_domain_start(struct device *dev)