drivers: clock_control_nrf2: Add missing cancelation of request

This is a follow-up to commit fe0e2dbc60.

If `nrf_clock_control_request_sync()` ends up with a timeout, before
returning it must cancel the request that was not fulfilled on time.
Otherwise, the request may actually finish successfully a bit later,
but the caller will not be aware that the clock needs to be released
(since the call resulted in an error). And actually even more serious
problem is that because the `req` structure is placed on stack, after
the function returns, the contents of this structure will be probably
overwritten with some other data, so if the request finishes at that
point, an attempt to execute the callback function pointed by this
structure will most likely cause a crash.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
Andrzej Głąbek 2024-12-14 14:34:02 +01:00 committed by Benjamin Cabé
parent a736e84754
commit c8fff0c77d

View file

@ -235,6 +235,7 @@ int nrf_clock_control_request_sync(const struct device *dev,
err = k_sem_take(&req.sem, timeout);
if (err < 0) {
nrf_clock_control_cancel_or_release(dev, spec, &req.cli);
return err;
}