Re: Clarifying platform_device_unregister

From: Dmitry Torokhov
Date: Tue Apr 01 2008 - 01:20:33 EST


Hi Jaya,

On Mon, Mar 31, 2008 at 09:14:35PM -0400, Jaya Kumar wrote:
> Hi,
>
> I'm trying to figure out a problem I'm experiencing with
> platform_device_unregister. Here's what I'm seeing with a piece of
> test code based on corgi_pm.c:
>
> static int mydata;
> static struct platform_device *mytest_device;
> static int __devinit mytest_init(void)
> {
> int ret;
>
> mytest_device = platform_device_alloc("no_such_driver", -1);
>
> // no_such_driver intentionally doesn't exist. i want to test this
> mytest module being insmod-ed/rmmod-ed without ever being bound to a
> platform driver.
>
> if (!mytest_device)
> return -ENOMEM;
>
>
> mytest_device->dev.platform_data = &mydata;

Platform device code does kfree(pdev->dev.platform_data) unpon
unregistration, so it is not a good idea to assign address of
statically-allocated variable here. You should be using:

platform_device_add_data(mytest_device, &mydata, sizeof(mydata));


> ret = platform_device_add(mytest_device);
>
> if (ret)
> platform_device_put(mytest_device);
>
> return ret;
> }
>
> static void mytest_exit(void)
> {
> platform_device_unregister(mytest_device);
> }
>
>

Hope this helps.

--
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/