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=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 D724CC3F68F for ; Tue, 10 Dec 2019 15:46:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE3B7207FF for ; Tue, 10 Dec 2019 15:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727613AbfLJPqw (ORCPT ); Tue, 10 Dec 2019 10:46:52 -0500 Received: from bmailout2.hostsharing.net ([83.223.78.240]:48669 "EHLO bmailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727178AbfLJPqw (ORCPT ); Tue, 10 Dec 2019 10:46:52 -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 D29CC2801A03E; Tue, 10 Dec 2019 16:46:49 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 7B3DC973; Tue, 10 Dec 2019 16:46:49 +0100 (CET) Date: Tue, 10 Dec 2019 16:46:49 +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: <20191210154649.o3vsqzrtofhvcjrl@wunner.de> References: <77aa6c01aefe1ebc4004e87b0bc714f2759f15c4.1575985006.git.lukas@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: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. 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