Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

binder: pre-allocate binder_transaction

Move the allocation of 'struct binder_transaction' to the beginning of
the binder_transaction() function, along with the initialization of all
the members that are known at that time. This minor refactoring helps to
consolidate the usage of transaction information at later points.

This patch is in preparation for binder's generic netlink implementation
and no functional changes are intended.

Signed-off-by: Carlos Llamas <cmllamas@google.com>
Link: https://lore.kernel.org/r/20250727182932.2499194-2-cmllamas@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Carlos Llamas and committed by
Greg Kroah-Hartman
4afc5bf0 bb7aa579

+30 -34
+30 -34
drivers/android/binder.c
··· 3042 3042 binder_set_extended_error(&thread->ee, t_debug_id, BR_OK, 0); 3043 3043 binder_inner_proc_unlock(proc); 3044 3044 3045 + t = kzalloc(sizeof(*t), GFP_KERNEL); 3046 + if (!t) { 3047 + binder_txn_error("%d:%d cannot allocate transaction\n", 3048 + thread->pid, proc->pid); 3049 + return_error = BR_FAILED_REPLY; 3050 + return_error_param = -ENOMEM; 3051 + return_error_line = __LINE__; 3052 + goto err_alloc_t_failed; 3053 + } 3054 + INIT_LIST_HEAD(&t->fd_fixups); 3055 + binder_stats_created(BINDER_STAT_TRANSACTION); 3056 + spin_lock_init(&t->lock); 3057 + t->debug_id = t_debug_id; 3058 + t->start_time = t_start_time; 3059 + t->from_pid = proc->pid; 3060 + t->from_tid = thread->pid; 3061 + t->sender_euid = task_euid(proc->tsk); 3062 + t->code = tr->code; 3063 + t->flags = tr->flags; 3064 + t->priority = task_nice(current); 3065 + t->work.type = BINDER_WORK_TRANSACTION; 3066 + if (!reply && !(tr->flags & TF_ONE_WAY)) 3067 + t->from = thread; 3068 + 3045 3069 if (reply) { 3046 3070 binder_inner_proc_lock(proc); 3047 3071 in_reply_to = thread->transaction_stack; ··· 3252 3228 } 3253 3229 binder_inner_proc_unlock(proc); 3254 3230 } 3231 + 3232 + t->to_proc = target_proc; 3233 + t->to_thread = target_thread; 3255 3234 if (target_thread) 3256 3235 e->to_thread = target_thread->pid; 3257 3236 e->to_proc = target_proc->pid; 3258 - 3259 - /* TODO: reuse incoming transaction for reply */ 3260 - t = kzalloc(sizeof(*t), GFP_KERNEL); 3261 - if (t == NULL) { 3262 - binder_txn_error("%d:%d cannot allocate transaction\n", 3263 - thread->pid, proc->pid); 3264 - return_error = BR_FAILED_REPLY; 3265 - return_error_param = -ENOMEM; 3266 - return_error_line = __LINE__; 3267 - goto err_alloc_t_failed; 3268 - } 3269 - INIT_LIST_HEAD(&t->fd_fixups); 3270 - binder_stats_created(BINDER_STAT_TRANSACTION); 3271 - spin_lock_init(&t->lock); 3272 3237 3273 3238 tcomplete = kzalloc(sizeof(*tcomplete), GFP_KERNEL); 3274 3239 if (tcomplete == NULL) { ··· 3269 3256 goto err_alloc_tcomplete_failed; 3270 3257 } 3271 3258 binder_stats_created(BINDER_STAT_TRANSACTION_COMPLETE); 3272 - 3273 - t->debug_id = t_debug_id; 3274 - t->start_time = t_start_time; 3275 3259 3276 3260 if (reply) 3277 3261 binder_debug(BINDER_DEBUG_TRANSACTION, ··· 3284 3274 target_proc->pid, target_node->debug_id, 3285 3275 (u64)tr->data_size, (u64)tr->offsets_size, 3286 3276 (u64)extra_buffers_size); 3287 - 3288 - if (!reply && !(tr->flags & TF_ONE_WAY)) 3289 - t->from = thread; 3290 - else 3291 - t->from = NULL; 3292 - t->from_pid = proc->pid; 3293 - t->from_tid = thread->pid; 3294 - t->sender_euid = task_euid(proc->tsk); 3295 - t->to_proc = target_proc; 3296 - t->to_thread = target_thread; 3297 - t->code = tr->code; 3298 - t->flags = tr->flags; 3299 - t->priority = task_nice(current); 3300 3277 3301 3278 if (target_node && target_node->txn_security_ctx) { 3302 3279 u32 secid; ··· 3681 3684 tcomplete->type = BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT; 3682 3685 else 3683 3686 tcomplete->type = BINDER_WORK_TRANSACTION_COMPLETE; 3684 - t->work.type = BINDER_WORK_TRANSACTION; 3685 3687 3686 3688 if (reply) { 3687 3689 binder_enqueue_thread_work(thread, tcomplete); ··· 3779 3783 err_alloc_tcomplete_failed: 3780 3784 if (trace_binder_txn_latency_free_enabled()) 3781 3785 binder_txn_latency_free(t); 3782 - kfree(t); 3783 - binder_stats_deleted(BINDER_STAT_TRANSACTION); 3784 - err_alloc_t_failed: 3785 3786 err_bad_todo_list: 3786 3787 err_bad_call_stack: 3787 3788 err_empty_call_stack: ··· 3788 3795 binder_dec_node(target_node, 1, 0); 3789 3796 binder_dec_node_tmpref(target_node); 3790 3797 } 3798 + kfree(t); 3799 + binder_stats_deleted(BINDER_STAT_TRANSACTION); 3800 + err_alloc_t_failed: 3791 3801 3792 3802 binder_debug(BINDER_DEBUG_FAILED_TRANSACTION, 3793 3803 "%d:%d transaction %s to %d:%d failed %d/%d/%d, code %u size %lld-%lld line %d\n",