Commits
Isaac J. Manjarres committed 226a0a7161c
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: acbfdf321afb ("ANDROID: staging: ion: add support for consistent heap ids") Change-Id: I66d0f3838a3ef4dc4ff8537f23dd4e226472b9e2 Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>