From 7a192ec334cab9fafe3a8665a65af398b0e24730 Mon Sep 17 00:00:00 2001 From: Ming Lei Date: Fri, 6 Feb 2009 23:40:12 +0800 Subject: platform driver: fix incorrect use of 'platform_bus_type' with 'struct device_driver' This patch fixes the bug reported in http://bugzilla.kernel.org/show_bug.cgi?id=11681. "Lots of device drivers register a 'struct device_driver' with the '.bus' member set to '&platform_bus_type'. This is wrong, since the platform_bus functions expect the 'struct device_driver' to be wrapped up in a 'struct platform_driver' which provides some additional callbacks (like suspend_late, resume_early). The effect may be that platform_suspend_late() uses bogus data outside the device_driver struct as a pointer pointer to the device driver's suspend_late() function or other hard to reproduce failures."(Lothar Wassmann) Signed-off-by: Ming Lei Acked-by: Henrique de Moraes Holschuh Acked-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/pcmcia/m32r_cfc.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'drivers/pcmcia/m32r_cfc.c') diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c index 2ab4f22..62b4ecc 100644 --- a/drivers/pcmcia/m32r_cfc.c +++ b/drivers/pcmcia/m32r_cfc.c @@ -696,13 +696,25 @@ static struct pccard_operations pcc_operations = { .set_mem_map = pcc_set_mem_map, }; +static int cfc_drv_pcmcia_suspend(struct platform_device *dev, + pm_message_t state) +{ + return pcmcia_socket_dev_suspend(&dev->dev, state); +} + +static int cfc_drv_pcmcia_resume(struct platform_device *dev) +{ + return pcmcia_socket_dev_resume(&dev->dev); +} /*====================================================================*/ -static struct device_driver pcc_driver = { - .name = "cfc", - .bus = &platform_bus_type, - .suspend = pcmcia_socket_dev_suspend, - .resume = pcmcia_socket_dev_resume, +static struct platform_driver pcc_driver = { + .driver = { + .name = "cfc", + .owner = THIS_MODULE, + }, + .suspend = cfc_drv_pcmcia_suspend, + .resume = cfc_drv_pcmcia_resume, }; static struct platform_device pcc_device = { @@ -716,13 +728,13 @@ static int __init init_m32r_pcc(void) { int i, ret; - ret = driver_register(&pcc_driver); + ret = platform_driver_register(&pcc_driver); if (ret) return ret; ret = platform_device_register(&pcc_device); if (ret){ - driver_unregister(&pcc_driver); + platform_driver_unregister(&pcc_driver); return ret; } @@ -754,7 +766,7 @@ static int __init init_m32r_pcc(void) if (pcc_sockets == 0) { printk("socket is not found.\n"); platform_device_unregister(&pcc_device); - driver_unregister(&pcc_driver); + platform_driver_unregister(&pcc_driver); return -ENODEV; } @@ -802,7 +814,7 @@ static void __exit exit_m32r_pcc(void) if (poll_interval != 0) del_timer_sync(&poll_timer); - driver_unregister(&pcc_driver); + platform_driver_unregister(&pcc_driver); } /* exit_m32r_pcc */ module_init(init_m32r_pcc); -- cgit v1.1