unsigned int total_rx_bytes = 0, total_rx_packets = 0;
        u16 next_to_process = rx_ring->next_to_process;
        u16 next_to_clean = rx_ring->next_to_clean;
-       u16 count_mask = rx_ring->count - 1;
        unsigned int xdp_res, xdp_xmit = 0;
        struct xdp_buff *first = NULL;
+       u32 count = rx_ring->count;
        struct bpf_prog *xdp_prog;
+       u32 entries_to_alloc;
        bool failure = false;
-       u16 cleaned_count;
 
        if (next_to_process != next_to_clean)
                first = *i40e_rx_bi(rx_ring, next_to_clean);
                                                      qword);
                        bi = *i40e_rx_bi(rx_ring, next_to_process);
                        xsk_buff_free(bi);
-                       next_to_process = (next_to_process + 1) & count_mask;
+                       if (++next_to_process == count)
+                               next_to_process = 0;
                        continue;
                }
 
                else if (i40e_add_xsk_frag(rx_ring, first, bi, size))
                        break;
 
-               next_to_process = (next_to_process + 1) & count_mask;
+               if (++next_to_process == count)
+                       next_to_process = 0;
 
                if (i40e_is_non_eop(rx_ring, rx_desc))
                        continue;
 
        rx_ring->next_to_clean = next_to_clean;
        rx_ring->next_to_process = next_to_process;
-       cleaned_count = (next_to_clean - rx_ring->next_to_use - 1) & count_mask;
 
-       if (cleaned_count >= I40E_RX_BUFFER_WRITE)
-               failure |= !i40e_alloc_rx_buffers_zc(rx_ring, cleaned_count);
+       entries_to_alloc = I40E_DESC_UNUSED(rx_ring);
+       if (entries_to_alloc >= I40E_RX_BUFFER_WRITE)
+               failure |= !i40e_alloc_rx_buffers_zc(rx_ring, entries_to_alloc);
 
        i40e_finalize_xdp_rx(rx_ring, xdp_xmit);
        i40e_update_rx_stats(rx_ring, total_rx_bytes, total_rx_packets);
 
 void i40e_xsk_clean_rx_ring(struct i40e_ring *rx_ring)
 {
-       u16 count_mask = rx_ring->count - 1;
        u16 ntc = rx_ring->next_to_clean;
        u16 ntu = rx_ring->next_to_use;
 
-       for ( ; ntc != ntu; ntc = (ntc + 1)  & count_mask) {
+       while (ntc != ntu) {
                struct xdp_buff *rx_bi = *i40e_rx_bi(rx_ring, ntc);
 
                xsk_buff_free(rx_bi);
+               ntc++;
+               if (ntc >= rx_ring->count)
+                       ntc = 0;
        }
 }