[ARM] pxa: avoid kfreeing static data if platform device fails to register
authorRussell King <rmk@dyn-67.arm.linux.org.uk>
Thu, 24 Apr 2008 14:28:11 +0000 (15:28 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Mon, 2 Jun 2008 12:49:16 +0000 (13:49 +0100)
When a dynamically allocated platform device is 'put', the platform
device's platform_data is kfree'd.  This is bad if it's pointing at
static data.  Use the provided function to register platform data
for these devices.

This also means we can mark the pcmcia ops structures as __initdata.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
drivers/pcmcia/pxa2xx_cm_x270.c
drivers/pcmcia/pxa2xx_mainstone.c
drivers/pcmcia/pxa2xx_sharpsl.c

index 4a6c020afb3736b9d2ac4e8c8e29fbe1f461661d..f123fce65f2e19e736fa54cf48958ce34fa8ca14 100644 (file)
@@ -131,7 +131,7 @@ static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
 }
 
 
-static struct pcmcia_low_level cmx270_pcmcia_ops = {
+static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
        .owner                  = THIS_MODULE,
        .hw_init                = cmx270_pcmcia_hw_init,
        .hw_shutdown            = cmx270_pcmcia_shutdown,
@@ -156,10 +156,13 @@ static int __init cmx270_pcmcia_init(void)
        if (!cmx270_pcmcia_device)
                return -ENOMEM;
 
-       cmx270_pcmcia_device->dev.platform_data = &cmx270_pcmcia_ops;
+       ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops,
+                                      sizeof(cmx270_pcmcia_ops));
 
-       printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
-       ret = platform_device_add(cmx270_pcmcia_device);
+       if (ret == 0) {
+               printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
+               ret = platform_device_add(cmx270_pcmcia_device);
+       }
 
        if (ret)
                platform_device_put(cmx270_pcmcia_device);
index 36a59960b5afd9e8bd710d82d29767d1f3490f01..92d1cc33808ceee0f4f1fd51a1730f5be61f8e06 100644 (file)
@@ -137,7 +137,7 @@ static void mst_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
 {
 }
 
-static struct pcmcia_low_level mst_pcmcia_ops = {
+static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
        .owner                  = THIS_MODULE,
        .hw_init                = mst_pcmcia_hw_init,
        .hw_shutdown            = mst_pcmcia_hw_shutdown,
@@ -161,9 +161,10 @@ static int __init mst_pcmcia_init(void)
        if (!mst_pcmcia_device)
                return -ENOMEM;
 
-       mst_pcmcia_device->dev.platform_data = &mst_pcmcia_ops;
-
-       ret = platform_device_add(mst_pcmcia_device);
+       ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
+                                      sizeof(mst_pcmcia_ops));
+       if (ret == 0)
+               ret = platform_device_add(mst_pcmcia_device);
 
        if (ret)
                platform_device_put(mst_pcmcia_device);
index d5c33bd78d685fcb3a52a26a60ad6359530cbdfe..d71f93d45833ffb287d45d5209ff409affef76e5 100644 (file)
@@ -222,7 +222,7 @@ static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
        sharpsl_pcmcia_init_reset(skt);
 }
 
-static struct pcmcia_low_level sharpsl_pcmcia_ops = {
+static struct pcmcia_low_level sharpsl_pcmcia_ops __initdata = {
        .owner                  = THIS_MODULE,
        .hw_init                = sharpsl_pcmcia_hw_init,
        .hw_shutdown            = sharpsl_pcmcia_hw_shutdown,
@@ -261,10 +261,12 @@ static int __init sharpsl_pcmcia_init(void)
        if (!sharpsl_pcmcia_device)
                return -ENOMEM;
 
-       sharpsl_pcmcia_device->dev.platform_data = &sharpsl_pcmcia_ops;
-       sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev;
-
-       ret = platform_device_add(sharpsl_pcmcia_device);
+       ret = platform_device_add_data(sharpsl_pcmcia_device,
+                       &sharpsl_pcmcia_ops, sizeof(sharpsl_pcmcia_ops));
+       if (ret == 0) {
+               sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev;
+               ret = platform_device_add(sharpsl_pcmcia_device);
+       }
 
        if (ret)
                platform_device_put(sharpsl_pcmcia_device);