summaryrefslogtreecommitdiff
path: root/backport/compat
diff options
context:
space:
mode:
authorLuca Coelho <luciano.coelho@intel.com>2018-09-20 14:28:31 +0300
committerJohannes Berg <johannes.berg@intel.com>2018-09-24 09:20:53 +0200
commit9bc425e27ab9e46c2da4618658c3c6a86911f779 (patch)
tree1d62bb4ce62e2d2c73fa718abaad537e5529e402 /backport/compat
parentd9d83fd0d928ebffea7af2267745995ef50ec6c2 (diff)
backport: introduce match_string() for kernels < 4.6
This function was introduced in v4.6 and now the iwlwifi driver uses it. Add the function for kernels older than v4.6. Signed-off-by: Luca Coelho <luciano.coelho@intel.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'backport/compat')
-rw-r--r--backport/compat/backport-4.6.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/backport/compat/backport-4.6.c b/backport/compat/backport-4.6.c
index 54ff669d..8d0ecf56 100644
--- a/backport/compat/backport-4.6.c
+++ b/backport/compat/backport-4.6.c
@@ -75,3 +75,29 @@ int kstrtobool_from_user(const char __user *s, size_t count, bool *res)
return kstrtobool(buf, res);
}
EXPORT_SYMBOL_GPL(kstrtobool_from_user);
+
+/**
+ * match_string - matches given string in an array
+ * @array: array of strings
+ * @n: number of strings in the array or -1 for NULL terminated arrays
+ * @string: string to match with
+ *
+ * Return:
+ * index of a @string in the @array if matches, or %-EINVAL otherwise.
+ */
+int match_string(const char * const *array, size_t n, const char *string)
+{
+ int index;
+ const char *item;
+
+ for (index = 0; index < n; index++) {
+ item = array[index];
+ if (!item)
+ break;
+ if (!strcmp(item, string))
+ return index;
+ }
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL(match_string);