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
| ||
|
Message-ID: <2023100237-satirical-prance-bd57@gregkh> Date: Mon, 2 Oct 2023 11:14:36 +0200 From: Greg KH <greg@...ah.com> To: FUJITA Tomonori <fujita.tomonori@...il.com> Cc: netdev@...r.kernel.org, rust-for-linux@...r.kernel.org, andrew@...n.ch, miguel.ojeda.sandonis@...il.com Subject: Re: [PATCH v1 1/3] rust: core abstractions for network PHY drivers On Mon, Oct 02, 2023 at 05:53:00PM +0900, FUJITA Tomonori wrote: > +/// Corresponds to the kernel's `enum phy_state`. > +#[derive(PartialEq)] > +pub enum DeviceState { > + /// PHY device and driver are not ready for anything. > + Down, > + /// PHY is ready to send and receive packets. > + Ready, > + /// PHY is up, but no polling or interrupts are done. > + Halted, > + /// PHY is up, but is in an error state. > + Error, > + /// PHY and attached device are ready to do work. > + Up, > + /// PHY is currently running. > + Running, > + /// PHY is up, but not currently plugged in. > + NoLink, > + /// PHY is performing a cable test. > + CableTest, > +} I still think these should come straight from the C code, and that moving them to an enum makes sense to make this possible, but hey, it's not my subsystem to maintain! :) > +/// Wraps the kernel's `struct phy_device`. > +/// > +/// # Invariants > +/// > +/// `self.0` is always in a valid state. > +#[repr(transparent)] > +pub struct Device(Opaque<bindings::phy_device>); > + > +impl Device { > + /// Creates a new [`Device`] instance from a raw pointer. > + /// > + /// # Safety > + /// > + /// For the duration of the lifetime 'a, the pointer must be valid for writing and nobody else > + /// may read or write to the `phy_device` object. > + pub unsafe fn from_raw<'a>(ptr: *mut bindings::phy_device) -> &'a mut Self { > + unsafe { &mut *ptr.cast() } > + } > + > + /// Gets the id of the PHY. > + pub fn id(&mut self) -> u32 { > + let phydev = self.0.get(); > + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. > + unsafe { (*phydev).phy_id } > + } Naming question, why are you making this "id" instead of "phy_id" like the C code has? Same for many of these bindings. > + /// Returns true if the link is up. > + pub fn get_link(&mut self) -> bool { > + const LINK_IS_UP: u32 = 1; > + let phydev = self.0.get(); > + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. > + unsafe { (*phydev).link() == LINK_IS_UP } > + } "get_" normally means to grab a reference, if this isn't matching a C call, why not just call it link_is_up or to match your other state checks "is_link_up"? but hey, I'm just bikeshedding at this point in time, if they maintainer likes these as-is, keep them :) thanks, greg k-h
Powered by blists - more mailing lists