The calculation results of the variables 'func_addr' and 'func_size' are not affected by the for loop and do not change due to the changes of entries[i]. The performance can be improved by moving it outside the loop. No functional change.
Showing the changes to kernel/livepatch (1 of 1 file). Show all
Unified · Split
| @@ -196,36 +196,36 @@ static int klp_check_stack_func(struct klp_func *func, unsigned long *entries, · 195 unmodified lines | ||
| 196 | 196 | struct klp_ops *ops; |
| 197 | 197 | int i; |
| 198 | 198 | |
| 199 | − for (i = 0; i < nr_entries; i++) { | |
| 200 | − address = entries[i]; | |
| 199 | + if (klp_target_state == KLP_UNPATCHED) { | |
| 200 | + /* | |
| 201 | + * Check for the to-be-unpatched function | |
| 202 | + * (the func itself). | |
| 203 | + */ | |
| 204 | + func_addr = (unsigned long)func->new_func; | |
| 205 | + func_size = func->new_size; | |
| 206 | + } else { | |
| 207 | + /* | |
| 208 | + * Check for the to-be-patched function | |
| 209 | + * (the previous func). | |
| 210 | + */ | |
| 211 | + ops = klp_find_ops(func->old_func); | |
| 201 | 212 | |
| 202 | − if (klp_target_state == KLP_UNPATCHED) { | |
| 203 | − /* | |
| 204 | − * Check for the to-be-unpatched function | |
| 205 | − * (the func itself). | |
| 206 | − */ | |
| 207 | − func_addr = (unsigned long)func->new_func; | |
| 208 | − func_size = func->new_size; | |
| 213 | + if (list_is_singular(&ops->func_stack)) { | |
| 214 | + /* original function */ | |
| 215 | + func_addr = (unsigned long)func->old_func; | |
| 216 | + func_size = func->old_size; | |
| 209 | 217 | } else { |
| 210 | − /* | |
| 211 | − * Check for the to-be-patched function | |
| 212 | − * (the previous func). | |
| 213 | − */ | |
| 214 | − ops = klp_find_ops(func->old_func); | |
| 215 | − | |
| 216 | − if (list_is_singular(&ops->func_stack)) { | |
| 217 | − /* original function */ | |
| 218 | − func_addr = (unsigned long)func->old_func; | |
| 219 | − func_size = func->old_size; | |
| 220 | − } else { | |
| 221 | − /* previously patched function */ | |
| 222 | − struct klp_func *prev; | |
| 223 | − | |
| 224 | − prev = list_next_entry(func, stack_node); | |
| 225 | − func_addr = (unsigned long)prev->new_func; | |
| 226 | − func_size = prev->new_size; | |
| 227 | − } | |
| 218 | + /* previously patched function */ | |
| 219 | + struct klp_func *prev; | |
| 220 | + | |
| 221 | + prev = list_next_entry(func, stack_node); | |
| 222 | + func_addr = (unsigned long)prev->new_func; | |
| 223 | + func_size = prev->new_size; | |
| 228 | 224 | } |
| 225 | + } | |
| 226 | + | |
| 227 | + for (i = 0; i < nr_entries; i++) { | |
| 228 | + address = entries[i]; | |
| 229 | 229 | |
| 230 | 230 | if (address >= func_addr && address < func_addr + func_size) |
| 231 | 231 | return -EAGAIN; |