Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp941873pxb; Thu, 26 Aug 2021 19:40:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy26nzBJ/kBak0WTfPXHvSxOUQAA9mI8xp+AIZvDMvkIjMFzVKGyq5ttf7sSndJn8R6T9XM X-Received: by 2002:a05:6e02:1353:: with SMTP id k19mr4963136ilr.157.1630032022897; Thu, 26 Aug 2021 19:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630032022; cv=none; d=google.com; s=arc-20160816; b=cxtZvbDXKK7eYswquGE6VBxh1WG/xgM7vb60l0k26u/iWthq0ckltex3lXXrkVeyE5 B1fsCxCUkS7vB4Z2v12nYOiqM+Wga2m6iWvxg5Mk8GCZ8wL7CwIzn269RzOAKxctYB/I FnonUhAQNouKYZbRfwRHXaHFZpuOPegWlX6hPe0YTMpIqkC34w0q5HekPpZRJdtRoudN hpVJHGToNMkngssMIyMJmzIAyVPU0QebwUOJflV880bqjbZszfcI6sIRMlmrxJH/3WuD nv/pbe/HqQtamWIDduNV8J0XMd23wDD9TQ8m38IFCOCnd2NZ5jGgcD/Pi8Mm6g544E4h i0rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:cc:to:subject:message-id :from:content-transfer-encoding:date:dkim-signature:mime-version; bh=cjmEmg6cpIJ91TusMZj8RMe8MiPkJJ/XPTVR7nIuQXc=; b=evN60ostouMWUXTePLeYVPISB0ode4xmPmGatksL0sr8T3B2eBs60zKjTsFThHVHLA wC8Xn0kPA8PRv5Q84fWZLt8aPePGnh/X/JUI7G75aDTjRnkFlAxnqaV+B2NxcwwLGMwF 1OPNQExjhbGFWJg5DiLl3hsOi6wPJLqGYHH8T+oxsovOVubcCUYA+gXeVxJjR6ck4UmI Og2Cf9TMKulXyHPZbZNZI422of5azyrdFxH+bO8HeyrTvudkQ21Lr56vT6y1stuXZZSa oOip4XV4Aic2iyjCnkeKJfP5yYqeVE8JbVYYPZT2yw32Sfj8+PCUSukNBXHE67H4klnv woLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=FEG3a7rl; 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=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q20si4497100ilj.61.2021.08.26.19.40.09; Thu, 26 Aug 2021 19:40:22 -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=@linux.dev header.s=key1 header.b=FEG3a7rl; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244030AbhH0CkO (ORCPT + 99 others); Thu, 26 Aug 2021 22:40:14 -0400 Received: from out1.migadu.com ([91.121.223.63]:49005 "EHLO out1.migadu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233556AbhH0CkN (ORCPT ); Thu, 26 Aug 2021 22:40:13 -0400 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1630031963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cjmEmg6cpIJ91TusMZj8RMe8MiPkJJ/XPTVR7nIuQXc=; b=FEG3a7rlv9ydh/zXYd+Jp5uiExw6VBBKUNoIn1doDGX+YzrNQhZbJEiNxY74lanvF5w+A4 CivOHPTefNPxhDh2013lghgE8m/4Lzr80nNExfU6SzOFQnX1Z2aLyNVrBpVqc86TIxDy5J npKSx4tntrGIS4nF80m+0OGA9MTDyOU= Date: Fri, 27 Aug 2021 02:39:23 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: yajun.deng@linux.dev Message-ID: Subject: Re: [PATCH linux-next] PCI: Fix the order in unregister path To: "Rob Herring" Cc: "Bjorn Helgaas" , "Arnd Bergmann" , "Lorenzo Pieralisi" , "PCI" , linux-kernel@vger.kernel.org In-Reply-To: References: <20210825083425.32740-1-yajun.deng@linux.dev> <63e1e9ea1e4b74b56aeafcc6695ecfa8@linux.dev> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: yajun.deng@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org August 26, 2021 8:01 PM, "Rob Herring" wrote:=0A=0A> On= Wed, Aug 25, 2021 at 10:57 PM wrote:=0A> =0A>> Au= gust 25, 2021 9:55 PM, "Rob Herring" wrote:=0A>> =0A>> = On Wed, Aug 25, 2021 at 3:34 AM Yajun Deng wrote:= =0A>> =0A>> device_del() should be called first and then called put_devic= e() in=0A>> unregister path, becase if that the final reference count, th= e device=0A>> will be cleaned up via device_release() above. So use devic= e_unregister()=0A>> instead.=0A>> =0A>> Fixes: 9885440b16b8 (PCI: Fix pci= _host_bridge struct device release/free handling)=0A>> Signed-off-by: Yaj= un Deng =0A>> ---=0A>> drivers/pci/probe.c | 4 +---= =0A>> 1 file changed, 1 insertion(+), 3 deletions(-)=0A>> =0A>> NAK.=0A>>= =0A>> The current code is correct. Go read the comments for device_add/d= evice_del.=0A>> =0A>> But the device_unregister() is only contains device= _del() and put_device(). It just put=0A>> device_del() before put_device(= ).=0A> =0A> And that is the wrong order as we want to undo what the code = above=0A> did. The put_device here is for the get_device we did. The put_= device=0A> in device_unregister is for the get_device that device_registe= r did=0A> (on success only).=0A> =0A> Logically, it is wrong too to call = unregister if register failed. That=0A> would be like doing this:=0A> =0A= > p =3D malloc(1);=0A> if (!p)=0A> free(p);=0A>=0AThis is the raw code:= =0A err =3D device_register(&bus->dev);=0A if (err)=0A = goto unregister;=0Aunregister:=0A put_device(&bridge->d= ev);=0A device_del(&bridge->dev);=0A=0AThis is my code:=0A = err =3D device_register(&bus->dev);=0A if (err)=0A = goto unregister;=0A unregister:=0A device_unregister(&bridge->dev)= ;=0A=0A=0AThe parameter in device_register() is bus->dev, but the parame= ter in device_unregister() is bridge->dev.The are different.=0AThe bridge= ->dev is already success before called device_register().So it wouldn't b= e happen like your code.=0A=0A =0A> Rob