public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Alexander Sergeyev <sergeev917@gmail.com>
Cc: Jeremy Szu <jeremy.szu@canonical.com>,
	tiwai@suse.com,
	"moderated list:SOUND" <alsa-devel@alsa-project.org>,
	Kailang Yang <kailang@realtek.com>,
	open list <linux-kernel@vger.kernel.org>,
	Huacai Chen <chenhuacai@kernel.org>,
	Jian-Hong Pan <jhp@endlessos.org>,
	Hui Wang <hui.wang@canonical.com>, PeiSen Hou <pshou@realtek.com>
Subject: Re: [PATCH 1/4] ALSA: hda/realtek: fix mute/micmute LEDs for HP 855 G8
Date: Tue, 08 Feb 2022 15:36:08 +0100	[thread overview]
Message-ID: <s5h4k59s9wn.wl-tiwai@suse.de> (raw)
In-Reply-To: <s5htudk9cn3.wl-tiwai@suse.de>

On Mon, 31 Jan 2022 15:57:04 +0100,
Takashi Iwai wrote:
> 
> On Sun, 30 Jan 2022 12:10:20 +0100,
> Alexander Sergeyev wrote:
> > What is also interesting, unbind & bind consistently fails on 31th bind:
> > 
> > echo -n '0000:05:00.6' > /sys/bus/pci/drivers/snd_hda_intel/bind
> > -bash: echo: write error: No such device
> > 
> > And does not recover from there until a reboot.
> 
> This is intended behavior.  The driver has a static device index that
> is incremented at each probe, so that the driver may probe multiple
> instances.  It'll be tricky to reset this for dynamic binding,
> though.  This problem is not only for HD-audio but for most of other
> drivers.  But I leave this as is for now, since the dynamic binding is
> rarely used for PCI and other buses, so far.

... and here is a fix patch for allowing more rebinds.
Give it a try.


Takashi

-- 8< --
From: Takashi Iwai <tiwai@suse.de>
Subject: [PATCH] ALSA: hda: Fix driver index handling at re-binding

HD-audio driver handles the multiple instances and keeps the static
index that is incremented at each probe.  This becomes a problem when
user tries to re-bind the device via sysfs multiple times; as the
device index isn't cleared unlike rmmod case, it points to the next
element at re-binding, and eventually later you can't probe any more
when it reaches to SNDRV_CARDS_MAX (usually 32).

This patch is an attempt to improve the handling at rebinding.
Instead of a static device index, now we keep a bitmap and assigns to
the first zero bit position.  At the driver remove, in return, the
bitmap slot is cleared again, so that it'll be available for the next
probe.

Reported-by: Alexander Sergeyev <sergeev917@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/hda/hda_intel.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 4b0338c4c543..a2922233e85f 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -2064,14 +2064,16 @@ 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)
 {
-	static int dev;
 	struct snd_card *card;
 	struct hda_intel *hda;
 	struct azx *chip;
 	bool schedule_probe;
+	int dev;
 	int err;
 
 	if (pci_match_id(driver_denylist, pci)) {
@@ -2079,10 +2081,11 @@ static int azx_probe(struct pci_dev *pci,
 		return -ENODEV;
 	}
 
+	dev = find_first_zero_bit(probed_devs, SNDRV_CARDS);
 	if (dev >= SNDRV_CARDS)
 		return -ENODEV;
 	if (!enable[dev]) {
-		dev++;
+		set_bit(dev, probed_devs);
 		return -ENOENT;
 	}
 
@@ -2149,7 +2152,7 @@ static int azx_probe(struct pci_dev *pci,
 	if (schedule_probe)
 		schedule_delayed_work(&hda->probe_work, 0);
 
-	dev++;
+	set_bit(dev, probed_devs);
 	if (chip->disabled)
 		complete_all(&hda->probe_wait);
 	return 0;
@@ -2372,6 +2375,7 @@ static void azx_remove(struct pci_dev *pci)
 		cancel_delayed_work_sync(&hda->probe_work);
 		device_lock(&pci->dev);
 
+		clear_bit(chip->dev_index, probed_devs);
 		pci_set_drvdata(pci, NULL);
 		snd_card_free(card);
 	}
-- 
2.34.1


  parent reply	other threads:[~2022-02-08 14:36 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-19 17:03 [PATCH 1/4] ALSA: hda/realtek: fix mute/micmute LEDs for HP 855 G8 Jeremy Szu
2021-05-19 17:03 ` [PATCH 2/4] ALSA: hda/realtek: fix mute/micmute LEDs and speaker for HP Zbook G8 Jeremy Szu
2021-05-19 17:03 ` [PATCH 3/4] ALSA: hda/realtek: fix mute/micmute LEDs and speaker for HP Zbook Fury 15 G8 Jeremy Szu
2021-05-19 17:03 ` [PATCH 4/4] ALSA: hda/realtek: fix mute/micmute LEDs and speaker for HP Zbook Fury 17 G8 Jeremy Szu
2021-05-27  2:00 ` [PATCH 1/4] ALSA: hda/realtek: fix mute/micmute LEDs for HP 855 G8 Jeremy Szu
2021-05-27  6:14   ` Takashi Iwai
2022-01-11 19:52 ` Alexander Sergeyev
2022-01-12  9:45   ` Takashi Iwai
2022-01-12 10:12     ` Alexander Sergeyev
2022-01-12 10:13       ` Takashi Iwai
2022-01-12 10:48         ` Alexander Sergeyev
2022-01-12 20:18           ` Alexander Sergeyev
2022-01-13  7:14             ` Takashi Iwai
2022-01-13 18:31               ` Alexander Sergeyev
2022-01-13 21:19                 ` Alexander Sergeyev
2022-01-14 16:37                 ` Takashi Iwai
2022-01-14 18:37                   ` Alexander Sergeyev
2022-01-15  7:55                     ` Takashi Iwai
2022-01-15 15:22                       ` Alexander Sergeyev
2022-01-19  9:12                         ` Takashi Iwai
2022-01-19  9:32                           ` Alexander Sergeyev
2022-01-22 19:05                             ` Alexander Sergeyev
2022-01-22 20:56                               ` Alexander Sergeyev
2022-01-26 15:24                                 ` Takashi Iwai
2022-01-29 14:47                                   ` Alexander Sergeyev
2022-01-30 11:10                                     ` Alexander Sergeyev
2022-01-31 14:57                                       ` Takashi Iwai
2022-02-05 15:00                                         ` Alexander Sergeyev
2022-02-05 17:51                                           ` Alexander Sergeyev
2022-02-07 14:21                                             ` Takashi Iwai
2022-02-08 19:49                                               ` Alexander Sergeyev
2022-02-08 14:36                                         ` Takashi Iwai [this message]
2022-02-08 19:52                                           ` Alexander Sergeyev

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=s5h4k59s9wn.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=chenhuacai@kernel.org \
    --cc=hui.wang@canonical.com \
    --cc=jeremy.szu@canonical.com \
    --cc=jhp@endlessos.org \
    --cc=kailang@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pshou@realtek.com \
    --cc=sergeev917@gmail.com \
    --cc=tiwai@suse.com \
    /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