The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Thomas Gleixner <tglx@kernel.org>, Ryan Chen <ryan_chen@aspeedtech.com>
Cc: Arnd Bergmann <arnd@arndb.de>, linux-kernel@vger.kernel.org
Subject: [PATCH] irqchip/ast2700-intc: reduce stack usage in kunit tests
Date: Fri, 15 May 2026 11:07:06 +0200	[thread overview]
Message-ID: <20260515090730.403171-1-arnd@kernel.org> (raw)

From: Arnd Bergmann <arnd@arndb.de>

Build testing this driver can show excessive stack usage, because
of the construction of various large structures on the stack:

drivers/irqchip/irq-ast2700-intc0-test.c: In function 'aspeed_intc0_resolve_route_c1i1o1mc0i1o1_bad_range_upstream':
drivers/irqchip/irq-ast2700-intc0-test.c:451:1: error: the frame size of 1616 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
  451 | }
      | ^
drivers/irqchip/irq-ast2700-intc0-test.c: In function 'aspeed_intc0_resolve_route_c1i1o2mc0i1o1_invalid':
drivers/irqchip/irq-ast2700-intc0-test.c:403:1: error: the frame size of 1632 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
  403 | }
      | ^
drivers/irqchip/irq-ast2700-intc0-test.c: In function 'aspeed_intc0_resolve_route_c1i2o2mc0i1o1':
drivers/irqchip/irq-ast2700-intc0-test.c:292:1: error: the frame size of 1632 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
  292 | }
      | ^
drivers/irqchip/irq-ast2700-intc0-test.c: In function 'aspeed_intc0_resolve_route_c1i1o1mc0i1o1':
drivers/irqchip/irq-ast2700-intc0-test.c:233:1: error: the frame size of 1632 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
  233 | }
      | ^
drivers/irqchip/irq-ast2700-intc0-test.c: In function 'aspeed_intc0_resolve_route_c1i1o1c0i1o1_disconnected':
drivers/irqchip/irq-ast2700-intc0-test.c:183:1: error: the frame size of 1616 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
  183 | }
      | ^
drivers/irqchip/irq-ast2700-intc0-test.c: In function 'aspeed_intc0_resolve_route_c1i1o1c0i1o1_connected':
drivers/irqchip/irq-ast2700-intc0-test.c:135:1: error: the frame size of 1632 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
  135 | }
      | ^

The largest structure in each case is the irq_domain. Since at most
two of its members are actually assigned here, change this part to
be dynamically allocated and initialized in a common helper.

The other structures here are still fairly large, so it would be
possible to take this further by making additional structures
allocated either statically or through kzalloc(), but the simpler
fix is sufficient to stay below the warning limit.

Fixes: 46e39ee92d14 ("irqchip/ast2700-intc: Add KUnit tests for route resolution")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/irqchip/irq-ast2700-intc0-test.c | 109 +++++++++++------------
 1 file changed, 53 insertions(+), 56 deletions(-)

diff --git a/drivers/irqchip/irq-ast2700-intc0-test.c b/drivers/irqchip/irq-ast2700-intc0-test.c
index d49784509ac7..5ca668812347 100644
--- a/drivers/irqchip/irq-ast2700-intc0-test.c
+++ b/drivers/irqchip/irq-ast2700-intc0-test.c
@@ -6,23 +6,41 @@
 
 #include "irq-ast2700.h"
 
