Re: [PATCH 2/3] Add platform_device_register_simple

Russell King
2004-06-10T10:16:28Z

On Thu, Jun 10, 2004 at 01:43:51AM -0500, Dmitry Torokhov wrote:
> ChangeSet@1.1767, 2004-06-09 23:58:52-05:00, dtor_core@ameritech.net
> sysfs: add platform_device_register_simple() that creates a simple
> platform device that does not manage any resources. Modules
> using such platform devices can be unloaded without waiting
> for the device to me released (but any additional resources
> allocated by module should be freed beforehand).

What about platform devices which have resources associated with them?

> +struct platform_device *platform_device_register_simple(char *name, unsigned int id)
> +{
> + struct platform_device *pdev;
> + int retval;
> +
> + pdev = kmalloc(sizeof(*pdev), GFP_KERNEL);
> + if (!pdev) {
> + retval = -ENOMEM;
> + goto error;
> + }
> +
> + memset(pdev, 0, sizeof(*pdev));
> + pdev->name = name;
> + pdev->id = id;
> + pdev->dev.release = platform_device_release_simple;
> +
> + retval = platform_device_register(pdev);
> + if (retval)
> + goto error;
> +
> + return pdev;
> +
> +error:
> + kfree(pdev);
> + return ERR_PTR(retval);

As this currently stands, you have no chance to add resources to the
platform device before it's made available to the driver. It's likely
that any attached resources will have the same lifetime as the
device itself, so it makes sense to allocate them together with the
platform device.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial core