Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp451725pxb; Wed, 25 Aug 2021 07:07:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrkuyLmoriJWwsqeqejWUpaTMMi93HJTzBsNUBU9JvlDgUGrkoDuq3rylu9cGySIy/z459 X-Received: by 2002:a05:6402:49a:: with SMTP id k26mr48742012edv.279.1629900438776; Wed, 25 Aug 2021 07:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629900438; cv=none; d=google.com; s=arc-20160816; b=JVhk9+xKsLQ6ZSWRgkg881NymVfY8WIiONtJnWSlTLNt40pYYyfPYRRRRSFosTWZRK iiZANJiz88jKomUR37pIUn8DQovacqFxfWd3n8UrmkUVF5ajxOpP4BcHCxFOvd5GkxGm neTBU7BBhd2tdjnwTsN6JwiKYPArhbwt+nMPGqp7KmKErB1vHGdJLefTJS7uH4DzRjnc jtnRFdPkiR/i3e0T0Ymv1Gur6//TXphRCHV5+bYZujlWGdZDsM8BZGk30mnIJuo4W/d6 xkv+pxfHwrTnUlOcgFM2EGXbiTUoeo1Ukn4trsqdgOWm+5KOjh6weR2ej4DMalh1vORF qfLw== 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:dkim-signature; bh=y+zsqB08oF2ittv2V/0zS0iRislOd4HtKgp0LZtVo9g=; b=Ez+637Ml4W1c3kDLZEE8iB7mmedISx2ty3sOB4RvI/QYrRJXXVdW1ERKLD45mKkw3G O5YTM7G+c7yHRjl69q4OI0Aq5Dd9dZ06J+1tHelaRvf3pqERJCT5HjI0QGoYDfi1YYR9 QdNFRyPSXH4Np2s9XA0CxAO+PLwU4mfX8VxF2Yx8mt84kdz7Pj43cVEmyUGP+qkBt8Pl tJEWm/C9iblZHKke42yNKlBJGXYpfztpsCZCZXLtsR6DrjOv5PIOwbUVxltIqPBUqtRr Hy2GLxyCdI9KYvdZ7bsRp323eVKTq/QLQlRpniRpqLUUh6X9/tuHNDQIdYplTJXoItNt +yEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V3SgFiNh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j25si19151866eje.334.2021.08.25.07.06.54; Wed, 25 Aug 2021 07:07:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V3SgFiNh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S240958AbhHYN40 (ORCPT + 99 others); Wed, 25 Aug 2021 09:56:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:41412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229760AbhHYN4Z (ORCPT ); Wed, 25 Aug 2021 09:56:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3BDE261181; Wed, 25 Aug 2021 13:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629899740; bh=CMOIWCczQT4MgFaI6GqXH+oiMJf1br9qrx50dqeRq5I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=V3SgFiNhC0R9bdoddbTu5Pg06dVEss6l1c+OfOQj39ExOPiFGwoZ4QgvxQ9MdvZLv 4ZOJpIMkj+bMESUXcbMUSUW+FEuX3pJGnltEGwJ4wzuUhxq4ECJs1SBY93mvu4a4xe NX+99v5e/UHzDjzEGBuFvKEvNE0LUkgLSMPeH85rmuA++6rzMHhPH3FOPkJnzvg5F4 +l+R4TBt3otnnjQvcuRRLhq+LaU8Qt5PTb3czhhIeLOQ6Lw0gblTcZqXQh514JEuTM CgPqVo1Oi1BGPP05lcWoOr3oKnQr0PLs6ds/GaVF/bwhEbH63IlV0NYzb2awvuifNx PzyKP8N51W5Nw== Received: by mail-ed1-f46.google.com with SMTP id y5so6270704edp.8; Wed, 25 Aug 2021 06:55:40 -0700 (PDT) X-Gm-Message-State: AOAM532NZuShtGh6hlBurYSuOCYm20sCxfmSOMjVgGPoiRDFXB7FK4VO AaY2b3uG+iw9BOP5dQ6OJjy9An38PHRdu3f2MQ== X-Received: by 2002:a50:eb8a:: with SMTP id y10mr5724315edr.137.1629899738846; Wed, 25 Aug 2021 06:55:38 -0700 (PDT) MIME-Version: 1.0 References: <20210825083425.32740-1-yajun.deng@linux.dev> In-Reply-To: <20210825083425.32740-1-yajun.deng@linux.dev> From: Rob Herring Date: Wed, 25 Aug 2021 08:55:24 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH linux-next] PCI: Fix the order in unregister path To: Yajun Deng Cc: Bjorn Helgaas , Arnd Bergmann , Lorenzo Pieralisi , PCI , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 25, 2021 at 3:34 AM Yajun Deng wrote: > > device_del() should be called first and then called put_device() in > unregister path, becase if that the final reference count, the device > will be cleaned up via device_release() above. So use device_unregister() > instead. > > Fixes: 9885440b16b8 (PCI: Fix pci_host_bridge struct device release/free handling) > Signed-off-by: Yajun Deng > --- > drivers/pci/probe.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) NAK. The current code is correct. Go read the comments for device_add/device_del. > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c > index 0ec5c792c27d..abd481a15a17 100644 > --- a/drivers/pci/probe.c > +++ b/drivers/pci/probe.c > @@ -994,9 +994,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) > return 0; > > unregister: We get here if device_register() failed. Calling device_unregister() in that case is never right. > - put_device(&bridge->dev); This is for the get_device() we do above, not the get the driver core does. > - device_del(&bridge->dev); This undoes the device_add() we do following the comment: "NOTE: this should be called manually _iff_ device_add() was also called manually." > - > + device_unregister(&bridge->dev); > free: > kfree(bus); > return err; > -- > 2.32.0 >