From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796365462; b=Nj+ALh0ojDCFAC+TU2gtjgkm9hxhgFs9nXgTqy97av6fZLeYwyOo9G/rsE2LdNlYSEV9 3DavpO+8xO8GrxpbMxJSpQzCPoMj9oUWAt22z1bgciQwbAEJxk0R+OX2Ttz3BnwvHkcCr xGUBrVWqH39FAP2Q+enWmIH90bLipGL0EKQaxW38jYaEVIzns0dEM+YbzOX6fpRPiU/h8 VKqJzG8HZUV6mIS8+plWbZNtEfjtoqlxWhQOlx0iNXwvyum0yzdbiDM0rcCZULfpBI8rx jsqnXv6zXmPsYNCxS2bdyBEMZ75MjVWwtx9QXm37IYn+f/4yDA2IqYwTttpu5ulWnHQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365462; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=TJREbYYNLz59JlaSUKz+q694pC558uUbKU2EqOF3ey0=; b=wklJcu9edTBDdxrw5kboBjlCHmNb1CyYKUGpH/DSG01qnznjWA9TgWxBHE50iG2rtHY1 3q77gD4vM5CRyeUr8mzJryvZz9hkJc84zCyaNTw/V8KblB72aNR0Zgx/fby5CHRTJRPqH jzgVyrjBSRtUStDMtJY+BSR6I5Z3vGD09dMXREtjEpDRqnQqDRUWqdahxXZ6oW+ouGUAc gb88p/h0tu+xDfHs5bgodAYG61t4H5Q8nt9eo+GNlvceMr1v64nsFug2nitrrSqGI70to VMDTnXZ6IK4HaTAEfFFgQYsTeLycRUq1Ed6Yv8jXRCWL6O0X1KyGanxOCEDc0MSIMVw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kTQ4mRpO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (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 4DAC0606A335 for ; Fri, 4 Dec 2026 06:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kTQ4mRpO Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD6151F000CE; Fri, 4 Dec 2026 06:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796365461; bh=TJREbYYNLz59JlaSUKz+q694pC558uUbKU2EqOF3ey0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=kTQ4mRpOlew9t0rbPv9lgPXnK1u/cbI6DUMHS4MvziGURfiNXNdO2g7ZFNma3HYYc 0QH0mMdVfQOMOxa4lE3/rQmRgDYdJ+eY+FIIUWEqeXz2qm8IYJ3NfJ9g9TBeWDEv18 Wo3eoYg/wFCRgI5/fObvlwsfKD2BqvPYBMyPI/+zN7xiG9gZdGm9VQGurND8W3663x LjEnPBdYFt+MQ0ZhDfx6sPUj6dEMhaog0fCObMazR9jje4+FXawtRG5HB/uE6QHtBk 1RTvloH7Ko44vBZGRvJgINbCF2rU4O1ibtvcYmfSBS56Prw8rchhvtxaETd6XGOG1I zgU17NdjNq0TQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 2/5] clocksource/drivers/spacemit: Add K1 timer support Reply-To: sashiko-reviews@lists.linux.dev To: "Troy Mitchell" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204-spacemit-soc-timer-v5-2-c863b6ffc645@linux.spacemit.com> References: <20261204-spacemit-soc-timer-v5-0-c863b6ffc645@linux.spacemit.com> <20261204-spacemit-soc-timer-v5-2-c863b6ffc645@linux.spacemit.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 06:24:21 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] clocksource/spacemit: devm-managed clkevt freed on CCU supplier unbind - [Medium] clocksource/drivers/spacemit: missing set_state_oneshot_stopped callback - [Medium] clocksource: redundant quiesce udelay in spacemit_timer_next_event() - [Low] clocksource/drivers/spacemit: missing RESET_CONTROLLER Kconfig dependency -- commit ad7135b3687fa52d25d983234e9577a502e58903 Author: Troy Mitchell clocksource/drivers/spacemit: Add K1 timer support This commit adds a platform clockevent driver for the SpacemiT K1/K3 APB timers, registering counter 0 and its first match comparator as a shared oneshot device for tick broadcast. > diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig > index da83483296d5a..e14bb40f9a314 100644 > --- a/drivers/clocksource/Kconfig > +++ b/drivers/clocksource/Kconfig > @@ -163,6 +163,17 @@ config RZN1_TIMER > - 2 32-bit timers > Two timers blocks are available in RZ/N1 SoCs. > =20 > +config SPACEMIT_TIMER > + bool "SpacemiT K1/K3 timer" > + depends on ARCH_SPACEMIT || COMPILE_TEST > + depends on OF && COMMON_CLK && HAS_IOMEM > + default y if ARCH_SPACEMIT [Severity: Low] Should SPACEMIT_TIMER also depend on RESET_CONTROLLER? spacemit_timer_probe() requests a mandatory reset via devm_reset_control_get_exclusive(), which fails with -ENOTSUPP when CONFIG_RESET_CONTROLLER is disabled. Neither ARCH_SPACEMIT nor SPACEMIT_TIMER selects RESET_CONTROLLER, so the driver can be built in on ARCH_SPACEMIT and then unconditionally fail to probe. > diff --git a/drivers/clocksource/timer-spacemit.c b/drivers/clocksource/t= imer-spacemit.c > new file mode 100644 > index 0000000000000..e0f24b133a216 > --- /dev/null > +++ b/drivers/clocksource/timer-spacemit.c [ ... ] > +static int spacemit_timer_next_event(unsigned long delta, > + struct clock_event_device *evt) > +{ > + struct spacemit_timer *timer =3D to_spacemit_timer(evt); > + unsigned long flags; > + u32 val; > + int ret; > + > + raw_spin_lock_irqsave(&timer->lock, flags); > + > + ret =3D spacemit_timer_quiesce(timer); > + if (ret) > + goto out; [Severity: Medium] Can spacemit_timer_next_event() skip spacemit_timer_quiesce() when the counter is already stopped and synchronized? spacemit_timer_stop() always runs udelay(timer->sync_us) at least once. When a broadcast expiry schedules a next wakeup, spacemit_timer_interrupt() has already quiesced the timer before event_handler() re-enters spacemit_timer_next_event() under tick_broadcast_lock with IRQs disabled. Since clockevents_program_event() computes delta beforehand, the redundant busy-wait holds tick_broadcast_lock with IRQs off and delays the wakeup by at least sync_us (3 us at 1 MHz, 92 us at 32.768 kHz). Tracking whether the timer is already quiesced under timer->lock would avoid this. [ ... ] > + timer->clkevt.set_next_event =3D spacemit_timer_next_event; > + timer->clkevt.set_state_shutdown =3D spacemit_timer_shutdown; > + timer->clkevt.set_state_oneshot =3D spacemit_timer_shutdown; > + timer->clkevt.tick_resume =3D spacemit_timer_resume; [Severity: Medium] Should timer->clkevt.set_state_oneshot_stopped also be set to spacemit_timer_shutdown? When NOHZ idle cancels an event with tick_program_event(KTIME_MAX), __clockevents_switch_state() returns -ENOSYS when set_state_oneshot_stopped is NULL. On UP systems without Sstc (where rating 200 beats the RISC-V timer's 100), counter 0 stays armed and fires a spurious wakeup interrupt. [ ... ] > + ret =3D devm_request_irq(dev, irq, spacemit_timer_interrupt, IRQF_TIMER, > + dev_name(dev), timer); > + if (ret) > + return dev_err_probe(dev, ret, "Failed to request timer interrupt\n"); > + > + clockevents_config_and_register(&timer->clkevt, rate, TMR_MIN_DELTA, > + U32_MAX - 1); > + return 0; > +} > + > +static const struct of_device_id spacemit_timer_match[] =3D { > + { .compatible =3D "spacemit,k1-timer" }, > + { } > +}; > + > +static struct platform_driver spacemit_timer_driver =3D { > + .probe =3D spacemit_timer_probe, > + .driver =3D { > + .name =3D "spacemit-timer", > + .of_match_table =3D spacemit_timer_match, > + .suppress_bind_attrs =3D true, > + }, > +}; [Severity: High] Can unbinding the CCU supplier free struct spacemit_timer and its devm resources while &timer->clkevt is still registered? suppress_bind_attrs only hides this driver's own sysfs unbind file, not forced consumer unbind in device_links_unbind_consumers(). Because k1_ccu_driver and k3_ccu_driver expose sysfs unbind, unbinding syscon_apbc runs devres_release_all() on spacemit-timer. That frees struct spacemit_timer, unmaps timer->base, disables the clocks, and frees the IRQ while &timer->clkevt stays live in clockevent_devices and tick_broadcast_device.evtdev, causing a use-after-free on the next broadcast event. Using non-devm allocations and resource acquisitions with explicit probe error cleanup avoids releasing permanent clockevent state. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-spacemit-s= oc-timer-v5-0-c863b6ffc645@linux.spacemit.com?part=3D2