From owner-dev-commits-src-all@freebsd.org Sun Sep 26 06:34:32 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2A9C2672847; Sun, 26 Sep 2021 06:34:32 +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 4HHGG00RXdz3CFM; Sun, 26 Sep 2021 06:34:32 +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 E396019050; Sun, 26 Sep 2021 06:34:31 +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 18Q6YVj2063932; Sun, 26 Sep 2021 06:34:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18Q6YVUI063931; Sun, 26 Sep 2021 06:34:31 GMT (envelope-from git) Date: Sun, 26 Sep 2021 06:34:31 GMT Message-Id: <202109260634.18Q6YVUI063931@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Xin LI Subject: git: cb17f4a6bdaf - main - kern_ctf: Use zlib's uncompress function for simpler code. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: delphij X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cb17f4a6bdaf133bdc658b8ed92ad2c62eff8a18 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Sep 2021 06:34:32 -0000 The branch main has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=cb17f4a6bdaf133bdc658b8ed92ad2c62eff8a18 commit cb17f4a6bdaf133bdc658b8ed92ad2c62eff8a18 Author: Yoshihiro Ota AuthorDate: 2021-09-26 06:28:43 +0000 Commit: Xin LI CommitDate: 2021-09-26 06:33:00 +0000 kern_ctf: Use zlib's uncompress function for simpler code. Reviewed by: markj, delphij MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D21531 --- sys/kern/kern_ctf.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/sys/kern/kern_ctf.c b/sys/kern/kern_ctf.c index 6a6a08033137..ee7576ab6fb9 100644 --- a/sys/kern/kern_ctf.c +++ b/sys/kern/kern_ctf.c @@ -244,7 +244,7 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) /* Check if decompression is required. */ if (raw != NULL) { - z_stream zs; + uLongf destlen; int ret; /* @@ -253,22 +253,12 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) */ bcopy(ctf_hdr, ctftab, sizeof(ctf_hdr)); - /* Initialise the zlib structure. */ - bzero(&zs, sizeof(zs)); - - if (inflateInit(&zs) != Z_OK) { - error = EIO; - goto out; - } - - zs.avail_in = shdr[i].sh_size - sizeof(ctf_hdr); - zs.next_in = ((uint8_t *) raw) + sizeof(ctf_hdr); - zs.avail_out = sz - sizeof(ctf_hdr); - zs.next_out = ((uint8_t *) ctftab) + sizeof(ctf_hdr); - ret = inflate(&zs, Z_FINISH); - inflateEnd(&zs); - if (ret != Z_STREAM_END) { - printf("%s(%d): zlib inflate returned %d\n", __func__, __LINE__, ret); + destlen = sz - sizeof(ctf_hdr); + ret = uncompress(((uint8_t *) ctftab) + sizeof(ctf_hdr), + &destlen, ((uint8_t *) raw) + sizeof(ctf_hdr), + shdr[i].sh_size - sizeof(ctf_hdr)); + if (ret != Z_OK) { + printf("%s(%d): zlib uncompress returned %d\n", __func__, __LINE__, ret); error = EIO; goto out; }