From: Olivier Houchard Date: Tue, 14 May 2019 15:50:32 +0000 (+0200) Subject: MINOR: h2: Use BUG_ON() to enforce rules in subscribe/unsubscribe. X-Git-Tag: v2.0-dev3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8338151a31310fdbe55382c1ab8273c8413b0ca;p=thirdparty%2Fhaproxy.git MINOR: h2: Use BUG_ON() to enforce rules in subscribe/unsubscribe. It is not legal to subscribe if we're already subscribed, or to unsubscribe if we did not subscribe, so instead of trying to handle those cases, just assert that it's ok using the new BUG_ON() macro. --- diff --git a/src/mux_h2.c b/src/mux_h2.c index 73d32a926b..90c6a440c6 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -5199,24 +5199,22 @@ static int h2_subscribe(struct conn_stream *cs, int event_type, void *param) if (event_type & SUB_RETRY_RECV) { sw = param; - if (!(sw->events & SUB_RETRY_RECV)) { - sw->events |= SUB_RETRY_RECV; - h2s->recv_wait = sw; - } + BUG_ON(h2s->recv_wait != NULL || (sw->events & SUB_RETRY_RECV)); + sw->events |= SUB_RETRY_RECV; + h2s->recv_wait = sw; event_type &= ~SUB_RETRY_RECV; } if (event_type & SUB_RETRY_SEND) { sw = param; - if (!(sw->events & SUB_RETRY_SEND)) { - sw->events |= SUB_RETRY_SEND; - h2s->send_wait = sw; - if (!(h2s->flags & H2_SF_BLK_SFCTL) && - !LIST_ADDED(&h2s->list)) { - if (h2s->flags & H2_SF_BLK_MFCTL) - LIST_ADDQ(&h2c->fctl_list, &h2s->list); - else - LIST_ADDQ(&h2c->send_list, &h2s->list); - } + BUG_ON(h2s->send_wait != NULL || (sw->events & SUB_RETRY_SEND)); + sw->events |= SUB_RETRY_SEND; + h2s->send_wait = sw; + if (!(h2s->flags & H2_SF_BLK_SFCTL) && + !LIST_ADDED(&h2s->list)) { + if (h2s->flags & H2_SF_BLK_MFCTL) + LIST_ADDQ(&h2c->fctl_list, &h2s->list); + else + LIST_ADDQ(&h2c->send_list, &h2s->list); } event_type &= ~SUB_RETRY_SEND; } @@ -5237,26 +5235,23 @@ static int h2_unsubscribe(struct conn_stream *cs, int event_type, void *param) if (event_type & SUB_RETRY_RECV) { sw = param; - if (h2s->recv_wait == sw) { - sw->events &= ~SUB_RETRY_RECV; - h2s->recv_wait = NULL; - } + BUG_ON(h2s->recv_wait != sw); + sw->events &= ~SUB_RETRY_RECV; + h2s->recv_wait = NULL; } if (event_type & SUB_RETRY_SEND) { sw = param; - if (h2s->send_wait == sw) { - LIST_DEL(&h2s->list); - LIST_INIT(&h2s->list); - sw->events &= ~SUB_RETRY_SEND; - /* We were about to send, make sure it does not happen */ - if (LIST_ADDED(&h2s->sending_list) && - h2s->send_wait != &h2s->wait_event) { - task_remove_from_tasklet_list((struct task *)h2s->send_wait->task); - LIST_DEL_INIT(&h2s->sending_list); - } - h2s->send_wait = NULL; - + BUG_ON(h2s->send_wait != sw); + LIST_DEL(&h2s->list); + LIST_INIT(&h2s->list); + sw->events &= ~SUB_RETRY_SEND; + /* We were about to send, make sure it does not happen */ + if (LIST_ADDED(&h2s->sending_list) && + h2s->send_wait != &h2s->wait_event) { + task_remove_from_tasklet_list((struct task *)h2s->send_wait->task); + LIST_DEL_INIT(&h2s->sending_list); } + h2s->send_wait = NULL; } return 0; }