From 86df268705696ce2286410f1493e294e889bdce6 Mon Sep 17 00:00:00 2001 From: David Graham White Date: Sun, 21 Jul 2013 20:41:14 -0400 Subject: drivers:base:core: Moved sym export macros to respective functions Moved 11 calls to the EXPORT_SYMBOL_GPL beneath their respective functions per checkpatch.pl warnings. Signed-off-by: David Graham White Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index 8856d74545d9..4b9b0d7f6022 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -626,6 +626,7 @@ int device_create_file(struct device *dev, return error; } +EXPORT_SYMBOL_GPL(device_create_file); /** * device_remove_file - remove sysfs attribute file. @@ -638,6 +639,7 @@ void device_remove_file(struct device *dev, if (dev) sysfs_remove_file(&dev->kobj, &attr->attr); } +EXPORT_SYMBOL_GPL(device_remove_file); /** * device_create_bin_file - create sysfs binary attribute file for device. @@ -748,6 +750,7 @@ void device_initialize(struct device *dev) device_pm_init(dev); set_dev_node(dev, -1); } +EXPORT_SYMBOL_GPL(device_initialize); struct kobject *virtual_device_parent(struct device *dev) { @@ -1187,6 +1190,7 @@ name_error: dev->p = NULL; goto done; } +EXPORT_SYMBOL_GPL(device_add); /** * device_register - register a device with the system. @@ -1211,6 +1215,7 @@ int device_register(struct device *dev) device_initialize(dev); return device_add(dev); } +EXPORT_SYMBOL_GPL(device_register); /** * get_device - increment reference count for device. @@ -1224,6 +1229,7 @@ struct device *get_device(struct device *dev) { return dev ? kobj_to_dev(kobject_get(&dev->kobj)) : NULL; } +EXPORT_SYMBOL_GPL(get_device); /** * put_device - decrement reference count. @@ -1235,6 +1241,7 @@ void put_device(struct device *dev) if (dev) kobject_put(&dev->kobj); } +EXPORT_SYMBOL_GPL(put_device); /** * device_del - delete device from system. @@ -1297,6 +1304,7 @@ void device_del(struct device *dev) kobject_del(&dev->kobj); put_device(parent); } +EXPORT_SYMBOL_GPL(device_del); /** * device_unregister - unregister device from system. @@ -1315,6 +1323,7 @@ void device_unregister(struct device *dev) device_del(dev); put_device(dev); } +EXPORT_SYMBOL_GPL(device_unregister); static struct device *next_device(struct klist_iter *i) { @@ -1403,6 +1412,7 @@ int device_for_each_child(struct device *parent, void *data, klist_iter_exit(&i); return error; } +EXPORT_SYMBOL_GPL(device_for_each_child); /** * device_find_child - device iterator for locating a particular device. @@ -1437,6 +1447,7 @@ struct device *device_find_child(struct device *parent, void *data, klist_iter_exit(&i); return child; } +EXPORT_SYMBOL_GPL(device_find_child); int __init devices_init(void) { @@ -1464,21 +1475,6 @@ int __init devices_init(void) return -ENOMEM; } -EXPORT_SYMBOL_GPL(device_for_each_child); -EXPORT_SYMBOL_GPL(device_find_child); - -EXPORT_SYMBOL_GPL(device_initialize); -EXPORT_SYMBOL_GPL(device_add); -EXPORT_SYMBOL_GPL(device_register); - -EXPORT_SYMBOL_GPL(device_del); -EXPORT_SYMBOL_GPL(device_unregister); -EXPORT_SYMBOL_GPL(get_device); -EXPORT_SYMBOL_GPL(put_device); - -EXPORT_SYMBOL_GPL(device_create_file); -EXPORT_SYMBOL_GPL(device_remove_file); - static DEFINE_MUTEX(device_hotplug_lock); void lock_device_hotplug(void) -- cgit v1.2.3-59-g8ed1b From 34da5e6770ac06df770a0355b417155e6e84e263 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Fri, 26 Jul 2013 13:10:22 +0900 Subject: driver core: replace strict_strto*() with kstrto*() The usage of strict_strto*() is not preferred, because strict_strto*() is obsolete. Thus, kstrto*() should be used. Signed-off-by: Jingoo Han Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 2 +- drivers/base/memory.c | 4 ++-- drivers/base/power/sysfs.c | 2 +- drivers/base/regmap/regmap-debugfs.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index 4b9b0d7f6022..e51c78782933 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -38,7 +38,7 @@ long sysfs_deprecated = 0; #endif static __init int sysfs_deprecated_setup(char *arg) { - return strict_strtol(arg, 10, &sysfs_deprecated); + return kstrtol(arg, 10, &sysfs_deprecated); } early_param("sysfs.deprecated", sysfs_deprecated_setup); #endif diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 2b7813ec6d02..ddd14ce6654c 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -469,7 +469,7 @@ store_soft_offline_page(struct device *dev, u64 pfn; if (!capable(CAP_SYS_ADMIN)) return -EPERM; - if (strict_strtoull(buf, 0, &pfn) < 0) + if (kstrtoull(buf, 0, &pfn) < 0) return -EINVAL; pfn >>= PAGE_SHIFT; if (!pfn_valid(pfn)) @@ -488,7 +488,7 @@ store_hard_offline_page(struct device *dev, u64 pfn; if (!capable(CAP_SYS_ADMIN)) return -EPERM; - if (strict_strtoull(buf, 0, &pfn) < 0) + if (kstrtoull(buf, 0, &pfn) < 0) return -EINVAL; pfn >>= PAGE_SHIFT; ret = memory_failure(pfn, 0, 0); diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index a53ebd265701..03e089ade5ce 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c @@ -206,7 +206,7 @@ static ssize_t autosuspend_delay_ms_store(struct device *dev, if (!dev->power.use_autosuspend) return -EIO; - if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay) + if (kstrtol(buf, 10, &delay) != 0 || delay != (int) delay) return -EINVAL; device_lock(dev); diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 53495753fbdb..634164da9c15 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -281,7 +281,7 @@ static ssize_t regmap_map_write_file(struct file *file, reg = simple_strtoul(start, &start, 16); while (*start == ' ') start++; - if (strict_strtoul(start, 16, &value)) + if (kstrtoul(start, 16, &value)) return -EINVAL; /* Userspace has been fiddling around behind the kernel's back */ -- cgit v1.2.3-59-g8ed1b From 29f1953d51faa3995192ba4ccff3b71c661940c2 Mon Sep 17 00:00:00 2001 From: Hanjun Guo Date: Sat, 27 Jul 2013 11:00:49 +0800 Subject: cpu topology: remove stale arch_provides_topology_pointers and define_siblings_show_map/list() arch_provides_topology_pointers was introduced in commit 23ca4bba3 (x86: cleanup early per cpu variables/accesses v4) to indicate pointers to the topology cpumask_t maps are valid to avoid copying data on to/off of the stack. But later in commit fbd59a8d (cpumask: Use topology_core_cpumask()/ topology_thread_cpumask()), the pointers to the topology struct cpumask maps are always valid. After that commit, the only difference is that there is a redundant "unsigned int cpu = dev->id;" if arch_provides_topology_pointers defined, but dev->id is type 'u32' which devolves to 'unsigned int' on all supported arches. So this arch_provides_topology_pointers define is pointless and only cause obfuscation now, remove it. Tested on x86 machine, topology information in sys/devices/system/cpu/ cpuX/topology/ is the same after appling this patch set. Signed-off-by: Hanjun Guo Signed-off-by: Greg Kroah-Hartman --- drivers/base/topology.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/topology.c b/drivers/base/topology.c index 2f5919ed91ab..94ffee378f10 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c @@ -62,25 +62,6 @@ static ssize_t show_cpumap(int type, const struct cpumask *mask, char *buf) } #endif -#ifdef arch_provides_topology_pointers -#define define_siblings_show_map(name) \ -static ssize_t show_##name(struct device *dev, \ - struct device_attribute *attr, char *buf) \ -{ \ - unsigned int cpu = dev->id; \ - return show_cpumap(0, topology_##name(cpu), buf); \ -} - -#define define_siblings_show_list(name) \ -static ssize_t show_##name##_list(struct device *dev, \ - struct device_attribute *attr, \ - char *buf) \ -{ \ - unsigned int cpu = dev->id; \ - return show_cpumap(1, topology_##name(cpu), buf); \ -} - -#else #define define_siblings_show_map(name) \ static ssize_t show_##name(struct device *dev, \ struct device_attribute *attr, char *buf) \ @@ -95,7 +76,6 @@ static ssize_t show_##name##_list(struct device *dev, \ { \ return show_cpumap(1, topology_##name(dev->id), buf); \ } -#endif #define define_siblings_show_func(name) \ define_siblings_show_map(name); define_siblings_show_list(name) -- cgit v1.2.3-59-g8ed1b From fa6fdb33b486a8afc5439c504da8d581e142c77d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Aug 2013 15:22:55 -0700 Subject: driver core: bus_type: add dev_groups attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add dev_groups to struct bus_type which should be used instead of dev_attrs. dev_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 5 +++++ drivers/base/bus.c | 6 ++++++ drivers/base/core.c | 7 +++---- include/linux/device.h | 4 +++- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/base.h b/drivers/base/base.h index b8bdfe61daa6..fccf954f82fd 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -119,6 +119,11 @@ static inline int driver_match_device(struct device_driver *drv, return drv->bus->match ? drv->bus->match(dev, drv) : 1; } +extern int device_add_groups(struct device *dev, + const struct attribute_group **groups); +extern void device_remove_groups(struct device *dev, + const struct attribute_group **groups); + extern char *make_class_name(const char *name, struct kobject *kobj); extern int devres_release_all(struct device *dev); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index d414331b480e..7b2dc5ba7d79 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -499,6 +499,9 @@ int bus_add_device(struct device *dev) error = device_add_attrs(bus, dev); if (error) goto out_put; + error = device_add_groups(dev, bus->dev_groups); + if (error) + goto out_groups; error = sysfs_create_link(&bus->p->devices_kset->kobj, &dev->kobj, dev_name(dev)); if (error) @@ -513,6 +516,8 @@ int bus_add_device(struct device *dev) out_subsys: sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); +out_groups: + device_remove_groups(dev, bus->dev_groups); out_id: device_remove_attrs(bus, dev); out_put: @@ -575,6 +580,7 @@ void bus_remove_device(struct device *dev) sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev_name(dev)); device_remove_attrs(dev->bus, dev); + device_remove_groups(dev, dev->bus->dev_groups); if (klist_node_attached(&dev->p->knode_bus)) klist_del(&dev->p->knode_bus); diff --git a/drivers/base/core.c b/drivers/base/core.c index e51c78782933..09a99d609644 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -491,8 +491,7 @@ static void device_remove_bin_attributes(struct device *dev, device_remove_bin_file(dev, &attrs[i]); } -static int device_add_groups(struct device *dev, - const struct attribute_group **groups) +int device_add_groups(struct device *dev, const struct attribute_group **groups) { int error = 0; int i; @@ -511,8 +510,8 @@ static int device_add_groups(struct device *dev, return error; } -static void device_remove_groups(struct device *dev, - const struct attribute_group **groups) +void device_remove_groups(struct device *dev, + const struct attribute_group **groups) { int i; diff --git a/include/linux/device.h b/include/linux/device.h index 22b546a58591..3aec4a68b1d4 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -66,6 +66,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @bus_attrs: Default attributes of the bus. * @dev_attrs: Default attributes of the devices on the bus. * @drv_attrs: Default attributes of the device drivers on the bus. + * @dev_groups: Default attributes of the devices on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver * is added for this bus. It should return a nonzero value if the * given device can be handled by the given driver. @@ -104,8 +105,9 @@ struct bus_type { const char *dev_name; struct device *dev_root; struct bus_attribute *bus_attrs; - struct device_attribute *dev_attrs; + struct device_attribute *dev_attrs; /* use dev_groups instead */ struct driver_attribute *drv_attrs; + const struct attribute_group **dev_groups; int (*match)(struct device *dev, struct device_driver *drv); int (*uevent)(struct device *dev, struct kobj_uevent_env *env); -- cgit v1.2.3-59-g8ed1b From ed0617b5c0bcd7fd04053568aa0cc19a977a1f26 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Aug 2013 15:22:56 -0700 Subject: driver core: bus_type: add drv_groups attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add drv_groups to struct bus_type which should be used instead of drv_attrs. drv_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 5 +++++ drivers/base/bus.c | 5 +++++ drivers/base/driver.c | 8 ++++---- include/linux/device.h | 4 +++- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/base.h b/drivers/base/base.h index fccf954f82fd..2cbc6774f4cd 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -119,6 +119,11 @@ static inline int driver_match_device(struct device_driver *drv, return drv->bus->match ? drv->bus->match(dev, drv) : 1; } +extern int driver_add_groups(struct device_driver *drv, + const struct attribute_group **groups); +extern void driver_remove_groups(struct device_driver *drv, + const struct attribute_group **groups); + extern int device_add_groups(struct device *dev, const struct attribute_group **groups); extern void device_remove_groups(struct device *dev, diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 7b2dc5ba7d79..de5ce22df306 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -725,6 +725,10 @@ int bus_add_driver(struct device_driver *drv) printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", __func__, drv->name); } + error = driver_add_groups(drv, bus->drv_groups); + if (error) + printk(KERN_ERR "%s: driver_create_groups(%s) failed\n", + __func__, drv->name); if (!drv->suppress_bind_attrs) { error = add_bind_files(drv); @@ -762,6 +766,7 @@ void bus_remove_driver(struct device_driver *drv) if (!drv->suppress_bind_attrs) remove_bind_files(drv); driver_remove_attrs(drv->bus, drv); + driver_remove_groups(drv, drv->bus->drv_groups); driver_remove_file(drv, &driver_attr_uevent); klist_remove(&drv->p->knode_bus); pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 974e301a1ef0..89db726ebb98 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -123,8 +123,8 @@ void driver_remove_file(struct device_driver *drv, } EXPORT_SYMBOL_GPL(driver_remove_file); -static int driver_add_groups(struct device_driver *drv, - const struct attribute_group **groups) +int driver_add_groups(struct device_driver *drv, + const struct attribute_group **groups) { int error = 0; int i; @@ -143,8 +143,8 @@ static int driver_add_groups(struct device_driver *drv, return error; } -static void driver_remove_groups(struct device_driver *drv, - const struct attribute_group **groups) +void driver_remove_groups(struct device_driver *drv, + const struct attribute_group **groups) { int i; diff --git a/include/linux/device.h b/include/linux/device.h index 3aec4a68b1d4..94d987f128bb 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -67,6 +67,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @dev_attrs: Default attributes of the devices on the bus. * @drv_attrs: Default attributes of the device drivers on the bus. * @dev_groups: Default attributes of the devices on the bus. + * @drv_groups: Default attributes of the device drivers on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver * is added for this bus. It should return a nonzero value if the * given device can be handled by the given driver. @@ -106,8 +107,9 @@ struct bus_type { struct device *dev_root; struct bus_attribute *bus_attrs; struct device_attribute *dev_attrs; /* use dev_groups instead */ - struct driver_attribute *drv_attrs; + struct driver_attribute *drv_attrs; /* use drv_groups instead */ const struct attribute_group **dev_groups; + const struct attribute_group **drv_groups; int (*match)(struct device *dev, struct device_driver *drv); int (*uevent)(struct device *dev, struct kobj_uevent_env *env); -- cgit v1.2.3-59-g8ed1b From 12478ba077adf8b53be6101b80dd8a65e4df9ea6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Aug 2013 15:22:57 -0700 Subject: driver core: bus_type: add bus_groups attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add bus_groups to struct bus_type which should be used instead of bus_attrs. bus_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/device.h | 4 +++- 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index de5ce22df306..5ee5d3c1d74b 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -881,6 +881,37 @@ static void bus_remove_attrs(struct bus_type *bus) } } +static int bus_add_groups(struct bus_type *bus, + const struct attribute_group **groups) +{ + int error = 0; + int i; + + if (groups) { + for (i = 0; groups[i]; i++) { + error = sysfs_create_group(&bus->p->subsys.kobj, + groups[i]); + if (error) { + while (--i >= 0) + sysfs_remove_group(&bus->p->subsys.kobj, + groups[i]); + break; + } + } + } + return error; +} + +static void bus_remove_groups(struct bus_type *bus, + const struct attribute_group **groups) +{ + int i; + + if (groups) + for (i = 0; groups[i]; i++) + sysfs_remove_group(&bus->p->subsys.kobj, groups[i]); +} + static void klist_devices_get(struct klist_node *n) { struct device_private *dev_prv = to_device_private_bus(n); @@ -973,10 +1004,15 @@ int bus_register(struct bus_type *bus) retval = bus_add_attrs(bus); if (retval) goto bus_attrs_fail; + retval = bus_add_groups(bus, bus->bus_groups); + if (retval) + goto bus_groups_fail; pr_debug("bus: '%s': registered\n", bus->name); return 0; +bus_groups_fail: + bus_remove_attrs(bus); bus_attrs_fail: remove_probe_files(bus); bus_probe_files_fail: @@ -1007,6 +1043,7 @@ void bus_unregister(struct bus_type *bus) if (bus->dev_root) device_unregister(bus->dev_root); bus_remove_attrs(bus); + bus_remove_groups(bus, bus->bus_groups); remove_probe_files(bus); kset_unregister(bus->p->drivers_kset); kset_unregister(bus->p->devices_kset); diff --git a/include/linux/device.h b/include/linux/device.h index 94d987f128bb..26e23b22ed0a 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -66,6 +66,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @bus_attrs: Default attributes of the bus. * @dev_attrs: Default attributes of the devices on the bus. * @drv_attrs: Default attributes of the device drivers on the bus. + * @bus_groups: Default attributes of the bus. * @dev_groups: Default attributes of the devices on the bus. * @drv_groups: Default attributes of the device drivers on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver @@ -105,9 +106,10 @@ struct bus_type { const char *name; const char *dev_name; struct device *dev_root; - struct bus_attribute *bus_attrs; + struct bus_attribute *bus_attrs; /* use bus_groups instead */ struct device_attribute *dev_attrs; /* use dev_groups instead */ struct driver_attribute *drv_attrs; /* use drv_groups instead */ + const struct attribute_group **bus_groups; const struct attribute_group **dev_groups; const struct attribute_group **drv_groups; -- cgit v1.2.3-59-g8ed1b From c7991b0b720efa5e0a590f6359d36e09bd187b76 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 13 Aug 2013 02:39:30 +0200 Subject: driver core / cpu: Check if NUMA node is valid before bringing CPU up There is a potential race condition between cpu_subsys_online() and either acpi_processor_remove() or remove_memory() that execute try_offline_node(). Namely, it is possible that cpu_subsys_online() will run right after the CPUs NUMA node has been put offline and cpu_to_node() executed by it will return NUMA_NO_NODE (-1). In that case the CPU is gone and it doesn't make sense to call cpu_up() for it, so make cpu_subsys_online() return -ENODEV then. Signed-off-by: Rafael J. Wysocki Acked-by: Toshi Kani Signed-off-by: Greg Kroah-Hartman --- drivers/base/cpu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 4c358bc44c72..6bfaaca6955e 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -43,11 +43,14 @@ static int __ref cpu_subsys_online(struct device *dev) struct cpu *cpu = container_of(dev, struct cpu, dev); int cpuid = dev->id; int from_nid, to_nid; - int ret; + int ret = -ENODEV; cpu_hotplug_driver_lock(); from_nid = cpu_to_node(cpuid); + if (from_nid == NUMA_NO_NODE) + goto out; + ret = cpu_up(cpuid); /* * When hot adding memory to memoryless node and enabling a cpu @@ -57,6 +60,7 @@ static int __ref cpu_subsys_online(struct device *dev) if (from_nid != to_nid) change_cpu_under_node(cpu, from_nid, to_nid); + out: cpu_hotplug_driver_unlock(); return ret; } -- cgit v1.2.3-59-g8ed1b From 3454bf96041e8c4cecc7d85b87c35056050a15b5 Mon Sep 17 00:00:00 2001 From: Hanjun Guo Date: Sat, 17 Aug 2013 20:42:24 +0800 Subject: drivers / base: Fix sysfs_deprecated_setup() __init attribute location __init belongs after the return type on functions, not before it. Signed-off-by: Hanjun Guo 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 09a99d609644..af646afa5b7e 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -36,7 +36,7 @@ long sysfs_deprecated = 1; #else long sysfs_deprecated = 0; #endif -static __init int sysfs_deprecated_setup(char *arg) +static int __init sysfs_deprecated_setup(char *arg) { return kstrtol(arg, 10, &sysfs_deprecated); } -- cgit v1.2.3-59-g8ed1b From a82579106c79484a5ea0c4c424c8860648c2e389 Mon Sep 17 00:00:00 2001 From: Hanjun Guo Date: Sat, 17 Aug 2013 20:42:25 +0800 Subject: drivers / platform: Fix __init attribute location __init belongs after the return type on functions, not before it. Signed-off-by: Hanjun Guo 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 3c3197a8de41..9d538cf9204a 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1054,7 +1054,7 @@ void __init early_platform_driver_register_all(char *class_str) * @epdrv: early platform driver structure * @id: id to match against */ -static __init struct platform_device * +static struct platform_device * __init early_platform_match(struct early_platform_driver *epdrv, int id) { struct platform_device *pd; @@ -1072,7 +1072,7 @@ early_platform_match(struct early_platform_driver *epdrv, int id) * @epdrv: early platform driver structure * @id: return true if id or above exists */ -static __init int early_platform_left(struct early_platform_driver *epdrv, +static int __init early_platform_left(struct early_platform_driver *epdrv, int id) { struct platform_device *pd; -- cgit v1.2.3-59-g8ed1b From cebcac7c59e812d17237c13405aa6886199a1b90 Mon Sep 17 00:00:00 2001 From: Hanjun Guo Date: Sat, 17 Aug 2013 20:42:26 +0800 Subject: drivers / dma-contiguous: Fix __init attribute location __init belongs after the return type on functions, not before it. Signed-off-by: Hanjun Guo Signed-off-by: Greg Kroah-Hartman --- drivers/base/dma-contiguous.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index 0ca54421ce97..6c9cdaa9200d 100644 --- a/drivers/base/dma-contiguous.c +++ b/drivers/base/dma-contiguous.c @@ -134,7 +134,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit) static DEFINE_MUTEX(cma_mutex); -static __init int cma_activate_area(unsigned long base_pfn, unsigned long count) +static int __init cma_activate_area(unsigned long base_pfn, unsigned long count) { unsigned long pfn = base_pfn; unsigned i = count >> pageblock_order; @@ -156,7 +156,7 @@ static __init int cma_activate_area(unsigned long base_pfn, unsigned long count) return 0; } -static __init struct cma *cma_create_area(unsigned long base_pfn, +static struct cma * __init cma_create_area(unsigned long base_pfn, unsigned long count) { int bitmap_size = BITS_TO_LONGS(count) * sizeof(long); -- cgit v1.2.3-59-g8ed1b From b1eaef3da5a7bbc48fa9dbefaa2a28e45367fdb1 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:12:57 -0500 Subject: drivers: base: move mutex lock out of add_memory_section() There is no point in releasing the mutex for each section that is added during boot time. Just hold it over the entire initialization loop. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index ddd14ce6654c..ed3ada244a07 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -613,8 +613,6 @@ static int add_memory_section(int nid, struct mem_section *section, int scn_nr = __section_nr(section); int ret = 0; - mutex_lock(&mem_sysfs_mutex); - if (context == BOOT) { /* same memory block ? */ if (mem_p && *mem_p) @@ -643,7 +641,6 @@ static int add_memory_section(int nid, struct mem_section *section, ret = register_mem_sect_under_node(mem, nid); } - mutex_unlock(&mem_sysfs_mutex); return ret; } @@ -653,7 +650,13 @@ static int add_memory_section(int nid, struct mem_section *section, */ int register_new_memory(int nid, struct mem_section *section) { - return add_memory_section(nid, section, NULL, MEM_OFFLINE, HOTPLUG); + int ret; + + mutex_lock(&mem_sysfs_mutex); + ret = add_memory_section(nid, section, NULL, MEM_OFFLINE, HOTPLUG); + mutex_unlock(&mem_sysfs_mutex); + + return ret; } #ifdef CONFIG_MEMORY_HOTREMOVE @@ -746,6 +749,7 @@ int __init memory_dev_init(void) * Create entries for memory sections that were found * during boot and have been initialized */ + mutex_lock(&mem_sysfs_mutex); for (i = 0; i < NR_MEM_SECTIONS; i++) { if (!present_section_nr(i)) continue; @@ -757,6 +761,7 @@ int __init memory_dev_init(void) if (!ret) ret = err; } + mutex_unlock(&mem_sysfs_mutex); out: if (ret) -- cgit v1.2.3-59-g8ed1b From 879f1bec8e136c7bc71e38715e62a73b75f91d78 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:12:58 -0500 Subject: drivers: base: remove unneeded variable The error variable is not needed. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index ed3ada244a07..b31d998a63a5 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -565,16 +565,13 @@ static const struct attribute_group *memory_memblk_attr_groups[] = { static int register_memory(struct memory_block *memory) { - int error; - memory->dev.bus = &memory_subsys; memory->dev.id = memory->start_section_nr / sections_per_block; memory->dev.release = memory_block_release; memory->dev.groups = memory_memblk_attr_groups; memory->dev.offline = memory->state == MEM_OFFLINE; - error = device_register(&memory->dev); - return error; + return device_register(&memory->dev); } static int init_memory_block(struct memory_block **memory, -- cgit v1.2.3-59-g8ed1b From df2b717c667d2cab37d1bbd585e891f10ed2bca4 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:12:59 -0500 Subject: drivers: base: use device get/put functions Use the [get|put]_device functions for ref'ing the memory block device rather than the kobject functions which should be hidden away by the device layer. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index b31d998a63a5..e97519bc3d06 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -616,14 +616,14 @@ static int add_memory_section(int nid, struct mem_section *section, if (scn_nr >= (*mem_p)->start_section_nr && scn_nr <= (*mem_p)->end_section_nr) { mem = *mem_p; - kobject_get(&mem->dev.kobj); + get_device(&mem->dev); } } else mem = find_memory_block(section); if (mem) { mem->section_count++; - kobject_put(&mem->dev.kobj); + put_device(&mem->dev); } else { ret = init_memory_block(&mem, section, state); /* store memory_block pointer for next loop */ @@ -663,7 +663,7 @@ unregister_memory(struct memory_block *memory) BUG_ON(memory->dev.bus != &memory_subsys); /* drop the ref. we got in remove_memory_block() */ - kobject_put(&memory->dev.kobj); + put_device(&memory->dev); device_unregister(&memory->dev); } @@ -680,7 +680,7 @@ static int remove_memory_block(unsigned long node_id, if (mem->section_count == 0) unregister_memory(mem); else - kobject_put(&mem->dev.kobj); + put_device(&mem->dev); mutex_unlock(&mem_sysfs_mutex); return 0; -- cgit v1.2.3-59-g8ed1b From d7f80530ad0a71615f54607128c30d2422bf4c02 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:13:00 -0500 Subject: drivers: base: unshare add_memory_section() from hotplug add_memory_section() is currently called from both boot time and run time via hotplug and there is a lot of nastiness to allow for shared code including an enum parameter to convey the calling context to add_memory_section(). This patch is the first step in breaking up the messy code sharing by pulling the hotplug path for add_memory_section() directly into register_new_memory(). Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index e97519bc3d06..2e9a68c64679 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -647,12 +647,25 @@ static int add_memory_section(int nid, struct mem_section *section, */ int register_new_memory(int nid, struct mem_section *section) { - int ret; + int ret = 0; + struct memory_block *mem; mutex_lock(&mem_sysfs_mutex); - ret = add_memory_section(nid, section, NULL, MEM_OFFLINE, HOTPLUG); - mutex_unlock(&mem_sysfs_mutex); + mem = find_memory_block(section); + if (mem) { + mem->section_count++; + put_device(&mem->dev); + } else { + ret = init_memory_block(&mem, section, MEM_OFFLINE); + if (ret) + goto out; + } + + if (mem->section_count == sections_per_block) + ret = register_mem_sect_under_node(mem, nid); +out: + mutex_unlock(&mem_sysfs_mutex); return ret; } -- cgit v1.2.3-59-g8ed1b From 37a7bd6255b415afe197489b5cd1f9568a7ae058 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:13:01 -0500 Subject: drivers: base: reduce add_memory_section() for boot-time only Now that add_memory_section() is only called from boot time, reduce the logic and remove the enum. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 41 ++++++++++++++--------------------------- include/linux/memory.h | 1 - 2 files changed, 14 insertions(+), 28 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 2e9a68c64679..a9e9c0902cce 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -602,40 +602,29 @@ static int init_memory_block(struct memory_block **memory, return ret; } -static int add_memory_section(int nid, struct mem_section *section, - struct memory_block **mem_p, - unsigned long state, enum mem_add_context context) +static int add_memory_section(struct mem_section *section, + struct memory_block **mem_p) { struct memory_block *mem = NULL; int scn_nr = __section_nr(section); int ret = 0; - if (context == BOOT) { - /* same memory block ? */ - if (mem_p && *mem_p) - if (scn_nr >= (*mem_p)->start_section_nr && - scn_nr <= (*mem_p)->end_section_nr) { - mem = *mem_p; - get_device(&mem->dev); - } - } else - mem = find_memory_block(section); + if (mem_p && *mem_p) { + if (scn_nr >= (*mem_p)->start_section_nr && + scn_nr <= (*mem_p)->end_section_nr) { + mem = *mem_p; + get_device(&mem->dev); + } + } if (mem) { mem->section_count++; put_device(&mem->dev); } else { - ret = init_memory_block(&mem, section, state); + ret = init_memory_block(&mem, section, MEM_ONLINE); /* store memory_block pointer for next loop */ - if (!ret && context == BOOT) - if (mem_p) - *mem_p = mem; - } - - if (!ret) { - if (context == HOTPLUG && - mem->section_count == sections_per_block) - ret = register_mem_sect_under_node(mem, nid); + if (!ret && mem_p) + *mem_p = mem; } return ret; @@ -764,10 +753,8 @@ int __init memory_dev_init(void) if (!present_section_nr(i)) continue; /* don't need to reuse memory_block if only one per block */ - err = add_memory_section(0, __nr_to_section(i), - (sections_per_block == 1) ? NULL : &mem, - MEM_ONLINE, - BOOT); + err = add_memory_section(__nr_to_section(i), + (sections_per_block == 1) ? NULL : &mem); if (!ret) ret = err; } diff --git a/include/linux/memory.h b/include/linux/memory.h index 85c31a8e2904..4c89fb0c8f4c 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -125,7 +125,6 @@ extern struct memory_block *find_memory_block_hinted(struct mem_section *, struct memory_block *); extern struct memory_block *find_memory_block(struct mem_section *); #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< Date: Tue, 20 Aug 2013 12:13:02 -0500 Subject: drivers: base: remove improper get/put in add_memory_section() The path through add_memory_section() when the memory block already exists uses flawed refcounting logic. A get_device() is done on a memory block using a pointer that might not be valid as we dropped our previous reference and didn't obtain a new reference in the proper way. Lets stop pretending and just remove the get/put. The mem_sysfs_mutex, which we hold over the entire init loop now, will prevent the memory blocks from disappearing from under us. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index a9e9c0902cce..9438d541b5c3 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -613,14 +613,12 @@ static int add_memory_section(struct mem_section *section, if (scn_nr >= (*mem_p)->start_section_nr && scn_nr <= (*mem_p)->end_section_nr) { mem = *mem_p; - get_device(&mem->dev); } } - if (mem) { + if (mem) mem->section_count++; - put_device(&mem->dev); - } else { + else { ret = init_memory_block(&mem, section, MEM_ONLINE); /* store memory_block pointer for next loop */ if (!ret && mem_p) -- cgit v1.2.3-59-g8ed1b From cb5e39b8038be913030a7b01d4396cfa5f9ded7b Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:13:03 -0500 Subject: drivers: base: refactor add_memory_section() to add_memory_block() Right now memory_dev_init() maintains the memory block pointer between iterations of add_memory_section(). This is nasty. This patch refactors add_memory_section() to become add_memory_block(). The refactoring pulls the section scanning out of memory_dev_init() and simplifies the signature. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 9438d541b5c3..0187fe483d7c 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -602,32 +602,31 @@ static int init_memory_block(struct memory_block **memory, return ret; } -static int add_memory_section(struct mem_section *section, - struct memory_block **mem_p) +static int add_memory_block(int base_section_nr) { - struct memory_block *mem = NULL; - int scn_nr = __section_nr(section); - int ret = 0; - - if (mem_p && *mem_p) { - if (scn_nr >= (*mem_p)->start_section_nr && - scn_nr <= (*mem_p)->end_section_nr) { - mem = *mem_p; - } - } + struct memory_block *mem; + int i, ret, section_count = 0, section_nr; - if (mem) - mem->section_count++; - else { - ret = init_memory_block(&mem, section, MEM_ONLINE); - /* store memory_block pointer for next loop */ - if (!ret && mem_p) - *mem_p = mem; + for (i = base_section_nr; + (i < base_section_nr + sections_per_block) && i < NR_MEM_SECTIONS; + i++) { + if (!present_section_nr(i)) + continue; + if (section_count == 0) + section_nr = i; + section_count++; } - return ret; + if (section_count == 0) + return 0; + ret = init_memory_block(&mem, __nr_to_section(section_nr), MEM_ONLINE); + if (ret) + return ret; + mem->section_count = section_count; + return 0; } + /* * need an interface for the VM to add new memory regions, * but without onlining it. @@ -733,7 +732,6 @@ int __init memory_dev_init(void) int ret; int err; unsigned long block_sz; - struct memory_block *mem = NULL; ret = subsys_system_register(&memory_subsys, memory_root_attr_groups); if (ret) @@ -747,12 +745,8 @@ int __init memory_dev_init(void) * during boot and have been initialized */ mutex_lock(&mem_sysfs_mutex); - for (i = 0; i < NR_MEM_SECTIONS; i++) { - if (!present_section_nr(i)) - continue; - /* don't need to reuse memory_block if only one per block */ - err = add_memory_section(__nr_to_section(i), - (sections_per_block == 1) ? NULL : &mem); + for (i = 0; i < NR_MEM_SECTIONS; i += sections_per_block) { + err = add_memory_block(i); if (!ret) ret = err; } -- cgit v1.2.3-59-g8ed1b From fa2be40fe7c0aa3b7accbf6dfa9ef0976e191d4c Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 16:05:05 -0500 Subject: drivers: base: use standard device online/offline for state change There are two ways to set the online/offline state for a memory block: echo 0|1 > online and echo online|online_kernel|online_movable|offline > state. The state attribute can online a memory block with extra data, the "online type", where the online attribute uses a default online type of ONLINE_KEEP, same as echo online > state. Currently there is a state_mutex that provides consistency between the memory block state and the underlying memory. The problem is that this code does a lot of things that the common device layer can do for us, such as the serialization of the online/offline handlers using the device lock, setting the dev->offline field, and calling kobject_uevent(). This patch refactors the online/offline code to allow the common device_[online|offline] functions to be used. The result is a simpler and more common code path for the two state setting mechanisms. It also removes the state_mutex from the struct memory_block as the memory block device lock provides the state consistency. No functional change is intended by this patch. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 127 +++++++++++++++++++++---------------------------- include/linux/memory.h | 13 ++--- 2 files changed, 58 insertions(+), 82 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 0187fe483d7c..2a38cd2da2e5 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -261,9 +260,8 @@ memory_block_action(unsigned long phys_index, unsigned long action, int online_t return ret; } -static int __memory_block_change_state(struct memory_block *mem, - unsigned long to_state, unsigned long from_state_req, - int online_type) +static int memory_block_change_state(struct memory_block *mem, + unsigned long to_state, unsigned long from_state_req) { int ret = 0; @@ -273,105 +271,91 @@ static int __memory_block_change_state(struct memory_block *mem, if (to_state == MEM_OFFLINE) mem->state = MEM_GOING_OFFLINE; - ret = memory_block_action(mem->start_section_nr, to_state, online_type); + ret = memory_block_action(mem->start_section_nr, to_state, + mem->online_type); + mem->state = ret ? from_state_req : to_state; + return ret; } +/* The device lock serializes operations on memory_subsys_[online|offline] */ static int memory_subsys_online(struct device *dev) { struct memory_block *mem = container_of(dev, struct memory_block, dev); int ret; - mutex_lock(&mem->state_mutex); + if (mem->state == MEM_ONLINE) + return 0; - ret = mem->state == MEM_ONLINE ? 0 : - __memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE, - ONLINE_KEEP); + /* + * If we are called from store_mem_state(), online_type will be + * set >= 0 Otherwise we were called from the device online + * attribute and need to set the online_type. + */ + if (mem->online_type < 0) + mem->online_type = ONLINE_KEEP; + + ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); + + /* clear online_type */ + mem->online_type = -1; - mutex_unlock(&mem->state_mutex); return ret; } static int memory_subsys_offline(struct device *dev) { struct memory_block *mem = container_of(dev, struct memory_block, dev); - int ret; - mutex_lock(&mem->state_mutex); - - ret = mem->state == MEM_OFFLINE ? 0 : - __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE, -1); - - mutex_unlock(&mem->state_mutex); - return ret; -} + if (mem->state == MEM_OFFLINE) + return 0; -static int __memory_block_change_state_uevent(struct memory_block *mem, - unsigned long to_state, unsigned long from_state_req, - int online_type) -{ - int ret = __memory_block_change_state(mem, to_state, from_state_req, - online_type); - if (!ret) { - switch (mem->state) { - case MEM_OFFLINE: - kobject_uevent(&mem->dev.kobj, KOBJ_OFFLINE); - break; - case MEM_ONLINE: - kobject_uevent(&mem->dev.kobj, KOBJ_ONLINE); - break; - default: - break; - } - } - return ret; + return memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); } -static int memory_block_change_state(struct memory_block *mem, - unsigned long to_state, unsigned long from_state_req, - int online_type) -{ - int ret; - - mutex_lock(&mem->state_mutex); - ret = __memory_block_change_state_uevent(mem, to_state, from_state_req, - online_type); - mutex_unlock(&mem->state_mutex); - - return ret; -} static ssize_t store_mem_state(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct memory_block *mem; - bool offline; - int ret = -EINVAL; + int ret, online_type; mem = container_of(dev, struct memory_block, dev); lock_device_hotplug(); - if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) { - offline = false; - ret = memory_block_change_state(mem, MEM_ONLINE, - MEM_OFFLINE, ONLINE_KERNEL); - } else if (!strncmp(buf, "online_movable", min_t(int, count, 14))) { - offline = false; - ret = memory_block_change_state(mem, MEM_ONLINE, - MEM_OFFLINE, ONLINE_MOVABLE); - } else if (!strncmp(buf, "online", min_t(int, count, 6))) { - offline = false; - ret = memory_block_change_state(mem, MEM_ONLINE, - MEM_OFFLINE, ONLINE_KEEP); - } else if(!strncmp(buf, "offline", min_t(int, count, 7))) { - offline = true; - ret = memory_block_change_state(mem, MEM_OFFLINE, - MEM_ONLINE, -1); + if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) + online_type = ONLINE_KERNEL; + else if (!strncmp(buf, "online_movable", min_t(int, count, 14))) + online_type = ONLINE_MOVABLE; + else if (!strncmp(buf, "online", min_t(int, count, 6))) + online_type = ONLINE_KEEP; + else if (!strncmp(buf, "offline", min_t(int, count, 7))) + online_type = -1; + else + return -EINVAL; + + switch (online_type) { + case ONLINE_KERNEL: + case ONLINE_MOVABLE: + case ONLINE_KEEP: + /* + * mem->online_type is not protected so there can be a + * race here. However, when racing online, the first + * will succeed and the second will just return as the + * block will already be online. The online type + * could be either one, but that is expected. + */ + mem->online_type = online_type; + ret = device_online(&mem->dev); + break; + case -1: + ret = device_offline(&mem->dev); + break; + default: + ret = -EINVAL; /* should never happen */ } - if (!ret) - dev->offline = offline; unlock_device_hotplug(); @@ -592,7 +576,6 @@ static int init_memory_block(struct memory_block **memory, mem->end_section_nr = mem->start_section_nr + sections_per_block - 1; mem->state = state; mem->section_count++; - mutex_init(&mem->state_mutex); start_pfn = section_nr_to_pfn(mem->start_section_nr); mem->phys_device = arch_get_memory_phys_device(start_pfn); diff --git a/include/linux/memory.h b/include/linux/memory.h index 4c89fb0c8f4c..9a6bbf76452d 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -25,16 +25,9 @@ struct memory_block { unsigned long start_section_nr; unsigned long end_section_nr; - unsigned long state; - int section_count; - - /* - * This serializes all state change requests. It isn't - * held during creation because the control files are - * created long after the critical areas during - * initialization. - */ - struct mutex state_mutex; + unsigned long state; /* serialized by the dev->lock */ + int section_count; /* serialized by mem_sysfs_mutex */ + int online_type; /* for passing data to online routine */ int phys_device; /* to which fru does this belong? */ void *hw; /* optional pointer to fw/hw data */ int (*phys_callback)(struct memory_block *); -- cgit v1.2.3-59-g8ed1b From 3e9b2bae8369661070622d05570cbcdfa01770e6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 13:47:50 -0700 Subject: sysfs: add sysfs_create/remove_groups() These functions are being open-coded in 3 different places in the driver core, and other driver subsystems will want to start doing this as well, so move it to the sysfs core to keep it all in one place, where we know it is written properly. Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 23 ++-------------------- drivers/base/core.c | 22 ++------------------- drivers/base/driver.c | 22 ++------------------- fs/sysfs/group.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/sysfs.h | 4 ++++ 5 files changed, 64 insertions(+), 61 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 5ee5d3c1d74b..f099af0b41af 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -884,32 +884,13 @@ static void bus_remove_attrs(struct bus_type *bus) static int bus_add_groups(struct bus_type *bus, const struct attribute_group **groups) { - int error = 0; - int i; - - if (groups) { - for (i = 0; groups[i]; i++) { - error = sysfs_create_group(&bus->p->subsys.kobj, - groups[i]); - if (error) { - while (--i >= 0) - sysfs_remove_group(&bus->p->subsys.kobj, - groups[i]); - break; - } - } - } - return error; + return sysfs_create_groups(&bus->p->subsys.kobj, groups); } static void bus_remove_groups(struct bus_type *bus, const struct attribute_group **groups) { - int i; - - if (groups) - for (i = 0; groups[i]; i++) - sysfs_remove_group(&bus->p->subsys.kobj, groups[i]); + sysfs_remove_groups(&bus->p->subsys.kobj, groups); } static void klist_devices_get(struct klist_node *n) diff --git a/drivers/base/core.c b/drivers/base/core.c index af646afa5b7e..d743dcee1e77 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -493,31 +493,13 @@ static void device_remove_bin_attributes(struct device *dev, int device_add_groups(struct device *dev, const struct attribute_group **groups) { - int error = 0; - int i; - - if (groups) { - for (i = 0; groups[i]; i++) { - error = sysfs_create_group(&dev->kobj, groups[i]); - if (error) { - while (--i >= 0) - sysfs_remove_group(&dev->kobj, - groups[i]); - break; - } - } - } - return error; + return sysfs_create_groups(&dev->kobj, groups); } void device_remove_groups(struct device *dev, const struct attribute_group **groups) { - int i; - - if (groups) - for (i = 0; groups[i]; i++) - sysfs_remove_group(&dev->kobj, groups[i]); + sysfs_remove_groups(&dev->kobj, groups); } static int device_add_attrs(struct device *dev) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 89db726ebb98..c7efccb6f3bb 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -126,31 +126,13 @@ EXPORT_SYMBOL_GPL(driver_remove_file); int driver_add_groups(struct device_driver *drv, const struct attribute_group **groups) { - int error = 0; - int i; - - if (groups) { - for (i = 0; groups[i]; i++) { - error = sysfs_create_group(&drv->p->kobj, groups[i]); - if (error) { - while (--i >= 0) - sysfs_remove_group(&drv->p->kobj, - groups[i]); - break; - } - } - } - return error; + return sysfs_create_groups(&drv->p->kobj, groups); } void driver_remove_groups(struct device_driver *drv, const struct attribute_group **groups) { - int i; - - if (groups) - for (i = 0; groups[i]; i++) - sysfs_remove_group(&drv->p->kobj, groups[i]); + sysfs_remove_groups(&drv->p->kobj, groups); } /** diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 09a1a25cd145..68baf8501552 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -130,6 +130,40 @@ int sysfs_create_group(struct kobject *kobj, return internal_create_group(kobj, 0, grp); } +/** + * sysfs_create_groups - given a directory kobject, create a bunch of attribute groups + * @kobj: The kobject to create the group on + * @groups: The attribute groups to create, NULL terminated + * + * This function creates a bunch of attribute groups. If an error occurs when + * creating a group, all previously created groups will be removed, unwinding + * everything back to the original state when this function was called. + * It will explicitly warn and error if any of the attribute files being + * created already exist. + * + * Returns 0 on success or error code from sysfs_create_groups on error. + */ +int sysfs_create_groups(struct kobject *kobj, + const struct attribute_group **groups) +{ + int error = 0; + int i; + + if (!groups) + return 0; + + for (i = 0; groups[i]; i++) { + error = sysfs_create_group(kobj, groups[i]); + if (error) { + while (--i >= 0) + sysfs_remove_group(kobj, groups[i]); + break; + } + } + return error; +} +EXPORT_SYMBOL_GPL(sysfs_create_groups); + /** * sysfs_update_group - given a directory kobject, update an attribute group * @kobj: The kobject to update the group on @@ -178,6 +212,26 @@ void sysfs_remove_group(struct kobject * kobj, sysfs_put(sd); } +/** + * sysfs_remove_groups - remove a list of groups + * + * kobj: The kobject for the groups to be removed from + * groups: NULL terminated list of groups to be removed + * + * If groups is not NULL, the all groups will be removed from the kobject + */ +void sysfs_remove_groups(struct kobject *kobj, + const struct attribute_group **groups) +{ + int i; + + if (!groups) + return; + for (i = 0; groups[i]; i++) + sysfs_remove_group(kobj, groups[i]); +} +EXPORT_SYMBOL_GPL(sysfs_remove_groups); + /** * sysfs_merge_group - merge files into a pre-existing attribute group. * @kobj: The kobject containing the group. diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 0f04958623d7..4dbb9d31daa8 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -215,10 +215,14 @@ void sysfs_delete_link(struct kobject *dir, struct kobject *targ, int __must_check sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp); +int __must_check sysfs_create_groups(struct kobject *kobj, + const struct attribute_group **groups); int sysfs_update_group(struct kobject *kobj, const struct attribute_group *grp); void sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp); +void sysfs_remove_groups(struct kobject *kobj, + const struct attribute_group **groups); int sysfs_add_file_to_group(struct kobject *kobj, const struct attribute *attr, const char *group); void sysfs_remove_file_from_group(struct kobject *kobj, -- cgit v1.2.3-59-g8ed1b From 3e1026b3fa2f61d33ce6a9e42a22398cc4ab8e58 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 22 Aug 2013 10:25:34 -0700 Subject: sysfs.h: remove attr_name() macro Gotta love a macro that doesn't reduce the typing you have to do. Also, only the driver core, and one network driver uses this. The driver core functions will be going away soon, and I'll convert the network driver soon to not need this as well, so delete it for now before anyone else gets some bright ideas and wants to use it. Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 12 ++++++------ drivers/base/class.c | 4 ++-- drivers/base/core.c | 8 ++++---- drivers/net/ethernet/sun/niu.c | 2 +- include/linux/sysfs.h | 2 -- 5 files changed, 13 insertions(+), 15 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index f099af0b41af..235e2b06ac05 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -460,7 +460,7 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev) if (!bus->dev_attrs) return 0; - for (i = 0; attr_name(bus->dev_attrs[i]); i++) { + for (i = 0; bus->dev_attrs[i].attr.name; i++) { error = device_create_file(dev, &bus->dev_attrs[i]); if (error) { while (--i >= 0) @@ -476,7 +476,7 @@ static void device_remove_attrs(struct bus_type *bus, struct device *dev) int i; if (bus->dev_attrs) { - for (i = 0; attr_name(bus->dev_attrs[i]); i++) + for (i = 0; bus->dev_attrs[i].attr.name; i++) device_remove_file(dev, &bus->dev_attrs[i]); } } @@ -596,7 +596,7 @@ static int driver_add_attrs(struct bus_type *bus, struct device_driver *drv) int i; if (bus->drv_attrs) { - for (i = 0; attr_name(bus->drv_attrs[i]); i++) { + for (i = 0; bus->drv_attrs[i].attr.name; i++) { error = driver_create_file(drv, &bus->drv_attrs[i]); if (error) goto err; @@ -616,7 +616,7 @@ static void driver_remove_attrs(struct bus_type *bus, int i; if (bus->drv_attrs) { - for (i = 0; attr_name(bus->drv_attrs[i]); i++) + for (i = 0; bus->drv_attrs[i].attr.name; i++) driver_remove_file(drv, &bus->drv_attrs[i]); } } @@ -857,7 +857,7 @@ static int bus_add_attrs(struct bus_type *bus) int i; if (bus->bus_attrs) { - for (i = 0; attr_name(bus->bus_attrs[i]); i++) { + for (i = 0; bus->bus_attrs[i].attr.name; i++) { error = bus_create_file(bus, &bus->bus_attrs[i]); if (error) goto err; @@ -876,7 +876,7 @@ static void bus_remove_attrs(struct bus_type *bus) int i; if (bus->bus_attrs) { - for (i = 0; attr_name(bus->bus_attrs[i]); i++) + for (i = 0; bus->bus_attrs[i].attr.name; i++) bus_remove_file(bus, &bus->bus_attrs[i]); } } diff --git a/drivers/base/class.c b/drivers/base/class.c index 3ce845471327..8b7818b80056 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -135,7 +135,7 @@ static int add_class_attrs(struct class *cls) int error = 0; if (cls->class_attrs) { - for (i = 0; attr_name(cls->class_attrs[i]); i++) { + for (i = 0; cls->class_attrs[i].attr.name; i++) { error = class_create_file(cls, &cls->class_attrs[i]); if (error) goto error; @@ -154,7 +154,7 @@ static void remove_class_attrs(struct class *cls) int i; if (cls->class_attrs) { - for (i = 0; attr_name(cls->class_attrs[i]); i++) + for (i = 0; cls->class_attrs[i].attr.name; i++) class_remove_file(cls, &cls->class_attrs[i]); } } diff --git a/drivers/base/core.c b/drivers/base/core.c index d743dcee1e77..ae1acdf21bd3 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -440,7 +440,7 @@ static int device_add_attributes(struct device *dev, int i; if (attrs) { - for (i = 0; attr_name(attrs[i]); i++) { + for (i = 0; attrs[i].attr.name; i++) { error = device_create_file(dev, &attrs[i]); if (error) break; @@ -458,7 +458,7 @@ static void device_remove_attributes(struct device *dev, int i; if (attrs) - for (i = 0; attr_name(attrs[i]); i++) + for (i = 0; attrs[i].attr.name; i++) device_remove_file(dev, &attrs[i]); } @@ -469,7 +469,7 @@ static int device_add_bin_attributes(struct device *dev, int i; if (attrs) { - for (i = 0; attr_name(attrs[i]); i++) { + for (i = 0; attrs[i].attr.name; i++) { error = device_create_bin_file(dev, &attrs[i]); if (error) break; @@ -487,7 +487,7 @@ static void device_remove_bin_attributes(struct device *dev, int i; if (attrs) - for (i = 0; attr_name(attrs[i]); i++) + for (i = 0; attrs[i].attr.name; i++) device_remove_bin_file(dev, &attrs[i]); } diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c index fa322409bff3..52b2adf63cbf 100644 --- a/drivers/net/ethernet/sun/niu.c +++ b/drivers/net/ethernet/sun/niu.c @@ -9478,7 +9478,7 @@ static struct niu_parent *niu_new_parent(struct niu *np, if (IS_ERR(plat_dev)) return NULL; - for (i = 0; attr_name(niu_parent_attributes[i]); i++) { + for (i = 0; niu_parent_attributes[i].attr.name; i++) { int err = device_create_file(&plat_dev->dev, &niu_parent_attributes[i]); if (err) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index a864b8d918ee..b5a9d9b26bd4 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -108,8 +108,6 @@ static const struct attribute_group _name##_group = { \ }; \ __ATTRIBUTE_GROUPS(_name) -#define attr_name(_attr) (_attr).attr.name - struct file; struct vm_area_struct; -- cgit v1.2.3-59-g8ed1b From d06262e58546e5bf5669ef185fb913cca4637bd6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 14:24:37 -0700 Subject: driver-core: platform: convert bus code to use dev_groups The dev_attrs field of struct bus_type is going away soon, dev_groups should be used instead. This converts the platform bus code to use the correct field. Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 9d538cf9204a..4f8bef3eb5a8 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -672,11 +672,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a, return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; } +static DEVICE_ATTR_RO(modalias); -static struct device_attribute platform_dev_attrs[] = { - __ATTR_RO(modalias), - __ATTR_NULL, +static struct attribute *platform_dev_attrs[] = { + &dev_attr_modalias.attr, + NULL, }; +ATTRIBUTE_GROUPS(platform_dev); static int platform_uevent(struct device *dev, struct kobj_uevent_env *env) { @@ -893,7 +895,7 @@ static const struct dev_pm_ops platform_dev_pm_ops = { struct bus_type platform_bus_type = { .name = "platform", - .dev_attrs = platform_dev_attrs, + .dev_groups = platform_dev_groups, .match = platform_match, .uevent = platform_uevent, .pm = &platform_dev_pm_ops, -- cgit v1.2.3-59-g8ed1b From 2581c9cc0de6eeba8d5553c98aab6e0f75d184e0 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 15:04:42 -0700 Subject: driver core: bus: use DRIVER_ATTR_WO() There are two bus attributes that can better be defined using DRIVER_ATTR_WO(), so convert them to the new macro, making it easier to audit attribute permissions. Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 235e2b06ac05..7fc2a13e84a1 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -165,8 +165,8 @@ static const struct kset_uevent_ops bus_uevent_ops = { static struct kset *bus_kset; /* Manually detach a device from its associated driver. */ -static ssize_t driver_unbind(struct device_driver *drv, - const char *buf, size_t count) +static ssize_t unbind_store(struct device_driver *drv, const char *buf, + size_t count) { struct bus_type *bus = bus_get(drv->bus); struct device *dev; @@ -185,15 +185,15 @@ static ssize_t driver_unbind(struct device_driver *drv, bus_put(bus); return err; } -static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); +static DRIVER_ATTR_WO(unbind); /* * Manually attach a device to a driver. * Note: the driver must want to bind to the device, * it is not possible to override the driver's id table. */ -static ssize_t driver_bind(struct device_driver *drv, - const char *buf, size_t count) +static ssize_t bind_store(struct device_driver *drv, const char *buf, + size_t count) { struct bus_type *bus = bus_get(drv->bus); struct device *dev; @@ -221,7 +221,7 @@ static ssize_t driver_bind(struct device_driver *drv, bus_put(bus); return err; } -static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); +static DRIVER_ATTR_WO(bind); static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) { @@ -665,8 +665,8 @@ static void remove_probe_files(struct bus_type *bus) bus_remove_file(bus, &bus_attr_drivers_probe); } -static ssize_t driver_uevent_store(struct device_driver *drv, - const char *buf, size_t count) +static ssize_t uevent_store(struct device_driver *drv, const char *buf, + size_t count) { enum kobject_action action; @@ -674,7 +674,7 @@ static ssize_t driver_uevent_store(struct device_driver *drv, kobject_uevent(&drv->p->kobj, action); return count; } -static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store); +static DRIVER_ATTR_WO(uevent); /** * bus_add_driver - Add a driver to the bus. -- cgit v1.2.3-59-g8ed1b From c5e064a6981603de65c61c4989856e984c7ad66d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 17:07:26 -0700 Subject: driver core: core: use DEVICE_ATTR_RO Use DEVICE_ATTR_RO() instead of a "raw" __ATTR macro, making it easier to audit exactly what is going on with the sysfs files. Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index ae1acdf21bd3..921b94184dcc 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -345,7 +345,7 @@ static const struct kset_uevent_ops device_uevent_ops = { .uevent = dev_uevent, }; -static ssize_t show_uevent(struct device *dev, struct device_attribute *attr, +static ssize_t uevent_show(struct device *dev, struct device_attribute *attr, char *buf) { struct kobject *top_kobj; @@ -388,7 +388,7 @@ out: return count; } -static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, +static ssize_t uevent_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { enum kobject_action action; @@ -399,11 +399,9 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, dev_err(dev, "uevent: unknown action-string\n"); return count; } +static DEVICE_ATTR_RW(uevent); -static struct device_attribute uevent_attr = - __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent); - -static ssize_t show_online(struct device *dev, struct device_attribute *attr, +static ssize_t online_show(struct device *dev, struct device_attribute *attr, char *buf) { bool val; @@ -414,7 +412,7 @@ static ssize_t show_online(struct device *dev, struct device_attribute *attr, return sprintf(buf, "%u\n", val); } -static ssize_t store_online(struct device *dev, struct device_attribute *attr, +static ssize_t online_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { bool val; @@ -429,9 +427,7 @@ static ssize_t store_online(struct device *dev, struct device_attribute *attr, unlock_device_hotplug(); return ret < 0 ? ret : count; } - -static struct device_attribute online_attr = - __ATTR(online, S_IRUGO | S_IWUSR, show_online, store_online); +static DEVICE_ATTR_RW(online); static int device_add_attributes(struct device *dev, struct device_attribute *attrs) @@ -531,7 +527,7 @@ static int device_add_attrs(struct device *dev) goto err_remove_type_groups; if (device_supports_offline(dev) && !dev->offline_disabled) { - error = device_create_file(dev, &online_attr); + error = device_create_file(dev, &dev_attr_online); if (error) goto err_remove_type_groups; } @@ -559,7 +555,7 @@ static void device_remove_attrs(struct device *dev) struct class *class = dev->class; const struct device_type *type = dev->type; - device_remove_file(dev, &online_attr); + device_remove_file(dev, &dev_attr_online); device_remove_groups(dev, dev->groups); if (type) @@ -572,15 +568,12 @@ static void device_remove_attrs(struct device *dev) } } - -static ssize_t show_dev(struct device *dev, struct device_attribute *attr, +static ssize_t dev_show(struct device *dev, struct device_attribute *attr, char *buf) { return print_dev_t(buf, dev->devt); } - -static struct device_attribute devt_attr = - __ATTR(dev, S_IRUGO, show_dev, NULL); +static DEVICE_ATTR_RO(dev); /* /sys/devices/ */ struct kset *devices_kset; @@ -1084,12 +1077,12 @@ int device_add(struct device *dev) if (platform_notify) platform_notify(dev); - error = device_create_file(dev, &uevent_attr); + error = device_create_file(dev, &dev_attr_uevent); if (error) goto attrError; if (MAJOR(dev->devt)) { - error = device_create_file(dev, &devt_attr); + error = device_create_file(dev, &dev_attr_dev); if (error) goto ueventattrError; @@ -1156,9 +1149,9 @@ done: device_remove_sys_dev_entry(dev); devtattrError: if (MAJOR(dev->devt)) - device_remove_file(dev, &devt_attr); + device_remove_file(dev, &dev_attr_dev); ueventattrError: - device_remove_file(dev, &uevent_attr); + device_remove_file(dev, &dev_attr_uevent); attrError: kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_del(&dev->kobj); @@ -1254,7 +1247,7 @@ void device_del(struct device *dev) if (MAJOR(dev->devt)) { devtmpfs_delete_node(dev); device_remove_sys_dev_entry(dev); - device_remove_file(dev, &devt_attr); + device_remove_file(dev, &dev_attr_dev); } if (dev->class) { device_remove_class_symlinks(dev); @@ -1269,7 +1262,7 @@ void device_del(struct device *dev) klist_del(&dev->knode_class); mutex_unlock(&dev->class->p->mutex); } - device_remove_file(dev, &uevent_attr); + device_remove_file(dev, &dev_attr_uevent); device_remove_attrs(dev); bus_remove_device(dev); device_pm_remove(dev); -- cgit v1.2.3-59-g8ed1b From 14adbe5307a4110af7d1e95fb604a1abcdaa6cce Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 17:08:48 -0700 Subject: driver core: firmware: use __ATTR_RW() Use __ATTR_RW() instead of __ATTR() to make it more obvious what the type of attribute is being created. Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware_class.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index a439602ea919..e4107d5f036b 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -486,9 +486,8 @@ static struct notifier_block fw_shutdown_nb = { .notifier_call = fw_shutdown_notify, }; -static ssize_t firmware_timeout_show(struct class *class, - struct class_attribute *attr, - char *buf) +static ssize_t timeout_show(struct class *class, struct class_attribute *attr, + char *buf) { return sprintf(buf, "%d\n", loading_timeout); } @@ -506,9 +505,8 @@ static ssize_t firmware_timeout_show(struct class *class, * * Note: zero means 'wait forever'. **/ -static ssize_t firmware_timeout_store(struct class *class, - struct class_attribute *attr, - const char *buf, size_t count) +static ssize_t timeout_store(struct class *class, struct class_attribute *attr, + const char *buf, size_t count) { loading_timeout = simple_strtol(buf, NULL, 10); if (loading_timeout < 0) @@ -518,8 +516,7 @@ static ssize_t firmware_timeout_store(struct class *class, } static struct class_attribute firmware_class_attrs[] = { - __ATTR(timeout, S_IWUSR | S_IRUGO, - firmware_timeout_show, firmware_timeout_store), + __ATTR_RW(timeout), __ATTR_NULL }; -- cgit v1.2.3-59-g8ed1b From 63967685605b3c73c078807cd498c4fbf62847c1 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 27 Aug 2013 10:24:15 -0700 Subject: driver core: add #include to core files. This is needed to fix the build on sh systems. Reported-by: kbuild test robot Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 1 + drivers/base/core.c | 1 + drivers/base/driver.c | 1 + 3 files changed, 3 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 7fc2a13e84a1..4c289ab91357 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" diff --git a/drivers/base/core.c b/drivers/base/core.c index 921b94184dcc..c7b0925f627a 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" diff --git a/drivers/base/driver.c b/drivers/base/driver.c index c7efccb6f3bb..9e29943e56ca 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "base.h" static struct device *next_device(struct klist_iter *i) -- cgit v1.2.3-59-g8ed1b From 7315f0ccfc283ae998ca4d8102de83bba21936fa Mon Sep 17 00:00:00 2001 From: Gu Zheng Date: Wed, 28 Aug 2013 14:38:27 +0800 Subject: drivers/base/memory.c: introduce help macro to_memory_block Introduce help macro to_memory_block to hide the conversion(device-->memory_block), just clean up. Reviewed-by: Yasuaki Ishimatsu Signed-off-by: Gu Zheng Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 2a38cd2da2e5..69e09a1b62a4 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -29,6 +29,8 @@ static DEFINE_MUTEX(mem_sysfs_mutex); #define MEMORY_CLASS_NAME "memory" +#define to_memory_block(dev) container_of(dev, struct memory_block, dev) + static int sections_per_block; static inline int base_memory_block_id(int section_nr) @@ -76,7 +78,7 @@ EXPORT_SYMBOL(unregister_memory_isolate_notifier); static void memory_block_release(struct device *dev) { - struct memory_block *mem = container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); kfree(mem); } @@ -109,8 +111,7 @@ static unsigned long get_memory_block_size(void) static ssize_t show_mem_start_phys_index(struct device *dev, struct device_attribute *attr, char *buf) { - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); unsigned long phys_index; phys_index = mem->start_section_nr / sections_per_block; @@ -120,8 +121,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev, static ssize_t show_mem_end_phys_index(struct device *dev, struct device_attribute *attr, char *buf) { - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); unsigned long phys_index; phys_index = mem->end_section_nr / sections_per_block; @@ -136,8 +136,7 @@ static ssize_t show_mem_removable(struct device *dev, { unsigned long i, pfn; int ret = 1; - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); for (i = 0; i < sections_per_block; i++) { pfn = section_nr_to_pfn(mem->start_section_nr + i); @@ -153,8 +152,7 @@ static ssize_t show_mem_removable(struct device *dev, static ssize_t show_mem_state(struct device *dev, struct device_attribute *attr, char *buf) { - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); ssize_t len = 0; /* @@ -282,7 +280,7 @@ static int memory_block_change_state(struct memory_block *mem, /* The device lock serializes operations on memory_subsys_[online|offline] */ static int memory_subsys_online(struct device *dev) { - struct memory_block *mem = container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); int ret; if (mem->state == MEM_ONLINE) @@ -306,7 +304,7 @@ static int memory_subsys_online(struct device *dev) static int memory_subsys_offline(struct device *dev) { - struct memory_block *mem = container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); if (mem->state == MEM_OFFLINE) return 0; @@ -318,11 +316,9 @@ static ssize_t store_mem_state(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct memory_block *mem; + struct memory_block *mem = to_memory_block(dev); int ret, online_type; - mem = container_of(dev, struct memory_block, dev); - lock_device_hotplug(); if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) @@ -376,8 +372,7 @@ store_mem_state(struct device *dev, static ssize_t show_phys_device(struct device *dev, struct device_attribute *attr, char *buf) { - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); return sprintf(buf, "%d\n", mem->phys_device); } @@ -509,7 +504,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section, put_device(&hint->dev); if (!dev) return NULL; - return container_of(dev, struct memory_block, dev); + return to_memory_block(dev); } /* -- cgit v1.2.3-59-g8ed1b From 1eeeef153c02f5856ec109fa532eb5f31c39f85c Mon Sep 17 00:00:00 2001 From: Maxime Bizon Date: Thu, 29 Aug 2013 20:28:13 +0200 Subject: firmware loader: fix pending_fw_head list corruption Got the following oops just before reboot: Unable to handle kernel NULL pointer dereference at virtual address 00000000 [<8028d300>] (__list_del_entry+0x44/0xac) [<802e3320>] (__fw_load_abort.part.13+0x1c/0x50) [<802e337c>] (fw_shutdown_notify+0x28/0x50) [<80034f80>] (notifier_call_chain.isra.1+0x5c/0x9c) [<800350ec>] (__blocking_notifier_call_chain+0x44/0x58) [<80035114>] (blocking_notifier_call_chain+0x14/0x18) [<80035d64>] (kernel_restart_prepare+0x14/0x38) [<80035d94>] (kernel_restart+0xc/0x50) The following race condition triggers here: _request_firmware_load() device_create_file(...) kobject_uevent(...) (schedule) (resume) firmware_loading_store(1) firmware_loading_store(0) list_del_init(&buf->pending_list) (schedule) (resume) list_add(&buf->pending_list, &pending_fw_head); wait_for_completion(&buf->completion); causing an oops later when walking pending_list after the firmware has been released. The proposed fix is to move the list_add() before sysfs attribute creation. Signed-off-by: Maxime Bizon Acked-by: Ming Lei Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware_class.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index e4107d5f036b..10a4467c63f1 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -865,8 +865,15 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, goto err_del_dev; } + mutex_lock(&fw_lock); + list_add(&buf->pending_list, &pending_fw_head); + mutex_unlock(&fw_lock); + retval = device_create_file(f_dev, &dev_attr_loading); if (retval) { + mutex_lock(&fw_lock); + list_del_init(&buf->pending_list); + mutex_unlock(&fw_lock); dev_err(f_dev, "%s: device_create_file failed\n", __func__); goto err_del_bin_attr; } @@ -881,10 +888,6 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, kobject_uevent(&fw_priv->dev.kobj, KOBJ_ADD); } - mutex_lock(&fw_lock); - list_add(&buf->pending_list, &pending_fw_head); - mutex_unlock(&fw_lock); - wait_for_completion(&buf->completion); cancel_delayed_work_sync(&fw_priv->timeout_work); -- cgit v1.2.3-59-g8ed1b