Linux IIO development
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: Vincent Whitchurch <vincent.whitchurch@axis.com>,
	rafael.j.wysocki@intel.com, jic23@kernel.org
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org
Subject: Re: PM runtime_error handling missing in many drivers?
Date: Tue, 21 Jun 2022 11:38:33 +0200	[thread overview]
Message-ID: <5caa944f-c841-6f74-8e43-a278b2b93b06@suse.com> (raw)
In-Reply-To: <20220620144231.GA23345@axis.com>

On 20.06.22 16:42, Vincent Whitchurch wrote:

Hi,

> Many drivers do something like the following to resume their hardware
> before performing some hardware access when user space ask for it:
> 
> 	ret = pm_runtime_resume_and_get(dev);
> 	if (ret)
> 		return ret;
> 
> But if the ->runtime_resume() callback fails, then the
> power.runtime_error is set and any further attempts to use
> pm_runtime_resume_and_get() will fail, as documented in
> Documentation/power/runtime_pm.rst.

Whether this is properly documented is debatable.
4. Runtime PM Device Helper Functions (as a chapter)
does _not_ document it.


> [110778.050000][   T27] rpm_resume: 0-0009 flags-4 cnt-1  dep-0  auto-1 p-0 irq-0 child-0
> [110778.050000][   T27] rpm_return_int: rpm_resume+0x24d/0x11d0:0-0009 ret=-22
> 
> The following patch fixes the issue on vcnl4000, but is this the right in the


> fix?  And, unless I'm missing something, there are dozens of drivers
> with the same problem.

Yes. The point of pm_runtime_resume_and_get() is to remove the need
for handling errors when the resume fails. So I fail to see why a
permanent record of a failure makes sense for this API.

> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index e02e92bc2928..082b8969fe2f 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -414,6 +414,8 @@ static int vcnl4000_set_pm_runtime_state(struct vcnl4000_data *data, bool on)
>  
>  	if (on) {
>  		ret = pm_runtime_resume_and_get(dev);
> +		if (ret)
> +			pm_runtime_set_suspended(dev);
>  	} else {
>  		pm_runtime_mark_last_busy(dev);
>  		ret = pm_runtime_put_autosuspend(dev);

If you need to add this to every driver, you can just as well add it to
pm_runtime_resume_and_get() to avoid the duplication.

But I am afraid we need to ask a deeper question. Is there a point
in recording failures to resume? The error code is reported back.
If a driver wishes to act upon it, it can. The core really only
uses the result to block new PM operations.
But nobody requests a resume unless it is necessary. Thus I fail
to see the point of checking this flag in resume as opposed to
suspend. If we fail, we fail, why not retry? It seems to me that the
record should be used only during runtime suspend.

And as an immediate band aid, some errors like ENOMEM should
never be recorded.

	Regards
		Oliver

  reply	other threads:[~2022-06-21  9:38 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 14:42 PM runtime_error handling missing in many drivers? Vincent Whitchurch
2022-06-21  9:38 ` Oliver Neukum [this message]
2022-07-08 11:03   ` Vincent Whitchurch
2022-07-08 20:10     ` Rafael J. Wysocki
2022-07-26  9:05       ` Oliver Neukum
2022-07-26 15:41         ` Rafael J. Wysocki
2022-07-27  8:08           ` Oliver Neukum
2022-07-27 16:31             ` Rafael J. Wysocki
2025-02-10  3:32               ` Ajay Agarwal
2025-02-11 22:21                 ` Brian Norris
2025-02-12 19:29                   ` Rafael J. Wysocki
2025-02-17  3:49                     ` Ajay Agarwal
2025-02-17 20:23                       ` Rafael J. Wysocki
2025-02-18  5:37                         ` Ajay Agarwal
2025-02-18  5:45                           ` Ajay Agarwal
2025-02-18 14:57                             ` Rafael J. Wysocki
2025-02-19 22:15                     ` Brian Norris
2025-02-20  9:30                       ` Oliver Neukum
2025-02-22  1:51                         ` Brian Norris

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=5caa944f-c841-6f74-8e43-a278b2b93b06@suse.com \
    --to=oneukum@suse.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=vincent.whitchurch@axis.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