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 A83052FDC2C; Tue, 12 Aug 2025 17:37:54 +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=1755020275; cv=none; b=BRqw+h58Gzj1fZu1Ea1rFQRhYPmf/TS836T0QO7+xsOzcEpBXL1hGpdykStwJ5uImzh0jb7c6M/ICrXp1MMnhyzWNMpzZjEUbfM1k2idUUETCLtPAfCSCGQwt0n1MLEbBXV/VM4mkGe5F3fHOIS+XHMk95gJSIL8C+ISSZ2ewks= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755020275; c=relaxed/simple; bh=BMfFMVP65wDWRor72k1I9b2EuPB3y7/hojKdLDSufUU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kNERxYc6vAbAlNzCko61quGW3Jcx1YMj26DeU0h4n3R2r557+eQEdBYDPJTu161097SRQCX3zhg8roo0jGkiZwOg8K5SBWxHjun+LVua7X4OWg1W4qJnpV8RJscH3z0w5yKbg1J7mSp+KLjWzQbPO8M9mEKI/25R05/jCwKQjPA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qQBp22A9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qQBp22A9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C30D5C4CEF0; Tue, 12 Aug 2025 17:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755020274; bh=BMfFMVP65wDWRor72k1I9b2EuPB3y7/hojKdLDSufUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qQBp22A97GzoeQty5C/uFgiueXTWVC1o1Vj4pto8zAi4KafVDDaXDmwLHdIUqz/yf 6Rj96pW0KV8QI5Y+c5YSucIjHVNLYZiQAZU1t7RQbybK2qt4N/Dt/tplv607Jpn9yh rf6XqKadqlHJgKEnUMJqN4pZ2EJeSNwfRDWOgz0M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ma Ke , Ioana Ciornei , Simon Horman , Jakub Kicinski Subject: [PATCH 6.1 032/253] dpaa2-eth: Fix device reference count leak in MAC endpoint handling Date: Tue, 12 Aug 2025 19:27:00 +0200 Message-ID: <20250812172950.099874984@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250812172948.675299901@linuxfoundation.org> References: <20250812172948.675299901@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ma Ke commit ee9f3a81ab08dfe0538dbd1746f81fd4d5147fdc upstream. The fsl_mc_get_endpoint() function uses device_find_child() for localization, which implicitly calls get_device() to increment the device's reference count before returning the pointer. However, the caller dpaa2_eth_connect_mac() fails to properly release this reference in multiple scenarios. We should call put_device() to decrement reference count properly. As comment of device_find_child() says, 'NOTE: you will need to drop the reference with put_device() after use'. Found by code review. Cc: stable@vger.kernel.org Fixes: 719479230893 ("dpaa2-eth: add MAC/PHY support through phylink") Signed-off-by: Ma Ke Tested-by: Ioana Ciornei Reviewed-by: Ioana Ciornei Reviewed-by: Simon Horman Link: https://patch.msgid.link/20250717022309.3339976-2-make24@iscas.ac.cn Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -4446,12 +4446,19 @@ static int dpaa2_eth_connect_mac(struct if (PTR_ERR(dpmac_dev) == -EPROBE_DEFER) return PTR_ERR(dpmac_dev); - if (IS_ERR(dpmac_dev) || dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) + if (IS_ERR(dpmac_dev)) return 0; + if (dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) { + err = 0; + goto out_put_device; + } + mac = kzalloc(sizeof(struct dpaa2_mac), GFP_KERNEL); - if (!mac) - return -ENOMEM; + if (!mac) { + err = -ENOMEM; + goto out_put_device; + } mac->mc_dev = dpmac_dev; mac->mc_io = priv->mc_io; @@ -4478,6 +4485,8 @@ err_close_mac: priv->mac = NULL; err_free_mac: kfree(mac); +out_put_device: + put_device(&dpmac_dev->dev); return err; }