From 8c60a14104e8e85f08b855e62ee8fe6947da2870 Mon Sep 17 00:00:00 2001 From: Julian Wiedmann Date: Wed, 12 May 2021 16:10:54 +0200 Subject: driver core: replace open-coded device_lock_assert() Using the right wrapper makes it easier to associate this assert statement with the device_[un]lock() helpers. Signed-off-by: Julian Wiedmann Link: https://lore.kernel.org/r/20210512141054.2180373-1-jwi@linux.ibm.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index 4a8bf8cda52b..bfa3536d48df 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3437,7 +3437,7 @@ bool kill_device(struct device *dev) * to run while we are tearing out the bus/class/sysfs from * underneath the device. */ - lockdep_assert_held(&dev->mutex); + device_lock_assert(dev); if (dev->p->dead) return false; -- cgit v1.2.3 From a6daf4bb5fcb893f7aa2a97e043ee11816743f81 Mon Sep 17 00:00:00 2001 From: Yang Yingliang Date: Wed, 12 May 2021 15:22:33 +0800 Subject: driver core: attribute_container: fix W=1 warnings Fix the following make W=1 kernel build warnings: drivers/base/attribute_container.c:304: warning: Function parameter or member 'fn' not described in 'attribute_container_device_trigger_safe' drivers/base/attribute_container.c:304: warning: Function parameter or member 'undo' not described in 'attribute_container_device_trigger_safe' drivers/base/attribute_container.c:357: warning: Function parameter or member 'fn' not described in 'attribute_container_device_trigger' Signed-off-by: Yang Yingliang Link: https://lore.kernel.org/r/20210512072233.3817056-1-yangyingliang@huawei.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/attribute_container.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c index 9c00d203d61e..01ef796c2055 100644 --- a/drivers/base/attribute_container.c +++ b/drivers/base/attribute_container.c @@ -284,8 +284,8 @@ fail: * matching classdev or fail all of them. * * @dev: The generic device to run the trigger for - * @fn the function to execute for each classdev. - * @undo A function to undo the work previously done in case of error + * @fn: the function to execute for each classdev. + * @undo: A function to undo the work previously done in case of error * * This function is a safe version of * attribute_container_device_trigger. It stops on the first error and @@ -343,7 +343,7 @@ attribute_container_device_trigger_safe(struct device *dev, * attribute_container_device_trigger - execute a trigger for each matching classdev * * @dev: The generic device to run the trigger for - * @fn the function to execute for each classdev. + * @fn: the function to execute for each classdev. * * This function is for executing a trigger when you need to know both * the container and the classdev. If you only care about the -- cgit v1.2.3 From fd03c075e362edc2ad637dfb5b945d304f80efe5 Mon Sep 17 00:00:00 2001 From: Ruiqi Gong Date: Fri, 14 May 2021 10:05:48 +0800 Subject: drivers/base/node.c: make CACHE_ATTR define static DEVICE_ATTR_RO Mark DEVICE_ATTR_RO(name) in CACHE_ATTR(name, fmt)'s definition as static to fix the following Sparse tool reports: drivers/base/node.c:239:1: warning: symbol 'dev_attr_line_size' was not declared. Should it be static? drivers/base/node.c:240:1: warning: symbol 'dev_attr_indexing' was not declared. Should it be static? Where dev_attr_{line_size,indexing} are generated by CACHE_ATTR's expansion. Reported-by: Hulk Robot Signed-off-by: Ruiqi Gong Link: https://lore.kernel.org/r/20210514020548.32483-1-gongruiqi1@huawei.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/node.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/node.c b/drivers/base/node.c index 2c36f61d30bc..6d0210357da3 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -233,7 +233,7 @@ static ssize_t name##_show(struct device *dev, \ return sysfs_emit(buf, fmt "\n", \ to_cache_info(dev)->cache_attrs.name); \ } \ -DEVICE_ATTR_RO(name); +static DEVICE_ATTR_RO(name); CACHE_ATTR(size, "%llu") CACHE_ATTR(line_size, "%u") -- cgit v1.2.3 From 7e7ba9b3d46d47e9f75cbf9d5392583a958a9807 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Tue, 18 May 2021 09:48:43 +0300 Subject: device property: Don't check for NULL twice in the loops In fwnode_get_next_available_child_node() we check next_child for NULL twice. All the same in fwnode_get_next_parent_dev() we may avoid checking fwnode for NULL twice. Signed-off-by: Andy Shevchenko Link: https://lore.kernel.org/r/20210518064843.3524015-1-andy.shevchenko@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/property.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/property.c b/drivers/base/property.c index 1421e9548857..2ad605eb3c31 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -627,14 +627,15 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_parent); */ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) { - struct device *dev = NULL; + struct device *dev; fwnode_handle_get(fwnode); do { fwnode = fwnode_get_next_parent(fwnode); - if (fwnode) - dev = get_dev_from_fwnode(fwnode); - } while (fwnode && !dev); + if (!fwnode) + return NULL; + dev = get_dev_from_fwnode(fwnode); + } while (!dev); fwnode_handle_put(fwnode); return dev; } @@ -742,10 +743,9 @@ fwnode_get_next_available_child_node(const struct fwnode_handle *fwnode, do { next_child = fwnode_get_next_child_node(fwnode, next_child); - - if (!next_child || fwnode_device_is_available(next_child)) - break; - } while (next_child); + if (!next_child) + return NULL; + } while (!fwnode_device_is_available(next_child)); return next_child; } -- cgit v1.2.3 From 82769cc671b6ddfc87654ff8169efdb3925a621b Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Wed, 19 May 2021 17:25:13 -0700 Subject: component: Drop 'dev' argument to component_match_realloc() This argument isn't used. Drop it. Cc: Daniel Vetter Cc: "Rafael J. Wysocki" Cc: Rob Clark Cc: Russell King Cc: Saravana Kannan Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20210520002519.3538432-2-swboyd@chromium.org Signed-off-by: Greg Kroah-Hartman --- drivers/base/component.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/component.c b/drivers/base/component.c index 272ba42392f0..bbe1757dfa89 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -307,8 +307,7 @@ static void devm_component_match_release(struct device *dev, void *res) component_match_release(dev, res); } -static int component_match_realloc(struct device *dev, - struct component_match *match, size_t num) +static int component_match_realloc(struct component_match *match, size_t num) { struct component_match_array *new; @@ -359,7 +358,7 @@ static void __component_match_add(struct device *master, size_t new_size = match->alloc + 16; int ret; - ret = component_match_realloc(master, match, new_size); + ret = component_match_realloc(match, new_size); if (ret) { *matchptr = ERR_PTR(ret); return; @@ -469,7 +468,7 @@ int component_master_add_with_match(struct device *dev, int ret; /* Reallocate the match array for its true size */ - ret = component_match_realloc(dev, match, match->num); + ret = component_match_realloc(match, match->num); if (ret) return ret; -- cgit v1.2.3 From d52ff34ee952b68c6d08eb56f2e99b926188f9e6 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Wed, 19 May 2021 17:25:14 -0700 Subject: component: Rename 'dev' to 'parent' Let's rename this struct member to 'parent' to better reflect the reality that it's the parent device of this psuedo-device. In the next patch we'll put a 'struct device' inside of this struct so moving this away simplifies that patch by reducing the number of places that 'dev' is modified. Cc: Daniel Vetter Cc: "Rafael J. Wysocki" Cc: Rob Clark Cc: Russell King Cc: Saravana Kannan Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20210520002519.3538432-3-swboyd@chromium.org Signed-off-by: Greg Kroah-Hartman --- drivers/base/component.c | 89 +++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 47 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/component.c b/drivers/base/component.c index bbe1757dfa89..5e79299f6c3f 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -63,7 +63,7 @@ struct master { bool bound; const struct component_master_ops *ops; - struct device *dev; + struct device *parent; struct component_match *match; }; @@ -95,7 +95,7 @@ static int component_devices_show(struct seq_file *s, void *data) seq_printf(s, "%-40s %20s\n", "master name", "status"); seq_puts(s, "-------------------------------------------------------------\n"); seq_printf(s, "%-40s %20s\n\n", - dev_name(m->dev), m->bound ? "bound" : "not bound"); + dev_name(m->parent), m->bound ? "bound" : "not bound"); seq_printf(s, "%-40s %20s\n", "device name", "status"); seq_puts(s, "-------------------------------------------------------------\n"); @@ -124,13 +124,13 @@ core_initcall(component_debug_init); static void component_master_debugfs_add(struct master *m) { - debugfs_create_file(dev_name(m->dev), 0444, component_debugfs_dir, m, + debugfs_create_file(dev_name(m->parent), 0444, component_debugfs_dir, m, &component_devices_fops); } static void component_master_debugfs_del(struct master *m) { - debugfs_remove(debugfs_lookup(dev_name(m->dev), component_debugfs_dir)); + debugfs_remove(debugfs_lookup(dev_name(m->parent), component_debugfs_dir)); } #else @@ -143,13 +143,13 @@ static void component_master_debugfs_del(struct master *m) #endif -static struct master *__master_find(struct device *dev, +static struct master *__master_find(struct device *parent, const struct component_master_ops *ops) { struct master *m; list_for_each_entry(m, &masters, node) - if (m->dev == dev && (!ops || m->ops == ops)) + if (m->parent == parent && (!ops || m->ops == ops)) return m; return NULL; @@ -189,7 +189,7 @@ static int find_components(struct master *master) struct component_match_array *mc = &match->compare[i]; struct component *c; - dev_dbg(master->dev, "Looking for component %zu\n", i); + dev_dbg(master->parent, "Looking for component %zu\n", i); if (match->compare[i].component) continue; @@ -200,7 +200,7 @@ static int find_components(struct master *master) break; } - dev_dbg(master->dev, "found component %s, duplicate %u\n", dev_name(c->dev), !!c->master); + dev_dbg(master->parent, "found component %s, duplicate %u\n", dev_name(c->dev), !!c->master); /* Attach this component to the master */ match->compare[i].duplicate = !!c->master; @@ -233,28 +233,28 @@ static int try_to_bring_up_master(struct master *master, { int ret; - dev_dbg(master->dev, "trying to bring up master\n"); + dev_dbg(master->parent, "trying to bring up master\n"); if (find_components(master)) { - dev_dbg(master->dev, "master has incomplete components\n"); + dev_dbg(master->parent, "master has incomplete components\n"); return 0; } if (component && component->master != master) { - dev_dbg(master->dev, "master is not for this component (%s)\n", + dev_dbg(master->parent, "master is not for this component (%s)\n", dev_name(component->dev)); return 0; } - if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) + if (!devres_open_group(master->parent, NULL, GFP_KERNEL)) return -ENOMEM; /* Found all components */ - ret = master->ops->bind(master->dev); + ret = master->ops->bind(master->parent); if (ret < 0) { - devres_release_group(master->dev, NULL); + devres_release_group(master->parent, NULL); if (ret != -EPROBE_DEFER) - dev_info(master->dev, "master bind failed: %d\n", ret); + dev_info(master->parent, "master bind failed: %d\n", ret); return ret; } @@ -281,32 +281,27 @@ static int try_to_bring_up_masters(struct component *component) static void take_down_master(struct master *master) { if (master->bound) { - master->ops->unbind(master->dev); - devres_release_group(master->dev, NULL); + master->ops->unbind(master->parent); + devres_release_group(master->parent, NULL); master->bound = false; } } -static void component_match_release(struct device *master, - struct component_match *match) +static void devm_component_match_release(struct device *parent, void *res) { + struct component_match *match = res; unsigned int i; for (i = 0; i < match->num; i++) { struct component_match_array *mc = &match->compare[i]; if (mc->release) - mc->release(master, mc->data); + mc->release(parent, mc->data); } kfree(match->compare); } -static void devm_component_match_release(struct device *dev, void *res) -{ - component_match_release(dev, res); -} - static int component_match_realloc(struct component_match *match, size_t num) { struct component_match_array *new; @@ -450,7 +445,7 @@ static void free_master(struct master *master) /** * component_master_add_with_match - register an aggregate driver - * @dev: device with the aggregate driver + * @parent: parent device of the aggregate driver * @ops: callbacks for the aggregate driver * @match: component match list for the aggregate driver * @@ -460,7 +455,7 @@ static void free_master(struct master *master) * &component_master_ops.bind from @ops. Must be unregistered by calling * component_master_del(). */ -int component_master_add_with_match(struct device *dev, +int component_master_add_with_match(struct device *parent, const struct component_master_ops *ops, struct component_match *match) { @@ -476,7 +471,7 @@ int component_master_add_with_match(struct device *dev, if (!master) return -ENOMEM; - master->dev = dev; + master->parent = parent; master->ops = ops; master->match = match; @@ -498,20 +493,20 @@ EXPORT_SYMBOL_GPL(component_master_add_with_match); /** * component_master_del - unregister an aggregate driver - * @dev: device with the aggregate driver + * @parent: parent device of the aggregate driver * @ops: callbacks for the aggregate driver * * Unregisters an aggregate driver registered with * component_master_add_with_match(). If necessary the aggregate driver is first * disassembled by calling &component_master_ops.unbind from @ops. */ -void component_master_del(struct device *dev, +void component_master_del(struct device *parent, const struct component_master_ops *ops) { struct master *master; mutex_lock(&component_mutex); - master = __master_find(dev, ops); + master = __master_find(parent, ops); if (master) { take_down_master(master); free_master(master); @@ -526,7 +521,7 @@ static void component_unbind(struct component *component, WARN_ON(!component->bound); if (component->ops && component->ops->unbind) - component->ops->unbind(component->dev, master->dev, data); + component->ops->unbind(component->dev, master->parent, data); component->bound = false; /* Release all resources claimed in the binding of this component */ @@ -535,14 +530,14 @@ static void component_unbind(struct component *component, /** * component_unbind_all - unbind all components of an aggregate driver - * @master_dev: device with the aggregate driver + * @parent: parent device of the aggregate driver * @data: opaque pointer, passed to all components * - * Unbinds all components of the aggregate @dev by passing @data to their + * Unbinds all components of the aggregate device by passing @data to their * &component_ops.unbind functions. Should be called from * &component_master_ops.unbind. */ -void component_unbind_all(struct device *master_dev, void *data) +void component_unbind_all(struct device *parent, void *data) { struct master *master; struct component *c; @@ -550,7 +545,7 @@ void component_unbind_all(struct device *master_dev, void *data) WARN_ON(!mutex_is_locked(&component_mutex)); - master = __master_find(master_dev, NULL); + master = __master_find(parent, NULL); if (!master) return; @@ -573,7 +568,7 @@ static int component_bind(struct component *component, struct master *master, * This allows us to roll-back a failed component without * affecting anything else. */ - if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) + if (!devres_open_group(master->parent, NULL, GFP_KERNEL)) return -ENOMEM; /* @@ -582,14 +577,14 @@ static int component_bind(struct component *component, struct master *master, * at the appropriate moment. */ if (!devres_open_group(component->dev, component, GFP_KERNEL)) { - devres_release_group(master->dev, NULL); + devres_release_group(master->parent, NULL); return -ENOMEM; } - dev_dbg(master->dev, "binding %s (ops %ps)\n", + dev_dbg(master->parent, "binding %s (ops %ps)\n", dev_name(component->dev), component->ops); - ret = component->ops->bind(component->dev, master->dev, data); + ret = component->ops->bind(component->dev, master->parent, data); if (!ret) { component->bound = true; @@ -600,16 +595,16 @@ static int component_bind(struct component *component, struct master *master, * can clean those resources up independently. */ devres_close_group(component->dev, NULL); - devres_remove_group(master->dev, NULL); + devres_remove_group(master->parent, NULL); - dev_info(master->dev, "bound %s (ops %ps)\n", + dev_info(master->parent, "bound %s (ops %ps)\n", dev_name(component->dev), component->ops); } else { devres_release_group(component->dev, NULL); - devres_release_group(master->dev, NULL); + devres_release_group(master->parent, NULL); if (ret != -EPROBE_DEFER) - dev_err(master->dev, "failed to bind %s (ops %ps): %d\n", + dev_err(master->parent, "failed to bind %s (ops %ps): %d\n", dev_name(component->dev), component->ops, ret); } @@ -618,14 +613,14 @@ static int component_bind(struct component *component, struct master *master, /** * component_bind_all - bind all components of an aggregate driver - * @master_dev: device with the aggregate driver + * @parent: parent device of the aggregate driver * @data: opaque pointer, passed to all components * * Binds all components of the aggregate @dev by passing @data to their * &component_ops.bind functions. Should be called from * &component_master_ops.bind. */ -int component_bind_all(struct device *master_dev, void *data) +int component_bind_all(struct device *parent, void *data) { struct master *master; struct component *c; @@ -634,7 +629,7 @@ int component_bind_all(struct device *master_dev, void *data) WARN_ON(!mutex_is_locked(&component_mutex)); - master = __master_find(master_dev, NULL); + master = __master_find(parent, NULL); if (!master) return -EINVAL; -- cgit v1.2.3 From 39b27e89a76f3827ad93aed9213a6daf2b91f819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Tue, 25 May 2021 12:37:11 +0200 Subject: driver core: Drop helper devm_platform_ioremap_resource_wc() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the macro was introduced in 2019 (commit bb6243b4f73d ("drivers: platform: provide devm_platform_ioremap_resource_wc()") there is only a single user which hardly justifies the function for the small task it provides. So drop the helper and open-code it in the only user. Adapt the non-wc case accordingly. For a all-mod-config build on amd64 this change introduces the following changes according to bloat-o-meter: add/remove: 0/1 grow/shrink: 1/0 up/down: 20/-252 (-232) Function old new delta devm_platform_ioremap_resource_wc 252 - -252 sram_probe 796 816 +20 Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20210525103711.956438-1-u.kleine-koenig@pengutronix.de Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 9cd34def2237..ae071e8ed665 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -124,26 +124,6 @@ void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev, } EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource); -/** - * devm_platform_ioremap_resource_wc - write-combined variant of - * devm_platform_ioremap_resource() - * - * @pdev: platform device to use both for memory resource lookup as well as - * resource management - * @index: resource index - * - * Return: a pointer to the remapped memory or an ERR_PTR() encoded error code - * on failure. - */ -void __iomem *devm_platform_ioremap_resource_wc(struct platform_device *pdev, - unsigned int index) -{ - struct resource *res; - - res = platform_get_resource(pdev, IORESOURCE_MEM, index); - return devm_ioremap_resource_wc(&pdev->dev, res); -} - /** * devm_platform_ioremap_resource_byname - call devm_ioremap_resource for * a platform device, retrieve the -- cgit v1.2.3 From 4e0c02431a71d4e9bd368320b389371df48d2e66 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 28 May 2021 10:03:14 +0200 Subject: devcoredump: remove contact information That email address hasn't existed for a long time, and the mailing address is pretty useless; remove all of this. Signed-off-by: Johannes Berg Link: https://lore.kernel.org/r/20210528100314.d419f6e8e2d2.Ica8076036c755d6f782becd62d04c41361323130@changeid Signed-off-by: Greg Kroah-Hartman --- drivers/base/devcoredump.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c index 8eec0e0ddff7..f4d794d6bb85 100644 --- a/drivers/base/devcoredump.c +++ b/drivers/base/devcoredump.c @@ -3,10 +3,6 @@ * Copyright(c) 2014 Intel Mobile Communications GmbH * Copyright(c) 2015 Intel Deutschland GmbH * - * Contact Information: - * Intel Linux Wireless - * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 - * * Author: Johannes Berg */ #include -- cgit v1.2.3 From 7f787701b2981d1a22f3951612fbb5a97ee658d3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 29 May 2021 02:34:03 +0900 Subject: firmware_loader: remove unneeded 'comma' macro Commit 553671b76859 ("firmware_loader: Fix labels with comma for builtin firmware") added this line, which was unneeded. The macro 'comma' is defined in scripts/Kbuild.include. Signed-off-by: Masahiro Yamada Link: https://lore.kernel.org/r/20210528173404.169764-1-masahiroy@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware_loader/builtin/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/firmware_loader/builtin/Makefile b/drivers/base/firmware_loader/builtin/Makefile index 5fa7ce3745a0..101754ad48d9 100644 --- a/drivers/base/firmware_loader/builtin/Makefile +++ b/drivers/base/firmware_loader/builtin/Makefile @@ -8,7 +8,6 @@ fwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir)) obj-y := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE))) FWNAME = $(patsubst $(obj)/%.gen.S,%,$@) -comma := , FWSTR = $(subst $(comma),_,$(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME))))) ASM_WORD = $(if $(CONFIG_64BIT),.quad,.long) ASM_ALIGN = $(if $(CONFIG_64BIT),3,2) -- cgit v1.2.3 From 5a576764e4190f7b48cf3cf40f4294f001918605 Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Fri, 28 May 2021 23:34:08 +0200 Subject: drivers/base: Constify static attribute_group structs These are only used by putting their address in an array of pointers to const struct attribute_group (either directly or via the __ATTRIBUTE_GROUP macro). Make them const to allow the compiler to place them in read-only memory. Signed-off-by: Rikard Falkeborn Link: https://lore.kernel.org/r/20210528213408.20067-1-rikard.falkeborn@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/cpu.c | 4 ++-- drivers/base/memory.c | 4 ++-- drivers/base/node.c | 2 +- drivers/base/platform.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 2b9e41377a07..5ef14db97904 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -175,7 +175,7 @@ static struct attribute *crash_note_cpu_attrs[] = { NULL }; -static struct attribute_group crash_note_cpu_attr_group = { +static const struct attribute_group crash_note_cpu_attr_group = { .attrs = crash_note_cpu_attrs, }; #endif @@ -475,7 +475,7 @@ static struct attribute *cpu_root_attrs[] = { NULL }; -static struct attribute_group cpu_root_attr_group = { +static const struct attribute_group cpu_root_attr_group = { .attrs = cpu_root_attrs, }; diff --git a/drivers/base/memory.c b/drivers/base/memory.c index b31b3af5c490..600ae518c02a 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -596,7 +596,7 @@ static struct attribute *memory_memblk_attrs[] = { NULL }; -static struct attribute_group memory_memblk_attr_group = { +static const struct attribute_group memory_memblk_attr_group = { .attrs = memory_memblk_attrs, }; @@ -772,7 +772,7 @@ static struct attribute *memory_root_attrs[] = { NULL }; -static struct attribute_group memory_root_attr_group = { +static const struct attribute_group memory_root_attr_group = { .attrs = memory_root_attrs, }; diff --git a/drivers/base/node.c b/drivers/base/node.c index 6d0210357da3..c4202bbb8af2 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -1036,7 +1036,7 @@ static struct attribute *node_state_attrs[] = { NULL }; -static struct attribute_group memory_root_attr_group = { +static const struct attribute_group memory_root_attr_group = { .attrs = node_state_attrs, }; diff --git a/drivers/base/platform.c b/drivers/base/platform.c index ae071e8ed665..8640578f45e9 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1335,7 +1335,7 @@ static umode_t platform_dev_attrs_visible(struct kobject *kobj, struct attribute return a->mode; } -static struct attribute_group platform_dev_group = { +static const struct attribute_group platform_dev_group = { .attrs = platform_dev_attrs, .is_visible = platform_dev_attrs_visible, }; -- cgit v1.2.3 From bbc8f3e79e9e35469ac87b0b3329729afc715885 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 17 May 2021 15:29:43 +0300 Subject: devres: Make locking straight forward in release_nodes() It seems for the sake of saving stack memory of couple of pointers, the locking in release_nodes() callers becomes interesting. Replace this logic with a straight forward locking and unlocking scheme. Signed-off-by: Andy Shevchenko Link: https://lore.kernel.org/r/20210517122946.53161-1-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/devres.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 8746f2212781..7970217191e0 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -503,28 +503,18 @@ static int remove_nodes(struct device *dev, return cnt; } -static int release_nodes(struct device *dev, struct list_head *first, - struct list_head *end, unsigned long flags) - __releases(&dev->devres_lock) +static void release_nodes(struct device *dev, struct list_head *todo) { - LIST_HEAD(todo); - int cnt; struct devres *dr, *tmp; - cnt = remove_nodes(dev, first, end, &todo); - - spin_unlock_irqrestore(&dev->devres_lock, flags); - /* Release. Note that both devres and devres_group are * handled as devres in the following loop. This is safe. */ - list_for_each_entry_safe_reverse(dr, tmp, &todo, node.entry) { + list_for_each_entry_safe_reverse(dr, tmp, todo, node.entry) { devres_log(dev, &dr->node, "REL"); dr->node.release(dev, dr->data); kfree(dr); } - - return cnt; } /** @@ -537,13 +527,19 @@ static int release_nodes(struct device *dev, struct list_head *first, int devres_release_all(struct device *dev) { unsigned long flags; + LIST_HEAD(todo); + int cnt; /* Looks like an uninitialized device structure */ if (WARN_ON(dev->devres_head.next == NULL)) return -ENODEV; + spin_lock_irqsave(&dev->devres_lock, flags); - return release_nodes(dev, dev->devres_head.next, &dev->devres_head, - flags); + cnt = remove_nodes(dev, dev->devres_head.next, &dev->devres_head, &todo); + spin_unlock_irqrestore(&dev->devres_lock, flags); + + release_nodes(dev, &todo); + return cnt; } /** @@ -679,6 +675,7 @@ int devres_release_group(struct device *dev, void *id) { struct devres_group *grp; unsigned long flags; + LIST_HEAD(todo); int cnt = 0; spin_lock_irqsave(&dev->devres_lock, flags); @@ -691,7 +688,10 @@ int devres_release_group(struct device *dev, void *id) if (!list_empty(&grp->node[1].entry)) end = grp->node[1].entry.next; - cnt = release_nodes(dev, first, end, flags); + cnt = remove_nodes(dev, first, end, &todo); + spin_unlock_irqrestore(&dev->devres_lock, flags); + + release_nodes(dev, &todo); } else { WARN_ON(1); spin_unlock_irqrestore(&dev->devres_lock, flags); -- cgit v1.2.3 From c3cd0ff7aa18a60229134fb8e467d5e1d92abec3 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 17 May 2021 15:29:44 +0300 Subject: devres: Use list_for_each_safe_from() in remove_nodes() The remove_nodes() open codes the list_for_each_safe_from(). Replace it by a generic macro. Signed-off-by: Andy Shevchenko Link: https://lore.kernel.org/r/20210517122946.53161-2-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/devres.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 7970217191e0..db1f3137fc81 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -438,20 +438,16 @@ static int remove_nodes(struct device *dev, struct list_head *first, struct list_head *end, struct list_head *todo) { + struct devres_node *node, *n; int cnt = 0, nr_groups = 0; - struct list_head *cur; /* First pass - move normal devres entries to @todo and clear * devres_group colors. */ - cur = first; - while (cur != end) { - struct devres_node *node; + node = list_entry(first, struct devres_node, entry); + list_for_each_entry_safe_from(node, n, end, entry) { struct devres_group *grp; - node = list_entry(cur, struct devres_node, entry); - cur = cur->next; - grp = node_to_group(node); if (grp) { /* clear color of group markers in the first pass */ @@ -471,18 +467,14 @@ static int remove_nodes(struct device *dev, /* Second pass - Scan groups and color them. A group gets * color value of two iff the group is wholly contained in - * [cur, end). That is, for a closed group, both opening and - * closing markers should be in the range, while just the + * [current node, end). That is, for a closed group, both opening + * and closing markers should be in the range, while just the * opening marker is enough for an open group. */ - cur = first; - while (cur != end) { - struct devres_node *node; + node = list_entry(first, struct devres_node, entry); + list_for_each_entry_safe_from(node, n, end, entry) { struct devres_group *grp; - node = list_entry(cur, struct devres_node, entry); - cur = cur->next; - grp = node_to_group(node); BUG_ON(!grp || list_empty(&grp->node[0].entry)); @@ -492,7 +484,7 @@ static int remove_nodes(struct device *dev, BUG_ON(grp->color <= 0 || grp->color > 2); if (grp->color == 2) { - /* No need to update cur or end. The removed + /* No need to update current node or end. The removed * nodes are always before both. */ list_move_tail(&grp->node[0].entry, todo); -- cgit v1.2.3 From a7f1d03b6046cf44f1dd702aeaad3b5e4d7b33a5 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 17 May 2021 15:29:45 +0300 Subject: devres: No need to call remove_nodes() when there none present If a list of devres nodes is empty, no need to call remove_nodes(). Signed-off-by: Andy Shevchenko Link: https://lore.kernel.org/r/20210517122946.53161-3-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/devres.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/devres.c b/drivers/base/devres.c index db1f3137fc81..dee48858663f 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -526,6 +526,10 @@ int devres_release_all(struct device *dev) if (WARN_ON(dev->devres_head.next == NULL)) return -ENODEV; + /* Nothing to release if list is empty */ + if (list_empty(&dev->devres_head)) + return 0; + spin_lock_irqsave(&dev->devres_lock, flags); cnt = remove_nodes(dev, dev->devres_head.next, &dev->devres_head, &todo); spin_unlock_irqrestore(&dev->devres_lock, flags); -- cgit v1.2.3 From 09705dcb63d269000595284b5dd7f5c938d647b9 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 17 May 2021 15:29:46 +0300 Subject: devres: Enable trace events In some cases the printf() mechanism is too heavy and can't be used. For example, when debugging a race condition involving devres API. When CONFIG_DEBUG_DEVRES is enabled I can't reproduce an issue, and otherwise it's quite visible with a useful information being collected. Enable trace events for devres part of the driver core. Signed-off-by: Andy Shevchenko Link: https://lore.kernel.org/r/20210517122946.53161-4-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/Makefile | 3 +++ drivers/base/devres.c | 47 ++++++++++++++++++------------------------ drivers/base/trace.c | 10 +++++++++ drivers/base/trace.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 27 deletions(-) create mode 100644 drivers/base/trace.c create mode 100644 drivers/base/trace.h (limited to 'drivers/base') diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 8b93a7f291ec..ef8e44a7d288 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -30,3 +30,6 @@ obj-y += test/ ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG +# define_trace.h needs to know how to find our header +CFLAGS_trace.o := -I$(src) +obj-$(CONFIG_TRACING) += trace.o diff --git a/drivers/base/devres.c b/drivers/base/devres.c index dee48858663f..eaa9a5cd1db9 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -14,14 +14,13 @@ #include #include "base.h" +#include "trace.h" struct devres_node { struct list_head entry; dr_release_t release; -#ifdef CONFIG_DEBUG_DEVRES const char *name; size_t size; -#endif }; struct devres { @@ -43,10 +42,6 @@ struct devres_group { /* -- 8 pointers */ }; -#ifdef CONFIG_DEBUG_DEVRES -static int log_devres = 0; -module_param_named(log, log_devres, int, S_IRUGO | S_IWUSR); - static void set_node_dbginfo(struct devres_node *node, const char *name, size_t size) { @@ -54,7 +49,11 @@ static void set_node_dbginfo(struct devres_node *node, const char *name, node->size = size; } -static void devres_log(struct device *dev, struct devres_node *node, +#ifdef CONFIG_DEBUG_DEVRES +static int log_devres = 0; +module_param_named(log, log_devres, int, S_IRUGO | S_IWUSR); + +static void devres_dbg(struct device *dev, struct devres_node *node, const char *op) { if (unlikely(log_devres)) @@ -62,10 +61,16 @@ static void devres_log(struct device *dev, struct devres_node *node, op, node, node->name, node->size); } #else /* CONFIG_DEBUG_DEVRES */ -#define set_node_dbginfo(node, n, s) do {} while (0) -#define devres_log(dev, node, op) do {} while (0) +#define devres_dbg(dev, node, op) do {} while (0) #endif /* CONFIG_DEBUG_DEVRES */ +static void devres_log(struct device *dev, struct devres_node *node, + const char *op) +{ + trace_devres_log(dev, op, node, node->name, node->size); + devres_dbg(dev, node, op); +} + /* * Release functions for devres group. These callbacks are used only * for identification. @@ -134,26 +139,13 @@ static void replace_dr(struct device *dev, list_replace(&old->entry, &new->entry); } -#ifdef CONFIG_DEBUG_DEVRES -void * __devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid, - const char *name) -{ - struct devres *dr; - - dr = alloc_dr(release, size, gfp | __GFP_ZERO, nid); - if (unlikely(!dr)) - return NULL; - set_node_dbginfo(&dr->node, name, size); - return dr->data; -} -EXPORT_SYMBOL_GPL(__devres_alloc_node); -#else /** - * devres_alloc_node - Allocate device resource data + * __devres_alloc_node - Allocate device resource data * @release: Release function devres will be associated with * @size: Allocation size * @gfp: Allocation flags * @nid: NUMA node + * @name: Name of the resource * * Allocate devres of @size bytes. The allocated area is zeroed, then * associated with @release. The returned pointer can be passed to @@ -162,17 +154,18 @@ EXPORT_SYMBOL_GPL(__devres_alloc_node); * RETURNS: * Pointer to allocated devres on success, NULL on failure. */ -void * devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid) +void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid, + const char *name) { struct devres *dr; dr = alloc_dr(release, size, gfp | __GFP_ZERO, nid); if (unlikely(!dr)) return NULL; + set_node_dbginfo(&dr->node, name, size); return dr->data; } -EXPORT_SYMBOL_GPL(devres_alloc_node); -#endif +EXPORT_SYMBOL_GPL(__devres_alloc_node); /** * devres_for_each_res - Resource iterator diff --git a/drivers/base/trace.c b/drivers/base/trace.c new file mode 100644 index 000000000000..b24b0a309c4a --- /dev/null +++ b/drivers/base/trace.c @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Device core Trace Support + * Copyright (C) 2021, Intel Corporation + * + * Author: Andy Shevchenko + */ + +#define CREATE_TRACE_POINTS +#include "trace.h" diff --git a/drivers/base/trace.h b/drivers/base/trace.h new file mode 100644 index 000000000000..3192e18f877e --- /dev/null +++ b/drivers/base/trace.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Device core Trace Support + * Copyright (C) 2021, Intel Corporation + * + * Author: Andy Shevchenko + */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM dev + +#if !defined(__DEV_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define __DEV_TRACE_H + +#include +#include +#include + +DECLARE_EVENT_CLASS(devres, + TP_PROTO(struct device *dev, const char *op, void *node, const char *name, size_t size), + TP_ARGS(dev, op, node, name, size), + TP_STRUCT__entry( + __string(devname, dev_name(dev)) + __field(struct device *, dev) + __field(const char *, op) + __field(void *, node) + __field(const char *, name) + __field(size_t, size) + ), + TP_fast_assign( + __assign_str(devname, dev_name(dev)); + __entry->op = op; + __entry->node = node; + __entry->name = name; + __entry->size = size; + ), + TP_printk("%s %3s %p %s (%zu bytes)", __get_str(devname), + __entry->op, __entry->node, __entry->name, __entry->size) +); + +DEFINE_EVENT(devres, devres_log, + TP_PROTO(struct device *dev, const char *op, void *node, const char *name, size_t size), + TP_ARGS(dev, op, node, name, size) +); + +#endif /* __DEV_TRACE_H */ + +/* this part has to be here */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE trace + +#include -- cgit v1.2.3