locking/ww_mutex/test: Fix potential workqueue corruption · maurer/linux@bccdd80
@@ -479,7 +479,6 @@ static void stress_inorder_work(struct work_struct *work)
479479 } while (!time_after(jiffies, stress->timeout));
480480481481kfree(order);
482-kfree(stress);
483482}
484483485484struct reorder_lock {
@@ -544,7 +543,6 @@ static void stress_reorder_work(struct work_struct *work)
544543list_for_each_entry_safe(ll, ln, &locks, link)
545544kfree(ll);
546545kfree(order);
547-kfree(stress);
548546}
549547550548static void stress_one_work(struct work_struct *work)
@@ -565,8 +563,6 @@ static void stress_one_work(struct work_struct *work)
565563break;
566564 }
567565 } while (!time_after(jiffies, stress->timeout));
568-569-kfree(stress);
570566}
571567572568#define STRESS_INORDER BIT(0)
@@ -577,15 +573,24 @@ static void stress_one_work(struct work_struct *work)
577573static int stress(int nlocks, int nthreads, unsigned int flags)
578574{
579575struct ww_mutex *locks;
580-int n;
576+struct stress *stress_array;
577+int n, count;
581578582579locks = kmalloc_array(nlocks, sizeof(*locks), GFP_KERNEL);
583580if (!locks)
584581return -ENOMEM;
585582583+stress_array = kmalloc_array(nthreads, sizeof(*stress_array),
584+GFP_KERNEL);
585+if (!stress_array) {
586+kfree(locks);
587+return -ENOMEM;
588+ }
589+586590for (n = 0; n < nlocks; n++)
587591ww_mutex_init(&locks[n], &ww_class);
588592593+count = 0;
589594for (n = 0; nthreads; n++) {
590595struct stress *stress;
591596void (*fn)(struct work_struct *work);
@@ -609,9 +614,7 @@ static int stress(int nlocks, int nthreads, unsigned int flags)
609614if (!fn)
610615continue;
611616612-stress = kmalloc(sizeof(*stress), GFP_KERNEL);
613-if (!stress)
614-break;
617+stress = &stress_array[count++];
615618616619INIT_WORK(&stress->work, fn);
617620stress->locks = locks;
@@ -626,6 +629,7 @@ static int stress(int nlocks, int nthreads, unsigned int flags)
626629627630for (n = 0; n < nlocks; n++)
628631ww_mutex_destroy(&locks[n]);
632+kfree(stress_array);
629633kfree(locks);
630634631635return 0;