From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5771EC2BB3F for ; Wed, 15 Nov 2023 20:57:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344521AbjKOU5H (ORCPT ); Wed, 15 Nov 2023 15:57:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344569AbjKOU5G (ORCPT ); Wed, 15 Nov 2023 15:57:06 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB64CBD for ; Wed, 15 Nov 2023 12:57:02 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7179FC4E779; Wed, 15 Nov 2023 20:57:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1700081822; bh=oPmD1YP4CNjw5hx5Io0Q6IaOqqF0/1PsK8dA75b0epQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mDD3KFkBMOyVSQfoPGBGCzC47AFdytLRAJRgEQ24VxkhkJ9GTDMcOeJfghCNaeufZ RCSwmJdRXGH4orB8eDXBi8KOdpx2b+ovqGG37am3m2yL1kTe5bmIck/hWQDD4ekQGA WghLz7rewYqZFSJnug5GXVmHW+3+Nl1lWFzOsTuY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dinghao Liu , Alexandre Belloni , Sasha Levin Subject: [PATCH 5.10 148/191] i3c: Fix potential refcount leak in i3c_master_register_new_i3c_devs Date: Wed, 15 Nov 2023 15:47:03 -0500 Message-ID: <20231115204653.388424612@linuxfoundation.org> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231115204644.490636297@linuxfoundation.org> References: <20231115204644.490636297@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dinghao Liu [ Upstream commit cab63f64887616e3c4e31cfd8103320be6ebc8d3 ] put_device() needs to be called on failure of device_register() to give up the reference initialized in it to avoid refcount leak. Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure") Signed-off-by: Dinghao Liu Link: https://lore.kernel.org/r/20230921082410.25548-1-dinghao.liu@zju.edu.cn Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/i3c/master.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 1c6b78ad5ade4..828fb236a63ae 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1509,9 +1509,11 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master) desc->dev->dev.of_node = desc->boardinfo->of_node; ret = device_register(&desc->dev->dev); - if (ret) + if (ret) { dev_err(&master->dev, "Failed to add I3C device (err = %d)\n", ret); + put_device(&desc->dev->dev); + } } } -- 2.42.0