Skip to content

Commit 0e40852

Browse files
Jakob-KoschelAvenger-285714
authored andcommitted
FROMLIST: staging: android: ashmem: remove usage of list iterator after the loop body
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 head needs to be used explicitly if the variable is NULL. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ifaf19dd876a513a1952fac448079d664aebdf604 (cherry picked from commit 4f49a861af661e062c65f79fff181b804e61e7a3) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 2baa690 commit 0e40852

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

drivers/staging/android/ashmem.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -703,30 +703,33 @@ static int ashmem_pin(struct ashmem_area *asma, size_t pgstart, size_t pgend,
703703
static int ashmem_unpin(struct ashmem_area *asma, size_t pgstart, size_t pgend,
704704
struct ashmem_range **new_range)
705705
{
706-
struct ashmem_range *range, *next;
706+
struct ashmem_range *range = NULL, *iter, *next;
707707
unsigned int purged = ASHMEM_NOT_PURGED;
708708

709709
restart:
710-
list_for_each_entry_safe(range, next, &asma->unpinned_list, unpinned) {
710+
list_for_each_entry_safe(iter, next, &asma->unpinned_list, unpinned) {
711711
/* short circuit: this is our insertion point */
712-
if (range_before_page(range, pgstart))
712+
if (range_before_page(iter, pgstart)) {
713+
range = iter;
713714
break;
715+
}
714716

715717
/*
716718
* The user can ask us to unpin pages that are already entirely
717719
* or partially pinned. We handle those two cases here.
718720
*/
719-
if (page_range_subsumed_by_range(range, pgstart, pgend))
721+
if (page_range_subsumed_by_range(iter, pgstart, pgend))
720722
return 0;
721-
if (page_range_in_range(range, pgstart, pgend)) {
722-
pgstart = min(range->pgstart, pgstart);
723-
pgend = max(range->pgend, pgend);
724-
purged |= range->purged;
725-
range_del(range);
723+
if (page_range_in_range(iter, pgstart, pgend)) {
724+
pgstart = min(iter->pgstart, pgstart);
725+
pgend = max(iter->pgend, pgend);
726+
purged |= iter->purged;
727+
range_del(iter);
726728
goto restart;
727729
}
728730
}
729731

732+
range = list_prepare_entry(range, &asma->unpinned_list, unpinned);
730733
range_alloc(asma, range, purged, pgstart, pgend, new_range);
731734
return 0;
732735
}

0 commit comments

Comments
 (0)