Thread (108 messages) 108 messages, 11 authors, 2023-11-22

Re: [PATCH net-next v7 2/5] rust: net::phy add module_phy_driver macro

From: FUJITA Tomonori <fujita.tomonori@gmail.com>
Date: 2023-11-19 10:50:36
Also in: rust-for-linux

On Fri, 17 Nov 2023 09:39:08 +0000
Alice Ryhl [off-list ref] wrote:
FUJITA Tomonori [off-list ref] writes:
quoted
This macro creates an array of kernel's `struct phy_driver` and
registers it. This also corresponds to the kernel's
`MODULE_DEVICE_TABLE` macro, which embeds the information for module
loading into the module binary file.

A PHY driver should use this macro.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>

A few minor nits:
quoted
+    (drivers: [$($driver:ident),+], device_table: [$($dev:expr),+], $($f:tt)*) => {
Here, you can add $(,)? to allow trailing commas when the macro is used.
Like this:

(drivers: [$($driver:ident),+ $(,)?], device_table: [$($dev:expr),+ $(,)?], $($f:tt)*) => {
Updated.
quoted
+            ::kernel::bindings::mdio_device_id {
Here, I recommend `$crate` instead of `::kernel`.
I copied the code that Benno wrote, IIRC. Either is fine by me. Why
`$crate` is better here?

Also better to replace other `::kernel` in this macro?

quoted
+/// #[no_mangle]
+/// static __mod_mdio__phydev_device_table: [::kernel::bindings::mdio_device_id; 2] = [
+///     ::kernel::bindings::mdio_device_id {
+///         phy_id: 0x003b1861,
+///         phy_id_mask: 0xffffffff,
+///     },
+///     ::kernel::bindings::mdio_device_id {
+///         phy_id: 0,
+///         phy_id_mask: 0,
+///     },
+/// ];
I'd probably put a safety comment on the `#[no_mangle]` invocation to say that
"C will not read off the end of this constant since the last element is zero".
Added.

Thanks a lot!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help