Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Sep 2017 15:44:52 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r323316 - head/lib/libgeom
Message-ID:  <201709081544.v88FiqbX001394@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Fri Sep  8 15:44:52 2017
New Revision: 323316
URL: https://svnweb.freebsd.org/changeset/base/323316

Log:
  libgeom: Remove redundant and duplicated code
  
  In g_open(), g_device_path_open().
  
  No functional change.
  
  Sponsored by:	Dell EMC Isilon

Modified:
  head/lib/libgeom/geom_util.c

Modified: head/lib/libgeom/geom_util.c
==============================================================================
--- head/lib/libgeom/geom_util.c	Fri Sep  8 15:38:02 2017	(r323315)
+++ head/lib/libgeom/geom_util.c	Fri Sep  8 15:44:52 2017	(r323316)
@@ -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 
 	/* 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 *



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201709081544.v88FiqbX001394>