svn commit: r293349 - head/sys/kern

Konstantin Belousov kib at FreeBSD.org
Thu Jan 7 20:15:11 UTC 2016


Author: kib
Date: Thu Jan  7 20:15:09 2016
New Revision: 293349
URL: https://svnweb.freebsd.org/changeset/base/293349

Log:
  Convert tty common code to use make_dev_s().
  
  Tty.c was untypical in that it handled the si_drv1 issue consistently
  and correctly, by always checking for si_drv1 being non-NULL and
  sleeping if NULL.  The removed code also illustrated unneeded
  complications in drivers which are eliminated by the use of new KPI.
  
  Reviewed by:	hps, jhb
  Discussed with:	bde
  Sponsored by:	The FreeBSD Foundation
  MFC after:	3 weeks
  Differential revision:	https://reviews.freebsd.org/D4746

Modified:
  head/sys/kern/tty.c

Modified: head/sys/kern/tty.c
==============================================================================
--- head/sys/kern/tty.c	Thu Jan  7 20:15:05 2016	(r293348)
+++ head/sys/kern/tty.c	Thu Jan  7 20:15:09 2016	(r293349)
@@ -237,14 +237,10 @@ static int
 ttydev_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
 {
 	struct tty *tp;
-	int error = 0;
-
-	while ((tp = dev->si_drv1) == NULL) {
-		error = tsleep(&dev->si_drv1, PCATCH, "ttdrv1", 1);
-		if (error != EWOULDBLOCK)
-			return (error);
-	}
+	int error;
 
+	tp = dev->si_drv1;
+	error = 0;
 	tty_lock(tp);
 	if (tty_gone(tp)) {
 		/* Device is already gone. */
@@ -755,13 +751,10 @@ static int
 ttyil_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
 {
 	struct tty *tp;
-	int error = 0;
+	int error;
 
-	while ((tp = dev->si_drv1) == NULL) {
-		error = tsleep(&dev->si_drv1, PCATCH, "ttdrv1", 1);
-		if (error != EWOULDBLOCK)
-			return (error);
-	}
+	tp = dev->si_drv1;
+	error = 0;
 	tty_lock(tp);
 	if (tty_gone(tp))
 		error = ENODEV;
@@ -1189,6 +1182,7 @@ tty_makedevf(struct tty *tp, struct ucre
     const char *fmt, ...)
 {
 	va_list ap;
+	struct make_dev_args args;
 	struct cdev *dev, *init, *lock, *cua, *cinit, *clock;
 	const char *prefix = "tty";
 	char name[SPECNAMELEN - 3]; /* for "tty" and "cua". */
@@ -1221,71 +1215,72 @@ tty_makedevf(struct tty *tp, struct ucre
 	flags |= MAKEDEV_CHECKNAME;
 
 	/* Master call-in device. */
-	error = make_dev_p(flags, &dev, &ttydev_cdevsw, cred, uid, gid, mode,
-	    "%s%s", prefix, name);
-	if (error)
+	make_dev_args_init(&args);
+	args.mda_flags = flags;
+	args.mda_devsw = &ttydev_cdevsw;
+	args.mda_cr = cred;
+	args.mda_uid = uid;
+	args.mda_gid = gid;
+	args.mda_mode = mode;
+	args.mda_si_drv1 = tp;
+	error = make_dev_s(&args, &dev, "%s%s", prefix, name);
+	if (error != 0)
 		return (error);
-	dev->si_drv1 = tp;
-	wakeup(&dev->si_drv1);
 	tp->t_dev = dev;
 
 	init = lock = cua = cinit = clock = NULL;
 
 	/* Slave call-in devices. */
 	if (tp->t_flags & TF_INITLOCK) {
-		error = make_dev_p(flags, &init, &ttyil_cdevsw, cred, uid,
-		    gid, mode, "%s%s.init", prefix, name);
-		if (error)
+		args.mda_devsw = &ttyil_cdevsw;
+		args.mda_unit = TTYUNIT_INIT;
+		args.mda_si_drv1 = tp;
+		args.mda_si_drv2 = &tp->t_termios_init_in;
+		error = make_dev_s(&args, &init, "%s%s.init", prefix, name);
+		if (error != 0)
 			goto fail;
 		dev_depends(dev, init);
-		dev2unit(init) = TTYUNIT_INIT;
-		init->si_drv1 = tp;
-		wakeup(&init->si_drv1);
-		init->si_drv2 = &tp->t_termios_init_in;
 
-		error = make_dev_p(flags, &lock, &ttyil_cdevsw, cred, uid,
-		    gid, mode, "%s%s.lock", prefix, name);
-		if (error)
+		args.mda_unit = TTYUNIT_LOCK;
+		args.mda_si_drv2 = &tp->t_termios_lock_in;
+		error = make_dev_s(&args, &lock, "%s%s.lock", prefix, name);
+		if (error != 0)
 			goto fail;
 		dev_depends(dev, lock);
-		dev2unit(lock) = TTYUNIT_LOCK;
-		lock->si_drv1 = tp;
-		wakeup(&lock->si_drv1);
-		lock->si_drv2 = &tp->t_termios_lock_in;
 	}
 
 	/* Call-out devices. */
 	if (tp->t_flags & TF_CALLOUT) {
-		error = make_dev_p(flags, &cua, &ttydev_cdevsw, cred,
-		    UID_UUCP, GID_DIALER, 0660, "cua%s", name);
-		if (error)
+		make_dev_args_init(&args);
+		args.mda_flags = flags;
+		args.mda_devsw = &ttydev_cdevsw;
+		args.mda_cr = cred;
+		args.mda_uid = UID_UUCP;
+		args.mda_gid = GID_DIALER;
+		args.mda_mode = 0660;
+		args.mda_unit = TTYUNIT_CALLOUT;
+		args.mda_si_drv1 = tp;
+		error = make_dev_s(&args, &cua, "cua%s", name);
+		if (error != 0)
 			goto fail;
 		dev_depends(dev, cua);
-		dev2unit(cua) = TTYUNIT_CALLOUT;
-		cua->si_drv1 = tp;
-		wakeup(&cua->si_drv1);
 
 		/* Slave call-out devices. */
 		if (tp->t_flags & TF_INITLOCK) {
-			error = make_dev_p(flags, &cinit, &ttyil_cdevsw, cred,
-			    UID_UUCP, GID_DIALER, 0660, "cua%s.init", name);
-			if (error)
+			args.mda_devsw = &ttyil_cdevsw;
+			args.mda_unit = TTYUNIT_CALLOUT | TTYUNIT_INIT;
+			args.mda_si_drv2 = &tp->t_termios_init_out;
+			error = make_dev_s(&args, &cinit, "cua%s.init", name);
+			if (error != 0)
 				goto fail;
 			dev_depends(dev, cinit);
-			dev2unit(cinit) = TTYUNIT_CALLOUT | TTYUNIT_INIT;
-			cinit->si_drv1 = tp;
-			wakeup(&cinit->si_drv1);
-			cinit->si_drv2 = &tp->t_termios_init_out;
 
-			error = make_dev_p(flags, &clock, &ttyil_cdevsw, cred,
-			    UID_UUCP, GID_DIALER, 0660, "cua%s.lock", name);
-			if (error)
+			args.mda_unit = TTYUNIT_CALLOUT | TTYUNIT_LOCK;
+			args.mda_si_drv2 = &tp->t_termios_lock_out;
+			error = make_dev_s(&args, &clock, "cua%s.lock", name);
+			if (error != 0)
 				goto fail;
 			dev_depends(dev, clock);
-			dev2unit(clock) = TTYUNIT_CALLOUT | TTYUNIT_LOCK;
-			clock->si_drv1 = tp;
-			wakeup(&clock->si_drv1);
-			clock->si_drv2 = &tp->t_termios_lock_out;
 		}
 	}
 


More information about the svn-src-head mailing list