Skip to content

Commit 6309727

Browse files
Andreas Gruenbacherakpm00
authored andcommitted
kthread: add kthread_stop_put
Add a kthread_stop_put() helper that stops a thread and puts its task struct. Use it to replace the various instances of kthread_stop() followed by put_task_struct(). Remove the kthread_stop_put() macro in usbip that is similar but doesn't return the result of kthread_stop(). [[email protected]: fix kerneldoc comment] Link: https://lkml.kernel.org/r/[email protected] [[email protected]: document kthread_stop_put()'s argument] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Andreas Gruenbacher <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ed5378a commit 6309727

File tree

13 files changed

+38
-46
lines changed

13 files changed

+38
-46
lines changed

drivers/accel/ivpu/ivpu_job.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,5 @@ int ivpu_job_done_thread_init(struct ivpu_device *vdev)
618618

619619
void ivpu_job_done_thread_fini(struct ivpu_device *vdev)
620620
{
621-
kthread_stop(vdev->job_done_thread);
622-
put_task_struct(vdev->job_done_thread);
621+
kthread_stop_put(vdev->job_done_thread);
623622
}

drivers/dma-buf/st-dma-fence-chain.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,9 @@ static int find_race(void *arg)
476476
for (i = 0; i < ncpus; i++) {
477477
int ret;
478478

479-
ret = kthread_stop(threads[i]);
479+
ret = kthread_stop_put(threads[i]);
480480
if (ret && !err)
481481
err = ret;
482-
put_task_struct(threads[i]);
483482
}
484483
kfree(threads);
485484

@@ -591,8 +590,7 @@ static int wait_forward(void *arg)
591590
for (i = 0; i < fc.chain_length; i++)
592591
dma_fence_signal(fc.fences[i]);
593592

594-
err = kthread_stop(tsk);
595-
put_task_struct(tsk);
593+
err = kthread_stop_put(tsk);
596594

597595
err:
598596
fence_chains_fini(&fc);
@@ -621,8 +619,7 @@ static int wait_backward(void *arg)
621619
for (i = fc.chain_length; i--; )
622620
dma_fence_signal(fc.fences[i]);
623621

624-
err = kthread_stop(tsk);
625-
put_task_struct(tsk);
622+
err = kthread_stop_put(tsk);
626623

627624
err:
628625
fence_chains_fini(&fc);
@@ -669,8 +666,7 @@ static int wait_random(void *arg)
669666
for (i = 0; i < fc.chain_length; i++)
670667
dma_fence_signal(fc.fences[i]);
671668

672-
err = kthread_stop(tsk);
673-
put_task_struct(tsk);
669+
err = kthread_stop_put(tsk);
674670

675671
err:
676672
fence_chains_fini(&fc);

drivers/dma-buf/st-dma-fence.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,9 @@ static int race_signal_callback(void *arg)
548548
for (i = 0; i < ARRAY_SIZE(t); i++) {
549549
int err;
550550

551-
err = kthread_stop(t[i].task);
551+
err = kthread_stop_put(t[i].task);
552552
if (err && !ret)
553553
ret = err;
554-
555-
put_task_struct(t[i].task);
556554
}
557555
}
558556

drivers/gpu/drm/i915/gt/selftest_migrate.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,9 @@ static int threaded_migrate(struct intel_migrate *migrate,
719719
if (IS_ERR_OR_NULL(tsk))
720720
continue;
721721

722-
status = kthread_stop(tsk);
722+
status = kthread_stop_put(tsk);
723723
if (status && !err)
724724
err = status;
725-
726-
put_task_struct(tsk);
727725
}
728726

729727
kfree(thread);

drivers/net/xen-netback/interface.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,7 @@ int xenvif_connect_ctrl(struct xenvif *vif, grant_ref_t ring_ref,
672672
static void xenvif_disconnect_queue(struct xenvif_queue *queue)
673673
{
674674
if (queue->task) {
675-
kthread_stop(queue->task);
676-
put_task_struct(queue->task);
675+
kthread_stop_put(queue->task);
677676
queue->task = NULL;
678677
}
679678

drivers/usb/usbip/usbip_common.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,6 @@ struct usbip_device {
298298
__k; \
299299
})
300300

301-
#define kthread_stop_put(k) \
302-
do { \
303-
kthread_stop(k); \
304-
put_task_struct(k); \
305-
} while (0)
306-
307301
/* usbip_common.c */
308302
void usbip_dump_urb(struct urb *purb);
309303
void usbip_dump_header(struct usbip_header *pdu);

fs/gfs2/ops_fstype.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,22 +1126,19 @@ static int init_threads(struct gfs2_sbd *sdp)
11261126
return 0;
11271127

11281128
fail:
1129-
kthread_stop(sdp->sd_logd_process);
1130-
put_task_struct(sdp->sd_logd_process);
1129+
kthread_stop_put(sdp->sd_logd_process);
11311130
sdp->sd_logd_process = NULL;
11321131
return error;
11331132
}
11341133

11351134
void gfs2_destroy_threads(struct gfs2_sbd *sdp)
11361135
{
11371136
if (sdp->sd_logd_process) {
1138-
kthread_stop(sdp->sd_logd_process);
1139-
put_task_struct(sdp->sd_logd_process);
1137+
kthread_stop_put(sdp->sd_logd_process);
11401138
sdp->sd_logd_process = NULL;
11411139
}
11421140
if (sdp->sd_quotad_process) {
1143-
kthread_stop(sdp->sd_quotad_process);
1144-
put_task_struct(sdp->sd_quotad_process);
1141+
kthread_stop_put(sdp->sd_quotad_process);
11451142
sdp->sd_quotad_process = NULL;
11461143
}
11471144
}

include/linux/kthread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ void free_kthread_struct(struct task_struct *k);
8686
void kthread_bind(struct task_struct *k, unsigned int cpu);
8787
void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask);
8888
int kthread_stop(struct task_struct *k);
89+
int kthread_stop_put(struct task_struct *k);
8990
bool kthread_should_stop(void);
9091
bool kthread_should_park(void);
9192
bool kthread_should_stop_or_park(void);

kernel/irq/manage.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,15 +1852,13 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
18521852
struct task_struct *t = new->thread;
18531853

18541854
new->thread = NULL;
1855-
kthread_stop(t);
1856-
put_task_struct(t);
1855+
kthread_stop_put(t);
18571856
}
18581857
if (new->secondary && new->secondary->thread) {
18591858
struct task_struct *t = new->secondary->thread;
18601859

18611860
new->secondary->thread = NULL;
1862-
kthread_stop(t);
1863-
put_task_struct(t);
1861+
kthread_stop_put(t);
18641862
}
18651863
out_mput:
18661864
module_put(desc->owner);
@@ -1971,12 +1969,9 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
19711969
* the same bit to a newly requested action.
19721970
*/
19731971
if (action->thread) {
1974-
kthread_stop(action->thread);
1975-
put_task_struct(action->thread);
1976-
if (action->secondary && action->secondary->thread) {
1977-
kthread_stop(action->secondary->thread);
1978-
put_task_struct(action->secondary->thread);
1979-
}
1972+
kthread_stop_put(action->thread);
1973+
if (action->secondary && action->secondary->thread)
1974+
kthread_stop_put(action->secondary->thread);
19801975
}
19811976

19821977
/* Last action releases resources */

kernel/kthread.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,24 @@ int kthread_stop(struct task_struct *k)
715715
}
716716
EXPORT_SYMBOL(kthread_stop);
717717

718+
/**
719+
* kthread_stop_put - stop a thread and put its task struct
720+
* @k: thread created by kthread_create().
721+
*
722+
* Stops a thread created by kthread_create() and put its task_struct.
723+
* Only use when holding an extra task struct reference obtained by
724+
* calling get_task_struct().
725+
*/
726+
int kthread_stop_put(struct task_struct *k)
727+
{
728+
int ret;
729+
730+
ret = kthread_stop(k);
731+
put_task_struct(k);
732+
return ret;
733+
}
734+
EXPORT_SYMBOL(kthread_stop_put);
735+
718736
int kthreadd(void *unused)
719737
{
720738
struct task_struct *tsk = current;

0 commit comments

Comments
 (0)