Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Scott Murray and committed by
Greg Kroah-Hartman
0bec2c85 694625c0

+21 -45
+21 -45
drivers/pci/hotplug/cpci_hotplug_core.c
··· 35 35 #include <linux/smp_lock.h> 36 36 #include <asm/atomic.h> 37 37 #include <linux/delay.h> 38 + #include <linux/kthread.h> 38 39 #include "cpci_hotplug.h" 39 40 40 41 #define DRIVER_AUTHOR "Scott Murray <scottm@somanetworks.com>" ··· 60 59 static atomic_t extracting; 61 60 int cpci_debug; 62 61 static struct cpci_hp_controller *controller; 63 - static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */ 64 - static struct semaphore thread_exit; /* guard ensure thread has exited before calling it quits */ 65 - static int thread_finished = 1; 62 + static struct task_struct *cpci_thread; 63 + static int thread_finished; 66 64 67 65 static int enable_slot(struct hotplug_slot *slot); 68 66 static int disable_slot(struct hotplug_slot *slot); ··· 357 357 controller->ops->disable_irq(); 358 358 359 359 /* 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); 363 361 return IRQ_HANDLED; 364 362 } 365 363 ··· 519 521 { 520 522 int rc; 521 523 522 - lock_kernel(); 523 - daemonize("cpci_hp_eventd"); 524 - unlock_kernel(); 525 - 526 524 dbg("%s - event thread started", __FUNCTION__); 527 525 while (1) { 528 526 dbg("event thread sleeping"); 529 - down_interruptible(&event_semaphore); 530 - dbg("event thread woken, thread_finished = %d", 531 - thread_finished); 532 - if (thread_finished || signal_pending(current)) 527 + set_current_state(TASK_INTERRUPTIBLE); 528 + schedule(); 529 + if (kthread_should_stop()) 533 530 break; 534 531 do { 535 532 rc = check_slots(); ··· 534 541 } else if (rc < 0) { 535 542 dbg("%s - error checking slots", __FUNCTION__); 536 543 thread_finished = 1; 537 - break; 544 + goto out; 538 545 } 539 - } while (atomic_read(&extracting) && !thread_finished); 540 - if (thread_finished) 546 + } while (atomic_read(&extracting) && !kthread_should_stop()); 547 + if (kthread_should_stop()) 541 548 break; 542 549 543 550 /* Re-enable ENUM# interrupt */ 544 551 dbg("%s - re-enabling irq", __FUNCTION__); 545 552 controller->ops->enable_irq(); 546 553 } 547 - dbg("%s - event thread signals exit", __FUNCTION__); 548 - up(&thread_exit); 554 + out: 549 555 return 0; 550 556 } 551 557 ··· 554 562 { 555 563 int rc; 556 564 557 - lock_kernel(); 558 - daemonize("cpci_hp_polld"); 559 - unlock_kernel(); 560 - 561 565 while (1) { 562 - if (thread_finished || signal_pending(current)) 566 + if (kthread_should_stop() || signal_pending(current)) 563 567 break; 564 568 if (controller->ops->query_enum()) { 565 569 do { ··· 566 578 } else if (rc < 0) { 567 579 dbg("%s - error checking slots", __FUNCTION__); 568 580 thread_finished = 1; 569 - break; 581 + goto out; 570 582 } 571 - } while (atomic_read(&extracting) && !thread_finished); 583 + } while (atomic_read(&extracting) && !kthread_should_stop()); 572 584 } 573 585 msleep(100); 574 586 } 575 - dbg("poll thread signals exit"); 576 - up(&thread_exit); 587 + out: 577 588 return 0; 578 589 } 579 590 580 591 static int 581 592 cpci_start_thread(void) 582 593 { 583 - int pid; 584 - 585 - /* initialize our semaphores */ 586 - init_MUTEX_LOCKED(&event_semaphore); 587 - init_MUTEX_LOCKED(&thread_exit); 588 - thread_finished = 0; 589 - 590 594 if (controller->irq) 591 - pid = kernel_thread(event_thread, NULL, 0); 595 + cpci_thread = kthread_run(event_thread, NULL, "cpci_hp_eventd"); 592 596 else 593 - pid = kernel_thread(poll_thread, NULL, 0); 594 - if (pid < 0) { 597 + cpci_thread = kthread_run(poll_thread, NULL, "cpci_hp_polld"); 598 + if (IS_ERR(cpci_thread)) { 595 599 err("Can't start up our thread"); 596 - return -1; 600 + return PTR_ERR(cpci_thread); 597 601 } 598 - dbg("Our thread pid = %d", pid); 602 + thread_finished = 0; 599 603 return 0; 600 604 } 601 605 602 606 static void 603 607 cpci_stop_thread(void) 604 608 { 609 + kthread_stop(cpci_thread); 605 610 thread_finished = 1; 606 - dbg("thread finish command given"); 607 - if (controller->irq) 608 - up(&event_semaphore); 609 - dbg("wait for thread to exit"); 610 - down(&thread_exit); 611 611 } 612 612 613 613 int