From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 6/6] serial: add amba-pl011-pci
Date: Sat, 26 May 2012 09:43:28 +0100 [thread overview]
Message-ID: <20120526084328.GE24149@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <b166cb0fce2a67b24da5808604553b4196258f45.1337959750.git.rubini@gnudd.com>
On Fri, May 25, 2012 at 05:48:57PM +0200, Alessandro Rubini wrote:
> diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
> index 070b442..e5e5ef6 100644
> --- a/drivers/tty/serial/Kconfig
> +++ b/drivers/tty/serial/Kconfig
> @@ -39,14 +39,22 @@ config SERIAL_AMBA_PL010_CONSOLE
> config SERIAL_AMBA_PL011
> tristate "ARM AMBA PL011 serial port support"
> depends on ARM_AMBA
> + default y if STA2X11
I don't think we want to encourage an ever growing list of platforms
here. If we did this on ARM, this would be hellishly long.
> +/* This is a template, copied every time a new pci device appears */
> +static AMBA_APB_DEVICE(pl011_pci_template, "pl011-pci", 0,
> + 0 /* base */, {0} /* irqs */, NULL /* data */);
> +
> +static int __devinit pl011_pci_probe(struct pci_dev *pdev,
> + const struct pci_device_id *id)
> +{
> + struct amba_device *adev;
> + struct amba_pl011_data *data;
> + int ret;
> +
> + /* Simply build an amba device and register it */
> + adev = kmemdup(&pl011_pci_template_device,
> + sizeof(pl011_pci_template_device), GFP_KERNEL);
NAK. We have interfaces in the AMBA code for dynamically allocating
AMBA devices now - please use them instead of coding your own. They
avoid bugs.
> + /* change name */
> + adev->dev.init_name = kasprintf(GFP_ATOMIC, "pl011-pci-%02x:%04x",
> + pdev->bus->number, pdev->devfn);
> +
> + printk(KERN_INFO "%s %i\n", __func__, __LINE__);
This looks like debugging.
> + if ((ret = amba_device_register(adev, &pdev->resource[0])) < 0) {
> + kfree(adev);
> + return ret;
> + }
> + return 0;
> +};
> +
> +static void __devexit pl011_pci_remove(struct pci_dev *pdev)
> +{
> + struct amba_device *adev = pci_get_drvdata(pdev);
> + amba_device_unregister(adev);
> + kfree(adev->dev.platform_data);
> + kfree(adev);
This comes nowhere close to being sane with the driver model. This is
an oops waiting to happen. You can't guarantee that 'adev' will be
unused by the time amba_device_unregister() (or in fact any such call
into the driver model) returns.
This is because these suckers (and all devices) are refcounted. If you
use the correct interfaces, the devices will be freed for you automatically
at the correct time.
The only thing that won't be is adev->dev.platform_data - the correct way
to do this is the following along with the correct allocation interfaces:
struct amba_device *adev = pci_get_drvdata(pdev);
void *priv = adev->dev.platform_data;
amba_device_unregister(adev);
kfree(priv);
In other words, save off the platform data pointer, unregister the struct
device, and then free the platform data (it will not be used at that point.)
next prev parent reply other threads:[~2012-05-26 8:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-25 15:47 [PATCH 0/6] Bridging PCI to amba Alessandro Rubini
2012-05-25 15:48 ` [PATCH 1/6] sizes.h: move from asm-generic to <linux/sizes.h> Alessandro Rubini
2012-05-25 15:48 ` [PATCH 2/6] amba: use the new linux/sizes.h Alessandro Rubini
2012-05-26 8:33 ` Russell King - ARM Linux
2012-05-25 15:48 ` [PATCH 3/6] ARM: " Alessandro Rubini
2012-05-25 15:48 ` [PATCH 4/6] pl011: " Alessandro Rubini
2012-05-25 15:48 ` [PATCH 5/6] x86: add CONFIG_ARM_AMBA, selected by STA2X11 Alessandro Rubini
2012-05-25 15:48 ` [PATCH 6/6] serial: add amba-pl011-pci Alessandro Rubini
2012-05-26 7:39 ` Arnd Bergmann
2012-05-26 7:58 ` Alessandro Rubini
2012-05-26 8:29 ` Arnd Bergmann
2012-05-26 8:43 ` Russell King - ARM Linux [this message]
2012-05-26 8:48 ` Russell King - ARM Linux
2012-05-26 9:27 ` Alessandro Rubini
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=20120526084328.GE24149@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).