From d79d32440c33cf60f1e0efbeb8144b1647be0b50 Mon Sep 17 00:00:00 2001 From: Patrick Pannuto Date: Fri, 6 Aug 2010 17:12:41 -0700 Subject: driver core: platform: Use drv->driver.bus instead of assuming platform_bus_type In theory (although not *yet* in practice), a driver being passed to platform_driver_probe might have driver.bus set to something other than platform_bus_type. Locking drv->driver.bus is always correct. Signed-off-by: Patrick Pannuto 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 c6c933f58102..579906f88b09 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -488,12 +488,12 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv, * if the probe was successful, and make sure any forced probes of * new devices fail. */ - spin_lock(&platform_bus_type.p->klist_drivers.k_lock); + spin_lock(&drv->driver.bus->p->klist_drivers.k_lock); drv->probe = NULL; if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list)) retval = -ENODEV; drv->driver.probe = platform_drv_probe_fail; - spin_unlock(&platform_bus_type.p->klist_drivers.k_lock); + spin_unlock(&drv->driver.bus->p->klist_drivers.k_lock); if (code != retval) platform_driver_unregister(drv); -- cgit v1.2.3 From c64a0926710153b9d44c979d2942f4a8648fd74e Mon Sep 17 00:00:00 2001 From: Kevin Hilman Date: Wed, 25 Aug 2010 12:50:00 -0700 Subject: driver core: platform_bus: allow runtime override of dev_pm_ops Currently, the platform_bus allows customization of several of the busses dev_pm_ops methods by using weak symbols so that platform code can override them. The weak-symbol approach is not scalable when wanting to support multiple platforms in a single kernel binary. Instead, provide __init methods for platform code to customize the dev_pm_ops methods at runtime. NOTE: after these dynamic methods are merged, the weak symbols should be removed from drivers/base/platform.c. AFAIK, this will only affect SH and sh-mobile which should be converted to use this runtime approach instead of the weak symbols. After SH & sh-mobile are converted, the weak symobols could be removed. Tested on OMAP3. Cc: Magnus Damm Acked-by: Grant Likely Signed-off-by: Kevin Hilman Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 579906f88b09..a01abf9ebf7b 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -976,6 +976,41 @@ struct bus_type platform_bus_type = { }; EXPORT_SYMBOL_GPL(platform_bus_type); +/** + * platform_bus_get_pm_ops() - return pointer to busses dev_pm_ops + * + * This function can be used by platform code to get the current + * set of dev_pm_ops functions used by the platform_bus_type. + */ +const struct dev_pm_ops * __init platform_bus_get_pm_ops(void) +{ + return platform_bus_type.pm; +} + +/** + * platform_bus_set_pm_ops() - update dev_pm_ops for the platform_bus_type + * + * @pm: pointer to new dev_pm_ops struct to be used for platform_bus_type + * + * Platform code can override the dev_pm_ops methods of + * platform_bus_type by using this function. It is expected that + * platform code will first do a platform_bus_get_pm_ops(), then + * kmemdup it, then customize selected methods and pass a pointer to + * the new struct dev_pm_ops to this function. + * + * Since platform-specific code is customizing methods for *all* + * devices (not just platform-specific devices) it is expected that + * any custom overrides of these functions will keep existing behavior + * and simply extend it. For example, any customization of the + * runtime PM methods should continue to call the pm_generic_* + * functions as the default ones do in addition to the + * platform-specific behavior. + */ +void __init platform_bus_set_pm_ops(const struct dev_pm_ops *pm) +{ + platform_bus_type.pm = pm; +} + int __init platform_bus_init(void) { int error; -- cgit v1.2.3 From 5cfc64ceb6222aabec640ba76e89529a8fc2c1f0 Mon Sep 17 00:00:00 2001 From: Anton Vorontsov Date: Tue, 7 Sep 2010 17:31:49 +0400 Subject: base/platform: Safe handling for NULL platform data and resources Some users of platform_device_add_{data,resources}() assume that NULL data and resources will be handled specially, i.e. just ignored. But the platform core ends up calling kmemdup(NULL, 0, ...), which returns a non-NULL result (i.e. ZERO_SIZE_PTR), which causes drivers to oops on a valid code, something like: if (platform_data) stuff = platform_data->stuff; This patch makes the platform core a bit more safe for such cases. Signed-off-by: Anton Vorontsov Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index a01abf9ebf7b..c794fec1c435 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -192,6 +192,9 @@ int platform_device_add_resources(struct platform_device *pdev, { struct resource *r; + if (!res) + return 0; + r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL); if (r) { pdev->resource = r; @@ -215,8 +218,12 @@ EXPORT_SYMBOL_GPL(platform_device_add_resources); int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size) { - void *d = kmemdup(data, size, GFP_KERNEL); + void *d; + + if (!data) + return 0; + d = kmemdup(data, size, GFP_KERNEL); if (d) { pdev->dev.platform_data = d; return 0; -- cgit v1.2.3 From 807508c8ff9af6ce8f25c5ca5f3eb06a8e7d3286 Mon Sep 17 00:00:00 2001 From: Anton Vorontsov Date: Tue, 7 Sep 2010 17:31:54 +0400 Subject: base/platform: Simplifications for NULL platform data/resources handling There's no need to explicitly check for data and resources being NULL, as platform_device_add_{data,resources}() do this internally nowadays. This makes the code more linear and less indented. Signed-off-by: Anton Vorontsov Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index c794fec1c435..3966e62ad019 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -380,17 +380,13 @@ struct platform_device *__init_or_module platform_device_register_resndata( pdev->dev.parent = parent; - if (res) { - ret = platform_device_add_resources(pdev, res, num); - if (ret) - goto err; - } + ret = platform_device_add_resources(pdev, res, num); + if (ret) + goto err; - if (data) { - ret = platform_device_add_data(pdev, data, size); - if (ret) - goto err; - } + ret = platform_device_add_data(pdev, data, size); + if (ret) + goto err; ret = platform_device_add(pdev); if (ret) { @@ -537,17 +533,13 @@ struct platform_device * __init_or_module platform_create_bundle( goto err_out; } - if (res) { - error = platform_device_add_resources(pdev, res, n_res); - if (error) - goto err_pdev_put; - } + error = platform_device_add_resources(pdev, res, n_res); + if (error) + goto err_pdev_put; - if (data) { - error = platform_device_add_data(pdev, data, size); - if (error) - goto err_pdev_put; - } + error = platform_device_add_data(pdev, data, size); + if (error) + goto err_pdev_put; error = platform_device_add(pdev); if (error) -- cgit v1.2.3 From 39aba963d937edb20db7d9d93e6dda5d2adfdcdd Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 4 Sep 2010 22:33:14 -0700 Subject: driver core: remove CONFIG_SYSFS_DEPRECATED_V2 but keep it for block devices This patch removes the old CONFIG_SYSFS_DEPRECATED_V2 config option, but it keeps the logic around to handle block devices in the old manner as some people like to run new kernel versions on old (pre 2007/2008) distros. Signed-off-by: Kay Sievers Cc: Jens Axboe Cc: Stephen Hemminger Cc: "Eric W. Biederman" Cc: Alan Stern Cc: "James E.J. Bottomley" Cc: Andrew Morton Cc: Alexey Kuznetsov Cc: Randy Dunlap Cc: Tejun Heo Cc: "David S. Miller" Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Ingo Molnar Cc: Peter Zijlstra Cc: David Howells Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 22 ------ drivers/base/class.c | 19 ----- drivers/base/core.c | 194 +++++++-------------------------------------------- 3 files changed, 25 insertions(+), 210 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index eb1b7fa20dce..33c270a64db7 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -440,22 +440,6 @@ static void device_remove_attrs(struct bus_type *bus, struct device *dev) } } -#ifdef CONFIG_SYSFS_DEPRECATED -static int make_deprecated_bus_links(struct device *dev) -{ - return sysfs_create_link(&dev->kobj, - &dev->bus->p->subsys.kobj, "bus"); -} - -static void remove_deprecated_bus_links(struct device *dev) -{ - sysfs_remove_link(&dev->kobj, "bus"); -} -#else -static inline int make_deprecated_bus_links(struct device *dev) { return 0; } -static inline void remove_deprecated_bus_links(struct device *dev) { } -#endif - /** * bus_add_device - add device to bus * @dev: device being added @@ -482,15 +466,10 @@ int bus_add_device(struct device *dev) &dev->bus->p->subsys.kobj, "subsystem"); if (error) goto out_subsys; - error = make_deprecated_bus_links(dev); - if (error) - goto out_deprecated; klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices); } return 0; -out_deprecated: - sysfs_remove_link(&dev->kobj, "subsystem"); out_subsys: sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); out_id: @@ -530,7 +509,6 @@ void bus_remove_device(struct device *dev) { if (dev->bus) { sysfs_remove_link(&dev->kobj, "subsystem"); - remove_deprecated_bus_links(dev); sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev_name(dev)); device_remove_attrs(dev->bus, dev); diff --git a/drivers/base/class.c b/drivers/base/class.c index 8e231d05b400..1078969889fd 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -276,25 +276,6 @@ void class_destroy(struct class *cls) class_unregister(cls); } -#ifdef CONFIG_SYSFS_DEPRECATED -char *make_class_name(const char *name, struct kobject *kobj) -{ - char *class_name; - int size; - - size = strlen(name) + strlen(kobject_name(kobj)) + 2; - - class_name = kmalloc(size, GFP_KERNEL); - if (!class_name) - return NULL; - - strcpy(class_name, name); - strcat(class_name, ":"); - strcat(class_name, kobject_name(kobj)); - return class_name; -} -#endif - /** * class_dev_iter_init - initialize class device iterator * @iter: class iterator to initialize diff --git a/drivers/base/core.c b/drivers/base/core.c index d1b2c9adc271..6cf9069f3150 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -203,37 +203,6 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, if (dev->driver) add_uevent_var(env, "DRIVER=%s", dev->driver->name); -#ifdef CONFIG_SYSFS_DEPRECATED - if (dev->class) { - struct device *parent = dev->parent; - - /* find first bus device in parent chain */ - while (parent && !parent->bus) - parent = parent->parent; - if (parent && parent->bus) { - const char *path; - - path = kobject_get_path(&parent->kobj, GFP_KERNEL); - if (path) { - add_uevent_var(env, "PHYSDEVPATH=%s", path); - kfree(path); - } - - add_uevent_var(env, "PHYSDEVBUS=%s", parent->bus->name); - - if (parent->driver) - add_uevent_var(env, "PHYSDEVDRIVER=%s", - parent->driver->name); - } - } else if (dev->bus) { - add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); - - if (dev->driver) - add_uevent_var(env, "PHYSDEVDRIVER=%s", - dev->driver->name); - } -#endif - /* have the bus specific function add its stuff */ if (dev->bus && dev->bus->uevent) { retval = dev->bus->uevent(dev, env); @@ -578,24 +547,6 @@ void device_initialize(struct device *dev) set_dev_node(dev, -1); } -#ifdef CONFIG_SYSFS_DEPRECATED -static struct kobject *get_device_parent(struct device *dev, - struct device *parent) -{ - /* class devices without a parent live in /sys/class// */ - if (dev->class && (!parent || parent->class != dev->class)) - return &dev->class->p->class_subsys.kobj; - /* all other devices keep their parent */ - else if (parent) - return &parent->kobj; - - return NULL; -} - -static inline void cleanup_device_parent(struct device *dev) {} -static inline void cleanup_glue_dir(struct device *dev, - struct kobject *glue_dir) {} -#else static struct kobject *virtual_device_parent(struct device *dev) { static struct kobject *virtual_dir = NULL; @@ -666,6 +617,14 @@ static struct kobject *get_device_parent(struct device *dev, struct kobject *parent_kobj; struct kobject *k; +#ifdef CONFIG_SYSFS_DEPRECATED + /* block disks show up in /sys/block */ + if (dev->class == &block_class) { + if (parent && parent->class == &block_class) + return &parent->kobj; + return &block_class.p->class_subsys.kobj; + } +#endif /* * If we have no parent, we live in "virtual". * Class-devices with a non class-device as parent, live @@ -719,7 +678,6 @@ static void cleanup_device_parent(struct device *dev) { cleanup_glue_dir(dev, dev->kobj.parent); } -#endif static void setup_parent(struct device *dev, struct device *parent) { @@ -742,70 +700,29 @@ static int device_add_class_symlinks(struct device *dev) if (error) goto out; -#ifdef CONFIG_SYSFS_DEPRECATED - /* stacked class devices need a symlink in the class directory */ - if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && - device_is_not_partition(dev)) { - error = sysfs_create_link(&dev->class->p->class_subsys.kobj, - &dev->kobj, dev_name(dev)); - if (error) - goto out_subsys; - } - if (dev->parent && device_is_not_partition(dev)) { - struct device *parent = dev->parent; - char *class_name; - - /* - * stacked class devices have the 'device' link - * pointing to the bus device instead of the parent - */ - while (parent->class && !parent->bus && parent->parent) - parent = parent->parent; - - error = sysfs_create_link(&dev->kobj, - &parent->kobj, + error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); if (error) - goto out_busid; - - class_name = make_class_name(dev->class->name, - &dev->kobj); - if (class_name) - error = sysfs_create_link(&dev->parent->kobj, - &dev->kobj, class_name); - kfree(class_name); - if (error) - goto out_device; + goto out_subsys; } - return 0; -out_device: - if (dev->parent && device_is_not_partition(dev)) - sysfs_remove_link(&dev->kobj, "device"); -out_busid: - if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && - device_is_not_partition(dev)) - sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, - dev_name(dev)); -#else +#ifdef CONFIG_SYSFS_DEPRECATED + /* /sys/block has directories and does not need symlinks */ + if (dev->class == &block_class) + return 0; +#endif + /* link in the class directory pointing to the device */ error = sysfs_create_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); if (error) - goto out_subsys; + goto out_device; - if (dev->parent && device_is_not_partition(dev)) { - error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, - "device"); - if (error) - goto out_busid; - } return 0; -out_busid: - sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); -#endif +out_device: + sysfs_remove_link(&dev->kobj, "device"); out_subsys: sysfs_remove_link(&dev->kobj, "subsystem"); @@ -818,30 +735,14 @@ static void device_remove_class_symlinks(struct device *dev) if (!dev->class) return; -#ifdef CONFIG_SYSFS_DEPRECATED - if (dev->parent && device_is_not_partition(dev)) { - char *class_name; - - class_name = make_class_name(dev->class->name, &dev->kobj); - if (class_name) { - sysfs_remove_link(&dev->parent->kobj, class_name); - kfree(class_name); - } - sysfs_remove_link(&dev->kobj, "device"); - } - - if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && - device_is_not_partition(dev)) - sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, - dev_name(dev)); -#else if (dev->parent && device_is_not_partition(dev)) sysfs_remove_link(&dev->kobj, "device"); - - sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); -#endif - sysfs_remove_link(&dev->kobj, "subsystem"); +#ifdef CONFIG_SYSFS_DEPRECATED + if (dev->class == &block_class) + return; +#endif + sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); } /** @@ -1613,41 +1514,23 @@ int device_rename(struct device *dev, const char *new_name) pr_debug("device: '%s': %s: renaming to '%s'\n", dev_name(dev), __func__, new_name); -#ifdef CONFIG_SYSFS_DEPRECATED - if ((dev->class) && (dev->parent)) - old_class_name = make_class_name(dev->class->name, &dev->kobj); -#endif - old_device_name = kstrdup(dev_name(dev), GFP_KERNEL); if (!old_device_name) { error = -ENOMEM; goto out; } -#ifndef CONFIG_SYSFS_DEPRECATED if (dev->class) { error = sysfs_rename_link(&dev->class->p->class_subsys.kobj, &dev->kobj, old_device_name, new_name); if (error) goto out; } -#endif + error = kobject_rename(&dev->kobj, new_name); if (error) goto out; -#ifdef CONFIG_SYSFS_DEPRECATED - if (old_class_name) { - new_class_name = make_class_name(dev->class->name, &dev->kobj); - if (new_class_name) { - error = sysfs_rename_link(&dev->parent->kobj, - &dev->kobj, - old_class_name, - new_class_name); - } - } -#endif - out: put_device(dev); @@ -1664,40 +1547,13 @@ static int device_move_class_links(struct device *dev, struct device *new_parent) { int error = 0; -#ifdef CONFIG_SYSFS_DEPRECATED - char *class_name; - class_name = make_class_name(dev->class->name, &dev->kobj); - if (!class_name) { - error = -ENOMEM; - goto out; - } - if (old_parent) { - sysfs_remove_link(&dev->kobj, "device"); - sysfs_remove_link(&old_parent->kobj, class_name); - } - if (new_parent) { - error = sysfs_create_link(&dev->kobj, &new_parent->kobj, - "device"); - if (error) - goto out; - error = sysfs_create_link(&new_parent->kobj, &dev->kobj, - class_name); - if (error) - sysfs_remove_link(&dev->kobj, "device"); - } else - error = 0; -out: - kfree(class_name); - return error; -#else if (old_parent) sysfs_remove_link(&dev->kobj, "device"); if (new_parent) error = sysfs_create_link(&dev->kobj, &new_parent->kobj, "device"); return error; -#endif } /** -- cgit v1.2.3 From e52eec13cd6b7f30ab19081b387813e03e592ae5 Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Wed, 8 Sep 2010 16:54:17 +0200 Subject: SYSFS: Allow boot time switching between deprecated and modern sysfs layout I have some systems which need legacy sysfs due to old tools that are making assumptions that a directory can never be a symlink to another directory, and it's a big hazzle to compile separate kernels for them. This patch turns CONFIG_SYSFS_DEPRECATED into a run time option that can be switched on/off the kernel command line. This way the same binary can be used in both cases with just a option on the command line. The old CONFIG_SYSFS_DEPRECATED_V2 option is still there to set the default. I kept the weird name to not break existing config files. Also the compat code can be still completely disabled by undefining CONFIG_SYSFS_DEPRECATED_SWITCH -- just the optimizer takes care of this now instead of lots of ifdefs. This makes the code look nicer. v2: This is an updated version on top of Kay's patch to only handle the block devices. I tested it on my old systems and that seems to work. Cc: axboe@kernel.dk Signed-off-by: Andi Kleen Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/class.c | 4 ++-- drivers/base/core.c | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/class.c b/drivers/base/class.c index 1078969889fd..9c63a5687d69 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -184,9 +184,9 @@ int __class_register(struct class *cls, struct lock_class_key *key) if (!cls->dev_kobj) cls->dev_kobj = sysfs_dev_char_kobj; -#if defined(CONFIG_SYSFS_DEPRECATED) && defined(CONFIG_BLOCK) +#if defined(CONFIG_BLOCK) /* let the block class directory show up in the root of sysfs */ - if (cls != &block_class) + if (!sysfs_deprecated || cls != &block_class) cp->class_subsys.kobj.kset = class_kset; #else cp->class_subsys.kobj.kset = class_kset; diff --git a/drivers/base/core.c b/drivers/base/core.c index 6cf9069f3150..f7f906f0a2f2 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -26,6 +26,19 @@ #include "base.h" #include "power/power.h" +#ifdef CONFIG_SYSFS_DEPRECATED +#ifdef CONFIG_SYSFS_DEPRECATED_V2 +long sysfs_deprecated = 1; +#else +long sysfs_deprecated = 0; +#endif +static __init int sysfs_deprecated_setup(char *arg) +{ + return strict_strtol(arg, 10, &sysfs_deprecated); +} +early_param("sysfs.deprecated", sysfs_deprecated_setup); +#endif + int (*platform_notify)(struct device *dev) = NULL; int (*platform_notify_remove)(struct device *dev) = NULL; static struct kobject *dev_kobj; @@ -617,14 +630,13 @@ static struct kobject *get_device_parent(struct device *dev, struct kobject *parent_kobj; struct kobject *k; -#ifdef CONFIG_SYSFS_DEPRECATED /* block disks show up in /sys/block */ - if (dev->class == &block_class) { + if (sysfs_deprecated && dev->class == &block_class) { if (parent && parent->class == &block_class) return &parent->kobj; return &block_class.p->class_subsys.kobj; } -#endif + /* * If we have no parent, we live in "virtual". * Class-devices with a non class-device as parent, live @@ -707,11 +719,9 @@ static int device_add_class_symlinks(struct device *dev) goto out_subsys; } -#ifdef CONFIG_SYSFS_DEPRECATED /* /sys/block has directories and does not need symlinks */ - if (dev->class == &block_class) + if (sysfs_deprecated && dev->class == &block_class) return 0; -#endif /* link in the class directory pointing to the device */ error = sysfs_create_link(&dev->class->p->class_subsys.kobj, @@ -738,10 +748,8 @@ static void device_remove_class_symlinks(struct device *dev) if (dev->parent && device_is_not_partition(dev)) sysfs_remove_link(&dev->kobj, "device"); sysfs_remove_link(&dev->kobj, "subsystem"); -#ifdef CONFIG_SYSFS_DEPRECATED - if (dev->class == &block_class) + if (sysfs_deprecated && dev->class == &block_class) return; -#endif sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); } -- cgit v1.2.3 From 5fc6e9cbce3342379719fc0f8294c45bb888f5cc Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Sat, 18 Sep 2010 13:23:08 -0700 Subject: FW_LOADER: fix kconfig dependency warning on HOTPLUG Fix kconfig dependency warning for FW_LOADER. Lots of drivers select FW_LOADER without bothering to depend on HOTPLUG and/or without selecting HOTPLUG. A kernel builds fine when FW_LOADER is enabled, whether HOTPLUG is enabled or not, and a kernel config file (make oldconfig) is not changed by this patch. (Yes, drivers/base/firmware_class.c uses interfaces from linux/kobject.h, which does have some CONFIG_HOTPLUG dependencies, but this patch does not change that.) warning: (MICROCODE || MICROCODE_INTEL && MICROCODE || MICROCODE_AMD && MICROCODE || PCMCIA_LOAD_CIS && PCCARD && PCMCIA && EXPERIMENTAL || USB_IRDA && NET && IRDA && USB || BT_HCIBCM203X && NET && BT && USB || BT_HCIBFUSB && NET && BT && USB || BT_HCIBT3C && NET && BT && PCMCIA || BT_MRVL_SDIO && NET ... !STAGING_EXCLUDE_BUILD && USB && (X86 || ARM) && WLAN || DRM_NOUVEAU && STAGING && !STAGING_EXCLUDE_BUILD && DRM && PCI || TI_ST && STAGING && !STAGING_EXCLUDE_BUILD && RFKILL || DELL_RBU && X86) selects FW_LOADER which has unmet direct dependencies (HOTPLUG) (5200 byte line reduced a lot) Signed-off-by: Randy Dunlap Signed-off-by: Greg Kroah-Hartman --- drivers/base/Kconfig | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index ef38aff737eb..fd96345bc35c 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -71,7 +71,6 @@ config PREVENT_FIRMWARE_BUILD config FW_LOADER tristate "Userspace firmware loading support" if EMBEDDED - depends on HOTPLUG default y ---help--- This option is provided for the case where no in-kernel-tree modules -- cgit v1.2.3 From 7a868088ee48d1816c10f9be6d32aef4cf30bcf7 Mon Sep 17 00:00:00 2001 From: matt mooney Date: Fri, 24 Sep 2010 12:17:11 -0700 Subject: driver-core: base: change to new flag variable Replace EXTRA_CFLAGS with ccflags-y. Signed-off-by: matt mooney Acked-by: WANG Cong Signed-off-by: Greg Kroah-Hartman --- drivers/base/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/Makefile b/drivers/base/Makefile index c12c7f2f2a6f..5f51c3b4451e 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -19,7 +19,5 @@ obj-$(CONFIG_MODULES) += module.o endif obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o -ifeq ($(CONFIG_DEBUG_DRIVER),y) -EXTRA_CFLAGS += -DDEBUG -endif +ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG -- cgit v1.2.3 From ead454feb6cbfe0fa6a1eeb30aa9abc338dacf62 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Fri, 24 Sep 2010 14:36:49 -0700 Subject: driver core: fix build for CONFIG_BLOCK not enabled Fix build errors when CONFIG_BLOCK is not enabled: drivers/base/core.c: In function 'get_device_parent': drivers/base/core.c:634: error: 'block_class' undeclared (first use in this function) drivers/base/core.c: In function 'device_add_class_symlinks': drivers/base/core.c:723: error: 'block_class' undeclared (first use in this function) drivers/base/core.c: In function 'device_remove_class_symlinks': drivers/base/core.c:751: error: 'block_class' undeclared (first use in this function) Signed-off-by: Randy Dunlap Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index f7f906f0a2f2..2cb49a93b1e6 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -630,12 +630,14 @@ static struct kobject *get_device_parent(struct device *dev, struct kobject *parent_kobj; struct kobject *k; +#ifdef CONFIG_BLOCK /* block disks show up in /sys/block */ if (sysfs_deprecated && dev->class == &block_class) { if (parent && parent->class == &block_class) return &parent->kobj; return &block_class.p->class_subsys.kobj; } +#endif /* * If we have no parent, we live in "virtual". @@ -719,9 +721,11 @@ static int device_add_class_symlinks(struct device *dev) goto out_subsys; } +#ifdef CONFIG_BLOCK /* /sys/block has directories and does not need symlinks */ if (sysfs_deprecated && dev->class == &block_class) return 0; +#endif /* link in the class directory pointing to the device */ error = sysfs_create_link(&dev->class->p->class_subsys.kobj, @@ -748,8 +752,10 @@ static void device_remove_class_symlinks(struct device *dev) if (dev->parent && device_is_not_partition(dev)) sysfs_remove_link(&dev->kobj, "device"); sysfs_remove_link(&dev->kobj, "subsystem"); +#ifdef CONFIG_BLOCK if (sysfs_deprecated && dev->class == &block_class) return; +#endif sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); } -- cgit v1.2.3 From 98383031ed77c6eb49ab612166fef9c0efe1604a Mon Sep 17 00:00:00 2001 From: Robin Holt Date: Wed, 29 Sep 2010 14:00:55 -0500 Subject: driver core: Introduce find_memory_block_hinted which utilizes kset_find_obj_hinted. Introduce a find_memory_block_hinted() which utilizes the recently added kset_find_obj_hinted(). Signed-off-by: Robin Holt To: Dave Hansen To: Matt Tolentino Reviewed-by: KAMEZAWA Hiroyuki Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 933442f40321..a7994409b9a5 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -468,28 +468,23 @@ static int add_memory_block(int nid, struct mem_section *section, return ret; } -/* - * For now, we have a linear search to go find the appropriate - * memory_block corresponding to a particular phys_index. If - * this gets to be a real problem, we can always use a radix - * tree or something here. - * - * This could be made generic for all sysdev classes. - */ -struct memory_block *find_memory_block(struct mem_section *section) +struct memory_block *find_memory_block_hinted(struct mem_section *section, + struct memory_block *hint) { struct kobject *kobj; struct sys_device *sysdev; struct memory_block *mem; char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1]; + kobj = hint ? &hint->sysdev.kobj : NULL; + /* * This only works because we know that section == sysdev->id * slightly redundant with sysdev_register() */ sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, __section_nr(section)); - kobj = kset_find_obj(&memory_sysdev_class.kset, name); + kobj = kset_find_obj_hinted(&memory_sysdev_class.kset, name, kobj); if (!kobj) return NULL; @@ -499,6 +494,19 @@ struct memory_block *find_memory_block(struct mem_section *section) return mem; } +/* + * For now, we have a linear search to go find the appropriate + * memory_block corresponding to a particular phys_index. If + * this gets to be a real problem, we can always use a radix + * tree or something here. + * + * This could be made generic for all sysdev classes. + */ +struct memory_block *find_memory_block(struct mem_section *section) +{ + return find_memory_block_hinted(section, NULL); +} + int remove_memory_block(unsigned long node_id, struct mem_section *section, int phys_device) { -- cgit v1.2.3 From 63d027a63888e993545d10fdfe4107d543f01bca Mon Sep 17 00:00:00 2001 From: Robin Holt Date: Wed, 29 Sep 2010 14:00:56 -0500 Subject: driver core: Convert link_mem_sections to use find_memory_block_hinted. Modify link_mem_sections() to pass in the previous mem_block as a hint to locating the next mem_block. Since they are typically added in order this results in a massive saving in time during boot of a very large system. For example, on a 16TB x86_64 machine, it reduced the total time spent linking all node's memory sections from 1 hour, 27 minutes to 46 seconds. Signed-off-by: Robin Holt To: Gary Hade To: Badari Pulavarty To: Ingo Molnar Reviewed-by: KAMEZAWA Hiroyuki Signed-off-by: Greg Kroah-Hartman --- drivers/base/node.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/node.c b/drivers/base/node.c index 2872e86837b2..ee53558b452f 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -409,25 +409,27 @@ static int link_mem_sections(int nid) unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn; unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages; unsigned long pfn; + struct memory_block *mem_blk = NULL; int err = 0; for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { unsigned long section_nr = pfn_to_section_nr(pfn); struct mem_section *mem_sect; - struct memory_block *mem_blk; int ret; if (!present_section_nr(section_nr)) continue; mem_sect = __nr_to_section(section_nr); - mem_blk = find_memory_block(mem_sect); + mem_blk = find_memory_block_hinted(mem_sect, mem_blk); ret = register_mem_sect_under_node(mem_blk, nid); if (!err) err = ret; /* discard ref obtained in find_memory_block() */ - kobject_put(&mem_blk->sysdev.kobj); } + + if (mem_blk) + kobject_put(&mem_blk->sysdev.kobj); return err; } -- cgit v1.2.3 From e4619c857d1d769b1172a75ba6b6ebd1186a9c58 Mon Sep 17 00:00:00 2001 From: Nathan Fontenot Date: Tue, 19 Oct 2010 12:44:20 -0500 Subject: Driver core: Move find_memory_block routine Move the find_memory_block() routine up to avoid needing a forward declaration in subsequent patches. Signed-off-by: Nathan Fontenot Reviewed-by: Robin Holt Reviewed-By: KAMEZAWA Hiroyuki Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 66 +++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index a7994409b9a5..63c25601572d 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -435,39 +435,6 @@ int __weak arch_get_memory_phys_device(unsigned long start_pfn) return 0; } -static int add_memory_block(int nid, struct mem_section *section, - unsigned long state, enum mem_add_context context) -{ - struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL); - unsigned long start_pfn; - int ret = 0; - - if (!mem) - return -ENOMEM; - - mem->phys_index = __section_nr(section); - mem->state = state; - mutex_init(&mem->state_mutex); - start_pfn = section_nr_to_pfn(mem->phys_index); - mem->phys_device = arch_get_memory_phys_device(start_pfn); - - ret = register_memory(mem, section); - if (!ret) - ret = mem_create_simple_file(mem, phys_index); - if (!ret) - ret = mem_create_simple_file(mem, state); - if (!ret) - ret = mem_create_simple_file(mem, phys_device); - if (!ret) - ret = mem_create_simple_file(mem, removable); - if (!ret) { - if (context == HOTPLUG) - ret = register_mem_sect_under_node(mem, nid); - } - - return ret; -} - struct memory_block *find_memory_block_hinted(struct mem_section *section, struct memory_block *hint) { @@ -507,6 +474,39 @@ struct memory_block *find_memory_block(struct mem_section *section) return find_memory_block_hinted(section, NULL); } +static int add_memory_block(int nid, struct mem_section *section, + unsigned long state, enum mem_add_context context) +{ + struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL); + unsigned long start_pfn; + int ret = 0; + + if (!mem) + return -ENOMEM; + + mem->phys_index = __section_nr(section); + mem->state = state; + mutex_init(&mem->state_mutex); + start_pfn = section_nr_to_pfn(mem->phys_index); + mem->phys_device = arch_get_memory_phys_device(start_pfn); + + ret = register_memory(mem, section); + if (!ret) + ret = mem_create_simple_file(mem, phys_index); + if (!ret) + ret = mem_create_simple_file(mem, state); + if (!ret) + ret = mem_create_simple_file(mem, phys_device); + if (!ret) + ret = mem_create_simple_file(mem, removable); + if (!ret) { + if (context == HOTPLUG) + ret = register_mem_sect_under_node(mem, nid); + } + + return ret; +} + int remove_memory_block(unsigned long node_id, struct mem_section *section, int phys_device) { -- cgit v1.2.3 From 2938ffbd466d2811a6012609684a2298eef35065 Mon Sep 17 00:00:00 2001 From: Nathan Fontenot Date: Tue, 19 Oct 2010 12:45:24 -0500 Subject: Driver core: Add mutex for adding/removing memory blocks Add a new mutex for use in adding and removing of memory blocks. This is needed to avoid any race conditions in which the same memory block could be added and removed at the same time. Signed-off-by: Nathan Fontenot Reviewed-by: Robin Holt Reviewed-By: KAMEZAWA Hiroyuki Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 63c25601572d..5185bcff2de9 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -27,6 +27,8 @@ #include #include +static DEFINE_MUTEX(mem_sysfs_mutex); + #define MEMORY_CLASS_NAME "memory" static struct sysdev_class memory_sysdev_class = { @@ -484,6 +486,8 @@ static int add_memory_block(int nid, struct mem_section *section, if (!mem) return -ENOMEM; + mutex_lock(&mem_sysfs_mutex); + mem->phys_index = __section_nr(section); mem->state = state; mutex_init(&mem->state_mutex); @@ -504,6 +508,7 @@ static int add_memory_block(int nid, struct mem_section *section, ret = register_mem_sect_under_node(mem, nid); } + mutex_unlock(&mem_sysfs_mutex); return ret; } @@ -512,6 +517,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section, { struct memory_block *mem; + mutex_lock(&mem_sysfs_mutex); mem = find_memory_block(section); unregister_mem_sect_under_nodes(mem); mem_remove_simple_file(mem, phys_index); @@ -520,6 +526,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section, mem_remove_simple_file(mem, removable); unregister_memory(mem, section); + mutex_unlock(&mem_sysfs_mutex); return 0; } -- cgit v1.2.3 From 07681215975e05a1454b0afdeef07deb0db626ee Mon Sep 17 00:00:00 2001 From: Nathan Fontenot Date: Tue, 19 Oct 2010 12:46:19 -0500 Subject: Driver core: Add section count to memory_block struct Add a section count property to the memory_block struct to track the number of memory sections that have been added/removed from a memory block. This allows us to know when the last memory section of a memory block has been removed so we can remove the memory block. Signed-off-by: Nathan Fontenot Reviewed-by: Robin Holt Reviewed-by: KAMEZAWA Hiroyuki Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 5185bcff2de9..cafeaaf0428f 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -490,6 +490,7 @@ static int add_memory_block(int nid, struct mem_section *section, mem->phys_index = __section_nr(section); mem->state = state; + mem->section_count++; mutex_init(&mem->state_mutex); start_pfn = section_nr_to_pfn(mem->phys_index); mem->phys_device = arch_get_memory_phys_device(start_pfn); @@ -519,12 +520,16 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section, mutex_lock(&mem_sysfs_mutex); mem = find_memory_block(section); - unregister_mem_sect_under_nodes(mem); - mem_remove_simple_file(mem, phys_index); - mem_remove_simple_file(mem, state); - mem_remove_simple_file(mem, phys_device); - mem_remove_simple_file(mem, removable); - unregister_memory(mem, section); + + mem->section_count--; + if (mem->section_count == 0) { + unregister_mem_sect_under_nodes(mem); + mem_remove_simple_file(mem, phys_index); + mem_remove_simple_file(mem, state); + mem_remove_simple_file(mem, phys_device); + mem_remove_simple_file(mem, removable); + unregister_memory(mem, section); + } mutex_unlock(&mem_sysfs_mutex); return 0; -- cgit v1.2.3 From 5abd935661e01289ba143c3b2c1ba300c65bcc5f Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 20 Oct 2010 11:22:42 -0700 Subject: driver core: Display error codes when class suspend fails Aid diagnostics by printing the error code from failed suspends, which doesn't otherwise seem to get displayed. Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/base/sys.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 9354dc10a363..1667aaf4fde6 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -432,13 +432,13 @@ int sysdev_suspend(pm_message_t state) /* resume current sysdev */ cls_driver: drv = NULL; - printk(KERN_ERR "Class suspend failed for %s\n", - kobject_name(&sysdev->kobj)); + printk(KERN_ERR "Class suspend failed for %s: %d\n", + kobject_name(&sysdev->kobj), ret); aux_driver: if (drv) - printk(KERN_ERR "Class driver suspend failed for %s\n", - kobject_name(&sysdev->kobj)); + printk(KERN_ERR "Class driver suspend failed for %s: %d\n", + kobject_name(&sysdev->kobj), ret); list_for_each_entry(err_drv, &cls->drivers, entry) { if (err_drv == drv) break; -- cgit v1.2.3