libvmmapi: Fix warnings and stop overridding WARNS

- Avoid shadowing the global optarg.
- Sprinkle __unused.
- Cast nitems() to int.
- Fix sign in vm_copy_setup().

Reviewed by:	grehan
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31306
This commit is contained in:
Mark Johnston 2021-07-26 16:40:16 -04:00
parent ba21825202
commit 45cd18ec73
2 changed files with 17 additions and 19 deletions

View file

@ -5,8 +5,6 @@ LIB= vmmapi
SRCS= vmmapi.c vmmapi_freebsd.c
INCS= vmmapi.h
WARNS?= 2
LIBADD= util
CFLAGS+= -I${.CURDIR}

View file

@ -111,7 +111,7 @@ vm_create(const char *name)
/* Try to load vmm(4) module before creating a guest. */
if (modfind("vmm") < 0)
kldload("vmm");
return (CREATE((char *)name));
return (CREATE(name));
}
struct vmctx *
@ -153,14 +153,14 @@ vm_destroy(struct vmctx *vm)
}
int
vm_parse_memsize(const char *optarg, size_t *ret_memsize)
vm_parse_memsize(const char *opt, size_t *ret_memsize)
{
char *endptr;
size_t optval;
int error;
optval = strtoul(optarg, &endptr, 0);
if (*optarg != '\0' && *endptr == '\0') {
optval = strtoul(opt, &endptr, 0);
if (*opt != '\0' && *endptr == '\0') {
/*
* For the sake of backward compatibility if the memory size
* specified on the command line is less than a megabyte then
@ -171,7 +171,7 @@ vm_parse_memsize(const char *optarg, size_t *ret_memsize)
*ret_memsize = optval;
error = 0;
} else
error = expand_number(optarg, ret_memsize);
error = expand_number(opt, ret_memsize);
return (error);
}
@ -729,7 +729,7 @@ vm_inject_exception(struct vmctx *ctx, int vcpu, int vector, int errcode_valid,
}
int
vm_apicid2vcpu(struct vmctx *ctx, int apicid)
vm_apicid2vcpu(struct vmctx *ctx __unused, int apicid)
{
/*
* The apic id associated with the 'vcpu' has the same numerical value
@ -907,7 +907,7 @@ vm_capability_name2type(const char *capname)
{
int i;
for (i = 0; i < nitems(capstrmap); i++) {
for (i = 0; i < (int)nitems(capstrmap); i++) {
if (strcmp(capstrmap[i], capname) == 0)
return (i);
}
@ -918,7 +918,7 @@ vm_capability_name2type(const char *capname)
const char *
vm_capability_type2name(int type)
{
if (type >= 0 && type < nitems(capstrmap))
if (type >= 0 && type < (int)nitems(capstrmap))
return (capstrmap[type]);
return (NULL);
@ -1366,8 +1366,8 @@ vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
int *fault)
{
void *va;
uint64_t gpa;
int error, i, n, off;
uint64_t gpa, off;
int error, i, n;
for (i = 0; i < iovcnt; i++) {
iov[i].iov_base = 0;
@ -1381,7 +1381,7 @@ vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
return (error);
off = gpa & PAGE_MASK;
n = min(len, PAGE_SIZE - off);
n = MIN(len, PAGE_SIZE - off);
va = vm_map_gpa(ctx, gpa, n);
if (va == NULL)
@ -1399,14 +1399,14 @@ vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
}
void
vm_copy_teardown(struct vmctx *ctx, int vcpu, struct iovec *iov, int iovcnt)
vm_copy_teardown(struct vmctx *ctx __unused, int vcpu __unused,
struct iovec *iov __unused, int iovcnt __unused)
{
return;
}
void
vm_copyin(struct vmctx *ctx, int vcpu, struct iovec *iov, void *vp, size_t len)
vm_copyin(struct vmctx *ctx __unused, int vcpu __unused, struct iovec *iov,
void *vp, size_t len)
{
const char *src;
char *dst;
@ -1426,8 +1426,8 @@ vm_copyin(struct vmctx *ctx, int vcpu, struct iovec *iov, void *vp, size_t len)
}
void
vm_copyout(struct vmctx *ctx, int vcpu, const void *vp, struct iovec *iov,
size_t len)
vm_copyout(struct vmctx *ctx __unused, int vcpu __unused, const void *vp,
struct iovec *iov, size_t len)
{
const char *src;
char *dst;