Re: Using statically allocated memory for platform_data.
From: Russell King - ARM Linux
Date: Mon Nov 02 2009 - 11:37:40 EST
On Mon, Nov 02, 2009 at 04:28:39PM +0000, Ben Dooks wrote:
> On Mon, Nov 02, 2009 at 03:56:25PM +0000, Russell King - ARM Linux wrote:
> > The reason we have platform_device_add_data() is that people think that
> > the device data needs to persist for the lifetime of the device. I
> > personally disagree with that - once you unregister the device, it's
> > guaranteed that device drivers will have been unregistered, so who's
> > going to use the platform data?
> That doesn't make any sense, in the current case of using the
> platform_device_alloc() and those calls the data is only living
> for the lifetime of the device, as the release call is tidying up
> the result.
What I'm saying is that the lifetime of the data finishes once
the _unregister() call has returned. So:
data = pdev->dev.platform_data;
is an entirely valid way of handling the "I allocated my platform
data" problem - it doesn't need to exist to the point where the
device itself is freed.
> There are a number of places where this data isn't __initdata, and
> still needs to be copied, and then freed once the device has been
What I'm saying is that the point where the platform data can be
freed is the point where the device is unregistered. It is not the
point where the device is actually freed.
Whenever you have the pointer for the platform device to be unregistered,
you also have the pointer for its data available.
If we accept that the lifetime for the platform data is from the point
the device is registered to the point immediately following when the
device is unregistered, then the above solution is acceptable and
we don't need to play games with release pointers.
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/