From owner-svn-src-head@freebsd.org Fri Sep 8 15:44:54 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1357CE1EBFB; Fri, 8 Sep 2017 15:44:54 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D5C0E376; Fri, 8 Sep 2017 15:44:53 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v88Fiqv5001395; Fri, 8 Sep 2017 15:44:52 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v88FiqbX001394; Fri, 8 Sep 2017 15:44:52 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201709081544.v88FiqbX001394@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Fri, 8 Sep 2017 15:44:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323316 - head/lib/libgeom X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/lib/libgeom X-SVN-Commit-Revision: 323316 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Sep 2017 15:44:54 -0000 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 *