From: Takashi Iwai Subject: Re: [PATCH 1/2] New virtual device snd_disconnected rc3 Date: Thu, 05 Oct 2006 16:13:45 +0200 Message-ID: References: <200610051253.46779.annabellesgarden@yahoo.de> <200610051552.37812.annabellesgarden@yahoo.de> <200610051554.48027.annabellesgarden@yahoo.de> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <200610051554.48027.annabellesgarden@yahoo.de> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@lists.sourceforge.net Errors-To: alsa-devel-bounces@lists.sourceforge.net To: Karsten Wiese Cc: alsa-devel@lists.sourceforge.net, Jaroslav Kysela List-Id: alsa-devel@alsa-project.org At Thu, 5 Oct 2006 15:54:47 +0200, Karsten Wiese wrote: > > snd_disconnected_file, virtual device > > On response to "usb disconnect" an usb-soundcard manipulates > that snd_card's file's f_ops to only allow release > by calling this virtual device's > void snd_disconnect_file(struct file *file). > After release is actually called, the virtual device instance is freed. > > Signed-off-by: Karsten Wiese Thanks, the code looks better. > +void snd_disconnect_file(struct file *file) > +{ > + struct snd_disconnected_file *df; > + df = kmalloc(sizeof(struct snd_disconnected_file), GFP_KERNEL); > + if (df == NULL) > + panic("Atomic allocation failed for snd_disconnected_file!"); The message doesn't match... Some people prefer "if (!df)" although I myself don't mind at all. > + > + df->file = file; > + df->f_op = file->f_op; > + > + mutex_lock(&mutex); > + list_add(&df->list, &disconnected_files); > + mutex_unlock(&mutex); > + > + fops_get(&snd_disconnect_f_ops); > + file->f_op = &snd_disconnect_f_ops; > + printk(KERN_INFO "%s rc3\n", __FUNCTION__); This will be removed in the final version, right? > +} My only concern is whether the release of the old f_op can be called at the same time during snd_disconnect_file(). If this can happen, it's racy and results in a memory leak. Could you check whether this scenario could be true? For example, insert ssleep(10) after kmalloc so that you have a chance to close the app manually during disconnect is called. Mmaybe better to add a debug printk in the original release f_ops, too. Takashi ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV