linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Aniroop Mathur <aniroop.mathur@gmail.com>
Cc: linux-input@vger.kernel.org, a.mathur@samsung.com
Subject: Re: [PATCH] Input: Avoid kernel panic during device unregistration
Date: Sun, 28 Dec 2014 12:21:49 -0800	[thread overview]
Message-ID: <20141228202149.GA21544@dtor-ws> (raw)
In-Reply-To: <1419790325-4004-1-git-send-email-aniroop.mathur@gmail.com>

Hi Aniroop,

On Sun, Dec 28, 2014 at 11:42:05PM +0530, Aniroop Mathur wrote:
> This patch adds null check before actually unregistering the input device
> to avoid null pointer exception which leads to kernel panic.
> 
> So now, input device drivers won't have to worry about or add null case
> condition before calling input_unregister_device() in shutdown and
> remove functions.

input_unregister_device() should be called only if
input_register_device() succeeded, which it would not with input device
being NULL.

Unlike input_free_device() which does handle NULL argument, similar to
many other "free" APIs I do not believe that input_unregister_device
should be handling such cases.

> 
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
> ---
>  drivers/input/input.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 01fe49e..575219d 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -2170,6 +2170,9 @@ EXPORT_SYMBOL(input_register_device);
>   */
>  void input_unregister_device(struct input_dev *dev)
>  {
> +	if (!dev)
> +		return;
> +
>  	if (dev->devres_managed) {
>  		WARN_ON(devres_destroy(dev->dev.parent,
>  					devm_input_device_unregister,
> -- 
> 1.9.1
> 

Thanks.

-- 
Dmitry

  reply	other threads:[~2014-12-28 20:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-28 18:12 [PATCH] Input: Avoid kernel panic during device unregistration Aniroop Mathur
2014-12-28 20:21 ` Dmitry Torokhov [this message]
2014-12-29 16:41   ` Aniroop Mathur
2014-12-29 17:23     ` Dmitry Torokhov
2014-12-29 17:38       ` Aniroop Mathur

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=20141228202149.GA21544@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=a.mathur@samsung.com \
    --cc=aniroop.mathur@gmail.com \
    --cc=linux-input@vger.kernel.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 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).