There is a chance pie_cleanup() cannot stop fq_calculate_drop_prob() callout and and as consequence fq_pie_free_sched() cannot free flows memory allocation.
Currently, the code that deal with this problem is complex and could cause races.
We simplify the code by resetting pie instance callout to schedule fqpie_callout_cleanup() that destroy its mtx and free flows allocated memory when number of active sub-queues (nr_active_q) becomes zero.
As dummynet destroys the scheduler instance after calling fq_pie_free_sched(), we moved nr_active_q and flows pointer variables to a separated struct (fq_pie_si_extra). An instance of fq_pie_si_extra is allocated when fq_pie_new_sched() is called.
We also removed freemem_mtx lock and some not needed code.
The patch has been tested without problems.
Patch has been suggested by truckman (Don Lewis)