[PATCH 21/26] AMBA: pci-amba bridge: improve code readability

From: Davide Ciminaghi
Date: Wed Aug 07 2013 - 06:27:55 EST


This patch moves the code fixing up irq numbers for amba devices
to a separate function (fixup_amba_irqs()).

Signed-off-by: Davide Ciminaghi <ciminaghi@xxxxxxxxx>
Acked-by: Giancarlo Asnaghi <giancarlo.asnaghi@xxxxxx>
---
drivers/amba/pci-amba.c | 97 +++++++++++++++++++++++++---------------------
1 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/drivers/amba/pci-amba.c b/drivers/amba/pci-amba.c
index e56717b..c825c7a 100644
--- a/drivers/amba/pci-amba.c
+++ b/drivers/amba/pci-amba.c
@@ -25,19 +25,63 @@
*/
#define IMAP_ROW_LEN (1 + 1 + 1 + 1 + 1)

+static int fixup_amba_irq(struct device_node *amba_node,
+ struct device_node *amba_bus,
+ struct pci_dev *pdev)
+{
+ const void *p;
+ struct property *newimap;
+ u32 *ptr, *newv;
+ const u32 *reg;
+ int i, len, found;
+
+ p = of_get_property(amba_bus, "interrupt-map", &len);
+ if (!p)
+ /* No amba bus interrupt-map property */
+ return -EINVAL;
+
+ newimap = devm_kzalloc(&pdev->dev, sizeof(*newimap), GFP_KERNEL);
+ if (!newimap)
+ return -ENOMEM;
+
+ newimap->name = kstrdup("interrupt-map", GFP_KERNEL);
+ if (!newimap->name)
+ return -ENOMEM;
+
+ newv = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
+ if (!newv) {
+ kfree(newimap->name);
+ return -ENOMEM;
+ }
+
+ newimap->value = newv;
+ newimap->length = len;
+ memcpy(newv, p, len);
+ for (ptr = newv, i = 0, found = 0;
+ i < len/sizeof(u32); ptr += IMAP_ROW_LEN, i += IMAP_ROW_LEN) {
+ reg = of_get_property(amba_node, "reg", NULL);
+ if (ptr[0] == reg[0]) {
+ ptr[IMAP_ROW_LEN - 1] = cpu_to_be32(pdev->irq);
+ found = 1;
+ break;
+ }
+ }
+ if (!found) {
+ pr_err("Could not update amba irq\n");
+ return -EINVAL;
+ }
+ of_update_property(amba_bus, newimap);
+ return 0;
+}
+
static int pci_amba_probe(struct pci_dev *pdev,
const struct pci_device_id *id)
{
struct amba_device *adev;
- int i, ret, len;
+ int ret;
struct device_node *n, *node, *pci_amba_bridge, *amba_bus = NULL,
*amba_node = NULL;
- const void *p;
char *name;
- struct property *newimap;
- u32 *newv, *ptr;
- const u32 *reg;
- int found;

pci_enable_msi(pdev);
ret = pci_enable_device(pdev);
@@ -96,44 +140,9 @@ static int pci_amba_probe(struct pci_dev *pdev,
map to fix things up.
*/
if (of_get_property(amba_node, "interrupts", NULL)) {
- p = of_get_property(amba_bus, "interrupt-map", &len);
- if (!p)
- /* No amba bus interrupt-map property */
- return -EINVAL;
-
- newimap = devm_kzalloc(&pdev->dev, sizeof(*newimap),
- GFP_KERNEL);
- if (!newimap)
- return -ENOMEM;
-
- newimap->name = kstrdup("interrupt-map", GFP_KERNEL);
- if (!newimap->name)
- return -ENOMEM;
-
- newv = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
- if (!newv) {
- kfree(newimap->name);
- return -ENOMEM;
- }
-
- newimap->value = newv;
- newimap->length = len;
- memcpy(newv, p, len);
- for (ptr = newv, i = 0, found = 0;
- i < len/sizeof(u32);
- ptr += IMAP_ROW_LEN, i += IMAP_ROW_LEN) {
- reg = of_get_property(amba_node, "reg", NULL);
- if (ptr[0] == reg[0]) {
- ptr[IMAP_ROW_LEN - 1] = cpu_to_be32(pdev->irq);
- found = 1;
- break;
- }
- }
- if (!found) {
- pr_err("Could not update amba irq\n");
- return -EINVAL;
- }
- of_update_property(amba_bus, newimap);
+ ret = fixup_amba_irq(amba_node, amba_bus, pdev);
+ if (ret < 0)
+ return ret;
}

/* And finally create the amba device */
--
1.7.7.2
--
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/