From: Lars-Peter Clausen <lars@metafoo.de>
To: Ricard Wanderlof <ricard.wanderlof@axis.com>,
Clemens Ladisch <clemens@ladisch.de>
Cc: alsa-devel <alsa-devel@alsa-project.org>
Subject: Re: Unregister a card from userspace?
Date: Thu, 12 Nov 2015 14:26:15 +0100 [thread overview]
Message-ID: <56449377.2050409@metafoo.de> (raw)
In-Reply-To: <alpine.DEB.2.02.1511121402000.11990@lnxricardw1.se.axis.com>
On 11/12/2015 02:07 PM, Ricard Wanderlof wrote:
>
> On Wed, 4 Nov 2015, Clemens Ladisch wrote:
>
>> Ricard Wanderlof wrote:
>>> My use case is that I have a card driver I'm working on as a module, and
>>> while insmodding it works fine, I can't rmmod it because once
>>> snd_soc_register_card() has been called, it has a usage count of 2 and
>>> thus cannot be rmmod:ed.
>>
>> soc_probe_component() adds a reference to each component's driver's
>> module. Maybe putting each component into its own module would help.
>
> I'd rather not as there's no real gain from it (the constituent drivers
> cannot be used separately or in any other combination), but perhaps that
> is the only way to go.
>
>> Anyway, you should be able to unbind the driver:
>> <https://lwn.net/Articles/143397/>
>
> Yes, that works. After unbinding the driver, the usage count drops to 0,
> and I can successfully rmmod it. So at least that's a workable solution.
>
> It just seems to me that there's something I must have missed, as there
> should be a mechanism to do this automatically when a module containing a
> driver is rmmod'ed.
The way it works is that the reference count for the modules of the
individual components is incremented when they are bound to the card to
ensure that they are not removed when still in use. This usually does not
affect the reference count on the module of the card and you can still rmmod
the module of the card which will unregister the card. This again drops the
reference count on the components and you can remove those modules as well.
In your case the components and the card are in the same module and you end
up with a cyclic dependency. The card ensures that the reference count of
the module for the components is incremented, which in this case is also the
cards module, so the cards module reference count is non 0 and you can't
rmmod the card module, which means the card won't be unregistered which
means the references to the module wont be dropped.
next prev parent reply other threads:[~2015-11-12 13:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 9:36 Unregister a card from userspace? Ricard Wanderlof
2015-11-04 11:24 ` Clemens Ladisch
2015-11-12 13:07 ` Ricard Wanderlof
2015-11-12 13:26 ` Lars-Peter Clausen [this message]
2015-11-12 15:38 ` Ricard Wanderlof
2015-11-09 11:24 ` Felipe Ferreri Tonello
2015-11-10 7:55 ` Ricard Wanderlof
2015-11-11 10:34 ` Felipe Ferreri Tonello
2015-11-11 12:59 ` Ricard Wanderlof
2015-11-11 13:09 ` Lars-Peter Clausen
2015-11-11 15:24 ` Ricard Wanderlof
2015-11-11 14:50 ` Felipe Ferreri Tonello
2015-11-11 15:33 ` Ricard Wanderlof
2015-11-12 10:31 ` Felipe Ferreri Tonello
2015-11-12 14:02 ` Ricard Wanderlof
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=56449377.2050409@metafoo.de \
--to=lars@metafoo.de \
--cc=alsa-devel@alsa-project.org \
--cc=clemens@ladisch.de \
--cc=ricard.wanderlof@axis.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