From: Russell King <rmk+lkml@arm.linux.org.uk>
To: Linux Kernel List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] [DRIVER MODEL] Fix macsonic
Date: Sat, 5 Nov 2005 10:58:53 +0000 [thread overview]
Message-ID: <20051105105853.GC30315@flint.arm.linux.org.uk> (raw)
In-Reply-To: <20051105105628.GE28438@flint.arm.linux.org.uk>
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>
diff --git a/drivers/net/macsonic.c b/drivers/net/macsonic.c
--- a/drivers/net/macsonic.c
+++ b/drivers/net/macsonic.c
@@ -599,18 +599,8 @@ static struct device_driver mac_sonic_dr
.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))) {
@@ -618,27 +608,20 @@ static int __init mac_sonic_init_module(
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;
}
--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core
next prev parent reply other threads:[~2005-11-05 10:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-05 10:56 [PATCH] [DRIVER MODEL] Improved dynamically allocated platform_device interface Russell King
2005-11-05 10:57 ` [PATCH] [DRIVER MODEL] Fix depca Russell King
2005-11-05 10:58 ` [PATCH] [DRIVER MODEL] Fix jazzsonic Russell King
2005-11-05 10:58 ` Russell King [this message]
2005-11-05 10:59 ` [PATCH] [DRIVER MODEL] Fix arcfb Russell King
2005-11-05 10:59 ` [PATCH] [DRIVER MODEL] Fix gbefb Russell King
2005-11-05 11:00 ` [PATCH] [DRIVER MODEL] Fix sgivwfb Russell King
2005-11-05 11:02 ` [RFC] [DRIVER MODEL] Make other buggy drivers warn Russell King
2005-11-05 15:42 ` [PATCH] [DRIVER MODEL] Improved dynamically allocated platform_device interface Greg KH
2005-11-05 17:19 ` Russell King
2005-11-05 19:40 ` Greg KH
2005-11-05 17:23 ` Russell King
2005-11-05 21:38 ` Russell King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051105105853.GC30315@flint.arm.linux.org.uk \
--to=rmk+lkml@arm.linux.org.uk \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox