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));

480480481481

kfree(order);

482-

kfree(stress);

483482

}

484483485484

struct reorder_lock {

@@ -544,7 +543,6 @@ static void stress_reorder_work(struct work_struct *work)

544543

list_for_each_entry_safe(ll, ln, &locks, link)

545544

kfree(ll);

546545

kfree(order);

547-

kfree(stress);

548546

}

549547550548

static void stress_one_work(struct work_struct *work)

@@ -565,8 +563,6 @@ static void stress_one_work(struct work_struct *work)

565563

break;

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)

577573

static int stress(int nlocks, int nthreads, unsigned int flags)

578574

{

579575

struct ww_mutex *locks;

580-

int n;

576+

struct stress *stress_array;

577+

int n, count;

581578582579

locks = kmalloc_array(nlocks, sizeof(*locks), GFP_KERNEL);

583580

if (!locks)

584581

return -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+586590

for (n = 0; n < nlocks; n++)

587591

ww_mutex_init(&locks[n], &ww_class);

588592593+

count = 0;

589594

for (n = 0; nthreads; n++) {

590595

struct stress *stress;

591596

void (*fn)(struct work_struct *work);

@@ -609,9 +614,7 @@ static int stress(int nlocks, int nthreads, unsigned int flags)

609614

if (!fn)

610615

continue;

611616612-

stress = kmalloc(sizeof(*stress), GFP_KERNEL);

613-

if (!stress)

614-

break;

617+

stress = &stress_array[count++];

615618616619

INIT_WORK(&stress->work, fn);

617620

stress->locks = locks;

@@ -626,6 +629,7 @@ static int stress(int nlocks, int nthreads, unsigned int flags)

626629627630

for (n = 0; n < nlocks; n++)

628631

ww_mutex_destroy(&locks[n]);

632+

kfree(stress_array);

629633

kfree(locks);

630634631635

return 0;