Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1301590 > unrolled thread

[PATCH 1/3] driver core: bus: use list_for_each_entry*

Started byGeliang Tang <geliangtang@163.com>
First post2016-01-05 16:10 +0100
Last post2016-01-05 16:10 +0100
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/3] driver core: bus: use list_for_each_entry* Geliang Tang <geliangtang@163.com> - 2016-01-05 16:10 +0100
    [PATCH 3/3] driver core: bus: add a new helper to_driver_private_bus Geliang Tang <geliangtang@163.com> - 2016-01-05 16:10 +0100
    [PATCH 2/3] driver core: bus: use to_subsys_private and to_device_private_bus Geliang Tang <geliangtang@163.com> - 2016-01-05 16:10 +0100

#1301590 — [PATCH 1/3] driver core: bus: use list_for_each_entry*

FromGeliang Tang <geliangtang@163.com>
Date2016-01-05 16:10 +0100
Subject[PATCH 1/3] driver core: bus: use list_for_each_entry*
Message-ID<qNBph-4ua-31@gated-at.bofh.it>
Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/base/bus.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 5005924..4bee6b0 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -1019,13 +1019,11 @@ static void device_insertion_sort_klist(struct device *a, struct list_head *list
 					int (*compare)(const struct device *a,
 							const struct device *b))
 {
-	struct list_head *pos;
 	struct klist_node *n;
 	struct device_private *dev_prv;
 	struct device *b;
 
-	list_for_each(pos, list) {
-		n = container_of(pos, struct klist_node, n_node);
+	list_for_each_entry(n, list, n_node) {
 		dev_prv = to_device_private_bus(n);
 		b = dev_prv->device;
 		if (compare(a, b) <= 0) {
@@ -1042,8 +1040,7 @@ void bus_sort_breadthfirst(struct bus_type *bus,
 					  const struct device *b))
 {
 	LIST_HEAD(sorted_devices);
-	struct list_head *pos, *tmp;
-	struct klist_node *n;
+	struct klist_node *n, *tmp;
 	struct device_private *dev_prv;
 	struct device *dev;
 	struct klist *device_klist;
@@ -1051,8 +1048,7 @@ void bus_sort_breadthfirst(struct bus_type *bus,
 	device_klist = bus_get_device_klist(bus);
 
 	spin_lock(&device_klist->k_lock);
-	list_for_each_safe(pos, tmp, &device_klist->k_list) {
-		n = container_of(pos, struct klist_node, n_node);
+	list_for_each_entry_safe(n, tmp, &device_klist->k_list, n_node) {
 		dev_prv = to_device_private_bus(n);
 		dev = dev_prv->device;
 		device_insertion_sort_klist(dev, &sorted_devices, compare);
-- 
2.5.0


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1301591 — [PATCH 3/3] driver core: bus: add a new helper to_driver_private_bus

FromGeliang Tang <geliangtang@163.com>
Date2016-01-05 16:10 +0100
Subject[PATCH 3/3] driver core: bus: add a new helper to_driver_private_bus
Message-ID<qNBph-4ua-35@gated-at.bofh.it>
In reply to#1301590
Add a new helper to_driver_private_bus() for consistency with
to_device_private_bus() and use it in bus.c.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/base/base.h | 2 ++
 drivers/base/bus.c  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index e05db38..88119d6 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -51,6 +51,8 @@ struct driver_private {
 	struct device_driver *driver;
 };
 #define to_driver(obj) container_of(obj, struct driver_private, kobj)
+#define to_driver_private_bus(obj)	\
+	container_of(obj, struct driver_private, knode_bus)
 
 /**
  * struct device_private - structure to hold the private to the driver core portions of the device structure.
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 6470eb8..ddc2b0b 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -422,7 +422,7 @@ static struct device_driver *next_driver(struct klist_iter *i)
 	struct driver_private *drv_priv;
 
 	if (n) {
-		drv_priv = container_of(n, struct driver_private, knode_bus);
+		drv_priv = to_driver_private_bus(n);
 		return drv_priv->driver;
 	}
 	return NULL;
-- 
2.5.0


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1301592 — [PATCH 2/3] driver core: bus: use to_subsys_private and to_device_private_bus

FromGeliang Tang <geliangtang@163.com>
Date2016-01-05 16:10 +0100
Subject[PATCH 2/3] driver core: bus: use to_subsys_private and to_device_private_bus
Message-ID<qNBph-4ua-33@gated-at.bofh.it>
In reply to#1301590
Use to_subsys_private() and to_device_private_bus() instead of open-coding.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/base/bus.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 4bee6b0..6470eb8 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -149,8 +149,7 @@ EXPORT_SYMBOL_GPL(bus_remove_file);
 
 static void bus_release(struct kobject *kobj)
 {
-	struct subsys_private *priv =
-		container_of(kobj, typeof(*priv), subsys.kobj);
+	struct subsys_private *priv = to_subsys_private(kobj);
 	struct bus_type *bus = priv->bus;
 
 	kfree(priv);
@@ -1103,7 +1102,7 @@ struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter)
 		knode = klist_next(&iter->ki);
 		if (!knode)
 			return NULL;
-		dev = container_of(knode, struct device_private, knode_bus)->device;
+		dev = to_device_private_bus(knode)->device;
 		if (!iter->type || iter->type == dev->type)
 			return dev;
 	}
-- 
2.5.0


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web