From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-244107.protonmail.ch (mail-244107.protonmail.ch [109.224.244.107]) (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 DED8333F5AB; Mon, 8 Jun 2026 11:09:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.107 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780916977; cv=none; b=NrkSnrsmjn0kKGApSyF83H8ge5KVk7SYBIBO+at2ptx453D/1lYkhrrLCBUT7bu3V0xdeWvxBvlxAyHDXxw/gcjddmZjwoda8soH39sIYniJrPMOn7UNTcTP2mwiMM05tterZHZVcmwpXf+HxIuiDJQfA5KuprsBgAap3A0LIoA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780916977; c=relaxed/simple; bh=ulh0evGVPPNjBy7iwCTYBFGX/Ds4y8hHb8LHBFs/1Uo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t9ABlyTNp0/s/fZ5TNfLdejM8DyVfSURj6xiN1dy1dd2n6dedyaIefMkDSmtgqiYe0sBeOZ3dtrbeXdUba2Y4ua0HtDQFADk9YB/pmBiIMulcD2LojgdzffXdruzT7Ozc7oahzTID2sPYHdsd3BQw6BzMHoop0AIemqPOeI9luU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (2048-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=NsXeS3L0; arc=none smtp.client-ip=109.224.244.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="NsXeS3L0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=protonmail; t=1780916965; x=1781176165; bh=yE0kow4cPVmFeFmEU4SXwVIDnwzfPDzpouaEmX4Fpfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=NsXeS3L04i15iimqeQaZUZYdMfXHdM6AtyVzrrKg6DzkZAeUqnoVni7BzJWv9tRFy md3+OCdXghTfJSoR7pe0a32hH6HbsE3/WiSon673+Vzdp7zjehk0QrZuFh8V7JUADg VagBPktDkP4duqhHP0LKSf3pbngkzHAxrYI/+t66RRB2Nbbi/cMmjkNTxluw+wB1sz EqHNtng0Aw6ptyHkF0y/b0/bBKW/ke9ZZxYQ0Sym5HHdXGxDoN8veFLY/PYa/aUXO+ QXLE2vECd+/1NoVCBvSNLCAPl+xobUREhrcqv0ZNrJ1kW7+EgxZHeVY7vGViw7Bi+N haetP5ApFakYg== X-Pm-Submission-Id: 4gYq755lFlz2ScNk From: =?UTF-8?q?Onur=20=C3=96zkan?= To: Maurice Hieronymus Cc: Michael Turquette , Stephen Boyd , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Drew Fustini , Guo Ren , Fu Wei , Michal Wilczynski , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-clk@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pwm@vger.kernel.org Subject: Re: [PATCH v2 1/2] rust: clk: Add ExclusiveClk wrapper for clk_rate_exclusive_get Date: Mon, 8 Jun 2026 14:09:13 +0300 Message-ID: <20260608110920.422773-1-work@onurozkan.dev> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260605-rate-exclusive-get-th1520-v2-1-695640bf7249@mailbox.org> References: <20260605-rate-exclusive-get-th1520-v2-0-695640bf7249@mailbox.org> <20260605-rate-exclusive-get-th1520-v2-1-695640bf7249@mailbox.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, 05 Jun 2026 08:59:59 +0200=0D Maurice Hieronymus wrote:=0D =0D > Add Rust bindings for clk_rate_exclusive_get() and=0D > clk_rate_exclusive_put().=0D > =0D > Clk::rate_exclusive_get() consumes the Clk and returns an ExclusiveClk;=0D > the matching put is issued from its Drop impl. ExclusiveClk derefs to=0D > Clk so existing rate / prepare / enable APIs remain available on the=0D > locked handle.=0D > =0D > Reviewed-by: Alice Ryhl =0D > Signed-off-by: Maurice Hieronymus =0D > ---=0D > rust/kernel/clk.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++++=0D > 1 file changed, 60 insertions(+)=0D > =0D > diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs=0D > index 7abbd0767d8c..f834f4833f18 100644=0D > --- a/rust/kernel/clk.rs=0D > +++ b/rust/kernel/clk.rs=0D > @@ -249,6 +249,22 @@ pub fn set_rate(&self, rate: Hertz) -> Result {=0D > // [`clk_set_rate`].=0D > to_result(unsafe { bindings::clk_set_rate(self.as_raw(), rat= e.as_hz()) })=0D > }=0D > +=0D > + /// Acquire exclusive control over the clock's rate.=0D > + ///=0D > + /// Consumes the [`Clk`] and returns an [`ExclusiveClk`] that re= leases the exclusivity=0D > + /// when dropped. While held, no other consumer may change the c= lock's rate.=0D > + ///=0D > + /// Equivalent to the kernel's [`clk_rate_exclusive_get`] API. M= ust not be called from=0D > + /// atomic context.=0D > + ///=0D > + /// [`clk_rate_exclusive_get`]: https://docs.kernel.org/core-api= /kernel-api.html#c.clk_rate_exclusive_get=0D > + pub fn rate_exclusive_get(self) -> Result {=0D > + // SAFETY: By the type invariants, self.as_raw() is a valid = argument for=0D > + // [`clk_rate_exclusive_get`].=0D > + to_result(unsafe { bindings::clk_rate_exclusive_get(self.as_= raw()) })?;=0D > + Ok(ExclusiveClk(self))=0D > + }=0D =0D We usually inline FFI wrappers.=0D =0D > }=0D > =0D > impl Drop for Clk {=0D > @@ -329,6 +345,50 @@ fn deref(&self) -> &Clk {=0D > &self.0=0D > }=0D > }=0D > +=0D > + /// A [`Clk`] with exclusive control over its rate.=0D > + ///=0D > + /// While an [`ExclusiveClk`] exists, no other consumer of the same = clock may change its rate.=0D > + /// Obtained by calling [`Clk::rate_exclusive_get`]; the exclusivity= is released automatically=0D > + /// when the value is dropped, after which the inner [`Clk`] is drop= ped as usual.=0D > + ///=0D > + /// # Invariants=0D > + ///=0D > + /// An [`ExclusiveClk`] instance owns a [`Clk`] for which `clk_rate_= exclusive_get` has been=0D > + /// called and the matching `clk_rate_exclusive_put` has not yet bee= n called.=0D > + ///=0D > + /// # Examples=0D > + ///=0D > + /// ```=0D > + /// use kernel::clk::{Clk, ExclusiveClk};=0D > + /// use kernel::device::Device;=0D > + /// use kernel::error::Result;=0D > + ///=0D > + /// fn lock_rate(dev: &Device) -> Result {=0D > + /// let clk =3D Clk::get(dev, None)?;=0D > + /// clk.prepare_enable()?;=0D > + /// clk.rate_exclusive_get()=0D > + /// }=0D > + /// ```=0D > + pub struct ExclusiveClk(Clk);=0D > +=0D > + // Make [`ExclusiveClk`] behave like [`Clk`].=0D > + impl Deref for ExclusiveClk {=0D > + type Target =3D Clk;=0D > +=0D > + fn deref(&self) -> &Clk {=0D > + &self.0=0D > + }=0D > + }=0D > +=0D > + impl Drop for ExclusiveClk {=0D > + fn drop(&mut self) {=0D > + // SAFETY: By the type invariants, self.as_raw() is a valid = argument for=0D > + // [`clk_rate_exclusive_put`] and balances the [`clk_rate_ex= clusive_get`] call from=0D > + // [`Clk::rate_exclusive_get`].=0D =0D I think [`...`] wouldn't work on regular comments. They are only for=0D doc-comments.=0D =0D Thanks,=0D Onur=0D =0D > + unsafe { bindings::clk_rate_exclusive_put(self.as_raw()) };= =0D > + }=0D > + }=0D > }=0D > =0D > #[cfg(CONFIG_COMMON_CLK)]=0D > =0D > -- =0D > 2.51.2=0D > =0D