From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D252C2D0BF for ; Tue, 10 Dec 2019 16:10:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6DADD2077B for ; Tue, 10 Dec 2019 16:10:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727590AbfLJQKp (ORCPT ); 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 >