Skip to content

Commit

Permalink
[DRIVER MODEL] Fix macsonic
Browse files Browse the repository at this point in the history
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: Russell King <rmk+kernel@arm.linux.org.uk>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Russell King authored and Russell King committed Nov 5, 2005
1 parent 95cb5d9 commit 09c6518
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions drivers/net/macsonic.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,46 +599,29 @@ static struct device_driver mac_sonic_driver = {
.remove = __devexit_p(mac_sonic_device_remove),
};

static void mac_sonic_platform_release(struct device *device)
{
struct platform_device *pldev;

/* free device */
pldev = to_platform_device (device);
kfree (pldev);
}

static int __init mac_sonic_init_module(void)
{
struct platform_device *pldev;
int err;

if ((err = driver_register(&mac_sonic_driver))) {
printk(KERN_ERR "Driver registration failed\n");
return err;
}

mac_sonic_device = NULL;

if (!(pldev = kmalloc (sizeof (*pldev), GFP_KERNEL))) {
mac_sonic_device = platform_device_alloc(mac_sonic_string, 0);
if (!mac_sonic_device) {
goto out_unregister;
}

memset(pldev, 0, sizeof (*pldev));
pldev->name = mac_sonic_string;
pldev->id = 0;
pldev->dev.release = mac_sonic_platform_release;
mac_sonic_device = pldev;

if (platform_device_register (pldev)) {
kfree(pldev);
if (platform_device_add(mac_sonic_device)) {
platform_device_put(mac_sonic_device);
mac_sonic_device = NULL;
}

return 0;

out_unregister:
platform_device_unregister(pldev);
driver_unregister(&mac_sonic_driver);

return -ENOMEM;
}
Expand Down

0 comments on commit 09c6518

Please sign in to comment.