From nobody Sun Jan 16 23:20:54 2022 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 2423F19678C8; Sun, 16 Jan 2022 23:20:55 +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 4JcWHW0Lvbz3mDc; Sun, 16 Jan 2022 23:20:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642375255; 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=FyCh4bHuEfesNqZORKl1qH4aNf0rfOe26D/4M3SCW4w=; b=kFfArSP7e3Iph4w1XXygTdtPRHf93k+yWrWLUBL6K07pH5vbPb1cy87+V6hN3WWIR3fYdx oi5V6GMzMOz5VwPdFyD/FGXkeyHK4wLIsqkh7HIXPFE6U8TRZiIl32t6vrdN/IcJlQU9sd nBTLX7273Vs1ppqnDn+tA5EhB3fc793coaT1Lhj8FuhjejpdF0aXTSnkQo072ZB1t3fDde kuUuvoX1M18aZTTJ3L1AURngz9wQZ+VzxsT4XXEaq2AU5YFrTkJ9kkCADr2NguB7xh6lL9 eYzF04xNLHu7G3VN1NTRV1z8C3McmpgnAfkgZXrIqWz+/PAoBkPMhPSqBOa4eQ== 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 E20B622CDF; Sun, 16 Jan 2022 23:20:54 +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 20GNKsLH052694; Sun, 16 Jan 2022 23:20:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20GNKswY052693; Sun, 16 Jan 2022 23:20:54 GMT (envelope-from git) Date: Sun, 16 Jan 2022 23:20:54 GMT Message-Id: <202201162320.20GNKswY052693@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: f88fcc52d888 - stable/13 - LinuxKPI: add hex2bin() 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: f88fcc52d888ce3d1be5b602964a42d8b3d90bc3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642375255; 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=FyCh4bHuEfesNqZORKl1qH4aNf0rfOe26D/4M3SCW4w=; b=tgp2FpePQvrAnHRVOYsGY1mJIJdBnUF91kgrdcP4x5sOxcMdKnbUlgJ9WkTbq6vmY8Cz4d iLXN760DyWiBM0OM9BFjJrKqmcpFOTZ19IHiaeM4ln5tz2c4aNMTABqEdI5FJ7KkKn/IfE 4sEwGE43ICPm1t7Aode3rORRUb+NP2JBIyLZxzZdjiP87kUBX1Wd9/thFH1KHqzs+s2uTR v1uorhXcVk6LbOdwl4xnJpwpefez2KYUQj9LwJy/g+gEnT+Q2ydydhv9gKgD4sJCp8w5+z ClD15CKHgtReqgrQ6bvpar5XC7ClyKTuM7ti69IDKfXJ81lHj7h0R73q+QNcIQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642375255; a=rsa-sha256; cv=none; b=Wgbi0GitAUT4UhjeIYiPzv7B3mZVTdMv8qIP5mfgJAGmQT1ibuObcwtLaG9i5y2v9QpB4n Vl2DVbCMTcDedvZRBclGgE15ZcTyZmzaYbU3aDfGqHO4owN+M3VsiLm97n4Y+YSUICCZbz KTj0MX3pRXH1/3hX+ux88je6DLWroWGmXr0hP8RdKpOAPkIBx/UJXFfdeAJV55BjIoCU1f S09CtpgY+TpRzIc8FwstiJUNrW1WKj2fzZ6m46xAPU1c0GaSODe2BP5i+xZxHsyO9NEWWB 2o8iBOx33A+YkNG5r42qDj2/e7TockbDSabT57Pczs3XXFy8587FugyEMAb0hw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=f88fcc52d888ce3d1be5b602964a42d8b3d90bc3 commit f88fcc52d888ce3d1be5b602964a42d8b3d90bc3 Author: Bjoern A. Zeeb AuthorDate: 2022-01-09 01:09:17 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-01-16 22:38:48 +0000 LinuxKPI: add hex2bin() Add a hex2bin() implementation needed by a driver's debugfs code. Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D33798 (cherry picked from commit deb9bfbd5bcea70c79f70c7091c35d399b40fb0a) --- 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 c67a9b8e22b0..8690d9efa1f2 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