Linux Documentation
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Vishwaroop A <va@nvidia.com>
Cc: linux-spi@vger.kernel.org, smangipudi@nvidia.com,
	jonathanh@nvidia.com, thierry.reding@gmail.com, corbet@lwn.net,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH v4 1/2] spi: add new_device/delete_device sysfs interface
Date: Sat, 16 May 2026 11:44:13 +0900	[thread overview]
Message-ID: <agfZ_aYMPeXhG037@sirena.co.uk> (raw)
In-Reply-To: <20260511104002.976269-2-va@nvidia.com>

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

On Mon, May 11, 2026 at 10:40:01AM +0000, Vishwaroop A wrote:

> +static ssize_t
> +new_device_store(struct device *dev, struct device_attribute *attr,
> +		 const char *buf, size_t count)
> +{

> +	/* Controller is dying; clean up if __unregister hasn't already */
> +	if (device_is_registered(&spi->dev))
> +		spi_unregister_device(spi);

This runs outside of userspace_clients_lock so there's a possibility
that if the controller is in the middle of unregistering (which is
likely since that's the case we're handling!) it might be running

	device_for_each_child(&ctlr->dev, NULL, __unregister);

which would result in a double free.

> @@ -3633,8 +3813,35 @@ void spi_unregister_controller(struct spi_controller *ctlr)
>  	if (IS_ENABLED(CONFIG_SPI_DYNAMIC))
>  		mutex_lock(&ctlr->add_lock);
>  
> +	/*
> +	 * Mark dead and drain userspace_clients before __unregister,
> +	 * since spi_unregister_device() doesn't do list_del() itself.
> +	 */
> +#if IS_ENABLED(CONFIG_SPI_DYNAMIC)
> +	mutex_lock(&ctlr->userspace_clients_lock);
> +	ctlr->dead = true;
> +	while (!list_empty(&ctlr->userspace_clients)) {
> +		struct spi_device *spi;
> +
> +		spi = list_first_entry(&ctlr->userspace_clients,
> +				       struct spi_device,
> +				       userspace_node);
> +		list_del(&spi->userspace_node);
> +		spi_unregister_device(spi);
> +	}
> +	mutex_unlock(&ctlr->userspace_clients_lock);

The spi_unregister_controller() side does things with the lock.

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

  reply	other threads:[~2026-05-16  2:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 10:40 [PATCH v4 0/2] spi: add new_device/delete_device sysfs interface Vishwaroop A
2026-05-11 10:40 ` [PATCH v4 1/2] " Vishwaroop A
2026-05-16  2:44   ` Mark Brown [this message]
2026-05-11 10:40 ` [PATCH v4 2/2] docs: spi: add documentation for userspace device instantiation Vishwaroop A

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=agfZ_aYMPeXhG037@sirena.co.uk \
    --to=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=jonathanh@nvidia.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=smangipudi@nvidia.com \
    --cc=thierry.reding@gmail.com \
    --cc=va@nvidia.com \
    /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