Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: ChaoHuang <958028483@qq.com>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chao Huang <huangchao@kylinos.cn>
Subject: Re: [PATCH] spi: Add spi_for_each_controller() helper
Date: Sat, 16 May 2026 07:48:10 +0100	[thread overview]
Message-ID: <aggTKly_pVAYLVRt@sirena.co.uk> (raw)
In-Reply-To: <tencent_4C5A0FCF387BDB37C5512E5D709FD557F106@qq.com>

[-- Attachment #1: Type: text/plain, Size: 1948 bytes --]

On Thu, May 14, 2026 at 04:45:44PM +0800, ChaoHuang wrote:
> From: Chao Huang <huangchao@kylinos.cn>
> 
> Add a new helper function to iterate over all SPI controllers.
> This provides a convenient way for SPI core code and drivers
> to perform operations on all registered controllers.

> This helper is useful for scenarios like statistics gathering,
> configuration updates, or debugging operations that need to
> process all SPI controllers in the system.

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.

> +int spi_for_each_controller(int (*fn)(struct spi_controller *, void *), void *data)
> +{
> +	struct spi_controller *ctlr;
> +	int ret = 0;
> +
> +	mutex_lock(&board_lock);
> +	list_for_each_entry(ctlr, &spi_controller_list, list) {
> +		ret = fn(ctlr, data);

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.

There's also some obvious potential for things to go wrong here with
something in the callback deadlocking, though that's a bit of a "don't
do that kind of thing".

> +		if (ret)
> +			break;
> +	}
> +	mutex_unlock(&board_lock);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(spi_for_each_controller);
> +
>  static int __init spi_init(void)
>  {
>  	int	status;
> diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
> index 79513f5941cc..8fcf3faf9739 100644
> --- a/include/linux/spi/spi.h
> +++ b/include/linux/spi/spi.h
> @@ -934,6 +934,8 @@ static inline int acpi_spi_count_resources(struct acpi_device *adev)
>  }
>  #endif
>  
> +int spi_for_each_controller(int (*fn)(struct spi_controller *, void *), void *data);
> +
>  /*
>   * SPI resource management while processing a SPI message
>   */
> -- 
> 2.25.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-05-16  6:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-14  8:45 [PATCH] spi: Add spi_for_each_controller() helper ChaoHuang
2026-05-16  6:48 ` Mark Brown [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-05-14  6:13 958028483
2026-05-14  7:08 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aggTKly_pVAYLVRt@sirena.co.uk \
    --to=broonie@kernel.org \
    --cc=958028483@qq.com \
    --cc=huangchao@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox