diff options
author | Ido Yariv <ido@wizery.com> | 2013-07-15 20:41:27 +0400 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2013-08-09 16:38:15 +0400 |
commit | 351746c9ad790260ffe5cc78f41e2a8a1e6ab8b6 (patch) | |
tree | 880864271e6378dec80a9467bcf4ce80e8fafc25 /drivers/net/wireless/iwlwifi/pcie/rx.c | |
parent | a9b292464311d32441cd3284109263d92c413a48 (diff) | |
download | linux-351746c9ad790260ffe5cc78f41e2a8a1e6ab8b6.tar.xz |
iwlwifi: pcie: Refactor iwl_rxq_space
Simplify iwl_rxq_space to improve readability and reduce
the ambiguity spares to a single element.
Signed-off-by: Ido Yariv <ido@wizery.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'drivers/net/wireless/iwlwifi/pcie/rx.c')
-rw-r--r-- | drivers/net/wireless/iwlwifi/pcie/rx.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/drivers/net/wireless/iwlwifi/pcie/rx.c b/drivers/net/wireless/iwlwifi/pcie/rx.c index 5fdb4eea146d..8c9641b863f7 100644 --- a/drivers/net/wireless/iwlwifi/pcie/rx.c +++ b/drivers/net/wireless/iwlwifi/pcie/rx.c @@ -112,15 +112,16 @@ */ static int iwl_rxq_space(const struct iwl_rxq *rxq) { - int s = rxq->read - rxq->write; - - if (s <= 0) - s += RX_QUEUE_SIZE; - /* keep some buffer to not confuse full and empty queue */ - s -= 2; - if (s < 0) - s = 0; - return s; + /* Make sure RX_QUEUE_SIZE is a power of 2 */ + BUILD_BUG_ON(RX_QUEUE_SIZE & (RX_QUEUE_SIZE - 1)); + + /* + * There can be up to (RX_QUEUE_SIZE - 1) free slots, to avoid ambiguity + * between empty and completely full queues. + * The following is equivalent to modulo by RX_QUEUE_SIZE and is well + * defined for negative dividends. + */ + return (rxq->read - rxq->write - 1) & (RX_QUEUE_SIZE - 1); } /* |