backports: add devm_kstrdup()
authorHauke Mehrtens <hauke@hauke-m.de>
Sat, 22 Feb 2014 21:42:17 +0000 (22:42 +0100)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 23 Feb 2014 23:13:26 +0000 (00:13 +0100)
This is needed by drivers/regulator/fixed.c

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
backport/backport-include/linux/device.h
backport/compat/Makefile
backport/compat/backport-3.15.c [new file with mode: 0644]

index aa91c6283935ffccd7e955c4c0636aeed87a1763..ebfc01a5b49e4a26b879eabe70ed7a557737ecf8 100644 (file)
@@ -247,4 +247,9 @@ static inline void *dev_get_platdata(const struct device *dev)
 #define devm_kmalloc(dev, size, flags) devm_kzalloc(dev, size, flags) 
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0)
+#define devm_kstrdup LINUX_BACKPORT(devm_kstrdup)
+extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);
+#endif
+
 #endif /* __BACKPORT_DEVICE_H */
index ac2dc47e5b94617f3a631c23188a7033a7019171..e2da341367818119bc02bd3caa3dc0eecf987d89 100644 (file)
@@ -30,6 +30,7 @@ compat-$(CPTCFG_BACKPORT_KERNEL_3_10) += backport-3.10.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_12) += backport-3.12.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_13) += backport-3.13.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_14) += backport-3.14.o
+compat-$(CPTCFG_BACKPORT_KERNEL_3_15) += backport-3.15.o
 
 compat-$(CPTCFG_BACKPORT_BUILD_KFIFO) += kfifo.o
 compat-$(CPTCFG_BACKPORT_BUILD_GENERIC_ATOMIC64) += compat_atomic.o
diff --git a/backport/compat/backport-3.15.c b/backport/compat/backport-3.15.c
new file mode 100644 (file)
index 0000000..367ff9d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014  Hauke Mehrtens <hauke@hauke-m.de>
+ *
+ * Backport functionality introduced in Linux 3.15.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+
+/**
+ * devm_kstrdup - Allocate resource managed space and
+ *                copy an existing string into that.
+ * @dev: Device to allocate memory for
+ * @s: the string to duplicate
+ * @gfp: the GFP mask used in the devm_kmalloc() call when
+ *       allocating memory
+ * RETURNS:
+ * Pointer to allocated string on success, NULL on failure.
+ */
+char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
+{
+       size_t size;
+       char *buf;
+
+       if (!s)
+               return NULL;
+
+       size = strlen(s) + 1;
+       buf = devm_kmalloc(dev, size, gfp);
+       if (buf)
+               memcpy(buf, s, size);
+       return buf;
+}
+EXPORT_SYMBOL_GPL(devm_kstrdup);