]> git.hungrycats.org Git - linux/commitdiff
ntb: Fix calculation ntb_transport_tx_free_entry()
authorDave Jiang <dave.jiang@intel.com>
Tue, 22 Aug 2023 16:04:57 +0000 (09:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:48:41 +0000 (09:48 +0200)
commit 5a7693e6bbf19b22fd6c1d2c4b7beb0a03969e2c upstream.

ntb_transport_tx_free_entry() never returns 0 with the current
calculation. If head == tail, then it would return qp->tx_max_entry.
Change compare to tail >= head and when they are equal, a 0 would be
returned.

Fixes: e74bfeedad08 ("NTB: Add flow control to the ntb_netdev")
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: renlonglong <ren.longlong@h3c.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Jon Mason <jdmason@kudzu.us>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/ntb/ntb_transport.c

index 7884ea9c7643fb1536be4109ad18e098f4200fad..9532108d2dce1ea613b400f88d6963b6a0908a04 100644 (file)
@@ -2429,7 +2429,7 @@ unsigned int ntb_transport_tx_free_entry(struct ntb_transport_qp *qp)
        unsigned int head = qp->tx_index;
        unsigned int tail = qp->remote_rx_info->entry;
 
-       return tail > head ? tail - head : qp->tx_max_entry + tail - head;
+       return tail >= head ? tail - head : qp->tx_max_entry + tail - head;
 }
 EXPORT_SYMBOL_GPL(ntb_transport_tx_free_entry);