public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Cc: Naushir Patuck <naush@raspberrypi.com>,
	Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>,
	David Plowman <david.plowman@raspberrypi.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	linux-media@vger.kernel.org
Subject: Re: [PATCH v4 4/4] media: pisp_be: Fix pm_runtime underrun in probe
Date: Tue, 3 Sep 2024 02:13:16 +0300	[thread overview]
Message-ID: <20240902231316.GC26371@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20240902112408.493201-5-jacopo.mondi@ideasonboard.com>

Hi Jacopo,

Thank you for the patch.

On Mon, Sep 02, 2024 at 01:24:06PM +0200, Jacopo Mondi wrote:
> During the probe() routine, the driver needs to power up the interface
> in order to identify and initialize the hardware and it later suspends
> it at the end of probe().
> 
> The driver erroneously resumes the interface by calling the
> pispbe_runtime_resume() function directly but suspends it by
> calling pm_runtime_put_autosuspend().
> 
> This causes a PM usage count imbalance at probe time, notified by the
> runtime_pm framework with the below message in the system log:
> 
>  pispbe 1000880000.pisp_be: Runtime PM usage count underflow!
> 
> Fix this by suspending the interface using pm_runtime_idle() which
> doesn't decrease the pm_runtime usage count and inform the PM framework
> that the device is active by calling pm_runtime_set_active().
> 
> Adjust the pispbe_remove() function as well to disable
> the pm_runtime in the correct order,

s/,$/./

> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> 
> ---
> v3->v4:
> - Instead of using pm_runtime for resuming, suspend using
>   pm_runtime_idle() to support !CONFIG_PM
> 
> v2->v3:
> - Mark pispbe_runtime_resume() as __maybe_unused as reported by
>   the kernel test robot <lkp@intel.com>
> ---
>  .../platform/raspberrypi/pisp_be/pisp_be.c    | 26 +++++++++----------
>  1 file changed, 12 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
> index d614f53f0f68..1c19ca946bd4 100644
> --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
> +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
> @@ -1720,36 +1720,32 @@ static int pispbe_probe(struct platform_device *pdev)
>  				     "Failed to get clock");
>  
>  	/* Hardware initialisation */
> -	pm_runtime_set_autosuspend_delay(pispbe->dev, 200);
> -	pm_runtime_use_autosuspend(pispbe->dev);
> -	pm_runtime_enable(pispbe->dev);
> -
>  	ret = pispbe_runtime_resume(pispbe->dev);
>  	if (ret)
> -		goto pm_runtime_disable_err;
> +		return ret;
>  
>  	pispbe->hw_busy = false;
>  	spin_lock_init(&pispbe->hw_lock);
>  	ret = pispbe_hw_init(pispbe);
>  	if (ret)
> -		goto pm_runtime_suspend_err;
> +		goto runtime_suspend_err;
>  
>  	ret = pispbe_init_devices(pispbe);
>  	if (ret)
>  		goto disable_devs_err;
>  
> -	pm_runtime_mark_last_busy(pispbe->dev);
> -	pm_runtime_put_autosuspend(pispbe->dev);
> +	pm_runtime_set_autosuspend_delay(pispbe->dev, 200);
> +	pm_runtime_use_autosuspend(pispbe->dev);
> +	pm_runtime_set_active(pispbe->dev);
> +	pm_runtime_enable(pispbe->dev);
> +	pm_runtime_idle(pispbe->dev);
>  
>  	return 0;
>  
>  disable_devs_err:

It would be nice to rename the error labels to start with err_, like
commonly done (in another patch of course).

>  	pispbe_destroy_devices(pispbe);
> -pm_runtime_suspend_err:
> +runtime_suspend_err:
>  	pispbe_runtime_suspend(pispbe->dev);
> -pm_runtime_disable_err:
> -	pm_runtime_dont_use_autosuspend(pispbe->dev);
> -	pm_runtime_disable(pispbe->dev);
>  
>  	return ret;
>  }
> @@ -1760,9 +1756,11 @@ static void pispbe_remove(struct platform_device *pdev)
>  
>  	pispbe_destroy_devices(pispbe);
>  
> -	pispbe_runtime_suspend(pispbe->dev);
>  	pm_runtime_dont_use_autosuspend(pispbe->dev);
> -	pm_runtime_disable(pispbe->dev);
> +        pm_runtime_disable(pispbe->dev);
> +        if (!pm_runtime_status_suspended(pispbe->dev))
> +                pispbe_runtime_suspend(pispbe->dev);
> +        pm_runtime_set_suspended(pispbe->dev);

Wrong indentation, you're using spaces instead of tabs.

With those issues fixed,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  }
>  
>  static const struct dev_pm_ops pispbe_pm_ops = {

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2024-09-02 23:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-02 11:24 [PATCH v4 0/4] media: pisp-be: Split jobs creation and scheduling Jacopo Mondi
2024-09-02 11:24 ` [PATCH v4 1/4] media: pisp_be: Drop reference to non-existing function Jacopo Mondi
2024-09-02 22:42   ` Laurent Pinchart
2024-09-02 11:24 ` [PATCH v4 2/4] media: pisp_be: Remove config validation from schedule() Jacopo Mondi
2024-09-02 23:07   ` Laurent Pinchart
2024-09-02 11:24 ` [PATCH v4 3/4] media: pisp-be: Split jobs creation and scheduling Jacopo Mondi
2024-09-03 12:19   ` Laurent Pinchart
2024-09-04  7:21     ` Jacopo Mondi
2024-09-04  7:53       ` Laurent Pinchart
2024-09-04  8:35         ` Jacopo Mondi
2024-09-04 10:41           ` Laurent Pinchart
2024-09-02 11:24 ` [PATCH v4 4/4] media: pisp_be: Fix pm_runtime underrun in probe Jacopo Mondi
2024-09-02 23:13   ` Laurent Pinchart [this message]
2024-09-03  6:18     ` Jacopo Mondi

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=20240902231316.GC26371@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=david.plowman@raspberrypi.com \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=naush@raspberrypi.com \
    --cc=nick.hollinghurst@raspberrypi.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