[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLghO3eh4VWjSiwX4bqORBMC8JF6RyDQM2eCPg6On5Ti9WQ@mail.gmail.com>
Date: Wed, 22 Jan 2025 11:15:37 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Abdiel Janulgue <abdiel.janulgue@...il.com>
Cc: rust-for-linux@...r.kernel.org, daniel.almeida@...labora.com,
dakr@...nel.org, robin.murphy@....com, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>, Valentin Obst <kernel@...entinobst.de>,
open list <linux-kernel@...r.kernel.org>, Christoph Hellwig <hch@....de>,
Marek Szyprowski <m.szyprowski@...sung.com>, airlied@...hat.com,
"open list:DMA MAPPING HELPERS" <iommu@...ts.linux.dev>
Subject: Re: [PATCH v10 2/3] rust: add dma coherent allocator abstraction.
On Wed, Jan 22, 2025 at 11:14 AM Abdiel Janulgue
<abdiel.janulgue@...il.com> wrote:
> >> + /// Returns the device, base address, dma handle, attributes and the size of the
> >> + /// allocated region.
> >> + ///
> >> + /// The caller takes ownership of the returned resources, i.e., will have the responsibility
> >> + /// in calling `bindings::dma_free_attrs`. The allocated region is valid as long as
> >> + /// the returned device exists.
> >> + pub fn into_parts(
> >> + self,
> >> + ) -> (
> >> + ARef<Device>,
> >> + *mut T,
> >> + bindings::dma_addr_t,
> >> + crate::ffi::c_ulong,
> >> + usize,
> >> + ) {
> >> + let size = self.count * core::mem::size_of::<T>();
> >> + let ret = (
> >> + self.dev.clone(),
> >
> > Calling clone here increments the refcount, but you don't want to do
> > that since it leaks a count.
> >
>
> You mean return the raw *mut bindings::device instead of ARef<Device>.
> Otherwise the compiler complains not being able to move out ARef<Device>
> because it doesn't implement Copy.
What I mean is that you should return an ARef<Device> without
incrementing the refcount. I acknowledge that this requires unsafe,
but it's the correct semantics and the unsafe is a consequence of
using mem::forget.
You can write `core::ptr::read(&self.dev)`.
Alice
Powered by blists - more mailing lists