linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org,
	mike.leach@linaro.org, robert.walker@arm.com,
	coresight@lists.linaro.org, robh@kernel.org,
	frowand.list@gmail.com, devicetree@vger.kernel.org,
	matt.sealey@arm.com, charles.garcia-tobin@arm.com,
	john.horley@arm.com, al.grant@arm.com,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Arvind Yadav <arvind.yadav.cs@gmail.com>
Subject: [PATCH v3 1/9] coresight: Document error handling in coresight_register
Date: Fri, 27 Jul 2018 11:15:29 +0100	[thread overview]
Message-ID: <1532686537-12380-2-git-send-email-suzuki.poulose@arm.com> (raw)
In-Reply-To: <1532686537-12380-1-git-send-email-suzuki.poulose@arm.com>

commit 6403587a930c ("coresight: use put_device() instead of kfree()")
fixes the double freeing of resources and ensures that the device
refcount is dropped properly. Add a comment to explain this to
help the readers and prevent people trying to "unfix" it again.

While at it, rename the labels for better readability.

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
Change since v1:
 - Document the error handling than trying to "unfix" the
   problem.
---
 drivers/hwtracing/coresight/coresight.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 3e07fd3..9fd0c38 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1006,7 +1006,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 	csdev = kzalloc(sizeof(*csdev), GFP_KERNEL);
 	if (!csdev) {
 		ret = -ENOMEM;
-		goto err_kzalloc_csdev;
+		goto err_out;
 	}
 
 	if (desc->type == CORESIGHT_DEV_TYPE_LINK ||
@@ -1022,7 +1022,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 	refcnts = kcalloc(nr_refcnts, sizeof(*refcnts), GFP_KERNEL);
 	if (!refcnts) {
 		ret = -ENOMEM;
-		goto err_kzalloc_refcnts;
+		goto err_free_csdev;
 	}
 
 	csdev->refcnt = refcnts;
@@ -1035,7 +1035,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 		conns = kcalloc(csdev->nr_outport, sizeof(*conns), GFP_KERNEL);
 		if (!conns) {
 			ret = -ENOMEM;
-			goto err_kzalloc_conns;
+			goto err_free_refcnts;
 		}
 
 		for (i = 0; i < csdev->nr_outport; i++) {
@@ -1062,7 +1062,11 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 	ret = device_register(&csdev->dev);
 	if (ret) {
 		put_device(&csdev->dev);
-		goto err_kzalloc_csdev;
+		/*
+		 * All resources are free'd explicitly via
+		 * coresight_device_release(), triggered from put_device().
+		 */
+		goto err_out;
 	}
 
 	mutex_lock(&coresight_mutex);
@@ -1074,11 +1078,11 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 
 	return csdev;
 
-err_kzalloc_conns:
+err_free_refcnts:
 	kfree(refcnts);
-err_kzalloc_refcnts:
+err_free_csdev:
 	kfree(csdev);
-err_kzalloc_csdev:
+err_out:
 	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(coresight_register);
-- 
2.7.4


  reply	other threads:[~2018-07-27 10:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-27 10:15 [PATCH v3 0/9] coresight: Update device tree bindings Suzuki K Poulose
2018-07-27 10:15 ` Suzuki K Poulose [this message]
2018-07-27 10:15 ` [PATCH v3 2/9] coresight: platform: Refactor graph endpoint parsing Suzuki K Poulose
2018-07-27 10:15 ` [PATCH v3 3/9] coresight: platform: Fix refcounting for graph nodes Suzuki K Poulose
2018-07-27 10:15 ` [PATCH v3 4/9] coresight: platform: Fix leaking device reference Suzuki K Poulose
2018-07-27 10:15 ` [PATCH v3 5/9] coresight: Fix remote endpoint parsing Suzuki K Poulose
2018-07-27 10:15 ` [PATCH v3 6/9] coresight: Add helper to check if the endpoint is input Suzuki K Poulose
2018-07-27 10:15 ` [PATCH v3 7/9] coresight: platform: Cleanup coresight connection handling Suzuki K Poulose
2018-07-27 10:15 ` [PATCH v3 8/9] coresight: Cleanup coresight DT bindings Suzuki K Poulose
2018-07-30 23:13   ` Rob Herring
2018-07-27 10:15 ` [PATCH v3 9/9] dts: juno: Update coresight bindings Suzuki K Poulose
2018-07-27 10:17   ` Liviu Dudau
2018-07-30 23:14   ` Rob Herring
2018-07-30 20:02 ` [PATCH v3 0/9] coresight: Update device tree bindings Mathieu Poirier
2018-07-31 15:06   ` Mathieu Poirier
2018-09-10 15:35     ` Sudeep Holla
2018-09-10 15:49       ` Mathieu Poirier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1532686537-12380-2-git-send-email-suzuki.poulose@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=al.grant@arm.com \
    --cc=arvind.yadav.cs@gmail.com \
    --cc=charles.garcia-tobin@arm.com \
    --cc=coresight@lists.linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=john.horley@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=matt.sealey@arm.com \
    --cc=mike.leach@linaro.org \
    --cc=robert.walker@arm.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).