summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authoranton <anton@cvs.openbsd.org>2019-08-06 07:16:49 +0000
committeranton <anton@cvs.openbsd.org>2019-08-06 07:16:49 +0000
commit26c3391758b5c6627f2788b54f3f54ad227ec7f3 (patch)
tree0ad299b2347a3f4584465f9976f2ada9160cea53 /sys
parentab31e00b3249546be36fbd66f2be5ddc9ea0ab66 (diff)
Resolve some minor nits in diskmapioctl():
* Favor ENOTTY for unknown ioctl commands * Return the actual error from copyinstr and copyoutstr, removes the need to initialize the local error variable * Do not use parens around return expressions consistently ok visa@
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/diskmap.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/sys/dev/diskmap.c b/sys/dev/diskmap.c
index e035ee36466..d7293e2b115 100644
--- a/sys/dev/diskmap.c
+++ b/sys/dev/diskmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diskmap.c,v 1.25 2019/08/05 08:46:46 anton Exp $ */
+/* $OpenBSD: diskmap.c,v 1.26 2019/08/06 07:16:48 anton Exp $ */
/*
* Copyright (c) 2009, 2010 Joel Sing <jsing@openbsd.org>
@@ -60,10 +60,10 @@ diskmapioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
struct file *fp0 = NULL, *fp = NULL;
struct vnode *vp = NULL;
char *devname, flags;
- int fd, error = EINVAL;
+ int error, fd;
if (cmd != DIOCMAP)
- return EINVAL;
+ return ENOTTY;
/*
* Map a request for a disk to the correct device. We should be
@@ -73,11 +73,13 @@ diskmapioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
dm = (struct dk_diskmap *)addr;
fd = dm->fd;
devname = malloc(PATH_MAX, M_DEVBUF, M_WAITOK);
- if (copyinstr(dm->device, devname, PATH_MAX, NULL))
+ if ((error = copyinstr(dm->device, devname, PATH_MAX, NULL)) != 0)
goto invalid;
- if (disk_map(devname, devname, PATH_MAX, dm->flags) == 0)
- if (copyoutstr(devname, dm->device, PATH_MAX, NULL))
+ if (disk_map(devname, devname, PATH_MAX, dm->flags) == 0) {
+ error = copyoutstr(devname, dm->device, PATH_MAX, NULL);
+ if (error != 0)
goto invalid;
+ }
/* Attempt to open actual device. */
if ((error = getvnode(p, fd, &fp0)) != 0)
@@ -142,7 +144,7 @@ invalid:
free(devname, M_DEVBUF, PATH_MAX);
- return (error);
+ return error;
}
int