Re: [PATCH] spi: Add spi_for_each_controller() helper
From: Mark Brown
Date: Mon May 18 2026 - 04:28:29 EST
On Mon, May 18, 2026 at 03:10:26PM +0800, Chao Huang wrote:
> > Do you have an actual user for this or is this just purely theoretical
> > at this point? It'd make a lot more sense to add this along with a
> > user.
> Yes, I do have an actual user for this helper in my project.
> The goal is to provide a new SPI controller API that allows users to
> access SPI controllers by bus number and chip select (CS). The
> `spi_for_each_controller()` helper is used to iterate over all registered
> controllers, find the target controller by bus number, and then operate
> on it.
OK, I would hold off on this patch and sumbit it along with the user -
it's not really something that's clearly useful without that user.
> > When unregistering controllers we do start the teardown process before
> > we pull the device off the controller list, and drop the lock while
> > doing so. That's probably fine for a lot of uses.
> >
> Regarding the controller unregistration case you mentioned — do you mean
> the `spi_unregister_controller()` function?
Yes.
> In my `fn` callback, I call `spi_controller_get()` to safely grab a
> reference to the controller, and later call `spi_controller_put()` at an
> appropriate time (e.g., after the operation is done). This should
> prevent the controller from being freed while it is still in use, even
> if unregistration happens concurrently.
The controller itself will be there but we do things like stopping the
queue before we destroy the controller.
Attachment:
signature.asc
Description: PGP signature