From patchwork Sat Dec 26 03:35:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 7921321 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0930D9F350 for ; Sat, 26 Dec 2015 03:37:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2827B203E1 for ; Sat, 26 Dec 2015 03:37:45 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id E19B7203C2 for ; Sat, 26 Dec 2015 03:37:43 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 85461266835; Sat, 26 Dec 2015 04:37:41 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E974A26153C; Sat, 26 Dec 2015 04:35:51 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 864F0261497; Sat, 26 Dec 2015 04:35:47 +0100 (CET) Received: from smtp310.phy.lolipop.jp (smtp310.phy.lolipop.jp [210.157.22.78]) by alsa0.perex.cz (Postfix) with ESMTP id 6BF7D26149D for ; Sat, 26 Dec 2015 04:35:36 +0100 (CET) Received: from smtp310.phy.lolipop.lan (HELO smtp310.phy.lolipop.jp) (172.17.1.10) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp310.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Sat, 26 Dec 2015 12:35:34 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp310.phy.lolipop.jp (LOLIPOP-Fsecure); Sat, 26 Dec 2015 12:35:27 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: clemens@ladisch.de, tiwai@suse.de Date: Sat, 26 Dec 2015 12:35:24 +0900 Message-Id: <1451100926-20637-4-git-send-email-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1451100926-20637-1-git-send-email-o-takashi@sakamocchi.jp> References: <1451100926-20637-1-git-send-email-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org, stefanr@s5r6.in-berlin.de, ffado-devel@lists.sf.net Subject: [alsa-devel] [PATCH 3/5] ALSA: dice: ensure to release sound devices after sound card registration fails X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP When work of sound card registration fails, bus reset on IEEE 1394 can schedule the work again. In this case, currently instances of PCM and RawMIDI devices are not released, but allocated and errors occurs. This commit solves this issue. The allocated data is kept and released at any failures in the work. Signed-off-by: Takashi Sakamoto --- sound/firewire/dice/dice-midi.c | 2 ++ sound/firewire/dice/dice-pcm.c | 2 ++ sound/firewire/dice/dice.c | 30 +++++++++++++++++++++--------- sound/firewire/dice/dice.h | 2 ++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/sound/firewire/dice/dice-midi.c b/sound/firewire/dice/dice-midi.c index 151b09f..908b43f 100644 --- a/sound/firewire/dice/dice-midi.c +++ b/sound/firewire/dice/dice-midi.c @@ -153,5 +153,7 @@ int snd_dice_create_midi(struct snd_dice *dice) if ((midi_out_ports > 0) && (midi_in_ports > 0)) rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX; + dice->rmidi_dev = rmidi; + return 0; } diff --git a/sound/firewire/dice/dice-pcm.c b/sound/firewire/dice/dice-pcm.c index 9b34319..6246ce3 100644 --- a/sound/firewire/dice/dice-pcm.c +++ b/sound/firewire/dice/dice-pcm.c @@ -426,5 +426,7 @@ int snd_dice_create_pcm(struct snd_dice *dice) if (playback > 0) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops); + dice->pcm_dev = pcm; + return 0; } diff --git a/sound/firewire/dice/dice.c b/sound/firewire/dice/dice.c index 0bc7d08..21ad894 100644 --- a/sound/firewire/dice/dice.c +++ b/sound/firewire/dice/dice.c @@ -202,33 +202,45 @@ static void do_registration(struct work_struct *work) if (dice->card->shutdown || dice->registered) return; + dice->pcm_dev = NULL; + dice->rmidi_dev = NULL; + err = snd_dice_transaction_init(dice); if (err < 0) - goto end; + goto error; err = dice_read_params(dice); if (err < 0) - goto end; + goto error; dice_card_strings(dice); err = snd_dice_create_pcm(dice); if (err < 0) - goto end; + goto error; err = snd_dice_create_midi(dice); if (err < 0) - goto end; + goto error; err = snd_card_register(dice->card); if (err < 0) - goto end; + goto error; dice->registered = true; -end: - if (err < 0) - dev_info(&dice->unit->device, - "Sound card registration failed: %d\n", err); + + return; +error: + snd_dice_transaction_destroy(dice); + + if (dice->pcm_dev) + snd_device_free(dice->card, dice->pcm_dev); + + if (dice->rmidi_dev) + snd_device_free(dice->card, dice->rmidi_dev); + + dev_info(&dice->unit->device, + "Sound card registration failed: %d\n", err); } static void schedule_registration(struct snd_dice *dice) diff --git a/sound/firewire/dice/dice.h b/sound/firewire/dice/dice.h index 3d5ebeb..d632ac1 100644 --- a/sound/firewire/dice/dice.h +++ b/sound/firewire/dice/dice.h @@ -47,6 +47,8 @@ struct snd_dice { bool registered; struct delayed_work dwork; + struct snd_pcm *pcm_dev; + struct snd_rawmidi *rmidi_dev; /* Offsets for sub-addresses */ unsigned int global_offset;