This replaces the older k_sleep(K_MSEC(time)) pattern with the modern,
more efficient k_msleep(time) API. This prevents double-macro expansion
overhead and adheres to Zephyr's preferred timeout style.
Signed-off-by: Saksham Gupta <saksham77779@gmail.com>
K_SPINLOCK() expands to a for loop, so the compiler cannot prove the
guarded block always executes and warns that ret is used uninitialized
on return from runtime_usage_put():
subsys/pm/device_runtime.c:116:16: warning: 'ret' may be used
uninitialized [-Wmaybe-uninitialized]
Both branches inside the block assign ret, so this is a false positive.
Initialize ret at declaration, matching runtime_usage_put_fast() which
already initializes its return value for the same reason.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Connected transports (TLS/DTLS, offloaded sockets) may not report a
per-packet source address, so replying to a received packet with the
unpopulated address made ACK/RST fail. Use the received source when the
transport provides one, otherwise fall back to the request's address.
Assisted-by: Cursor:claude-opus-4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
shell_stop() read/wrote sh->ctx->state without taking the shell lock.
If a command was still running on the shell thread, state_collect()
would finish with an unconditional state_set(ACTIVE), clobbering the
SHELL_STATE_INITIALIZED shell_stop() had just set. The log backend
was left disabled and shell_start() would then fail with -ENOTSUP.
Fix by having shell_stop() take the same lock shell_thread() already
holds during shell_process()/state_collect(), like shell_start()
already does. Returns -EBUSY if the lock is busy.
Fixes#115019
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
The get/put fast paths update pm->base.usage under the global runtime
PM spinlock, but the slow paths update the same non-atomic counter
while holding only the per-device semaphore. A pm_device_runtime_get()
call from an ISR can then interleave with the last-user
pm_device_runtime_put() read-modify-write running in a thread: the
fast path sees usage == 1 with the device active, increments the
counter and returns 0, and the interrupted thread overwrites the
counter with 0 and suspends the device. The ISR ends up holding a
runtime PM reference on a suspended device and the usage count is
permanently off by one.
Serialize all usage read-modify-write sequences of the non-ISR-safe
paths through the global spinlock: the unbalanced check, decrement and
last-user decision in runtime_suspend(), the suspend failure restores,
the slow-path get increment and the resume failure decrement. State
keeps being written under the per-device semaphore: every transition
away from the active state happens with usage == 0, which is now
visible under the spinlock, so the fast-path "usage > 0 and state
active" check cannot claim a reference on a device that is about to be
suspended. The ISR-safe paths already serialize everything under the
per-device spinlock and are unchanged. The counter updates are
factored into small runtime_usage_*() helpers so that every
read-modify-write visibly goes through the same lock.
The race window was confirmed on qemu_x86 by disassembly (the usage
load and store are split across a branch, so the timer IRQ can be
delivered in between) and reproduced deterministically with the stress
test added in the following commit, which fails without this fix and
passes with it.
Fixes the race left open by commit 46e5ba3732 ("pm: device_runtime:
Fix managing the device from multiple contexts").
Signed-off-by: Holt Sun <holt.sun@nxp.com>
Use #include <> instead of #include "" to include a header file which path
is not relative to the directory path of the file emitting the #include
directive.
This change was made running scripts/check_quoted_includes.py script
proposed in https://github.com/zephyrproject-rtos/zephyr/pull/112135
with the Linux shell command below and manually selecting the applicable
changes:
$ ./scripts/check_quoted_includes.py -w subsys/usb/
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
lcp_open() resets the peer async control character map and lcp_down()
clears the negotiated authentication protocol, but nothing clears the
peer PFC and ACFC requests. After a link drop they survive into the next
session, so a peer that stops asking for compression is still recorded as
having asked for it.
Clear both in lcp_down(), which runs on every link loss, and in lcp_open()
for the initial state.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Aleksandr Senin <al@meshium.net>
ppp_send_proto_rej() ignores its protocol argument; ppp_send_pkt() builds
the Rejected-Protocol field by copying the received frame from offset zero,
so the field is whatever arrived on the wire. Under PFC that is a single
octet, while RFC 1661 ch. 5.7 requires the Rejected-Protocol field to be
two octets.
The packet has no headroom to expand the field in place, so skip the reject
for a compressed protocol instead of emitting a malformed one. This is
reachable for an inbound 0x21 with CONFIG_NET_IPV4=n, or 0x57 with
CONFIG_NET_IPV6=n, where the IP fast path is compiled out.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Aleksandr Senin <al@meshium.net>
Add LCP negotiation for Protocol-Field-Compression (RFC 1661 option 7)
and Address-and-Control-Field-Compression (option 8), behind new Kconfig
NET_L2_PPP_OPTION_PFC / NET_L2_PPP_OPTION_ACFC (default off).
Follows the existing PPP_MY_OPTION / PPP_PEER_OPTION pattern: advertise
the flag options in my-options so the peer knows we can receive the
compressed form, and record a peer request in ctx->lcp.peer_options.
This is the negotiation layer only. Compressing on transmit is not
implemented, and the receive path accepts compressed frames independently
of what was negotiated.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Aleksandr Senin <al@meshium.net>
mq_open() looked the queue up under mq_sem, released it, and only then
incremented ref_count, so a concurrent mq_close()/mq_unlink() could remove
and free the object in that window - a use-after-free on the increment.
Re-confirm the queue is still linked and take the reference without
dropping the lock.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
ieee802154_create_data_frame() and ieee802154_decrypt_data() computed
payload_len = total_len - ll_hdr_len - authtag_len without verifying
that total_len >= ll_hdr_len + authtag_len. A crafted or short frame
caused a uint8_t underflow, producing a ~4 GB payload length passed to
the crypto layer.
Assisted-by: Claude:claude-sonnet-4-6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This macro eliminates manual size/alignment management and prevents
namespace collisions by moving internal queues to file-private scope.
Signed-off-by: Cesar Vandevelde <cesar.vandevelde@gmail.com>
This macro eliminates manual size/alignment management and prevents
namespace collisions by moving internal queues to file-private scope.
Signed-off-by: Cesar Vandevelde <cesar.vandevelde@gmail.com>
This macro eliminates manual size/alignment management and prevents
namespace collisions by moving internal queues to file-private scope.
Signed-off-by: Cesar Vandevelde <cesar.vandevelde@gmail.com>
This macro eliminates manual size/alignment management and prevents
namespace collisions by moving internal queues to file-private scope.
Signed-off-by: Cesar Vandevelde <cesar.vandevelde@gmail.com>
This macro eliminates manual size/alignment management and prevents
namespace collisions by moving internal queues to file-private scope.
Signed-off-by: Cesar Vandevelde <cesar.vandevelde@gmail.com>
This macro eliminates manual size/alignment management and prevents
namespace collisions by moving internal queues to file-private scope.
Signed-off-by: Cesar Vandevelde <cesar.vandevelde@gmail.com>
This macro eliminates manual size/alignment management and prevents
namespace collisions by moving internal queues to file-private scope.
Signed-off-by: Cesar Vandevelde <cesar.vandevelde@gmail.com>
This macro eliminates manual size/alignment management and prevents
namespace collisions by moving internal queues to file-private scope.
Signed-off-by: Cesar Vandevelde <cesar.vandevelde@gmail.com>
wifi_ap_sta_list_lock is already init at build time
with K_MUTEX_DEFINE, so we don't need the k_mutex_init.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
The KERNEL define polluted namespace it was only really used for the ztest
unit test framework. This commit removes the define and updates the ztest
code to use the unittest define instead.
Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
Correct the trace message %zu specifier added by commit e5bc5c7a6d
that that should rather be %u since argument is not of size_t or like
type.
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Handling Previous Track and Next Track in this state
allowed mpl to dereference and advance track state,
then transition to Paused. This behavior contradicts
the MCS state model and causes failures.
Reject Next Track and Previous Track commands while
the Media Player is in the Inactive state. Handle
both opcodes like the other commands that are invalid
while the player is inactive.
Signed-off-by: Alex Ciascai <ext-alexandru.ciascai@nordicsemi.no>
Rename some struct fields from ase to ase_id[s] where
the value reflect an ASE ID. This is to avoid any confusion
with `struct bt_ascs_ase *ase` variables.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
When DTLS support is enabled lwm2m_engine.c includes
mbedtls/ssl_ciphersuites.h which requires Mbed TLS to be enabled.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
Add a Cortex-M perf backend that samples interrupted context from the
SysTick exception frame.
Install a SysTick wrapper when stack-sampling perf is enabled and
capture the interrupted stack pointer, EXC_RETURN, and r7 on exception
entry. Validate the complete hardware-stacked frame, including optional
alignment padding and extended FP state, against the Thread-mode or
Handler-mode stack before unwinding with arch_stack_walk().
The Arm stack walker uses EHABI unwind tables, so the backend does not
require CONFIG_FRAME_POINTER. Preserve r7 because EHABI unwind recipes
may use it to recover VSP even when frame pointers are not enabled
globally.
Return -EAGAIN when the interrupted context is invalid or unavailable
so the perf core discards that sample without reporting buffer
exhaustion.
Limit the backend to uniprocessor configurations because its captured
sample state is global and remote SMP sampling does not enter the
SysTick wrapper.
Disable the backend for Non-secure Trusted Execution images. A
Non-secure SysTick can be taken while the core executes Secure code,
but Non-secure firmware cannot access the Secure exception frame.
The stack pointer read by the wrapper instead refers to the suspended
Non-secure context, so it cannot be unwound as the interrupted frame.
Sampling across Security states is unsupported.
Signed-off-by: Sudan Landge <sudan.landge@arm.com>
Extend arch_perf_current_stack_trace() to distinguish samples that
should be skipped from buffer exhaustion. Keep zero as the existing
full-buffer signal and use negative values for samples that should be
discarded without stopping recording.
Change the return type to int across the existing backends. Their
current zero-on-exhaustion behavior remains unchanged.
Signed-off-by: Sudan Landge <sudan.landge@arm.com>
Only add perf backend sources when CONFIG_PROFILING_PERF is enabled.
This keeps backend source selection tied to the perf subsystem instead
of evaluating backend files when the perf command itself is disabled.
Signed-off-by: Sudan Landge <sudan.landge@arm.com>
When a context was bound to a specific interface, net_context_bind()
still looked the requested address up across all interfaces, so a bind
could succeed with an address owned by a different interface. Restrict
the lookup to the bound interface with
net_if_ipv{4,6}_addr_lookup_by_iface().
Assisted-by: Cursor:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add an IPv4 counterpart to net_if_ipv6_addr_lookup_by_iface(), along with
its raw variant, so callers can check whether an address is assigned to
one specific interface instead of scanning all of them.
Assisted-by: Cursor:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The telnet backend exposes the full Zephyr shell over an unauthenticated,
unencrypted TCP port, which is equivalent to granting full device control
to anyone who can reach the port. There is no in-tree authentication to
switch on, so add the security warning to the Kconfig help, mirroring the
guidance already given for MCUMGR_GRP_SHELL.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
`bt_bip_disconnect_rsp()` was incorrectly passing NULL instead of the
`buf` parameter to `bt_obex_disconnect_rsp()`. This prevented any
optional headers in the disconnect response from being sent. And
leading a result that the passed `buf` will not be released anymore.
Pass the `buf` parameter through to `bt_obex_disconnect_rsp()` so that
optional headers can be included in the disconnect response as
intended. And also the passed buffer `buf` will be managed by the
underlay if the OBEX disconnect response is sent without any errors
via the function `bt_obex_disconnect_rsp()`.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Raise the minimum required CMake version from 3.20.0 (documented as
3.20.5) to 3.28.0, which is satisfied by the CMake 3.28.3 package
shipped in the Ubuntu 24.04 LTS repositories. Ubuntu 24.04 is the
current Ubuntu LTS release targeted by the Zephyr getting started
guide, and by the time of the next Zephyr release, Ubuntu 22.04 will be
within months of its end of standard support. Users of distributions
shipping an older CMake can use the Kitware APT repository or a
pip-installed CMake, as the documentation already suggests.
Raising the floor to 3.28 unlocks a range of modern CMake features for
the build system, among which the cmake_file_api() command (3.27),
file(COPY_FILE) (3.21), block()/endblock() (3.25), and allows removal
of several version-conditional workarounds.
The tree-wide cmake_minimum_required() occurrences in samples, tests
and boards are updated accordingly, together with the documentation
and the sysbuild CMake presets. The IAR C-STAT integration keeps its
own higher requirement (4.1.0).
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The bt_bap_stream_qos() function validates ASE operations for all
streams in the unicast group, but it should only validate streams
that belong to the specified connection.
When a unicast group contains streams from multiple connections,
the current implementation incorrectly validates streams belonging
to other connections, which may cause false -EBADMSG errors if
those streams are in different states.
Add a connection check to skip streams that do not belong to the
specified connection during ASE operation validation.
Signed-off-by: Chang An <chang.an_1@nxp.com>
Addressing the issue for which packets may be reordered after a peek on
tcp socket. The process of requeuing an observed packet may be
incomplete, when the peek size is not large enough to visit all the
packets in the queue.
Signed-off-by: Andrea Gilardoni <a.gilardoni@arduino.cc>
find_msg() returns NULL when no message matches the given reply, but
notify_message_reply_cb() dereferenced it unconditionally. Bail out
instead, like the other find_msg() call sites in this file already do.
Reported by the GCC static analyzer (-Wanalyzer-null-dereference).
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Assisted-by: Claude:claude-opus-5
tracing_syscall.h had no CTF branch, so syscalls were untraced under CTF
(only SystemView and the test format hooked them). Add
tracing_ctf_syscall.h, mirroring the SystemView integration: it maps
sys_port_trace_syscall_enter and _exit to CTF events recording the
syscall id (and, on entry, the syscall name as a bounded string). Wire
it in with a CONFIG_TRACING_CTF branch in tracing_syscall.h, plus the
event ids, emitters, trampolines and TSDL metadata.
The header includes <zephyr/types.h> rather than <zephyr/kernel.h>: it
is pulled in very early from the generated syscall dispatch, before the
kernel types are complete.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for PM system suspend (enter/exit with the tick
budget and chosen power state); the sys_port_trace_pm_system_* hooks
fell through to the no-op fallback, so it was invisible in a CTF trace.
Add CTF coverage for every hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for the PM device runtime API (get, put,
put_async, enable, disable); the sys_port_trace_pm_device_runtime_*
hooks fell through to the no-op fallback, so it was invisible in a CTF
trace.
Add CTF coverage for every hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for rtio (submit, sqe/cqe acquire/release/consume,
cqe submit, txn and chain next, sqe cancel); the sys_port_trace_rtio_*
hooks fell through to the no-op fallback, so it was invisible in a CTF
trace.
Add CTF coverage for every hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for k_pipe (init, reset, close, write and read)
for the current pipe API; the sys_port_trace_k_pipe_* hooks fell through
to the no-op fallback, so it was invisible in a CTF trace.
Add CTF coverage for every live hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
The old-API pipe hooks (get/put/flush/cleanup/alloc_init) have no call
site and are left to the no-op fallback.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for the system heap
k_malloc/k_calloc/k_aligned_alloc/k_realloc/k_free family; the
sys_port_trace_k_heap_sys_* hooks fell through to the no-op fallback, so
it was invisible in a CTF trace.
Add CTF coverage for every live hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for k_heap (init, alloc, aligned_alloc, calloc,
realloc and free); the sys_port_trace_k_heap_* hooks fell through to the
no-op fallback, so it was invisible in a CTF trace.
Add CTF coverage for every live hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for k_stack (init, alloc_init, cleanup, push and
pop); the sys_port_trace_k_stack_* hooks fell through to the no-op
fallback, so it was invisible in a CTF trace.
Add CTF coverage for every live hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for k_lifo (init, put and alloc_put, get); the
sys_port_trace_k_lifo_* hooks fell through to the no-op fallback, so it
was invisible in a CTF trace.
Add CTF coverage for every live hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for k_fifo (init, put and alloc_put, put_list,
put_slist, get, peek head/tail, cancel_wait); the
sys_port_trace_k_fifo_* hooks fell through to the no-op fallback, so it
was invisible in a CTF trace.
Add CTF coverage for every live hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
CTF emitted no events for k_queue (init, append/prepend and their alloc
variants, insert, append_list, merge_slist, get, remove, unique_append
and peek); the sys_port_trace_k_queue_* hooks fell through to the no-op
fallback, so it was invisible in a CTF trace.
Add CTF coverage for every live hook: the event ids, ctf_top_* emitters,
sys_trace_* trampolines and prototypes, the sys_port_trace_* macros and
the matching TSDL event definitions in the metadata.
k_queue_insert_blocking has no kernel call site and is left to the no-op
fallback.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Both mctp_memory.c and mctp_log.c were using SYS_INIT_NAMED without the
right include - were working only due transitive includes. Make it
explicit so it work on all architectures.
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Add a CONFIG_SECURE_STORAGE_INIT_PRIORITY option to allow
changing the initialization priority of the secure storage
subsystem.
Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>