bhyve/virtio: Fix comparison of integer expressions of different signedness

It's a bit silly to have iov_to_buf() and buf_to_iov() return a ssize_t
to begin with, just to be able to return -1 for error. Change this to
size_t and use 0 as an error indicator, which won't require any changes
to the code using these functions.

While here, switch iov_to_buf() to use reallocf() instead of realloc().

Reviewed by: jhb
Fixes: 2a514d377b ("bhyve/virtio-scsi: Preallocate all I/O requests")
Differential Revision: https://reviews.freebsd.org/D55800
This commit is contained in:
Hans Rosenfeld
2026-03-09 19:10:54 +01:00
committed by Ed Maste
parent d0afead876
commit 970e0db1c3
2 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -110,16 +110,16 @@ check_iov_len(const struct iovec *iov, size_t niov, size_t len)
return (false);
}
ssize_t
size_t
iov_to_buf(const struct iovec *iov, size_t niov, void **buf)
{
size_t ptr, total;
size_t i;
total = count_iov(iov, niov);
*buf = realloc(*buf, total);
*buf = reallocf(*buf, total);
if (*buf == NULL)
return (-1);
return (0);
for (i = 0, ptr = 0; i < niov; i++) {
memcpy((uint8_t *)*buf + ptr, iov[i].iov_base, iov[i].iov_len);
@@ -129,7 +129,7 @@ iov_to_buf(const struct iovec *iov, size_t niov, void **buf)
return (total);
}
ssize_t
size_t
buf_to_iov(const void *buf, size_t buflen, const struct iovec *iov, size_t niov)
{
size_t off = 0, len;
@@ -141,5 +141,5 @@ buf_to_iov(const void *buf, size_t buflen, const struct iovec *iov, size_t niov)
off += len;
}
return ((ssize_t)off);
return (off);
}
+2 -2
View File
@@ -40,7 +40,7 @@
struct iovec *split_iov(struct iovec *, size_t *, size_t, size_t *);
size_t count_iov(const struct iovec *, size_t);
bool check_iov_len(const struct iovec *, size_t, size_t);
ssize_t iov_to_buf(const struct iovec *, size_t, void **);
ssize_t buf_to_iov(const void *, size_t, const struct iovec *, size_t);
size_t iov_to_buf(const struct iovec *, size_t, void **);
size_t buf_to_iov(const void *, size_t, const struct iovec *, size_t);
#endif /* _IOV_H_ */