panfrost: Rework midgard_pair_load_store() to kill the nested foreach loop
authorBoris Brezillon <boris.brezillon@collabora.com>
Tue, 27 Aug 2019 10:36:43 +0000 (12:36 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Fri, 13 Sep 2019 10:03:47 +0000 (12:03 +0200)
commitc9bebae2877e55cdcd94f9f9f3f6805238caeb28
treec255641606d991badffc2094e52e94d793b1841a
parent0e513ccca484c9086bdc13181e64c71fb8641649
panfrost: Rework midgard_pair_load_store() to kill the nested foreach loop

mir_foreach_instr_in_block_safe() is based on list_for_each_entry_safe()
which is designed to protect against removal of the current entry, but
removing the entry placed just after the current one will lead to a
use-after-free situation.

Luckily, the midgard_pair_load_store() logic guarantees that the
instruction being removed (if any) is never placed just after ins which
in turn guarantees that the hidden __next variable always points to a
valid object.
Took me a bit of time to realize that this code was safe, so I'm
suggesting to get rid of the inner mir_foreach_instr_in_block_from()
loop and rework the code so that the removed instruction is always the
current one (which is what the list_for_each_entry_safe() API was
initially designed for).

While at it, we also get rid of the unecessary insert(ins)/remove(ins)
dance by simply moving the instruction around.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/midgard/midgard_schedule.c