From: bvanassche@acm.org (Bart Van Assche) Date: Fri, 28 Jun 2019 16:26:19 -0700 Subject: [PATCH v2] nvme-fc: fix module unloads while lports still pending In-Reply-To: <20190628231621.15867-1-jsmart2021@gmail.com> References: <20190628231621.15867-1-jsmart2021@gmail.com> Message-ID: On 6/28/19 4:16 PM, James Smart wrote: > @@ -237,6 +242,7 @@ nvme_fc_free_lport(struct kref *ref) > put_device(lport->dev); > > kfree(lport); > + > } Spurious whitespace? > +static void > +nvme_fc_cleanup_for_unload(void) > +{ > + struct nvme_fc_lport *lport; > + struct nvme_fc_rport *rport; > + unsigned long flags; > + > + spin_lock_irqsave(&nvme_fc_lock, flags); > + list_for_each_entry(lport, &nvme_fc_lport_list, port_list) { > + list_for_each_entry(rport, &lport->endp_list, endp_list) { > + nvme_fc_delete_controllers(rport); > + } > + } > + spin_unlock_irqrestore(&nvme_fc_lock, flags); > + > + pr_info("%s: waiting for ctlr deletes\n", __func__); > + wait_for_completion(&nvme_fc_unload_proceed); > + pr_info("%s: ctrl deletes complete\n", __func__); > +} > + > static void __exit nvme_fc_exit_module(void) > { > - /* sanity check - all lports should be removed */ > + unsigned long flags; > + bool need_cleanup = false; > + > + spin_lock_irqsave(&nvme_fc_lock, flags); > + nvme_fc_waiting_to_unload = true; > + init_completion(&nvme_fc_unload_proceed); > if (!list_empty(&nvme_fc_lport_list)) > - pr_warn("%s: localport list not empty\n", __func__); > + need_cleanup = true; > + spin_unlock_irqrestore(&nvme_fc_lock, flags); > + if (need_cleanup) > + nvme_fc_cleanup_for_unload(); Can the nvme_fc_lport_list list become empty after nvme_fc_exit_module() has unlocked nvme_fc_lock and before nvme_fc_cleanup_for_unload() is called? If so, shouldn't nvme_fc_cleanup_for_unload() be called unconditionally and shouldn't the wait_for_completion(&nvme_fc_unload_proceed) call depend on whether or not nvme_fc_cleanup_for_unload() has deleted any controllers? Thanks, Bart.