From nobody Mon Jun 22 12:28:56 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 BC363360ED5; Mon, 22 Jun 2026 07:11:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782112271; cv=none; b=LSrDqqVPyubQuVgbcDhHvcWyXdPNSDs86LPqiQWCDBHWyVpX//ic728db13bPzlgMyXRe0jtsJ1Gfe4G4463yjIhDsIEElo2R4XS1J9GmqpS+oClFoL2H7RB1EWiqCHVwtulm+M9hG+qgacBtbipGxdeEMz4qbD1PbEwxIcTjs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782112271; c=relaxed/simple; bh=B40VaEU65JwSYa7gOXvsSdUFzIVvMvqwMZdEw1ZcIV8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uDXUQyUlGwnpCMRVWxdTRsp9eaV+JCXVT6DcbMmFj/YFCbnjO5Eq8BkmPtnux7zRFN4QT9krjhHKjO19oEfE6UP/ckReRNjWNkO0lHclrevaFJnTFsaTuERjQ9DjhCzEvHBvTl/7/eBwHyjE+G1+15skOoaW2uLf5w/SsmpD+yA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Mc61r6eo; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Mc61r6eo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=PK KpVdrDqnA2ZI2QQYb9QpGJK08L53pkl9uf3Eglr+E=; b=Mc61r6eoBo3Zj2fSog DbAenP3c1ATyZb8YielV5V/QhtIZNPmWDLsD+VRT4q7KPOcwTWLLdnj9fn3t7u0w qBI5dHDFGnqdP9OE/1Z0QMucpqt2VmnKU2cH15FOpje5KP5QscdN4nejk63+IgRZ iCC3ak4ikwPQWJmYZiXILHZqg= Received: from ubuntu.. (unknown []) by gzga-smtp-mtada-g1-1 (Coremail) with SMTP id _____wA3RArQ3zhq4SzfEw--.24449S4; Mon, 22 Jun 2026 15:10:15 +0800 (CST) From: Ma Ke To: suzuki.poulose@arm.com, mike.leach@arm.com, james.clark@linaro.org, leo.yan@arm.com, alexander.shishkin@linux.intel.com, mathieu.poirier@linaro.org Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, Ma Ke , stable@vger.kernel.org Subject: [RESEND PATCH v3] coresight: etm-perf: Fix reference count leak in etm_setup_aux Date: Mon, 22 Jun 2026 15:10:07 +0800 Message-ID: <20260622071007.691231-1-make_ruc2021@163.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wA3RArQ3zhq4SzfEw--.24449S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kw4UAr17uF43tr4kJF48Crg_yoW8ZFyrpF 4jkws0yF98Gr40vws7Jr18Zay5uw4SvF4agFyfKw4DuF4YqFWfZFyjgryFyrn3urZ5Gas0 g3WxtF48uFWUXaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0p_miiDUUUUU= X-CM-SenderInfo: 5pdnvshuxfjiisr6il2tof0z/xtbC0xfV4Go439cCMAAA3Z Content-Type: text/plain; charset="utf-8" bus_find_device() returns a device with its reference count incremented. When a user-selected sink is obtained through coresight_get_sink_by_id(), etm_setup_aux() keeps using the returned sink while building the path and allocating the sink buffer. Therefore the lookup reference must remain valid while etm_setup_aux() is still using the sink, otherwise the sink could be removed under the caller. Drop the lookup reference on the common exit path, after etm_setup_aux() no longer directly uses the user-selected sink. The CoreSight path code takes the references it needs for built paths, so the initial lookup reference from coresight_get_sink_by_id() is no longer needed after setup_aux finishes. Found by code review. Signed-off-by: Ma Ke Cc: stable@vger.kernel.org Fixes: 0e6c20517596 ("coresight: etm-perf: Allow an event to use different = sinks") --- Changes in v3: - do not drop the lookup reference in coresight_get_sink_by_id(), as=20 that would return a sink pointer without keeping the device reference=20 while etm_setup_aux() is still using it. - dropped the lookup reference in etm_setup_aux on the common exit path,=20 as suggested by Suzuki. - updated the commit message to describe why the reference is kept=20 until etm_setup_aux() finishes using the sink. Changes in v2: - modified the patch as suggestions. --- drivers/hwtracing/coresight/coresight-etm-perf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwt= racing/coresight/coresight-etm-perf.c index f85dedf89a3f..d5116177c1b9 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -456,6 +456,11 @@ static void *etm_setup_aux(struct perf_event *event, v= oid **pages, goto err; =20 out: + if (user_sink) { + put_device(&user_sink->dev); + user_sink =3D NULL; + } + return event_data; =20 err: --=20 2.43.0