From 9d018107e9c1d69c3cda20f1d4c899b44841d5ed Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 28 May 2025 09:35:02 +0200 Subject: [PATCH] net: lib: coap: Return an error on removing a non-existing observer If we're parsing a CoAP request with an observe option of '1', but there is no matching observer, return an error instead of returning a zero. Signed-off-by: Pieter De Gendt (cherry picked from commit d5931bae93ad473a6f803fffc44d30c98ea26975) --- subsys/net/lib/coap/coap_server.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/net/lib/coap/coap_server.c b/subsys/net/lib/coap/coap_server.c index 8b7fc0168c3ad..cd76363d1ea53 100644 --- a/subsys/net/lib/coap/coap_server.c +++ b/subsys/net/lib/coap/coap_server.c @@ -658,6 +658,12 @@ int coap_resource_parse_observe(struct coap_resource *resource, const struct coa ret = coap_service_remove_observer(service, resource, addr, token, tkl); if (ret < 0) { LOG_WRN("Failed to remove observer (%d)", ret); + goto unlock; + } + + if (ret == 0) { + /* Observer not found */ + ret = -ENOENT; } }