Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 226a0a71 authored by Isaac J. Manjarres's avatar Isaac J. Manjarres Committed by Hridya Valsaraju
Browse files

ANDROID: staging: ion: Fix dynamic heap ID assignment



The current implementation derives the heap ID using
ffs(), which is one-indexed, and then proceeds to use
this value with functions such as find_next_zero_bit()
and test_and_set_bit() which operate under a zero-indexing
scheme. This can lead to some clumsy/erroneous handling when
dynamically allocating a heap ID, as follows:

CMA heap bits range: [8, 15]

First CMA heap without a heap ID registration:

start_bit = ffs(ION_HEAP_DMA_START) /* 9 */
end_bit = ffs(ION_HEAP_DMA_END) /* 16 */
id_bit = find_next_zero_bit(dev->heap_ids, 16 + 1, 9) /* 9 */
test_and_set_bit(9 - 1, dev->heap_ids) /* Succeeds */

Second CMA heap without a heap ID registration:

start_bit = ffs(ION_HEAP_DMA_START) /* 9 */
end_bit = ffs(ION_HEAP_DMA_END) == 16 /* 16 */
id_bit = find_next_zero_bit(dev->heap_ids, 16 + 1, 9) /* 9 */
test_and_set_bit(9 - 1, dev->heap_ids) /* Fails */

Thus, switch to a zero-indexing scheme when deriving the
heap ID parameters to simplify the logic, as well as correct
the dynamic heap ID assignment logic.

Fixes: acbfdf32 ("ANDROID: staging: ion: add support for consistent heap ids")
Change-Id: I66d0f3838a3ef4dc4ff8537f23dd4e226472b9e2
Signed-off-by: default avatarIsaac J. Manjarres <isaacm@codeaurora.org>
parent 511b851f
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment