Re: [net-next PATCH v10 7/7] rust: net::phy sync with match_phy_device C changes
From: FUJITA Tomonori
Date: Mon May 19 2025 - 08:45:24 EST
On Mon, 19 May 2025 14:32:44 +0200
"Benno Lossin" <lossin@xxxxxxxxxx> wrote:
>>>> The other use case, as mentioned above, is when using the generic helper
>>>> function inside match_phy_device() callback. For example, the 4th
>>>> patch in this patchset adds genphy_match_phy_device():
>>>>
>>>> int genphy_match_phy_device(struct phy_device *phydev,
>>>> const struct phy_driver *phydrv)
>>>>
>>>> We could add a wrapper for this function as phy::Device's method like
>>>>
>>>> impl Device {
>>>> ...
>>>> pub fn genphy_match_phy_device(&self, drv: &phy::DriverVTable) -> i32
>>>
>>> Not sure why this returns an `i32`, but we probably could have such a
>>
>> Maybe a bool would be more appropriate here because the C's comment
>> says:
>>
>> Return: 1 if the PHY device matches the driver, 0 otherwise.
>>
>>> function as well (though I wouldn't use the vtable for that).
>>
>> What would you use instead?
>
> The concept that I sketched above:
>
> impl Device {
> fn genphy_match_phy_device<T: Driver>(&self) -> bool {
> self.phy_id() == T::PHY_DEVICE_ID.id
> }
> }
I think there might be a misunderstanding.
Rust's genphy_match_phy_device() is supposed to be a wrapper for C's
genphy_match_phy_device():
https://lore.kernel.org/rust-for-linux/20250517201353.5137-5-ansuelsmth@xxxxxxxxx/