+static int aspeed_intc0_resolve_route_test(struct fwnode_handle *fwnode,
+					   void *host_data,
+					   size_t nc1outs,
+					   const u32 *c1outs,
+					   size_t nc1ranges,
+					   const struct aspeed_intc_interrupt_range *c1ranges,
+					   struct aspeed_intc_interrupt_range *resolved)
+{
+	struct irq_domain *c0domain __free(kfree) = kzalloc_obj(*c0domain);
+
+	if (!c0domain)
+		return -ENOMEM;
+
+	c0domain->host_data = host_data;
+	c0domain->fwnode = fwnode;
+	return aspeed_intc0_resolve_route(c0domain, nc1outs, c1outs,
+					  nc1ranges, c1ranges, resolved);
+}
+
 static void aspeed_intc0_resolve_route_bad_args(struct kunit *test)
 {
 	static const struct aspeed_intc_interrupt_range c1ranges[] = { 0 };
 	static const u32 c1outs[] = { 0 };
 	struct aspeed_intc_interrupt_range resolved;
-	const struct irq_domain c0domain = { 0 };
 	int rc;
 
 	rc = aspeed_intc0_resolve_route(NULL, 0, c1outs, 0, c1ranges, NULL);
 	KUNIT_EXPECT_EQ(test, rc, -EINVAL);
 
-	rc = aspeed_intc0_resolve_route(&c0domain, 0, c1outs,
+	rc = aspeed_intc0_resolve_route_test(NULL, NULL, 0, c1outs,
 					ARRAY_SIZE(c1ranges), c1ranges,
 					&resolved);
 	KUNIT_EXPECT_EQ(test, rc, -ENOENT);
 
-	rc = aspeed_intc0_resolve_route(&c0domain, ARRAY_SIZE(c1outs), c1outs,
+	rc = aspeed_intc0_resolve_route_test(NULL, NULL, ARRAY_SIZE(c1outs), c1outs,
 					0, c1ranges, &resolved);
 	KUNIT_EXPECT_EQ(test, rc, -ENOENT);
 }
@@ -52,15 +70,15 @@ static void aspeed_intc_resolve_route_invalid_c0domain(struct kunit *test)
 	struct device_node intc0_node = {
 		.fwnode = { .ops = &arm_gicv3_fwnode_ops },
 	};
-	const struct irq_domain c0domain = { .fwnode = &intc0_node.fwnode };
 	static const struct aspeed_intc_interrupt_range c1ranges[] = { 0 };
 	static const u32 c1outs[] = { 0 };
 	struct aspeed_intc_interrupt_range resolved;
 	int rc;
 
-	rc = aspeed_intc0_resolve_route(&c0domain, ARRAY_SIZE(c1outs), c1outs,
-					ARRAY_SIZE(c1ranges), c1ranges,
-					&resolved);
+	rc = aspeed_intc0_resolve_route_test(&intc0_node.fwnode, NULL,
+					     ARRAY_SIZE(c1outs), c1outs,
+					     ARRAY_SIZE(c1ranges), c1ranges,
+					     &resolved);
 	KUNIT_EXPECT_NE(test, rc, 0);
 }
 
@@ -119,15 +137,12 @@ aspeed_intc0_resolve_route_c1i1o1c0i1o1_connected(struct kunit *test)
 	struct aspeed_intc0 intc0 = {
 		.ranges = { .ranges = intc0_ranges, .nranges = ARRAY_SIZE(intc0_ranges), }
 	};
-	const struct irq_domain c0domain = {
-		.host_data = &intc0,
-		.fwnode = &intc0_node.fwnode
-	};
 	int rc;
 
-	rc = aspeed_intc0_resolve_route(&c0domain, ARRAY_SIZE(c1outs), c1outs,
-					ARRAY_SIZE(c1ranges), c1ranges,
-					&resolved);
+	rc = aspeed_intc0_resolve_route_test(&intc0_node.fwnode, &intc0,
+					     ARRAY_SIZE(c1outs), c1outs,
+					     ARRAY_SIZE(c1ranges), c1ranges,
+					     &resolved);
 	KUNIT_EXPECT_EQ(test, rc, 0);
 	KUNIT_EXPECT_EQ(test, resolved.start, 0);
 	KUNIT_EXPECT_EQ(test, resolved.count, 1);
@@ -170,15 +185,12 @@ aspeed_intc0_resolve_route_c1i1o1c0i1o1_disconnected(struct kunit *test)
 			.nranges = ARRAY_SIZE(intc0_ranges),
 		}
 	};
-	const struct irq_domain c0domain = {
-		.host_data = &intc0,
-		.fwnode = &intc0_node.fwnode
-	};
 	int rc;
 
-	rc = aspeed_intc0_resolve_route(&c0domain, ARRAY_SIZE(c1outs), c1outs,
-					ARRAY_SIZE(c1ranges), c1ranges,
-					&resolved);
+	rc = aspeed_intc0_resolve_route_test(&intc0_node.fwnode, &intc0,
+					     ARRAY_SIZE(c1outs), c1outs,
+					     ARRAY_SIZE(c1ranges), c1ranges,
+					     &resolved);
 	KUNIT_EXPECT_NE(test, rc, 0);
 }
 
@@ -217,15 +229,12 @@ static void aspeed_intc0_resolve_route_c1i1o1mc0i1o1(struct kunit *test)
 			.nranges = ARRAY_SIZE(intc0_ranges),
 		}
 	};
-	const struct irq_domain c0domain = {
-		.host_data = &intc0,
-		.fwnode = &intc0_node.fwnode
-	};
 	int rc;
 
-	rc = aspeed_intc0_resolve_route(&c0domain, ARRAY_SIZE(c1outs), c1outs,
-					ARRAY_SIZE(c1ranges), c1ranges,
-					&resolved);
+	rc = aspeed_intc0_resolve_route_test(&intc0_node.fwnode, &intc0,
+					     ARRAY_SIZE(c1outs), c1outs,
+					     ARRAY_SIZE(c1ranges), c1ranges,
+					     &resolved);
 	KUNIT_EXPECT_EQ(test, rc, 0);
 	KUNIT_EXPECT_EQ(test, resolved.start, 0);
 	KUNIT_EXPECT_EQ(test, resolved.count, 1);
