git: ea717376822e - stable/13 - kldxref: Simplify elf_read_raw_data

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

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

commit ea717376822edc921a66f8b149ba3b6ca7536e8a
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:22 +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)