Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp360700pxb; Thu, 26 Aug 2021 05:04:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZKMdQFN4uU0ddsRjS1zpNi7vO/a+WlX1dlCASaGwTs25hsQ9FmSE51GbxcukA1GkSmycl X-Received: by 2002:a05:6638:3048:: with SMTP id u8mr3141725jak.91.1629979480874; Thu, 26 Aug 2021 05:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629979480; cv=none; d=google.com; s=arc-20160816; b=JOreZoNTw3fXrVigUFlPkO+hyc7oiGPKinT8MXROuhlrmM0FTRKBAgTzV8gZ5iZv2H o9MM7wrrIpRcZ47CV/WRqIgd2SNyGaPEjkE7H5vNMNRDp6WxmAlluaEE+85t+uGqUjDD IhuFWMDr7hJsvHWZK2IcSACz4AZRVk8tn++g7gogoK0LMFpDR7XOl4A9YU5nRT7st8yj rWOfV+IbPlw+OrQPZFEH4kxcJtas4UNe6LcmH7P4iDvi9Gq2zE2K1MbywwjIqH1uVVfh rO8FEft9afooQkXh2wZM3mkWL7S/c4XweGtJ3VrT7+71BWgMpc9qXZWpG5Me7pZJM1Ab RuRg== 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=U8Uih67uFvTv5aIzXKP2gTtWKhIpGBz/9a+5CwoXPxc=; b=KiGTNkH0N6b8XYXcRG5G4GZB/FURw3Q7ibXMazntRWhfr8QObiKfNq19W1DJFDAshv d1l4EKryDBxLqDc/HKGirjGMDurfVEguEf/Fwv3dCtI10NTCWMrBWNNHjrYzkmqD+wHI LN5GGM3KmbBqYj+Iot0l0zUNH6JIOiRDYhXVNew/+AJxvaf3xRfTe3eF4cDrOXyt1t5W R0mm/0UjgJRMPOljjEdd1anZKCAU3ZfROD3SkTdIA863veIkq6XMyPi1UaaUZcXR2m/n Jn4UxMt5OmydY+ceciZHa9tvpCUI07MsS7JJ1y2nf1Fw6BsAkO/VJseDjv1FxQTNv0R2 ouzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Uu3ex+pP; 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 i4si2493497ila.157.2021.08.26.05.04.28; Thu, 26 Aug 2021 05:04:40 -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=Uu3ex+pP; 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 S242449AbhHZMCN (ORCPT + 99 others); Thu, 26 Aug 2021 08:02:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:45784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242147AbhHZMCI (ORCPT ); Thu, 26 Aug 2021 08:02:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4151C60EBA; Thu, 26 Aug 2021 12:01:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629979281; bh=O99YQ+TsybHzsga5F3D+tnXvUZcw1ANvaDzlHxFeSBM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Uu3ex+pPv7Hr8a23oL6UmINhYFVLjCSrg0mHaQId9fTLk5tm9DDPxsVoqZa6hWsk9 z9RIqBU3x1eQBYtAzAhnLRkYaqAibOBBVpefjLPqxO3ly04tCUyzmdN4jsydAd648w bavC8sjpwjuckvLdX8R08FvqCW3/aGV4w59u6PyjJXCeh2zfISbBWGY29zgW4wT22z X19FbZpmjnVUZAOSYq/bfWz4EiydUNCJ0COsgjvfjr2gOGQ6DXjEdoSvJw0Pa2XpsM 0y1xLzwm7qwv19p+PrsT4YLAkZctNfwKLVPiJ9Cb9XbkzymJ040SKVxkRP6Qw9e2kH DQuqwelYNv4Kg== Received: by mail-ed1-f42.google.com with SMTP id b7so4302768edu.3; Thu, 26 Aug 2021 05:01:21 -0700 (PDT) X-Gm-Message-State: AOAM533uDzGQ3Bw33SGdwlv8mtX22Ja0ENdgzpodnQVkjC9rK0MWmYbD PdcgezNdedmwrj9XrAsmF5trZCkWiOa/vp2xpw== X-Received: by 2002:aa7:cb19:: with SMTP id s25mr3926073edt.194.1629979279871; Thu, 26 Aug 2021 05:01:19 -0700 (PDT) MIME-Version: 1.0 References: <20210825083425.32740-1-yajun.deng@linux.dev> <63e1e9ea1e4b74b56aeafcc6695ecfa8@linux.dev> In-Reply-To: <63e1e9ea1e4b74b56aeafcc6695ecfa8@linux.dev> From: Rob Herring Date: Thu, 26 Aug 2021 07:01:06 -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 10:57 PM wrote: > > August 25, 2021 9:55 PM, "Rob Herring" wrote: > > > 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. > > But the device_unregister() is only contains device_del() and put_device(). It just put > device_del() before put_device(). And that is the wrong order as we want to undo what the code above did. The put_device here is for the get_device we did. The put_device in device_unregister is for the get_device that device_register did (on success only). Logically, it is wrong too to call unregister if register failed. That would be like doing this: p = malloc(1); if (!p) free(p); Rob