All of lore.kernel.org
 help / color / mirror / Atom feed
From: <laurentiu.tudor@nxp.com>
To: <gregkh@linuxfoundation.org>
Cc: <devel@driverdev.osuosl.org>, <linux-kernel@vger.kernel.org>,
	<agraf@suse.de>, <arnd@arndb.de>, <ioana.ciornei@nxp.com>,
	<ruxandra.radulescu@nxp.com>, <bharat.bhushan@nxp.com>,
	<stuart.yoder@nxp.com>, <catalin.horghidan@nxp.com>,
	<leoyang.li@nxp.com>, <roy.pledge@nxp.com>,
	Laurentiu Tudor <laurentiu.tudor@nxp.com>
Subject: [PATCH 4/9] staging: fsl-mc: don't use devres api for refcounted objects
Date: Wed, 1 Feb 2017 05:43:24 -0600	[thread overview]
Message-ID: <20170201114329.21276-5-laurentiu.tudor@nxp.com> (raw)
In-Reply-To: <20170201114329.21276-1-laurentiu.tudor@nxp.com>

From: Laurentiu Tudor <laurentiu.tudor@nxp.com>

Mixing two memory management systems, in this case
managed device resource api and refcounted objects
is a bad idea. Lifetime of an object is controlled
by its refcount so allocating it with other apis
that have their own lifetime control is not ok.
Drop devm_*() apis in favor of plain allocations.

While at it, let's drop the slab cache for objects
until we actually have proof that it improves
performance. This allows for some code cleanup.

Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
---
 drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 43 +++++----------------------------
 1 file changed, 6 insertions(+), 37 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
index 6601bde..c493427 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
@@ -27,8 +27,6 @@
 #include "fsl-mc-private.h"
 #include "dprc-cmd.h"
 
-static struct kmem_cache *mc_dev_cache;
-
 /**
  * Default DMA mask for devices on a fsl-mc bus
  */
@@ -422,17 +420,12 @@ bool fsl_mc_is_root_dprc(struct device *dev)
 static void fsl_mc_device_release(struct device *dev)
 {
 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
-	struct fsl_mc_bus *mc_bus = NULL;
 
 	kfree(mc_dev->regions);
-
-	if (strcmp(mc_dev->obj_desc.type, "dprc") == 0)
-		mc_bus = to_fsl_mc_bus(mc_dev);
-
-	if (mc_bus)
-		devm_kfree(mc_dev->dev.parent, mc_bus);
+	if (!strcmp(mc_dev->obj_desc.type, "dprc"))
+		kfree(to_fsl_mc_bus(mc_dev));
 	else
-		kmem_cache_free(mc_dev_cache, mc_dev);
+		kfree(mc_dev);
 }
 
 /**
@@ -457,7 +450,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
 		/*
 		 * Allocate an MC bus device object:
 		 */
-		mc_bus = devm_kzalloc(parent_dev, sizeof(*mc_bus), GFP_KERNEL);
+		mc_bus = kzalloc(sizeof(*mc_bus), GFP_KERNEL);
 		if (!mc_bus)
 			return -ENOMEM;
 
@@ -466,7 +459,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
 		/*
 		 * Allocate a regular fsl_mc_device object:
 		 */
-		mc_dev = kmem_cache_zalloc(mc_dev_cache, GFP_KERNEL);
+		mc_dev = kzalloc(sizeof(*mc_dev), GFP_KERNEL);
 		if (!mc_dev)
 			return -ENOMEM;
 	}
@@ -561,10 +554,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
 
 error_cleanup_dev:
 	kfree(mc_dev->regions);
-	if (mc_bus)
-		devm_kfree(parent_dev, mc_bus);
-	else
-		kmem_cache_free(mc_dev_cache, mc_dev);
+	kfree(mc_bus ? (void *)mc_bus : (void *)mc_dev);
 
 	return error;
 }
