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
13681368
13691369 /* If another context is idling the device then defer */
13701370 if (ctlr->idling) {
1371− kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
1371+ kthread_queue_work(ctlr->kworker, &ctlr->pump_messages);
13721372 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
13731373 return;
13741374 }
@@ -1382,7 +1382,7 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) · 7 unmodified lines
13821382
13831383 /* Only do teardown in the thread */
13841384 if (!in_kthread) {
1385− kthread_queue_work(&ctlr->kworker,
1385+ kthread_queue_work(ctlr->kworker,
13861386 &ctlr->pump_messages);
13871387 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
13881388 return;
@@ -1618,7 +1618,7 @@ static void spi_set_thread_rt(struct spi_controller *ctlr) · 229 unmodified lines
16181618
16191619 dev_info(&ctlr->dev,
16201620 "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);
16221622 }
16231623
16241624 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
16261626 ctlr->running = false;
16271627 ctlr->busy = false;
16281628
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);
16351633 }
1634+
16361635 kthread_init_work(&ctlr->pump_messages, spi_pump_messages);
16371636
16381637 /*
@@ -1716,7 +1715,7 @@ void spi_finalize_current_message(struct spi_controller *ctlr) · 77 unmodified lines
17161715 ctlr->cur_msg = NULL;
17171716 ctlr->cur_msg_prepared = false;
17181717 ctlr->fallback = false;
1719− kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
1718+ kthread_queue_work(ctlr->kworker, &ctlr->pump_messages);
17201719 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
17211720
17221721 trace_spi_message_done(mesg);
@@ -1742,7 +1741,7 @@ static int spi_start_queue(struct spi_controller *ctlr) · 19 unmodified lines
17421741 ctlr->cur_msg = NULL;
17431742 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
17441743
1745− kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
1744+ kthread_queue_work(ctlr->kworker, &ctlr->pump_messages);
17461745
17471746 return 0;
17481747 }
@@ -1798,8 +1797,7 @@ static int spi_destroy_queue(struct spi_controller *ctlr) · 49 unmodified lines
17981797 return ret;
17991798 }
18001799
1801− kthread_flush_worker(&ctlr->kworker);
1802− kthread_stop(ctlr->kworker_task);
1800+ kthread_destroy_worker(ctlr->kworker);
18031801
18041802 return 0;
18051803 }
@@ -1822,7 +1820,7 @@ static int __spi_queued_transfer(struct spi_device *spi, · 16 unmodified lines
18221820
18231821 list_add_tail(&msg->queue, &ctlr->queue);
18241822 if (!ctlr->busy && need_pump)
1825− kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
1823+ kthread_queue_work(ctlr->kworker, &ctlr->pump_messages);
18261824
18271825 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
18281826 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
358358 * @cleanup: frees controller-specific state
359359 * @can_dma: determine whether this controller supports DMA
360360 * @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
363362 * @pump_messages: work struct for scheduling work to the message pump
364363 * @queue_lock: spinlock to syncronise access to message queue
365364 * @queue: message queue
@@ -593,8 +592,7 @@ struct spi_controller { · 227 unmodified lines
593592 * Over time we expect SPI drivers to be phased over to this API.
594593 */
595594 bool queued;
596− struct kthread_worker kworker;
597− struct task_struct *kworker_task;
595+ struct kthread_worker *kworker;
598596 struct kthread_work pump_messages;
599597 spinlock_t queue_lock;
600598 struct list_head queue;