Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 May 2011 18:54:18 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r221397 - in head/sys: kern sys
Message-ID:  <201105031854.p43IsIJ5006816@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Tue May  3 18:54:18 2011
New Revision: 221397
URL: http://svn.freebsd.org/changeset/base/221397

Log:
  Add make_dev_alias_p() function. It is similar to make_dev_alias(),
  but it may return an error like make_dev_p() does.
  
  Reviewed by:	kib (previous version)
  MFC after:	2 weeks

Modified:
  head/sys/kern/kern_conf.c
  head/sys/sys/conf.h

Modified: head/sys/kern/kern_conf.c
==============================================================================
--- head/sys/kern/kern_conf.c	Tue May  3 18:48:06 2011	(r221396)
+++ head/sys/kern/kern_conf.c	Tue May  3 18:54:18 2011	(r221397)
@@ -893,23 +893,34 @@ dev_depends(struct cdev *pdev, struct cd
 	dev_unlock();
 }
 
-struct cdev *
-make_dev_alias(struct cdev *pdev, const char *fmt, ...)
+static int
+make_dev_alias_v(int flags, struct cdev **cdev, struct cdev *pdev,
+    const char *fmt, va_list ap)
 {
 	struct cdev *dev;
-	va_list ap;
 	int error;
 
-	KASSERT(pdev != NULL, ("NULL pdev"));
-	dev = devfs_alloc(MAKEDEV_WAITOK);
+	KASSERT(pdev != NULL, ("make_dev_alias_v: pdev is NULL"));
+	KASSERT((flags & MAKEDEV_WAITOK) == 0 || (flags & MAKEDEV_NOWAIT) == 0,
+	    ("make_dev_alias_v: both WAITOK and NOWAIT specified"));
+	KASSERT((flags & ~(MAKEDEV_WAITOK | MAKEDEV_NOWAIT |
+	    MAKEDEV_CHECKNAME)) == 0,
+	    ("make_dev_alias_v: invalid flags specified (flags=%02x)", flags));
+
+	dev = devfs_alloc(flags);
+	if (dev == NULL)
+		return (ENOMEM);
 	dev_lock();
 	dev->si_flags |= SI_ALIAS;
-	va_start(ap, fmt);
 	error = prep_devname(dev, fmt, ap);
-	va_end(ap);
 	if (error != 0) {
-		panic("make_dev_alias: bad si_name (error=%d, si_name=%s)",
-		    error, dev->si_name);
+		if ((flags & MAKEDEV_CHECKNAME) == 0) {
+			panic("make_dev_alias_v: bad si_name "
+			    "(error=%d, si_name=%s)", error, dev->si_name);
+		}
+		dev_unlock();
+		devfs_free(dev);
+		return (error);
 	}
 	dev->si_flags |= SI_NAMED;
 	devfs_create(dev);
@@ -917,11 +928,41 @@ make_dev_alias(struct cdev *pdev, const 
 	clean_unrhdrl(devfs_inos);
 	dev_unlock();
 
-	notify_create(dev, MAKEDEV_WAITOK);
+	notify_create(dev, flags);
+	*cdev = dev;
+
+	return (0);
+}
 
+struct cdev *
+make_dev_alias(struct cdev *pdev, const char *fmt, ...)
+{
+	struct cdev *dev;
+	va_list ap;
+	int res;
+
+	va_start(ap, fmt);
+	res = make_dev_alias_v(MAKEDEV_WAITOK, &dev, pdev, fmt, ap);
+	va_end(ap);
+
+	KASSERT(res == 0 && dev != NULL,
+	    ("make_dev_alias: failed make_dev_alias_v (error=%d)", res));
 	return (dev);
 }
 
+int
+make_dev_alias_p(int flags, struct cdev **cdev, struct cdev *pdev,
+    const char *fmt, ...)
+{
+	va_list ap;
+	int res;
+
+	va_start(ap, fmt);
+	res = make_dev_alias_v(flags, cdev, pdev, fmt, ap);
+	va_end(ap);
+	return (res);
+}
+
 static void
 destroy_devl(struct cdev *dev)
 {

Modified: head/sys/sys/conf.h
==============================================================================
--- head/sys/sys/conf.h	Tue May  3 18:48:06 2011	(r221396)
+++ head/sys/sys/conf.h	Tue May  3 18:54:18 2011	(r221397)
@@ -278,6 +278,8 @@ int	make_dev_p(int _flags, struct cdev *
 		const char *_fmt, ...) __printflike(8, 9);
 struct cdev *make_dev_alias(struct cdev *_pdev, const char *_fmt, ...)
 		__printflike(2, 3);
+int	make_dev_alias_p(int _flags, struct cdev **_cdev, struct cdev *_pdev,
+		const char *_fmt, ...) __printflike(4, 5);
 void	dev_lock(void);
 void	dev_unlock(void);
 void	setconf(void);



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