@@ -578,23 +568,11 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
  */
 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
 {
-	struct fsl_mc_bus *mc_bus = NULL;
-
-	kfree(mc_dev->regions);
-
 	/*
 	 * The device-specific remove callback will get invoked by device_del()
 	 */
 	device_del(&mc_dev->dev);
 	put_device(&mc_dev->dev);
-
-	if (strcmp(mc_dev->obj_desc.type, "dprc") == 0)
-		mc_bus = to_fsl_mc_bus(mc_dev);
-
-	if (mc_bus)
-		devm_kfree(mc_dev->dev.parent, mc_bus);
-	else
-		kmem_cache_free(mc_dev_cache, mc_dev);
 }
 EXPORT_SYMBOL_GPL(fsl_mc_device_remove);
 
@@ -835,14 +813,6 @@ static int __init fsl_mc_bus_driver_init(void)
 {
 	int error;
 
-	mc_dev_cache = kmem_cache_create("fsl_mc_device",
-					 sizeof(struct fsl_mc_device), 0, 0,
-					 NULL);
-	if (!mc_dev_cache) {
-		pr_err("Could not create fsl_mc_device cache\n");
-		return -ENOMEM;
-	}
-
 	error = bus_register(&fsl_mc_bus_type);
 	if (error < 0) {
 		pr_err("bus type registration failed: %d\n", error);
@@ -882,7 +852,6 @@ static int __init fsl_mc_bus_driver_init(void)
 	bus_unregister(&fsl_mc_bus_type);
 
 error_cleanup_cache:
-	kmem_cache_destroy(mc_dev_cache);
 	return error;
 }
 postcore_initcall(fsl_mc_bus_driver_init);
-- 
1.8.3.1

  parent reply	other threads:[~2017-02-01 11:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-01 11:43 [PATCH 0/9] staging: fsl-mc: fixes and cleanups laurentiu.tudor
2017-02-01 11:43 ` [PATCH 1/9] staging: fsl-mc: drop root dprc counting laurentiu.tudor
2017-02-01 11:43 ` [PATCH 2/9] staging: fsl-mc: fix device ref counting laurentiu.tudor
2017-02-03  9:56   ` Greg KH
2017-02-03 10:17     ` Laurentiu Tudor
2017-02-03 10:31       ` Greg KH
2017-02-01 11:43 ` [PATCH 3/9] staging: fsl-mc: add device release callback laurentiu.tudor
2017-02-01 11:43 ` laurentiu.tudor [this message]
2017-02-03  0:02   ` [PATCH 4/9] staging: fsl-mc: don't use devres api for refcounted objects Stuart Yoder
2017-02-03 10:31     ` Laurentiu Tudor
2017-02-01 11:43 ` [PATCH 5/9] staging: fsl-mc: dpmcp: drop unused APIs laurentiu.tudor
2017-02-01 11:43 ` [PATCH 6/9] staging: fsl-mc: dpmng: drop unused prototype laurentiu.tudor
2017-02-01 11:43 ` [PATCH 7/9] staging: fsl-mc: dpbp: drop unused APIs laurentiu.tudor
2017-02-01 11:43 ` [PATCH 8/9] staging: fsl-mc: dpbp: add a few missing EXPORT_SYMBOL()s laurentiu.tudor
2017-02-01 11:43 ` [PATCH 9/9] staging: fsl-mc: dprc: drop unused APIs laurentiu.tudor
2017-02-03  0:03   ` Stuart Yoder

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=20170201114329.21276-5-laurentiu.tudor@nxp.com \
    --to=laurentiu.tudor@nxp.com \
    --cc=agraf@suse.de \
    --cc=arnd@arndb.de \
    --cc=bharat.bhushan@nxp.com \
    --cc=catalin.horghidan@nxp.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ioana.ciornei@nxp.com \
    --cc=leoyang.li@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roy.pledge@nxp.com \
    --cc=ruxandra.radulescu@nxp.com \
    --cc=stuart.yoder@nxp.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.