From: "Danilo Krummrich" <dakr@kernel.org>
To: "Ke Sun" <sunke@kylinos.cn>
Cc: gregkh@linuxfoundation.org, rafael@kernel.org,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
linux-rtc@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Alvin Sun" <sk.alvin.x@gmail.com>
Subject: Re: [RFC PATCH v1 2/4] rust: add device wakeup support
Date: Sun, 04 Jan 2026 14:31:33 +0100 [thread overview]
Message-ID: <DFFUBX61WWDD.3FE0Q8P9IMYXI@kernel.org> (raw)
In-Reply-To: <20260104060621.3757812-3-sunke@kylinos.cn>
(Cc: Greg, Rafael)
On Sun Jan 4, 2026 at 7:06 AM CET, Ke Sun wrote:
> diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
> index c79be2e2bfe38..c064111a24531 100644
> --- a/rust/kernel/device.rs
> +++ b/rust/kernel/device.rs
> @@ -325,6 +325,41 @@ pub fn drvdata<T: 'static>(&self) -> Result<Pin<&T>> {
> // - We've just checked that the type of the driver's private data is in fact `T`.
> Ok(unsafe { self.drvdata_unchecked() })
> }
> +
> + /// Initialize device wakeup capability.
> + ///
> + /// Marks the device as wakeup-capable and enables wakeup. The wakeup capability is
> + /// automatically disabled when the device is removed (resource-managed).
Let's use "when the device is unbound". While "remove" is a common term for this
as well, I prefer "unbind" since it is less ambiguous in this context.
> + ///
> + /// Returns `Ok(())` on success, or an error code on failure.
> + pub fn init_wakeup(&self) -> Result {
Please call this devm_init_wakeup().
> + // SAFETY: `self.as_raw()` is a valid pointer to a `struct device`.
> + // The function is exported from bindings_helper module via pub use.
> + let ret = unsafe { bindings::devm_device_init_wakeup(self.as_raw()) };
> + if ret != 0 {
> + return Err(Error::from_errno(ret));
> + }
> + Ok(())
Please use to_result() instead.
> + }
> +
> + /// Set a device interrupt as a wake IRQ.
> + ///
> + /// Attaches the interrupt `irq` as a wake IRQ for this device. The wake IRQ is
> + /// automatically configured for wake-up from suspend. Must be called after
> + /// [`Device::init_wakeup`].
> + ///
> + /// Returns `Ok(())` on success, or an error code on failure.
> + pub fn set_wake_irq(&self, irq: i32) -> Result {
The irq argument should be a new type holding the irq number and a
&'a Device<Bound>, i.e. IrqRequest [1].
Technically, this can also be implemented on IrqRequest directly, this way no
additional check for comparing the device pointers is needed; but the method is
fallible anyways, and it is a bit odd to have this method on IrqRequest, so I'd
abstain from this.
> + if irq < 0 {
> + return Err(crate::error::code::EINVAL);
You do not need the full qualified name, just EINVAL should work, but with the
above you don't need any manual irq number validation anyways.
> + }
> + // SAFETY: `self.as_raw()` is a valid pointer to a `struct device`.
> + let ret = unsafe { bindings::dev_pm_set_wake_irq(self.as_raw(), irq) };
> + if ret != 0 {
> + return Err(Error::from_errno(ret));
> + }
> + Ok(())
Please use to_result() instead.
> + }
> }
[1] https://rust.docs.kernel.org/kernel/irq/struct.IrqRequest.html
next prev parent reply other threads:[~2026-01-04 13:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-04 6:06 [RFC PATCH v1 0/4] rust: Add RTC driver support Ke Sun
2026-01-04 6:06 ` [RFC PATCH v1 1/4] rust: add AMBA bus abstractions Ke Sun
2026-01-04 11:37 ` Miguel Ojeda
2026-01-04 12:37 ` Danilo Krummrich
2026-01-04 6:06 ` [RFC PATCH v1 2/4] rust: add device wakeup support Ke Sun
2026-01-04 13:31 ` Danilo Krummrich [this message]
2026-01-04 6:06 ` [RFC PATCH v1 3/4] rust: add RTC core abstractions and data structures Ke Sun
2026-01-04 13:00 ` Danilo Krummrich
2026-01-04 6:06 ` [RFC PATCH v1 4/4] rust: add PL031 RTC driver Ke Sun
2026-01-04 9:02 ` Dirk Behme
2026-01-07 10:15 ` Danilo Krummrich
2026-01-04 11:40 ` Miguel Ojeda
2026-01-04 13:10 ` Danilo Krummrich
2026-01-06 2:51 ` Ke Sun
2026-01-06 13:32 ` Danilo Krummrich
2026-01-06 14:44 ` Greg Kroah-Hartman
2026-01-06 15:04 ` Danilo Krummrich
2026-01-06 15:12 ` Greg Kroah-Hartman
2026-01-04 13:36 ` [RFC PATCH v1 0/4] rust: Add RTC driver support Danilo Krummrich
2026-01-04 14:11 ` Ke Sun
2026-01-06 7:41 ` Kari Argillander
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DFFUBX61WWDD.3FE0Q8P9IMYXI@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-rtc@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sk.alvin.x@gmail.com \
--cc=sunke@kylinos.cn \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox