From b44d6974910511214e518598dd223b3089f25574 Mon Sep 17 00:00:00 2001 From: glebius Date: Sat, 22 Sep 2012 18:47:14 +0000 Subject: Use M_NOWAIT in wtab_alloc(), too. Convert panic() to a soft failure here. wtab_alloc() is used by red_alloc(), which can fail. Reported by: Kim Culhan --- sys/contrib/altq/altq/altq_red.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sys/contrib/altq/altq/altq_red.c b/sys/contrib/altq/altq/altq_red.c index b589454..be9eff8 100644 --- a/sys/contrib/altq/altq/altq_red.c +++ b/sys/contrib/altq/altq/altq_red.c @@ -235,6 +235,13 @@ red_alloc(int weight, int inv_pmax, int th_min, int th_max, int flags, if (rp == NULL) return (NULL); + /* allocate weight table */ + rp->red_wtab = wtab_alloc(rp->red_weight); + if (rp->red_wtab == NULL) { + free(rp, M_DEVBUF); + return (NULL); + } + rp->red_avg = 0; rp->red_idle = 1; @@ -301,9 +308,6 @@ red_alloc(int weight, int inv_pmax, int th_min, int th_max, int flags, rp->red_probd = (2 * (rp->red_thmax - rp->red_thmin) * rp->red_inv_pmax) << FP_SHIFT; - /* allocate weight table */ - rp->red_wtab = wtab_alloc(rp->red_weight); - microtime(&rp->red_last); return (rp); } @@ -638,10 +642,9 @@ wtab_alloc(int weight) return (w); } - w = malloc(sizeof(struct wtab), M_DEVBUF, M_WAITOK); + w = malloc(sizeof(struct wtab), M_DEVBUF, M_NOWAIT | M_ZERO); if (w == NULL) - panic("wtab_alloc: malloc failed!"); - bzero(w, sizeof(struct wtab)); + return (NULL); w->w_weight = weight; w->w_refcount = 1; w->w_next = wtab_list; -- cgit v1.1