All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@ti.com>
To: linux-pm <linux-pm@lists.linux-foundation.org>
Subject: use of pm_runtime_disable() from driver probe?
Date: Fri, 06 Jul 2012 15:29:07 -0700	[thread overview]
Message-ID: <873954a5ho.fsf@ti.com> (raw)

Hello,

I've got a question around the proper use of pm_runtime_disable() in a
driver's ->probe method.  Basically, using pm_runtime_disable() in
->probe() (e.g because of a error/failure) can result in the device
remaning runtime enabled forever.  This is because the driver core wraps
the probe in _get_noresume()/_put_sync() so any usage of _put_sync() in
->probe itself does not trigger an actual device runtime suspend.  If
the driver also calls pm_runtime_disable() in probe, that results in the
device remaining runtime enabled.

Consider this example (based on drivers/mmc/host/omap_hsmmc.c).  In the
normal/success path, everything works fine.  But in the failure case,
the after the failed probe, the driver calls pm_runtime_disable() and
the device is left runtime enabled:

driver_probe()
{
    /* usage count == 1; due to _get_noresume() in driver core */
    pm_runtime_enable();
    pm_runtime_get_sync()
    /* usage_count == 2 */
  
    /* probe HW */
    if (failure)
        goto error;    

    /* otherwise, finish HW init */

    pm_runtime_put_sync();
    /* usage_count == 1 */
    /* _put_sync() in driver core will make count = 0
     * and device will be runtime suspended */
    return 0;  

 error:
    pm_runtime_put_sync();
    /* usage_count = 1 */
    pm_runtime_disable();

    /* Now, the _put_sync() in driver core will not actually suspend
       since runtime PM has been disabled. */
}


So, the question is: is it right to use pm_runtime_disable() this way?

Removing it means the device is left in runtime suspended state even in
the error case.  However, without the pm_runtime_disable(), if this
driver was a module, repeated attempts to load would result in
unbalalced calls to pm_runtime_enable.

What is the right way to handle the runtime PM enable/disable in a
failed probe attempt?

Thanks,

Kevin

             reply	other threads:[~2012-07-06 22:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-06 22:29 Kevin Hilman [this message]
2012-07-07 19:25 ` use of pm_runtime_disable() from driver probe? Rafael J. Wysocki
2012-07-08  2:01   ` Alan Stern
2012-07-08 14:59     ` Rafael J. Wysocki
2012-07-10 18:11   ` Kevin Hilman
2012-07-10 18:31     ` Rafael J. Wysocki
2012-07-10 18:47       ` Alan Stern
2012-07-10 19:14         ` Rafael J. Wysocki
2012-07-10 19:41           ` Rafael J. Wysocki
2012-07-10 20:17             ` Alan Stern
2012-07-10 21:04               ` Kevin Hilman
2012-07-10 22:31               ` Rafael J. Wysocki
2012-07-11 14:20                 ` Alan Stern
2012-07-11 17:36                   ` Rafael J. Wysocki
2012-07-11 23:07                     ` Kevin Hilman
2012-07-11 23:16                       ` Rafael J. Wysocki

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=873954a5ho.fsf@ti.com \
    --to=khilman@ti.com \
    --cc=linux-pm@lists.linux-foundation.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.