Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5576345ybl; Tue, 10 Dec 2019 08:11:34 -0800 (PST) X-Google-Smtp-Source: APXvYqwSc6r4a8KoqHeNHQcK4ED/NDBf//Uj3DvlsHEZoyrHYK/uXwRB+HJ2h56PkdLKOr1kZAWe X-Received: by 2002:a05:6808:ab1:: with SMTP id r17mr4323331oij.141.1575994293974; Tue, 10 Dec 2019 08:11:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575994293; cv=none; d=google.com; s=arc-20160816; b=hNTNWfIPsPvhQ0EPUbefdUPLPHqZl6GUYfkKj5alzdIQ29IbU6/+daaVQUlmPH7oTh VDoJOplWWVPn/YlSqWrzBmJj/xMoLAEs2yFnRdZAgJGzpEfv131KnoCXVDwyu7VB/Lwl 7WMFJrXN33zwjXZY/3rOSJx6dkqqYNpsjB8v1329EZRqqsFU5TmitAt9dfqQqLFqMSyO ME06Ba6WQCSE0tnFdklL2eMlTPbP8m0uPZeMIUwsKsT6WNy8XUKsnkwWLePc6fvIL4Tt V+MMejgbgtEG6Hpp4aQzUT8VOZwjzqwKeWvOF122vfFECMSfU+kdXUmTK/IQjz6L+Iiv C/0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=B+bWHV5ZXPkT/YJUYGVT+PVUesb3KwyYrn1lcrNY8Ms=; b=KmUFLZQ6I/aybpjIEZm++FkPUDU+G5HD+qI/mbKwRWu7lED+M7HCw1XofEeJE1Hasn CwpBeiyKWfPeH6skqITzCrmDLsZdg6bBXmk6H/NtJQocaIFf+rLG5kNhY1r1t3w01kfV nhjlYWdDoOWI9Td8YNCROXIZIt2c1CBYi6e6jiN2ksyGXSfADIQE4/wrta3eNWF5RsDf N6BytyuoIfV54bGY3XxsIcfrbNOxcwiZdNWsG41XkAiZEY+RqEhuWOad42hhqcwQUozS kLX41cpM7O29HkEoJrg2/xC6cnbXKqFkCeqb94MAGjOCeohAGckNyiAXKr5H8mEE6DWD /Epw== 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 q6si2635532otg.248.2019.12.10.08.11.19; Tue, 10 Dec 2019 08:11: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 S1727566AbfLJQKp (ORCPT + 99 others); Tue, 10 Dec 2019 11:10:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:34166 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727178AbfLJQKp (ORCPT ); Tue, 10 Dec 2019 11:10:45 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CF0E5B089; Tue, 10 Dec 2019 16:10:41 +0000 (UTC) Date: Tue, 10 Dec 2019 17:10:40 +0100 Message-ID: From: Takashi Iwai To: "Deucher, Alexander" Cc: Lukas Wunner , 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 In-Reply-To: References: <77aa6c01aefe1ebc4004e87b0bc714f2759f15c4.1575985006.git.lukas@wunner.de> <20191210154649.o3vsqzrtofhvcjrl@wunner.de> 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 10 Dec 2019 16:53:20 +0100, Deucher, Alexander wrote: > > > -----Original Message----- > > From: Lukas Wunner > > Sent: Tuesday, December 10, 2019 10:47 AM > > To: Deucher, Alexander > > Cc: Takashi Iwai ; Jaroslav Kysela ; Mika > > Westerberg ; Bjorn Helgaas > > ; Nicholas Johnson > opensource@outlook.com.au>; 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 > > > > 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. Well, the tricky part is that pci_get_class() itself does unrefeference the old object and reference the new object (if found). At the end of the loop, nothing is referenced, so it's fine. OTOH, if you go out of the loop in the middle, you're still keeping the pdev object reference, so you need to manually unreference it. Takashi > > Alex > > > > > 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 >