Skip to content

Commit 82d5f4a

Browse files
kkaneshigegregkh
authored andcommitted
[PATCH] shpchp: Create shpchpd at controller probe time
The workqueue thread of shpchp driver should be created only when SHPC based hotplug slots are detected on the system. Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Cc: Kristen Accardi <kristen.c.accardi@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent d49f2c4 commit 82d5f4a

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎drivers/pci/hotplug/shpchp_core.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,24 +491,16 @@ static int __init shpcd_init(void)
491491
shpchp_poll_mode = 1;
492492
#endif
493493

494-
shpchp_wq = create_singlethread_workqueue("shpchpd");
495-
if (!shpchp_wq)
496-
return -ENOMEM;
497-
498494
retval = pci_register_driver(&shpc_driver);
499495
dbg("%s: pci_register_driver = %d\n", __FUNCTION__, retval);
500496
info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
501-
if (retval) {
502-
destroy_workqueue(shpchp_wq);
503-
}
504497
return retval;
505498
}
506499

507500
static void __exit shpcd_cleanup(void)
508501
{
509502
dbg("unload_shpchpd()\n");
510503
pci_unregister_driver(&shpc_driver);
511-
destroy_workqueue(shpchp_wq);
512504
info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
513505
}
514506

‎drivers/pci/hotplug/shpchp_hpc.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */
216216
static int ctlr_seq_num = 0; /* Controller sequenc # */
217217
static spinlock_t list_lock;
218218

219+
static atomic_t shpchp_num_controllers = ATOMIC_INIT(0);
220+
219221
static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs);
220222

221223
static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds);
@@ -866,6 +868,13 @@ static void hpc_release_ctlr(struct controller *ctrl)
866868

867869
kfree(php_ctlr);
868870

871+
/*
872+
* If this is the last controller to be released, destroy the
873+
* shpchpd work queue
874+
*/
875+
if (atomic_dec_and_test(&shpchp_num_controllers))
876+
destroy_workqueue(shpchp_wq);
877+
869878
DBG_LEAVE_ROUTINE
870879

871880
}
@@ -1460,6 +1469,16 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
14601469

14611470
ctlr_seq_num++;
14621471

1472+
/*
1473+
* If this is the first controller to be initialized,
1474+
* initialize the shpchpd work queue
1475+
*/
1476+
if (atomic_add_return(1, &shpchp_num_controllers) == 1) {
1477+
shpchp_wq = create_singlethread_workqueue("shpchpd");
1478+
if (!shpchp_wq)
1479+
return -ENOMEM;
1480+
}
1481+
14631482
/*
14641483
* Unmask all event interrupts of all slots
14651484
*/

0 commit comments

Comments
 (0)