From nobody Fri Jul 24 23:31:28 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.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 0F6C1443A80; Wed, 22 Jul 2026 07:32:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784705574; cv=none; b=pHpjk65rvGFVGFi9q051ysXVbi5s6ifTrbbe/OlYeNKfFqy4HkklBcxYGbWgnw+VvsAjwJ1gbFw9blie6xsMVMWeHY/Ky8ORZi2tzMkLH9wBNXA0ntpQySRAnQSsDBzjE/dH1ekWRJ9FOv1LjlOk9m7Gsz49DKZFqNm/G+RhFxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784705574; c=relaxed/simple; bh=sjSntLCSysQkK53FZ+99YUPy4NhyQJPGMZYMeDhK/UA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GIbg74fxHHOInpbHcUgHa4l1yn4AxD6VNmZArzp5Qbfvr3mlX1m/kAvn7ZQAKx+TpHvyaC8BZFIoioiA6Lb7bxabKPwWHBxPdT8Wcka7BnJvIo7dA/o64IxeSuaK2UYtPhExBQP9r4Zd1q+kQgsYhmK5RQgTxYoYaE176fJsm/A= 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=F35iZptH; arc=none smtp.client-ip=220.197.31.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="F35iZptH" 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=Xm vnf3eUbULdFm7pDoD/hgbP3E1mr0Xg4XKRaqaAFkM=; b=F35iZptHMYHUX3ofsl kbjL4+wVanY7hKzkCx4Q72z0JP7GQPeV6cuFf37oKcy+Ps/cmJ4OA4AgiVbyCu9v zXjUc7yf89ZmLcQL8aVxxChFglggBGqxlOVzewtS/TqJTJJICYBJwCVa/ctw4hO3 9f/55xRzfDw7OEnGjYlWojLy8= Received: from ubuntu.. (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wCn9gvlcWBq66KzKw--.36137S4; Wed, 22 Jul 2026 15:31:57 +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: Wed, 22 Jul 2026 15:31:48 +0800 Message-ID: <20260722073148.1825280-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: _____wCn9gvlcWBq66KzKw--.36137S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kw4UAr17uF43tr4kJF48Crg_yoW8ZFyrpF 4jkw4Yyr98Gr40vws7Jr18Zay5uw4SvF4agryfKw4Dur4YqFWxZF1jgryFyrs3urZ5Gas0 g3WxJF409FWDXaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piGjg7UUUUU= X-CM-SenderInfo: 5pdnvshuxfjiisr6il2tof0z/xtbC1A5KVWpgce503QAA35 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 09b21a711a87..a25985743b7f 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -509,6 +509,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