* [PATCH 1/3] driver core: bus: use list_for_each_entry*
@ 2016-01-05 15:03 Geliang Tang
2016-01-05 15:03 ` [PATCH 2/3] driver core: bus: use to_subsys_private and to_device_private_bus Geliang Tang
0 siblings, 1 reply; 4+ messages in thread
From: Geliang Tang @ 2016-01-05 15:03 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Geliang Tang, linux-kernel
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] driver core: bus: use to_subsys_private and to_device_private_bus
2016-01-05 15:03 [PATCH 1/3] driver core: bus: use list_for_each_entry* Geliang Tang
@ 2016-01-05 15:03 ` Geliang Tang
2016-01-05 15:03 ` [PATCH 3/3] driver core: bus: add a new helper to_driver_private_bus Geliang Tang
0 siblings, 1 reply; 4+ messages in thread
From: Geliang Tang @ 2016-01-05 15:03 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Geliang Tang, linux-kernel
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] driver core: bus: add a new helper to_driver_private_bus
2016-01-05 15:03 ` [PATCH 2/3] driver core: bus: use to_subsys_private and to_device_private_bus Geliang Tang
@ 2016-01-05 15:03 ` Geliang Tang
2016-02-10 1:25 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Geliang Tang @ 2016-01-05 15:03 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Geliang Tang, linux-kernel
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 3/3] driver core: bus: add a new helper to_driver_private_bus
2016-01-05 15:03 ` [PATCH 3/3] driver core: bus: add a new helper to_driver_private_bus Geliang Tang
@ 2016-02-10 1:25 ` Greg Kroah-Hartman
0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2016-02-10 1:25 UTC (permalink / raw)
To: Geliang Tang; +Cc: linux-kernel
On Tue, Jan 05, 2016 at 11:03:39PM +0800, Geliang Tang wrote:
> 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);
No need for a macro in a .h file that is only used in one place in one
file, right?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-10 1:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-05 15:03 [PATCH 1/3] driver core: bus: use list_for_each_entry* Geliang Tang
2016-01-05 15:03 ` [PATCH 2/3] driver core: bus: use to_subsys_private and to_device_private_bus Geliang Tang
2016-01-05 15:03 ` [PATCH 3/3] driver core: bus: add a new helper to_driver_private_bus Geliang Tang
2016-02-10 1:25 ` Greg Kroah-Hartman
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.