From owner-svn-src-head@FreeBSD.ORG Wed Sep 10 05:44:16 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 65EE9649; Wed, 10 Sep 2014 05:44:16 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 465529C9; Wed, 10 Sep 2014 05:44:16 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8A5iGPm035136; Wed, 10 Sep 2014 05:44:16 GMT (envelope-from grehan@FreeBSD.org) Received: (from grehan@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8A5iGQD035135; Wed, 10 Sep 2014 05:44:16 GMT (envelope-from grehan@FreeBSD.org) Message-Id: <201409100544.s8A5iGQD035135@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: grehan set sender to grehan@FreeBSD.org using -f From: Peter Grehan Date: Wed, 10 Sep 2014 05:44:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271350 - head/sys/dev/nmdm X-SVN-Group: head 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.18-1 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: Wed, 10 Sep 2014 05:44:16 -0000 Author: grehan Date: Wed Sep 10 05:44:15 2014 New Revision: 271350 URL: http://svnweb.freebsd.org/changeset/base/271350 Log: Fix issue with nmdm and leading zeros in device name. The nmdm code enforces a number between the 'nmdm' and 'A|B' portions of the device name. This is then used as a unit number, and sprintf'd back into the tty name. If leading zeros were used in the name, the created device name is different than the string used for the clone-open (e.g. /dev/nmdm0001A will result in /dev/nmdm1A). Since unit numbers are no longer required with the updated tty code, there seems to be no reason to force the string to be a number. The fix is to allow an arbitrary string between 'nmdm' and 'A|B', within the constraints of devfs names. This allows all existing user of numeric strings to continue to work, and also allows more meaningful names to be used, such as bhyve VM names. Tested on amd64, i386 and ppc64. Reported by: Dave Smith PR: 192281 Reviewed by: neel, glebius Phabric: D729 MFC after: 3 days Modified: head/sys/dev/nmdm/nmdm.c Modified: head/sys/dev/nmdm/nmdm.c ============================================================================== --- head/sys/dev/nmdm/nmdm.c Wed Sep 10 03:54:57 2014 (r271349) +++ head/sys/dev/nmdm/nmdm.c Wed Sep 10 05:44:15 2014 (r271350) @@ -157,21 +157,21 @@ nmdm_clone(void *arg, struct ucred *cred { struct nmdmsoftc *ns; struct tty *tp; - unsigned long unit; char *end; int error; + char endc; if (*dev != NULL) return; if (strncmp(name, "nmdm", 4) != 0) return; - - /* Device name must be "nmdm%lu%c", where %c is 'A' or 'B'. */ - name += 4; - unit = strtoul(name, &end, 10); - if (unit == ULONG_MAX || name == end) + if (strlen(name) <= strlen("nmdmX")) return; - if ((end[0] != 'A' && end[0] != 'B') || end[1] != '\0') + + /* Device name must be "nmdm%s%c", where %c is 'A' or 'B'. */ + end = name + strlen(name) - 1; + endc = *end; + if (endc != 'A' && endc != 'B') return; ns = malloc(sizeof(*ns), M_NMDM, M_WAITOK | M_ZERO); @@ -191,9 +191,11 @@ nmdm_clone(void *arg, struct ucred *cred /* Create device nodes. */ tp = ns->ns_part1.np_tty = tty_alloc_mutex(&nmdm_class, &ns->ns_part1, &ns->ns_mtx); - error = tty_makedevf(tp, NULL, end[0] == 'A' ? TTYMK_CLONING : 0, - "nmdm%luA", unit); + *end = 'A'; + error = tty_makedevf(tp, NULL, endc == 'A' ? TTYMK_CLONING : 0, + "%s", name); if (error) { + *end = endc; mtx_destroy(&ns->ns_mtx); free(ns, M_NMDM); return; @@ -201,9 +203,11 @@ nmdm_clone(void *arg, struct ucred *cred tp = ns->ns_part2.np_tty = tty_alloc_mutex(&nmdm_class, &ns->ns_part2, &ns->ns_mtx); - error = tty_makedevf(tp, NULL, end[0] == 'B' ? TTYMK_CLONING : 0, - "nmdm%luB", unit); + *end = 'B'; + error = tty_makedevf(tp, NULL, endc == 'B' ? TTYMK_CLONING : 0, + "%s", name); if (error) { + *end = endc; mtx_lock(&ns->ns_mtx); /* see nmdm_free() */ ns->ns_part1.np_other = NULL; @@ -212,11 +216,12 @@ nmdm_clone(void *arg, struct ucred *cred return; } - if (end[0] == 'A') + if (endc == 'A') *dev = ns->ns_part1.np_tty->t_dev; else *dev = ns->ns_part2.np_tty->t_dev; + *end = endc; atomic_add_int(&nmdm_count, 1); }