From patchwork Tue Jul 18 11:57:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13317103 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5BFD6EB64DC for ; Tue, 18 Jul 2023 12:21:58 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 600D8AEA; Tue, 18 Jul 2023 14:21:06 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 600D8AEA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1689682916; bh=Ri0zfK2hY4L0jOIG1zMaup7ETnipgavpYVEb/UyrYGw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=KUnZ9beUIbkfFSAy16sQbVBoPGPjH3a2sUlKgPLvh+dUM9wAjovMVY5x+29k3LLnx LZtulSp+6K9wZXPIdklMyMpNd8Ntpd5c1ZuIkqP5+jO6u6C5PZ//yhK2RW6knBLsKk 8vnYQsS0r8vmEtuu/AeUL/ZdJ2efihEtf3dz8HEg= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 38B6FF80527; Tue, 18 Jul 2023 14:20:40 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id D22B2F800D2; Tue, 18 Jul 2023 14:20:39 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id DAFA7F8032D; Tue, 18 Jul 2023 13:57:44 +0200 (CEST) Received: from mblankhorst.nl (lankhorst.se [IPv6:2a02:2308:0:7ec:e79c:4e97:b6c4:f0ae]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 62E0EF80153; Tue, 18 Jul 2023 13:57:37 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 62E0EF80153 Message-ID: <2a727311-46d8-e999-1461-2ed2f1b704e0@linux.intel.com> Date: Tue, 18 Jul 2023 13:57:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: [v2 PATCH 1/2] ALSA: hda/intel: Fix error handling in azx_probe() To: Takashi Iwai Cc: alsa-devel@alsa-project.org, sound-open-firmware@alsa-project.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Takashi Iwai , Cezary Rojewski , Pierre-Louis Bossart , Liam Girdwood , Peter Ujfalusi , Bard Liao , Ranjani Sridharan , Kai Vehmanen , Mark Brown , Daniel Baluta References: <20230718084522.116952-1-maarten.lankhorst@linux.intel.com> <20230718084522.116952-6-maarten.lankhorst@linux.intel.com> <87h6q1o82l.wl-tiwai@suse.de> Content-Language: en-US From: Maarten Lankhorst In-Reply-To: <87h6q1o82l.wl-tiwai@suse.de> X-MailFrom: maarten.lankhorst@linux.intel.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1 Message-ID-Hash: 7M4626CXOGU7WT4G3ASP3WE3K4PL6MEA X-Message-ID-Hash: 7M4626CXOGU7WT4G3ASP3WE3K4PL6MEA X-Mailman-Approved-At: Tue, 18 Jul 2023 12:20:35 +0000 X-Content-Filtered-By: Mailman/MimeDel 3.3.8 X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hey, On 2023-07-18 11:57, Takashi Iwai wrote: > On Tue, 18 Jul 2023 10:45:20 +0200, > Maarten Lankhorst wrote: >> Now that we can use -EPROBE_DEFER, it's no longer required to spin off >> the snd_hdac_i915_init into a workqueue. >> >> Use the -EPROBE_DEFER mechanism instead, which must be returned in the >> probe function. >> >> Signed-off-by: Maarten Lankhorst >> --- >> sound/pci/hda/hda_intel.c | 58 +++++++++++++++++++++------------------ >> 1 file changed, 31 insertions(+), 27 deletions(-) >> >> diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c >> index 5af1138e745bc..d40345a0088d8 100644 >> --- a/sound/pci/hda/hda_intel.c >> +++ b/sound/pci/hda/hda_intel.c >> @@ -213,6 +213,7 @@ MODULE_DESCRIPTION("Intel HDA driver"); >> #endif >> #endif >> >> +static DECLARE_BITMAP(probed_devs, SNDRV_CARDS); >> >> /* >> */ >> @@ -2094,8 +2095,6 @@ static const struct hda_controller_ops pci_hda_ops = { >> .position_check = azx_position_check, >> }; >> >> -static DECLARE_BITMAP(probed_devs, SNDRV_CARDS); >> - >> static int azx_probe(struct pci_dev *pci, >> const struct pci_device_id *pci_id) >> { > Any specific reason to move the definition? Otherwise let's > concentrate on the needed change. Originally I moved the chunk to azx_create(), but I felt it was the wrong place. Fixed now. > >> @@ -2174,7 +2173,36 @@ static int azx_probe(struct pci_dev *pci, >> } >> #endif /* CONFIG_SND_HDA_PATCH_LOADER */ >> >> -#ifndef CONFIG_SND_HDA_I915 >> +#ifdef CONFIG_SND_HDA_I915 >> + /* bind with i915 if needed */ >> + if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) { >> + err = snd_hdac_i915_init(azx_bus(chip), false); >> + if (err < 0) { >> + /* if the controller is bound only with HDMI/DP >> + * (for HSW and BDW), we need to abort the probe; >> + * for other chips, still continue probing as other >> + * codecs can be on the same link. >> + */ >> + if (CONTROLLER_IN_GPU(pci)) { >> + if (err != -EPROBE_DEFER) >> + dev_err(card->dev, >> + "HSW/BDW HD-audio HDMI/DP requires binding with gfx driver\n"); >> + >> + clear_bit(chip->dev_index, probed_devs); >> + pci_set_drvdata(pci, NULL); >> + snd_device_free(card, chip); >> + return err; > This may leak resources, I'm afraid. > > Here you just need to "goto out_free;" instead of manual resource > releases, which eventually calls snd_card_free(), and that's all. > > (Though, pci_set_drvdata(pci, NULL) might be still missing; but it's > not only for this change, and we'll need to address it in another > patch.) git am --scissors patch below for cleanup of error path. It seems azx_free will unregister from vga_switcheroo safely. ------------>8--- Make sure azx is freed after azx_create() succeeded and an error was encountered. Signed-off-by: Maarten Lankhorst --- sound/pci/hda/hda_intel.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 5af1138e745bc..196ca76ac43ad 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -2150,7 +2150,7 @@ static int azx_probe(struct pci_dev *pci, err = register_vga_switcheroo(chip); if (err < 0) { dev_err(card->dev, "Error registering vga_switcheroo client\n"); - goto out_free; + goto out_azx_free; } if (check_hdmi_disabled(pci)) { @@ -2169,7 +2169,7 @@ static int azx_probe(struct pci_dev *pci, &pci->dev, GFP_KERNEL, card, azx_firmware_cb); if (err < 0) - goto out_free; + goto out_azx_free; schedule_probe = false; /* continued in azx_firmware_cb() */ } #endif /* CONFIG_SND_HDA_PATCH_LOADER */ @@ -2187,6 +2187,9 @@ static int azx_probe(struct pci_dev *pci, complete_all(&hda->probe_wait); return 0; +out_azx_free: + azx_free(chip); + pci_set_drvdata(pci, NULL); out_free: snd_card_free(card); return err;