All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Matteo Martelli <matteomartelli3@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Alisa-Dariana Roman <alisa.roman@analog.com>,
	Christian Eggers <ceggers@arri.de>, Peter Rosin <peda@axentia.se>,
	Paul Cercueil <paul@crapouillou.net>,
	Sebastian Reichel <sre@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mips@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v5 2/5] iio: consumers: copy/release available info from producer to fix race
Date: Wed, 30 Oct 2024 16:47:50 +0200	[thread overview]
Message-ID: <ZyJHFp6vbQ7deLFs@black.fi.intel.com> (raw)
In-Reply-To: <20241021-iio-read-avail-release-v5-2-b168713fab33@gmail.com>

On Mon, Oct 21, 2024 at 02:54:15PM +0200, Matteo Martelli wrote:
> Consumers need to call the producer's read_avail_release_resource()
> callback after reading producer's available info. To avoid a race
> condition with the producer unregistration, change inkern
> iio_channel_read_avail() so that it copies the available info from the
> producer and immediately calls its release callback with info_exists
> locked.
> 
> Also, modify the users of iio_read_avail_channel_raw() and
> iio_read_avail_channel_attribute() to free the copied available buffers
> after calling these functions. To let users free the copied buffer with
> a cleanup pattern, also add a iio_read_avail_channel_attr_retvals()
> consumer helper that is equivalent to iio_read_avail_channel_attribute()
> but stores the available values in the returned variable.

...

> +static void dpot_dac_read_avail_release_res(struct iio_dev *indio_dev,
> +					    struct iio_chan_spec const *chan,
> +					    const int *vals, long mask)
> +{
> +	kfree(vals);
> +}
> +
>  static int dpot_dac_write_raw(struct iio_dev *indio_dev,
>  			      struct iio_chan_spec const *chan,
>  			      int val, int val2, long mask)
> @@ -125,6 +132,7 @@ static int dpot_dac_write_raw(struct iio_dev *indio_dev,
>  static const struct iio_info dpot_dac_info = {
>  	.read_raw = dpot_dac_read_raw,
>  	.read_avail = dpot_dac_read_avail,
> +	.read_avail_release_resource = dpot_dac_read_avail_release_res,
>  	.write_raw = dpot_dac_write_raw,
>  };

I have a problem with this approach. The issue is that we allocate
memory in one place and must clear it in another. This is not well
designed thingy in my opinion. I was thinking a bit of the solution and
at least these two comes to my mind:

1) having a special callback for .read_avail_with_copy (choose better
name) that will dump the data to the intermediate buffer and clean it
after all;

2) introduce a new type (or bit there), like IIO_AVAIL_LIST_ALLOC.

In any case it looks fragile and not scalable. I propose to drop this
and think again.

Yes, yes, I'm fully aware about the problem you are trying to solve and
agree on the report, I think this solution is not good enough.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2024-10-30 14:47 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-21 12:54 [PATCH v5 0/5] iio: fix possible race condition during access of available info lists Matteo Martelli
2024-10-21 12:54 ` [PATCH v5 1/5] iio: core: add read_avail_release_resource callback to fix race Matteo Martelli
2024-10-21 12:54 ` [PATCH v5 2/5] iio: consumers: copy/release available info from producer " Matteo Martelli
2024-10-30 14:47   ` Andy Shevchenko [this message]
2024-10-30 17:35     ` Jonathan Cameron
2024-10-30 18:23     ` Matteo Martelli
2024-10-30 20:30       ` Jonathan Cameron
2024-10-31 11:26         ` Matteo Martelli
2024-10-31 14:31           ` Jonathan Cameron
2024-10-31 18:06             ` Matteo Martelli
2024-11-15 14:25               ` Matteo Martelli
2024-11-18 10:21                 ` Andy Shevchenko
2024-11-18 14:45                   ` Matteo Martelli
2024-11-18 16:05                     ` Andy Shevchenko
2024-11-19 11:25                       ` Matteo Martelli
2024-11-19 12:05                         ` Andy Shevchenko
2024-11-23 14:13                           ` Jonathan Cameron
2024-11-25 10:05                             ` Andy Shevchenko
2024-11-26 16:31                             ` Matteo Martelli
2024-11-26 17:41                               ` Jonathan Cameron
2024-11-29 16:04                                 ` Matteo Martelli
2024-12-02 17:42                                   ` Andy Shevchenko
2024-12-12  9:46                                     ` Matteo Martelli
2024-12-12 14:06                                       ` Andy Shevchenko
2024-12-15 13:46                                         ` Jonathan Cameron
2024-12-23 15:28                                           ` Matteo Martelli
2025-01-05 11:22                                             ` Jonathan Cameron
2024-10-21 12:54 ` [PATCH v5 3/5] iio: pac1921: use read_avail+release APIs instead of custom ext_info Matteo Martelli
2024-10-21 12:54 ` [PATCH v5 4/5] iio: ad7192: copy/release available filter frequencies to fix race Matteo Martelli
2024-10-21 12:54 ` [PATCH v5 5/5] iio: as73211: copy/release available integration times " Matteo Martelli
2024-10-27  9:43 ` [PATCH v5 0/5] iio: fix possible race condition during access of available info lists Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2024-10-24 22:59 [PATCH v5 2/5] iio: consumers: copy/release available info from producer to fix race kernel test robot

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=ZyJHFp6vbQ7deLFs@black.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=alisa.roman@analog.com \
    --cc=ceggers@arri.de \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=matteomartelli3@gmail.com \
    --cc=paul@crapouillou.net \
    --cc=peda@axentia.se \
    --cc=sre@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.