All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Gaignard <benjamin.gaignard@linaro.org>
To: robh+dt@kernel.org, frowand.list@gmail.com,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	vincent.abriou@st.com, dri-devel@lists.freedesktop.org
Cc: linaro-kernel@lists.linaro.org,
	Benjamin Gaignard <benjamin.gaignard@linaro.org>
Subject: [PATCH v1 1/2] of: add devm_ functions for populate and depopulate
Date: Fri, 17 Feb 2017 15:31:25 +0100	[thread overview]
Message-ID: <1487341886-13829-2-git-send-email-benjamin.gaignard@linaro.org> (raw)
In-Reply-To: <1487341886-13829-1-git-send-email-benjamin.gaignard@linaro.org>

Lost 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>
---
 drivers/of/platform.c       | 77 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_platform.h | 20 ++++++++++++
 2 files changed, 97 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index b8064bc..3dbebf7 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -571,6 +571,83 @@ 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
+ * @root: parent of the first level to probe or NULL for the root of the tree
+ * @matches: match table, NULL to use the default
+ * @lookup: auxdata table for matching id and platform_data with device nodes
+ * @parent: parent to hook devices from, NULL for toplevel
+ *
+ * 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_node *root,
+			      const struct of_device_id *matches,
+			      const struct of_dev_auxdata *lookup,
+			      struct device *parent)
+{
+	struct device **ptr;
+	int ret;
+
+	ptr = devres_alloc(devm_of_platform_populate_release,
+			   sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return -ENOMEM;
+
+	ret = of_platform_populate(root, matches, lookup, parent);
+	if (ret) {
+		devres_free(ptr);
+	} else {
+		*ptr = parent;
+		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 populate from device tree data
+ * @parent: device which children will be removed
+ *
+ * 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, struct device *parent)
+{
+	int ret;
+
+	ret = devres_release(dev, devm_of_platform_populate_release,
+			     devm_of_platform_match, parent);
+
+	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..282fae3 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -76,6 +76,14 @@ 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,
+				     struct device_node *root,
+				     const struct of_device_id *matches,
+				     const struct of_dev_auxdata *lookup,
+				     struct device *parent);
+extern void devm_of_platform_depopulate(struct device *dev,
+					struct device *parent);
 #else
 static inline int of_platform_populate(struct device_node *root,
 					const struct of_device_id *matches,
@@ -91,6 +99,18 @@ 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,
+					    struct device_node *root,
+					    const struct of_device_id *matches,
+					    const struct of_dev_auxdata *lookup,
+					    struct device *parent)
+{
+	return -ENODEV;
+}
+
+static inline void devm_of_platform_depopulate(struct device *dev,
+					       struct device *parent) { }
 #endif
 
 #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
-- 
1.9.1

WARNING: multiple messages have this Message-ID (diff)
From: Benjamin Gaignard <benjamin.gaignard@linaro.org>
To: robh+dt@kernel.org, frowand.list@gmail.com,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	vincent.abriou@st.com, dri-devel@lists.freedesktop.org
Cc: linaro-kernel@lists.linaro.org
Subject: [PATCH v1 1/2] of: add devm_ functions for populate and depopulate
Date: Fri, 17 Feb 2017 15:31:25 +0100	[thread overview]
Message-ID: <1487341886-13829-2-git-send-email-benjamin.gaignard@linaro.org> (raw)
In-Reply-To: <1487341886-13829-1-git-send-email-benjamin.gaignard@linaro.org>

Lost 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>
---
 drivers/of/platform.c       | 77 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_platform.h | 20 ++++++++++++
 2 files changed, 97 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index b8064bc..3dbebf7 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -571,6 +571,83 @@ 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
+ * @root: parent of the first level to probe or NULL for the root of the tree
+ * @matches: match table, NULL to use the default
+ * @lookup: auxdata table for matching id and platform_data with device nodes
+ * @parent: parent to hook devices from, NULL for toplevel
+ *
+ * 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_node *root,
+			      const struct of_device_id *matches,
+			      const struct of_dev_auxdata *lookup,
+			      struct device *parent)
+{
+	struct device **ptr;
+	int ret;
+
+	ptr = devres_alloc(devm_of_platform_populate_release,
+			   sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return -ENOMEM;
+
+	ret = of_platform_populate(root, matches, lookup, parent);
+	if (ret) {
+		devres_free(ptr);
+	} else {
+		*ptr = parent;
+		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 populate from device tree data
+ * @parent: device which children will be removed
+ *
+ * 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, struct device *parent)
+{
+	int ret;
+
+	ret = devres_release(dev, devm_of_platform_populate_release,
+			     devm_of_platform_match, parent);
+
+	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..282fae3 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -76,6 +76,14 @@ 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,
+				     struct device_node *root,
+				     const struct of_device_id *matches,
+				     const struct of_dev_auxdata *lookup,
+				     struct device *parent);
+extern void devm_of_platform_depopulate(struct device *dev,
+					struct device *parent);
 #else
 static inline int of_platform_populate(struct device_node *root,
 					const struct of_device_id *matches,
@@ -91,6 +99,18 @@ 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,
+					    struct device_node *root,
+					    const struct of_device_id *matches,
+					    const struct of_dev_auxdata *lookup,
+					    struct device *parent)
+{
+	return -ENODEV;
+}
+
+static inline void devm_of_platform_depopulate(struct device *dev,
+					       struct device *parent) { }
 #endif
 
 #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
-- 
1.9.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-02-17 14:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17 14:31 [PATCH v1 0/2] Introduce devm_of_platform_populate() helper Benjamin Gaignard
2017-02-17 14:31 ` Benjamin Gaignard
2017-02-17 14:31 ` Benjamin Gaignard [this message]
2017-02-17 14:31   ` [PATCH v1 1/2] of: add devm_ functions for populate and depopulate Benjamin Gaignard
2017-02-24 14:17   ` Rob Herring
2017-02-24 14:17     ` Rob Herring
2017-02-24 15:13     ` Benjamin Gaignard
2017-02-24 15:13       ` Benjamin Gaignard
2017-02-24 15:20       ` Rob Herring
2017-02-24 15:20         ` Rob Herring
2017-02-24 15:26         ` Benjamin Gaignard
2017-02-24 15:26           ` Benjamin Gaignard
2017-02-24 15:30           ` Rob Herring
2017-02-24 15:30             ` Rob Herring
2017-02-17 14:31 ` [PATCH v1 2/2] drm: sti: make driver use devm_of_platform_populate() Benjamin Gaignard
2017-02-17 14:31   ` Benjamin Gaignard

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=1487341886-13829-2-git-send-email-benjamin.gaignard@linaro.org \
    --to=benjamin.gaignard@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=frowand.list@gmail.com \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=vincent.abriou@st.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.