From: Takashi Iwai Subject: Re: Strange code in Date: Mon, 23 Apr 2007 12:11:45 +0200 Message-ID: References: <20070420152638.1834b1b5.zaitcev@redhat.com> 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 (ns2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 61D7624841 for ; Mon, 23 Apr 2007 12:11:55 +0200 (CEST) In-Reply-To: <20070420152638.1834b1b5.zaitcev@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Pete Zaitcev Cc: alsa-devel@alsa-project.org, linux-usb-devel@lists.sourceforge.net, j.w.r.degoede@hhs.nl List-Id: alsa-devel@alsa-project.org At Fri, 20 Apr 2007 15:26:38 -0700, Pete Zaitcev wrote: > > Dear Takashi: > > Hans de Goede (on cc:) hits a problem when snd-usb-audio breaks with: > "USB device is in the shutdown state, cannot create a card instance". > > This is how the place looks: > > chip = NULL; > for (i = 0; i < SNDRV_CARDS; i++) { > if (usb_chip[i] && usb_chip[i]->dev == dev) { > if (usb_chip[i]->shutdown) { > snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n"); > goto __error; > } > chip = usb_chip[i]; > break; > } > } > > The code looks broken to me, because dev at this time is a new device > structure, freshly allocated. You cannot compare it with an old instance, > and I don't know why you would want to. This function was implemented in that way because some devices have multiple audio control interfaces per device, and it results in the multiple calls of probe function for each interface. > Unfortunately (for fortunately), I have zero clue about the way ALSA > works, specifically rules for snd_device_ops.dev_free, so I am asking > you to look at this problem. Hard to guess unless knowing what is exactly happening, but most likely a race at disconnection. Yes, potentially the check of usb_device there is a problem indeed. The (untested) patch below might fix. Takashi diff -r aed6a15c9398 sound/usb/usbaudio.c --- a/sound/usb/usbaudio.c Mon Apr 23 11:54:41 2007 +0200 +++ b/sound/usb/usbaudio.c Mon Apr 23 12:09:12 2007 +0200 @@ -3611,6 +3611,7 @@ static void snd_usb_audio_disconnect(str list_for_each(p, &chip->mixer_list) { snd_usb_mixer_disconnect(p); } + chip->dev = NULL; mutex_unlock(®ister_mutex); snd_card_free_when_closed(card); } else {