Skip to content

Commit 0bec2c8

Browse files
Scott Murraygregkh
authored andcommitted
PCI: cpci_hotplug: Convert to use the kthread API
Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Scott Murray <scottm@somanetworks.com> Acked-by: Kristen Carlson Accardi <kristen.c.accardi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 694625c commit 0bec2c8

1 file changed

Lines changed: 21 additions & 45 deletions

File tree

‎drivers/pci/hotplug/cpci_hotplug_core.c‎

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/smp_lock.h>
3636
#include <asm/atomic.h>
3737
#include <linux/delay.h>
38+
#include <linux/kthread.h>
3839
#include "cpci_hotplug.h"
3940

4041
#define DRIVER_AUTHOR "Scott Murray <scottm@somanetworks.com>"
@@ -59,9 +60,8 @@ static int slots;
5960
static atomic_t extracting;
6061
int cpci_debug;
6162
static struct cpci_hp_controller *controller;
62-
static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
63-
static struct semaphore thread_exit; /* guard ensure thread has exited before calling it quits */
64-
static int thread_finished = 1;
63+
static struct task_struct *cpci_thread;
64+
static int thread_finished;
6565

6666
static int enable_slot(struct hotplug_slot *slot);
6767
static int disable_slot(struct hotplug_slot *slot);
@@ -357,9 +357,7 @@ cpci_hp_intr(int irq, void *data)
357357
controller->ops->disable_irq();
358358

359359
/* Trigger processing by the event thread */
360-
dbg("Signal event_semaphore");
361-
up(&event_semaphore);
362-
dbg("exited cpci_hp_intr");
360+
wake_up_process(cpci_thread);
363361
return IRQ_HANDLED;
364362
}
365363

@@ -521,17 +519,12 @@ event_thread(void *data)
521519
{
522520
int rc;
523521

524-
lock_kernel();
525-
daemonize("cpci_hp_eventd");
526-
unlock_kernel();
527-
528522
dbg("%s - event thread started", __FUNCTION__);
529523
while (1) {
530524
dbg("event thread sleeping");
531-
down_interruptible(&event_semaphore);
532-
dbg("event thread woken, thread_finished = %d",
533-
thread_finished);
534-
if (thread_finished || signal_pending(current))
525+
set_current_state(TASK_INTERRUPTIBLE);
526+
schedule();
527+
if (kthread_should_stop())
535528
break;
536529
do {
537530
rc = check_slots();
@@ -541,18 +534,17 @@ event_thread(void *data)
541534
} else if (rc < 0) {
542535
dbg("%s - error checking slots", __FUNCTION__);
543536
thread_finished = 1;
544-
break;
537+
goto out;
545538
}
546-
} while (atomic_read(&extracting) && !thread_finished);
547-
if (thread_finished)
539+
} while (atomic_read(&extracting) && !kthread_should_stop());
540+
if (kthread_should_stop())
548541
break;
549542

550543
/* Re-enable ENUM# interrupt */
551544
dbg("%s - re-enabling irq", __FUNCTION__);
552545
controller->ops->enable_irq();
553546
}
554-
dbg("%s - event thread signals exit", __FUNCTION__);
555-
up(&thread_exit);
547+
out:
556548
return 0;
557549
}
558550

@@ -562,12 +554,8 @@ poll_thread(void *data)
562554
{
563555
int rc;
564556

565-
lock_kernel();
566-
daemonize("cpci_hp_polld");
567-
unlock_kernel();
568-
569557
while (1) {
570-
if (thread_finished || signal_pending(current))
558+
if (kthread_should_stop() || signal_pending(current))
571559
break;
572560
if (controller->ops->query_enum()) {
573561
do {
@@ -578,48 +566,36 @@ poll_thread(void *data)
578566
} else if (rc < 0) {
579567
dbg("%s - error checking slots", __FUNCTION__);
580568
thread_finished = 1;
581-
break;
569+
goto out;
582570
}
583-
} while (atomic_read(&extracting) && !thread_finished);
571+
} while (atomic_read(&extracting) && !kthread_should_stop());
584572
}
585573
msleep(100);
586574
}
587-
dbg("poll thread signals exit");
588-
up(&thread_exit);
575+
out:
589576
return 0;
590577
}
591578

592579
static int
593580
cpci_start_thread(void)
594581
{
595-
int pid;
596-
597-
/* initialize our semaphores */
598-
init_MUTEX_LOCKED(&event_semaphore);
599-
init_MUTEX_LOCKED(&thread_exit);
600-
thread_finished = 0;
601-
602582
if (controller->irq)
603-
pid = kernel_thread(event_thread, NULL, 0);
583+
cpci_thread = kthread_run(event_thread, NULL, "cpci_hp_eventd");
604584
else
605-
pid = kernel_thread(poll_thread, NULL, 0);
606-
if (pid < 0) {
585+
cpci_thread = kthread_run(poll_thread, NULL, "cpci_hp_polld");
586+
if (IS_ERR(cpci_thread)) {
607587
err("Can't start up our thread");
608-
return -1;
588+
return PTR_ERR(cpci_thread);
609589
}
610-
dbg("Our thread pid = %d", pid);
590+
thread_finished = 0;
611591
return 0;
612592
}
613593

614594
static void
615595
cpci_stop_thread(void)
616596
{
597+
kthread_stop(cpci_thread);
617598
thread_finished = 1;
618-
dbg("thread finish command given");
619-
if (controller->irq)
620-
up(&event_semaphore);
621-
dbg("wait for thread to exit");
622-
down(&thread_exit);
623599
}
624600

625601
int

0 commit comments

Comments
 (0)