public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Andy Shevchenko" <andriy.shevchenko@intel.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Daniel Lezcano" <daniel.lezcano@linaro.org>,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>
Subject: Re: [PATCH 2/7] iio: buffer: iio_push_to_buffers_with_ts_unaligned() might_sleep()
Date: Sat, 13 Sep 2025 14:52:18 +0100	[thread overview]
Message-ID: <20250913145218.03d1be7d@jic23-huawei> (raw)
In-Reply-To: <7f71c489-410b-4fdb-9d78-9f2835c32379@baylibre.com>

On Fri, 12 Sep 2025 13:40:37 -0500
David Lechner <dlechner@baylibre.com> wrote:

> On 9/12/25 1:10 PM, Andy Shevchenko wrote:
> > On Fri, Sep 12, 2025 at 11:05:53AM -0500, David Lechner wrote:  
> >> Call might_sleep() in iio_push_to_buffers_with_ts_unaligned() since it
> >> can allocate memory, which may sleep.  
> > 
> > It can or does it always do?
> > If the first one is correct, better to use might_sleep_if().
> >   
> 
> Just below this in the function is:
> 
> 	if (iio_dev_opaque->bounce_buffer_size !=  indio_dev->scan_bytes) {
> 		void *bb;
> 
> 		bb = devm_krealloc(&indio_dev->dev,
> 				   iio_dev_opaque->bounce_buffer,
> 				   indio_dev->scan_bytes, GFP_KERNEL);
> 		if (!bb)
> 			return -ENOMEM;
> 		iio_dev_opaque->bounce_buffer = bb;
> 		iio_dev_opaque->bounce_buffer_size = indio_dev->scan_bytes;
> 	}
> 
> 
> Would it make sense to move the might_sleep() inside of this
> if statement rather than repeat the condition in might_sleep_if()?
> 
> devm_krealloc() is the only part of this function that might sleep.
> 
Whilst true that the sleep is only at this point, we always go into
this path the first time (assuming I remember correctly how this works).

So I'd argue a might_sleep() where you have it is appropriate
as we will already have spat out the debug info if we get to the
second case that doesn't sleep.

If this ever matters to a driver, we could add a new function
to allocate the bounce buffer earlier. 

Jonathan




  reply	other threads:[~2025-09-13 13:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-12 16:05 [PATCH 0/7] iio: buffer: document calling context when pushing to buffers David Lechner
2025-09-12 16:05 ` [PATCH 1/7] iio: buffer: document iio_push_to_buffers_with_ts_unaligned() may sleep David Lechner
2025-09-12 18:12   ` Andy Shevchenko
2025-09-12 16:05 ` [PATCH 2/7] iio: buffer: iio_push_to_buffers_with_ts_unaligned() might_sleep() David Lechner
2025-09-12 18:10   ` Andy Shevchenko
2025-09-12 18:40     ` David Lechner
2025-09-13 13:52       ` Jonathan Cameron [this message]
2025-09-12 16:05 ` [PATCH 3/7] iio: buffer: document iio_push_to_buffers_with_ts() David Lechner
2025-09-13 13:54   ` Jonathan Cameron
2025-09-12 16:05 ` [PATCH 4/7] iio: buffer: deprecated iio_push_to_buffers_with_timestamp() David Lechner
2025-09-12 18:11   ` Andy Shevchenko
2025-09-12 16:05 ` [PATCH 5/7] iio: buffer: document iio_push_to_buffers() calling context David Lechner
2025-09-12 16:05 ` [PATCH 6/7] iio: buffer: document store_to() callback may be called in any context David Lechner
2025-09-12 16:05 ` [PATCH 7/7] iio: buffer: document that buffer callback must be context safe David Lechner
2025-09-13 13:57 ` [PATCH 0/7] iio: buffer: document calling context when pushing to buffers Jonathan Cameron

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=20250913145218.03d1be7d@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=dlechner@baylibre.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