public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [RESEND PATCH 2/3] PCI: ARM: add support for generic PCI host controller
Date: Tue, 06 May 2014 21:11:48 +0200	[thread overview]
Message-ID: <12021375.dFzSuv1Afb@wuerfel> (raw)
In-Reply-To: <20140506183811.GI13677@arm.com>

On Tuesday 06 May 2014 19:38:12 Will Deacon wrote:
> Ok, I've respun the patch and included it below. It's turned probe() into a
> bit of a beast, but the cleanup is a lot simpler (unless I'm missing
> something).

Let's see if we can make it a bit more readable. None of these are important,
but together they could improve readability.

> +static int gen_pci_probe(struct platform_device *pdev)
> +{
> +       struct gen_pci *pci;
> +       int err, res_valid;
> +       struct pci_host_bridge_window *win;
> +       struct resource *bus_range;
> +       resource_size_t busn;
> +       const char *type;
> +       struct of_pci_range range;
> +       struct of_pci_range_parser parser;
> +       struct hw_pci hw;
> +       const struct of_device_id *of_id;
> +       const int *prop;
> +       u8 bus_max;
> +       struct device *dev = &pdev->dev;
> +       struct device_node *np = dev->of_node;
> +
> +       if (!dev->of_node)
> +               return -ENODEV;

This check can go away: you don't get here without an of node.

> +       pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
> +       if (!pci)
> +               return -ENOMEM;
> +
> +       pci->host.dev.parent = dev;
> +       hw = (struct hw_pci) {
> +               .nr_controllers = 1,
> +               .private_data   = (void **)&pci,
> +               .setup          = gen_pci_setup,
> +               .map_irq        = of_irq_parse_and_map_pci,
> +               .ops            = &gen_pci_ops,
> +       };

C constructors are actually a gcc extension, I think it would be more
common to turn this into an initializer by moving it to the declaration:

	struct gen_pci *pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
	struct hw_pci hw = {
               .nr_controllers = 1,
               .private_data   = (void **)&pci,
               .setup          = gen_pci_setup,
               .map_irq        = of_irq_parse_and_map_pci,
               .ops            = &gen_pci_ops,
       };


> +       if (of_pci_range_parser_init(&parser, np)) {
> +               dev_err(dev, "missing \"ranges\" property\n");
> +               return -EINVAL;
> +       }

If you move everything related to the range parser into a separate function,
you end up with two more compact parts. 

> +       /* Create and register resources from the ranges property */
> +       res_valid = 0;
> +       for_each_of_pci_range(&parser, &range) {
> +               struct resource *parent, *res;
> +               resource_size_t offset;
> +               u32 restype = range.flags & IORESOURCE_TYPE_BITS;

You could also move the body of the for loop into another function, or
both.

	Arnd

  reply	other threads:[~2014-05-06 19:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-02 16:41 [RESEND PATCH 0/3] Support for Generic PCI Host Controller Will Deacon
2014-05-02 16:41 ` [RESEND PATCH 1/3] ARM: mach-virt: allow PCI support to be selected Will Deacon
2014-05-02 18:11   ` Arnd Bergmann
2014-05-02 18:21     ` Will Deacon
2014-05-02 16:41 ` [RESEND PATCH 2/3] PCI: ARM: add support for generic PCI host controller Will Deacon
2014-05-02 17:23   ` Jason Gunthorpe
2014-05-02 18:25     ` Arnd Bergmann
2014-05-02 18:44       ` Will Deacon
2014-05-02 19:03         ` Jason Gunthorpe
2014-05-02 19:29           ` Arnd Bergmann
2014-05-06 18:38             ` Will Deacon
2014-05-06 19:11               ` Arnd Bergmann [this message]
2014-05-07  9:18                 ` Will Deacon
2014-05-06 16:05           ` Will Deacon
2014-05-02 16:41 ` [RESEND PATCH 3/3] MAINTAINERS: add entry for generic PCI host controller driver Will Deacon

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=12021375.dFzSuv1Afb@wuerfel \
    --to=arnd@arndb.de \
    --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