aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorRussell King <rmk@dyn-67.arm.linux.org.uk>2005-11-05 16:21:10 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2005-11-05 16:21:10 -0500
commit09c6518ca0de24549a923891b2d335e8496d79a9 (patch)
tree0088dfdc7ef26d6a5c9d63d3fdffc1a2319356e9 /drivers/net
parent95cb5d954ee656a0b048ea2298188569e0759336 (diff)
[DRIVER MODEL] Fix macsonic
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>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/macsonic.c27
1 files changed, 5 insertions, 22 deletions
diff --git a/drivers/net/macsonic.c b/drivers/net/macsonic.c
index e9c999d7eb39..9ef4592aca03 100644
--- a/drivers/net/macsonic.c
+++ b/drivers/net/macsonic.c
@@ -599,18 +599,8 @@ static struct device_driver mac_sonic_driver = {
599 .remove = __devexit_p(mac_sonic_device_remove), 599 .remove = __devexit_p(mac_sonic_device_remove),
600}; 600};
601 601
602static void mac_sonic_platform_release(struct device *device)
603{
604 struct platform_device *pldev;
605
606 /* free device */
607 pldev = to_platform_device (device);
608 kfree (pldev);
609}
610
611static int __init mac_sonic_init_module(void) 602static int __init mac_sonic_init_module(void)
612{ 603{
613 struct platform_device *pldev;
614 int err; 604 int err;
615 605
616 if ((err = driver_register(&mac_sonic_driver))) { 606 if ((err = driver_register(&mac_sonic_driver))) {
@@ -618,27 +608,20 @@ static int __init mac_sonic_init_module(void)
618 return err; 608 return err;
619 } 609 }
620 610
621 mac_sonic_device = NULL; 611 mac_sonic_device = platform_device_alloc(mac_sonic_string, 0);
622 612 if (!mac_sonic_device) {
623 if (!(pldev = kmalloc (sizeof (*pldev), GFP_KERNEL))) {
624 goto out_unregister; 613 goto out_unregister;
625 } 614 }
626 615
627 memset(pldev, 0, sizeof (*pldev)); 616 if (platform_device_add(mac_sonic_device)) {
628 pldev->name = mac_sonic_string; 617 platform_device_put(mac_sonic_device);
629 pldev->id = 0;
630 pldev->dev.release = mac_sonic_platform_release;
631 mac_sonic_device = pldev;
632
633 if (platform_device_register (pldev)) {
634 kfree(pldev);
635 mac_sonic_device = NULL; 618 mac_sonic_device = NULL;
636 } 619 }
637 620
638 return 0; 621 return 0;
639 622
640out_unregister: 623out_unregister:
641 platform_device_unregister(pldev); 624 driver_unregister(&mac_sonic_driver);
642 625
643 return -ENOMEM; 626 return -ENOMEM;
644} 627}