git: 66206e00de17 - stable/14 - linuxkpi: Correct kstrtobool

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Mon, 12 Jan 2026 17:19:28 UTC
The branch stable/14 has been updated by des:

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

commit 66206e00de17f929a863f92c11cbb2938796beed
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-01-03 09:09:41 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-01-11 02:30:31 +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
    
    (cherry picked from commit f86148d2777d4d7985ed8f4ae957c41c44bd2484)
---
 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);