git: 87ed6840a0a6 - main - rtlbtfw(8): Load firmware from filesystem with mmap()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 24 Apr 2026 15:15:52 UTC
The branch main has been updated by wulf:
URL: https://cgit.FreeBSD.org/src/commit/?id=87ed6840a0a6320295f6abb43a987d20ae126cf7
commit 87ed6840a0a6320295f6abb43a987d20ae126cf7
Author: Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2026-04-24 15:15:22 +0000
Commit: Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2026-04-24 15:15:22 +0000
rtlbtfw(8): Load firmware from filesystem with mmap()
rather than with read() to alleviate concerns about partial reads.
---
usr.sbin/bluetooth/rtlbtfw/rtlbt_fw.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/usr.sbin/bluetooth/rtlbtfw/rtlbt_fw.c b/usr.sbin/bluetooth/rtlbtfw/rtlbt_fw.c
index d7e9f2f939c6..aadd254571bb 100644
--- a/usr.sbin/bluetooth/rtlbtfw/rtlbt_fw.c
+++ b/usr.sbin/bluetooth/rtlbtfw/rtlbt_fw.c
@@ -29,6 +29,7 @@
#include <sys/param.h>
#include <sys/endian.h>
+#include <sys/mman.h>
#include <sys/stat.h>
#include <err.h>
@@ -166,8 +167,7 @@ rtlbt_fw_read(struct rtlbt_firmware *fw, const char *fwname)
{
int fd;
struct stat sb;
- unsigned char *buf;
- ssize_t r;
+ unsigned char *buf, *mmap_addr;
fd = open(fwname, O_RDONLY);
if (fd < 0) {
@@ -188,23 +188,16 @@ rtlbt_fw_read(struct rtlbt_firmware *fw, const char *fwname)
return (0);
}
- /* XXX handle partial reads */
- r = read(fd, buf, sb.st_size);
- if (r < 0) {
- warn("%s: read", __func__);
+ mmap_addr = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (mmap_addr == MAP_FAILED) {
+ warn("%s: mmap: %s", __func__, fwname);
free(buf);
close(fd);
return (0);
}
- if (r != sb.st_size) {
- rtlbt_err("read len %d != file size %d",
- (int) r,
- (int) sb.st_size);
- free(buf);
- close(fd);
- return (0);
- }
+ memcpy(buf, mmap_addr, sb.st_size);
+ munmap(mmap_addr, sb.st_size);
/* We have everything, so! */