aboutsummaryrefslogtreecommitdiff
path: root/lib/libgeom
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2017-09-08 15:44:52 +0000
committerConrad Meyer <cem@FreeBSD.org>2017-09-08 15:44:52 +0000
commitb906c1a02a119261c1935b9a98853e2dd18b3494 (patch)
tree892d4c853aa08ec2b5bc20bcb5ea07010ed55235 /lib/libgeom
parent985f4b3eb540211f4b91f350c27f95815b1181af (diff)
downloadsrc-b906c1a02a119261c1935b9a98853e2dd18b3494.tar.gz
src-b906c1a02a119261c1935b9a98853e2dd18b3494.zip
libgeom: Remove redundant and duplicated code
In g_open(), g_device_path_open(). No functional change. Sponsored by: Dell EMC Isilon
Notes
Notes: svn path=/head/; revision=323316
Diffstat (limited to 'lib/libgeom')
-rw-r--r--lib/libgeom/geom_util.c77
1 files changed, 31 insertions, 46 deletions
diff --git a/lib/libgeom/geom_util.c b/lib/libgeom/geom_util.c
index 54844c6e451c..73c305a4201b 100644
--- a/lib/libgeom/geom_util.c
+++ b/lib/libgeom/geom_util.c
@@ -56,8 +56,6 @@ g_open(const char *name, int dowrite)
path = g_device_path_open(name, &fd, dowrite);
if (path != NULL)
free(path);
- if (fd == -1)
- return (-1);
return (fd);
}
@@ -281,58 +279,45 @@ g_device_path_open(const char *devpath, int *fdp, int dowrite)
/* Make sure that we can fail. */
if (fdp != NULL)
*fdp = -1;
+
/* Use the device node if we're able to open it. */
- do {
- fd = open(devpath, dowrite ? O_RDWR : O_RDONLY);
- if (fd == -1)
- break;
- /*
- * Let try to get sectorsize, which will prove it is a GEOM
- * provider.
- */
- if (g_sectorsize(fd) == -1) {
- close(fd);
- errno = EFTYPE;
- return (NULL);
- }
+ fd = open(devpath, dowrite ? O_RDWR : O_RDONLY);
+ if (fd != -1) {
if ((path = strdup(devpath)) == NULL) {
close(fd);
return (NULL);
}
- if (fdp != NULL)
- *fdp = fd;
- else
- close(fd);
- return (path);
- } while (0);
+ goto fd_ok;
+ }
/* If we're not given an absolute path, assume /dev/ prefix. */
- if (*devpath != '/') {
- asprintf(&path, "%s%s", _PATH_DEV, devpath);
- if (path == NULL)
- return (NULL);
- fd = open(path, dowrite ? O_RDWR : O_RDONLY);
- if (fd == -1) {
- free(path);
- return (NULL);
- }
- /*
- * Let try to get sectorsize, which will prove it is a GEOM
- * provider.
- */
- if (g_sectorsize(fd) == -1) {
- free(path);
- close(fd);
- errno = EFTYPE;
- return (NULL);
- }
- if (fdp != NULL)
- *fdp = fd;
- else
- close(fd);
- return (path);
+ if (*devpath == '/')
+ return (NULL);
+
+ asprintf(&path, "%s%s", _PATH_DEV, devpath);
+ if (path == NULL)
+ return (NULL);
+ fd = open(path, dowrite ? O_RDWR : O_RDONLY);
+ if (fd == -1) {
+ free(path);
+ return (NULL);
}
- return (NULL);
+
+fd_ok:
+ /*
+ * Let try to get sectorsize, which will prove it is a GEOM provider.
+ */
+ if (g_sectorsize(fd) == -1) {
+ free(path);
+ close(fd);
+ errno = EFTYPE;
+ return (NULL);
+ }
+ if (fdp != NULL)
+ *fdp = fd;
+ else
+ close(fd);
+ return (path);
}
char *