Message ID | 20240804233835.223460-3-fujita.tomonori@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: phy: add Applied Micro QT2025 PHY driver | expand |
> + /// # Safety > + /// > + /// `phydev` must be passed by the corresponding callback in `phy_driver`. > + unsafe extern "C" fn probe_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { > + from_result(|| { > + // SAFETY: This callback is called only in contexts > + // where we can exclusively access to `phy_device` because > + // it's not published yet, so the accessors on `Device` are okay > + // to call. Minor English nitpick. Its is normally 'have access to'. Or you can drop the 'to'. Otherwise Reviewed-by: Andrew Lunn <andrew@lunn.ch> Andrew
On Fri, 16 Aug 2024 02:40:12 +0200 Andrew Lunn <andrew@lunn.ch> wrote: >> + /// # Safety >> + /// >> + /// `phydev` must be passed by the corresponding callback in `phy_driver`. >> + unsafe extern "C" fn probe_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { >> + from_result(|| { >> + // SAFETY: This callback is called only in contexts >> + // where we can exclusively access to `phy_device` because >> + // it's not published yet, so the accessors on `Device` are okay >> + // to call. > > Minor English nitpick. Its is normally 'have access to'. Or you can > drop the 'to'. > > Otherwise > > Reviewed-by: Andrew Lunn <andrew@lunn.ch> Dropped the 'to' and added your Reviewed-by. Thanks!
diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index fd40b703d224..60d3d8f8b44f 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -338,6 +338,21 @@ impl<T: Driver> Adapter<T> { }) } + /// # Safety + /// + /// `phydev` must be passed by the corresponding callback in `phy_driver`. + unsafe extern "C" fn probe_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { + from_result(|| { + // SAFETY: This callback is called only in contexts + // where we can exclusively access to `phy_device` because + // it's not published yet, so the accessors on `Device` are okay + // to call. + let dev = unsafe { Device::from_raw(phydev) }; + T::probe(dev)?; + Ok(0) + }) + } + /// # Safety /// /// `phydev` must be passed by the corresponding callback in `phy_driver`. @@ -511,6 +526,11 @@ pub const fn create_phy_driver<T: Driver>() -> DriverVTable { } else { None }, + probe: if T::HAS_PROBE { + Some(Adapter::<T>::probe_callback) + } else { + None + }, get_features: if T::HAS_GET_FEATURES { Some(Adapter::<T>::get_features_callback) } else { @@ -583,6 +603,11 @@ fn soft_reset(_dev: &mut Device) -> Result { kernel::build_error(VTABLE_DEFAULT_ERROR) } + /// Sets up device-specific structures during discovery. + fn probe(_dev: &mut Device) -> Result { + kernel::build_error(VTABLE_DEFAULT_ERROR) + } + /// Probes the hardware to determine what abilities it has. fn get_features(_dev: &mut Device) -> Result { kernel::build_error(VTABLE_DEFAULT_ERROR)