From 05212157e94ccf4cf458413bbba509cfa95ff92b Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Tue, 8 Jun 2010 07:48:20 -0600 Subject: drivercore/of: Add OF style matching to platform bus As part of the merge between platform bus and of_platform bus, add the ability to do of-style matching to the platform bus. Signed-off-by: Grant Likely Acked-by: Greg Kroah-Hartman CC: Michal Simek CC: Grant Likely CC: Benjamin Herrenschmidt CC: Stephen Rothwell CC: linux-kernel@vger.kernel.org CC: microblaze-uclinux@itee.uq.edu.au CC: linuxppc-dev@ozlabs.org CC: devicetree-discuss@lists.ozlabs.org --- drivers/base/platform.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 4d99c8bdfedc..fac3633c7223 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -673,7 +674,11 @@ static int platform_match(struct device *dev, struct device_driver *drv) struct platform_device *pdev = to_platform_device(dev); struct platform_driver *pdrv = to_platform_driver(drv); - /* match against the id table first */ + /* Attempt an OF style match first */ + if (of_driver_match_device(dev, drv)) + return 1; + + /* Then try to match against the id table */ if (pdrv->id_table) return platform_match_id(pdrv->id_table, pdev) != NULL; -- cgit v1.2.3 From eca3930163ba8884060ce9d9ff5ef0d9b7c7b00f Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Tue, 8 Jun 2010 07:48:21 -0600 Subject: of: Merge of_platform_bus_type with platform_bus_type of_platform_bus was being used in the same manner as the platform_bus. The only difference being that of_platform_bus devices are generated from data in the device tree, and platform_bus devices are usually statically allocated in platform code. Having them separate causes the problem of device drivers having to be registered twice if it was possible for the same device to appear on either bus. This patch removes of_platform_bus_type and registers all of_platform bus devices and drivers on the platform bus instead. A previous patch made the of_device structure an alias for the platform_device structure, and a shim is used to adapt of_platform_drivers to the platform bus. After all of of_platform_bus drivers are converted to be normal platform drivers, the shim code can be removed. Signed-off-by: Grant Likely Acked-by: David S. Miller --- drivers/base/platform.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index fac3633c7223..f699fabf403b 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -636,6 +636,12 @@ static struct device_attribute platform_dev_attrs[] = { static int platform_uevent(struct device *dev, struct kobj_uevent_env *env) { struct platform_device *pdev = to_platform_device(dev); + int rc; + + /* Some devices have extra OF data and an OF-style MODALIAS */ + rc = of_device_uevent(dev,env); + if (rc != -ENODEV) + return rc; add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX, (pdev->id_entry) ? pdev->id_entry->name : pdev->name); -- cgit v1.2.3 From ed1d218c95c6846416ddb39085b20a5b3c0872e4 Mon Sep 17 00:00:00 2001 From: Marin Mitov Date: Mon, 31 May 2010 13:03:04 +0300 Subject: Driver core: internal struct dma_coherent_mem, change type of a member. struct dma_coherent_mem in drivers/base/dma-coherent.c has member 'device_base' that is of type u32, but is assigned value of type dma_addr_t, which may be 64 bits for x86_64. Change the type to dma_addr_t. Signed-off-by: Marin Mitov Signed-off-by: Greg Kroah-Hartman --- drivers/base/dma-coherent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c index d4d8ce53886a..f369e2795985 100644 --- a/drivers/base/dma-coherent.c +++ b/drivers/base/dma-coherent.c @@ -8,7 +8,7 @@ struct dma_coherent_mem { void *virt_base; - u32 device_base; + dma_addr_t device_base; int size; int flags; unsigned long *bitmap; -- cgit v1.2.3 From 0983ca2d0f0ff645bc86899aefb936cffb314839 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 4 Jun 2010 00:54:37 -0700 Subject: firmware loader: use statically initialized data attribute There is no reason why we are using a template for binary attribute and copying it into per-firmware data before registering. Using the original works as well. Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware_class.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 3f093b0dd217..fb29c64ebecc 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -87,7 +87,6 @@ static DEFINE_MUTEX(fw_lock); struct firmware_priv { struct completion completion; - struct bin_attribute attr_data; struct firmware *fw; unsigned long status; struct page **pages; @@ -420,8 +419,8 @@ out: return retval; } -static struct bin_attribute firmware_attr_data_tmpl = { - .attr = {.name = "data", .mode = 0644}, +static struct bin_attribute firmware_attr_data = { + .attr = { .name = "data", .mode = 0644 }, .size = 0, .read = firmware_data_read, .write = firmware_data_write, @@ -452,7 +451,6 @@ static int fw_register_device(struct device **dev_p, const char *fw_name, strcpy(fw_priv->fw_id, fw_name); init_completion(&fw_priv->completion); - fw_priv->attr_data = firmware_attr_data_tmpl; fw_priv->timeout.function = firmware_class_timeout; fw_priv->timeout.data = (u_long) fw_priv; init_timer(&fw_priv->timeout); @@ -498,8 +496,7 @@ static int fw_setup_device(struct firmware *fw, struct device **dev_p, fw_priv->nowait = nowait; fw_priv->fw = fw; - sysfs_bin_attr_init(&fw_priv->attr_data); - retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data); + retval = sysfs_create_bin_file(&f_dev->kobj, &firmware_attr_data); if (retval) { dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__); goto error_unreg; -- cgit v1.2.3 From f8a4bd3456b988fc73b2c291b9e01b434c8fa940 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 4 Jun 2010 00:54:43 -0700 Subject: firmware loader: embed device into firmware_priv structure Both these structures have the same lifetime rules so instead of allocating and managing them separately embed struct device into struct firmware_priv. Also make sure to delete sysfs attributes ourselves instead of expecting sysfs to clean up our mess. Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware_class.c | 255 ++++++++++++++++++++---------------------- 1 file changed, 122 insertions(+), 133 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index fb29c64ebecc..c8a44f5e0584 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -93,22 +93,26 @@ struct firmware_priv { int nr_pages; int page_array_size; struct timer_list timeout; + struct device dev; bool nowait; char fw_id[]; }; -static void -fw_load_abort(struct firmware_priv *fw_priv) +static struct firmware_priv *to_firmware_priv(struct device *dev) +{ + return container_of(dev, struct firmware_priv, dev); +} + +static void fw_load_abort(struct firmware_priv *fw_priv) { set_bit(FW_STATUS_ABORT, &fw_priv->status); wmb(); complete(&fw_priv->completion); } -static ssize_t -firmware_timeout_show(struct class *class, - struct class_attribute *attr, - char *buf) +static ssize_t firmware_timeout_show(struct class *class, + struct class_attribute *attr, + char *buf) { return sprintf(buf, "%d\n", loading_timeout); } @@ -126,14 +130,14 @@ 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 firmware_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) loading_timeout = 0; + return count; } @@ -145,21 +149,20 @@ static struct class_attribute firmware_class_attrs[] = { static void fw_dev_release(struct device *dev) { - struct firmware_priv *fw_priv = dev_get_drvdata(dev); + struct firmware_priv *fw_priv = to_firmware_priv(dev); int i; for (i = 0; i < fw_priv->nr_pages; i++) __free_page(fw_priv->pages[i]); kfree(fw_priv->pages); kfree(fw_priv); - kfree(dev); module_put(THIS_MODULE); } static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env) { - struct firmware_priv *fw_priv = dev_get_drvdata(dev); + struct firmware_priv *fw_priv = to_firmware_priv(dev); if (add_uevent_var(env, "FIRMWARE=%s", fw_priv->fw_id)) return -ENOMEM; @@ -181,8 +184,9 @@ static struct class firmware_class = { static ssize_t firmware_loading_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct firmware_priv *fw_priv = dev_get_drvdata(dev); + struct firmware_priv *fw_priv = to_firmware_priv(dev); int loading = test_bit(FW_STATUS_LOADING, &fw_priv->status); + return sprintf(buf, "%d\n", loading); } @@ -218,7 +222,7 @@ static ssize_t firmware_loading_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct firmware_priv *fw_priv = dev_get_drvdata(dev); + struct firmware_priv *fw_priv = to_firmware_priv(dev); int loading = simple_strtol(buf, NULL, 10); int i; @@ -276,13 +280,12 @@ static ssize_t firmware_loading_store(struct device *dev, static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store); -static ssize_t -firmware_data_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buffer, loff_t offset, - size_t count) +static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buffer, loff_t offset, size_t count) { struct device *dev = to_dev(kobj); - struct firmware_priv *fw_priv = dev_get_drvdata(dev); + struct firmware_priv *fw_priv = to_firmware_priv(dev); struct firmware *fw; ssize_t ret_count; @@ -321,8 +324,7 @@ out: return ret_count; } -static int -fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size) +static int fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size) { int pages_needed = ALIGN(min_size, PAGE_SIZE) >> PAGE_SHIFT; @@ -372,13 +374,12 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size) * Data written to the 'data' attribute will be later handed to * the driver as a firmware image. **/ -static ssize_t -firmware_data_write(struct file* filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buffer, - loff_t offset, size_t count) +static ssize_t firmware_data_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buffer, loff_t offset, size_t count) { struct device *dev = to_dev(kobj); - struct firmware_priv *fw_priv = dev_get_drvdata(dev); + struct firmware_priv *fw_priv = to_firmware_priv(dev); struct firmware *fw; ssize_t retval; @@ -426,107 +427,96 @@ static struct bin_attribute firmware_attr_data = { .write = firmware_data_write, }; -static void -firmware_class_timeout(u_long data) +static void firmware_class_timeout(u_long data) { struct firmware_priv *fw_priv = (struct firmware_priv *) data; + fw_load_abort(fw_priv); } -static int fw_register_device(struct device **dev_p, const char *fw_name, - struct device *device) +static struct firmware_priv * +fw_create_instance(struct firmware *firmware, const char *fw_name, + struct device *device, bool uevent, bool nowait) { - int retval; - struct firmware_priv *fw_priv = - kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL); - struct device *f_dev = kzalloc(sizeof(*f_dev), GFP_KERNEL); - - *dev_p = NULL; + struct firmware_priv *fw_priv; + struct device *f_dev; + int error; - if (!fw_priv || !f_dev) { + fw_priv = kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL); + if (!fw_priv) { dev_err(device, "%s: kmalloc failed\n", __func__); - retval = -ENOMEM; - goto error_kfree; + error = -ENOMEM; + goto err_out; } + fw_priv->fw = firmware; + fw_priv->nowait = nowait; strcpy(fw_priv->fw_id, fw_name); init_completion(&fw_priv->completion); - fw_priv->timeout.function = firmware_class_timeout; - fw_priv->timeout.data = (u_long) fw_priv; - init_timer(&fw_priv->timeout); + setup_timer(&fw_priv->timeout, + firmware_class_timeout, (u_long) fw_priv); + f_dev = &fw_priv->dev; + + device_initialize(f_dev); dev_set_name(f_dev, "%s", dev_name(device)); f_dev->parent = device; f_dev->class = &firmware_class; - dev_set_drvdata(f_dev, fw_priv); - dev_set_uevent_suppress(f_dev, 1); - retval = device_register(f_dev); - if (retval) { - dev_err(device, "%s: device_register failed\n", __func__); - put_device(f_dev); - return retval; - } - *dev_p = f_dev; - return 0; - -error_kfree: - kfree(f_dev); - kfree(fw_priv); - return retval; -} -static int fw_setup_device(struct firmware *fw, struct device **dev_p, - const char *fw_name, struct device *device, - int uevent, bool nowait) -{ - struct device *f_dev; - struct firmware_priv *fw_priv; - int retval; - - *dev_p = NULL; - retval = fw_register_device(&f_dev, fw_name, device); - if (retval) - goto out; + dev_set_uevent_suppress(f_dev, true); /* Need to pin this module until class device is destroyed */ __module_get(THIS_MODULE); - fw_priv = dev_get_drvdata(f_dev); - - fw_priv->nowait = nowait; + error = device_add(f_dev); + if (error) { + dev_err(device, "%s: device_register failed\n", __func__); + goto err_put_dev; + } - fw_priv->fw = fw; - retval = sysfs_create_bin_file(&f_dev->kobj, &firmware_attr_data); - if (retval) { + error = device_create_bin_file(f_dev, &firmware_attr_data); + if (error) { dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__); - goto error_unreg; + goto err_del_dev; } - retval = device_create_file(f_dev, &dev_attr_loading); - if (retval) { + error = device_create_file(f_dev, &dev_attr_loading); + if (error) { dev_err(device, "%s: device_create_file failed\n", __func__); - goto error_unreg; + goto err_del_bin_attr; } if (uevent) - dev_set_uevent_suppress(f_dev, 0); - *dev_p = f_dev; - goto out; + dev_set_uevent_suppress(f_dev, false); + + return fw_priv; + +err_del_bin_attr: + device_remove_bin_file(f_dev, &firmware_attr_data); +err_del_dev: + device_del(f_dev); +err_put_dev: + put_device(f_dev); +err_out: + return ERR_PTR(error); +} + +static void fw_destroy_instance(struct firmware_priv *fw_priv) +{ + struct device *f_dev = &fw_priv->dev; -error_unreg: + device_remove_file(f_dev, &dev_attr_loading); + device_remove_bin_file(f_dev, &firmware_attr_data); device_unregister(f_dev); -out: - return retval; } -static int -_request_firmware(const struct firmware **firmware_p, const char *name, - struct device *device, int uevent, bool nowait) +static int _request_firmware(const struct firmware **firmware_p, + const char *name, struct device *device, + bool uevent, bool nowait) { - struct device *f_dev; struct firmware_priv *fw_priv; struct firmware *firmware; - int retval; + int retval = 0; if (!firmware_p) return -EINVAL; @@ -547,41 +537,40 @@ _request_firmware(const struct firmware **firmware_p, const char *name, if (uevent) dev_dbg(device, "firmware: requesting %s\n", name); - retval = fw_setup_device(firmware, &f_dev, name, device, - uevent, nowait); - if (retval) - goto error_kfree_fw; - - fw_priv = dev_get_drvdata(f_dev); + fw_priv = fw_create_instance(firmware, name, device, uevent, nowait); + if (IS_ERR(fw_priv)) { + retval = PTR_ERR(fw_priv); + goto out; + } if (uevent) { - if (loading_timeout > 0) { - fw_priv->timeout.expires = jiffies + loading_timeout * HZ; - add_timer(&fw_priv->timeout); - } + if (loading_timeout > 0) + mod_timer(&fw_priv->timeout, + round_jiffies_up(jiffies + + loading_timeout * HZ)); + + kobject_uevent(&fw_priv->dev.kobj, KOBJ_ADD); + } + + wait_for_completion(&fw_priv->completion); - kobject_uevent(&f_dev->kobj, KOBJ_ADD); - wait_for_completion(&fw_priv->completion); - set_bit(FW_STATUS_DONE, &fw_priv->status); - del_timer_sync(&fw_priv->timeout); - } else - wait_for_completion(&fw_priv->completion); + set_bit(FW_STATUS_DONE, &fw_priv->status); + del_timer_sync(&fw_priv->timeout); mutex_lock(&fw_lock); - if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status)) { + if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status)) retval = -ENOENT; - release_firmware(fw_priv->fw); - *firmware_p = NULL; - } fw_priv->fw = NULL; mutex_unlock(&fw_lock); - device_unregister(f_dev); - goto out; -error_kfree_fw: - kfree(firmware); - *firmware_p = NULL; + fw_destroy_instance(fw_priv); + out: + if (retval) { + release_firmware(firmware); + firmware_p = NULL; + } + return retval; } @@ -632,23 +621,24 @@ struct firmware_work { int uevent; }; -static int -request_firmware_work_func(void *arg) +static int request_firmware_work_func(void *arg) { struct firmware_work *fw_work = arg; const struct firmware *fw; int ret; + if (!arg) { WARN_ON(1); return 0; } - ret = _request_firmware(&fw, fw_work->name, fw_work->device, - fw_work->uevent, true); + ret = _request_firmware(&fw, fw_work->name, fw_work->device, + fw_work->uevent, true); fw_work->cont(fw, fw_work->context); module_put(fw_work->module); kfree(fw_work); + return ret; } @@ -676,34 +666,33 @@ request_firmware_nowait( void (*cont)(const struct firmware *fw, void *context)) { struct task_struct *task; - struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work), - gfp); + struct firmware_work *fw_work; + fw_work = kzalloc(sizeof (struct firmware_work), gfp); if (!fw_work) return -ENOMEM; + + fw_work->module = module; + fw_work->name = name; + fw_work->device = device; + fw_work->context = context; + fw_work->cont = cont; + fw_work->uevent = uevent; + if (!try_module_get(module)) { kfree(fw_work); return -EFAULT; } - *fw_work = (struct firmware_work) { - .module = module, - .name = name, - .device = device, - .context = context, - .cont = cont, - .uevent = uevent, - }; - task = kthread_run(request_firmware_work_func, fw_work, "firmware/%s", name); - if (IS_ERR(task)) { fw_work->cont(NULL, fw_work->context); module_put(fw_work->module); kfree(fw_work); return PTR_ERR(task); } + return 0; } -- cgit v1.2.3 From 3e61dfd8509a52d165726831c57b4c8a015d626c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Tue, 15 Jun 2010 10:47:55 +0200 Subject: Driver core: use kmemdup in platform_device_add_resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes platform_device_add_resources look like platform_device_add_data. Signed-off-by: Uwe Kleine-König Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 4d99c8bdfedc..26eb69d88eb6 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -191,13 +191,13 @@ int platform_device_add_resources(struct platform_device *pdev, { struct resource *r; - r = kmalloc(sizeof(struct resource) * num, GFP_KERNEL); + r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL); if (r) { - memcpy(r, res, sizeof(struct resource) * num); pdev->resource = r; pdev->num_resources = num; + return 0; } - return r ? 0 : -ENOMEM; + return -ENOMEM; } EXPORT_SYMBOL_GPL(platform_device_add_resources); -- cgit v1.2.3 From 44f28bdea09415d40b4d73a7668db5961362ec53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Mon, 21 Jun 2010 16:11:44 +0200 Subject: Driver core: reduce duplicated code for platform_device creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the two similar functions platform_device_register_simple and platform_device_register_data one line inline functions using a new generic function platform_device_register_resndata. Signed-off-by: Uwe Kleine-König Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 104 ++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 78 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 26eb69d88eb6..ffcfd73fe8a6 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -344,108 +344,56 @@ void platform_device_unregister(struct platform_device *pdev) EXPORT_SYMBOL_GPL(platform_device_unregister); /** - * platform_device_register_simple - add a platform-level device and its resources - * @name: base name of the device we're adding - * @id: instance id - * @res: set of resources that needs to be allocated for the device - * @num: number of resources - * - * This function creates a simple platform device that requires minimal - * resource and memory management. Canned release function freeing memory - * allocated for the device allows drivers using such devices to be - * unloaded without waiting for the last reference to the device to be - * dropped. + * platform_device_register_resndata - add a platform-level device with + * resources and platform-specific data * - * This interface is primarily intended for use with legacy drivers which - * probe hardware directly. Because such drivers create sysfs device nodes - * themselves, rather than letting system infrastructure handle such device - * enumeration tasks, they don't fully conform to the Linux driver model. - * In particular, when such drivers are built as modules, they can't be - * "hotplugged". - * - * Returns &struct platform_device pointer on success, or ERR_PTR() on error. - */ -struct platform_device *platform_device_register_simple(const char *name, - int id, - const struct resource *res, - unsigned int num) -{ - struct platform_device *pdev; - int retval; - - pdev = platform_device_alloc(name, id); - if (!pdev) { - retval = -ENOMEM; - goto error; - } - - if (num) { - retval = platform_device_add_resources(pdev, res, num); - if (retval) - goto error; - } - - retval = platform_device_add(pdev); - if (retval) - goto error; - - return pdev; - -error: - platform_device_put(pdev); - return ERR_PTR(retval); -} -EXPORT_SYMBOL_GPL(platform_device_register_simple); - -/** - * platform_device_register_data - add a platform-level device with platform-specific data * @parent: parent device for the device we're adding * @name: base name of the device we're adding * @id: instance id + * @res: set of resources that needs to be allocated for the device + * @num: number of resources * @data: platform specific data for this platform device * @size: size of platform specific data * - * This function creates a simple platform device that requires minimal - * resource and memory management. Canned release function freeing memory - * allocated for the device allows drivers using such devices to be - * unloaded without waiting for the last reference to the device to be - * dropped. - * * Returns &struct platform_device pointer on success, or ERR_PTR() on error. */ -struct platform_device *platform_device_register_data( +struct platform_device *platform_device_register_resndata( struct device *parent, const char *name, int id, + const struct resource *res, unsigned int num, const void *data, size_t size) { + int ret = -ENOMEM; struct platform_device *pdev; - int retval; pdev = platform_device_alloc(name, id); - if (!pdev) { - retval = -ENOMEM; - goto error; - } + if (!pdev) + goto err; pdev->dev.parent = parent; - if (size) { - retval = platform_device_add_data(pdev, data, size); - if (retval) - goto error; + if (res) { + ret = platform_device_add_resources(pdev, res, num); + if (ret) + goto err; } - retval = platform_device_add(pdev); - if (retval) - goto error; + if (data) { + ret = platform_device_add_data(pdev, data, size); + if (ret) + goto err; + } - return pdev; + ret = platform_device_add(pdev); + if (ret) { +err: + platform_device_put(pdev); + return ERR_PTR(ret); + } -error: - platform_device_put(pdev); - return ERR_PTR(retval); + return pdev; } -EXPORT_SYMBOL_GPL(platform_device_register_data); +EXPORT_SYMBOL_GPL(platform_device_register_resndata); static int platform_drv_probe(struct device *_dev) { -- cgit v1.2.3 From 737a3bb9416ce2a7c7a4170852473a4fcc9c67e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Mon, 21 Jun 2010 16:11:45 +0200 Subject: Driver core: move platform device creation helpers to .init.text (if MODULE=n) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Platform devices should only be called by init code, so it should be possible to move creation helpers to .init.text -- at least if modules are disabled. Signed-off-by: Uwe Kleine-König Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index ffcfd73fe8a6..1bb8faaa443f 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -357,7 +357,7 @@ EXPORT_SYMBOL_GPL(platform_device_unregister); * * Returns &struct platform_device pointer on success, or ERR_PTR() on error. */ -struct platform_device *platform_device_register_resndata( +struct platform_device *__init_or_module platform_device_register_resndata( struct device *parent, const char *name, int id, const struct resource *res, unsigned int num, -- cgit v1.2.3 From 600c20f34f645adf7884277302b10601583aa7d5 Mon Sep 17 00:00:00 2001 From: Jike Song Date: Thu, 15 Jul 2010 17:43:54 +0800 Subject: driver core: fix memory leak on one error path in bus_register() Reported-by: huangweibing@gmail.com Signed-off-by: Jike Song Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 12eec3f633b1..eb1b7fa20dce 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -945,8 +945,8 @@ bus_devices_fail: bus_remove_file(bus, &bus_attr_uevent); bus_uevent_fail: kset_unregister(&bus->p->subsys); - kfree(bus->p); out: + kfree(bus->p); bus->p = NULL; return retval; } -- cgit v1.2.3 From 45daef0fdcc44f6af86fdebc4fc7eb7c79375398 Mon Sep 17 00:00:00 2001 From: Magnus Damm Date: Fri, 23 Jul 2010 19:56:18 +0900 Subject: Driver core: Add BUS_NOTIFY_BIND_DRIVER Add BUS_NOTIFY_BIND_DRIVER as a bus notifier event. For driver binding/unbinding we with this in place have the following bus notifier events: - BUS_NOTIFY_BIND_DRIVER - before ->probe() - BUS_NOTIFY_BOUND_DRIVER - after ->probe() - BUS_NOTIFY_UNBIND_DRIVER - before ->remove() - BUS_NOTIFY_UNBOUND_DRIVER - after ->remove() The event BUS_NOTIFY_BIND_DRIVER allows bus code to be notified that ->probe() is about to be called. Useful for bus code that needs to setup hardware before the driver gets to run. With this in place platform drivers can be loaded and unloaded as modules and the new BIND event allows bus code to control for instance device clocks that must be enabled before the driver can be executed. Without this patch there is no way for the bus code to get notified that a modular driver is about to be probed. Signed-off-by: Magnus Damm Signed-off-by: Greg Kroah-Hartman --- drivers/base/dd.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 503c2620bbcc..da57ee9d63fe 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -51,6 +51,10 @@ static int driver_sysfs_add(struct device *dev) { int ret; + if (dev->bus) + blocking_notifier_call_chain(&dev->bus->p->bus_notifier, + BUS_NOTIFY_BIND_DRIVER, dev); + ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, kobject_name(&dev->kobj)); if (ret == 0) { -- cgit v1.2.3 From 6937e8f8c0135f2325194c372ada6dc655499992 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Thu, 5 Aug 2010 17:38:18 +0200 Subject: driver core: device_rename's new_name can be const The new_name argument to device_rename() can be const as kobject_rename's new_name argument is. Signed-off-by: Johannes Berg 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 f8e72724dd4b..d1b2c9adc271 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1599,7 +1599,7 @@ EXPORT_SYMBOL_GPL(device_destroy); * on the same device to ensure that new_name is valid and * won't conflict with other devices. */ -int device_rename(struct device *dev, char *new_name) +int device_rename(struct device *dev, const char *new_name) { char *old_class_name = NULL; char *new_class_name = NULL; -- cgit v1.2.3 From 7ee92255470daa0edb93866aec6e27534cd9a177 Mon Sep 17 00:00:00 2001 From: KOSAKI Motohiro Date: Mon, 9 Aug 2010 17:19:50 -0700 Subject: drivers/base/node.c: reduce stack usage of node_read_meminfo() drivers/base/node.c: In function 'node_read_meminfo': drivers/base/node.c:139: warning: the frame size of 848 bytes is larger than 512 bytes Fix it by splitting the sprintf() into three parts. It has no functional change. Signed-off-by: KOSAKI Motohiro Cc: Greg KH Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/base/node.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/node.c b/drivers/base/node.c index 2bdd8a94ec94..2872e86837b2 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -66,8 +66,7 @@ static ssize_t node_read_meminfo(struct sys_device * dev, struct sysinfo i; si_meminfo_node(&i, nid); - - n = sprintf(buf, "\n" + n = sprintf(buf, "Node %d MemTotal: %8lu kB\n" "Node %d MemFree: %8lu kB\n" "Node %d MemUsed: %8lu kB\n" @@ -78,13 +77,33 @@ static ssize_t node_read_meminfo(struct sys_device * dev, "Node %d Active(file): %8lu kB\n" "Node %d Inactive(file): %8lu kB\n" "Node %d Unevictable: %8lu kB\n" - "Node %d Mlocked: %8lu kB\n" + "Node %d Mlocked: %8lu kB\n", + nid, K(i.totalram), + nid, K(i.freeram), + nid, K(i.totalram - i.freeram), + nid, K(node_page_state(nid, NR_ACTIVE_ANON) + + node_page_state(nid, NR_ACTIVE_FILE)), + nid, K(node_page_state(nid, NR_INACTIVE_ANON) + + node_page_state(nid, NR_INACTIVE_FILE)), + nid, K(node_page_state(nid, NR_ACTIVE_ANON)), + nid, K(node_page_state(nid, NR_INACTIVE_ANON)), + nid, K(node_page_state(nid, NR_ACTIVE_FILE)), + nid, K(node_page_state(nid, NR_INACTIVE_FILE)), + nid, K(node_page_state(nid, NR_UNEVICTABLE)), + nid, K(node_page_state(nid, NR_MLOCK))); + #ifdef CONFIG_HIGHMEM + n += sprintf(buf + n, "Node %d HighTotal: %8lu kB\n" "Node %d HighFree: %8lu kB\n" "Node %d LowTotal: %8lu kB\n" - "Node %d LowFree: %8lu kB\n" + "Node %d LowFree: %8lu kB\n", + nid, K(i.totalhigh), + nid, K(i.freehigh), + nid, K(i.totalram - i.totalhigh), + nid, K(i.freeram - i.freehigh)); #endif + n += sprintf(buf + n, "Node %d Dirty: %8lu kB\n" "Node %d Writeback: %8lu kB\n" "Node %d FilePages: %8lu kB\n" @@ -99,25 +118,6 @@ static ssize_t node_read_meminfo(struct sys_device * dev, "Node %d Slab: %8lu kB\n" "Node %d SReclaimable: %8lu kB\n" "Node %d SUnreclaim: %8lu kB\n", - nid, K(i.totalram), - nid, K(i.freeram), - nid, K(i.totalram - i.freeram), - nid, K(node_page_state(nid, NR_ACTIVE_ANON) + - node_page_state(nid, NR_ACTIVE_FILE)), - nid, K(node_page_state(nid, NR_INACTIVE_ANON) + - node_page_state(nid, NR_INACTIVE_FILE)), - nid, K(node_page_state(nid, NR_ACTIVE_ANON)), - nid, K(node_page_state(nid, NR_INACTIVE_ANON)), - nid, K(node_page_state(nid, NR_ACTIVE_FILE)), - nid, K(node_page_state(nid, NR_INACTIVE_FILE)), - nid, K(node_page_state(nid, NR_UNEVICTABLE)), - nid, K(node_page_state(nid, NR_MLOCK)), -#ifdef CONFIG_HIGHMEM - nid, K(i.totalhigh), - nid, K(i.freehigh), - nid, K(i.totalram - i.totalhigh), - nid, K(i.freeram - i.freehigh), -#endif nid, K(node_page_state(nid, NR_FILE_DIRTY)), nid, K(node_page_state(nid, NR_WRITEBACK)), nid, K(node_page_state(nid, NR_FILE_PAGES)), -- cgit v1.2.3