From: Caleb James DeLisle <cjd@cjdns.fr>
To: linux-mips@vger.kernel.org
Cc: conor+dt@kernel.org, daniel.lezcano@kernel.org,
devicetree@vger.kernel.org, krzk+dt@kernel.org,
linux-kernel@vger.kernel.org, naseefkm@gmail.com,
robh@kernel.org, tglx@kernel.org, grandmaster@al2klimov.de,
Caleb James DeLisle <cjd@cjdns.fr>
Subject: [PATCH v10 5/5] clocksource/timer-econet-en751221: Do not use NR_CPUS for resource array size
Date: Thu, 15 Oct 2026 14:53:31 +0000 [thread overview]
Message-ID: <20261015145331.453837-6-cjd@cjdns.fr> (raw)
In-Reply-To: <20261015145331.453837-1-cjd@cjdns.fr>
Each pair of VPEs has one timer block, so the number of blocks is half
the number of CPUs on the hardware. However, since NR_CPUS is a
configuration, it is possible that it will be less than the number of
actual CPUs on the hardware which will cause the array to be too small
for the specified DT.
Switch to an allocated buffer for storing the iomem resources, as is
done for the IRQs.
Signed-off-by: Caleb James DeLisle <cjd@cjdns.fr>
---
drivers/clocksource/timer-econet-en751221.c | 29 ++++++++++++++-------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/drivers/clocksource/timer-econet-en751221.c b/drivers/clocksource/timer-econet-en751221.c
index ebcc6fa34218..739d95275385 100644
--- a/drivers/clocksource/timer-econet-en751221.c
+++ b/drivers/clocksource/timer-econet-en751221.c
@@ -19,11 +19,10 @@
#define ECONET_BITS 32
#define ECONET_MIN_DELTA 0x00001000
#define ECONET_MAX_DELTA GENMASK(ECONET_BITS - 2, 0)
-/* 34Kc hardware has 1 block and 1004Kc has 2. */
-#define ECONET_NUM_BLOCKS DIV_ROUND_UP(NR_CPUS, 2)
static struct {
- void __iomem *membase[ECONET_NUM_BLOCKS];
+ void __iomem **membase;
+ int num_membase;
int *irqs;
int num_irqs;
bool is_percpu;
@@ -37,6 +36,10 @@ static DEFINE_PER_CPU(struct clock_event_device, econet_timer_pcpu);
*/
static inline void __iomem *reg_ctl(u32 timer_n)
{
+ /* reg_ctl() is used to check if a clock exists */
+ if (timer_n >> 1 >= econet_timer.num_membase)
+ return NULL;
+
return econet_timer.membase[timer_n >> 1];
}
@@ -200,11 +203,6 @@ static int __init timer_init(struct device_node *np)
num_irqs);
return -EINVAL;
}
- if (num_blocks > ARRAY_SIZE(econet_timer.membase)) {
- pr_err("%pOFn: Too many regs: max %zd got %d\n", np,
- ARRAY_SIZE(econet_timer.membase), num_blocks);
- return -EINVAL;
- }
if (num_blocks == 0) {
pr_err("%pOFn: At least one reg block must be provided\n", np);
return -EINVAL;
@@ -225,6 +223,15 @@ static int __init timer_init(struct device_node *np)
if (!econet_timer.irqs)
return -ENOMEM;
+ econet_timer.num_membase = num_blocks;
+ econet_timer.membase = kcalloc(num_blocks,
+ sizeof(*econet_timer.membase),
+ GFP_KERNEL);
+ if (!econet_timer.membase) {
+ ret = -ENOMEM;
+ goto out_kfree_irqs;
+ }
+
for (i = 0; i < num_blocks; i++) {
econet_timer.membase[i] = of_iomap(np, i);
if (!econet_timer.membase[i]) {
@@ -303,13 +310,17 @@ static int __init timer_init(struct device_node *np)
irq_dispose_mapping(econet_timer.irqs[i]);
}
out_membase:
- for (int i = 0; i < ARRAY_SIZE(econet_timer.membase); i++) {
+ for (int i = 0; i < num_blocks; i++) {
if (econet_timer.membase[i]) {
iounmap(econet_timer.membase[i]);
econet_timer.membase[i] = NULL;
}
}
+ kfree(econet_timer.membase);
+ econet_timer.membase = NULL;
+
+out_kfree_irqs:
kfree(econet_timer.irqs);
econet_timer.irqs = NULL;
--
2.39.5
prev parent reply other threads:[~2026-10-15 14:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 14:53 [PATCH v10 0/5] clocksource/timer-econet-en751221: Support irq number per timer Caleb James DeLisle
2026-10-15 14:53 ` [PATCH v10 1/5] dt-bindings: timer: econet: Update EN751627 for multi-IRQ Caleb James DeLisle
2026-10-15 14:53 ` [PATCH v10 2/5] clocksource/timer-econet-en751221: Init teardown on error if possible Caleb James DeLisle
2026-10-15 14:53 ` [PATCH v10 3/5] clocksource/timer-econet-en751221: Disable IRQ until cevt registered Caleb James DeLisle
2026-10-15 14:53 ` [PATCH v10 4/5] clocksource/timer-econet-en751221: Support EN751627 without percpu IRQ Caleb James DeLisle
2026-10-15 14:53 ` Caleb James DeLisle [this message]
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=20261015145331.453837-6-cjd@cjdns.fr \
--to=cjd@cjdns.fr \
--cc=conor+dt@kernel.org \
--cc=daniel.lezcano@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=grandmaster@al2klimov.de \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=naseefkm@gmail.com \
--cc=robh@kernel.org \
--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
all inboxes | Powered by JetHome®