[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLggWOkut0O+28NVYBSF2CTpHXe9Thb3rhXoRZo5e9zFjzw@mail.gmail.com>
Date: Fri, 6 Dec 2024 16:25:28 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: gregkh@...uxfoundation.org, rafael@...nel.org, bhelgaas@...gle.com,
ojeda@...nel.org, alex.gaynor@...il.com, boqun.feng@...il.com,
gary@...yguo.net, bjorn3_gh@...tonmail.com, benno.lossin@...ton.me,
tmgross@...ch.edu, a.hindborg@...sung.com, airlied@...il.com,
fujita.tomonori@...il.com, lina@...hilina.net, pstanner@...hat.com,
ajanulgu@...hat.com, lyude@...hat.com, robh@...nel.org,
daniel.almeida@...labora.com, saravanak@...gle.com, dirk.behme@...bosch.com,
j@...nau.net, fabien.parent@...aro.org, chrisi.schrefl@...il.com,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-pci@...r.kernel.org, devicetree@...r.kernel.org
Subject: Re: [PATCH v4 08/13] rust: pci: add basic PCI device / driver abstractions
On Thu, Dec 5, 2024 at 3:16 PM Danilo Krummrich <dakr@...nel.org> wrote:
>
> Implement the basic PCI abstractions required to write a basic PCI
> driver. This includes the following data structures:
>
> The `pci::Driver` trait represents the interface to the driver and
> provides `pci::Driver::probe` for the driver to implement.
>
> The `pci::Device` abstraction represents a `struct pci_dev` and provides
> abstractions for common functions, such as `pci::Device::set_master`.
>
> In order to provide the PCI specific parts to a generic
> `driver::Registration` the `driver::RegistrationOps` trait is implemented
> by `pci::Adapter`.
>
> `pci::DeviceId` implements PCI device IDs based on the generic
> `device_id::RawDevceId` abstraction.
>
> Co-developed-by: FUJITA Tomonori <fujita.tomonori@...il.com>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
> +impl<T: Driver + 'static> Adapter<T> {
> + extern "C" fn probe_callback(
> + pdev: *mut bindings::pci_dev,
> + id: *const bindings::pci_device_id,
> + ) -> core::ffi::c_int {
> + // SAFETY: The PCI bus only ever calls the probe callback with a valid pointer to a
> + // `struct pci_dev`.
> + let dev = unsafe { device::Device::get_device(&mut (*pdev).dev) };
It shouldn't be necessary to increment the refcount here.
Also, the mutable reference is illegal because it references a C type
without a Opaque wrapper. Please use the addr_of_mut! macro instead of
a mutable reference.
Alice
Powered by blists - more mailing lists