From nobody Sun Oct 5 20:22:48 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 5DF77298981; Tue, 29 Jul 2025 17:32:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753810336; cv=none; b=lH6FInrr8WiU20Gx5dlz7cDaFHMm6TvXC1JrG0dqg98GjLW4wlSUF4TDibQmgX6Agii6Cbm3fBVA1oeF9c9Pcnu0p2FSCzciyoDfkl+m9cGIJejJ/EWKINaUca9kWeDifBT7qs7GFU9dzM4Hths+TNCxLzfyw0mBW7SVMa/Y+7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753810336; c=relaxed/simple; bh=Oj4lRpToTiwjV+8i7TobinzVjwDho+X4zuQNTzFsO9E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f85H+g+qYMe3k/v0NnrsHj1Zt9KaUer+ySX5UciTiJwrXRy0JiWH1S8qOpfTQrAec60iYhSS4zwZraWpsgSa2e4h0PfVJg2VtJxuUsLFu7ZGWuyjCfCYYXgZaL5sFFff7B0c2La6TSeaeYSIHTRCVxm0AeSXwt29qR1e7JsajM0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=RfHCFh0J; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="RfHCFh0J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1753810332; bh=Oj4lRpToTiwjV+8i7TobinzVjwDho+X4zuQNTzFsO9E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RfHCFh0J3kSxDqAZOrX85qUrFJj+QvT40B6cASJSKeH8MDSSMjpdqoMMOS4lRSyM6 JcSK/9vAuD27jWweqib+vVd/gHjxZq3RYildi5iRApE+Yw4jq3+P+XAki1YXHUyCQT GhHs0mNi7hG7bf+NQmfUtQxOVt362wIBV7ez4IxmZ+Ln4NJ48aIGacGpixbrZD27I3 mpjd5Nprbgc12oqtdcGSuzr9BXIP3mgNzwSda4d1a4GL63CvFOQ7AJa/ypP76yINaL PFS8biNxUwBnFUfEBOa2eeVvOCzjvphN96d8++gOiM5e7EzXLD6eFyROV4nGChJfcN 3xknkMe9AZJMQ== Received: from [192.168.0.7] (unknown [IPv6:2804:14d:72b4:82f6:67c:16ff:fe57:b5a3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dwlsalmeida) by bali.collaboradmins.com (Postfix) with ESMTPSA id 400A617E14DB; Tue, 29 Jul 2025 19:32:10 +0200 (CEST) From: Daniel Almeida Date: Tue, 29 Jul 2025 14:31:40 -0300 Subject: [PATCH 1/2] rust: regulator: remove needless &mut from member functions 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 Message-Id: <20250729-regulator-send-sync-v1-1-8bcbd546b940@collabora.com> References: <20250729-regulator-send-sync-v1-0-8bcbd546b940@collabora.com> In-Reply-To: <20250729-regulator-send-sync-v1-0-8bcbd546b940@collabora.com> To: Liam Girdwood , Mark Brown , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Daniel Almeida X-Mailer: b4 0.14.2 Regulator functions like "regulator_enable()" and "regulator_disable()" already provide their own locking through "regulator_lock_dependent()", so we can safely call the Rust API with a shared reference. This was already the case with Regulator::set_voltage() on the Rust side, but it was forgotten for Regulator::enable() and Regulator::disable(). Signed-off-by: Daniel Almeida Reviewed-by: Alexandre Courbot Reviewed-by: Alice Ryhl --- rust/kernel/regulator.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs index 65f3a125348f2d821898188b4ac6a0b593f18bf2..d56aa229e838c45258a27cea742= a693dd71e8e40 100644 --- a/rust/kernel/regulator.rs +++ b/rust/kernel/regulator.rs @@ -203,20 +203,20 @@ pub struct Error { /// // A fictictious probe function that obtains a regulator and sets it u= p. /// fn probe(dev: &Device) -> Result { /// // Obtain a reference to a (fictitious) regulator. -/// let mut regulator =3D Regulator::::get(dev, c_str!("vcc")= )?; +/// let regulator =3D Regulator::::get(dev, c_str!("vcc"))?; /// /// Ok(PrivateData { regulator }) /// } /// /// // A fictictious function that indicates that the device is going to b= e used. -/// fn open(dev: &Device, data: &mut PrivateData) -> Result { +/// fn open(dev: &Device, data: &PrivateData) -> Result { /// // Increase the `enabled` reference count. /// data.regulator.enable()?; /// /// Ok(()) /// } /// -/// fn close(dev: &Device, data: &mut PrivateData) -> Result { +/// fn close(dev: &Device, data: &PrivateData) -> Result { /// // Decrease the `enabled` reference count. /// data.regulator.disable()?; /// @@ -289,12 +289,12 @@ fn get_internal(dev: &Device, name: &CStr) -> Result<= Regulator> { }) } =20 - fn enable_internal(&mut self) -> Result { + fn enable_internal(&self) -> Result { // SAFETY: Safe as per the type invariants of `Regulator`. to_result(unsafe { bindings::regulator_enable(self.inner.as_ptr())= }) } =20 - fn disable_internal(&mut self) -> Result { + fn disable_internal(&self) -> Result { // SAFETY: Safe as per the type invariants of `Regulator`. to_result(unsafe { bindings::regulator_disable(self.inner.as_ptr()= ) }) } @@ -310,7 +310,7 @@ pub fn get(dev: &Device, name: &CStr) -> Result { pub fn try_into_enabled(self) -> Result, Error> { // We will be transferring the ownership of our `regulator_get()` = count to // `Regulator`. - let mut regulator =3D ManuallyDrop::new(self); + let regulator =3D ManuallyDrop::new(self); =20 regulator .enable_internal() @@ -339,7 +339,7 @@ pub fn get(dev: &Device, name: &CStr) -> Result { pub fn try_into_disabled(self) -> Result, Error> { // We will be transferring the ownership of our `regulator_get()` = count // to `Regulator`. - let mut regulator =3D ManuallyDrop::new(self); + let regulator =3D ManuallyDrop::new(self); =20 regulator .disable_internal() @@ -366,12 +366,12 @@ pub fn get(dev: &Device, name: &CStr) -> Result= { } =20 /// Increases the `enabled` reference count. - pub fn enable(&mut self) -> Result { + pub fn enable(&self) -> Result { self.enable_internal() } =20 /// Decreases the `enabled` reference count. - pub fn disable(&mut self) -> Result { + pub fn disable(&self) -> Result { self.disable_internal() } } --=20 2.50.0 From nobody Sun Oct 5 20:22:48 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 F222229993B; Tue, 29 Jul 2025 17:32:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753810338; cv=none; b=Em3CpT5NdilkWx4YIofbKsB8TCrqyrf5BzgF1OoWgN7L4uysPTlwbELueVHL6nDIdS4EMnbfOxheRFuQb+BfTjYtdIMmEBljtNL3hStjjyY92CwPaDPHeaDIFRux146KdGGuqBrPyGJYSAEZj/kM3YuNN71CpunI3FWAWTcMWFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753810338; c=relaxed/simple; bh=Ks5rnGdq/WZDwyCCzJeCpscV0ClRUzaNDean8OPtm2Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L2My/yxIBICF94jvk2ypTIoGk1KkGFRzGE+iY0FCjIfpSOnwPfkljxddW5s7aeOdTT9pozVoao3BwjQYdZdF0URV8Tor3nseoF8ZMVTbRQpnI+TgJh0VOoQDXklk2u+WNwIvOP9M3V03bsIyjsjeDZ/0PT7hnFBkeb2QyNoX3Zc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=VpwDJOAq; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="VpwDJOAq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1753810335; bh=Ks5rnGdq/WZDwyCCzJeCpscV0ClRUzaNDean8OPtm2Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VpwDJOAqkiX3lD4854zEundkEt31YVJkW6keXUt+m6QiuQj24ig6JTrZ+4aRnEB1O MCrNhy7Lb3gnF6Icre+H/qrPvud9+d1NQgI2IuHlASDE17Ldam3bXc4pFAeasKZ7Dc VpGcRJr2kOAG5cBYxtCjXqr1ZSlZrxU+hF33zGnEjz0ht2GfBWWZrBpmGpJtStraNI Jrt8yDjBgQBe6NYGZUNczz1pR8eXFkgvLMtPccSzbbTS/jjD8jPL9HO4XFAjQ5l6Vy ZqZvcrJ7a9PVJFqjAIbwgWsKbvSkw/WaeTrZQL2u1HrFdrPKgV8KAOMHsqIu4ZsV0n N+BQZApQGEN1g== Received: from [192.168.0.7] (unknown [IPv6:2804:14d:72b4:82f6:67c:16ff:fe57:b5a3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dwlsalmeida) by bali.collaboradmins.com (Postfix) with ESMTPSA id DFEB217E14DD; Tue, 29 Jul 2025 19:32:12 +0200 (CEST) From: Daniel Almeida Date: Tue, 29 Jul 2025 14:31:41 -0300 Subject: [PATCH 2/2] rust: regulator: implement Send and Sync for Regulator 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 Message-Id: <20250729-regulator-send-sync-v1-2-8bcbd546b940@collabora.com> References: <20250729-regulator-send-sync-v1-0-8bcbd546b940@collabora.com> In-Reply-To: <20250729-regulator-send-sync-v1-0-8bcbd546b940@collabora.com> To: Liam Girdwood , Mark Brown , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Daniel Almeida X-Mailer: b4 0.14.2 Sending a &Regulator to another thread is safe, as the regulator core will properly handle the locking for us. Additionally, there are no restrictions that prevents sending a Regulator to another thread. Given these two facts, implement Send and Sync. Signed-off-by: Daniel Almeida Reviewed-by: Alexandre Courbot Reviewed-by: Alice Ryhl --- rust/kernel/regulator.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs index d56aa229e838c45258a27cea742a693dd71e8e40..704147e18bfc9c993a00f7a1871= 05360ad1d4956 100644 --- a/rust/kernel/regulator.rs +++ b/rust/kernel/regulator.rs @@ -398,6 +398,14 @@ fn drop(&mut self) { } } =20 +// SAFETY: It is safe to send a `Regulator` across threads. In particul= ar, a +// Regulator can be dropped from any thread. +unsafe impl Send for Regulator {} + +// SAFETY: It is safe to send a &Regulator across threads because the C= side +// handles its own locking. +unsafe impl Sync for Regulator {} + /// A voltage. /// /// This type represents a voltage value in microvolts. --=20 2.50.0