From: Luis R. Rodriguez Date: Wed, 12 Dec 2012 19:45:05 +0000 (-0800) Subject: compat: backport platform_device_register_data() X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=1337db88b14e369de099e11d50a3038b64c5dfad;p=openwrt%2Fstaging%2Fblogic.git compat: backport platform_device_register_data() 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 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 Cc: David Brownell Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman 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 --- diff --git a/compat/compat-2.6.28.c b/compat/compat-2.6.28.c index 0ae8f465dbb6..6be544275e98 100644 --- a/compat/compat-2.6.28.c +++ b/compat/compat-2.6.28.c @@ -11,10 +11,58 @@ #include #include #include +#include #include /* 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) /* diff --git a/include/linux/compat-2.6.28.h b/include/linux/compat-2.6.28.h index b82a7eae7a94..9f1b6290f87d 100644 --- a/include/linux/compat-2.6.28.h +++ b/include/linux/compat-2.6.28.h @@ -29,6 +29,10 @@ struct hid_device_id { #include #include +#include + +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;