Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1587751 > unrolled thread
| Started by | Benjamin Gaignard <benjamin.gaignard@linaro.org> |
|---|---|
| First post | 2017-02-24 17:20 +0100 |
| Last post | 2017-02-27 17:50 +0100 |
| Articles | 5 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v2 1/2] of: add devm_ functions for populate and depopulate Benjamin Gaignard <benjamin.gaignard@linaro.org> - 2017-02-24 17:20 +0100
Re: [PATCH v2 1/2] of: add devm_ functions for populate and depopulate Rob Herring <robh+dt@kernel.org> - 2017-02-24 17:40 +0100
Re: [PATCH v2 1/2] of: add devm_ functions for populate and depopulate Daniel Vetter <daniel@ffwll.ch> - 2017-02-26 21:20 +0100
Re: [PATCH v2 1/2] of: add devm_ functions for populate and depopulate Rob Herring <robh+dt@kernel.org> - 2017-02-27 14:50 +0100
Re: [PATCH v2 1/2] of: add devm_ functions for populate and depopulate Daniel Vetter <daniel@ffwll.ch> - 2017-02-27 17:50 +0100
| From | Benjamin Gaignard <benjamin.gaignard@linaro.org> |
|---|---|
| Date | 2017-02-24 17:20 +0100 |
| Subject | [PATCH v2 1/2] of: add devm_ functions for populate and depopulate |
| Message-ID | <teqL7-2Ds-1@gated-at.bofh.it> |
Lots of calls to of_platform_populate() are not unbalanced by a call
to of_platform_depopulate(). This create issues while drivers are
bind/unbind.
In way to solve those issues is to add devm_of_platform_populate()
which will call of_platform_depopulate() when the device is unbound
from the bus.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
---
version 2:
- simplify function prototype to only keep device as parameter
drivers/of/platform.c | 71 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/of_platform.h | 11 +++++++
2 files changed, 82 insertions(+)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index b8064bc..f5bbb50 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -571,6 +571,77 @@ void of_platform_depopulate(struct device *parent)
}
EXPORT_SYMBOL_GPL(of_platform_depopulate);
+static void devm_of_platform_populate_release(struct device *dev, void *res)
+{
+ of_platform_depopulate(*(struct device **)res);
+}
+
+/**
+ * devm_of_platform_populate() - Populate platform_devices from device tree data
+ * @dev: device that requested to populate from device tree data
+ *
+ * Similar to of_platform_populate(), but will automatically call
+ * of_platform_depopulate() when the device is unbound from the bus.
+ *
+ * Returns 0 on success, < 0 on failure.
+ */
+int devm_of_platform_populate(struct device *dev)
+{
+ struct device **ptr;
+ int ret;
+
+ if (!dev)
+ return -EINVAL;
+
+ ptr = devres_alloc(devm_of_platform_populate_release,
+ sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
+ if (ret) {
+ devres_free(ptr);
+ } else {
+ *ptr = dev;
+ devres_add(dev, ptr);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_of_platform_populate);
+
+static int devm_of_platform_match(struct device *dev, void *res, void *data)
+{
+ struct device **ptr = res;
+
+ if (!ptr) {
+ WARN_ON(!ptr);
+ return 0;
+ }
+
+ return *ptr == data;
+}
+
+/**
+ * devm_of_platform_depopulate() - Remove devices populated from device tree
+ * @dev: device that requested to depopulate from device tree data
+ *
+ * Complementary to devm_of_platform_populate(), this function removes children
+ * of the given device (and, recurrently, their children) that have been
+ * created from their respective device tree nodes (and only those,
+ * leaving others - eg. manually created - unharmed).
+ */
+void devm_of_platform_depopulate(struct device *dev)
+{
+ int ret;
+
+ ret = devres_release(dev, devm_of_platform_populate_release,
+ devm_of_platform_match, dev);
+
+ WARN_ON(ret);
+}
+EXPORT_SYMBOL_GPL(devm_of_platform_depopulate);
+
#ifdef CONFIG_OF_DYNAMIC
static int of_platform_notify(struct notifier_block *nb,
unsigned long action, void *arg)
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 956a100..dc8224a 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -76,6 +76,10 @@ extern int of_platform_default_populate(struct device_node *root,
const struct of_dev_auxdata *lookup,
struct device *parent);
extern void of_platform_depopulate(struct device *parent);
+
+extern int devm_of_platform_populate(struct device *dev);
+
+extern void devm_of_platform_depopulate(struct device *dev);
#else
static inline int of_platform_populate(struct device_node *root,
const struct of_device_id *matches,
@@ -91,6 +95,13 @@ static inline int of_platform_default_populate(struct device_node *root,
return -ENODEV;
}
static inline void of_platform_depopulate(struct device *parent) { }
+
+static inline int devm_of_platform_populate(struct device *dev)
+{
+ return -ENODEV;
+}
+
+static inline void devm_of_platform_depopulate(struct device *dev) { }
#endif
#if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
--
1.9.1
[toc] | [next] | [standalone]
| From | Rob Herring <robh+dt@kernel.org> |
|---|---|
| Date | 2017-02-24 17:40 +0100 |
| Message-ID | <ter4t-2Kh-3@gated-at.bofh.it> |
| In reply to | #1587751 |
On Fri, Feb 24, 2017 at 10:14 AM, Benjamin Gaignard <benjamin.gaignard@linaro.org> wrote: > Lots of calls to of_platform_populate() are not unbalanced by a call > to of_platform_depopulate(). This create issues while drivers are > bind/unbind. > > In way to solve those issues is to add devm_of_platform_populate() > which will call of_platform_depopulate() when the device is unbound > from the bus. > > Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org> > --- > version 2: > - simplify function prototype to only keep device as parameter > > drivers/of/platform.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ > include/linux/of_platform.h | 11 +++++++ > 2 files changed, 82 insertions(+) For this and patch 2: Acked-by: Rob Herring <robh@kernel.org> Rob
[toc] | [prev] | [next] | [standalone]
| From | Daniel Vetter <daniel@ffwll.ch> |
|---|---|
| Date | 2017-02-26 21:20 +0100 |
| Subject | Re: [PATCH v2 1/2] of: add devm_ functions for populate and depopulate |
| Message-ID | <tfdst-3gq-13@gated-at.bofh.it> |
| In reply to | #1587774 |
On Fri, Feb 24, 2017 at 10:31:25AM -0600, Rob Herring wrote: > On Fri, Feb 24, 2017 at 10:14 AM, Benjamin Gaignard > <benjamin.gaignard@linaro.org> wrote: > > Lots of calls to of_platform_populate() are not unbalanced by a call > > to of_platform_depopulate(). This create issues while drivers are > > bind/unbind. > > > > In way to solve those issues is to add devm_of_platform_populate() > > which will call of_platform_depopulate() when the device is unbound > > from the bus. > > > > Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org> > > --- > > version 2: > > - simplify function prototype to only keep device as parameter > > > > drivers/of/platform.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ > > include/linux/of_platform.h | 11 +++++++ > > 2 files changed, 82 insertions(+) > > For this and patch 2: > > Acked-by: Rob Herring <robh@kernel.org> Is this an ack for merging both through drm-misc, or should we do a topic-branch dance here? /me not sure anymore what we discussed here already Cheers, Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
[toc] | [prev] | [next] | [standalone]
| From | Rob Herring <robh+dt@kernel.org> |
|---|---|
| Date | 2017-02-27 14:50 +0100 |
| Message-ID | <tftQC-6g8-15@gated-at.bofh.it> |
| In reply to | #1588389 |
On Sun, Feb 26, 2017 at 2:11 PM, Daniel Vetter <daniel@ffwll.ch> wrote: > On Fri, Feb 24, 2017 at 10:31:25AM -0600, Rob Herring wrote: >> On Fri, Feb 24, 2017 at 10:14 AM, Benjamin Gaignard >> <benjamin.gaignard@linaro.org> wrote: >> > Lots of calls to of_platform_populate() are not unbalanced by a call >> > to of_platform_depopulate(). This create issues while drivers are >> > bind/unbind. >> > >> > In way to solve those issues is to add devm_of_platform_populate() >> > which will call of_platform_depopulate() when the device is unbound >> > from the bus. >> > >> > Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org> >> > --- >> > version 2: >> > - simplify function prototype to only keep device as parameter >> > >> > drivers/of/platform.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ >> > include/linux/of_platform.h | 11 +++++++ >> > 2 files changed, 82 insertions(+) >> >> For this and patch 2: >> >> Acked-by: Rob Herring <robh@kernel.org> > > Is this an ack for merging both through drm-misc, or should we do a > topic-branch dance here? You can apply it directly. Rob
[toc] | [prev] | [next] | [standalone]
| From | Daniel Vetter <daniel@ffwll.ch> |
|---|---|
| Date | 2017-02-27 17:50 +0100 |
| Subject | Re: [PATCH v2 1/2] of: add devm_ functions for populate and depopulate |
| Message-ID | <tfwEO-8dT-31@gated-at.bofh.it> |
| In reply to | #1588667 |
On Mon, Feb 27, 2017 at 07:30:24AM -0600, Rob Herring wrote: > On Sun, Feb 26, 2017 at 2:11 PM, Daniel Vetter <daniel@ffwll.ch> wrote: > > On Fri, Feb 24, 2017 at 10:31:25AM -0600, Rob Herring wrote: > >> On Fri, Feb 24, 2017 at 10:14 AM, Benjamin Gaignard > >> <benjamin.gaignard@linaro.org> wrote: > >> > Lots of calls to of_platform_populate() are not unbalanced by a call > >> > to of_platform_depopulate(). This create issues while drivers are > >> > bind/unbind. > >> > > >> > In way to solve those issues is to add devm_of_platform_populate() > >> > which will call of_platform_depopulate() when the device is unbound > >> > from the bus. > >> > > >> > Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org> > >> > --- > >> > version 2: > >> > - simplify function prototype to only keep device as parameter > >> > > >> > drivers/of/platform.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ > >> > include/linux/of_platform.h | 11 +++++++ > >> > 2 files changed, 82 insertions(+) > >> > >> For this and patch 2: > >> > >> Acked-by: Rob Herring <robh@kernel.org> > > > > Is this an ack for merging both through drm-misc, or should we do a > > topic-branch dance here? > > You can apply it directly. Ok, this seems like a pretty cool idea, so applied both to drm-misc for 4.12. Cheers, Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web