compat: backport platform_device_register_data()
authorLuis R. Rodriguez <mcgrof@do-not-panic.com>
Wed, 12 Dec 2012 19:45:05 +0000 (11:45 -0800)
committerLuis R. Rodriguez <mcgrof@do-not-panic.com>
Thu, 13 Dec 2012 04:39:24 +0000 (20:39 -0800)
Add the helper.

mcgrof@frijol ~/linux-next (git::master)$ git describe --contains d8bf254
v2.6.28-rc1~284^2~9

commit d8bf254089a6c31d7d01a4d1d2f1861662900855
Author: Dmitry Baryshkov <dbaryshkov@gmail.com>
Date:   Mon Sep 22 14:41:40 2008 -0700

    platform: add new device registration helper

    Add a helper that registers simple platform_device w/o resources but with
    parent and device data.

    This is usefull to cleanup platform code from code that registers such
    simple devices as leds-gpio, generic-bl, etc.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
mcgrof@drvbp1 ~/compat (git::master)$ time ckmake
Trying kernel 3.6.5-030605-generic [OK]
Trying kernel 3.5.7-030507-generic [OK]
Trying kernel 3.4.17-030417-generic [OK]
Trying kernel 3.3.8-030308-generic [OK]
Trying kernel 3.2.33-030233-generic [OK]
Trying kernel 3.1.10-030110-generic [OK]
Trying kernel 3.0.50-030050-generic [OK]
Trying kernel 2.6.39-02063904-generic [OK]
Trying kernel 2.6.38-02063808-generic [OK]
Trying kernel 2.6.37-02063706-generic [OK]
Trying kernel 2.6.36-02063604-generic [OK]
Trying kernel 2.6.35-02063513-generic [OK]
Trying kernel 2.6.34-02063413-generic [OK]
Trying kernel 2.6.33-02063320-generic [OK]
Trying kernel 2.6.32-02063260-generic [OK]
Trying kernel 2.6.31-02063113-generic [OK]
Trying kernel 2.6.30-02063010-generic [OK]
Trying kernel 2.6.29-02062906-generic [OK]
Trying kernel 2.6.28-02062810-generic [OK]
Trying kernel 2.6.27-020627-generic [OK]
Trying kernel 2.6.26-020626-generic [OK]
Trying kernel 2.6.25-020625-generic [OK]
Trying kernel 2.6.24-020624-generic [OK]

real    1m58.798s
user    3m59.967s
sys     1m25.585s

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
compat/compat-2.6.28.c
include/linux/compat-2.6.28.h

index 0ae8f465dbb6636b64b939045ece8dd747f8fa56..6be544275e98a7d57d456b8e600e4423020243de 100644 (file)
 #include <linux/compat.h>
 #include <linux/usb.h>
 #include <linux/tty.h>
+#include <linux/platform_device.h>
 #include <asm/poll.h>
 
 /* 2.6.28 compat code goes here */
 
+/**
+ * platform_device_register_data
+ * @parent: parent device for the device we're adding
+ * @name: base name of the device we're adding
+ * @id: instance id
+ * @data: platform specific data for this platform device
+ * @size: size of platform specific data
+ *
+ * This function creates a simple platform device that requires minimal
+ * resource and memory management. Canned release function freeing memory
+ * allocated for the device allows drivers using such devices to be
+ * unloaded without waiting for the last reference to the device to be
+ * dropped.
+ */
+struct platform_device *platform_device_register_data(
+               struct device *parent,
+               const char *name, int id,
+               const void *data, size_t size)
+{
+       struct platform_device *pdev;
+       int retval;
+
+       pdev = platform_device_alloc(name, id);
+       if (!pdev) {
+               retval = -ENOMEM;
+               goto error;
+       }
+
+       pdev->dev.parent = parent;
+
+       if (size) {
+               retval = platform_device_add_data(pdev, data, size);
+               if (retval)
+                       goto error;
+       }
+
+       retval = platform_device_add(pdev);
+       if (retval)
+               goto error;
+
+       return pdev;
+
+error:
+       platform_device_put(pdev);
+       return ERR_PTR(retval);
+}
+
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23))
 #if defined(CONFIG_USB) || defined(CONFIG_USB_MODULE)
 /*
index b82a7eae7a94fd8c67221a66e7f09faf22c6e4fc..9f1b6290f87d03af0eaaca48c1148fd034a7cdc4 100644 (file)
@@ -29,6 +29,10 @@ struct hid_device_id {
 
 #include <linux/pci.h>
 #include <linux/pci_regs.h>
+#include <linux/platform_device.h>
+
+extern struct platform_device *platform_device_register_data(struct device *,
+               const char *, int, const void *, size_t);
 
 typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } compat_cpumask_t;