[DRIVER MODEL] Fix jazzsonic
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>
This commit is contained in:
Родитель
5d994b7f5d
Коммит
95cb5d954e
|
@ -285,18 +285,8 @@ static struct device_driver jazz_sonic_driver = {
|
||||||
.remove = __devexit_p(jazz_sonic_device_remove),
|
.remove = __devexit_p(jazz_sonic_device_remove),
|
||||||
};
|
};
|
||||||
|
|
||||||
static void jazz_sonic_platform_release (struct device *device)
|
|
||||||
{
|
|
||||||
struct platform_device *pldev;
|
|
||||||
|
|
||||||
/* free device */
|
|
||||||
pldev = to_platform_device (device);
|
|
||||||
kfree (pldev);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __init jazz_sonic_init_module(void)
|
static int __init jazz_sonic_init_module(void)
|
||||||
{
|
{
|
||||||
struct platform_device *pldev;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((err = driver_register(&jazz_sonic_driver))) {
|
if ((err = driver_register(&jazz_sonic_driver))) {
|
||||||
|
@ -304,27 +294,19 @@ static int __init jazz_sonic_init_module(void)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
jazz_sonic_device = NULL;
|
jazz_sonic_device = platform_device_alloc(jazz_sonic_string, 0);
|
||||||
|
if (!jazz_sonnic_device)
|
||||||
if (!(pldev = kmalloc (sizeof (*pldev), GFP_KERNEL))) {
|
|
||||||
goto out_unregister;
|
goto out_unregister;
|
||||||
}
|
|
||||||
|
|
||||||
memset(pldev, 0, sizeof (*pldev));
|
if (platform_device_add(jazz_sonic_device)) {
|
||||||
pldev->name = jazz_sonic_string;
|
platform_device_put(jazz_sonic_device);
|
||||||
pldev->id = 0;
|
|
||||||
pldev->dev.release = jazz_sonic_platform_release;
|
|
||||||
jazz_sonic_device = pldev;
|
|
||||||
|
|
||||||
if (platform_device_register (pldev)) {
|
|
||||||
kfree(pldev);
|
|
||||||
jazz_sonic_device = NULL;
|
jazz_sonic_device = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_unregister:
|
out_unregister:
|
||||||
platform_device_unregister(pldev);
|
driver_unregister(&jazz_sonic_driver);
|
||||||
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче