From: Kalle Valo Date: Thu, 13 Jun 2013 21:08:18 +0300 Subject: [ath9k-devel] [PATCH 5/6] ath10k: wait for CE to drain when shutting down In-Reply-To: <1371040066-17631-6-git-send-email-michal.kazior@tieto.com> (Michal Kazior's message of "Wed, 12 Jun 2013 14:27:45 +0200") References: <1371040066-17631-1-git-send-email-michal.kazior@tieto.com> <1371040066-17631-6-git-send-email-michal.kazior@tieto.com> Message-ID: <87ip1hopd9.fsf@kamboji.qca.qualcomm.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ath9k-devel@lists.ath9k.org Michal Kazior writes: > ath10k_pci_process_ce() is used to process > completions. Only one thread can do that though. > > If one thread starts handling completions then the > other one (i.e. possibly PCI shutdown) would exit > immediatelely and free up memory while completions > are being processed leading to corruption. > > Signed-off-by: Michal Kazior [...] > +/* This function assumes no new data is going to be submitted/completed. It is > + * mainly intended to flush out completions when stopping the device. */ > +static void ath10k_pci_wait_for_ce_drain(struct ath10k *ar) > +{ > + struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); > + int ret; > + > + ret = wait_event_timeout(ar_pci->compl_wq, ({ > + bool processing; > + spin_lock_bh(&ar_pci->compl_lock); > + processing = ar_pci->compl_processing; > + spin_unlock_bh(&ar_pci->compl_lock); > + (!processing); > + }), 5*HZ); > + if (ret == 0) > + ath10k_warn("timed out while waiting for completions to be processed\n"); > +} This looks like a hack to me. Wouldn't it be a better to fix make sure that all threads/tasklets are stopped, for example with tasklet_kill() and cancel_work_sync()? (And of course first making sure that we don't fire new instances). That way we could be sure that there is no other thread running while we shutdown. -- Kalle Valo