From nobody Wed Jan 18 16:25:04 2023 X-Original-To: dev-commits-src-branches@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 4NxrhL2hQYz2yJNS; Wed, 18 Jan 2023 16:25:06 +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 4NxrhJ46sdz3FdL; Wed, 18 Jan 2023 16:25:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674059104; 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=1bOrLOlMwwooxrqFSe4MVbTOeyrHb8AIGtIguwckbEQ=; b=xASR3k5cWG1O6Jtl0OozqaHOI1ZG1REvua5nn9BdDfQWe6q7FSbd6xGRID4PJMQL3ug7ET 70stmKvnb2ReCcWsQmFu1tLa20m5j4lFs5P2FqAmClemQf7Ktt/Suo25smhFXD8qi7qL81 J67376XhRnCVN917YSsUnYCAvP8EhsEfV3EQqWiTTj7CYb4WaGGhBdU3mmunApkDSTzFr1 6fzDnHNK53cWtRQaY8FUfj+YMvs+2c3vKbIZE7CZClC4rksaNbbBWVwUgxdsnc7++W9qFy jd00E5pMdgc806KX6htV9vl2GxH2aMIk9jogzR0vPylah75wzuP0ytDXreLEBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674059104; 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=1bOrLOlMwwooxrqFSe4MVbTOeyrHb8AIGtIguwckbEQ=; b=wAoZGx85Q4/9vGZyBzf5SQrqZXn7OQDj5zFkbIlP7ue4CdrMTEDjzZ/vqKJW/aIP9Daep1 cWHzBgHDwnvIeZavQRv04nDutUyik9nclpE+7XVmKb05V4ZnH57X3PnbQ0QiKJAbrGZVhx sGuiAiMSAuiVgHzW+iAESK+SeN7DhHH55NuHQuASPmC2EPieaKFgRPX1IIu/m+nOxuby67 lgJ+Vy2yN8TEwgsbA4NzPFlkSchZbBSbh8O/fRF5+bKDRo9EilbMi8USkK4E03Pf3WE8I2 DR7ssjYl3XNW7U8VY6Y2Ks9+5NrIfRNHdK9CNCwSNMFgnRCcXffd+evRvGy4IA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674059104; a=rsa-sha256; cv=none; b=hXom7I10HMN9KSulflHJ70bzXKCtn3JEN5e6VVQEGfLvSNx6Um9K2Dui3KqWiIzSY8MeW4 hZSHSGtMF2IuOM8QIEMKy4DtdeoZziaPSNmqIqpUaoChDxSoDJX1NUVtHJNBG9IEq+9eUI RSfElsvZtk+fs1hUYG9wuTqWPHq5NYaq0e4iybfC+u+I0PbvuXwzwO9ebwZ1VGgnbOY2Ix /ptxkW5fLpbuUz+yCfIOwFzX6QVu0amaXtf6xCeHdOmD6Z+6LqxeUHwidVNmuIIYNgj2YS ldr9SeQ69t3BYvi5GUp7M7SxaHt9oJ8QE2CkiSU3UP1NIjoesZbm2NVoiZyX7Q== 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 4NxrhJ2nQ3zHc1; Wed, 18 Jan 2023 16:25:04 +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 30IGP4xw038282; Wed, 18 Jan 2023 16:25:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30IGP42c038281; Wed, 18 Jan 2023 16:25:04 GMT (envelope-from git) Date: Wed, 18 Jan 2023 16:25:04 GMT Message-Id: <202301181625.30IGP42c038281@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: b1479a5409cf - stable/13 - LinuxKPI: add kstrtou32_from_user() and mac_pton() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: b1479a5409cfe186b45322dbed034f024bfc6ed0 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=b1479a5409cfe186b45322dbed034f024bfc6ed0 commit b1479a5409cfe186b45322dbed034f024bfc6ed0 Author: Bjoern A. Zeeb AuthorDate: 2022-10-22 18:02:58 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-01-18 13:26:37 +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 Commented on by: emaste Differential Revision: https://reviews.freebsd.org/D37088 (cherry picked from commit f82cf28b317b6b3ffd1418ab9c5b230145da8f75) --- 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 2c40b2f33c41..f3078d94b2b5 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) @@ -716,6 +713,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]; }