greybus: kernel_ver: Add kstrtobool()

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>
This commit is contained in:
Viresh Kumar 2016-06-27 11:19:23 +05:30 committed by Greg Kroah-Hartman
parent 74ec7598b5
commit 0ef5be1885
1 changed files with 48 additions and 0 deletions

View 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 */