Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1353108iob; Fri, 29 Apr 2022 03:42:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsHaAKIhg/fFsaatuENfihAW+WsKIKRwzW8hr0i1dzOpp8bhx8i/xdiU8FN9di3RwscAlu X-Received: by 2002:a2e:8608:0:b0:24f:1725:114 with SMTP id a8-20020a2e8608000000b0024f17250114mr14218041lji.118.1651228971301; Fri, 29 Apr 2022 03:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651228971; cv=none; d=google.com; s=arc-20160816; b=mW4b3V38HCjBUOkF+yh862YPawDaQITsHce1tYiUusy1tEhXKoDEp68ZMew83rhaab TCRPQ4wcmCZdtvhposzRJnadyeWKtbihUVNERMkyyJ3L6zvZj9b+F9yL40+LSpOcEyTV NOnffNcFf+g3o6MG0wdhdh0tf5jJbcnZ9VB3M8kwlQq0o9dA5PJ8QTc3l6loFN+1t9uM HJx3zwQTZYdZ59RzNuQA6Ld6HhvWgiAbqE7LAQZRwOlqFlsY2oBUM+P3HLajU1XSpGHz p//9GEW0PZJQsnM6x/FhOUOpbq8ZG/CRYdB5O+DhAgelMN9SIb6ag54hytwTdPz1BGyU nAYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=z2P2jKLYZZOQU2ZB3TDiaxvOZqWuhDku45aifBchtso=; b=Se6x3CAxmpnvNmnYTIhZYwAMesdYHeZwkK2CHXAwO1i1w0U668WQR0vQ5Pyv5hOAnB UHlTlvOgP+uhPDxhh8dNpFuCXvogqOC9Kc/JZy2Q2gE9AL2InRss6l94VWwaSMuG9yP2 lmszB1Ilqk2I2x9zb0FC3+0AcpxmnY0zdMv3CACY7xa/Bsl/m6wa16U7zZct4rPgeGPE UNeXealQNlfbB2t0YQWPGhhRHAh9L1AL/CxZOLZUACbngTZqfuzyzCdcI10f5YodOscR anTBYnXzZBH8tH6rmMQf6AiGAcQs7p14Wzo9weoIZXBzzgZJmvhKqIjSLZXqYbYHd4I6 DzaA== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cf27-20020a056512281b00b00471fe39c4d6si8064817lfb.272.2022.04.29.03.42.23; Fri, 29 Apr 2022 03:42:51 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351745AbiD1UT2 (ORCPT + 99 others); Thu, 28 Apr 2022 16:19:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351683AbiD1UTR (ORCPT ); Thu, 28 Apr 2022 16:19:17 -0400 Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E1B94EA13; Thu, 28 Apr 2022 13:16:01 -0700 (PDT) Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-2f83983782fso65325387b3.6; Thu, 28 Apr 2022 13:16:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=z2P2jKLYZZOQU2ZB3TDiaxvOZqWuhDku45aifBchtso=; b=YgjF8yGo802hUQ0em8K5g4PcX+rBS14pHjpjg9F6Mk9HlZrVK1eFUhbbzQxFND9MOL 6DkoCqkILjVpG9KEjnNsQ8H43S6ig6dBNzQUCDbgAUQ2/Dc9000hah80RPfZLDk/gyGm Um3JIRFB/hhp62k4y13rwAOo6R0z9BcmZ3BHC37M+MrHqNRP9Z5Jee9cCU6urqWTsazb ckS7qE+N3sXI8fStlQR23bVsZlvOs6ZsML8omTb3/4jGAgC6AONTggtKZFazGGLav7bT /PVIXn0/JRDw1hjI5wdAVfmKmQY7Yr1L5EAXL2RezISAtrZU7kFJz3qr08uUi+p4UwOJ tr1Q== X-Gm-Message-State: AOAM531Mjj57xX6ubkksJn6jZUK/SWL6GDHySK5qZZ4GqxiswcroOGPk Rhn48N/8dnaJohjpwoAnBVxNLT+dXDOrvd2CIb0= X-Received: by 2002:a81:8493:0:b0:2f7:d7c3:15f8 with SMTP id u141-20020a818493000000b002f7d7c315f8mr25057473ywf.196.1651176960566; Thu, 28 Apr 2022 13:16:00 -0700 (PDT) MIME-Version: 1.0 References: <20220428142854.1065953-1-gregkh@linuxfoundation.org> <20220428155858.GA14614@bhelgaas> In-Reply-To: From: "Rafael J. Wysocki" Date: Thu, 28 Apr 2022 22:15:49 +0200 Message-ID: Subject: Re: [PATCH] PCI/ACPI: do not reference a pci device after it has been released To: Greg Kroah-Hartman Cc: Bjorn Helgaas , Bjorn Helgaas , "Rafael J. Wysocki" , Linux Kernel Mailing List , Len Brown , Linux PCI , ACPI Devel Maling List , whitehat002 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 On Thu, Apr 28, 2022 at 6:22 PM Greg Kroah-Hartman wrote: > > On Thu, Apr 28, 2022 at 10:58:58AM -0500, Bjorn Helgaas wrote: > > On Thu, Apr 28, 2022 at 04:28:53PM +0200, Greg Kroah-Hartman wrote: > > > In acpi_get_pci_dev(), the debugging message for when a PCI bridge is > > > not found uses a pointer to a pci device whose reference has just been > > > dropped. The chance that this really is a device that is now been > > > removed from the system is almost impossible to happen, but to be safe, > > > let's print out the debugging message based on the acpi root device > > > which we do have a valid reference to at the moment. > > > > This code was added by 497fb54f578e ("ACPI / PCI: Fix NULL pointer > > dereference in acpi_get_pci_dev() (rev. 2)"). Not sure if it's worth > > a Fixes: tag. > > Can't hurt, I'll add it for the v2 based on this review. > > > > > acpi_get_pci_dev() is used by only five callers, three of which are > > video/backlight related. I'm always skeptical of one-off interfaces > > like this, but I don't know enough to propose any refactoring or other > > alternatives. > > > > I'll leave this for Rafael, but if I were applying I would silently > > touch up the subject to match convention: > > > > PCI/ACPI: Do not reference PCI device after it has been released > > Much simpler, thanks. > > > > > > Cc: Bjorn Helgaas > > > Cc: "Rafael J. Wysocki" > > > Cc: Len Brown > > > Cc: linux-pci@vger.kernel.org > > > Cc: linux-acpi@vger.kernel.org > > > Reported-by: whitehat002 > > > Signed-off-by: Greg Kroah-Hartman > > > --- > > > drivers/acpi/pci_root.c | 3 ++- > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c > > > index 6f9e75d14808..ecda378dbc09 100644 > > > --- a/drivers/acpi/pci_root.c > > > +++ b/drivers/acpi/pci_root.c > > > @@ -303,7 +303,8 @@ struct pci_dev *acpi_get_pci_dev(acpi_handle handle) > > > * case pdev->subordinate will be NULL for the parent. > > > */ > > > if (!pbus) { > > > - dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n"); > > > + dev_dbg(&root->device->dev, > > > + "dev %d, function %d is not a PCI-to-PCI bridge\n", dev, fn); > > > > This should use "%02x.%d" to be consistent with the dev_set_name() in > > pci_setup_device(). > > Ah, missed that, will change it and send out a new version tomorrow. I would make the change below (modulo the gmail-induced wthite space breakage), though. --- drivers/acpi/pci_root.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) Index: linux-pm/drivers/acpi/pci_root.c =================================================================== --- linux-pm.orig/drivers/acpi/pci_root.c +++ linux-pm/drivers/acpi/pci_root.c @@ -295,8 +295,6 @@ struct pci_dev *acpi_get_pci_dev(acpi_ha break; pbus = pdev->subordinate; - pci_dev_put(pdev); - /* * This function may be called for a non-PCI device that has a * PCI parent (eg. a disk under a PCI SATA controller). In that @@ -304,9 +302,12 @@ struct pci_dev *acpi_get_pci_dev(acpi_ha */ if (!pbus) { dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n"); + pci_dev_put(pdev); pdev = NULL; break; } + + pci_dev_put(pdev); } out: list_for_each_entry_safe(node, tmp, &device_list, node)