mirror-linux/drivers/firmware/samsung
Tudor Ambarus 7fe40c32a3 firmware: samsung: acpm: Fix infinite loop on sequence number exhaustion
Sashiko identified a possible infinite loop [1].

ACPM IPC sequence numbers are tracked via a 64-bit bitmap. Previously,
acpm_prepare_xfer() used a do...while loop to search for a free
sequence number.

If all 63 available sequence numbers are leaked due to transient
hardware timeouts or mailbox failures, the bitmap becomes full.
The next call to acpm_prepare_xfer() would enter an infinite loop.

Fix this by utilizing the kernel's optimized bitmap search functions
(find_next_zero_bit / find_first_zero_bit). If the pool is completely
exhausted, log the failure and return -EBUSY to allow the kernel to
fail gracefully instead of hanging.

Furthermore, drop the allocation loop entirely. Because
acpm_prepare_xfer() is strictly called under the 'tx_lock' mutex,
sequence number allocations are perfectly serialized. If
find_next_zero_bit() locates a free bit, a single
test_and_set_bit_lock() is mathematically guaranteed to succeed.

To enforce this locking invariant, wrap the allocation in a
WARN_ON_ONCE. If the atomic set fails, it indicates the driver's
mutex serialization is fundamentally broken. The warning generates a
stack trace for debugging, while returning -EIO immediately aborts the
transfer to prevent silent payload corruption.

Cc: stable@vger.kernel.org
Fixes: a88927b534 ("firmware: add Exynos ACPM protocol driver")
Closes: https://sashiko.dev/#/patchset/20260420-acpm-tmu-v3-0-3dc8e93f0b26%40linaro.org [1]
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Link: https://patch.msgid.link/20260505-acpm-fixes-sashiko-reports-v5-7-43b5ee7f1674@linaro.org
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
2026-05-29 14:11:23 +02:00
..
Kconfig
Makefile firmware: exynos-acpm: add DVFS protocol 2025-10-20 08:49:44 +02:00
exynos-acpm-dvfs.c firmware: samsung: acpm: Fix cross-thread RX length corruption 2026-05-14 18:54:34 +02:00
exynos-acpm-dvfs.h firmware: exynos-acpm: Drop fake 'const' on handle pointer 2026-02-28 15:47:03 +01:00
exynos-acpm-pmic.c firmware: exynos-acpm: Drop fake 'const' on handle pointer 2026-02-28 15:47:03 +01:00
exynos-acpm-pmic.h firmware: exynos-acpm: Drop fake 'const' on handle pointer 2026-02-28 15:47:03 +01:00
exynos-acpm.c firmware: samsung: acpm: Fix infinite loop on sequence number exhaustion 2026-05-29 14:11:23 +02:00
exynos-acpm.h firmware: exynos-acpm: Drop fake 'const' on handle pointer 2026-02-28 15:47:03 +01:00