Skip to content

Commit 474fee3

Browse files
htejunSamuel Ortiz
authored andcommitted
NFC: Use system_nrt_wq instead of custom ones
NFC is using a number of custom ordered workqueues w/ WQ_MEM_RECLAIM. WQ_MEM_RECLAIM is unnecessary unless NFC is gonna be used as transport for storage device, and all use cases match one work item to one ordered workqueue - IOW, there's no actual ordering going on at all and using system_nrt_wq gives the same behavior. There's nothing to be gained by using custom workqueues. Use system_nrt_wq instead and drop all the custom ones. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 5db327f commit 474fee3

9 files changed

Lines changed: 26 additions & 122 deletions

File tree

‎include/net/nfc/hci.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,13 @@ struct nfc_hci_dev {
7474

7575
struct list_head msg_tx_queue;
7676

77-
struct workqueue_struct *msg_tx_wq;
7877
struct work_struct msg_tx_work;
7978

8079
struct timer_list cmd_timer;
8180
struct hci_msg *cmd_pending_msg;
8281

8382
struct sk_buff_head rx_hcp_frags;
8483

85-
struct workqueue_struct *msg_rx_wq;
8684
struct work_struct msg_rx_work;
8785

8886
struct sk_buff_head msg_rx_queue;

‎include/net/nfc/nfc.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ struct nfc_dev {
113113
int tx_tailroom;
114114

115115
struct timer_list check_pres_timer;
116-
struct workqueue_struct *check_pres_wq;
117116
struct work_struct check_pres_work;
118117

119118
struct nfc_ops *ops;

‎include/net/nfc/shdlc.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ struct nfc_shdlc {
7979

8080
struct sk_buff_head ack_pending_q;
8181

82-
struct workqueue_struct *sm_wq;
8382
struct work_struct sm_work;
8483

8584
struct nfc_shdlc_ops *ops;

‎net/nfc/core.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ static void nfc_release(struct device *d)
679679

680680
if (dev->ops->check_presence) {
681681
del_timer_sync(&dev->check_pres_timer);
682-
destroy_workqueue(dev->check_pres_wq);
682+
cancel_work_sync(&dev->check_pres_work);
683683
}
684684

685685
nfc_genl_data_exit(&dev->genl_data);
@@ -715,7 +715,7 @@ static void nfc_check_pres_timeout(unsigned long data)
715715
{
716716
struct nfc_dev *dev = (struct nfc_dev *)data;
717717

718-
queue_work(dev->check_pres_wq, &dev->check_pres_work);
718+
queue_work(system_nrt_wq, &dev->check_pres_work);
719719
}
720720

721721
struct class nfc_class = {
@@ -784,20 +784,11 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
784784
dev->targets_generation = 1;
785785

786786
if (ops->check_presence) {
787-
char name[32];
788787
init_timer(&dev->check_pres_timer);
789788
dev->check_pres_timer.data = (unsigned long)dev;
790789
dev->check_pres_timer.function = nfc_check_pres_timeout;
791790

792791
INIT_WORK(&dev->check_pres_work, nfc_check_pres_work);
793-
snprintf(name, sizeof(name), "nfc%d_check_pres_wq", dev->idx);
794-
dev->check_pres_wq = alloc_workqueue(name, WQ_NON_REENTRANT |
795-
WQ_UNBOUND |
796-
WQ_MEM_RECLAIM, 1);
797-
if (dev->check_pres_wq == NULL) {
798-
kfree(dev);
799-
return NULL;
800-
}
801792
}
802793

803794
return dev;

‎net/nfc/hci/core.c‎

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static void __nfc_hci_cmd_completion(struct nfc_hci_dev *hdev, int err,
141141
kfree(hdev->cmd_pending_msg);
142142
hdev->cmd_pending_msg = NULL;
143143

144-
queue_work(hdev->msg_tx_wq, &hdev->msg_tx_work);
144+
queue_work(system_nrt_wq, &hdev->msg_tx_work);
145145
}
146146

147147
void nfc_hci_resp_received(struct nfc_hci_dev *hdev, u8 result,
@@ -326,7 +326,7 @@ static void nfc_hci_cmd_timeout(unsigned long data)
326326
{
327327
struct nfc_hci_dev *hdev = (struct nfc_hci_dev *)data;
328328

329-
queue_work(hdev->msg_tx_wq, &hdev->msg_tx_work);
329+
queue_work(system_nrt_wq, &hdev->msg_tx_work);
330330
}
331331

332332
static int hci_dev_connect_gates(struct nfc_hci_dev *hdev, u8 gate_count,
@@ -659,23 +659,11 @@ EXPORT_SYMBOL(nfc_hci_free_device);
659659

660660
int nfc_hci_register_device(struct nfc_hci_dev *hdev)
661661
{
662-
struct device *dev = &hdev->ndev->dev;
663-
const char *devname = dev_name(dev);
664-
char name[32];
665-
int r = 0;
666-
667662
mutex_init(&hdev->msg_tx_mutex);
668663

669664
INIT_LIST_HEAD(&hdev->msg_tx_queue);
670665

671666
INIT_WORK(&hdev->msg_tx_work, nfc_hci_msg_tx_work);
672-
snprintf(name, sizeof(name), "%s_hci_msg_tx_wq", devname);
673-
hdev->msg_tx_wq = alloc_workqueue(name, WQ_NON_REENTRANT | WQ_UNBOUND |
674-
WQ_MEM_RECLAIM, 1);
675-
if (hdev->msg_tx_wq == NULL) {
676-
r = -ENOMEM;
677-
goto exit;
678-
}
679667

680668
init_timer(&hdev->cmd_timer);
681669
hdev->cmd_timer.data = (unsigned long)hdev;
@@ -684,27 +672,10 @@ int nfc_hci_register_device(struct nfc_hci_dev *hdev)
684672
skb_queue_head_init(&hdev->rx_hcp_frags);
685673

686674
INIT_WORK(&hdev->msg_rx_work, nfc_hci_msg_rx_work);
687-
snprintf(name, sizeof(name), "%s_hci_msg_rx_wq", devname);
688-
hdev->msg_rx_wq = alloc_workqueue(name, WQ_NON_REENTRANT | WQ_UNBOUND |
689-
WQ_MEM_RECLAIM, 1);
690-
if (hdev->msg_rx_wq == NULL) {
691-
r = -ENOMEM;
692-
goto exit;
693-
}
694675

695676
skb_queue_head_init(&hdev->msg_rx_queue);
696677

697-
r = nfc_register_device(hdev->ndev);
698-
699-
exit:
700-
if (r < 0) {
701-
if (hdev->msg_tx_wq)
702-
destroy_workqueue(hdev->msg_tx_wq);
703-
if (hdev->msg_rx_wq)
704-
destroy_workqueue(hdev->msg_rx_wq);
705-
}
706-
707-
return r;
678+
return nfc_register_device(hdev->ndev);
708679
}
709680
EXPORT_SYMBOL(nfc_hci_register_device);
710681

@@ -725,9 +696,8 @@ void nfc_hci_unregister_device(struct nfc_hci_dev *hdev)
725696

726697
nfc_unregister_device(hdev->ndev);
727698

728-
destroy_workqueue(hdev->msg_tx_wq);
729-
730-
destroy_workqueue(hdev->msg_rx_wq);
699+
cancel_work_sync(&hdev->msg_tx_work);
700+
cancel_work_sync(&hdev->msg_rx_work);
731701
}
732702
EXPORT_SYMBOL(nfc_hci_unregister_device);
733703

@@ -827,7 +797,7 @@ void nfc_hci_recv_frame(struct nfc_hci_dev *hdev, struct sk_buff *skb)
827797
nfc_hci_hcp_message_rx(hdev, pipe, type, instruction, hcp_skb);
828798
} else {
829799
skb_queue_tail(&hdev->msg_rx_queue, hcp_skb);
830-
queue_work(hdev->msg_rx_wq, &hdev->msg_rx_work);
800+
queue_work(system_nrt_wq, &hdev->msg_rx_work);
831801
}
832802
}
833803
EXPORT_SYMBOL(nfc_hci_recv_frame);

‎net/nfc/hci/hcp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe,
108108
list_add_tail(&cmd->msg_l, &hdev->msg_tx_queue);
109109
mutex_unlock(&hdev->msg_tx_mutex);
110110

111-
queue_work(hdev->msg_tx_wq, &hdev->msg_tx_work);
111+
queue_work(system_nrt_wq, &hdev->msg_tx_work);
112112

113113
return 0;
114114

‎net/nfc/hci/shdlc.c‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static void nfc_shdlc_connect_timeout(unsigned long data)
540540

541541
pr_debug("\n");
542542

543-
queue_work(shdlc->sm_wq, &shdlc->sm_work);
543+
queue_work(system_nrt_wq, &shdlc->sm_work);
544544
}
545545

546546
static void nfc_shdlc_t1_timeout(unsigned long data)
@@ -549,7 +549,7 @@ static void nfc_shdlc_t1_timeout(unsigned long data)
549549

550550
pr_debug("SoftIRQ: need to send ack\n");
551551

552-
queue_work(shdlc->sm_wq, &shdlc->sm_work);
552+
queue_work(system_nrt_wq, &shdlc->sm_work);
553553
}
554554

555555
static void nfc_shdlc_t2_timeout(unsigned long data)
@@ -558,7 +558,7 @@ static void nfc_shdlc_t2_timeout(unsigned long data)
558558

559559
pr_debug("SoftIRQ: need to retransmit\n");
560560

561-
queue_work(shdlc->sm_wq, &shdlc->sm_work);
561+
queue_work(system_nrt_wq, &shdlc->sm_work);
562562
}
563563

564564
static void nfc_shdlc_sm_work(struct work_struct *work)
@@ -598,7 +598,7 @@ static void nfc_shdlc_sm_work(struct work_struct *work)
598598
case SHDLC_NEGOCIATING:
599599
if (timer_pending(&shdlc->connect_timer) == 0) {
600600
shdlc->state = SHDLC_CONNECTING;
601-
queue_work(shdlc->sm_wq, &shdlc->sm_work);
601+
queue_work(system_nrt_wq, &shdlc->sm_work);
602602
}
603603

604604
nfc_shdlc_handle_rcv_queue(shdlc);
@@ -662,7 +662,7 @@ static int nfc_shdlc_connect(struct nfc_shdlc *shdlc)
662662

663663
mutex_unlock(&shdlc->state_mutex);
664664

665-
queue_work(shdlc->sm_wq, &shdlc->sm_work);
665+
queue_work(system_nrt_wq, &shdlc->sm_work);
666666

667667
wait_event(connect_wq, shdlc->connect_result != 1);
668668

@@ -679,7 +679,7 @@ static void nfc_shdlc_disconnect(struct nfc_shdlc *shdlc)
679679

680680
mutex_unlock(&shdlc->state_mutex);
681681

682-
queue_work(shdlc->sm_wq, &shdlc->sm_work);
682+
queue_work(system_nrt_wq, &shdlc->sm_work);
683683
}
684684

