From: Tomas Krizek Date: Tue, 8 Sep 2020 08:42:03 +0000 (+0200) Subject: daemon/worker: simplify err handling in worker_submit() X-Git-Tag: v5.2.0~32^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=42ee46dceb64baec15256cb3c6fd06bd54e4a0be;p=thirdparty%2Fknot-resolver.git daemon/worker: simplify err handling in worker_submit() If pkt was NULL, the function would return error from parse_packet(), which would then have no effect besides returning an error code from worker_submit(). There were also needless checks that pkt is indeed not NULL in cases where it was no longer possible for it to be so. This also removes assert(false) statements and simply return an error. --- diff --git a/daemon/worker.c b/daemon/worker.c index 97a2feeb8..dc262003a 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1571,17 +1571,12 @@ static int parse_packet(knot_pkt_t *query) int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt_t *pkt) { - if (!session) { - assert(false); + if (!session || !pkt) return kr_error(EINVAL); - } uv_handle_t *handle = session_get_handle(session); - bool OK = handle && handle->loop->data; - if (!OK) { - assert(false); + if (!handle || !handle->loop->data) return kr_error(EINVAL); - } int ret = parse_packet(pkt); @@ -1590,7 +1585,7 @@ int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt /* Ignore badly formed queries. */ if ((ret != kr_ok() && ret != kr_error(EMSGSIZE)) || (is_query == is_outgoing)) { - if (pkt && !is_outgoing) the_worker->stats.dropped += 1; + if (!is_outgoing) the_worker->stats.dropped += 1; return kr_error(EILSEQ); } @@ -1620,7 +1615,7 @@ int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt if (handle->type == UV_TCP && qr_task_register(task, session)) { return kr_error(ENOMEM); } - } else if (pkt) { /* response from upstream */ + } else { /* response from upstream */ const uint16_t id = knot_wire_get_id(pkt->wire); task = session_tasklist_del_msgid(session, id); if (task == NULL) {