Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1765773pxb; Wed, 9 Feb 2022 04:08:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNQVZT7uq1Z9M2Thu3Ng0kiMc6Xn0zw5KqoWf2DtMdXu+ldXBWewtwCpnHms72hJnS1T1q X-Received: by 2002:a63:88c8:: with SMTP id l191mr530242pgd.460.1644408496386; Wed, 09 Feb 2022 04:08:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644408496; cv=none; d=google.com; s=arc-20160816; b=MmdMGlEmHHOy8TARrdSijufLX0GzBx3BFdv8VNEFQ1swNwySi/weQfTppFItoRw+7B +JXRvBCy6UR79/cDsADTA9s0qOfmHDB26rNfhSWwDzJPB0uq9re4EsvWv6l+BHD2JSCT FCecjiF4XDqW7eCuntp0bD8T1FXbqmxCsK9s7MeJCSbrx/NNe4u7jK+efscYr+9P70k7 gGJlpf4SPOv97dwit2J/LDfU2nRF5aWBTUn1+18fCUbbJsoavECFsruMY2gtzyL/RrUg 7Ws570SA1GiVHrab6VZvOWCkiNLFdnB4NE9niZfPp6heo+KaqFNReVjlZTF2PPnTRfQj BFbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=w7gtMUxuaQuez2p2NU0gwYSVzb8SS4pccG2VoclEwiU=; b=N5ErGLaii5ABCn1ztml5tIKysmnd1Qd8DDamzB+dcwP9KcVMN7DHAKPXmfj+ppZTC8 JzG1UiV1NiqVtR7Ty6uGG96umi/KIvXMScGtevXXyc/IXw4dAM0pvWAyJ886+yJPZ0ig +pkmDuBMFXkYDi60s/76sGg2lNp/CDh23tbDBpBN8+iJoSpyE2j3tZKLOaCbpruL0of4 hSJK0Txgtzs9akZkFDGiYTiUBfHv/6PZ4zFwF75xc7On3Afpsa1HyjH0Y3/d5yrGKhL7 f0zo2lafq+qV0PJ35aSvAGYUJrE1bTJobiTTnuIUXtfU0Og/mxtQyPEnhf/BCRDwBksk yUYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=r6Lri+jQ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u9si4745152ple.105.2022.02.09.04.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 04:08:16 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=r6Lri+jQ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3F6FAE0FD27B; Wed, 9 Feb 2022 02:07:11 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347994AbiBHOgM (ORCPT + 99 others); Tue, 8 Feb 2022 09:36:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbiBHOgK (ORCPT ); Tue, 8 Feb 2022 09:36:10 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6067C03FECE for ; Tue, 8 Feb 2022 06:36:09 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 7FE7D1F383; Tue, 8 Feb 2022 14:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1644330968; 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=w7gtMUxuaQuez2p2NU0gwYSVzb8SS4pccG2VoclEwiU=; b=r6Lri+jQ6r2ENsII3Twwv2v1c/rAfwZszxD5OD02T5ZJ4frY4hodngTm1x8GhLZ/qWuob6 h4ijemgWAIO0Fu0FK7k1qrxB/kkimN9/5zLbUnylqWd9ven3McXdZvoc3XIgTyq0JCR+hn EpP3EbNTkoAVysoxEaU67BOPLB92jiE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1644330968; 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=w7gtMUxuaQuez2p2NU0gwYSVzb8SS4pccG2VoclEwiU=; b=CRndj1fBDXkEUsIDlWAUljevzY4lcwsl2B7HIRc2Lbasoqci228NUdYBaH5n9DLDVJnq0T aApLS2vqaCg1r7Dw== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 37069A3B85; Tue, 8 Feb 2022 14:36:08 +0000 (UTC) Date: Tue, 08 Feb 2022 15:36:08 +0100 Message-ID: From: Takashi Iwai To: Alexander Sergeyev Cc: Jeremy Szu , tiwai@suse.com, "moderated list:SOUND" , Kailang Yang , open list , Huacai Chen , Jian-Hong Pan , Hui Wang , PeiSen Hou Subject: Re: [PATCH 1/4] ALSA: hda/realtek: fix mute/micmute LEDs for HP 855 G8 In-Reply-To: References: <20220114183720.n46wealclg6spxkp@localhost.localdomain> <20220115152215.kprws5nja2i43qax@localhost.localdomain> <20220119093249.eaxem33bjqjxcher@localhost.localdomain> <20220122190522.ycaygrqcen7d3hj2@localhost.localdomain> <20220122205637.7gzurdu7xl4sthxw@localhost.localdomain> <20220129144704.xlmeylllvy3b3fum@localhost.localdomain> <20220130111020.44gzrm5ckrakjta2@localhost.localdomain> 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 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 Signed-off-by: Takashi Iwai --- 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