Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Leon Romanovsky <leon@leon.nu>
Cc: Mark Brown <broonie@kernel.org>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	patches <patches@opensource.wolfsonmicro.com>,
	linux-input@vger.kernel.org
Subject: Re: [alsa-devel] [PATCH] ASoC: wm8962: Convert to devm_input_allocate_device()
Date: Mon, 29 Apr 2013 11:07:28 -0700	[thread overview]
Message-ID: <20130429180727.GA3915@core.coreip.homeip.net> (raw)
In-Reply-To: <CALq1K=KGrDJZa_w_ZVdriptpiKsWvwYDcx3aV3oVXMyTxMjcqg@mail.gmail.com>

On Mon, Apr 29, 2013 at 08:47:37PM +0300, Leon Romanovsky wrote:
> On Mon, Apr 29, 2013 at 1:19 PM, Mark Brown <broonie@kernel.org> wrote:
> > On Sun, Apr 28, 2013 at 09:32:18PM +0300, Leon Romanovsky wrote:
> >
> >> I think the reason of our misunderstanding is due to the name of
> >> input_free_device call. From the code, it is device destroy function,
> >> and the freeing itself done as an error handling of
> >> input_register_device
> >> (http://lxr.free-electrons.com/source/drivers/input/input.c#L2114).
> >
> >> How do you think we need to proceed? Do I need to send patches with
> >> explicit call to input_free_device function?
> >
> > I really think the input API needs to be looked at here, this is all way
> > too error prone.  Calling input_free_device() on something allocated
> > using devm_ looks like an error itself...
> In general, I agree with you, but I think we both agree that the
> current patch is not working as expected.
> The problem is that you allocated device with devm_ and later at the
> code you tried to register it, but failed. In this case no one will
> call to devres_destroy, because it is done at unregister stage only.
> 
> I see two possible solutions:
> 1. short one - fix your patches
> 2. long one - add input_free_device code into input_register_device
> call (http://lxr.free-electrons.com/source/drivers/input/input.c#L2114).
> 

The rules are pretty straightforward:

1. If you are using devm_input_allocate_device() you do not need to call
input_free_device() nor input_unregister_device()  - the core will
create a devres structure for freeing the device and if
input_register_device() succeeds it will also add a 2nd devres for
unregistering. This way the "normal" unwind is a 2-step process with
device is "half alive" and being able to survive input_event() calls
from IRQ handlers if they are still alive.

IOW  it should all "just work".

2. If you are using input_allocate_device() then you need to call
input_free_device() until you called input_register_device(), afterward
input_unregister_device() should be called.

Thanks.

-- 
Dmitry

  reply	other threads:[~2013-04-29 18:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-20 13:18 [PATCH] ASoC: wm8962: Convert to devm_input_allocate_device() Mark Brown
2013-04-24 13:50 ` Leon Romanovsky
2013-04-25 12:52   ` Mark Brown
2013-04-28  5:00     ` Leon Romanovsky
2013-04-28  9:47       ` Mark Brown
2013-04-28 18:32         ` Leon Romanovsky
2013-04-29 10:19           ` Mark Brown
2013-04-29 17:47             ` [alsa-devel] " Leon Romanovsky
2013-04-29 18:07               ` Dmitry Torokhov [this message]
2013-04-29 18:19                 ` Dmitry Torokhov
2013-04-29 18:52                   ` Leon Romanovsky
2013-04-29 20:01                     ` Mark Brown

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=20130429180727.GA3915@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=leon@leon.nu \
    --cc=linux-input@vger.kernel.org \
    --cc=patches@opensource.wolfsonmicro.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