This are obvious and easy to fix unused but set variables.
There are more in vioscsi.c but those are actually used if compiled with
DEBUG set.
--
:wq Claudio
Index: loadfile_elf.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/loadfile_elf.c,v
retrieving revision 1.40
diff -u -p -r1.40 loadfile_elf.c
--- loadfile_elf.c 30 Dec 2021 08:12:23 -0000 1.40
+++ loadfile_elf.c 4 Jan 2022 09:46:07 -0000
@@ -499,7 +499,7 @@ mread(gzFile fp, paddr_t addr, size_t sz
const char *errstr = NULL;
int errnum = 0;
size_t ct;
- size_t i, rd, osz;
+ size_t i, osz;
char buf[PAGE_SIZE];
/*
@@ -507,7 +507,6 @@ mread(gzFile fp, paddr_t addr, size_t sz
* write_mem
*/
ct = 0;
- rd = 0;
osz = sz;
if ((addr & PAGE_MASK) != 0) {
memset(buf, 0, sizeof(buf));
@@ -524,7 +523,6 @@ mread(gzFile fp, paddr_t addr, size_t sz
errnum, errstr);
return (0);
}
- rd += ct;
if (write_mem(addr, buf, ct))
return (0);
@@ -552,7 +550,6 @@ mread(gzFile fp, paddr_t addr, size_t sz
errnum, errstr);
return (0);
}
- rd += ct;
if (write_mem(addr, buf, ct))
return (0);
@@ -678,7 +675,6 @@ elf64_exec(gzFile fp, Elf64_Ehdr *elf, u
Elf64_Off off;
int i;
size_t sz;
- int first;
int havesyms;
paddr_t minp = ~0, maxp = 0, pos = 0;
paddr_t offset = marks[MARK_START], shpp, elfp;
@@ -696,7 +692,7 @@ elf64_exec(gzFile fp, Elf64_Ehdr *elf, u
return 1;
}
- for (first = 1, i = 0; i < elf->e_phnum; i++) {
+ for (i = 0; i < elf->e_phnum; i++) {
if (phdr[i].p_type == PT_OPENBSD_RANDOMIZE) {
int m;
@@ -741,8 +737,6 @@ elf64_exec(gzFile fp, Elf64_Ehdr *elf, u
free(phdr);
return 1;
}
-
- first = 0;
}
if ((IS_TEXT(phdr[i]) && (flags & (LOAD_TEXT | COUNT_TEXT))) ||
@@ -816,7 +810,7 @@ elf64_exec(gzFile fp, Elf64_Ehdr *elf, u
if (shp[i].sh_type == SHT_SYMTAB)
havesyms = 1;
- for (first = 1, i = 0; i < elf->e_shnum; i++) {
+ for (i = 0; i < elf->e_shnum; i++) {
if (shp[i].sh_type == SHT_SYMTAB ||
shp[i].sh_type == SHT_STRTAB ||
!strcmp(shstr + shp[i].sh_name, ".debug_line") ||
@@ -841,7 +835,6 @@ elf64_exec(gzFile fp, Elf64_Ehdr *elf, u
shp[i].sh_flags |= SHF_ALLOC;
off += roundup(shp[i].sh_size,
sizeof(Elf64_Addr));
- first = 0;
}
}
if (flags & LOAD_SYM) {
@@ -900,7 +893,6 @@ elf32_exec(gzFile fp, Elf32_Ehdr *elf, u
Elf32_Off off;
int i;
size_t sz;
- int first;
int havesyms;
paddr_t minp = ~0, maxp = 0, pos = 0;
paddr_t offset = marks[MARK_START], shpp, elfp;
@@ -918,7 +910,7 @@ elf32_exec(gzFile fp, Elf32_Ehdr *elf, u
return 1;
}
- for (first = 1, i = 0; i < elf->e_phnum; i++) {
+ for (i = 0; i < elf->e_phnum; i++) {
if (phdr[i].p_type == PT_OPENBSD_RANDOMIZE) {
int m;
@@ -963,8 +955,6 @@ elf32_exec(gzFile fp, Elf32_Ehdr *elf, u
free(phdr);
return 1;
}
-
- first = 0;
}
if ((IS_TEXT(phdr[i]) && (flags & (LOAD_TEXT | COUNT_TEXT))) ||
@@ -1038,7 +1028,7 @@ elf32_exec(gzFile fp, Elf32_Ehdr *elf, u
if (shp[i].sh_type == SHT_SYMTAB)
havesyms = 1;
- for (first = 1, i = 0; i < elf->e_shnum; i++) {
+ for (i = 0; i < elf->e_shnum; i++) {
if (shp[i].sh_type == SHT_SYMTAB ||
shp[i].sh_type == SHT_STRTAB ||
!strcmp(shstr + shp[i].sh_name, ".debug_line")) {
@@ -1062,7 +1052,6 @@ elf32_exec(gzFile fp, Elf32_Ehdr *elf, u
shp[i].sh_flags |= SHF_ALLOC;
off += roundup(shp[i].sh_size,
sizeof(Elf32_Addr));
- first = 0;
}
}
if (flags & LOAD_SYM) {
Index: vioqcow2.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/vioqcow2.c,v
retrieving revision 1.16
diff -u -p -r1.16 vioqcow2.c
--- vioqcow2.c 16 Jun 2021 16:55:02 -0000 1.16
+++ vioqcow2.c 4 Jan 2022 09:50:31 -0000
@@ -518,7 +518,7 @@ mkcluster(struct qcdisk *disk, struct qc
orig = l2tab & ~QCOW2_INPLACE;
l2tab = disk->end;
disk->end += disk->clustersz;
- if (ftruncate(disk->fd, disk->end) == -1)
+ if (ftruncate(fd, disk->end) == -1)
fatal("%s: ftruncate failed", __func__);
/*
@@ -534,19 +534,19 @@ mkcluster(struct qcdisk *disk, struct qc
l2tab &= ~QCOW2_INPLACE;
/* Grow the disk */
- if (ftruncate(disk->fd, disk->end + disk->clustersz) < 0)
+ if (ftruncate(fd, disk->end + disk->clustersz) < 0)
fatalx("%s: could not grow disk", __func__);
if (src_phys > 0)
copy_cluster(disk, base, disk->end, src_phys);
cluster = disk->end;
disk->end += disk->clustersz;
buf = htobe64(cluster | QCOW2_INPLACE);
- if (pwrite(disk->fd, &buf, sizeof(buf), l2tab + l2off * 8) != 8)
+ if (pwrite(fd, &buf, sizeof(buf), l2tab + l2off * 8) != 8)
fatalx("%s: could not write cluster", __func__);
/* TODO: lazily sync: currently VMD doesn't close things */
buf = htobe64(disk->l1[l1off]);
- if (pwrite(disk->fd, &buf, sizeof(buf), disk->l1off + 8 * l1off) != 8)
+ if (pwrite(fd, &buf, sizeof(buf), disk->l1off + 8 * l1off) != 8)
fatalx("%s: could not write l1", __func__);
inc_refs(disk, cluster, 1);
Index: vmd.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/vmd.c,v
retrieving revision 1.128
diff -u -p -r1.128 vmd.c
--- vmd.c 13 Dec 2021 18:28:40 -0000 1.128
+++ vmd.c 4 Jan 2022 09:44:26 -0000
@@ -1421,7 +1421,6 @@ vm_instance(struct privsep *ps, struct v
struct vm_create_params *vcpp;
struct vmd_vm *vm = NULL;
unsigned int i, j;
- uint32_t id;
/* return without error if the parent is NULL (nothing to inherit) */
if ((vmc->vmc_flags & VMOP_CREATE_INSTANCE) == 0 ||
@@ -1442,7 +1441,6 @@ vm_instance(struct privsep *ps, struct v
return (ENAMETOOLONG);
}
- id = vcp->vcp_id;
name = vcp->vcp_name;
if ((vm = vm_getbyname(vcp->vcp_name)) != NULL ||
Index: vmm.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/vmm.c,v
retrieving revision 1.102
diff -u -p -r1.102 vmm.c
--- vmm.c 29 Nov 2021 05:17:35 -0000 1.102
+++ vmm.c 4 Jan 2022 09:44:57 -0000
@@ -102,7 +102,7 @@ int
vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
{
struct privsep *ps = p->p_ps;
- int res = 0, cmd = 0, verbose, ret;
+ int res = 0, cmd = 0, verbose;
struct vmd_vm *vm = NULL;
struct vm_terminate_params vtp;
struct vmop_id vid;
@@ -278,7 +278,7 @@ vmm_dispatch_parent(int fd, struct privs
case IMSG_VMDOP_RECEIVE_VM_REQUEST:
IMSG_SIZE_CHECK(imsg, &vmc);
memcpy(&vmc, imsg->data, sizeof(vmc));
- ret = vm_register(ps, &vmc, &vm,
+ vm_register(ps, &vmc, &vm,
imsg->hdr.peerid, vmc.vmc_owner.uid);
vm->vm_tty = imsg->fd;
vm->vm_state |= VM_STATE_RECEIVED;