From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71083C07E95 for ; Tue, 13 Jul 2021 16:16:48 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D53C9611AB for ; Tue, 13 Jul 2021 16:16:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D53C9611AB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 47B161683; Tue, 13 Jul 2021 18:15:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 47B161683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626193006; bh=hl+lIRA/4dHYDAFZ5Z4IUT8/vuPCzr6jGBJDmHqyGaY=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=OAd3DdaQzgWbdT71vFn3rPF92cwuveT+ryvCjVd1l3ePT5qXwe92MIhgchfj1qP6+ ccj6tJE5DyeL7ug/YjaXEpXJm56l5IbJK8TDFLtbTUA9qKhMgnFbK7nKCSV9dsGWWk ge7jUts8TxJ5U3R82TikYeHhvjF1CAKN/rLS2wxc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id DBD7FF800D3; Tue, 13 Jul 2021 18:15:55 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CDB95F80217; Tue, 13 Jul 2021 18:15:54 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 398A3F800D3 for ; Tue, 13 Jul 2021 18:15:51 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 398A3F800D3 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="GWqtFwcS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="nCQhOW6o" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id B772D1FD69; Tue, 13 Jul 2021 16:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626192951; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LU+dInQu9Jdqkd5CpV8rL7U5oz/FsqXDg3CRBGL5+sw=; b=GWqtFwcSNNNC6raZp1IlALbsmbpTL2hgXcnX9ESP2gP8X3tIhGFn5764j/xXUj2Y38Le7m W1gRnrbj9YDEYonu5ni+Ka/7iBlTbKHvuKxXkbEoIZ5yJGsQRwuhx4fe0kyT5H+9s5Cf4e DfYGo/O/eKDz7btOyYn2+JdhAUJRt8o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626192951; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LU+dInQu9Jdqkd5CpV8rL7U5oz/FsqXDg3CRBGL5+sw=; b=nCQhOW6oqyije80MihcrBIgBViKqNicAniNYzIcnyAH2SIzLn+Ju6vVOBOv3Qiii84J96S RBYpfFIMSihMvADQ== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id B0BCDA3B95; Tue, 13 Jul 2021 16:15:51 +0000 (UTC) Date: Tue, 13 Jul 2021 18:15:51 +0200 Message-ID: From: Takashi Iwai To: Amadeusz SX2awiX4ski Subject: Re: [PATCH 02/51] ALSA: core: Add managed card creation In-Reply-To: References: <20210713142857.19654-1-tiwai@suse.de> <20210713142857.19654-3-tiwai@suse.de> <9d6ce40b-101e-5b16-cd6c-8734aea4c4fd@linux.intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Tue, 13 Jul 2021 18:05:34 +0200, Takashi Iwai wrote: > > On Tue, 13 Jul 2021 17:23:02 +0200, > Amadeusz SX2awiX4ski wrote: > > > > On 7/13/2021 4:28 PM, Takashi Iwai wrote: > > > > > /** > > > * snd_card_ref - Get the card object from the index > > > @@ -481,6 +547,7 @@ EXPORT_SYMBOL_GPL(snd_card_disconnect_sync); > > > static int snd_card_do_free(struct snd_card *card) > > > { > > > + card->releasing = true; > > > #if IS_ENABLED(CONFIG_SND_MIXER_OSS) > > > if (snd_mixer_oss_notify_callback) > > > snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE); > > > @@ -498,7 +565,8 @@ static int snd_card_do_free(struct snd_card *card) > > > #endif > > > if (card->release_completion) > > > complete(card->release_completion); > > > - kfree(card); > > > + if (!card->managed) > > > + kfree(card); > > > return 0; > > > } > > > @@ -539,6 +607,9 @@ int snd_card_free(struct snd_card *card) > > > DECLARE_COMPLETION_ONSTACK(released); > > > int ret; > > > + if (card->releasing) > > > + return 0; > > > + > > > > "card->releasing" use feels bit racy to me... something like below > > would break it? > > > > thread1 thread2 > > snd_card_free() > > if(card->releasing) == false > > thread1 goes sleep > > snd_card_do_free() > > card->releasing = true > > run until the end > > thread1 resume > > continues with trying to release > > It's a destructor and can't be called in parallel. That is, what the code above cares is the case where snd_card_free() is called explicitly even if the card is created with devres. So the check of card->releasing could be __snd_card_release() instead in snd_card_free(), too. Takashi