The branch main has been updated by des:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f86148d2777d4d7985ed8f4ae957c41c44bd2484

commit f86148d2777d4d7985ed8f4ae957c41c44bd2484
Author:     Dag-Erling Smørgrav <[email protected]>
AuthorDate: 2026-01-03 09:09:41 +0000
Commit:     Dag-Erling Smørgrav <[email protected]>
CommitDate: 2026-01-03 09:10:22 +0000

    linuxkpi: Correct kstrtobool
    
    Implement the exact same logic as in Linux:
    
    * Accept 'e', 't', 'y', '1', "on" for true.
    
    * Accept 'd', 'f', 'n', '0', "of" for false.
    
    * Disregard any characters beyond that.
    
    * Check that the string is not null, but don't check the result pointer.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    bz, emaste
    Differential Revision:  https://reviews.freebsd.org/D54451
---
 sys/compat/linuxkpi/common/include/linux/kstrtox.h | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/kstrtox.h 
b/sys/compat/linuxkpi/common/include/linux/kstrtox.h
index 6a145c409038..05bf94dd375d 100644
--- a/sys/compat/linuxkpi/common/include/linux/kstrtox.h
+++ b/sys/compat/linuxkpi/common/include/linux/kstrtox.h
@@ -249,22 +249,16 @@ kstrtoull(const char *cp, unsigned int base, unsigned 
long long *res)
 static inline int
 kstrtobool(const char *s, bool *res)
 {
-       size_t len;
-
-       if (s == NULL || (len = strlen(s)) == 0 || res == NULL)
+       if (s == NULL || *s == '\0')
                return (-EINVAL);
 
-       /* skip newline character, if any */
-       if (s[len - 1] == '\n')
-               len--;
-
-       if (len == 1 && strchr("yY1", s[0]) != NULL)
+       if (strchr("eEtTyY1", s[0]) != NULL)
                *res = true;
-       else if (len == 1 && strchr("nN0", s[0]) != NULL)
+       else if (strchr("dDfFnN0", s[0]) != NULL)
                *res = false;
-       else if (strncasecmp("on", s, len) == 0)
+       else if (strncasecmp("on", s, 2) == 0)
                *res = true;
-       else if (strncasecmp("off", s, len) == 0)
+       else if (strncasecmp("of", s, 2) == 0)
                *res = false;
        else
                return (-EINVAL);

Reply via email to