From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=5.135.140.105 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796423039; b=G6sXGAOyz8anas9Dnu9h27YbVVU8cPt9nMf/5GV5MBWSAetZ/OxPwa0CywROfPsfS1+I 0z+TpSoy9PJwtNruJUQM9FFSaVRVQiqz/xYx7uV6KH0TYI4Ro5q0nRMSEKGbuVhrsgCWO KlUgud3myG9GuErnYHwjA68YSU1eKK/+LqNDykQjWeYCJfsA1/0tH/361OH2GEz2dFJoX Gj6dqyqSvodXCgsnNuik9+beIdyPESMZ0PiZXtvAm+s1i2OzHY7IGxLMfVUWdLQvjlD7A VSiJZ7Slme0OZQTPs1NGi6OecRRioX0EN6XrxqqOPRmM5ZzzsoOhN5t+arYdpydpFuA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796423039; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-Id:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=DAxqwqdMRnlc/xOoIYWHFEcslEmyDOsu3cQpjlwNjY4=; b=w5lags+GsuayyzWyjRNIuRyN6lgiRpil6z64kr02VWITOV3jN0prRE+qheTmlJFTAMrw +FA68ZMwenqMcQWep1xZCJ1ZgDYGl6Wgkyv91Nq6DHUSGVXxb2RVmj6FlGfthgkXNA0G2 eGPIbBR8w1KtqUDXMbPZO7w1o6u4mr9v2fYPKiTBb0q1YG+f0868KjIGKEnt14fuQNGXN r8bXLJbV5iidOPggumxN4ifLkEEV2PXbz1BfeVMfm1+fystEgdAohiQ+KtmE3afJIhq6a GLqeb1vr6Z2DKRJx2BcW0czfumJuA9P6l1h8X23caeuMvpuw+foT4X3KppSjZgdu2Ug== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=cjdns.fr; spf=pass smtp.mailfrom=cjdns.fr; dkim=pass header.d=cjdns.fr header.i=@cjdns.fr header.a=rsa-sha256 header.s=dkim header.b=enG0nrwT; arc=none smtp.remote-ip=5.135.140.105 Received: from mail.cjdns.fr (mail.cjdns.fr [5.135.140.105]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BD5A606A69F; Fri, 4 Dec 2026 22:23:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6BD5A606A69F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cjdns.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cjdns.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cjdns.fr header.i=@cjdns.fr header.a=rsa-sha256 header.s=dkim header.b=enG0nrwT Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 607296EE198; Fri, 4 Dec 2026 23:23:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cjdns.fr; s=dkim; t=1796423036; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=DAxqwqdMRnlc/xOoIYWHFEcslEmyDOsu3cQpjlwNjY4=; b=enG0nrwTEUGspq6xfg36IL3mcKMAzu+CrcgmqX41MkLCvzlVo3fmUbCOYxV+v+yQIQoHpV j1H0faZVEYXJQhwry01eSL4074+LxGy1DmfC7jaSNUUrLQ5kEgpBM/aR1yE0KQ1YUgXmiz 307lp4QTK8h8kFPEW28vNJCB5uYFBFn8RUOJakQtQkZDEjC/+/3bxtotxOYLUeMeOdXhpD Jxmg2rq3k94Rt+BAm3g9uce9PYZ9u/niAYaFgzwEPSCOH+QcDulVTe4Q2u4xqk3DuKdECK lO60B61jLe7LlIN18wg0Lcq7ARwYjAywIlycQ0TWDTETkmluwoUiDsDHY8ulvg== From: Caleb James DeLisle 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 Subject: [PATCH RESEND v12 5/5] clocksource/timer-econet-en751221: Do not use NR_CPUS for resource array size Date: Fri, 4 Dec 2026 22:23:34 +0000 Message-Id: <20261204222334.1085123-6-cjd@cjdns.fr> In-Reply-To: <20261204222334.1085123-1-cjd@cjdns.fr> References: <20261204222334.1085123-1-cjd@cjdns.fr> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 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 --- 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 edb3db3125ce3..9f28cc238372c 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]; } @@ -202,11 +205,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; @@ -227,6 +225,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]) { @@ -305,13 +312,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