vmm: Fix compiling error with BHYVE_SNAPSHOT

The return values of copyin() and copyout() must be checked.
vm_snapshot_buf_cmp() is unused by the kernel and was incorrectly
implemented, so just remove it.

Reviewed by:	markj
Sponsored by:	vStack
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D43754
This commit is contained in:
Vitaliy Gusev 2024-02-06 10:36:17 -05:00 committed by Mark Johnston
parent df64d7c8c8
commit 7572fe89ad
2 changed files with 12 additions and 39 deletions

View file

@ -98,8 +98,6 @@ void vm_snapshot_buf_err(const char *bufname, const enum vm_snapshot_op op);
int vm_snapshot_buf(void *data, size_t data_size,
struct vm_snapshot_meta *meta);
size_t vm_get_snapshot_size(struct vm_snapshot_meta *meta);
int vm_snapshot_buf_cmp(void *data, size_t data_size,
struct vm_snapshot_meta *meta);
#define SNAPSHOT_BUF_OR_LEAVE(DATA, LEN, META, RES, LABEL) \
do { \
@ -113,6 +111,10 @@ do { \
#define SNAPSHOT_VAR_OR_LEAVE(DATA, META, RES, LABEL) \
SNAPSHOT_BUF_OR_LEAVE(&(DATA), sizeof(DATA), (META), (RES), LABEL)
#ifndef _KERNEL
int vm_snapshot_buf_cmp(void *data, size_t data_size,
struct vm_snapshot_meta *meta);
/* compare the value in the meta buffer with the data */
#define SNAPSHOT_BUF_CMP_OR_LEAVE(DATA, LEN, META, RES, LABEL) \
do { \
@ -126,4 +128,5 @@ do { \
#define SNAPSHOT_VAR_CMP_OR_LEAVE(DATA, META, RES, LABEL) \
SNAPSHOT_BUF_CMP_OR_LEAVE(&(DATA), sizeof(DATA), (META), (RES), LABEL)
#endif /* _KERNEL */
#endif

View file

@ -57,7 +57,7 @@ int
vm_snapshot_buf(void *data, size_t data_size, struct vm_snapshot_meta *meta)
{
struct vm_snapshot_buffer *buffer;
int op;
int op, error;
buffer = &meta->buffer;
op = meta->op;
@ -68,11 +68,14 @@ vm_snapshot_buf(void *data, size_t data_size, struct vm_snapshot_meta *meta)
}
if (op == VM_SNAPSHOT_SAVE)
copyout(data, buffer->buf, data_size);
error = copyout(data, buffer->buf, data_size);
else if (op == VM_SNAPSHOT_RESTORE)
copyin(buffer->buf, data, data_size);
error = copyin(buffer->buf, data, data_size);
else
return (EINVAL);
error = EINVAL;
if (error)
return (error);
buffer->buf += data_size;
buffer->buf_rem -= data_size;
@ -98,36 +101,3 @@ vm_get_snapshot_size(struct vm_snapshot_meta *meta)
return (length);
}
int
vm_snapshot_buf_cmp(void *data, size_t data_size, struct vm_snapshot_meta *meta)
{
struct vm_snapshot_buffer *buffer;
int op;
int ret;
buffer = &meta->buffer;
op = meta->op;
if (buffer->buf_rem < data_size) {
printf("%s: buffer too small\r\n", __func__);
ret = E2BIG;
goto done;
}
if (op == VM_SNAPSHOT_SAVE) {
ret = 0;
copyout(data, buffer->buf, data_size);
} else if (op == VM_SNAPSHOT_RESTORE) {
ret = memcmp(data, buffer->buf, data_size);
} else {
ret = EINVAL;
goto done;
}
buffer->buf += data_size;
buffer->buf_rem -= data_size;
done:
return (ret);
}