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.

perf: Move common code into both rb and aux branches

if (cond) {
A;
} else {
B;
}
C;

into

if (cond) {
A;
C;
} else {
B;
C;
}

Notably C has a success branch and both A and B have two places for
success. For A (rb case), duplicate the success case because later
patches will result in them no longer being identical. For B (aux
case), share using goto (cleaned up later).

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/r/20250812104019.016252852@infradead.org

+16 -11
+16 -11
kernel/events/core.c
··· 7043 7043 ret = 0; 7044 7044 /* We need the rb to map pages. */ 7045 7045 rb = event->rb; 7046 + perf_mmap_account(vma, user_extra, extra); 7047 + atomic_inc(&event->mmap_count); 7046 7048 goto unlock; 7047 7049 } 7048 7050 ··· 7085 7083 perf_event_init_userpage(event); 7086 7084 perf_event_update_userpage(event); 7087 7085 ret = 0; 7086 + 7087 + perf_mmap_account(vma, user_extra, extra); 7088 + atomic_inc(&event->mmap_count); 7088 7089 } else { 7089 7090 /* 7090 7091 * AUX area mapping: if rb->aux_nr_pages != 0, it's already ··· 7132 7127 if (rb_has_aux(rb)) { 7133 7128 atomic_inc(&rb->aux_mmap_count); 7134 7129 ret = 0; 7135 - goto unlock; 7130 + goto aux_success; 7136 7131 } 7137 7132 7138 7133 if (!perf_mmap_calc_limits(vma, &user_extra, &extra)) { 7139 7134 ret = -EPERM; 7135 + atomic_dec(&rb->mmap_count); 7140 7136 goto unlock; 7141 7137 } 7142 7138 ··· 7148 7142 7149 7143 ret = rb_alloc_aux(rb, event, vma->vm_pgoff, nr_pages, 7150 7144 event->attr.aux_watermark, flags); 7151 - if (!ret) { 7152 - atomic_set(&rb->aux_mmap_count, 1); 7153 - rb->aux_mmap_locked = extra; 7145 + if (ret) { 7146 + atomic_dec(&rb->mmap_count); 7147 + goto unlock; 7154 7148 } 7149 + 7150 + atomic_set(&rb->aux_mmap_count, 1); 7151 + rb->aux_mmap_locked = extra; 7152 + aux_success: 7153 + perf_mmap_account(vma, user_extra, extra); 7154 + atomic_inc(&event->mmap_count); 7155 7155 } 7156 7156 7157 7157 unlock: 7158 - if (!ret) { 7159 - perf_mmap_account(vma, user_extra, extra); 7160 - atomic_inc(&event->mmap_count); 7161 - } else if (rb) { 7162 - /* AUX allocation failed */ 7163 - atomic_dec(&rb->mmap_count); 7164 - } 7165 7158 aux_unlock: 7166 7159 if (aux_mutex) 7167 7160 mutex_unlock(aux_mutex);