History

spi: use kthread_create_worker() helper

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.

Marek Szyprowski committed 6 years ago

Commit 60a883d1 parent 0e801d52 files · +14 −18Browse files

Unified · Split

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