linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: "Andrew Lunn" <andrew@lunn.ch>,
	"Gregory Clement" <gregory.clement@bootlin.com>,
	"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	linux-arm-kernel@lists.infradead.org, arm@kernel.org,
	"Andy Shevchenko" <andy@kernel.org>,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: "Marek Behún" <kabel@kernel.org>
Subject: [PATCH 09/10] irqchip/armada-370-xp: Refactor initial memory regions mapping
Date: Thu, 11 Jul 2024 18:09:06 +0200	[thread overview]
Message-ID: <20240711160907.31012-10-kabel@kernel.org> (raw)
In-Reply-To: <20240711160907.31012-1-kabel@kernel.org>

Refactor the initial memory regions mapping:
- put into its own function
- return error numbers on failure
- use WARN_ON() instead of BUG_ON()

Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/irqchip/irq-armada-370-xp.c | 62 ++++++++++++++++++++---------
 1 file changed, 44 insertions(+), 18 deletions(-)

diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c
index 2c8272fe7150..dccc69aa2bf4 100644
--- a/drivers/irqchip/irq-armada-370-xp.c
+++ b/drivers/irqchip/irq-armada-370-xp.c
@@ -12,6 +12,7 @@
 
 #include <linux/bitfield.h>
 #include <linux/bits.h>
+#include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
@@ -766,29 +767,54 @@ static struct syscore_ops mpic_syscore_ops = {
 	.resume		= mpic_resume,
 };
 
+static int __init mpic_map_region(struct device_node *np, int index,
+				  void __iomem **base, phys_addr_t *phys_base)
+{
+	struct resource res;
+	int err;
+
+	err = of_address_to_resource(np, index, &res);
+	if (WARN_ON(err))
+		goto fail;
+
+	if (WARN_ON(!request_mem_region(res.start, resource_size(&res),
+					np->full_name))) {
+		err = -EBUSY;
+		goto fail;
+	}
+
+	*base = ioremap(res.start, resource_size(&res));
+	if (WARN_ON(!*base)) {
+		err = -ENOMEM;
+		goto fail;
+	}
+
+	if (phys_base)
+		*phys_base = res.start;
+
+	return 0;
+
+fail:
+	pr_err("%pOF: Unable to map resource %d: %pE\n", np, index,
+	       ERR_PTR(err));
+
+	return err;
+}
+
 static int __init mpic_of_init(struct device_node *node,
 			       struct device_node *parent)
 {
-	struct resource main_int_res, per_cpu_int_res;
+	phys_addr_t phys_base;
 	unsigned int nr_irqs;
+	int err;
 
-	BUG_ON(of_address_to_resource(node, 0, &main_int_res));
-	BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res));
-
-	BUG_ON(!request_mem_region(main_int_res.start,
-				   resource_size(&main_int_res),
-				   node->full_name));
-	BUG_ON(!request_mem_region(per_cpu_int_res.start,
-				   resource_size(&per_cpu_int_res),
-				   node->full_name));
-
-	main_int_base = ioremap(main_int_res.start,
-				resource_size(&main_int_res));
-	BUG_ON(!main_int_base);
+	err = mpic_map_region(node, 0, &main_int_base, &phys_base);
+	if (err)
+		return err;
 
-	per_cpu_int_base = ioremap(per_cpu_int_res.start,
-				   resource_size(&per_cpu_int_res));
-	BUG_ON(!per_cpu_int_base);
+	err = mpic_map_region(node, 1, &per_cpu_int_base, NULL);
+	if (err)
+		return err;
 
 	nr_irqs = FIELD_GET(MPIC_INT_CONTROL_NUMINT_MASK,
 			    readl(main_int_base + MPIC_INT_CONTROL));
@@ -810,7 +836,7 @@ static int __init mpic_of_init(struct device_node *node,
 	mpic_perf_init();
 	mpic_smp_cpu_init();
 
-	mpic_msi_init(node, main_int_res.start);
+	mpic_msi_init(node, phys_base);
 
 	if (parent_irq <= 0) {
 		irq_set_default_host(mpic_domain);
-- 
2.44.2



  parent reply	other threads:[~2024-07-11 16:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-11 16:08 [PATCH 00/10] armada-370-xp irqchip updates round 4 Marek Behún
2024-07-11 16:08 ` [PATCH 01/10] irqchip/armada-370-xp: Use consistent variable names for hwirqs Marek Behún
2024-07-11 16:08 ` [PATCH 02/10] irqchip/armada-370-xp: Use consistent types when iterating interrupts Marek Behún
2024-07-11 16:09 ` [PATCH 03/10] irqchip/armada-370-xp: Use consistent name for struct irq_data variables Marek Behún
2024-07-11 16:09 ` [PATCH 04/10] irqchip/armada-370-xp: Simplify mpic_reenable_percpu() and mpic_resume() Marek Behún
2024-07-11 16:09 ` [PATCH 05/10] irqchip/armada-370-xp: Drop unneeded curly brackets Marek Behún
2024-07-29  8:52   ` Thomas Gleixner
2024-07-11 16:09 ` [PATCH 06/10] irqchip/armada-370-xp: Drop redundant continue Marek Behún
2024-07-11 16:09 ` [PATCH 07/10] irqchip/armada-370-xp: Rename variable for consistency Marek Behún
2024-07-11 16:09 ` [PATCH 08/10] irqchip/armada-370-xp: Use u32 type instead of unsigned long where possieble Marek Behún
2024-07-11 16:09 ` Marek Behún [this message]
2024-07-11 16:09 ` [PATCH 10/10] irqchip/armada-370-xp: Print error and return error code on initialization failure Marek Behún
2024-07-11 20:56 ` [PATCH 00/10] armada-370-xp irqchip updates round 4 Thomas Gleixner
2024-07-12  7:46   ` Marek Behún
2024-07-12 22:19     ` Thomas Gleixner
2024-07-29  9:44       ` Thomas Gleixner

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=20240711160907.31012-10-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=andy@kernel.org \
    --cc=arm@kernel.org \
    --cc=gregory.clement@bootlin.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=tglx@linutronix.de \
    /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).