From 4c62785e670e978294222a42200346f0538e19e7 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Tue, 5 Jan 2016 23:03:37 +0800 Subject: driver core: bus: use list_for_each_entry* Use list_for_each_entry*() instead of list_for_each*() to simplify the code. Signed-off-by: Geliang Tang Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 500592486e88..4bee6b0f9ea4 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); -- cgit v1.2.3-55-g7522 From 371fd7a2c438a56e00c18a83178555a7918329a2 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Tue, 5 Jan 2016 23:03:38 +0800 Subject: driver core: bus: use to_subsys_private and to_device_private_bus Use to_subsys_private() and to_device_private_bus() instead of open-coding. Signed-off-by: Geliang Tang Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 4bee6b0f9ea4..6470eb8088f4 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; } -- cgit v1.2.3-55-g7522 From 9e5b3d6f7f946a3fb4d83ac2ab6d2bfefcdafffb Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Mon, 4 Jan 2016 22:36:40 +0100 Subject: drivers: dma-coherent: simplify dma_init_coherent_memory return value Since only dma_declare_coherent_memory cares about dma_init_coherent_memory returning part of flags as it return value, move the condition to the former and simplify the latter. This in turn makes rmem_dma_device_init less confusing. Reported-by: Fugang Duan Signed-off-by: Michal Nazarewicz Acked-by: Marek Szyprowski Signed-off-by: Greg Kroah-Hartman --- drivers/base/dma-coherent.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c index 55b83983a9c0..87b808374888 100644 --- a/drivers/base/dma-coherent.c +++ b/drivers/base/dma-coherent.c @@ -17,9 +17,9 @@ struct dma_coherent_mem { spinlock_t spinlock; }; -static int dma_init_coherent_memory(phys_addr_t phys_addr, dma_addr_t device_addr, - size_t size, int flags, - struct dma_coherent_mem **mem) +static bool dma_init_coherent_memory( + phys_addr_t phys_addr, dma_addr_t device_addr, size_t size, int flags, + struct dma_coherent_mem **mem) { struct dma_coherent_mem *dma_mem = NULL; void __iomem *mem_base = NULL; @@ -50,17 +50,13 @@ static int dma_init_coherent_memory(phys_addr_t phys_addr, dma_addr_t device_add spin_lock_init(&dma_mem->spinlock); *mem = dma_mem; - - if (flags & DMA_MEMORY_MAP) - return DMA_MEMORY_MAP; - - return DMA_MEMORY_IO; + return true; out: kfree(dma_mem); if (mem_base) iounmap(mem_base); - return 0; + return false; } static void dma_release_coherent_memory(struct dma_coherent_mem *mem) @@ -88,15 +84,13 @@ int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, dma_addr_t device_addr, size_t size, int flags) { struct dma_coherent_mem *mem; - int ret; - ret = dma_init_coherent_memory(phys_addr, device_addr, size, flags, - &mem); - if (ret == 0) + if (!dma_init_coherent_memory(phys_addr, device_addr, size, flags, + &mem)) return 0; if (dma_assign_coherent_memory(dev, mem) == 0) - return ret; + return flags & DMA_MEMORY_MAP ? DMA_MEMORY_MAP : DMA_MEMORY_IO; dma_release_coherent_memory(mem); return 0; @@ -281,9 +275,9 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) struct dma_coherent_mem *mem = rmem->priv; if (!mem && - dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, - DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE, - &mem) != DMA_MEMORY_MAP) { + !dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, + DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE, + &mem)) { pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n", &rmem->base, (unsigned long)rmem->size / SZ_1M); return -ENODEV; -- cgit v1.2.3-55-g7522 From 4877bb91786e41426bcbec0e151c048a9bd8a1ce Mon Sep 17 00:00:00 2001 From: Sudip Mukherjee Date: Tue, 2 Feb 2016 12:57:53 +0530 Subject: component: remove impossible condition We will be evaluating this condition only if match->num == match->alloc and that means we have already dereferenced match which implies match can not be NULL at this point. Moreover we have done a NULL check on match just before this. Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/base/component.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/component.c b/drivers/base/component.c index 89f5cf68d80a..2085b234f7c8 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -265,7 +265,7 @@ void component_match_add_release(struct device *master, } if (match->num == match->alloc) { - size_t new_size = match ? match->alloc + 16 : 15; + size_t new_size = match->alloc + 16; int ret; ret = component_match_realloc(master, match, new_size); -- cgit v1.2.3-55-g7522 From 67d02a1bbb334558e9380409a3cd426b36d4578b Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 13 Nov 2015 09:14:20 +0100 Subject: driver-core: platform: probe of-devices only using list of compatibles There are several indications that make a platform device match a platform driver. For devices that are instantiated by a device tree matching by name, id table or acpi mechanisms doesn't make sense and might result in surprising effects. So limit matching to use the driver's of_match_table for these. Acked-by: Thierry Reding Signed-off-by: Uwe Kleine-König Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index f437afa17f2b..1b5b7b5b50c0 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -949,8 +949,8 @@ static int platform_match(struct device *dev, struct device_driver *drv) return !strcmp(pdev->driver_override, drv->name); /* Attempt an OF style match first */ - if (of_driver_match_device(dev, drv)) - return 1; + if (pdev->dev.of_node) + return of_driver_match_device(dev, drv); /* Then try ACPI style match */ if (acpi_driver_match_device(dev, drv)) -- cgit v1.2.3-55-g7522 From 112d125a89479519efc437b2961b8d4a98761c1b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 15 Feb 2016 12:52:59 -0800 Subject: Revert "driver-core: platform: probe of-devices only using list of compatibles" This reverts commit 67d02a1bbb334558e9380409a3cd426b36d4578b This should reallow binding of of-devices by name. It turned out that there are valid reasons (e.g. step by step conversion to device tree probing using auxdata) to bind of-instantiated devices to drivers by name. So revert to the original logic. Reported-by: Guenter Roeck Acked-by: Uwe Kleine-König Cc: Thierry Reding Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org --- drivers/base/platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 1b5b7b5b50c0..f437afa17f2b 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -949,8 +949,8 @@ static int platform_match(struct device *dev, struct device_driver *drv) return !strcmp(pdev->driver_override, drv->name); /* Attempt an OF style match first */ - if (pdev->dev.of_node) - return of_driver_match_device(dev, drv); + if (of_driver_match_device(dev, drv)) + return 1; /* Then try ACPI style match */ if (acpi_driver_match_device(dev, drv)) -- cgit v1.2.3-55-g7522