Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp696966pxb; Tue, 5 Apr 2022 19:11:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSxSHbMpr1woOmpugD7qFOec0EDVByn3t85f7fj3VxDLyfVdB8pFPUbH8OTWUICvWkKISI X-Received: by 2002:a17:902:bf06:b0:156:af5b:e6c with SMTP id bi6-20020a170902bf0600b00156af5b0e6cmr6244297plb.147.1649211091028; Tue, 05 Apr 2022 19:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649211091; cv=none; d=google.com; s=arc-20160816; b=lKTRSWXj9g8QuefdbQzsx3R1TYcXTdF7UQdHSlhecmoMRgkprWxdl8cxKlxFQ4nhae OeBjclCTkPKTHq1A6aJ25BOtihAImKBD37tSs6W1ZeCqDNz6RQMbGiLAxWhPtxWanytu oD5MGphhd/HRI+AqNjA04I9ZSj2RBWBlmXz0w8LxjzR1CA4beIT8DoKGb6iM3DVJ4OZX DbVErXRKUI+EUveoVVZiNV3Y3SlWk3MPbDIPVDOA8Uz0Qz3zRwp8M3AX71zeMeahIbgq JMI30N3CoCHoWFq8H5vWMlclsKxKEd9fDe8yt/xwhh480IyC7BnMjdFoSuasm26+k+jv ofiw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=De2cuBL05V1ebKh5vK4WMsfXIGJclql9Z/02IaQej4U=; b=U6QOlXz29QowOdJe8y1Jpx1QTErX+FPAAqSsSl24bznvvoSYklckEQyWgaU++8X6+I VFveguY6VnBCvclR33QUVXGgGrsizIwYWWZQjDJfqGASV0tiHULnhzzAEBaE2sy/gNho 16CM2b94F7X1169ziYjCSZD+GNiQFOi7iA49XMlAloX+w8UkYLNJMxOJ8YAjtG3iWRbg vBmlG0B98Y+6sXOvydleJwlouTIb0Tx1QCT3f5BQD13qDkHfT+EW9K/FzrPfiNAAwY/h A6ctx5VHu99xqEomYJuiE1L6TwSL7N4XbSQqCLnpgBEhJQRW89uAqD5+q6dSKb1oPb4m 75GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TNzFMWzT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x17-20020a056a00189100b004fe50672865si826486pfh.124.2022.04.05.19.11.15; Tue, 05 Apr 2022 19:11:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TNzFMWzT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390573AbiDENmc (ORCPT + 99 others); Tue, 5 Apr 2022 09:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345133AbiDEJWS (ORCPT ); Tue, 5 Apr 2022 05:22:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C981AF33; Tue, 5 Apr 2022 02:09:10 -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 dfw.source.kernel.org (Postfix) with ESMTPS id CCC6261527; Tue, 5 Apr 2022 09:09:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD0B9C385A0; Tue, 5 Apr 2022 09:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149749; bh=SXDpUl53LOcvA7vl1vjJ+tv7O0zHMaTxiH6T79oerk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TNzFMWzTggSyFycs2rGopa3fidi+5BDWAzAnJT3ideUkZn+HpswQdl211kHb7CNw2 vAqX9+V2fAWKcPDwlSw4zU5GuKw5vLpXO7O5v0QxuieTkfHE3Rf57DqaVZLbBzpFsr WEL7cz2W53TauL89ol/QzzQvGSVsKW/v+tz/PDHs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Sergeyev , Takashi Iwai , Sasha Levin Subject: [PATCH 5.16 0826/1017] ALSA: hda: Fix driver index handling at re-binding Date: Tue, 5 Apr 2022 09:28:59 +0200 Message-Id: <20220405070418.764497965@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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