685685
/*
@@ -697,7 +697,7 @@ void nfc_shdlc_recv_frame(struct nfc_shdlc *shdlc, struct sk_buff *skb)
697697
skb_queue_tail(&shdlc->rcv_q, skb);
698698
}
699699

700-
queue_work(shdlc->sm_wq, &shdlc->sm_work);
700+
queue_work(system_nrt_wq, &shdlc->sm_work);
701701
}
702702
EXPORT_SYMBOL(nfc_shdlc_recv_frame);
703703

@@ -754,7 +754,7 @@ static int nfc_shdlc_xmit(struct nfc_hci_dev *hdev, struct sk_buff *skb)
754754

755755
skb_queue_tail(&shdlc->send_q, skb);
756756

757-
queue_work(shdlc->sm_wq, &shdlc->sm_work);
757+
queue_work(system_nrt_wq, &shdlc->sm_work);
758758

759759
return 0;
760760
}
@@ -843,7 +843,6 @@ struct nfc_shdlc *nfc_shdlc_allocate(struct nfc_shdlc_ops *ops,
843843
{
844844
struct nfc_shdlc *shdlc;
845845
int r;
846-
char name[32];
847846

848847
if (ops->xmit == NULL)
849848
return NULL;
@@ -876,11 +875,6 @@ struct nfc_shdlc *nfc_shdlc_allocate(struct nfc_shdlc_ops *ops,
876875
skb_queue_head_init(&shdlc->ack_pending_q);
877876

878877
INIT_WORK(&shdlc->sm_work, nfc_shdlc_sm_work);
879-
snprintf(name, sizeof(name), "%s_shdlc_sm_wq", devname);
880-
shdlc->sm_wq = alloc_workqueue(name, WQ_NON_REENTRANT | WQ_UNBOUND |
881-
WQ_MEM_RECLAIM, 1);
882-
if (shdlc->sm_wq == NULL)
883-
goto err_allocwq;
884878

885879
shdlc->client_headroom = tx_headroom;
886880
shdlc->client_tailroom = tx_tailroom;
@@ -904,9 +898,6 @@ struct nfc_shdlc *nfc_shdlc_allocate(struct nfc_shdlc_ops *ops,
904898
nfc_hci_free_device(shdlc->hdev);
905899

906900
err_allocdev:
907-
destroy_workqueue(shdlc->sm_wq);
908-
909-
err_allocwq:
910901
kfree(shdlc);
911902

912903
return NULL;
@@ -920,7 +911,7 @@ void nfc_shdlc_free(struct nfc_shdlc *shdlc)
920911
nfc_hci_unregister_device(shdlc->hdev);
921912
nfc_hci_free_device(shdlc->hdev);
922913

923-
destroy_workqueue(shdlc->sm_wq);
914+
cancel_work_sync(&shdlc->sm_work);
924915

925916
skb_queue_purge(&shdlc->rcv_q);
926917
skb_queue_purge(&shdlc->send_q);

0 commit comments

Comments
 (0)