From: Russell King <rmk+lkml@arm.linux.org.uk>
To: Paul Sokolovsky <pmiscml@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC, PATCH 3/4] SoC base drivers: ASIC3 driver
Date: Tue, 1 May 2007 22:31:03 +0100 [thread overview]
Message-ID: <20070501213102.GF19872@flint.arm.linux.org.uk> (raw)
In-Reply-To: <06028862.20070501080948@gmail.com>
On Tue, May 01, 2007 at 08:09:48AM +0300, Paul Sokolovsky wrote:
> +static void asic3_release(struct device *dev)
> +{
> + struct platform_device *sdev = to_platform_device(dev);
> +
> + kfree(sdev->resource);
> + kfree(sdev);
> +}
> +
> +int asic3_register_mmc(struct device *dev)
> +{
> + struct platform_device *sdev = kzalloc(sizeof(*sdev), GFP_KERNEL);
> + struct tmio_mmc_hwconfig *mmc_config = kmalloc(sizeof(*mmc_config),
> + GFP_KERNEL);
> + struct platform_device *pdev = to_platform_device(dev);
> + struct asic3_data *asic = dev->driver_data;
> + struct asic3_platform_data *asic3_pdata = dev->platform_data;
> + struct resource *res;
> + int rc;
> +
> + if (sdev == NULL || mmc_config == NULL)
> + return -ENOMEM;
> +
> + if (asic3_pdata->tmio_mmc_hwconfig) {
> + memcpy(mmc_config, asic3_pdata->tmio_mmc_hwconfig,
> + sizeof(*mmc_config));
> + } else {
> + memset(mmc_config, 0, sizeof(*mmc_config));
> + }
> + mmc_config->address_shift = asic->bus_shift;
> +
> + sdev->id = -1;
> + sdev->name = "asic3_mmc";
> + sdev->dev.parent = dev;
> + sdev->num_resources = 2;
> + sdev->dev.platform_data = mmc_config;
> + sdev->dev.release = asic3_release;
> +
> + res = kzalloc(sdev->num_resources * sizeof(struct resource),
> + GFP_KERNEL);
> + if (res == NULL) {
> + kfree(sdev);
> + kfree(mmc_config);
> + return -ENOMEM;
> + }
> + sdev->resource = res;
> +
> + res[0].start = pdev->resource[2].start;
> + res[0].end = pdev->resource[2].end;
> + res[0].flags = IORESOURCE_MEM;
> + res[1].start = res[1].end = pdev->resource[3].start;
> + res[1].flags = IORESOURCE_IRQ;
> +
> + rc = platform_device_register(sdev);
> + if (rc) {
> + printk(KERN_ERR "asic3_base: "
> + "Could not register asic3_mmc device\n");
> + kfree(res);
> + kfree(sdev);
> + return rc;
> + }
> +
> + asic->mmc_dev = sdev;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(asic3_register_mmc);
> +
> +int asic3_unregister_mmc(struct device *dev)
> +{
> + struct asic3_data *asic = dev->driver_data;
> + platform_device_unregister(asic->mmc_dev);
> + asic->mmc_dev = 0;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(asic3_unregister_mmc);
...
> +static int asic3_probe(struct platform_device *pdev)
> +{
...
> + if (pdev->num_resources > 2) {
> + int rc;
> + rc = asic3_register_mmc(dev);
...
> + return 0;
> +}
> +
> +static int asic3_remove(struct platform_device *pdev)
> +{
> + struct asic3_platform_data *pdata = pdev->dev.platform_data;
> + struct asic3_data *asic = platform_get_drvdata(pdev);
> + int i;
...
> + if (asic->mmc_dev)
> + asic3_unregister_mmc(&pdev->dev);
...
> + return 0;
> +}
...
> +static struct platform_driver asic3_device_driver = {
> + .driver = {
> + .name = "asic3",
> + },
> + .probe = asic3_probe,
> + .remove = asic3_remove,
> + .suspend = asic3_suspend,
> + .resume = asic3_resume,
> + .shutdown = asic3_shutdown,
> +};
...
> +static void __exit asic3_base_exit(void)
> +{
> + platform_driver_unregister(&asic3_device_driver);
> +}
...
> +module_exit(asic3_base_exit);
What stops the remove function from being called after the module
has been removed from the system?
Again, with platform devices you _really_ want to use the already
provided dynamic allocation methods precisely because they don't
suffer from these problems.
--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of:
prev parent reply other threads:[~2007-05-01 21:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-01 5:09 [RFC, PATCH 3/4] SoC base drivers: ASIC3 driver Paul Sokolovsky
2007-05-01 6:57 ` Andrew Morton
2007-05-01 21:31 ` Russell King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070501213102.GF19872@flint.arm.linux.org.uk \
--to=rmk+lkml@arm.linux.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=pmiscml@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.