Messages in this thread Patch in this message | | | From | Jakob Koschel <> | Subject | [PATCH 1/3] ARM: ioremap: remove usage of list iterator for list_add() after the loop body | Date | Thu, 31 Mar 2022 23:47:17 +0200 |
| |
In preparation to limit the scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1].
Before, the code implicitly used the head when no element was found when using &pos->list. Since the new variable is only set if an element was found, the list_add() is performed within the loop and only done after the loop if it is done on the list head directly.
Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com> --- arch/arm/mm/ioremap.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c index aa08bcb72db9..417fd5ffa162 100644 --- a/arch/arm/mm/ioremap.c +++ b/arch/arm/mm/ioremap.c @@ -90,7 +90,7 @@ struct static_vm *find_static_vm_vaddr(void *vaddr) void __init add_static_vm_early(struct static_vm *svm) { - struct static_vm *curr_svm; + struct static_vm *curr_svm = NULL, *iter; struct vm_struct *vm; void *vaddr; @@ -98,13 +98,17 @@ void __init add_static_vm_early(struct static_vm *svm) vm_area_add_early(vm); vaddr = vm->addr; - list_for_each_entry(curr_svm, &static_vmlist, list) { - vm = &curr_svm->vm; + list_for_each_entry(iter, &static_vmlist, list) { + vm = &iter->vm; - if (vm->addr > vaddr) + if (vm->addr > vaddr) { + curr_svm = iter; + list_add_tail(&svm->list, &iter->list); break; + } } - list_add_tail(&svm->list, &curr_svm->list); + if (!curr_svm) + list_add_tail(&svm->list, &static_vmlist); } int ioremap_page(unsigned long virt, unsigned long phys, base-commit: f82da161ea75dc4db21b2499e4b1facd36dab275 -- 2.25.1
| |