mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Changyul Lee <lcy8047@gmail.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: trigger: free the trigger ID after device_del()
Date: Sat, 7 Nov 2026 01:31:59 +0000	[thread overview]
Message-ID: <20261107013159.7df2ab9f@jic23-hlaptop> (raw)
In-Reply-To: <20261106174737.2580011-1-lcy8047@gmail.com>

On Fri,  6 Nov 2026 12:47:37 -0500
Changyul Lee <lcy8047@gmail.com> wrote:

> iio_trigger_unregister() returns the trigger ID to iio_trigger_ida
> before device_del() removes the "trigger<N>" device. A trigger
> registered in between can get the same ID, and its device_add() fails:
> 
>   sysfs: cannot create duplicate filename '/bus/iio/devices/trigger0'
> 
> For example, adding a sysfs trigger while an hrtimer trigger is being
> removed through configfs, or the other way around, hits this because the
> two paths do not share a lock.
> 
> Free the ID after device_del(), as the error path of
> iio_trigger_register() already does, and drop the "Possible issue in
> here" comment.
> 
> Fixes: 1637db44413e ("Staging: IIO: Trigger support added to core.")
> Signed-off-by: Changyul Lee <lcy8047@gmail.com>
Nice find. Applied to the fixes-togreg branch of iio.git.

One passing comment below given you also deleted a very 'odd'
comment!


> ---
> Found with a static analysis tool we are developing.
> 
> Reproduced in QEMU (x86_64) with two threads running for 20 seconds.
> One writes to add_trigger and remove_trigger of iio_sysfs_trigger, the
> other creates and removes an hrtimer trigger in configfs. Without this
> patch, device_add() failed with the error above 160 to 1148 times per
> run in three runs. With it, it never failed.
> 
>  drivers/iio/industrialio-trigger.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
> index 76926fee0f84..206ede2c9b3c 100644
> --- a/drivers/iio/industrialio-trigger.c
> +++ b/drivers/iio/industrialio-trigger.c
> @@ -105,9 +105,8 @@ void iio_trigger_unregister(struct iio_trigger *trig_info)
>  	scoped_guard(mutex, &iio_trigger_list_lock)
>  		list_del(&trig_info->list);
>  
> -	ida_free(&iio_trigger_ida, trig_info->id);
> -	/* Possible issue in here */
This made me wonder - what is that on about?  I checked
the history and all the code on either side of that comment has
changed since it was added.  So who knows! :)


>  	device_del(&trig_info->dev);
> +	ida_free(&iio_trigger_ida, trig_info->id);
>  }
>  EXPORT_SYMBOL(iio_trigger_unregister);
>  
> 
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4


      reply	other threads:[~2026-11-07  1:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 17:47 Changyul Lee
2026-11-07  1:31 ` Jonathan Cameron [this message]

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=20261107013159.7df2ab9f@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=lcy8047@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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

all inboxes | Powered by JetHome®