@@ -276,15 +285,12 @@ static void aspeed_intc0_resolve_route_c1i2o2mc0i1o1(struct kunit *test)
 			.nranges = ARRAY_SIZE(intc0_ranges),
 		}
 	};
-	const struct irq_domain c0domain = {
-		.host_data = &intc0,
-		.fwnode = &intc0_node.fwnode
-	};
 	int rc;
 
-	rc = aspeed_intc0_resolve_route(&c0domain, ARRAY_SIZE(c1outs), c1outs,
-					ARRAY_SIZE(c1ranges), c1ranges,
-					&resolved);
+	rc = aspeed_intc0_resolve_route_test(&intc0_node.fwnode, &intc0,
+					     ARRAY_SIZE(c1outs), c1outs,
+					     ARRAY_SIZE(c1ranges), c1ranges,
+					     &resolved);
 	KUNIT_EXPECT_EQ(test, rc, 0);
 	KUNIT_EXPECT_EQ(test, resolved.start, 1);
 	KUNIT_EXPECT_EQ(test, resolved.count, 1);
@@ -335,15 +341,12 @@ static void aspeed_intc0_resolve_route_c1i1o1mc0i2o1(struct kunit *test)
 			.nranges = ARRAY_SIZE(intc0_ranges),
 		}
 	};
-	const struct irq_domain c0domain = {
-		.host_data = &intc0,
-		.fwnode = &intc0_node.fwnode
-	};
 	int rc;
 
-	rc = aspeed_intc0_resolve_route(&c0domain, ARRAY_SIZE(c1outs), c1outs,
-					ARRAY_SIZE(c1ranges), c1ranges,
-					&resolved);
+	rc = aspeed_intc0_resolve_route_test(&intc0_node.fwnode, &intc0,
+					     ARRAY_SIZE(c1outs), c1outs,
+					     ARRAY_SIZE(c1ranges), c1ranges,
+					     &resolved);
 	KUNIT_EXPECT_EQ(test, rc, 0);
 	KUNIT_EXPECT_EQ(test, resolved.start, 0);
 	KUNIT_EXPECT_EQ(test, resolved.count, 1);
@@ -387,15 +390,12 @@ static void aspeed_intc0_resolve_route_c1i1o2mc0i1o1_invalid(struct kunit *test)
 			.nranges = ARRAY_SIZE(intc0_ranges),
 		}
 	};
-	const struct irq_domain c0domain = {
-		.host_data = &intc0,
-		.fwnode = &intc0_node.fwnode
-	};
 	int rc;
 
-	rc = aspeed_intc0_resolve_route(&c0domain, ARRAY_SIZE(c1outs), c1outs,
-					ARRAY_SIZE(c1ranges), c1ranges,
-					&resolved);
+	rc = aspeed_intc0_resolve_route_test(&intc0_node.fwnode, &intc0,
+					     ARRAY_SIZE(c1outs), c1outs,
+					     ARRAY_SIZE(c1ranges), c1ranges,
+					     &resolved);
 	KUNIT_EXPECT_EQ(test, rc, 1);
 	KUNIT_EXPECT_EQ(test, resolved.start, 0);
 	KUNIT_EXPECT_EQ(test, resolved.count, 1);
@@ -438,15 +438,12 @@ aspeed_intc0_resolve_route_c1i1o1mc0i1o1_bad_range_upstream(struct kunit *test)
 			.nranges = ARRAY_SIZE(intc0_ranges),
 		}
 	};
-	const struct irq_domain c0domain = {
-		.host_data = &intc0,
-		.fwnode = &intc0_node.fwnode
-	};
 	int rc;
 
-	rc = aspeed_intc0_resolve_route(&c0domain, ARRAY_SIZE(c1outs), c1outs,
-					ARRAY_SIZE(c1ranges), c1ranges,
-					&resolved);
+	rc = aspeed_intc0_resolve_route_test(&intc0_node.fwnode, &intc0,
+					     ARRAY_SIZE(c1outs), c1outs,
+					     ARRAY_SIZE(c1ranges), c1ranges,
+					     &resolved);
 	KUNIT_EXPECT_NE(test, rc, 0);
 }
 
-- 
2.39.5


                 reply	other threads:[~2026-05-15  9:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260515090730.403171-1-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ryan_chen@aspeedtech.com \
    --cc=tglx@kernel.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