public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ben Dooks <ben-linux@fluff.org>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.arm.linux.org.uk
Cc: sameo@openedhand.com, dbaryshkov@gmail.com,
	Ben Dooks <ben-linux@fluff.org>
Subject: [patch 4/4] MFD: Change mfd platform device usage to wrapper platform_device
Date: Wed, 09 Jul 2008 11:49:20 +0100	[thread overview]
Message-ID: <20080709104933.101610936@fluff.org> (raw)
In-Reply-To: 20080709104916.200210922@fluff.org

[-- Attachment #1: mfd-dont-use-platform-device-data-to-store-mfd.patch --]
[-- Type: text/plain, Size: 3748 bytes --]

This patch changes the mfd core behaviour to wrapper the platform_device
it creates in an struct mfd_device which contains the information
about the cell that was created.

1) The creation of the resource list and then passing it to the
   platform_device_add_resources() causes the allocation of a
   large array on the stack as well as copying the source data
   twice (it is copied from the mfd_cell to the temporary array
   and then copied into the newly allocated array)

2) We can wrapper the platform_device into an mfd_device and use
   that to do the platform_device and resource allocation in one
   go to reduce the failiure.

Note, is there actually any reason to pass the sub devices any
information about the cell they are created from? The mfd core
already makes the appropriate resource adjustments and anything
else like clocks should be exported by the clock drivers?

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Index: linux-2.6.26-rc9-next20080709/include/linux/mfd/core.h
===================================================================
--- linux-2.6.26-rc9-next20080709.orig/include/linux/mfd/core.h	2008-07-09 10:46:23.000000000 +0100
+++ linux-2.6.26-rc9-next20080709/include/linux/mfd/core.h	2008-07-09 11:14:55.000000000 +0100
@@ -18,8 +18,6 @@
 
 /*
  * This struct describes the MFD part ("cell").
- * After registration the copy of this structure will become the platform data
- * of the resulting platform_device
  */
 struct mfd_cell {
 	const char		*name;
@@ -33,9 +31,21 @@ struct mfd_cell {
 	const struct resource	*resources;
 };
 
+struct mfd_device {
+	struct platform_device	pdev;
+	struct mfd_cell		*cell;
+	struct resource		resources[0];
+};
+
+static inline struct mfd_device *to_mfd_device(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	return container_of(pdev, struct mfd_device, pdev);
+}
+
 static inline struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
 {
-	return (struct mfd_cell *)pdev->dev.platform_data;
+	return container_of(pdev, struct mfd_device, pdev)->cell;
 }
 
 extern int mfd_add_devices(struct platform_device *parent,
Index: linux-2.6.26-rc9-next20080709/drivers/mfd/mfd-core.c
===================================================================
--- linux-2.6.26-rc9-next20080709.orig/drivers/mfd/mfd-core.c	2008-07-09 10:59:54.000000000 +0100
+++ linux-2.6.26-rc9-next20080709/drivers/mfd/mfd-core.c	2008-07-09 11:09:59.000000000 +0100
@@ -15,28 +15,41 @@
 #include <linux/platform_device.h>
 #include <linux/mfd/core.h>
 
+static void mfd_dev_release(struct device *dev)
+{
+	struct mfd_device *mdev = to_mfd_device(dev);
+
+	kfree(mdev);
+}
+
 static int mfd_add_device(struct platform_device *parent,
 			  const struct mfd_cell *cell,
 			  struct resource *mem_base,
 			  int irq_base)
 {
-	struct resource res[cell->num_resources];
+	struct resource *res;
+	struct mfd_device *mdev;
 	struct platform_device *pdev;
 	int ret = -ENOMEM;
 	int r;
 
-	pdev = platform_device_alloc(cell->name, parent->id);
-	if (!pdev)
+	mdev = kzalloc(sizeof(struct mfd_device) +
+		       sizeof(struct resource) * cell->num_resources,
+		       GFP_KERNEL);
+	if (!mdev)
 		goto fail_alloc;
 
-	pdev->dev.parent = &parent->dev;
+	mdev->cell = cell;
+	mdev->pdev.dev.parent = &parent->dev;
 
-	ret = platform_device_add_data(pdev,
-			cell, sizeof(struct mfd_cell));
-	if (ret)
-		goto fail_device;
+	pdev = &mdev->pdev;
+	res = &mdev->resources;
+
+	device_initialise(&pdev->dev);
+	pdev->id = parent->id;
+	pdev->name = cell->name;
+	pdev->release = mfd_device_release;
 
-	memzero(res, sizeof(res));
 	for (r = 0; r < cell->num_resources; r++) {
 		res[r].name = cell->resources[r].name;
 		res[r].flags = cell->resources[r].flags;

-- 

  parent reply	other threads:[~2008-07-09 10:50 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-09 10:49 [patch 0/4] mfd updates and proposed changes Ben Dooks
2008-07-09 10:49 ` [patch 1/4] MFD: Use to_platform_device instead of container_of Ben Dooks
2008-07-09 11:10   ` Dmitry
2008-07-10 14:47     ` Samuel Ortiz
2008-07-29  0:06   ` Samuel Ortiz
2008-07-09 10:49 ` [patch 2/4] MFD: Coding style fixes Ben Dooks
2008-07-09 11:11   ` Dmitry
2008-07-09 11:12     ` Ben Dooks
2008-07-10 14:48       ` Samuel Ortiz
2008-07-09 11:46     ` ian
2008-07-29  0:07   ` Samuel Ortiz
2008-07-09 10:49 ` [patch 3/4] MFD: Remove unnecessary fields if mfd_cell structure Ben Dooks
2008-07-09 11:09   ` Dmitry
2008-07-09 11:12     ` Ben Dooks
2008-07-09 11:16       ` Dmitry
2008-07-09 11:38         ` Ben Dooks
2008-07-09 11:44           ` Dmitry
2008-07-09 10:49 ` Ben Dooks [this message]
2008-07-09 11:15   ` [patch 4/4] MFD: Change mfd platform device usage to wrapper platform_device Dmitry
2008-07-09 11:24     ` Ben Dooks
2008-07-09 11:31       ` Dmitry
2008-07-09 11:50         ` Ben Dooks
2008-07-09 11:56           ` Dmitry
2008-07-09 12:07             ` Ben Dooks
2008-07-09 12:31               ` Dmitry
2008-07-09 13:28               ` ian
2008-07-09 13:34                 ` pHilipp Zabel
2008-07-09 13:37                   ` ian
2008-07-11 21:37             ` Samuel Ortiz
2008-07-09 12:13           ` ian
2008-07-09 12:29             ` pHilipp Zabel
2008-07-09 11:45     ` ian
2008-07-09 11:52       ` Dmitry
2008-07-09 21:03         ` Russell King - ARM Linux
2008-07-09 21:13           ` Dmitry Baryshkov
2008-07-09 21:13           ` ian
2008-07-11 21:41           ` Samuel Ortiz
2008-07-09 20:56   ` Russell King - ARM Linux
2008-07-09 21:04     ` Ben Dooks

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=20080709104933.101610936@fluff.org \
    --to=ben-linux@fluff.org \
    --cc=dbaryshkov@gmail.com \
    --cc=linux-arm-kernel@lists.arm.linux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sameo@openedhand.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox