lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zvq9OqEu0yN1Ahgq@pollux>
Date: Mon, 30 Sep 2024 17:01:14 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Guilherme Giácomo Simões <trintaeoitogc@...il.com>
Cc: gregkh@...uxfoundation.org, rafael@...nel.org, ojeda@...nel.org,
	alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net,
	bjorn3_gh@...tonmail.com, benno.lossin@...ton.me,
	aliceryhl@...gle.com, mcgrof@...nel.org, russ.weight@...ux.dev,
	dakr@...hat.com, a.hindborg@...nel.org,
	rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/1] device: rust: change the name function

On Mon, Sep 30, 2024 at 10:52:27AM -0300, Guilherme Giácomo Simões wrote:
> Danilo Krummrich <dakr@...nel.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