iwlwifi: pcie: Refactor iwl_rxq_space
authorIdo Yariv <ido@wizery.com>
Mon, 15 Jul 2013 16:41:27 +0000 (12:41 -0400)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 9 Aug 2013 12:38:15 +0000 (14:38 +0200)
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>
drivers/net/wireless/iwlwifi/pcie/rx.c

index 5fdb4eea146d34c3e2fcfd49d34453a8316ee60b..8c9641b863f76030501466537e1b472eb1ce9269 100644 (file)
  */
 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);
 }
 
 /*
This page took 0.02635 seconds and 5 git commands to generate.