mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Almeida <daniel.almeida@collabora.com>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Boris Brezillon" <boris.brezillon@collabora.com>,
	"Sebastian Reichel" <sebastian.reichel@collabora.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v6 1/2] rust: regulator: add a bare minimum regulator abstraction
Date: Wed, 2 Jul 2025 10:14:04 -0300	[thread overview]
Message-ID: <0FD01582-58D1-4DC2-89DB-A4C8771F7750@collabora.com> (raw)
In-Reply-To: <CAH5fLgg1-K6x0wRO79mt4fGvJeNanr9Km75=1Z9G0gy-WbeU2g@mail.gmail.com>


> 
>>>> +impl<T: RegulatorState + 'static> Drop for Regulator<T> {
>>>> +    fn drop(&mut self) {
>>>> +        if core::any::TypeId::of::<T>() == core::any::TypeId::of::<Enabled>() {
>>> 
>>> I would avoid this kind of logic. Instead, you can add an
>>> `disable_on_drop()` method or constant to the trait and check it here.
>>> 
>>> Alice
>>> 
>> 
>> Can you expand on this?
> 
> Along these lines:
> 
> pub trait RegulatorState: 'static {
>    const DISABLE_ON_DROP: bool;
> }
> 
> impl RegulatorState for Enabled {
>    const DISABLE_ON_DROP: bool = true;
> }
> impl RegulatorState for Disabled {
>    const DISABLE_ON_DROP: bool = false;
> }
> impl RegulatorState for Dynamic {
>    const DISABLE_ON_DROP: bool = false;
> }
> 
> impl<T: RegulatorState> Drop for Regulator<T> {
>    fn drop(&mut self) {
>        if T::DISABLE_ON_DROP {
>            unsafe { bindings::regulator_disable(self.inner.as_ptr()) };
>        }
>        unsafe { bindings::regulator_put(self.inner.as_ptr()) };
>    }
> }

Ah, that indeed looks better, thanks.

— Daniel



  reply	other threads:[~2025-07-02 13:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27 17:11 [PATCH v6 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
2025-06-27 17:11 ` [PATCH v6 1/2] rust: regulator: add a bare minimum regulator abstraction Daniel Almeida
2025-06-29 13:10   ` kernel test robot
2025-07-02 10:35   ` Alice Ryhl
2025-07-02 13:03     ` Daniel Almeida
2025-07-02 13:12       ` Alice Ryhl
2025-07-02 13:14         ` Daniel Almeida [this message]
2025-06-27 17:11 ` [PATCH v6 2/2] MAINAINTERS: add regulator.rs to the regulator API entry Daniel Almeida
2025-07-01 15:28 ` [PATCH v6 0/2] Add a bare-minimum Regulator abstraction Daniel Almeida
2025-07-01 15:34   ` Mark Brown
2025-07-01 16:09     ` Daniel Almeida
2025-07-01 18:22       ` Miguel Ojeda

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=0FD01582-58D1-4DC2-89DB-A4C8771F7750@collabora.com \
    --to=daniel.almeida@collabora.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=boris.brezillon@collabora.com \
    --cc=broonie@kernel.org \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sebastian.reichel@collabora.com \
    --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

all inboxes | Powered by JetHome®