Re: [PATCH v4 2/2] rust: leds: add basic led classdev abstractions

From: Danilo Krummrich

Date: Wed Oct 15 2025 - 13:28:03 EST


On Wed Oct 15, 2025 at 5:02 PM CEST, Markus Probst wrote:
> Not necessarily every, like I said `container::Device` itself also
> would implement `device::Container` (still allowing &Device<Bound>).

Sure, but eventually we'll need all bus devices to implement it because you want
to be able to use this class device on any bus.

> We already know the address of it with the `struct led_classdev`-
>`parent` field, we just need to substract the offset from `<T as
> Container>::Offset`, and we have the address of the device container
> (like `struct i2c_client`). No Box needed.

Yeah, that should work.

What I still don't like about it (and didn't like back then when I thought about
something similar) is that this provides a publicly accessible unsafe way to
upcast from a generic device to a bus device.

However, I do see the ergonomic advantage for drivers. Even though I'd say it's
minor, it is indeed nice that the class device callbacks can already carry the
actual parent bus device.

So, I'm fine giving this a shot. If go for an implementation, please name the
trait something along the lines of device::IntoBusDevice, device::Container is
too generic. Only bus devices have a DeviceContext.