From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Takashi Iwai <tiwai@suse.de>, Sasha Levin <sashal@kernel.org>,
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 [thread overview]
Message-ID: <20200424122237.9831-10-sashal@kernel.org> (raw)
In-Reply-To: <20200424122237.9831-1-sashal@kernel.org>
From: Takashi Iwai <tiwai@suse.de>
[ 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 <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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
next prev parent reply other threads:[~2020-04-24 12:32 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-24 12:21 [PATCH AUTOSEL 5.6 01/38] libbpf: Initialize *nl_pid so gcc 10 is happy Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 02/38] net: fec: set GPR bit on suspend by DT configuration Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 03/38] x86: hyperv: report value of misc_features Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 04/38] signal: check sig before setting info in kill_pid_usb_asyncio Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 05/38] hwmon: (drivetemp) Use drivetemp's true module name in Kconfig section Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 06/38] hwmon: (drivetemp) Return -ENODATA for invalid temperatures Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 07/38] afs: Fix length of dump of bad YFSFetchStatus record Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 08/38] xfs: acquire superblock freeze protection on eofblocks scans Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 09/38] xfs: fix partially uninitialized structure in xfs_reflink_remap_extent Sasha Levin
2020-04-24 12:22 ` Sasha Levin [this message]
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 11/38] ALSA: hda: Keep the controller initialization even if no codecs found Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 12/38] ALSA: hda: Skip controller resume if not needed Sasha Levin
2020-04-24 12:44 ` Takashi Iwai
2020-04-30 22:36 ` Roy Spliet
2020-05-01 1:17 ` Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 13/38] ALSA: hda: Explicitly permit using autosuspend if runtime PM is supported Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 14/38] drm/amdgpu: fix wrong vram lost counter increment V2 Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 15/38] scsi: target: fix PR IN / READ FULL STATUS for FC Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 16/38] scsi: target: tcmu: reset_ring should reset TCMU_DEV_BIT_BROKEN Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 17/38] clk: asm9260: fix __clk_hw_register_fixed_rate_with_accuracy typo Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 18/38] efi/x86: Don't remap text<->rodata gap read-only for mixed mode Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 19/38] objtool: Fix CONFIG_UBSAN_TRAP unreachable warnings Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 20/38] objtool: Support Clang non-section symbols in ORC dump Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 21/38] xen/xenbus: ensure xenbus_map_ring_valloc() returns proper grant status Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 22/38] ALSA: hda: call runtime_allow() for all hda controllers Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 23/38] net: stmmac: socfpga: Allow all RGMII modes Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 24/38] net/cxgb4: Check the return from t4_query_params properly Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 25/38] mac80211: fix channel switch trigger from unknown mesh peer Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 26/38] sched/isolation: Allow "isolcpus=" to skip unknown sub-parameters Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 27/38] sched/vtime: Work around an unitialized variable warning Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 28/38] i2c: remove i2c_new_probed_device API Sasha Levin
2020-04-24 13:36 ` Wolfram Sang
2020-04-25 1:51 ` Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 29/38] arm64: Delete the space separator in __emit_inst Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 30/38] i2c: tegra: Better handle case where CPU0 is busy for a long time Sasha Levin
2020-04-27 7:22 ` Thierry Reding
2020-05-01 0:59 ` Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 31/38] i2c: tegra: Synchronize DMA before termination Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 32/38] ext4: use matching invalidatepage in ext4_writepage Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 33/38] ext4: increase wait time needed before reuse of deleted inode numbers Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 34/38] ext4: convert BUG_ON's to WARN_ON's in mballoc.c Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 35/38] irqchip/gic-v4.1: Add support for VPENDBASER's Dirty+Valid signaling Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 36/38] blk-mq: Put driver tag in blk_mq_dispatch_rq_list() when no budget Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 37/38] irqchip/meson-gpio: Fix HARDIRQ-safe -> HARDIRQ-unsafe lock order Sasha Levin
2020-04-24 12:22 ` [PATCH AUTOSEL 5.6 38/38] hwmon: (jc42) Fix name to have no illegal characters Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200424122237.9831-10-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=alsa-devel@alsa-project.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).