linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ulf Hansson <ulf.hansson@linaro.org>
To: Kai-Heng Feng <kai.heng.feng@canonical.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Linux USB List <linux-usb@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/4 v5] memstick: Prevent memstick host from getting runtime suspended during card detection
Date: Mon, 29 Oct 2018 13:25:55 +0100	[thread overview]
Message-ID: <CAPDyKFrtQeDUK0Dxu9Z3-eyyMbChHHb2He1AFq2My_7-cTY2FA@mail.gmail.com> (raw)
In-Reply-To: <20181024084958.4627-3-kai.heng.feng@canonical.com>

On 24 October 2018 at 10:49, Kai-Heng Feng <kai.heng.feng@canonical.com> wrote:
> We can use MEMSTICK_POWER_{ON,OFF} along with pm_runtime_{get,put}
> helpers to let memstick host support runtime pm.
>
> There's a small window between memstick_detect_change() and its queued
> work, memstick_check(). In this window the rpm count may go down to zero
> before the memstick host powers on, so the host can be inadvertently
> suspended.
>
> Increment rpm count before calling memstick_check(), and decrement rpm
> count afterward, as now we are sure the memstick host should be
> suspended or not.
>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
>  drivers/memstick/core/memstick.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
> index 76382c858c35..5f16a8826401 100644
> --- a/drivers/memstick/core/memstick.c
> +++ b/drivers/memstick/core/memstick.c
> @@ -18,6 +18,7 @@
>  #include <linux/delay.h>
>  #include <linux/slab.h>
>  #include <linux/module.h>
> +#include <linux/pm_runtime.h>
>
>  #define DRIVER_NAME "memstick"
>
> @@ -209,6 +210,7 @@ static int memstick_dummy_check(struct memstick_dev *card)
>   */
>  void memstick_detect_change(struct memstick_host *host)
>  {
> +       pm_runtime_get_noresume(host->dev.parent);
>         queue_work(workqueue, &host->media_checker);
>  }
>  EXPORT_SYMBOL(memstick_detect_change);
> @@ -479,6 +481,8 @@ static void memstick_check(struct work_struct *work)
>                 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF);
>
>         mutex_unlock(&host->lock);
> +
> +       pm_runtime_put(host->dev.parent);
>         dev_dbg(&host->dev, "memstick_check finished\n");
>  }
>

I am not sure this works, sorry.

More precisely, I don't think there is a guarantee that the calls to
pm_runtime_get|put*() becomes properly balanced. In principle
memstick_detect_change() could be called, without actually causing a
new work to be scheduled if there is already such a work in the queue
(depends on the workqueue configuration). Isn't it so?

Kind regards
Uffe

  reply	other threads:[~2018-10-29 12:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-24  8:49 [PATCH 0/4 v5] Keep rtsx_usb suspended when there's no card Kai-Heng Feng
2018-10-24  8:49 ` [PATCH 1/4 v5] misc: rtsx_usb: Use USB remote wakeup signaling for card insertion detection Kai-Heng Feng
2018-10-24  8:49 ` [PATCH 2/4 v5] memstick: Prevent memstick host from getting runtime suspended during card detection Kai-Heng Feng
2018-10-29 12:25   ` Ulf Hansson [this message]
2018-10-29 16:31     ` Kai Heng Feng
2018-10-30 13:03       ` Ulf Hansson
2018-10-30 15:23         ` Kai Heng Feng
2018-10-30 16:04           ` Ulf Hansson
2018-10-31  6:33             ` Kai Heng Feng
2018-10-24  8:49 ` [PATCH 3/4 v5] memstick: rtsx_usb_ms: Use ms_dev() helper Kai-Heng Feng
2018-10-24  8:49 ` [PATCH 4/4 v5] memstick: rtsx_usb_ms: Support runtime power management Kai-Heng Feng
2018-10-27 13:13 ` [PATCH 0/4 v5] Keep rtsx_usb suspended when there's no card Oleksandr Natalenko

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=CAPDyKFrtQeDUK0Dxu9Z3-eyyMbChHHb2He1AFq2My_7-cTY2FA@mail.gmail.com \
    --to=ulf.hansson@linaro.org \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=kai.heng.feng@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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;
as well as URLs for NNTP newsgroup(s).