From mboxrd@z Thu Jan 1 00:00:00 1970 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: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 --- 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..d56aa229e838c45258a27cea742a693dd71e8e40 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 up. /// fn probe(dev: &Device) -> Result { /// // Obtain a reference to a (fictitious) regulator. -/// let mut regulator = Regulator::::get(dev, c_str!("vcc"))?; +/// let regulator = Regulator::::get(dev, c_str!("vcc"))?; /// /// Ok(PrivateData { regulator }) /// } /// /// // A fictictious function that indicates that the device is going to be 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> { }) } - 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()) }) } - 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 = ManuallyDrop::new(self); + let regulator = ManuallyDrop::new(self); 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 = ManuallyDrop::new(self); + let regulator = ManuallyDrop::new(self); regulator .disable_internal() @@ -366,12 +366,12 @@ pub fn get(dev: &Device, name: &CStr) -> Result { } /// Increases the `enabled` reference count. - pub fn enable(&mut self) -> Result { + pub fn enable(&self) -> Result { self.enable_internal() } /// Decreases the `enabled` reference count. - pub fn disable(&mut self) -> Result { + pub fn disable(&self) -> Result { self.disable_internal() } } -- 2.50.0