Use kthread_create_worker() helper to simplify the code. It uses the kthread worker API the right way. It will eventually allow to remove the FIXME in kthread_worker_fn() and add more consistency checks in the future.
Unified · Split
| @@ -1368,7 +1368,7 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) · 1367 unmodified lines | ||
| 1368 | 1368 | |
| 1369 | 1369 | /* If another context is idling the device then defer */ |
| 1370 | 1370 | if (ctlr->idling) { |
| 1371 | − kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages); | |
| 1371 | + kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); | |
| 1372 | 1372 | spin_unlock_irqrestore(&ctlr->queue_lock, flags); |
| 1373 | 1373 | return; |
| 1374 | 1374 | } |
| @@ -1382,7 +1382,7 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) · 7 unmodified lines | ||
| 1382 | 1382 | |
| 1383 | 1383 | /* Only do teardown in the thread */ |
| 1384 | 1384 | if (!in_kthread) { |
| 1385 | − kthread_queue_work(&ctlr->kworker, | |
| 1385 | + kthread_queue_work(ctlr->kworker, | |
| 1386 | 1386 | &ctlr->pump_messages); |
| 1387 | 1387 | spin_unlock_irqrestore(&ctlr->queue_lock, flags); |
| 1388 | 1388 | return; |
| @@ -1618,7 +1618,7 @@ static void spi_set_thread_rt(struct spi_controller *ctlr) · 229 unmodified lines | ||
| 1618 | 1618 | |
| 1619 | 1619 | dev_info(&ctlr->dev, |
| 1620 | 1620 | "will run message pump with realtime priority\n"); |
| 1621 | − sched_setscheduler(ctlr->kworker_task, SCHED_FIFO, ¶m); | |
| 1621 | + sched_setscheduler(ctlr->kworker->task, SCHED_FIFO, ¶m); | |
| 1622 | 1622 | } |
| 1623 | 1623 | |
| 1624 | 1624 | static int spi_init_queue(struct spi_controller *ctlr) |
| @@ -1626,13 +1626,12 @@ static int spi_init_queue(struct spi_controller *ctlr) · 1 unmodified line | ||
| 1626 | 1626 | ctlr->running = false; |
| 1627 | 1627 | ctlr->busy = false; |
| 1628 | 1628 | |
| 1629 | − kthread_init_worker(&ctlr->kworker); | |
| 1630 | − ctlr->kworker_task = kthread_run(kthread_worker_fn, &ctlr->kworker, | |
| 1631 | − "%s", dev_name(&ctlr->dev)); | |
| 1632 | − if (IS_ERR(ctlr->kworker_task)) { | |
| 1633 | − dev_err(&ctlr->dev, "failed to create message pump task\n"); | |
| 1634 | − return PTR_ERR(ctlr->kworker_task); | |
| 1629 | + ctlr->kworker = kthread_create_worker(0, dev_name(&ctlr->dev)); | |
| 1630 | + if (IS_ERR(ctlr->kworker)) { | |
| 1631 | + dev_err(&ctlr->dev, "failed to create message pump kworker\n"); | |
| 1632 | + return PTR_ERR(ctlr->kworker); | |
| 1635 | 1633 | } |
| 1634 | + | |
| 1636 | 1635 | kthread_init_work(&ctlr->pump_messages, spi_pump_messages); |
| 1637 | 1636 | |
| 1638 | 1637 | /* |
| @@ -1716,7 +1715,7 @@ void spi_finalize_current_message(struct spi_controller *ctlr) · 77 unmodified lines | ||
| 1716 | 1715 | ctlr->cur_msg = NULL; |
| 1717 | 1716 | ctlr->cur_msg_prepared = false; |
| 1718 | 1717 | ctlr->fallback = false; |
| 1719 | − kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages); | |
| 1718 | + kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); | |
| 1720 | 1719 | spin_unlock_irqrestore(&ctlr->queue_lock, flags); |
| 1721 | 1720 | |
| 1722 | 1721 | trace_spi_message_done(mesg); |
| @@ -1742,7 +1741,7 @@ static int spi_start_queue(struct spi_controller *ctlr) · 19 unmodified lines | ||
| 1742 | 1741 | ctlr->cur_msg = NULL; |
| 1743 | 1742 | spin_unlock_irqrestore(&ctlr->queue_lock, flags); |
| 1744 | 1743 | |
| 1745 | − kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages); | |
| 1744 | + kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); | |
| 1746 | 1745 | |
| 1747 | 1746 | return 0; |
| 1748 | 1747 | } |
| @@ -1798,8 +1797,7 @@ static int spi_destroy_queue(struct spi_controller *ctlr) · 49 unmodified lines | ||
| 1798 | 1797 | return ret; |
| 1799 | 1798 | } |
| 1800 | 1799 | |
| 1801 | − kthread_flush_worker(&ctlr->kworker); | |
| 1802 | − kthread_stop(ctlr->kworker_task); | |
| 1800 | + kthread_destroy_worker(ctlr->kworker); | |
| 1803 | 1801 | |
| 1804 | 1802 | return 0; |
| 1805 | 1803 | } |
| @@ -1822,7 +1820,7 @@ static int __spi_queued_transfer(struct spi_device *spi, · 16 unmodified lines | ||
| 1822 | 1820 | |
| 1823 | 1821 | list_add_tail(&msg->queue, &ctlr->queue); |
| 1824 | 1822 | if (!ctlr->busy && need_pump) |
| 1825 | − kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages); | |
| 1823 | + kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); | |
| 1826 | 1824 | |
| 1827 | 1825 | spin_unlock_irqrestore(&ctlr->queue_lock, flags); |
| 1828 | 1826 | return 0; |
| @@ -358,8 +358,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) · 357 unmodified lines | ||
| 358 | 358 | * @cleanup: frees controller-specific state |
| 359 | 359 | * @can_dma: determine whether this controller supports DMA |
| 360 | 360 | * @queued: whether this controller is providing an internal message queue |
| 361 | − * @kworker: thread struct for message pump | |
| 362 | − * @kworker_task: pointer to task for message pump kworker thread | |
| 361 | + * @kworker: pointer to thread struct for message pump | |
| 363 | 362 | * @pump_messages: work struct for scheduling work to the message pump |
| 364 | 363 | * @queue_lock: spinlock to syncronise access to message queue |
| 365 | 364 | * @queue: message queue |
| @@ -593,8 +592,7 @@ struct spi_controller { · 227 unmodified lines | ||
| 593 | 592 | * Over time we expect SPI drivers to be phased over to this API. |
| 594 | 593 | */ |
| 595 | 594 | bool queued; |
| 596 | − struct kthread_worker kworker; | |
| 597 | − struct task_struct *kworker_task; | |
| 595 | + struct kthread_worker *kworker; | |
| 598 | 596 | struct kthread_work pump_messages; |
| 599 | 597 | spinlock_t queue_lock; |
| 600 | 598 | struct list_head queue; |