All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: 张波 <zbsdta@126.com>, "Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Fix matrix keypad does not response with matrix_keypad driver in specific condition.
Date: Fri, 2 Feb 2018 21:43:20 +0200	[thread overview]
Message-ID: <CAHp75Vc-BfnE7ZrZ_R5pdC0OvVUi+iGkh6jj9VbEjP7BZ1_vNw@mail.gmail.com> (raw)
In-Reply-To: <69331bab.9854.161574424f2.Coremail.zbsdta@126.com>

+Cc: Dmitry

On Fri, Feb 2, 2018 at 6:05 PM, 张波 <zbsdta@126.com> wrote:
>
> in matrix_keypad.c, the function disable_row_irqs() may be called by matrix_keypad_interrupt() or matrix_keypad_stop(), there is race condition to disble irqs.
>
>
> If while matrix_keypad_stop() is calling, and the keypad interrupt is triggered, disable_row_irqs() is called by matrix_keypad_interrupt() and matrix_keypad_stop() at the same time. then disable_row_irqs() is called twice, and the device enter suspend state before keypad->work is executed. At this condition the device will start keypad and enable irq once after resume. and irqs are disabled yet because irqs are disabled twice and only enable once.
> then the device can't trigger keypad interrupts.
> this problem could reproduce easily by change code to add time delay in matrix_keypad_interrupt() just before calling schedule_delayed_work.
>

Thanks for the patch.

First of all, fix your email handlers. The patch is mangled quite badly.

Second, follow the process [1] and don't forget to put your
Signed-off-by tag (hint `git commit -a -s`).

[1]: http://elixir.free-electrons.com/linux/latest/source/Documentation/process/submit-checklist.rst

>
> diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
> index 1f316d66e6f7..03224ae9eedb 100644
> --- a/drivers/input/keyboard/matrix_keypad.c
> +++ b/drivers/input/keyboard/matrix_keypad.c
> @@ -36,6 +36,7 @@ struct matrix_keypad {
>   uint32_t last_key_state[MATRIX_MAX_COLS];
>   struct delayed_work work;
>   spinlock_t lock;
> + int irq_enabled;
>   bool scan_pending;
>   bool stopped;
>   bool gpio_all_disabled;
> @@ -90,6 +91,12 @@ static void enable_row_irqs(struct matrix_keypad *keypad)
>  {
>   const struct matrix_keypad_platform_data *pdata = keypad->pdata;
>   int i;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&keypad->lock, flags);
> +
> + if (keypad->irq_enabled == 1)
> + goto out;
>
>   if (pdata->clustered_irq > 0)
>   enable_irq(pdata->clustered_irq);
> @@ -97,19 +104,31 @@ static void enable_row_irqs(struct matrix_keypad *keypad)
>   for (i = 0; i < pdata->num_row_gpios; i++)
>   enable_irq(gpio_to_irq(pdata->row_gpios[i]));
>   }
> + keypad->irq_enabled = 1;
> +
> +out:
> + spin_unlock_irqrestore(&keypad->lock, flags);
>  }
>
>  static void disable_row_irqs(struct matrix_keypad *keypad)
>  {
>   const struct matrix_keypad_platform_data *pdata = keypad->pdata;
>   int i;
> + unsigned long flags;
>
> + spin_lock_irqsave(&keypad->lock, flags);
> + if (keypad->irq_enabled == 0)
> + goto out;
>   if (pdata->clustered_irq > 0)
>   disable_irq_nosync(pdata->clustered_irq);
>   else {
>   for (i = 0; i < pdata->num_row_gpios; i++)
>   disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
>   }
> + keypad->irq_enabled = 0;
> +
> +out:
> + spin_unlock_irqrestore(&keypad->lock, flags);
>  }
>
>  /*
> @@ -167,18 +186,13 @@ static void matrix_keypad_scan(struct work_struct *work)
>   activate_all_cols(pdata, true);
>
>   /* Enable IRQs again */
> - spin_lock_irq(&keypad->lock);
>   keypad->scan_pending = false;
>   enable_row_irqs(keypad);
> - spin_unlock_irq(&keypad->lock);
>  }
>
>  static irqreturn_t matrix_keypad_interrupt(int irq, void *id)
>  {
>   struct matrix_keypad *keypad = id;
> - unsigned long flags;
> -
> - spin_lock_irqsave(&keypad->lock, flags);
>
>   /*
>   * See if another IRQ beaten us to it and scheduled the
> @@ -194,7 +208,6 @@ static irqreturn_t matrix_keypad_interrupt(int irq, void *id)
>   msecs_to_jiffies(keypad->pdata->debounce_ms));
>
>  out:
> - spin_unlock_irqrestore(&keypad->lock, flags);
>   return IRQ_HANDLED;
>  }



-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2018-02-02 19:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02 16:05 Fix matrix keypad does not response with matrix_keypad driver in specific condition 张波
2018-02-02 19:43 ` Andy Shevchenko [this message]
2018-02-02 20:02   ` Dmitry Torokhov

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=CAHp75Vc-BfnE7ZrZ_R5pdC0OvVUi+iGkh6jj9VbEjP7BZ1_vNw@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zbsdta@126.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 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.