Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp558204ybz; Fri, 24 Apr 2020 05:24:42 -0700 (PDT) X-Google-Smtp-Source: APiQypLCNyJZemF8h9y8ZyW5vl/f56m9VOaGJQdyFoFMIG6x/EDSkfUmt7QyKnpQun6HcZEp6h3K X-Received: by 2002:a05:6402:1cac:: with SMTP id cz12mr6651426edb.373.1587731082127; Fri, 24 Apr 2020 05:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587731082; cv=none; d=google.com; s=arc-20160816; b=sOMqNQn33/LT7S/jHilEYaGdPdjZcxNg7Fc53JNUElUqdRjIR1bBJFhvgOEBG0BNOQ Pc7BDkqENr6UbK7li6Nw5i2Xniw0oZP7eAAYtvRlig0D4W2OyTzgg3ItezDNJq64rqT/ TtYBLvbx8QScoC6l6PJ0tTCEFCabYUhuO6UbHahXS1YEmHg9PfJ+75RrES4mxxzXcf3q mialG7VIlKvLG5JOb2CMHmKXfuNyFaCNayOpVhU12P/9ePHFeTuo04mfeurv3N+l+XIA WG6Y0ryQEqp2BHieCr8pd0stLiQSCb+MXoaZKhUOdZ8s9MgEW7jOEbq7cbMFlYzGBe3n u3bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cIjbN0tpgYe4IPh9FyjNEm8u0ZJJjUU8ckXvT5WOZkc=; b=pVouI4yDwzEIQr/BKctminEtnvHnJroE0GR5qoDQZSEis5OXw9Sc6tJkGrZ+JzcxXV qM8AOBJSNaDC7314IWA55lwnM/XyzD4J6U2qv5xouDizbKfGvOvrVdIUCmmxA8rb7YIC JIrpqRBGpBK4oIrT6mIEn1PNJlxc/WMD8CX1Oassu03A7juI2oJ+Xq74EAnibNaRlhuj 0APelnGFO790BvsYtNYDshE8uagpjq4Ldwn2PYCTD1BUQDwowtQMFi6SWUma4S+/qIcY KuGyGEP/m/gV/q2OxLISMKq6QIiDhknhC0XZk5vrWbQYdvcqcJZtiOX9sK3UZsEYAz+d O3Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JgUdaEJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h59si2978210edc.222.2020.04.24.05.24.18; Fri, 24 Apr 2020 05:24:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JgUdaEJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727096AbgDXMWw (ORCPT + 99 others); Fri, 24 Apr 2020 08:22:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:52028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbgDXMWt (ORCPT ); Fri, 24 Apr 2020 08:22:49 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 64E9B20776; Fri, 24 Apr 2020 12:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587730969; bh=IEy7Kjr9+UyETMpmsFP7167uF2IVWAuDrab38EHG1CA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JgUdaEJbxfb7mxDPBFKq41xK+EVKV0nHXWI0ZICSMfNSFP4EgyfY+sUGkqQJ7s7Q2 91rV0sM0TNxWFrjA7V15AoZd5C12i2bKbxueoHdsn8zN9zolzTHOklrMA2ZdoFp6aK BN1Juzg+84RltCa1wVwxx6wmkA4iG2oQsZuWtU6Q= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Takashi Iwai , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.6 10/38] ALSA: hda: Release resources at error in delayed probe Date: Fri, 24 Apr 2020 08:22:08 -0400 Message-Id: <20200424122237.9831-10-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200424122237.9831-1-sashal@kernel.org> References: <20200424122237.9831-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit 2393e7555b531a534152ffe7bfd1862cacedaacb ] snd-hda-intel driver handles the most of its probe task in the delayed work (either via workqueue or via firmware loader). When an error happens in the later delayed probe, we can't deregister the device itself because the probe callback already returned success and the device was bound. So, for now, we set hda->init_failed flag and make the rest untouched until the device gets really unbound. However, this leaves the device up running, keeping the resources without any use that prevents other operations. In this patch, we release the resources at first when a probe error happens in the delayed probe stage, but keeps the top-level object, so that the PM and other ops can still refer to the object itself. Also for simplicity, snd_hda_intel object is allocated via devm, so that we can get rid of the explicit kfree calls. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=207043 Link: https://lore.kernel.org/r/20200413082034.25166-4-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/pci/hda/hda_intel.c | 29 ++++++++++++++++------------- sound/pci/hda/hda_intel.h | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index f41d8b7864c1e..692857904d49e 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1203,10 +1203,8 @@ static void azx_vs_set_state(struct pci_dev *pci, if (!disabled) { dev_info(chip->card->dev, "Start delayed initialization\n"); - if (azx_probe_continue(chip) < 0) { + if (azx_probe_continue(chip) < 0) dev_err(chip->card->dev, "initialization error\n"); - hda->init_failed = true; - } } } else { dev_info(chip->card->dev, "%s via vga_switcheroo\n", @@ -1339,12 +1337,15 @@ static int register_vga_switcheroo(struct azx *chip) /* * destructor */ -static int azx_free(struct azx *chip) +static void azx_free(struct azx *chip) { struct pci_dev *pci = chip->pci; struct hda_intel *hda = container_of(chip, struct hda_intel, chip); struct hdac_bus *bus = azx_bus(chip); + if (hda->freed) + return; + if (azx_has_pm_runtime(chip) && chip->running) pm_runtime_get_noresume(&pci->dev); chip->running = 0; @@ -1388,9 +1389,8 @@ static int azx_free(struct azx *chip) if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) snd_hdac_i915_exit(bus); - kfree(hda); - return 0; + hda->freed = 1; } static int azx_dev_disconnect(struct snd_device *device) @@ -1406,7 +1406,8 @@ static int azx_dev_disconnect(struct snd_device *device) static int azx_dev_free(struct snd_device *device) { - return azx_free(device->device_data); + azx_free(device->device_data); + return 0; } #ifdef SUPPORT_VGA_SWITCHEROO @@ -1773,7 +1774,7 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci, if (err < 0) return err; - hda = kzalloc(sizeof(*hda), GFP_KERNEL); + hda = devm_kzalloc(&pci->dev, sizeof(*hda), GFP_KERNEL); if (!hda) { pci_disable_device(pci); return -ENOMEM; @@ -1814,7 +1815,6 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci, err = azx_bus_init(chip, model[dev]); if (err < 0) { - kfree(hda); pci_disable_device(pci); return err; } @@ -2340,13 +2340,16 @@ static int azx_probe_continue(struct azx *chip) pm_runtime_put_autosuspend(&pci->dev); out_free: - if (err < 0 || !hda->need_i915_power) + if (err < 0) { + azx_free(chip); + return err; + } + + if (!hda->need_i915_power) display_power(chip, false); - if (err < 0) - hda->init_failed = 1; complete_all(&hda->probe_wait); to_hda_bus(bus)->bus_probing = 0; - return err; + return 0; } static void azx_remove(struct pci_dev *pci) diff --git a/sound/pci/hda/hda_intel.h b/sound/pci/hda/hda_intel.h index 2acfff3da1a04..3fb119f090408 100644 --- a/sound/pci/hda/hda_intel.h +++ b/sound/pci/hda/hda_intel.h @@ -27,6 +27,7 @@ struct hda_intel { unsigned int use_vga_switcheroo:1; unsigned int vga_switcheroo_registered:1; unsigned int init_failed:1; /* delayed init failed */ + unsigned int freed:1; /* resources already released */ bool need_i915_power:1; /* the hda controller needs i915 power */ }; -- 2.20.1