From nobody Sun Dec 14 21:37:41 2025 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D8DC225766 for ; Tue, 10 Dec 2024 09:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823567; cv=none; b=EpuqmETNb/uzfvp/TbZuYphhqhqoBTko1Hi2vXtD9gm8InS8TwEKmnSRQ3YknsCVKqIbu6LKUEPrZV2TSmBBDEmwIghASmMkCIX2XojD8PShXL8qekJQI6TnAfCVbzLHAuWQHlOYAlscZe3WHIQCgGLf7ve+clt+rAfyd27YIG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823567; c=relaxed/simple; bh=lnFOkiQFTcM8+coi/kR1zS+3K3Kh9pdLRZYdj3FBLXU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YMhJ3Tp4rmuc2Yv83iGu/0VzH5c7+ZiUgk/KGpHgLwuOC4lUkNVkn9HVTjimFKmpkHsJp05JpY1oOZqWcpxCBPFumecrBa9rW2cBaX3946xwLAMzvT325Ma5+k6oEiXN0/JoDTdce1r4H/DFluat15exHUNsT1wXc8LiBO8wkIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ehDkAlUV; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ehDkAlUV" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-385d80576abso3855146f8f.3 for ; Tue, 10 Dec 2024 01:39:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733823564; x=1734428364; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5tOk4o16vH2wNnu69cAh5eCtJYr7jGfSK8UQRzizxqM=; b=ehDkAlUVBBEmIxy5Hy9P/t41SAa+BGGRlAtAUw2E/1y6UGdTdzFeqRZD4l7fAp/heO 6yfOe41hSbUQgioI9rkq9Kucr8zqUpCepMuwGTecgaN6jMso3Gn0ozlbUUIxdKBQgBrp i2udg8MrrfWa36ulG4Y+OP2g7NQv07GzEy6jGjPdGz3zpq1RjzHnRgI8EfQgGe+eZDuf 3Rw12XeIWQ7aMkHBSA7xOOuW3JaKRXSUynz2dBoVhDHMj9+l0nOhOzZhnINz5Ira3lno jQpopv1qoRagfJQfVmxzlstI7I+exM9+S5rk0IjL9AXk2ihjsDIP9LdG2wSP4d23nksJ +8UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823564; x=1734428364; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5tOk4o16vH2wNnu69cAh5eCtJYr7jGfSK8UQRzizxqM=; b=t0h2z+YqnNFZk7vg6ePNxEQn2TTHQmg3UQIiDtR4Eeb7fuWIl0NFKmHrM6YKrZCklQ JdbCyrCsvVrryOlCM4mrXR4vk1mZ2U4OYns3DoQOauQOEh8NvVmel2QcHG4ECjHU2wW9 3NhOPgBX1RHBf9Z3BPNFggDguoSWhj3n6pGuIn4BA3reB7a02qLDmxtVEJjCxCrnIUsz Lt6q2RClPO8VNb3hcbSg37PbonnCEs+4uF6op+Rvp9VZefnPHz2MbC9vlWYkSRwdXBT2 c1ca1eOAuWOQScWsZWGGWt4tDW2VIeaLUAXtZtU42UrWHpoBOq7rJtCEc50zUBYNIqmh x7ug== X-Forwarded-Encrypted: i=1; AJvYcCVVEajBr+dWBMqVwStmZ4ObsD1XDYX+gf1/Ed+gJhLfORW9TM14TMPdNCIBjmkqj6p+l/sb94rb00yS0T8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywh3WWVyuDZZw2ortfqTp0EUcR/7c0m6ToL1w5P5isBuZnPgRs7 kWZJX0WNZ9Y1ADfryq2BIxGAUNl/4XTEQ1IW3pb82txr15t2ppT5tCBy3S/pVp2p+vJHixhjZlR LL4hm+A/qzgoDVA== X-Google-Smtp-Source: AGHT+IEQH+bBoeURPhgYuV58AQQWr0dKwAWYHgfBI0gpjuFffFaCPPUpJAjfEuq0+lXKGerWydf7j2auMMI0ZXc= X-Received: from wmhf25.prod.google.com ([2002:a7b:cc19:0:b0:431:1903:8a3e]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:1868:b0:385:fd24:3317 with SMTP id ffacd0b85a97d-386453cf868mr3887389f8f.1.1733823563891; Tue, 10 Dec 2024 01:39:23 -0800 (PST) Date: Tue, 10 Dec 2024 09:39:02 +0000 In-Reply-To: <20241210-miscdevice-file-param-v3-0-b2a79b666dc5@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241210-miscdevice-file-param-v3-0-b2a79b666dc5@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1588; i=aliceryhl@google.com; h=from:subject:message-id; bh=+0BkFqw5a7yRTc6C9JLr0Z5W0YYOHlF+girdQwg1HnE=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnWAxC4+A+/FbfX/LfWzds/ch9RDXzjjGfkFplH pR0KBZZCV2JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZ1gMQgAKCRAEWL7uWMY5 RroJEACwpp4Qy0ibi5m1SfviuuuUdhfO1BazAv2k4RZvJi6FynNhfs7ZPZrMkEvZjKpsq5hxi6X O5WBedQbA+zEQ6SgR/OEkX74rnw4QupKbC1FwHUVVZtDEt4leqtz81IlAKpm8tQzD0W7yNzmMK0 qJQS60VAwDFOmfI1FruqPwtNnWFuWAYGs1KlADKlpQtJtdEC3IN5Btis+v8iSKgdxtVJdWBylM4 /4kP8/QzJNMfOPFaQUcNIb1aHLG/3JCCLBKRLb9p82uEloBKapX6/3K/JWyXzZYq5yPUcJCfen2 ictX8XnnmJJaDbCm+CPzp7Wz0SCioFrnXpOVu9D02mIQBBKEXV7IaCe4Ccqxzqzt+HqnlGoe4wB +ZitNdCoWQwOPwlut29o7K7eGnp7uDXRjOF6SN/qgxMndAMb1OtADXsIUvqrKo75p+hP3um3prg 30gd6nuBwGY/SazLJaAU0aUSTMpXt6AfYwaLdkw0GkE/yugdc0HsPo2u+Y/zaxMuYO1hbHOSYpw JP7+7GxjCIePBaYN2MOccaZFhmFOndv2CXZvii83vbhEasCbfsz/6fxbp1FnUC0FzIoxM5IPKOR pyNzNkq1poiOBO0kNIqsc2Vf9f3xqmtt36fVbfkg+VJ0mxZlJq/EhTnsqN4tjgYk/Wp7umSlsX1 VotSHlh+iAxfs6w== X-Mailer: b4 0.13.0 Message-ID: <20241210-miscdevice-file-param-v3-3-b2a79b666dc5@google.com> Subject: [PATCH v3 3/3] rust: miscdevice: Provide accessor to pull out miscdevice::this_device From: Alice Ryhl To: Arnd Bergmann , Greg Kroah-Hartman Cc: Alexander Viro , Christian Brauner , Jan Kara , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Lee Jones , Danilo Krummrich , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Lee Jones There are situations where a pointer to a `struct device` will become necessary (e.g. for calling into dev_*() functions). This accessor allows callers to pull this out from the `struct miscdevice`. Signed-off-by: Lee Jones Signed-off-by: Alice Ryhl Tested-by: Lee Jones --- rust/kernel/miscdevice.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index 75a9d26c8001..20895e809607 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -10,6 +10,7 @@ =20 use crate::{ bindings, + device::Device, error::{to_result, Error, Result, VTABLE_DEFAULT_ERROR}, fs::File, prelude::*, @@ -85,6 +86,16 @@ pub fn register(opts: MiscDeviceOptions) -> impl PinInit= { pub fn as_raw(&self) -> *mut bindings::miscdevice { self.inner.get() } + + /// Access the `this_device` field. + pub fn device(&self) -> &Device { + // SAFETY: This can only be called after a successful register(), = which always + // initialises `this_device` with a valid device. Furthermore, the= signature of this + // function tells the borrow-checker that the `&Device` reference = must not outlive the + // `&MiscDeviceRegistration` used to obtain it, so the last use= of the reference must be + // before the underlying `struct miscdevice` is destroyed. + unsafe { Device::as_ref((*self.as_raw()).this_device) } + } } =20 #[pinned_drop] --=20 2.47.1.613.gc27f4b7a9f-goog