From nobody Fri Jan 13 00:36:57 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NtMtf28ZKz2sflH; Fri, 13 Jan 2023 00:36:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NtMtf1bwTz3P3S; Fri, 13 Jan 2023 00:36:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673570218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oQiutJ8TwuK7F8ENbC8ZCv92uvh+0cK4Pi8El/e88AM=; b=R8i0cteWR/L8mYrrO4TwnEOK20TPW9eEBwoQoRmJhIGt32aUmpcXs39Vr5xwN+UXRjvRec Cy9tuhX4gcc1dmex+E7+DyGdJVkkyD1efEC8Cb/eTXRyL3erB8yRgPZS8L5ElOH6lEuL7P ZlF5m1BEdTs66T/2JRAWbtN19AqXLev1i5w9nkrbBLPLmbmgB2qhYlQcgHbQGj39ISXJ9N qbW8ErUsjsDBVPRbb80JHrLyDH0JkVYaSdxrYlQkurb+Ydw+J98nCzOX46HJjJNyLtS7Lu 7nIbu2tTl4hbvsBSaaOJanRjT104Xv7qOChWy6VG0vT/sfMzxsErQntJK7U7JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673570218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oQiutJ8TwuK7F8ENbC8ZCv92uvh+0cK4Pi8El/e88AM=; b=GwmnK4YVcuc3juOoYqY7BrgtWvr4HHtHaj5l8WtRxnkhmQkI92sxAP1Yk8HPUuecFtTHw5 dQBgghNR4E9Y/PrenOAAQ9+aUFs+jYg0YDiQxfiZcHQ1w1frf8LarYTOmVIetFb8kI7TS6 31DySv29wT9i8YqwpBcSnOCuOk1Szszf32AwZUCk5eOItDhRVbZDhc56spxSpJyWGzmO+1 Xp5OigKKiIosLPADz0nhsytHqx9jVElFoDEeRfc1AyRQRQaUxXFZDv+mWgyThUYNdKyKD8 5Jf/y1UVMFw0UjghZ5gwsocFGcEg90FazLIKPsc3VicLcB2zg8ukLOPTgF7UUg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673570218; a=rsa-sha256; cv=none; b=Ytjd/6uVDV479l5SE0KWtEtNvi/gjjMRjxfumpAZoX0XgH5LituFO2R9umCBurkgwRTfNs mKXOYgWnsIC2DKSRe3gs3q/lt8Grauz3FgSeTrpux4fBioP40Ca9YB3h01VCUTsIdeLjMA WTYOmB8hvyTRIIXHhSqy78VnWN3tzwLeMmuFoXIWyy6diQy0z5hpULDqDDTWYzo3/Xdm5H +w8iycT+2Cvb/6ozCtw1GOh5C5plvQAJq4gI5vhCFQXhUxqabva+uUmHraIJh+LGx3NqG2 WwsAY3oa8nwZ73yEdtUwnRHuXHksnMGS4aF1UVIkp6mQ/pwrtv0zghHeVB+WJQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NtMtf0fQZznZx; Fri, 13 Jan 2023 00:36:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30D0avcL051073; Fri, 13 Jan 2023 00:36:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30D0avvi051072; Fri, 13 Jan 2023 00:36:57 GMT (envelope-from git) Date: Fri, 13 Jan 2023 00:36:57 GMT Message-Id: <202301130036.30D0avvi051072@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: f82cf28b317b - main - LinuxKPI: add kstrtou32_from_user() and mac_pton() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f82cf28b317b6b3ffd1418ab9c5b230145da8f75 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=f82cf28b317b6b3ffd1418ab9c5b230145da8f75 commit f82cf28b317b6b3ffd1418ab9c5b230145da8f75 Author: Bjoern A. Zeeb AuthorDate: 2022-10-22 18:02:58 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-01-13 00:34:32 +0000 LinuxKPI: add kstrtou32_from_user() and mac_pton() While here: - fix an argument of kstrtouint_from_user() to correct signedness. - make kstrtou32() call kstrtouint() to avoid duplication (keep inline function) Add kstrtou32_from_user() based on other examples in the file making it a copy of the now fixed kstrtouint_from_user(). Also add a rudimentarily hacked up version of mac_pton() which is leanient accepting non-well-formed input but so far only with ':' separators. It does not seem to obviously belong to any networking header file so add it here. Both new functions are needed for debugfs support for iwlwifi hence coming together in one commit. Sponsored by: The FreeBSD Foundation MFC after: 3 days Commented on by: emaste Differential Revision: https://reviews.freebsd.org/D37088 --- sys/compat/linuxkpi/common/include/linux/kernel.h | 65 ++++++++++++++++++----- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h index 3ae8f31832fd..54b558d0bea2 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -437,19 +437,8 @@ kstrtou16(const char *cp, unsigned int base, u16 *res) static inline int kstrtou32(const char *cp, unsigned int base, u32 *res) { - char *end; - unsigned long temp; - - *res = temp = strtoul(cp, &end, base); - /* skip newline character, if any */ - if (*end == '\n') - end++; - if (*cp == 0 || *end != 0) - return (-EINVAL); - if (temp != (u32)temp) - return (-ERANGE); - return (0); + return (kstrtouint(cp, base, res)); } static inline int @@ -530,7 +519,7 @@ kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, static inline int kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, - int *p) + unsigned int *p) { char buf[36] = {}; @@ -543,6 +532,14 @@ kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, return (kstrtouint(buf, base, p)); } +static inline int +kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, + unsigned int *p) +{ + + return (kstrtouint_from_user(s, count, base, p)); +} + static inline int kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *p) @@ -718,6 +715,48 @@ hex2bin(uint8_t *bindst, const char *hexsrc, size_t binlen) return (0); } +static inline bool +mac_pton(const char *macin, uint8_t *macout) +{ + const char *s, *d; + uint8_t mac[6], hx, lx;; + int i; + + if (strlen(macin) < (3 * 6 - 1)) + return (false); + + i = 0; + s = macin; + do { + /* Should we also support '-'-delimiters? */ + d = strchrnul(s, ':'); + hx = lx = 0; + while (s < d) { + /* Fail on abc:123:xxx:... */ + if ((d - s) > 2) + return (false); + /* We do support non-well-formed strings: 3:45:6:... */ + if ((d - s) > 1) { + hx = _h2b(*s); + if (hx < 0) + return (false); + s++; + } + lx = _h2b(*s); + if (lx < 0) + return (false); + s++; + } + mac[i] = (hx << 4) | lx; + i++; + if (i >= 6) + return (false); + } while (d != NULL && *d != '\0'); + + memcpy(macout, mac, 6); + return (true); +} + #define DECLARE_FLEX_ARRAY(_t, _n) \ struct { struct { } __dummy_ ## _n; _t _n[0]; }