backports: backport hex2bin()
authorJohannes Berg <johannes.berg@intel.com>
Fri, 20 Dec 2013 20:47:26 +0000 (21:47 +0100)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 18 Jan 2014 12:42:11 +0000 (13:42 +0100)
This changed from not having a return value to having one,
so backport the version that has it.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
backport/backport-include/linux/kernel.h
backport/compat/Makefile
backport/compat/backport-3.2.c [new file with mode: 0644]

index 01e2e9a46c2f04f51654220a571abebb8717c4b2..0224a69f2fa44e89ae81e4628b0969cf35ab4769 100644 (file)
@@ -249,6 +249,12 @@ int hex_to_bin(char ch);
 )
 #endif /* rounddown */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0)
+/* kernels before 3.2 didn't have error checking for the function */
+#define hex2bin LINUX_BACKPORT(hex2bin)
+int __must_check hex2bin(u8 *dst, const char *src, size_t count);
+#endif /* < 3.2 */
+
 #endif /* __BACKPORT_KERNEL_H */
 
 /*
index dbf2bffa5b4d290aaddd7437b73a25c88e967a17..69f91e661bdb6e0d9375af8fe4f9b643dc718f82 100644 (file)
@@ -26,6 +26,7 @@ compat-$(CPTCFG_BACKPORT_KERNEL_2_6_37) += compat-2.6.37.o
 compat-$(CPTCFG_BACKPORT_KERNEL_2_6_39) += compat-2.6.39.o kstrtox.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_0) += compat-3.0.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_1) += compat-3.1.o
+compat-$(CPTCFG_BACKPORT_KERNEL_3_2) += backport-3.2.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_3) += compat-3.3.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_4) += compat-3.4.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_5) += compat-3.5.o user_namespace.o
diff --git a/backport/compat/backport-3.2.c b/backport/compat/backport-3.2.c
new file mode 100644 (file)
index 0000000..601a168
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Linux backport symbols for kernels 3.2.
+ *
+ * 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/kernel.h>
+#include <linux/export.h>
+
+int hex2bin(u8 *dst, const char *src, size_t count)
+{
+       while (count--) {
+               int hi = hex_to_bin(*src++);
+               int lo = hex_to_bin(*src++);
+
+               if ((hi < 0) || (lo < 0))
+                       return -1;
+
+               *dst++ = (hi << 4) | lo;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(hex2bin);