greybus: kernel_ver: Add kstrtobool()
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 27 Jun 2016 05:49:23 +0000 (11:19 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 29 Jun 2016 00:54:38 +0000 (17:54 -0700)
It was added in 4.6 and is required for one of the use case, copy it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/kernel_ver.h

index 98e3179..80ed27c 100644 (file)
@@ -341,4 +341,52 @@ static inline bool pwm_is_enabled(const struct pwm_device *pwm)
 }
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
+/**
+ * kstrtobool - convert common user inputs into boolean values
+ * @s: input string
+ * @res: result
+ *
+ * This routine returns 0 iff the first character is one of 'Yy1Nn0', or
+ * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL.  Value
+ * pointed to by res is updated upon finding a match.
+ */
+static inline int kstrtobool(const char *s, bool *res)
+{
+       if (!s)
+               return -EINVAL;
+
+       switch (s[0]) {
+       case 'y':
+       case 'Y':
+       case '1':
+               *res = true;
+               return 0;
+       case 'n':
+       case 'N':
+       case '0':
+               *res = false;
+               return 0;
+       case 'o':
+       case 'O':
+               switch (s[1]) {
+               case 'n':
+               case 'N':
+                       *res = true;
+                       return 0;
+               case 'f':
+               case 'F':
+                       *res = false;
+                       return 0;
+               default:
+                       break;
+               }
+       default:
+               break;
+       }
+
+       return -EINVAL;
+}
+#endif
+
 #endif /* __GREYBUS_KERNEL_VER_H */