Skip to content

Commit f9473c1

Browse files
danieljordan10gregkh
authored andcommitted
padata: Fix list iterator in padata_do_serial()
[ Upstream commit 57ddfec ] list_for_each_entry_reverse() assumes that the iterated list is nonempty and that every list_head is embedded in the same type, but its use in padata_do_serial() breaks both rules. This doesn't cause any issues now because padata_priv and padata_list happen to have their list fields at the same offset, but we really shouldn't be relying on that. Fixes: bfde23c ("padata: unbind parallel jobs from specific CPUs") Signed-off-by: Daniel Jordan <[email protected]> Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 7337adb commit f9473c1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kernel/padata.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,16 @@ void padata_do_serial(struct padata_priv *padata)
390390
int hashed_cpu = padata_cpu_hash(pd, padata->seq_nr);
391391
struct padata_list *reorder = per_cpu_ptr(pd->reorder_list, hashed_cpu);
392392
struct padata_priv *cur;
393+
struct list_head *pos;
393394

394395
spin_lock(&reorder->lock);
395396
/* Sort in ascending order of sequence number. */
396-
list_for_each_entry_reverse(cur, &reorder->list, list)
397+
list_for_each_prev(pos, &reorder->list) {
398+
cur = list_entry(pos, struct padata_priv, list);
397399
if (cur->seq_nr < padata->seq_nr)
398400
break;
399-
list_add(&padata->list, &cur->list);
401+
}
402+
list_add(&padata->list, pos);
400403
spin_unlock(&reorder->lock);
401404

402405
/*

0 commit comments

Comments
 (0)