From nobody Sat Feb 7 12:40:39 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D664A23CEFF for ; Mon, 12 May 2025 15:41:20 +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=1747064482; cv=none; b=W0VeHnurFKF7B/ugZf4l/HX9smi77AHXu4u3Dh7Pu7BOsP92Wh+SPmjGNaVQ0MuMXSYkYbX9+YthIvXME8trz4Gh5Ti10dqz5qvpWx6MHe8veyC0FBR5nxzHnwNZfMELBN6Vy5xMn3EwiHLhROYP7kx01I+3cRlFAGKowtv7rYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747064482; c=relaxed/simple; bh=7HshrWMoiyCidCuH2WyX5aZW74+zXsXRhkjU1Mdj/ZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OdmtDjXAJ4X7OyGizsEFn3hTkp8U8J8iHVwltUsnKv6zPt+L54HhFIE1fYn7NDEYP2CKj3SCoKqI+DthQd0zHAIabH70oFwBIYZ5CPDGN9ctDybXh8EZ/gY0ufC2HI25JdFEWVJcs6Z01GrH6t1Gx3BkBUwPPRDDexBQLnYf0lk= 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 22D811F60; Mon, 12 May 2025 08:41:09 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B8B443F63F; Mon, 12 May 2025 08:41:18 -0700 (PDT) From: Leo Yan To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Mao Jinlong , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 1/5] coresight: Correct sink ID map allocation failure handling Date: Mon, 12 May 2025 16:41:04 +0100 Message-Id: <20250512154108.23920-2-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512154108.23920-1-leo.yan@arm.com> References: <20250512154108.23920-1-leo.yan@arm.com> 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 Content-Type: text/plain; charset="utf-8" When registering a CoreSight device, it first increase the reference counter for the associated device and then allocates sink ID map. The problem happens when the sink ID map allocation fails - the flow misses decreasing the device's reference counter. As a result, the device can never be properly cleaned up after the memory allocation failure. To fix the issue, the allocation of the sink ID map is moved before increasing the reference counter. With this change, if sink ID map allocation fails, the function can exit without holding a reference to the device. Afterwords, any subsequent failures will invoke coresight_device_release() to release the device's resource, including decrementing the reference counter. 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 5632bcb8feb6..3e3823d9f991 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1318,12 +1318,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) { @@ -1335,6 +1329,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 Sat Feb 7 12:40:39 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E35123E35D for ; Mon, 12 May 2025 15:41:22 +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=1747064484; cv=none; b=cK031+nZOU1I68ygkI3Awzu9iupy3frllXoZWdwLIvLqvGtDSIcgnvi6h5/opvt1ObmIyBh1YXI8yzKTmhhF2Pv3ysIG01uxH72L+E66VnDfXXZ2GspboSSwJEDAlrbuLEBdWbNyMM3oOdYANiU8nDW3BW8rXKuWHK/6wJCQcmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747064484; c=relaxed/simple; bh=U9+npV2ZSJGfToBj4e6veFVrU4+srf6IpPx003Sm1w0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V0bLSQTF5sgzCdEuUJGhTo9M1Qhx5VXw2dRvvFxgOUl2MMVT3Q2tAQA8ICcUiB6Sra2+uPPcM/gHJH23tHP4Y3KPKEkWKnAKJDLqXkzvBXEr4X2sWB4WPfpXEmSX0iTljwRXUxVQn0v31i79y7UdoYiDlhjY87NFZZr1J1UxIj0= 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 C495B150C; Mon, 12 May 2025 08:41:10 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 659A33F63F; Mon, 12 May 2025 08:41:20 -0700 (PDT) From: Leo Yan To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Mao Jinlong , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 2/5] coresight: Protect unregistration with mutex Date: Mon, 12 May 2025 16:41:05 +0100 Message-Id: <20250512154108.23920-3-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512154108.23920-1-leo.yan@arm.com> References: <20250512154108.23920-1-leo.yan@arm.com> 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 Content-Type: text/plain; charset="utf-8" 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 3e3823d9f991..3eacdcf638df 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1400,14 +1400,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 Sat Feb 7 12:40:39 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 415A623CEFF for ; Mon, 12 May 2025 15:41:23 +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=1747064485; cv=none; b=AWKB9RUsUkTAP3mUv1RhAiI6USqtANP1HFTU0owttJLhkVqksOPgTxuwo3y5oKA/lWU15huCjdKzHJieFXIFbOpB2rXNmPGcilyzblxLIl3dub2sq8RUuo/OUfL1n9bAzIbQ7nADo5Vw7PyJZ3/Ly0IJk7k90USYO7sZJy91tKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747064485; c=relaxed/simple; bh=t4ObW6VRwmP3xQ9ZzCEL6qfciNiAzWKyqtNuoGlCcyE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PsL6ihqX1DvGutaPzhTCb1EVze7PqSZcd+ongVTJOJA6dBQ3ennhFzQJvuNy1XwRgq9TJhftyZDEoK2SgAGlAuqHaL2w7SV/wl5Ireu1ch0ALdKEKhZCtVaMKPKaV0BhFUf2aDPybSSmbp6s5JcYjIBvOy0nHNo/DkVSgvwDT5A= 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 729F21F60; Mon, 12 May 2025 08:41:12 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 136433F63F; Mon, 12 May 2025 08:41:21 -0700 (PDT) From: Leo Yan To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Mao Jinlong , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 3/5] coresight: Explicitly use the parent device handler Date: Mon, 12 May 2025 16:41:06 +0100 Message-Id: <20250512154108.23920-4-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512154108.23920-1-leo.yan@arm.com> References: <20250512154108.23920-1-leo.yan@arm.com> 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 Content-Type: text/plain; charset="utf-8" A CoreSight device is present on the CoreSight bus, and its device node in the DT binding is assigned as the parent device. Comments are added to document this relationship. The code is refined to explicitly use the parent device handle, making it more readable and clearly indicating which device handle is being used. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 3eacdcf638df..4f51ce152ac7 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1313,9 +1313,13 @@ struct coresight_device *coresight_register(struct c= oresight_desc *desc) csdev->access =3D desc->access; csdev->orphan =3D true; =20 + /* + * 'csdev->dev' is a device present on the CoreSight bus. The device + * node in the device tree is assigned as the parent device. + */ + csdev->dev.parent =3D desc->dev; csdev->dev.type =3D &coresight_dev_type[desc->type]; csdev->dev.groups =3D desc->groups; - csdev->dev.parent =3D desc->dev; csdev->dev.release =3D coresight_device_release; csdev->dev.bus =3D &coresight_bustype; =20 @@ -1334,7 +1338,7 @@ struct coresight_device *coresight_register(struct co= resight_desc *desc) * 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)); + csdev->dev.fwnode =3D fwnode_handle_get(dev_fwnode(csdev->dev.parent)); dev_set_name(&csdev->dev, "%s", desc->name); =20 /* @@ -1393,7 +1397,7 @@ 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); + coresight_release_platform_data(NULL, csdev->dev.parent, desc->pdata); return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(coresight_register); --=20 2.34.1 From nobody Sat Feb 7 12:40:39 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A9C8241662 for ; Mon, 12 May 2025 15:41:25 +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=1747064486; cv=none; b=hw4tqYv9QvdmSQUOTFWRUwg5TN0Tp6LfRjKnw4YATE1Od4pFQyuarZsYvffciO4jMXoAmAWrZ6bbg/yJ2y4fywaBopzXz5NC5fOMvC5sS225puWySWD3sVJaCLiH+FUy4Kg46F/qJIf97+f2jqyP45ALoVqknJBHAmlnKC6Iyys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747064486; c=relaxed/simple; bh=FiCPmeaAoNGdtHP+OviKtayovI7tXtqJ2SXShK4Zxzk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pdQHjvcyZALaoJs0yJHViBCy8IMt3pEls0X4bwc/EQJIqTA1c+qu/TKfWGkRgcm7cKcXNAVHwpUylgIOmr4y+esIEIjRjVDqP50T5A2zBXOzSNpayovx5SnU8lQDA6ts+uvfVAgS+1iU4nsu73aj0bcxbOG6XN8rZcJcpqzwG+o= 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 1F0E4150C; Mon, 12 May 2025 08:41:14 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B54DD3F63F; Mon, 12 May 2025 08:41:23 -0700 (PDT) From: Leo Yan To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Mao Jinlong , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 4/5] coresight: Separate failure and success flows Date: Mon, 12 May 2025 16:41:07 +0100 Message-Id: <20250512154108.23920-5-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512154108.23920-1-leo.yan@arm.com> References: <20250512154108.23920-1-leo.yan@arm.com> 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 Content-Type: text/plain; charset="utf-8" For a success registration, it releases mutex, then binds associated CTI device, and returns a device pointer. As a result, it separates flows between the success case and the failure flow, any code after the tag 'out_unlock' is only used for failure handling. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 4f51ce152ac7..4fc82206b326 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1377,17 +1377,21 @@ 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 Sat Feb 7 12:40:39 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF94224169B for ; Mon, 12 May 2025 15:41:26 +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=1747064488; cv=none; b=p/UsTaY1IatrrCnne81OvJPTeg+CU+wWxGCpAtvft1X22lng3UZFL9j/5jOl8D6QIzBQTBk/aexQ42Wsao0UJLhwwdXO+7qZQ3R0uD2Zpxgye9KVsFnCrAfz8jFEmHrILRqJru0n+Wbb16/0GCC2/QeWhj4+8bfcgCMFD69xqN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747064488; c=relaxed/simple; bh=W85QrcnlA19hf+CBRRkoFTCmf60elDmE7DDtJ6C/mXA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jZZhOBVbzD3uD8UXgdrqBxa+p9hdj06WmEgF68s83Cf4QZY7sxV3PP10Ky4N+uMMWGyituUaBIlCiyv510zbpQC429KzSIlA+J8VVfYjVrG9evmqKv7TsIQRxX3QcXSaXbvKbCfasVf6zaAPJIFA8JHYJ/MCtiptgMccyM7byiQ= 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 A30641F60; Mon, 12 May 2025 08:41:15 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 620A93F63F; Mon, 12 May 2025 08:41:25 -0700 (PDT) From: Leo Yan To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Mao Jinlong , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 5/5] coresight: Refine error handling for device registration Date: Mon, 12 May 2025 16:41:08 +0100 Message-Id: <20250512154108.23920-6-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512154108.23920-1-leo.yan@arm.com> References: <20250512154108.23920-1-leo.yan@arm.com> 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 Content-Type: text/plain; charset="utf-8" When error happens in a device registration, the coresight_unregister() function is invoked for cleanup. coresight_unregister() includes the complete flow for unregisteration a CoreSight device, it causes redundant operations for some errors. This commit changes to invoke more specific functions for cleanup resources for each error. This can allow the cleanup flow in better granularity. As a result, the local "registered" variable is not used anymore, remove it. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-core.c | 26 ++++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 4fc82206b326..1eb4f6f0fe40 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1297,7 +1297,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) { @@ -1362,27 +1361,23 @@ struct coresight_device *coresight_register(struct = coresight_desc *desc) csdev->type =3D=3D CORESIGHT_DEV_TYPE_LINKSINK) { ret =3D etm_perf_add_symlink_sink(csdev); =20 - if (ret) { - device_unregister(&csdev->dev); + if (ret) /* * 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; - } + goto out_unregister_device; } - /* Device is now registered */ - registered =3D true; =20 ret =3D coresight_create_conns_sysfs_group(csdev); if (ret) - goto out_unlock; + goto out_del_symlink_sink; =20 ret =3D coresight_fixup_orphan_conns(csdev); if (ret) - goto out_unlock; + goto out_remove_conns; =20 mutex_unlock(&coresight_mutex); =20 @@ -1390,15 +1385,14 @@ struct coresight_device *coresight_register(struct = coresight_desc *desc) cti_assoc_ops->add(csdev); return csdev; =20 +out_remove_conns: + coresight_remove_conns_sysfs_group(csdev); +out_del_symlink_sink: + etm_perf_del_symlink_sink(csdev); +out_unregister_device: + device_unregister(&csdev->dev); out_unlock: mutex_unlock(&coresight_mutex); - - /* Unregister the device if needed */ - if (registered) { - coresight_unregister(csdev); - return ERR_PTR(ret); - } - err_out: /* Cleanup the connection information */ coresight_release_platform_data(NULL, csdev->dev.parent, desc->pdata); --=20 2.34.1