aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2008-04-07 15:03:25 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-04-25 00:16:49 -0400
commita89a2cd396b20c46a37fa8db4b652fb00f29d0a4 (patch)
tree03f69864402c8a8c8a4faa81cfa347897b69c164 /drivers/usb/gadget
parent0e530b45783f75a29bde20bbf9e287c915a4f68b (diff)
USB: dummy-hcd: use dynamic allocation for platform_devices
This patch (as1075) changes dummy-hcd to dynamically allocate its platform_device structures, using the core platform_device_alloc() interface. This is what it should have done all along, because the dynamically-allocated structures have a release method in the driver core and are therefore immune to being released after the module has been unloaded. Thanks to Richard Purdie for pointing out the need for this change. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Cc: Richard Purdie <rpurdie@rpsys.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/dummy_hcd.c70
1 files changed, 29 insertions, 41 deletions
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 433f8c47cce5..74f51a703b42 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -1933,69 +1933,57 @@ static struct platform_driver dummy_hcd_driver = {
1933 1933
1934/*-------------------------------------------------------------------------*/ 1934/*-------------------------------------------------------------------------*/
1935 1935
1936/* These don't need to do anything because the pdev structures are 1936static struct platform_device *the_udc_pdev;
1937 * statically allocated. */ 1937static struct platform_device *the_hcd_pdev;
1938static void
1939dummy_udc_release (struct device *dev) {}
1940
1941static void
1942dummy_hcd_release (struct device *dev) {}
1943
1944static struct platform_device the_udc_pdev = {
1945 .name = (char *) gadget_name,
1946 .id = -1,
1947 .dev = {
1948 .release = dummy_udc_release,
1949 },
1950};
1951
1952static struct platform_device the_hcd_pdev = {
1953 .name = (char *) driver_name,
1954 .id = -1,
1955 .dev = {
1956 .release = dummy_hcd_release,
1957 },
1958};
1959 1938
1960static int __init init (void) 1939static int __init init (void)
1961{ 1940{
1962 int retval; 1941 int retval = -ENOMEM;
1963 1942
1964 if (usb_disabled ()) 1943 if (usb_disabled ())
1965 return -ENODEV; 1944 return -ENODEV;
1966 1945
1967 retval = platform_driver_register (&dummy_hcd_driver); 1946 the_hcd_pdev = platform_device_alloc(driver_name, -1);
1968 if (retval < 0) 1947 if (!the_hcd_pdev)
1969 return retval; 1948 return retval;
1949 the_udc_pdev = platform_device_alloc(gadget_name, -1);
1950 if (!the_udc_pdev)
1951 goto err_alloc_udc;
1970 1952
1971 retval = platform_driver_register (&dummy_udc_driver); 1953 retval = platform_driver_register(&dummy_hcd_driver);
1954 if (retval < 0)
1955 goto err_register_hcd_driver;
1956 retval = platform_driver_register(&dummy_udc_driver);
1972 if (retval < 0) 1957 if (retval < 0)
1973 goto err_register_udc_driver; 1958 goto err_register_udc_driver;
1974 1959
1975 retval = platform_device_register (&the_hcd_pdev); 1960 retval = platform_device_add(the_hcd_pdev);
1976 if (retval < 0) 1961 if (retval < 0)
1977 goto err_register_hcd; 1962 goto err_add_hcd;
1978 1963 retval = platform_device_add(the_udc_pdev);
1979 retval = platform_device_register (&the_udc_pdev);
1980 if (retval < 0) 1964 if (retval < 0)
1981 goto err_register_udc; 1965 goto err_add_udc;
1982 return retval; 1966 return retval;
1983 1967
1984err_register_udc: 1968err_add_udc:
1985 platform_device_unregister (&the_hcd_pdev); 1969 platform_device_del(the_hcd_pdev);
1986err_register_hcd: 1970err_add_hcd:
1987 platform_driver_unregister (&dummy_udc_driver); 1971 platform_driver_unregister(&dummy_udc_driver);
1988err_register_udc_driver: 1972err_register_udc_driver:
1989 platform_driver_unregister (&dummy_hcd_driver); 1973 platform_driver_unregister(&dummy_hcd_driver);
1974err_register_hcd_driver:
1975 platform_device_put(the_udc_pdev);
1976err_alloc_udc:
1977 platform_device_put(the_hcd_pdev);
1990 return retval; 1978 return retval;
1991} 1979}
1992module_init (init); 1980module_init (init);
1993 1981
1994static void __exit cleanup (void) 1982static void __exit cleanup (void)
1995{ 1983{
1996 platform_device_unregister (&the_udc_pdev); 1984 platform_device_unregister(the_udc_pdev);
1997 platform_device_unregister (&the_hcd_pdev); 1985 platform_device_unregister(the_hcd_pdev);
1998 platform_driver_unregister (&dummy_udc_driver); 1986 platform_driver_unregister(&dummy_udc_driver);
1999 platform_driver_unregister (&dummy_hcd_driver); 1987 platform_driver_unregister(&dummy_hcd_driver);
2000} 1988}
2001module_exit (cleanup); 1989module_exit (cleanup);