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 A3FC020E6; Wed, 30 Jul 2025 09:54:07 +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=1753869247; cv=none; b=OfY0Leydh1nDdV/q1msExUo7ieNNNQWrSrHnTqAObRKbAsEgL89CLyrT9Z1aYdrTJCQcDsOS3mNmx1bXKZ1Y5B319aO3Mi94fAOoPyVWfc34FI8SoG5qalcjBv9XQ8g8KNOHMfMbfWrHqeZynFLzNh06C8y6S6ZjdUCm39U2uiY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753869247; c=relaxed/simple; bh=Kk0BePpvO5tWZrBaghTq6zHgRwc/+vwJl52pO/tMpzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pk5b0lor37f/NRVFi8rINrfTC1TIpca5G0Ij2Cfef56v6lCsiHosY1bxe3bz7Mgph6xwgEpE8W18BbxqqY42bG4fAfIBzwlW1nicgpglmpDNlp9Gwpss2sgxjxp2j7zpfM3Eou2usNpd93KdknphTxlrYHwNU5Axnjhe2+mKlU0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hZbAbc5S; 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="hZbAbc5S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DFBEC4CEF6; Wed, 30 Jul 2025 09:54:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1753869247; bh=Kk0BePpvO5tWZrBaghTq6zHgRwc/+vwJl52pO/tMpzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hZbAbc5S4iQdsV+3qYKg/5RULC40GKxMeI29d1qkXOHT4sTW8aiSm7CkOXtbNr27o oGKkKxcWbxqmbFzYQtYSpd41W/5lCIHaexNcCCP/JfmZSsNcGGp1Muc/3gHerHtUsn rDfVnWGw4qpN+cssF7VmdJfy/DiyNHLfLvy7KzfE= 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.15 65/92] dpaa2-eth: Fix device reference count leak in MAC endpoint handling Date: Wed, 30 Jul 2025 11:36:13 +0200 Message-ID: <20250730093233.269600121@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250730093230.629234025@linuxfoundation.org> References: <20250730093230.629234025@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.15-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 @@ -4655,12 +4655,19 @@ static int dpaa2_eth_connect_mac(struct 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; @@ -4694,6 +4701,8 @@ err_close_mac: dpaa2_mac_close(mac); err_free_mac: kfree(mac); +out_put_device: + put_device(&dpmac_dev->dev); return err; }