From nobody Sun Jan 09 14:38:21 2022 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 A5BAC1934C12; Sun, 9 Jan 2022 14:38:21 +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 4JX01n2h0pz3m2v; Sun, 9 Jan 2022 14:38:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 3C72F14090; Sun, 9 Jan 2022 14:38:21 +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 209EcL0T057841; Sun, 9 Jan 2022 14:38:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 209EcL4D057840; Sun, 9 Jan 2022 14:38:21 GMT (envelope-from git) Date: Sun, 9 Jan 2022 14:38:21 GMT Message-Id: <202201091438.209EcL4D057840@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: deb9bfbd5bce - main - LinuxKPI: add hex2bin() 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: deb9bfbd5bcea70c79f70c7091c35d399b40fb0a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641739101; 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=RPlAgqCeMwPJc7cn2v0xZEmV47E69/tZQ9ZKNYeuYNg=; b=uDpNmGTyx/Uh1VJxFZ5Q6ZrzyjGwlZGfiFB/SLCR/c2Q4A6kDzLAwYiqqUB347ToHvNCa/ Kui4UdAOk07fzONw/MgWDuP7PmBHrp/YXeI8csPHi2sUUkX0w0mV2ZVDIUDKJIhbzGPD0K rd9izevn+ZVCuW+v/FBmQuehZm9ktmCD9XDu+c/t5AE/UUJZYeYIpVwu1dL3nv0bu+uGY7 Uj+TDowtKtrLGhu501BvgJyicePhn5U7bluAEo3oxxnEdeAzA4H1p1oYOxYehpqfM6brZM SLH+AayRsSdYhHD1++z0NhBbt/dgXOciNAZY66798C7UVrFaIqrzqOc3ggAv/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641739101; a=rsa-sha256; cv=none; b=X7RxkKMExBcwjdLtRFWUGBUINZL6p8guHWvsTG8aARH9iT2gnBGNltDnnMCKvqiV5iYv8Y nfoQ7mst8mj2Sj8bB+wraNU/7tCMYuDa8Wl0QCM0y50n4m8/GgFYkE3IG7g3ZDyBKVeYdv yOlbVYwf4CSKyNkOIvfNjvOE+vyLBvBubixDnJyXAM5UTCqogQYFoBrP9cK745Xyu9pIzF smqeuoleABHUMAPWj/qCvP7djoIagiYvbxfctJBRFnk8ecHj8ISxZF6+fsEWz9yTEAQmSD wIvyYN955ISoXpmscmtw4yvDT6kkASx27+Aw6ySAcwVz/Z2dDeIbO7eIOiFN/Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=deb9bfbd5bcea70c79f70c7091c35d399b40fb0a commit deb9bfbd5bcea70c79f70c7091c35d399b40fb0a Author: Bjoern A. Zeeb AuthorDate: 2022-01-09 01:09:17 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-01-09 14:36:28 +0000 LinuxKPI: add hex2bin() Add a hex2bin() implementation needed by a driver's debugfs code. MFC after: 3 days Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D33798 --- sys/compat/linuxkpi/common/include/linux/kernel.h | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h index 94af8f29c4d7..80b684745175 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -649,6 +649,37 @@ linux_ratelimited(linux_ratelimit_t *rl) #define TAINT_WARN 0 #define test_taint(x) (0) +static inline int +_h2b(const char c) +{ + + if (c >= '0' && c <= '9') + return (c - '0'); + if (c >= 'a' && c <= 'f') + return (10 + c - 'a'); + if (c >= 'A' && c <= 'F') + return (10 + c - 'A'); + return (-EINVAL); +} + +static inline int +hex2bin(uint8_t *bindst, const char *hexsrc, size_t binlen) +{ + int hi4, lo4; + + while (binlen > 0) { + hi4 = _h2b(*hexsrc++); + lo4 = _h2b(*hexsrc++); + if (hi4 < 0 || lo4 < 0) + return (-EINVAL); + + *bindst++ = (hi4 << 4) | lo4; + binlen--; + } + + return (0); +} + /* * Checking if an option is defined would be easy if we could do CPP inside CPP. * The defined case whether -Dxxx or -Dxxx=1 are easy to deal with. In either