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 E5F482FDC5F; Tue, 12 Aug 2025 17:37:47 +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=1755020268; cv=none; b=LpCXfxt+Sx0ZajCmyIHqYCw/fWmynAGqmA+0PIVnEtbjXi3Sj5nfsu1+WV6RMxIEyvAs9GoelSB+ScY8L0v/LryB8bPjJmqQIRpNH20bP+mFq/Q0D4O39xhT/Jd59ALPrsOgPJ/zmW9ng4CcqBzQkK0o96ARWmb/UUAeZWKmlLU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755020268; c=relaxed/simple; bh=IVCmp0NhqDqBlkOdVuZOKeXQH0JUyOllBBKMTwia5Bc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BhUmlwxBPkUwMXouV5dAc80D+ukvCMnBTypEO51SvFHilASNyJFAYGFMsO7Q3kJASRG9/5fiH9ZKSjo2/oAZMjwANYe993VJk7DsxgkDLNhsA63zVXFUEmyZeFpkW5CDttarBSVqO700ilgvzetpkCVfJRM3CQgt1yAjYSsGbW0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YnYQi7xG; 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="YnYQi7xG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55A11C4CEF0; Tue, 12 Aug 2025 17:37:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755020267; bh=IVCmp0NhqDqBlkOdVuZOKeXQH0JUyOllBBKMTwia5Bc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YnYQi7xGmIJA7mNFyPqbNIUC9KYSElatuI2Z7l/N3P+VgeNGGMnaF3jvJlZFGtz4B NVGNCNpG+9oOSCIbah8eljsm40fzoAw5T3lP5pJJdYQV7lDv3UY3Q0aL6m+Q7giIln eRjV5OvVBVDWX13W+BWch2jDbZmPtPNFphrA6VnI= 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 030/253] bus: fsl-mc: Fix potential double device reference in fsl_mc_get_endpoint() Date: Tue, 12 Aug 2025 19:26:58 +0200 Message-ID: <20250812172950.015877248@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 bddbe13d36a02d5097b99cf02354d5752ad1ac60 upstream. The fsl_mc_get_endpoint() function may call fsl_mc_device_lookup() twice, which would increment the device's reference count twice if both lookups find a device. This could lead to a reference count leak. Found by code review. Cc: stable@vger.kernel.org Fixes: 1ac210d128ef ("bus: fsl-mc: add the fsl_mc_get_endpoint function") Signed-off-by: Ma Ke Tested-by: Ioana Ciornei Reviewed-by: Simon Horman Fixes: 8567494cebe5 ("bus: fsl-mc: rescan devices if endpoint not found") Link: https://patch.msgid.link/20250717022309.3339976-1-make24@iscas.ac.cn Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/bus/fsl-mc/fsl-mc-bus.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -947,6 +947,7 @@ struct fsl_mc_device *fsl_mc_get_endpoin struct fsl_mc_obj_desc endpoint_desc = {{ 0 }}; struct dprc_endpoint endpoint1 = {{ 0 }}; struct dprc_endpoint endpoint2 = {{ 0 }}; + struct fsl_mc_bus *mc_bus; int state, err; mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); @@ -970,6 +971,8 @@ struct fsl_mc_device *fsl_mc_get_endpoin strcpy(endpoint_desc.type, endpoint2.type); endpoint_desc.id = endpoint2.id; endpoint = fsl_mc_device_lookup(&endpoint_desc, mc_bus_dev); + if (endpoint) + return endpoint; /* * We know that the device has an endpoint because we verified by @@ -977,17 +980,13 @@ struct fsl_mc_device *fsl_mc_get_endpoin * yet discovered by the fsl-mc bus, thus the lookup returned NULL. * Force a rescan of the devices in this container and retry the lookup. */ - if (!endpoint) { - struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); - - if (mutex_trylock(&mc_bus->scan_mutex)) { - err = dprc_scan_objects(mc_bus_dev, true); - mutex_unlock(&mc_bus->scan_mutex); - } - - if (err < 0) - return ERR_PTR(err); + mc_bus = to_fsl_mc_bus(mc_bus_dev); + if (mutex_trylock(&mc_bus->scan_mutex)) { + err = dprc_scan_objects(mc_bus_dev, true); + mutex_unlock(&mc_bus->scan_mutex); } + if (err < 0) + return ERR_PTR(err); endpoint = fsl_mc_device_lookup(&endpoint_desc, mc_bus_dev); /*