mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: iasnezhkov@gmail.com
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	andy@kernel.org, Arnav Kapoor <kapoorarnav43@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: inkern: guard fwnode_xlate with info_exist_lock
Date: Thu, 26 Nov 2026 16:24:17 +0200	[thread overview]
Message-ID: <awhBEfD6I5nakCKJ@ashevche-desk.local> (raw)
In-Reply-To: <20261126060615.63790-1-iasnezhkov@gmail.com>

On Thu, Nov 26, 2026 at 06:06:15AM +0000, Ilia Snezhkov via B4 Relay wrote:
> 
> __fwnode_iio_channel_get() dereferences indio_dev->info->fwnode_xlate
> and invokes it without holding info_exist_lock. Concurrent
> iio_device_unregister() clears indio_dev->info under info_exist_lock,
> allowing a NULL dereference or callback execution during provider
> teardown.
> 
> Hold iio_dev_opaque->info_exist_lock with scoped_guard(mutex, ...)
> matching the rest of inkern.c, and return -EPROBE_DEFER if
> indio_dev->info is NULL. Since iio_device_unregister() calls
> cdev_device_del() before clearing indio_dev->info, seeing a NULL info
> pointer corresponds to racing right before device removal from
> iio_bus_type, where !idev already returns -EPROBE_DEFER. Using
> -EPROBE_DEFER also avoids colliding with the -ENODEV sentinel used by
> callers to continue parent or map-list lookups and avoids the named
> lookup -EINVAL fallback in __fwnode_iio_channel_get_by_name().

...

> static int __fwnode_iio_channel_get(struct iio_channel *channel,
>  				    struct fwnode_handle *fwnode, int index)

>  {
>  	struct fwnode_reference_args iiospec;
> +	struct iio_dev_opaque *iio_dev_opaque;

I see that this block is not so ordered, but even though, try to follow
the reversed xmas tree order.

>  	struct device *idev;
>  	struct iio_dev *indio_dev;
>  	int err;

...

>  	indio_dev = dev_to_iio_dev(idev);
> +	iio_dev_opaque = to_iio_dev_opaque(indio_dev);
>  	channel->indio_dev = indio_dev;

You ignored my previous comment. Why?

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2026-11-26 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  6:06 Ilia Snezhkov via B4 Relay
2026-11-26  6:55 ` Arnav Kapoor
2026-11-26 14:24 ` Andy Shevchenko [this message]
2026-11-27  1:23   ` Ilia Snezhkov

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=awhBEfD6I5nakCKJ@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=iasnezhkov@gmail.com \
    --cc=jic23@kernel.org \
    --cc=kapoorarnav43@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®