Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5580028ybl; Tue, 10 Dec 2019 08:14:33 -0800 (PST) X-Google-Smtp-Source: APXvYqzlRF3lUy3jEL5iJvfNw4b0e/SsbzJgrIALpE5GPkt1AfOs1mhgs6aZiX3zlmIoVcg8+kpg X-Received: by 2002:aca:554d:: with SMTP id j74mr4785512oib.92.1575994473706; Tue, 10 Dec 2019 08:14:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575994473; cv=none; d=google.com; s=arc-20160816; b=jkYqW1sGof7RktXJ2QbzOGD+sHpRB9pRI9lbTN7+lo+GnqKYFZlA3GaLkmbLMvRBxN RxlI4iYAIRATUit1k5XP7WI255tdiDQDkqwlqxMQVUVILXx/svjFRL8z9EW1EK0uP/rK gKqpMdCEM2D0ss4+Utdo+W8S5ia9PwLN5c9b6Y19vaPsSPsWG6g4fx+dLMUVxowMK7rE itHz4b1SnHb7zX5So72jlzqtdhKz79d1PoO33wckonekjOxOw3QdElx8ZaTuy4e4ofBF oTFeZI68rZLVUif+QUilp/2r+61FqjiFildoyvClUsA2QuF7i3LA2I611Yin0B69cczj SQfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=mtOhS5OzRGcWHnPx3RKVOcZP6YtqcJNuorDCRqtpqVU=; b=G8IRklXve4/ISIgzdiEy2xZM/KDzvPhcEB2rBC6RUnPgacMvUZHDiISQH51LmGBRRJ y4Q0dOOYItbPy1KkGosFfAek6KfoMO2Cumf2qadcqIv+gJ6wRLAItXK2uVCfD7PMKfzT eSqShxMAJFCcWBoPwuD12NxWO1fkcdj+wBwprbJIKU8kMVLi9Oh+DWqIExFKRTv4U0bz aTLkz/6kNCBg3/uzDh4rWk8SvzxrZZv5EHkiELlR3qdxqxKibh1wnoHRDBF7sxlcgsSR XVYca/OHhoZAx+jL6mnYb+rB+rz7XezJ9w5PFoPEmBXaeQQiQ3Vdf6V1Ej4+G0Gdv3TN IwYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a26si1979571oto.199.2019.12.10.08.14.21; Tue, 10 Dec 2019 08:14:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727574AbfLJQNt (ORCPT + 99 others); Tue, 10 Dec 2019 11:13:49 -0500 Received: from bmailout2.hostsharing.net ([83.223.78.240]:44599 "EHLO bmailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727436AbfLJQNr (ORCPT ); Tue, 10 Dec 2019 11:13:47 -0500 Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 1C60C28022E40; Tue, 10 Dec 2019 17:13:46 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id D7EF5CD0; Tue, 10 Dec 2019 17:13:45 +0100 (CET) Date: Tue, 10 Dec 2019 17:13:45 +0100 From: Lukas Wunner To: "Deucher, Alexander" Cc: Takashi Iwai , Jaroslav Kysela , Mika Westerberg , Bjorn Helgaas , Nicholas Johnson , "alsa-devel@alsa-project.org" , "linux-kernel@vger.kernel.org" , "linux-pci@vger.kernel.org" Subject: Re: [PATCH] ALSA: hda/hdmi - Fix duplicate unref of pci_dev Message-ID: <20191210161345.apz4aixgszcd6vco@wunner.de> References: <77aa6c01aefe1ebc4004e87b0bc714f2759f15c4.1575985006.git.lukas@wunner.de> <20191210154649.o3vsqzrtofhvcjrl@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 10, 2019 at 03:53:20PM +0000, Deucher, Alexander wrote: > > On Tue, Dec 10, 2019 at 03:34:27PM +0000, Deucher, Alexander wrote: > > > > Nicholas Johnson reports a null pointer deref as well as a refcount > > > > underflow upon hot-removal of a Thunderbolt-attached AMD eGPU. > > > > He's bisected the issue down to commit 586bc4aab878 ("ALSA: hda/hdmi > > > > - fix vgaswitcheroo detection for AMD"). > > > > > > > > The commit iterates over PCI devices using pci_get_class() and > > > > unreferences each device found, even though pci_get_class() > > > > subsequently unreferences the device as well. Fix it. > > > > > > The pci_dev_put() a few lines above should probably be dropped as well. > > > > That one looks fine to me. The refcount is already increased in the caller > > get_bound_vga() via pci_get_domain_bus_and_slot() and it's increased > > again in atpx_present() via pci_get_class(). It needs to be decremented in > > atpx_present() to avoid leaking a ref. > > I'm not following. This is part of the same loop as the one you removed. > All we are doing is checking whether the ATPX method exists or not om the > platform. The pdev may not be the same one as the one in > pci_get_domain_bus_and_slot(). The APTX method in the APU's ACPI namespace, > not the dGPUs. Okay. Still, atpx_present() doesn't pass the found pci_dev back to the caller, so it would be leaked if the ref isn't returned. The situation is different for the pci_dev_put() I removed: The ref is returned by pci_get_class() on the next loop iteration. Thanks, Lukas > > > > diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c > > > > index 35b4526f0d28..b856b89378ac 100644 > > > > --- a/sound/pci/hda/hda_intel.c > > > > +++ b/sound/pci/hda/hda_intel.c > > > > @@ -1419,7 +1419,6 @@ static bool atpx_present(void) > > > > return true; > > > > } > > > > } > > > > - pci_dev_put(pdev); > > > > } > > > > return false; > > > > } > > > > -- > > > > 2.24.0