git: 38effbdd2d8a - stable/14 - kldxref: Simplify elf_read_raw_data

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 18 Jan 2024 22:25:59 UTC
The branch stable/14 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=38effbdd2d8a033e1221d309517c4d4418018ec3

commit 38effbdd2d8a033e1221d309517c4d4418018ec3
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-12-22 15:49:03 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-01-18 21:31:20 +0000

    kldxref: Simplify elf_read_raw_data
    
    Use pread as a valid offset is always passed now.  Originally the DSO
    code read the .hash section in two separate requests and relied on the
    implicit offset for the second read, but now the hash table is fetched
    in a single call.
    
    Reviewed by:    imp
    Sponsored by:   DARPA
    Differential Revision:  https://reviews.freebsd.org/D43125
    
    (cherry picked from commit ed96fd7fc652d77ae5e34727e54610e87854defc)
---
 usr.sbin/kldxref/elf.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/usr.sbin/kldxref/elf.c b/usr.sbin/kldxref/elf.c
index f8a6510ed352..cc9bf9e6cb38 100644
--- a/usr.sbin/kldxref/elf.c
+++ b/usr.sbin/kldxref/elf.c
@@ -170,11 +170,7 @@ elf_read_raw_data(struct elf_file *efile, off_t offset, void *dst, size_t len)
 {
 	ssize_t nread;
 
-	if (offset != (off_t)-1) {
-		if (lseek(efile->ef_fd, offset, SEEK_SET) == -1)
-			return (EIO);
-	}
-	nread = read(efile->ef_fd, dst, len);
+	nread = pread(efile->ef_fd, dst, len, offset);
 	if (nread == -1)
 		return (errno);
 	if (nread != len)