From nobody Mon May 25 05:55:44 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAE6E3E4C6B; Mon, 18 May 2026 09:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779095089; cv=none; b=YvlYOfePDYmHLnIGuoT0+42/TMPLfeSjm3Crqttv7+VUUycy3xZqRYjIw/eUvLsB82TjcP2QAyI0KZavcKK048NIhXVOrX3RS5aC4Q29mViFpNMnsWX/9xwNkq6NRThUtaCDny0RWd27PZtQ44MTOoE01x+plmkSGgZH7pS5mGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779095089; c=relaxed/simple; bh=ruE92vovZ7bi8wrfRt6OHMAHGwfGsUW1GoSL/IaG0EA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=ArXbN3jLl4jIBrne5H5sj5mtSm9bSrIdTxO6IcYL1HtgAPbbuMPhdZQUIzpxRjxplQ31CEBXCjFzv7YchblPs6h4NqMkzYF8YP4D7ZwMr0Y9UGzZllG8UPrgEWU3J8THY6DXcHlajLfRirHB8Mr4EDUtedoAEmMlV55As/36+mg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FcWTxTc6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QQB9ZPep; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FcWTxTc6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QQB9ZPep" Date: Mon, 18 May 2026 09:04:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779095086; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bgvn7blWsF/WJVnQaMK48x4ExjgmQPVeEownGxJJAYI=; b=FcWTxTc6SCSh/LsVZDi5Aj2GvO56FQ9j2PyG20c85XGgZ0diq5fR5RpTxV4BjZArBDu2or xJAgbAQbulK9FhA0TU/mGvlEdUsBn0VqsLsqZzgtzxS0PXcuU78aaHxnkoMSQpc54JlP/P 8WgNmwIYyo0Jg3w/Dx5eRvePaQ8lOfekPyLm0S5jALE3aXKRvX6wRQyFwZ4odw1DFodhmK T+xAt+skN2gvOjRiDboGA/sgoxDmOsvtBgWIz92RkKG3gNPpakAmxdaZW14NH4Gcw3fin8 AoTyWPZ9BFTumsFqbBYqA51JgF8hBQ0iln7dtEciQpfo0P9RK6EVFKwSssvu8w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779095086; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bgvn7blWsF/WJVnQaMK48x4ExjgmQPVeEownGxJJAYI=; b=QQB9ZPep7JWPo6QzrcuMhgW6SP5N+HX+9zinDZ48qw5pkkwAJVRY2mJhYtnr7AmhF/VhZe 0hxhnJ6JKBCBiUDQ== From: "tip-bot2 for Daniel Lezcano" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/clocksource] clocksource: Add devm_clocksource_register_*() helpers Cc: Daniel Lezcano , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260506153831.605159-1-daniel.lezcano@oss.qualcomm.com> References: <20260506153831.605159-1-daniel.lezcano@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177909508462.711.15508167697855490004.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the timers/clocksource branch of = tip: Commit-ID: 3eb4923e68511741f3eb3fab55ed1e8ded9e4da8 Gitweb: https://git.kernel.org/tip/3eb4923e68511741f3eb3fab55ed1e8de= d9e4da8 Author: Daniel Lezcano AuthorDate: Wed, 06 May 2026 17:38:31 +02:00 Committer: Thomas Gleixner CommitterDate: Mon, 18 May 2026 11:02:51 +02:00 clocksource: Add devm_clocksource_register_*() helpers Introduce device-managed helpers for clocksource registration. The clocksource framework currently provides __clocksource_register_scale() along with convenience wrappers for Hz and kHz registration. However, drivers must handle error paths and cleanup manually, typically by pairing registration with an explicit clocksource_unregister() call. Add a devm-based variant, __devm_clocksource_register_scale(), along with devm_clocksource_register_hz() and devm_clocksource_register_khz() helpers. These helpers register the clocksource and attach a devres action to automatically unregister it on driver detach or probe failure. This simplifies driver code by: * removing explicit cleanup paths * ensuring correct teardown ordering * aligning with the devm-based resource management model widely used across the kernel While drivers can open-code devm_add_action_or_reset(), providing a dedicated helper avoids duplication, reduces boilerplate, and ensures consistent usage across drivers, following patterns used in other subsystems. This is also particularly useful for drivers built as modules, where device-managed resource handling avoids manual cleanup in remove paths and ensures correct teardown on module unload. This helper is self-contained and can be adopted progressively by drivers. No functional change. Signed-off-by: Daniel Lezcano Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/20260506153831.605159-1-daniel.lezcano@oss.q= ualcomm.com --- include/linux/clocksource.h | 15 +++++++++++++++ kernel/time/clocksource.c | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 7c38190..c5b34c1 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -236,6 +236,9 @@ clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from,= u32 to, u32 minsec); */ extern int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq); +extern int +__devm_clocksource_register_scale(struct device *dev, struct clocksource *= cs, + u32 scale, u32 freq); extern void __clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 fre= q); =20 @@ -258,6 +261,18 @@ static inline int clocksource_register_khz(struct cloc= ksource *cs, u32 khz) return __clocksource_register_scale(cs, 1000, khz); } =20 +static inline int devm_clocksource_register_hz(struct device *dev, + struct clocksource *cs, u32 hz) +{ + return __devm_clocksource_register_scale(dev, cs, 1, hz); +} + +static inline int devm_clocksource_register_khz(struct device *dev, + struct clocksource *cs, u32 khz) +{ + return __devm_clocksource_register_scale(dev, cs, 1000, khz); +} + static inline void __clocksource_update_freq_hz(struct clocksource *cs, u3= 2 hz) { __clocksource_update_freq_scale(cs, 1, hz); diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index baee13a..313f6c8 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -1338,6 +1338,26 @@ int __clocksource_register_scale(struct clocksource = *cs, u32 scale, u32 freq) } EXPORT_SYMBOL_GPL(__clocksource_register_scale); =20 +static void __devm_clocksource_unregister(void *data) +{ + struct clocksource *cs =3D data; + + clocksource_unregister(cs); +} + +int __devm_clocksource_register_scale(struct device *dev, struct clocksour= ce *cs, + u32 scale, u32 freq) +{ + int ret; + + ret =3D __clocksource_register_scale(cs, scale, freq); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, __devm_clocksource_unregister, cs); +} +EXPORT_SYMBOL_GPL(__devm_clocksource_register_scale); + /* * Unbind clocksource @cs. Called with clocksource_mutex held */