From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91994224240 for ; Sat, 20 Dec 2025 10:45:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766227514; cv=none; b=ldC7eSIREZH/Rl2QnlUPWiCtpUFlVvCEZwBYNkhkQH5ybH77NIvkGWcxsFU9ybOMZcmckJJp/3vyPgJNiPFza3WvpqlFpelkaJDfVhjO9i0QEr58aOM9nD90vP3JZLvEU326hLcUrOZqGpIH2noHi21kX6njWXbQZWR8tUKb4Js= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766227514; c=relaxed/simple; bh=V5P5vXWLkKnry4xZROdXvmrEOjVqCHKY6ocQB130z6o=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=QHFI5QTtVbwmO7Z7fuQbSTRln8WDiDbAZgtFDnqKzGnOd54kVElHwvuXHtErrBJbW+RA1yjbxMuXkE5stA3P7ZtbJLqWL0dkeLQ9vruDH7wE00SeW13e7n3g3H+pNepuQWIWgAtGuhtussxLyWl1NT8nzYHeel0At/f8xhT6cqk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bRB0hHm4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bRB0hHm4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D0BDC4CEF5; Sat, 20 Dec 2025 10:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766227514; bh=V5P5vXWLkKnry4xZROdXvmrEOjVqCHKY6ocQB130z6o=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=bRB0hHm4nUD2k0rwJVhjtIgZd3iS4PLr4Rw8rW4AJNs1BKldZkf1PKdePJEY+10Sc 38oKr67givnzWArEIxU29dHrHuwhOzMwa+UxE3AIPTnidDfP44t/Yp3msEWXb/xzOu G6Fpn28pjGMsvuO6yOSWSMtxWr4I59kJStCPyqNJxjgvAuuBxIHv0jCnWakKWt1Ybi 912GbWJKweARZSrRNXHCrmjydzrIIqeYtTJchNfYF4boarfyUwbZJLSCwP3hQBPOTK bsmsWCWyJj08XFDM2yt/hHwPWhqXVufXvayHjEm6hkGdxLN5GspkhqCYGJ9I1gfHDX +TJI5mvws5yvA== Message-ID: Date: Sat, 20 Dec 2025 11:45:10 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] powerpc/fsl_rio: fix a improper release in fsl_rio_setup() To: Haoxiang Li , maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, mporter@kernel.crashing.org, alex.bou9@gmail.com Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20251219141033.632153-1-lihaoxiang@isrc.iscas.ac.cn> Content-Language: fr-FR From: "Christophe Leroy (CS GROUP)" In-Reply-To: <20251219141033.632153-1-lihaoxiang@isrc.iscas.ac.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 19/12/2025 à 15:10, Haoxiang Li a écrit : > [Vous ne recevez pas souvent de courriers de lihaoxiang@isrc.iscas.ac.cn. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] > > If rio_register_mport() fails, put_device() is the correct way > to drop the device reference. > To prevent a double free, remove put_device() in rio_register_mport() > Also, add a put_device() in tsi721_setup_mport() to prevent reference > leak. Your explanation is unclear. It is correct that put_device() is the correct way to drop the device reference, and it is already what rio_register_mport() does. Why do you need to move it out of rio_register_mport() ? This is what you have to explain. > > Found by code review. AI code review or human code review ? > > Signed-off-by: Haoxiang Li > --- > arch/powerpc/sysdev/fsl_rio.c | 2 +- > drivers/rapidio/devices/tsi721.c | 1 + > drivers/rapidio/rio.c | 1 - > 3 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/powerpc/sysdev/fsl_rio.c b/arch/powerpc/sysdev/fsl_rio.c > index f9b214b299e7..f6226b2619ed 100644 > --- a/arch/powerpc/sysdev/fsl_rio.c > +++ b/arch/powerpc/sysdev/fsl_rio.c > @@ -697,7 +697,7 @@ static int fsl_rio_setup(struct platform_device *dev) > if (rio_register_mport(port)) { > release_resource(&port->iores); > kfree(priv); > - kfree(port); Why do you remove this kfree() ? By doing this you will leak the port pointer allocated earlier in the loop by kzalloc() > + put_device(&port->dev); > continue; > } > active_ports++; > diff --git a/drivers/rapidio/devices/tsi721.c b/drivers/rapidio/devices/tsi721.c > index 4b84270a8906..17c2bcf29c5c 100644 > --- a/drivers/rapidio/devices/tsi721.c > +++ b/drivers/rapidio/devices/tsi721.c > @@ -2758,6 +2758,7 @@ static int tsi721_setup_mport(struct tsi721_device *priv) > err = rio_register_mport(mport); > if (err) { > tsi721_unregister_dma(priv); > + put_device(&mport->dev); > goto err_exit; > } > > diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c > index 46daf32ea13b..026b2328afd7 100644 > --- a/drivers/rapidio/rio.c > +++ b/drivers/rapidio/rio.c > @@ -2089,7 +2089,6 @@ int rio_register_mport(struct rio_mport *port) > mutex_lock(&rio_mport_list_lock); > list_del(&port->node); > mutex_unlock(&rio_mport_list_lock); > - put_device(&port->dev); > } else { > dev_dbg(&port->dev, "RIO: registered mport%d\n", port->id); > } > -- > 2.25.1 >