Commit 5d994b7f authored by Russell King's avatar Russell King Committed by Russell King

[DRIVER MODEL] Fix depca

Release code in driver modules is a potential cause of oopsen.
The device may be in use by a userspace process, which will keep
a reference to the device.  If the module is unloaded, the module
text will be freed.  Subsequently, when the last reference is
dropped, the release code will be called, which no longer exists.

Use generic platform device allocation/release code in modules.
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 37c12e74
...@@ -1470,15 +1470,6 @@ static int __init depca_mca_probe(struct device *device) ...@@ -1470,15 +1470,6 @@ static int __init depca_mca_probe(struct device *device)
** ISA bus I/O device probe ** ISA bus I/O device probe
*/ */
static void depca_platform_release (struct device *device)
{
struct platform_device *pldev;
/* free device */
pldev = to_platform_device (device);
kfree (pldev);
}
static void __init depca_platform_probe (void) static void __init depca_platform_probe (void)
{ {
int i; int i;
...@@ -1491,19 +1482,16 @@ static void __init depca_platform_probe (void) ...@@ -1491,19 +1482,16 @@ static void __init depca_platform_probe (void)
* line, use it (if valid) */ * line, use it (if valid) */
if (io && io != depca_io_ports[i].iobase) if (io && io != depca_io_ports[i].iobase)
continue; continue;
if (!(pldev = kmalloc (sizeof (*pldev), GFP_KERNEL))) pldev = platform_device_alloc(depca_string, i);
if (!pldev)
continue; continue;
memset (pldev, 0, sizeof (*pldev));
pldev->name = depca_string;
pldev->id = i;
pldev->dev.platform_data = (void *) depca_io_ports[i].iobase; pldev->dev.platform_data = (void *) depca_io_ports[i].iobase;
pldev->dev.release = depca_platform_release;
depca_io_ports[i].device = pldev; depca_io_ports[i].device = pldev;
if (platform_device_register (pldev)) { if (platform_device_add(pldev)) {
kfree (pldev); platform_device_put(pldev);
depca_io_ports[i].device = NULL; depca_io_ports[i].device = NULL;
continue; continue;
} }
...@@ -1515,6 +1503,7 @@ static void __init depca_platform_probe (void) ...@@ -1515,6 +1503,7 @@ static void __init depca_platform_probe (void)
* allocated structure */ * allocated structure */
depca_io_ports[i].device = NULL; depca_io_ports[i].device = NULL;
pldev->dev.platform_data = NULL;
platform_device_unregister (pldev); platform_device_unregister (pldev);
} }
} }
...@@ -2112,6 +2101,7 @@ static void __exit depca_module_exit (void) ...@@ -2112,6 +2101,7 @@ static void __exit depca_module_exit (void)
for (i = 0; depca_io_ports[i].iobase; i++) { for (i = 0; depca_io_ports[i].iobase; i++) {
if (depca_io_ports[i].device) { if (depca_io_ports[i].device) {
depca_io_ports[i].device->dev.platform_data = NULL;
platform_device_unregister (depca_io_ports[i].device); platform_device_unregister (depca_io_ports[i].device);
depca_io_ports[i].device = NULL; depca_io_ports[i].device = NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment