From nobody Mon Feb 9 09:23:06 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8E4133A9C1 for ; Mon, 26 Jan 2026 13:52:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435564; cv=none; b=s19YDWcfGechiojrbUpLRSToWLOKq8GvpdTyjmWTbedowlOsL17cmZwgKClp3f/Fv5IL/AcxLJYUcL3k+CLzEVBAS744kxVXLbxNeIR3didFF3PEyCnftMv04/fpazZ5ZWtkeDsv1buK9swhJIoEsxiD6KznzA0e1BXUSHH+7QQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435564; c=relaxed/simple; bh=wfdu7BgNyaudGo7x3olBbFwiUZzdWbnFwEbSgQIKBIE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lWpeEhm5m72NpCQE32wkRqjpcwhd/KnI3+IRPIa/6hwivkw073BRVIbp/RJQLZjrfyIJjtk5FhaceAAHEWVKj2UOhboxjQ46BNyhbgvirOoZ0d99PDSNu3BWX3jtSzzAbydUInxwuZjeacqMBChB+KPKlvxxt/XXy8rJFjuD7gA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A84BC497; Mon, 26 Jan 2026 05:52:34 -0800 (PST) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7012B3F632; Mon, 26 Jan 2026 05:52:39 -0800 (PST) From: Leo Yan Date: Mon, 26 Jan 2026 13:52:01 +0000 Subject: [PATCH v2 1/8] coresight: Fix memory leak in coresight_alloc_device_name() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260126-arm_coresight_refactor_dev_register-v2-1-b5a3c0441c15@arm.com> References: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> In-Reply-To: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Greg Kroah-Hartman , Mathieu Poirier , Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769435557; l=2227; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=wfdu7BgNyaudGo7x3olBbFwiUZzdWbnFwEbSgQIKBIE=; b=JXRDFl1FXfxzkOotT3Oic2XKedRywv/hZLcv6bZM4ul8omNk2C9p0Z/NWCUXlnEkMHG++1VOY r+oJd2CAEqMA79rFxFKwGoJNeczaTNSL96pg39ZJcnf+kIV38psAtez X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= The memory leak detector reports: echo clear > /sys/kernel/debug/kmemleak modprobe coresight_funnel rmmod coresight_funnel # Scan memory leak and report it echo scan > /sys/kernel/debug/kmemleak cat /sys/kernel/debug/kmemleak unreferenced object 0xffff0008020c7200 (size 64): comm "modprobe", pid 410, jiffies 4295333721 hex dump (first 32 bytes): d8 da fe 7e 09 00 ff ff e8 2e ff 7e 09 00 ff ff ...~.......~.... b0 6c ff 7e 09 00 ff ff 30 83 00 7f 09 00 ff ff .l.~....0....... backtrace (crc 4116a690): kmemleak_alloc+0xd8/0xf8 __kmalloc_node_track_caller_noprof+0x2c8/0x6f0 krealloc_node_align_noprof+0x13c/0x2c8 coresight_alloc_device_name+0xe4/0x158 [coresight] 0xffffd327ecef8394 0xffffd327ecef85ec amba_probe+0x118/0x1c8 really_probe+0xc8/0x3f0 __driver_probe_device+0x88/0x190 driver_probe_device+0x44/0x120 __driver_attach+0x100/0x238 bus_for_each_dev+0x84/0xf0 driver_attach+0x2c/0x40 bus_add_driver+0x128/0x258 driver_register+0x64/0x138 __amba_driver_register+0x2c/0x48 Change to use devm_krealloc_array() for allocation fwnode_list so that the device model can automatically release the memory when the module is unloaded. Fixes: 0f5f9b6ba9e1 ("coresight: Use platform agnostic names") Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index c660cf8adb1c7cafff8f85e501f056e4e151e372..ed304f292b7b02e89c59053d43f= 88fbf663cc993 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1546,7 +1546,7 @@ char *coresight_alloc_device_name(struct coresight_de= v_list *dict, if (idx < 0) { /* Make space for the new entry */ idx =3D dict->nr_idx; - list =3D krealloc_array(dict->fwnode_list, + list =3D devm_krealloc_array(dev, dict->fwnode_list, idx + 1, sizeof(*dict->fwnode_list), GFP_KERNEL); if (ZERO_OR_NULL_PTR(list)) { --=20 2.34.1 From nobody Mon Feb 9 09:23:06 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC45E33ADAD for ; Mon, 26 Jan 2026 13:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435566; cv=none; b=bhDMTZzy+GsFanpurBOr4J+H7TjDLJsDdNOFo5Uk0AXR2cJQp73QJltTZdrkWVLbqTYC2NLHyp0YrLS1oQ1h86KlWMp4NfNO55e3iYu+CSeRtEOTLarHHYO9PeYVBH+eqs+2/OqJ1SKxObPWoPAldjQsM0L5c8+J1SYC3Znl+uo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435566; c=relaxed/simple; bh=sU9u6OCx/Fy2Hv6Til4Fd08SgN9HV1pojJ6aLoovuyk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WZxBxa9BiSOE6pGWBr10Mzl+T8eFwNJ9UvHoS612rA7L9tmIYlSgOfKBxbptUIIwufkpPbsQe9QGf0UYmaeSQGnwM6CPUroQT7nX25/G8SH99sHBQrsn5R60LRHfI9W6+G8MBoeXqJsLDiA4BjWsNvd3I4D1d59kPxLovMc3ppY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B44911515; Mon, 26 Jan 2026 05:52:36 -0800 (PST) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7FA5D3F632; Mon, 26 Jan 2026 05:52:41 -0800 (PST) From: Leo Yan Date: Mon, 26 Jan 2026 13:52:02 +0000 Subject: [PATCH v2 2/8] coresight: Get parent device reference after sink ID map allocation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260126-arm_coresight_refactor_dev_register-v2-2-b5a3c0441c15@arm.com> References: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> In-Reply-To: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Greg Kroah-Hartman , Mathieu Poirier , Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769435557; l=1925; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=sU9u6OCx/Fy2Hv6Til4Fd08SgN9HV1pojJ6aLoovuyk=; b=nTeSFJqqhHh7Q4Jhm630XBz7DPukiHgXZaCTrQgI4Aoosj8Dr9ElkKoO0p2xadl4zHsBT1Gw4 WkV/K7PILW0DtJ/OE1OZLtas74C/k1I5EUxeqllmJAheGQYp+5dFNRC X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= The parent device's reference count is incremented before allocating the sink ID map. If the allocation fails, the reference count is not decremented, preventing proper cleanup. Fix this by incrementing the reference count only after the sink ID map is successfully allocated. Fixes: 5ad628a76176 ("coresight: Use per-sink trace ID maps for Perf sessio= ns") Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index ed304f292b7b02e89c59053d43f88fbf663cc993..6f21925a4913330a27db5d5836f= 34f13382339e7 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1346,12 +1346,6 @@ struct coresight_device *coresight_register(struct c= oresight_desc *desc) csdev->dev.parent =3D desc->dev; csdev->dev.release =3D coresight_device_release; csdev->dev.bus =3D &coresight_bustype; - /* - * Hold the reference to our parent device. This will be - * dropped only in coresight_device_release(). - */ - csdev->dev.fwnode =3D fwnode_handle_get(dev_fwnode(desc->dev)); - dev_set_name(&csdev->dev, "%s", desc->name); =20 if (csdev->type =3D=3D CORESIGHT_DEV_TYPE_SINK || csdev->type =3D=3D CORESIGHT_DEV_TYPE_LINKSINK) { @@ -1363,6 +1357,14 @@ struct coresight_device *coresight_register(struct c= oresight_desc *desc) goto err_out; } } + + /* + * Hold the reference to our parent device. This will be + * dropped only in coresight_device_release(). + */ + csdev->dev.fwnode =3D fwnode_handle_get(dev_fwnode(desc->dev)); + dev_set_name(&csdev->dev, "%s", desc->name); + /* * Make sure the device registration and the connection fixup * are synchronised, so that we don't see uninitialised devices --=20 2.34.1 From nobody Mon Feb 9 09:23:06 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AF4833B95D for ; Mon, 26 Jan 2026 13:52:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435571; cv=none; b=quSRdxVaan0IBhipcMCJzXCfCiqOEClYEUmPvllZwm9Oxo3OLJUUoDkBH4Qn0IHbegnJvajaJ1aHClc0o/YcXBES09PcFgmUwTuRendTBz00wiOPeJZUJI/FwwX8x2R3nJ/m8+YSR62DfdOSyuJt76RgVQZye53b8EJ7hnY2kRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435571; c=relaxed/simple; bh=NNtyAxNPwkV3k4xTpN3INAVKd2Yf9zKDsOUZfCQ+ZCw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kMipldz34EH9E/v/4R2vezH/fT+xgYT8t69RNNauZDLy5rqrg3ep4YKvgI+ITh2Ipq5bWHYqyImaknJY9FSRN69omw0Yvb6ubuqBhtsYQAbjTGCrtPIcsbkb3qAsFRt6Xe1XlBIR09ZxwjK1JXOAdmbqM6CoZ58IVBviK0nWJfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C39E5339; Mon, 26 Jan 2026 05:52:38 -0800 (PST) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8EA863F632; Mon, 26 Jan 2026 05:52:43 -0800 (PST) From: Leo Yan Date: Mon, 26 Jan 2026 13:52:03 +0000 Subject: [PATCH v2 3/8] coresight: Protect unregistration with mutex Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260126-arm_coresight_refactor_dev_register-v2-3-b5a3c0441c15@arm.com> References: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> In-Reply-To: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Greg Kroah-Hartman , Mathieu Poirier , Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769435557; l=1601; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=NNtyAxNPwkV3k4xTpN3INAVKd2Yf9zKDsOUZfCQ+ZCw=; b=9jvQ1yfATrYjaMdrbvY+6WdiUxjP8y7iXWCIDITcXWLM3hGr4fi6D8ykgbmuHpUFiIfk+dUxX kdDKJ1UgN5AAWGlNNlMmSILp/T3rjJ9Ip2EZLgkkcckO6iby/BUq+tU X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= The device registration is protected by CoreSight mutex to ensure the atomic operations when adding a device onto bus. One the other hand, the locking is absent when unregister a device. Use mutex to ensure atomicity on device unregistration. During unregistration, unbinding the associated CTI device is not included in the locking region, as CTI has its own locking mechanism. Fixes: 8c1d3f79d9ca ("coresight: core: Fix coresight device probe failure i= ssue") Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 6f21925a4913330a27db5d5836f34f13382339e7..b992ef5de8ddbd535e937c616bd= 7ab663f097f76 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1429,14 +1429,17 @@ EXPORT_SYMBOL_GPL(coresight_register); =20 void coresight_unregister(struct coresight_device *csdev) { - etm_perf_del_symlink_sink(csdev); /* Remove references of that device in the topology */ if (cti_assoc_ops && cti_assoc_ops->remove) cti_assoc_ops->remove(csdev); + + mutex_lock(&coresight_mutex); + etm_perf_del_symlink_sink(csdev); coresight_remove_conns(csdev); coresight_clear_default_sink(csdev); coresight_release_platform_data(csdev, csdev->dev.parent, csdev->pdata); device_unregister(&csdev->dev); + mutex_unlock(&coresight_mutex); } EXPORT_SYMBOL_GPL(coresight_unregister); =20 --=20 2.34.1 From nobody Mon Feb 9 09:23:06 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E565533B95C for ; Mon, 26 Jan 2026 13:52:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435572; cv=none; b=j/yBpK2jah+MyDd8BXVR9kZxaQIzJy8PPo8FOeC+3dVipQbrHfqeKtanco0Jxse+O1gqyKXIFWRaxKmFd81m8P7ftaeepN7vNnvTg1/AATp0ku8awW68mU6eSy2CLR1c+rMWeDqT2MTO1SFG9uje55tSwFHrkUVExOS3Hc+/M3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435572; c=relaxed/simple; bh=Yx67cjs2cf0XAe2qC02YFJDT5Ny84ezsmzyaa1leZa0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=babYv2dJZKGW8AGbNBsVqjGcfWy9zFEyYAARwajSrcy4lRzg2zRsKDYUaDtwz1IY6RZlKAE5Rhb/c2i90E9wz+7f2huy3tIRYoBwnQJEKp241wDW5dyllaNu9YWbGtziIOkKyuuu3RYXqANk5PLFyLPPOT3y1+tKcHoGFC9pTWQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D5517497; Mon, 26 Jan 2026 05:52:40 -0800 (PST) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9DF9F3F632; Mon, 26 Jan 2026 05:52:45 -0800 (PST) From: Leo Yan Date: Mon, 26 Jan 2026 13:52:04 +0000 Subject: [PATCH v2 4/8] coresight: Refactor output connection sysfs link cleanup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260126-arm_coresight_refactor_dev_register-v2-4-b5a3c0441c15@arm.com> References: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> In-Reply-To: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Greg Kroah-Hartman , Mathieu Poirier , Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769435557; l=2578; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=Yx67cjs2cf0XAe2qC02YFJDT5Ny84ezsmzyaa1leZa0=; b=Qsv0X14SF597vYl1GbtGUCKn8Zl/U+nnLWlEWitqNlHe7mEkAXDi92Sbo6Ojym0igyOwsZqLs HJ67qR8+9h/CT0vYNNkKo0BiK0b0HaUSrsTP0zbANzIdZduBMCt7+7q X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= To use a central place for releasing connections, move the output connection sysfs link cleanup into coresight_remove_conns(). Also update the comments accordingly. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index b992ef5de8ddbd535e937c616bd7ab663f097f76..b4b87b3e0a608a1df19d81ba796= d4db7d01290f5 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1149,7 +1149,6 @@ static int coresight_clear_filter_source(struct devic= e *dev, void *data) return 0; } =20 -/* coresight_remove_conns - Remove other device's references to this devic= e */ static void coresight_remove_conns(struct coresight_device *csdev) { int i, j; @@ -1159,10 +1158,6 @@ static void coresight_remove_conns(struct coresight_= device *csdev) bus_for_each_dev(&coresight_bustype, NULL, csdev, coresight_clear_filter_source); =20 - /* - * Remove the input connection references from the destination device - * for each output connection. - */ for (i =3D 0; i < csdev->pdata->nr_outconns; i++) { conn =3D csdev->pdata->out_conns[i]; if (conn->filter_src_fwnode) { @@ -1173,6 +1168,13 @@ static void coresight_remove_conns(struct coresight_= device *csdev) if (!conn->dest_dev) continue; =20 + /* Remove sysfs links for the output connection */ + coresight_remove_links(csdev, conn); + + /* + * Remove the input connection references from the destination + * device for each output connection. + */ for (j =3D 0; j < conn->dest_dev->pdata->nr_inconns; ++j) if (conn->dest_dev->pdata->in_conns[j] =3D=3D conn) { conn->dest_dev->pdata->in_conns[j] =3D NULL; @@ -1303,9 +1305,6 @@ void coresight_release_platform_data(struct coresight= _device *csdev, struct coresight_connection **conns =3D pdata->out_conns; =20 for (i =3D 0; i < pdata->nr_outconns; i++) { - /* If we have made the links, remove them now */ - if (csdev && conns[i]->dest_dev) - coresight_remove_links(csdev, conns[i]); /* * Drop the refcount and clear the handle as this device * is going away @@ -1421,7 +1420,6 @@ struct coresight_device *coresight_register(struct co= resight_desc *desc) } =20 err_out: - /* Cleanup the connection information */ coresight_release_platform_data(NULL, desc->dev, desc->pdata); return ERR_PTR(ret); } --=20 2.34.1 From nobody Mon Feb 9 09:23:06 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B209933064F for ; Mon, 26 Jan 2026 13:52:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435574; cv=none; b=K/3m5cKgndzcijzWsMq5HINWDZQWmtHJG8eWajHesUwspK09f/5gzAB+D5GzGbK5hFX++OuClNYN+c7HOo5JFC4gBLnd9yOmfFbbkAdBeF5xwo5ffvbD6AA90VXVIdH8MvmVWCWlwIHNd1LDRLuDFdz1AgOP19zPwnkIbiX7Zjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435574; c=relaxed/simple; bh=uxbdugfzF5j/ZRWTDpkTaPtvtlpVlyNyjUAkq+eRg0g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s1jPFAYrqcjfeGg1lJ44z9Eo33haaP+jEOdg05zuUt7b1FR65aidV4IDdinXlTAz+YmAylvShjZn9DjhIQ4uML7JHP3EYlia9owR1PDjNajsShiXhOf/qbuBH4pBcFgopCy8MBvY8T0gUCvDtb4Eo1+j4wjuacJh70IR7UQU/6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E18AC1515; Mon, 26 Jan 2026 05:52:42 -0800 (PST) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ACE6B3F632; Mon, 26 Jan 2026 05:52:47 -0800 (PST) From: Leo Yan Date: Mon, 26 Jan 2026 13:52:05 +0000 Subject: [PATCH v2 5/8] coresight: Refactor sysfs connection group cleanup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260126-arm_coresight_refactor_dev_register-v2-5-b5a3c0441c15@arm.com> References: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> In-Reply-To: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Greg Kroah-Hartman , Mathieu Poirier , Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769435557; l=4026; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=uxbdugfzF5j/ZRWTDpkTaPtvtlpVlyNyjUAkq+eRg0g=; b=SmFtJuI9WQW/3MZqxcEgZ4pzrXa4y33DOhUiDXktIJ4QlNa0wt5sTX5uVluf5LTs9w6BkEci9 u4QJxuAV+c9Dfo5j4+cEkLz545WYLt7HDGHYJG9Jtrby/LGojMDYinN X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= Move the sysfs connection group cleanup into coresight_remove_conns(), so that the driver removes connections and related sysfs resources in one go. As side effect, the csdev argument to coresight_release_platform_data() is no longer needed; adjust the code for this. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 11 +++++------ drivers/hwtracing/coresight/coresight-platform.c | 2 +- drivers/hwtracing/coresight/coresight-priv.h | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index b4b87b3e0a608a1df19d81ba796d4db7d01290f5..74fdaf3f445d139b493c2d30418= 84550931291b3 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1197,6 +1197,8 @@ static void coresight_remove_conns(struct coresight_d= evice *csdev) coresight_remove_links(conn->src_dev, conn); conn->dest_dev =3D NULL; } + + coresight_remove_conns_sysfs_group(csdev); } =20 /** @@ -1297,8 +1299,7 @@ void coresight_write64(struct coresight_device *csdev= , u64 val, u32 offset) * coresight_release_platform_data: Release references to the devices conn= ected * to the output port of this device. */ -void coresight_release_platform_data(struct coresight_device *csdev, - struct device *dev, +void coresight_release_platform_data(struct device *dev, struct coresight_platform_data *pdata) { int i; @@ -1316,8 +1317,6 @@ void coresight_release_platform_data(struct coresight= _device *csdev, devm_kfree(dev, pdata->out_conns); devm_kfree(dev, pdata->in_conns); devm_kfree(dev, pdata); - if (csdev) - coresight_remove_conns_sysfs_group(csdev); } =20 struct coresight_device *coresight_register(struct coresight_desc *desc) @@ -1420,7 +1419,7 @@ struct coresight_device *coresight_register(struct co= resight_desc *desc) } =20 err_out: - coresight_release_platform_data(NULL, desc->dev, desc->pdata); + coresight_release_platform_data(desc->dev, desc->pdata); return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(coresight_register); @@ -1435,7 +1434,7 @@ void coresight_unregister(struct coresight_device *cs= dev) etm_perf_del_symlink_sink(csdev); coresight_remove_conns(csdev); coresight_clear_default_sink(csdev); - coresight_release_platform_data(csdev, csdev->dev.parent, csdev->pdata); + coresight_release_platform_data(csdev->dev.parent, csdev->pdata); device_unregister(&csdev->dev); mutex_unlock(&coresight_mutex); } diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwt= racing/coresight/coresight-platform.c index 0db64c5f499592e1985141161b4f90fa1f0410b4..0ca3bd762454350d33b5630244d= 0cfe638ee03fb 100644 --- a/drivers/hwtracing/coresight/coresight-platform.c +++ b/drivers/hwtracing/coresight/coresight-platform.c @@ -849,7 +849,7 @@ coresight_get_platform_data(struct device *dev) error: if (!IS_ERR_OR_NULL(pdata)) /* Cleanup the connection information */ - coresight_release_platform_data(NULL, dev, pdata); + coresight_release_platform_data(dev, pdata); return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(coresight_get_platform_data); diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtraci= ng/coresight/coresight-priv.h index fd896ac07942ec0a4c7acff9f32421352c1efef2..1ea882dffd703b2873e41b4ce0c= 2564d2ce9bbad 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -239,8 +239,7 @@ static inline void *coresight_get_uci_data_from_amba(co= nst struct amba_id *table return NULL; } =20 -void coresight_release_platform_data(struct coresight_device *csdev, - struct device *dev, +void coresight_release_platform_data(struct device *dev, struct coresight_platform_data *pdata); struct coresight_device * coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode); --=20 2.34.1 From nobody Mon Feb 9 09:23:06 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A4E133B6D2 for ; Mon, 26 Jan 2026 13:52:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435576; cv=none; b=u1pZVy1Z/EWbvqMCzkco+WlUAlz6seCXLcpMlZyIheugpw29hjKKwG1xvVnEAjbwX7bta9+gL0F45MDmUrCXzxUTgoRATY0DUftBJKgKzZvI3SLojOj9k1faZX6fScZGPT/kDB93gcFNFok6sWrJyttgaVgJOBYwSUPBplQgba4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435576; c=relaxed/simple; bh=27wpsOgNfNhKBm7GTiE/SuFAA6NmwCB9exJiRjeVwXE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GZtGRbzk+NMB9P1KnKcWo6B3pfXaY9Y7i+IcCOEGCbKkfhdy6PmZTbLOzRtmJfTibNY1RnNKkCRj2DU5xEKwWxbItY8H+hNc305W9yPfT8/goc6tOKJXtKDXl6IIztguTBQaGVTrGIFoWnbCsf1cJOPBFwSRwsCQmOK7b/GIROM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F067F339; Mon, 26 Jan 2026 05:52:44 -0800 (PST) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BBDD63F632; Mon, 26 Jan 2026 05:52:49 -0800 (PST) From: Leo Yan Date: Mon, 26 Jan 2026 13:52:06 +0000 Subject: [PATCH v2 6/8] coresight: Move sink validation into etm_perf_add_symlink_sink() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260126-arm_coresight_refactor_dev_register-v2-6-b5a3c0441c15@arm.com> References: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> In-Reply-To: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Greg Kroah-Hartman , Mathieu Poirier , Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769435557; l=2473; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=27wpsOgNfNhKBm7GTiE/SuFAA6NmwCB9exJiRjeVwXE=; b=J9c/DLlyQSFdVfFEFXO2Ihr7zuPb4RJxlyg2tFRmjVBon1SzloDJYZonMRyTL/+YfVeEcAaUs lmD9aJlLQw5BHlYOEmJGAEERG09jzyu28Cb7Sm+hnEVfJ/+Ur1cCK3S X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= Move the sink device type checks into etm_perf_add_symlink_sink(), and return -EOPNOTSUPP for unsupported devices. This simplifies the registration flow to invoke etm_perf_add_symlink_sink() unconditionally. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 23 +++++++++-----------= --- drivers/hwtracing/coresight/coresight-etm-perf.c | 5 ++++- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 74fdaf3f445d139b493c2d3041884550931291b3..5c29f78de7f115d61f550dea62b= 6538940ec9182 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1380,21 +1380,16 @@ struct coresight_device *coresight_register(struct = coresight_desc *desc) goto out_unlock; } =20 - if ((csdev->type =3D=3D CORESIGHT_DEV_TYPE_SINK || - csdev->type =3D=3D CORESIGHT_DEV_TYPE_LINKSINK) && - sink_ops(csdev)->alloc_buffer) { - ret =3D etm_perf_add_symlink_sink(csdev); + ret =3D etm_perf_add_symlink_sink(csdev); =20 - if (ret) { - device_unregister(&csdev->dev); - /* - * As with the above, all resources are free'd - * explicitly via coresight_device_release() triggered - * from put_device(), which is in turn called from - * function device_unregister(). - */ - goto out_unlock; - } + /* + * As with the above, all resources are free'd explicitly via + * coresight_device_release() triggered from put_device(), which is in + * turn called from function device_unregister(). + */ + if (ret && ret !=3D -EOPNOTSUPP) { + device_unregister(&csdev->dev); + goto out_unlock; } /* Device is now registered */ registered =3D true; diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwt= racing/coresight/coresight-etm-perf.c index 3c8a6f795094bc1da9d8b1d0fda8d58640c87489..3b2a62521396dda819011d33698= 2e960a5bd3d0e 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -902,7 +902,10 @@ int etm_perf_add_symlink_sink(struct coresight_device = *csdev) =20 if (csdev->type !=3D CORESIGHT_DEV_TYPE_SINK && csdev->type !=3D CORESIGHT_DEV_TYPE_LINKSINK) - return -EINVAL; + return -EOPNOTSUPP; + + if (!sink_ops(csdev)->alloc_buffer) + return -EOPNOTSUPP; =20 if (csdev->ea !=3D NULL) return -EINVAL; --=20 2.34.1 From nobody Mon Feb 9 09:23:06 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A226B33B97D for ; Mon, 26 Jan 2026 13:52:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435577; cv=none; b=K2Ov8NtxKLRyHGaMoYhOXtyjMWlYkHXIRDDofqoN5Q7uXWTf4z5REjb7wpom5+YSBeFxXMMdaC0qjsS5dHmwcD3VUeS5k3dhOR/R98ccE/3pnmcjX7gm+VqdTm0JZ4pCkhxBP70EhEgfToxiIFkIhj9db4kHeLtU8hm8bT/0eiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435577; c=relaxed/simple; bh=880QgqoGJpM76WHGJPVeV8CTB+waFSOBrewKHx10yEo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ae8Yg8fAaMYFxTgGt9I6sWz1hjVZVOE4Jd0El7Ty2xzutftmqmTYjz06ipQpiRBhn1hROeMr+q8el5xOtswrs9R7UIj48ZKQqkW6EYyRxLA813M/akHhfdXDHEbcMnr/c92A3bYWfy+3d3fQr2wVJJ5J18AtoHDowbn8iSZEQvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0C025153B; Mon, 26 Jan 2026 05:52:47 -0800 (PST) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CA9C63F632; Mon, 26 Jan 2026 05:52:51 -0800 (PST) From: Leo Yan Date: Mon, 26 Jan 2026 13:52:07 +0000 Subject: [PATCH v2 7/8] coresight: Do not mix success path with failure handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260126-arm_coresight_refactor_dev_register-v2-7-b5a3c0441c15@arm.com> References: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> In-Reply-To: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Greg Kroah-Hartman , Mathieu Poirier , Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769435557; l=1351; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=880QgqoGJpM76WHGJPVeV8CTB+waFSOBrewKHx10yEo=; b=+F97SOQYNgFkPNvp4D35ZRyz3QF5wqUu0aiD3Fp88rR4E0hqReaOaSpE7zw9xdieG7ZE2RXuj YkIT7K1ZtSFAq6VkN1Z3ku4x3xfFauCvGrxetG6esUzFlQoUSdrU8Zx X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= Separate the failure handling path from the successful case. Use the 'out_unlock' label only for failure handling. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 5c29f78de7f115d61f550dea62b6538940ec9182..c2b5a6efd1c01b0fbfbc289cf27= 232ccc731ba34 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1395,17 +1395,22 @@ struct coresight_device *coresight_register(struct = coresight_desc *desc) registered =3D true; =20 ret =3D coresight_create_conns_sysfs_group(csdev); - if (!ret) - ret =3D coresight_fixup_orphan_conns(csdev); + if (ret) + goto out_unlock; + + ret =3D coresight_fixup_orphan_conns(csdev); + if (ret) + goto out_unlock; + + mutex_unlock(&coresight_mutex); + + if (cti_assoc_ops && cti_assoc_ops->add) + cti_assoc_ops->add(csdev); + + return csdev; =20 out_unlock: mutex_unlock(&coresight_mutex); - /* Success */ - if (!ret) { - if (cti_assoc_ops && cti_assoc_ops->add) - cti_assoc_ops->add(csdev); - return csdev; - } =20 /* Unregister the device if needed */ if (registered) { --=20 2.34.1 From nobody Mon Feb 9 09:23:06 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A2A733ADAC for ; Mon, 26 Jan 2026 13:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435579; cv=none; b=F26LPW6RFKIbuzQFDRh79NFpk69ZSRUsNe0MbBz4g3LZ2VtuPO6NvXPZxQfhyMXcqMYbQJDMjP11iBdzXbwgEiIQLE38sY30ql1zwpxPmvg+KQXOz9dFmZu1hJgktLueAVxDhe6kgnZM0UGGKlLwvkghnt3RDOO2ifxXa9fhUnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769435579; c=relaxed/simple; bh=DTF22SZMe66CIYK4lzqxzWYf/sXtAO+3p0iCWw5x/m4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eQGPHoLRVfjQ2flX7UBXuGYIbLd1P9dvKPLFF2jtlGD3WHMdcPlxnPa/vGubEr4uIDDK0yXdMj/V8wDuLiQFcMIaf4ojksbr/SOHkiCdD7Qz8ITgmd1GCBNCYxwlrUCaKMTeDFMs+ApWRZr3dQk6U2yAhBFtXuRh1dyPQEYy0QM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 19C77497; Mon, 26 Jan 2026 05:52:49 -0800 (PST) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D97963F632; Mon, 26 Jan 2026 05:52:53 -0800 (PST) From: Leo Yan Date: Mon, 26 Jan 2026 13:52:08 +0000 Subject: [PATCH v2 8/8] coresight: Unify error handling in coresight_register() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260126-arm_coresight_refactor_dev_register-v2-8-b5a3c0441c15@arm.com> References: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> In-Reply-To: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Greg Kroah-Hartman , Mathieu Poirier , Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769435557; l=2294; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=DTF22SZMe66CIYK4lzqxzWYf/sXtAO+3p0iCWw5x/m4=; b=EEbd/ybBNWTr2Z3VfrBCyH9ZM/rDxeLQ7++72xI76/+xEIBMEpyxYXcZwB/68Yx6FItImmKAn H0cU//t0Aa4C6VEVX9TSapPYa41e9Euu0PSc1FIn78JropPLmc6pIsr X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= Unify error handling during registration: 1) Failures before device registration are handled by err_out, which releases platform data. 2) Jump to the out_unlock label on failures after device registration to unwind the flow via coresight_unregister(). The "registered" variable is no longer used, remove it. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index c2b5a6efd1c01b0fbfbc289cf27232ccc731ba34..0aa64ee36dd06f86d3f6be1cab3= 067bf91467686 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1323,7 +1323,6 @@ struct coresight_device *coresight_register(struct co= resight_desc *desc) { int ret; struct coresight_device *csdev; - bool registered =3D false; =20 csdev =3D kzalloc(sizeof(*csdev), GFP_KERNEL); if (!csdev) { @@ -1377,7 +1376,8 @@ struct coresight_device *coresight_register(struct co= resight_desc *desc) * All resources are free'd explicitly via * coresight_device_release(), triggered from put_device(). */ - goto out_unlock; + mutex_unlock(&coresight_mutex); + goto err_out; } =20 ret =3D etm_perf_add_symlink_sink(csdev); @@ -1387,12 +1387,8 @@ struct coresight_device *coresight_register(struct c= oresight_desc *desc) * coresight_device_release() triggered from put_device(), which is in * turn called from function device_unregister(). */ - if (ret && ret !=3D -EOPNOTSUPP) { - device_unregister(&csdev->dev); + if (ret && ret !=3D -EOPNOTSUPP) goto out_unlock; - } - /* Device is now registered */ - registered =3D true; =20 ret =3D coresight_create_conns_sysfs_group(csdev); if (ret) @@ -1412,11 +1408,8 @@ struct coresight_device *coresight_register(struct c= oresight_desc *desc) out_unlock: mutex_unlock(&coresight_mutex); =20 - /* Unregister the device if needed */ - if (registered) { - coresight_unregister(csdev); - return ERR_PTR(ret); - } + coresight_unregister(csdev); + return ERR_PTR(ret); =20 err_out: coresight_release_platform_data(desc->dev, desc->pdata); --=20 2.34.1