rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Danilo Krummrich <dakr@kernel.org>
To: "Guilherme Giácomo Simões" <trintaeoitogc@gmail.com>
Cc: gregkh@linuxfoundation.org, rafael@kernel.org, ojeda@kernel.org,
	alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
	bjorn3_gh@protonmail.com, benno.lossin@proton.me,
	aliceryhl@google.com, mcgrof@kernel.org, russ.weight@linux.dev,
	dakr@redhat.com, a.hindborg@kernel.org,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] device: rust: change the name function
Date: Mon, 30 Sep 2024 17:01:14 +0200	[thread overview]
Message-ID: <Zvq9OqEu0yN1Ahgq@pollux> (raw)
In-Reply-To: <CAM_RzfYXWJ1ePZk7-DFR4P--F1pyzWg8bnC40mbLWaHpx_aNJA@mail.gmail.com>

On Mon, Sep 30, 2024 at 10:52:27AM -0300, Guilherme Giácomo Simões wrote:
> Danilo Krummrich <dakr@kernel.org> writes:
> > > diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
> > > index 851018eef885..ecffaff041e0 100644
> > > --- a/rust/kernel/device.rs
> > > +++ b/rust/kernel/device.rs
> > > @@ -51,7 +51,7 @@ impl Device {
> > >      ///
> > >      /// It must also be ensured that `bindings::device::release` can be called from any thread.
> > >      /// While not officially documented, this should be the case for any `struct device`.
> > > -    pub unsafe fn from_raw(ptr: *mut bindings::device) -> ARef<Self> {
> > > +    pub unsafe fn get_device(ptr: *mut bindings::device) -> ARef<Self> {
> >
> > As a follow-up, it probably makes sense to also change the function body to
> > just: `unsafe { Self::as_ref(ptr) }.into()`.
> 
> But if we change the function body that is suggested for you, the
> function will not have your own refcount. If I don't wrong, the
> Device::as_ref() expects the caller to have its own reference counter.
> And if we change the behavior of function, your name don't need to be
> changed, because your behavior will be equal the from_raw() from
> standard library.

I think you missed the `into()` above. This will convert `&'a Device` into
`ARef<Device>`, and also call `inc_ref` from the `AlwaysRefCounted` trait
implemented for `Device`, and hence increase the reference count.

  reply	other threads:[~2024-09-30 15:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30 12:39 [PATCH v2 0/1] device: rust: change the name function Guilherme Giacomo Simoes
2024-09-30 12:39 ` [PATCH v2 1/1] " Guilherme Giacomo Simoes
2024-09-30 13:00   ` Greg KH
2024-09-30 13:13   ` Danilo Krummrich
2024-09-30 13:52     ` Guilherme Giácomo Simões
2024-09-30 15:01       ` Danilo Krummrich [this message]
2024-09-30 16:53         ` Guilherme Giácomo Simões
2024-09-30 17:02           ` Danilo Krummrich
2024-09-30 13:00 ` [PATCH v2 0/1] " Greg KH

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=Zvq9OqEu0yN1Ahgq@pollux \
    --to=dakr@kernel.org \
    --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=dakr@redhat.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=russ.weight@linux.dev \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=trintaeoitogc@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).