From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [PATCH v2 1/2] ALSA: add snd_card_disconnect_sync() Date: Wed, 11 Oct 2017 14:19:52 +0200 Message-ID: References: <20171011101618.8736-1-tiwai@suse.de> <20171011101618.8736-2-tiwai@suse.de> <4f400024-56df-884c-efc4-8104e86b0b99@sakamocchi.jp> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 24AF1266D6B for ; Wed, 11 Oct 2017 14:19:53 +0200 (CEST) In-Reply-To: <4f400024-56df-884c-efc4-8104e86b0b99@sakamocchi.jp> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Takashi Sakamoto Cc: alsa-devel@alsa-project.org, Mark Brown , Kuninori Morimoto List-Id: alsa-devel@alsa-project.org On Wed, 11 Oct 2017 13:22:12 +0200, Takashi Sakamoto wrote: > > Hi, > > On Oct 11 2017 19:16, Takashi Iwai wrote: > > In case of user unbind ALSA driver during playing back / capturing, > > each driver needs to stop and remove it correctly. One note here is > > that we can't cancel from remove function in such case, because > > unbind operation doesn't check return value from remove function. > > So, we *must* stop and remove in this case. > > > > For this purpose, we need to sync (= wait) until the all top-level > > operations are canceled at remove function. > > For example, snd_card_free() processes the disconnection procedure at > > first, then waits for the completion. That's how the hot-unplug works > > safely. It's implemented, at least, in the top-level driver removal. > > > > Now for the lower level driver, we need a similar strategy. Notify to > > the toplevel for hot-unplug (disconnect in ALSA), and sync with the > > stop operation, then continue the rest of its own remove procedure. > > > > This patch adds snd_card_disconnect_sync(), and driver can use it from > > remove function. > > > > Tested-by: Kuninori Morimoto > > Signed-off-by: Takashi Iwai > > --- > > include/sound/core.h | 2 ++ > > sound/core/init.c | 32 ++++++++++++++++++++++++++++++++ > > 2 files changed, 34 insertions(+) > > I have a question for this patch. If this patch is applied and the > lower-level driver call this function in its .remove callback, after > all references to an instance of snd_card by file instances > corresponding to each of ALSA character devices are released, the > lower-level driver must explicitly releases the last reference to the > instance of snd_card. Not really. This is only about files user-space opened. It has nothing to do with the refcount of objects / resources. The refcount sync is done by card->release_completion instead, which is sync'ed in snd_card_free(). > On ALSA SoC part, which context perform this > important task? The "lower-level" might be confusing here; in the context, it's rather meant as middle layer (component) that can be unbound freely. Thus, for non-ASoC codes, this hasn't been a big problem, so far, since the helper modules can't be unbound. (Maybe the legacy AC97 codec driver needs something, and HD-audio has already some not-so-perfect workaround.) > In my opinion, this patch easily allows leak of > kobject. Do you have any safety? There isn't anything different from the current state wrt kobjects. The only merit of calling this in the remove callback is that it can assure that the all actions are stopped, by disconnecting the devices. It doesn't free resources by itself. > At least, it's better for us to add enough comments to inform it to > developers. Well, I thought it well informed about the disconnection procedure. Maybe the term "lower level driver" needs to be more explicit. thanks, Takashi