diff options
author | Carlos Llamas <cmllamas@google.com> | 2023-12-01 17:21:50 +0000 |
---|---|---|
committer | Rick Yiu <rickyiu@google.com> | 2024-01-17 02:59:26 +0000 |
commit | 51ffacd561d1745184b355766ceee473ddc17eab (patch) | |
tree | 6472c66573149cdcc3da0db93c568a6d32cb4fad | |
parent | 8d4ce4c5df6921dfec5afd33e69c24036942d37b (diff) | |
download | gs-51ffacd561d1745184b355766ceee473ddc17eab.tar.gz |
FROMGIT: binder: make oversized buffer code more readable
The sections in binder_alloc_new_buf_locked() dealing with oversized
buffers are scattered which makes them difficult to read. Instead,
consolidate this code into a single block to improve readability.
No functional change here.
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20231201172212.1813387-22-cmllamas@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Bug: 254650075
Bug: 320576997
(cherry picked from commit de0e6573125f8ea7a01a9b05a45b0c73116c73b2
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
char-misc-next)
Change-Id: I62c2cec7341e13d9174b4f0839a1345df7cfd808
Signed-off-by: Carlos Llamas <cmllamas@google.com>
-rw-r--r-- | drivers/android/binder_alloc.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 2ec324d3ed58..454409809a3b 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -501,32 +501,31 @@ static struct binder_buffer *binder_alloc_new_buf_locked( goto out; } - if (n == NULL) { + if (buffer_size != size) { + /* Found an oversized buffer and needs to be split */ buffer = rb_entry(best_fit, struct binder_buffer, rb_node); buffer_size = binder_alloc_buffer_size(alloc, buffer); + + WARN_ON(n || buffer_size == size); + new_buffer->user_data = buffer->user_data + size; + list_add(&new_buffer->entry, &buffer->entry); + new_buffer->free = 1; + binder_insert_free_buffer(alloc, new_buffer); + new_buffer = NULL; } binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, "%d: binder_alloc_buf size %zd got buffer %pK size %zd\n", alloc->pid, size, buffer, buffer_size); - WARN_ON(n && buffer_size != size); - has_page_addr = (buffer->user_data + buffer_size) & PAGE_MASK; end_page_addr = PAGE_ALIGN(buffer->user_data + size); if (end_page_addr > has_page_addr) end_page_addr = has_page_addr; binder_allocate_page_range(alloc, PAGE_ALIGN(buffer->user_data), end_page_addr); - if (buffer_size != size) { - new_buffer->user_data = buffer->user_data + size; - list_add(&new_buffer->entry, &buffer->entry); - new_buffer->free = 1; - binder_insert_free_buffer(alloc, new_buffer); - new_buffer = NULL; - } - rb_erase(best_fit, &alloc->free_buffers); + rb_erase(&buffer->rb_node, &alloc->free_buffers); buffer->free = 0; buffer->allow_user_free = 0; binder_insert_allocated_buffer_locked(alloc, buffer); |