Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2232296pxb; Wed, 30 Mar 2022 20:07:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwX5qATdfkqOstid/rsCpYeRVICYgBdkZHjuliXNMeUVkHPFrMvXq0TbZr06xXCGVaTlDPy X-Received: by 2002:a05:6a00:16d0:b0:4f6:f4b2:b1ca with SMTP id l16-20020a056a0016d000b004f6f4b2b1camr36539403pfc.46.1648696071514; Wed, 30 Mar 2022 20:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648696071; cv=none; d=google.com; s=arc-20160816; b=GgyQu+xtUCE220W2URKb8xp3bHhWo/v3h39MgClxbcHnCrPvkN8WjAXfOVoMNQD7yW IfzukCJ7FPFs7H+IqnuBp6/ahIO92RnbIgpxsXCvR8adNsSnpYu/0d8ghCFlZiFAWtDH E90aydfRUdP1FBlMvxNLVok2fjH84+LvNMvAq/kDSJKtfGedATEEnXXZncEaYUobczi8 CmmQffOyKnZtG9t6Plgj6rE6GWegXBke/rCdl2d/Hg7dUuoJN0c57UwVpHTwh/k+WO19 3arRocKRsTDKe3t035X9x+uaZ5XKBmHsIzFR+R5Nw4mwEkbE+PeWTtQiexxBSTtDg4/D m0MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=De2cuBL05V1ebKh5vK4WMsfXIGJclql9Z/02IaQej4U=; b=xg3IYhoEcefAo6Z2IazDsg6lO2+G+9eampt8QvKuyGfj/RZA18pWifxkTovoSNFZ5D g3R9/DcC2wgX+Su1gkndCAmXVRWU0gMsupYFTlW4zX3k2IM20no8e+7r8RfOtVqjjny7 7LgewtaWu3es3uv/NLz8rVkuk1yBwU6ppejqvZlj5fY3THZtAj+CAe1hVxGEnaFu2G75 yyJ0rjynwWcOBmgNrApcHqONF7wTdmg9BHHAdLMkH/RBOMJrle2jry58K7jC9Kr5GlMr YrhXdmMWfePBHz/yjur4MLR85VHIxz1efc6Bl6IgmiJkhwA4XmlrY9wrj0zbYg1UOWl5 +N7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kl++iMlz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u3-20020a170902e80300b00153b2d1641dsi2955990plg.37.2022.03.30.20.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 20:07:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kl++iMlz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 03C6EECC78; Wed, 30 Mar 2022 19:45:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242323AbiC3L7A (ORCPT + 99 others); Wed, 30 Mar 2022 07:59:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344587AbiC3LxS (ORCPT ); Wed, 30 Mar 2022 07:53:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F2B3264F50; Wed, 30 Mar 2022 04:49:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0099BB81C25; Wed, 30 Mar 2022 11:49:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2F6BC36AE2; Wed, 30 Mar 2022 11:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648640950; bh=SXDpUl53LOcvA7vl1vjJ+tv7O0zHMaTxiH6T79oerk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kl++iMlzQanbWuXliTryfv5p9W73Z2Jf1F5NnT9b9yRi/EbL1tIbs4PCOHY+i8l4R mJlcIFXHbU33qhybGe/05yrDTRC/SY18S/PQo4YzOQyX+NpBaUMed85pQvmb92oQii fpXd9iDbcYenyY1QPfKjuckSOfo9pW1wQaBWf1960qhZpBQCh2YIysyS+L7Qx4RQlE FxzcytBnzM9K3HUijD1Hh5yCze2xfL+x/8XmbE0t2SbhR73ST0zZ7JCASTvXR3VBpY FI0oQt4Q2nmaBTUdHN2uhMc0vGWHOrOkjwXxevX/trTIQkW0ct5w27vU2WchWVTGZE umzDqWgCvJ3VA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Takashi Iwai , Alexander Sergeyev , Sasha Levin , perex@perex.cz, tiwai@suse.com, gregkh@linuxfoundation.org, alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.16 24/59] ALSA: hda: Fix driver index handling at re-binding Date: Wed, 30 Mar 2022 07:47:56 -0400 Message-Id: <20220330114831.1670235-24-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330114831.1670235-1-sashal@kernel.org> References: <20220330114831.1670235-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Takashi Iwai [ Upstream commit 69458e2c27800da7697c87ed908b65323ef3f3bd ] 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 Link: https://lore.kernel.org/r/20220209081912.20687-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- 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 3b6f2aacda45..1ffd96fbf230 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -2061,14 +2061,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)) { @@ -2076,10 +2078,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; } @@ -2146,7 +2149,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; @@ -2369,6 +2372,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