From cf0b6068d2d20c7dcd937fcfb2cc3569894e1c0d Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 2 Apr 2025 15:14:10 +0200 Subject: [PATCH] net: coap_client: Fix CoAP client thread priority The default thread priority for the CoAP client thread is set to NUM_PREEMPT_PRIORITIES which is not a valid thread priority, as the lowest application thread priority is actually NUM_PREEMPT_PRIORITIES - 1. Because of this, CoAP client library gave an assert on boot if assertions were enabled. Kconfig does not allow for arithmetics when setting integer defaults, therefore handle this at the preprocessor stage by limiting the actual priority assigned to the CoAP client thread to a valid range. Signed-off-by: Robert Lubos --- subsys/net/lib/coap/coap_client.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/coap/coap_client.c b/subsys/net/lib/coap/coap_client.c index 2e70a4a8d79..67fd8af91c1 100644 --- a/subsys/net/lib/coap/coap_client.c +++ b/subsys/net/lib/coap/coap_client.c @@ -1139,6 +1139,10 @@ bool coap_client_has_ongoing_exchange(struct coap_client *client) return has_ongoing_exchange(client); } +#define COAP_CLIENT_THREAD_PRIORITY CLAMP(CONFIG_COAP_CLIENT_THREAD_PRIORITY, \ + K_HIGHEST_APPLICATION_THREAD_PRIO, \ + K_LOWEST_APPLICATION_THREAD_PRIO) + K_THREAD_DEFINE(coap_client_recv_thread, CONFIG_COAP_CLIENT_STACK_SIZE, coap_client_recv, NULL, NULL, NULL, - CONFIG_COAP_CLIENT_THREAD_PRIORITY, 0, 0); + COAP_CLIENT_THREAD_PRIORITY, 0, 0);