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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EEDAC433EF for ; Mon, 11 Apr 2022 15:14:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347632AbiDKPQg (ORCPT ); Mon, 11 Apr 2022 11:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347695AbiDKPQc (ORCPT ); Mon, 11 Apr 2022 11:16:32 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69DFF286F1 for ; Mon, 11 Apr 2022 08:14:17 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 2911B1F868; Mon, 11 Apr 2022 15:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1649690056; 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=bYyWuGBryhvqK2tsPLce9K8YGWCuvS5YA97DnFXA4Z8=; b=EauwTN4nsydagFeq6dRvkTovp3T+iJeKjfWWLPB6kqn3RvRNzAhMINqdCoikctMJ2EzpwO 2FG4AvhFn/Y0LkFe+5Imi5KITnk6UiLnRd+Uq4WoQzxWYaVfc+mL9kBJrYAJx4m8Vs+jYu G4BU/YQRPxzbk7oHSoCSmxYX9A6HqvI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1649690056; 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=bYyWuGBryhvqK2tsPLce9K8YGWCuvS5YA97DnFXA4Z8=; b=xhTEJM/zWjjSSmzCpVfvZD/zwYMgUfpSvsPpbyUpg1vE8Hf5vY2rb8BKhGJWANFeG/CWid po07yp1ifha5nEBw== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 0E4EFA3B9C; Mon, 11 Apr 2022 15:14:16 +0000 (UTC) Date: Mon, 11 Apr 2022 17:14:16 +0200 Message-ID: From: Takashi Iwai To: Zheyu Ma Cc: perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, Linux Kernel Mailing List Subject: Re: [BUG] ALSA: echoaudio: warning when the driver fails to probe In-Reply-To: References: 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 11 Apr 2022 12:34:56 +0200, Zheyu Ma wrote: > > On Mon, Apr 11, 2022 at 6:30 PM Takashi Iwai wrote: > > > > On Mon, 11 Apr 2022 11:15:41 +0200, > > Takashi Iwai wrote: > > > > > > On Mon, 11 Apr 2022 11:06:09 +0200, > > > Takashi Iwai wrote: > > > > > > > > On Mon, 11 Apr 2022 10:49:53 +0200, > > > > Zheyu Ma wrote: > > > > > > > > > > On Mon, Apr 11, 2022 at 3:41 PM Takashi Iwai wrote: > > > > > > > > > > > > On Sun, 10 Apr 2022 11:13:55 +0200, > > > > > > Zheyu Ma wrote: > > > > > > > > > > > > > > Hello, > > > > > > > > > > > > > > I found a bug in echoaudio.c. > > > > > > > When the driver fails at the function snd_echo_create(), it should > > > > > > > release resources requested before, otherwise we will get the > > > > > > > following warning: > > > > > > > > > > > > > > [ 3.262866] remove_proc_entry: removing non-empty directory > > > > > > > 'irq/21', leaking at least 'snd_indigodj' > > > > > > > [ 3.263577] WARNING: CPU: 3 PID: 261 at fs/proc/generic.c:717 > > > > > > > remove_proc_entry+0x389/0x3f0 > > > > > > > [ 3.267098] RIP: 0010:remove_proc_entry+0x389/0x3f0 > > > > > > > [ 3.269976] Call Trace: > > > > > > > [ 3.269979] > > > > > > > [ 3.269988] unregister_irq_proc+0x14c/0x170 > > > > > > > [ 3.269997] irq_free_descs+0x94/0xe0 > > > > > > > [ 3.270004] mp_unmap_irq+0xb6/0x100 > > > > > > > [ 3.270011] acpi_unregister_gsi_ioapic+0x27/0x40 > > > > > > > [ 3.270017] acpi_pci_irq_disable+0x1d3/0x320 > > > > > > > [ 3.270025] pci_disable_device+0x1ad/0x380 > > > > > > > [ 3.270034] pcim_release+0x566/0x6d0 > > > > > > > [ 3.270046] devres_release_all+0x1f1/0x2c0 > > > > > > > [ 3.270057] really_probe+0xe0/0x920 > > > > > > > > > > > > Could you try the patch below? > > > > > > > > > > The following patch works for me, the previous warning disappears, thank you. > > > > > But I got another error, I have no idea about it. > > > > > > > > OK, that's bad, it's basically the destructor order problem. > > > > Could you try the patch below instead of the previous one? > > > > > > Sorry, the below one instead. > > > > Err, scratch this one, too. It's a deeper problem than I thought. > > Will post a revised patch later. > > Yeah, you are right, these two patches do not work, I got the same > error message. > Thanks for your effort. Here we go, a revised patch. Basically it enforces the call of snd_card_free() at the error path during probe. There are a bunch of similar patterns, and we need to address them all... thanks, Takashi --- --- a/include/sound/core.h +++ b/include/sound/core.h @@ -279,6 +279,7 @@ int snd_card_new(struct device *parent, int idx, const char *xid, int snd_devm_card_new(struct device *parent, int idx, const char *xid, struct module *module, size_t extra_size, struct snd_card **card_ret); +int snd_devm_probe_or_release(struct device *dev, int ret); int snd_card_disconnect(struct snd_card *card); void snd_card_disconnect_sync(struct snd_card *card); --- a/sound/core/init.c +++ b/sound/core/init.c @@ -235,6 +235,19 @@ int snd_devm_card_new(struct device *parent, int idx, const char *xid, } EXPORT_SYMBOL_GPL(snd_devm_card_new); +int snd_devm_probe_or_release(struct device *dev, int ret) +{ + struct snd_card *card; + + if (!ret) + return 0; + card = devres_find(dev, __snd_card_release, NULL, NULL); + if (card) + snd_card_free(card); + return ret; +} +EXPORT_SYMBOL_GPL(snd_devm_probe_or_release); + static int snd_card_init(struct snd_card *card, struct device *parent, int idx, const char *xid, struct module *module, size_t extra_size) --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c @@ -1970,8 +1970,8 @@ static int snd_echo_create(struct snd_card *card, } /* constructor */ -static int snd_echo_probe(struct pci_dev *pci, - const struct pci_device_id *pci_id) +static int __snd_echo_probe(struct pci_dev *pci, + const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; @@ -2139,6 +2139,12 @@ static int snd_echo_probe(struct pci_dev *pci, return 0; } +static int snd_echo_probe(struct pci_dev *pci, + const struct pci_device_id *pci_id) +{ + return snd_devm_probe_or_release(&pci->dev, + __snd_echo_probe(pci, pci_id)); +} #if defined(CONFIG_PM_SLEEP)