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 804B5C072A2 for ; Wed, 15 Nov 2023 21:11:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235641AbjKOVLs (ORCPT ); Wed, 15 Nov 2023 16:11:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235688AbjKOVLj (ORCPT ); Wed, 15 Nov 2023 16:11:39 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3D261BF4 for ; Wed, 15 Nov 2023 13:02:22 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E5D2C4E773; Wed, 15 Nov 2023 20:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1700081550; bh=0apAH5gREU/bxdpj6hujIQRSLWikV1kaJIb7pdF/5Y8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MWhah1pCJhzDKeZtc/+QG0ltwBVOmtsoQa2ESB4pOqGQlbun2hedaWrAwcWiJZf68 h94EpAo4RS5ZNXHztsY1C2tvHkjZGRRrYXrzpjP3NAmDe/lpQs7PLOakgwxf48THYb 0aGkx9+ShGSps9npfDzCLi2DGagK8NY5C0Yw79IA= 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.15 195/244] i3c: Fix potential refcount leak in i3c_master_register_new_i3c_devs Date: Wed, 15 Nov 2023 15:36:27 -0500 Message-ID: <20231115203600.093445694@linuxfoundation.org> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231115203548.387164783@linuxfoundation.org> References: <20231115203548.387164783@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.15-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 dfe18dcd008d4..b6abbb0acbbd3 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1506,9 +1506,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