LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Chanwoo Choi <cw00.choi@samsung.com>
To: myungjoo.ham@samsung.com, kgene@kernel.org
Cc: kyungmin.park@samsung.com, rafael.j.wysocki@intel.com,
mark.rutland@arm.com, a.kesavan@samsung.com,
tomasz.figa@gmail.com, k.kozlowski@samsung.com,
b.zolnierkie@samsung.com, robh+dt@kernel.org,
cw00.choi@samsung.com, inki.dae@samsung.com,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org
Subject: [PATCHv8 2/9] devfreq: event: Add resource-managed function for devfreq-event device
Date: Mon, 12 Jan 2015 21:34:50 +0900 [thread overview]
Message-ID: <1421066097-26237-3-git-send-email-cw00.choi@samsung.com> (raw)
In-Reply-To: <1421066097-26237-1-git-send-email-cw00.choi@samsung.com>
This patch add the resource-managed function for devfreq-event device as
following functions. The devm_devfreq_event_add_edev() manages automatically
the memory of devfreq-event device using resource management.
- devm_devfreq_event_add_edev()
- devm_devfreq_event_remove_edev()
Cc: Myungjoo Ham <myungjoo.ham@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
drivers/devfreq/devfreq-event.c | 63 +++++++++++++++++++++++++++++++++++++++++
include/linux/devfreq-event.h | 16 +++++++++++
2 files changed, 79 insertions(+)
diff --git a/drivers/devfreq/devfreq-event.c b/drivers/devfreq/devfreq-event.c
index 9ba5ba4..57529af 100644
--- a/drivers/devfreq/devfreq-event.c
+++ b/drivers/devfreq/devfreq-event.c
@@ -389,6 +389,69 @@ int devfreq_event_remove_edev(struct devfreq_event_dev *edev)
}
EXPORT_SYMBOL_GPL(devfreq_event_remove_edev);
+static int devm_devfreq_event_match(struct device *dev, void *res, void *data)
+{
+ struct devfreq_event_dev **r = res;
+
+ if (WARN_ON(!r || !*r))
+ return 0;
+
+ return *r == data;
+}
+
+static void devm_devfreq_event_release(struct device *dev, void *res)
+{
+ devfreq_event_remove_edev(*(struct devfreq_event_dev **)res);
+}
+
+/**
+ * devm_devfreq_event_add_edev() - Resource-managed devfreq_event_add_edev()
+ * @dev : the device owning the devfreq-event device being created
+ * @desc : the devfreq-event device's decriptor which include essential
+ * data for devfreq-event device.
+ *
+ * Note that this function manages automatically the memory of devfreq-event
+ * device using device resource management and simplify the free operation
+ * for memory of devfreq-event device.
+ */
+struct devfreq_event_dev *devm_devfreq_event_add_edev(struct device *dev,
+ struct devfreq_event_desc *desc)
+{
+ struct devfreq_event_dev **ptr, *edev;
+
+ ptr = devres_alloc(devm_devfreq_event_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
+
+ edev = devfreq_event_add_edev(dev, desc);
+ if (IS_ERR(edev)) {
+ devres_free(ptr);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ *ptr = edev;
+ devres_add(dev, ptr);
+
+ return edev;
+}
+EXPORT_SYMBOL_GPL(devm_devfreq_event_add_edev);
+
+/**
+ * devm_devfreq_event_remove_edev()- Resource-managed devfreq_event_remove_edev()
+ * @dev : the device owning the devfreq-event device being created
+ * @edev : the devfreq-event device
+ *
+ * Note that this function manages automatically the memory of devfreq-event
+ * device using device resource management.
+ */
+void devm_devfreq_event_remove_edev(struct device *dev,
+ struct devfreq_event_dev *edev)
+{
+ WARN_ON(devres_release(dev, devm_devfreq_event_release,
+ devm_devfreq_event_match, edev));
+}
+EXPORT_SYMBOL_GPL(devm_devfreq_event_remove_edev);
+
/*
* Device attributes for devfreq-event class.
*/
diff --git a/include/linux/devfreq-event.h b/include/linux/devfreq-event.h
index b7363f5..b6e3afa 100644
--- a/include/linux/devfreq-event.h
+++ b/include/linux/devfreq-event.h
@@ -106,6 +106,10 @@ extern int devfreq_event_get_edev_count(struct device *dev);
extern struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
struct devfreq_event_desc *desc);
extern int devfreq_event_remove_edev(struct devfreq_event_dev *edev);
+extern struct devfreq_event_dev *devm_devfreq_event_add_edev(struct device *dev,
+ struct devfreq_event_desc *desc);
+extern void devm_devfreq_event_remove_edev(struct device *dev,
+ struct devfreq_event_dev *edev);
#else
static inline int devfreq_event_enable_edev(struct devfreq_event_dev *edev)
@@ -165,6 +169,18 @@ static inline int devfreq_event_remove_edev(struct devfreq_event_dev *edev)
{
return -EINVAL;
}
+
+static inline struct devfreq_event_dev *devm_devfreq_event_add_edev(
+ struct device *dev,
+ struct devfreq_event_desc *desc)
+{
+ return ERR_PTR(-EINVAL);
+}
+
+static inline void devm_devfreq_event_remove_edev(struct device *dev,
+ struct devfreq_event_dev *edev)
+{
+}
#endif /* CONFIG_PM_DEVFREQ_EVENT */
#endif /* __LINUX_DEVFREQ_EVENT_H__ */
--
1.8.5.5
next prev parent reply other threads:[~2015-01-12 12:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-12 12:34 [PATCHv8 0/9] devfreq: Add devfreq-event class to provide raw data for devfreq device Chanwoo Choi
2015-01-12 12:34 ` [PATCHv8 1/9] devfreq: event: Add new devfreq_event class to provide basic data for devfreq governor Chanwoo Choi
2015-01-19 10:12 ` Chanwoo Choi
2015-01-12 12:34 ` Chanwoo Choi [this message]
2015-01-12 12:34 ` [PATCHv8 3/9] devfreq: event: Add exynos-ppmu devfreq-event driver Chanwoo Choi
2015-01-12 12:34 ` [PATCHv8 4/9] devfreq: event: Add documentation for " Chanwoo Choi
2015-01-12 12:34 ` [PATCHv8 5/9] ARM: dts: Add PPMU dt node for Exynos3250 SoC Chanwoo Choi
2015-01-12 12:34 ` [PATCHv8 6/9] ARM: dts: Add PPMU dt node for Exynos4 SoCs Chanwoo Choi
2015-01-12 12:34 ` [PATCHv8 7/9] ARM: dts: Add PPMU dt node for Exynos5260 SoC Chanwoo Choi
2015-01-19 10:01 ` Chanwoo Choi
2015-01-12 12:34 ` [PATCHv8 8/9] ARM: dts: exynos: Add PPMU node to Exynos3250-based Rinato/Monk board Chanwoo Choi
2015-01-12 12:34 ` [PATCHv8 9/9] ARM: dts: exynos: Add PPMU node for Exynos4412-based TRATS2 board Chanwoo Choi
2015-01-19 0:50 ` [PATCHv8 0/9] devfreq: Add devfreq-event class to provide raw data for devfreq device Chanwoo Choi
2015-01-20 4:46 [PATCHv8 2/9] devfreq: event: Add resource-managed function for devfreq-event device MyungJoo Ham
2015-01-20 4:47 ` Chanwoo Choi
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=1421066097-26237-3-git-send-email-cw00.choi@samsung.com \
--to=cw00.choi@samsung.com \
--cc=a.kesavan@samsung.com \
--cc=b.zolnierkie@samsung.com \
--cc=inki.dae@samsung.com \
--cc=k.kozlowski@samsung.com \
--cc=kgene@kernel.org \
--cc=kyungmin.park@samsung.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=myungjoo.ham@samsung.com \
--cc=rafael.j.wysocki@intel.com \
--cc=robh+dt@kernel.org \
--cc=tomasz.figa@gmail.com \
--subject='Re: [PATCHv8 2/9] devfreq: event: Add resource-managed function for devfreq-event device' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).