summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorBret Lambert <blambert@cvs.openbsd.org>2009-07-19 08:16:07 +0000
committerBret Lambert <blambert@cvs.openbsd.org>2009-07-19 08:16:07 +0000
commitddd180af848e3d2125e1ceba31e33aa89a1b62a0 (patch)
tree2201872f08da866f4e81194b477dbf1921cf3842 /sys/kern
parent906efef01f5ab7d1d82c1f4358d4548429b929e3 (diff)
clalloc() can't fail, so there's no need to handle failure cases.
Change to void function. Also, no need to have global tty stats pointer, so just return it from clalloc, as the caller frees it immediately anyway. ok miod@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/tty.c23
-rw-r--r--sys/kern/tty_subr.c26
2 files changed, 22 insertions, 27 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index c31ce53cb65..378a801f594 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.79 2008/12/24 11:20:31 kettenis Exp $ */
+/* $OpenBSD: tty.c,v 1.80 2009/07/19 08:16:06 blambert Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -75,7 +75,7 @@ int filt_ttyread(struct knote *kn, long hint);
void filt_ttyrdetach(struct knote *kn);
int filt_ttywrite(struct knote *kn, long hint);
void filt_ttywdetach(struct knote *kn);
-int ttystats_init(void);
+void ttystats_init(struct itty **);
/* Symbolic sleep message strings. */
char ttclos[] = "ttycls";
@@ -2284,17 +2284,15 @@ ttyfree(struct tty *tp)
free(tp, M_TTYS);
}
-struct itty *ttystats;
-
-int
-ttystats_init(void)
+void
+ttystats_init(struct itty **ttystats)
{
struct itty *itp;
struct tty *tp;
- ttystats = malloc(tty_count * sizeof(struct itty),
+ *ttystats = malloc(tty_count * sizeof(struct itty),
M_SYSCTL, M_WAITOK);
- for (tp = TAILQ_FIRST(&ttylist), itp = ttystats; tp;
+ for (tp = TAILQ_FIRST(&ttylist), itp = *ttystats; tp;
tp = TAILQ_NEXT(tp, tty_link), itp++) {
itp->t_dev = tp->t_dev;
itp->t_rawq_c_cc = tp->t_rawq.c_cc;
@@ -2311,7 +2309,6 @@ ttystats_init(void)
itp->t_pgrp_pg_id = 0;
itp->t_line = tp->t_line;
}
- return (0);
}
/*
@@ -2336,13 +2333,15 @@ sysctl_tty(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
case KERN_TTY_TKCANCC:
return (sysctl_rdquad(oldp, oldlenp, newp, tk_cancc));
case KERN_TTY_INFO:
- err = ttystats_init();
- if (err)
- return (err);
+ {
+ struct itty *ttystats;
+
+ ttystats_init(&ttystats);
err = sysctl_rdstruct(oldp, oldlenp, newp, ttystats,
tty_count * sizeof(struct itty));
free(ttystats, M_SYSCTL);
return (err);
+ }
default:
#if NPTY > 0
return (sysctl_pty(name, namelen, oldp, oldlenp, newp, newlen));
diff --git a/sys/kern/tty_subr.c b/sys/kern/tty_subr.c
index 216c65528a6..e14e5bef642 100644
--- a/sys/kern/tty_subr.c
+++ b/sys/kern/tty_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty_subr.c,v 1.20 2008/03/31 22:40:34 deraadt Exp $ */
+/* $OpenBSD: tty_subr.c,v 1.21 2009/07/19 08:16:06 blambert Exp $ */
/* $NetBSD: tty_subr.c,v 1.13 1996/02/09 19:00:43 christos Exp $ */
/*
@@ -60,7 +60,7 @@ cinit(void)
* Initialize a particular clist. Ok, they are really ring buffers,
* of the specified length, with/without quoting support.
*/
-int
+void
clalloc(struct clist *clp, int size, int quot)
{
@@ -69,13 +69,12 @@ clalloc(struct clist *clp, int size, int quot)
if (quot)
clp->c_cq = malloc(QMEM(size), M_TTYS, M_WAITOK|M_ZERO);
else
- clp->c_cq = (u_char *)0;
+ clp->c_cq = NULL;
- clp->c_cf = clp->c_cl = (u_char *)0;
+ clp->c_cf = clp->c_cl = NULL;
clp->c_ce = clp->c_cs + size;
clp->c_cn = size;
clp->c_cc = 0;
- return (0);
}
void
@@ -89,7 +88,7 @@ clfree(struct clist *clp)
bzero(clp->c_cq, QMEM(clp->c_cn));
free(clp->c_cq, M_TTYS);
}
- clp->c_cs = clp->c_cq = (u_char *)0;
+ clp->c_cs = clp->c_cq = NULL;
}
@@ -245,19 +244,17 @@ putc(int c, struct clist *clp)
int s;
s = spltty();
- if (clp->c_cc == clp->c_cn)
- goto out;
+ if (clp->c_cc == clp->c_cn) {
+ splx(s);
+ return -1;
+ }
if (clp->c_cc == 0) {
if (!clp->c_cs) {
#if defined(DIAGNOSTIC) || 1
printf("putc: required clalloc\n");
#endif
- if (clalloc(clp, 1024, 1)) {
-out:
- splx(s);
- return -1;
- }
+ clalloc(clp, 1024, 1);
}
clp->c_cf = clp->c_cl = clp->c_cs;
}
@@ -338,8 +335,7 @@ b_to_q(u_char *cp, int count, struct clist *clp)
#if defined(DIAGNOSTIC) || 1
printf("b_to_q: required clalloc\n");
#endif
- if (clalloc(clp, 1024, 1))
- goto out;
+ clalloc(clp, 1024, 1);
}
clp->c_cf = clp->c_cl = clp->c_cs;
}