From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A43D6CE79D5 for ; Wed, 20 Sep 2023 12:05:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235188AbjITMF0 (ORCPT ); Wed, 20 Sep 2023 08:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235227AbjITMEv (ORCPT ); Wed, 20 Sep 2023 08:04:51 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A1AC93 for ; Wed, 20 Sep 2023 05:04:45 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D50E3C433C8; Wed, 20 Sep 2023 12:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1695211485; bh=K6IlsdM94XeDfd488GHJd1GGtqt51nohnYhbhFRn6zU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KVTnoImLn9xvmo/yauruqvXORFL6YJJslAKBHbXUOZ0yZG10NiORoXKp0+CgxlUbq iFC0bmvWzxsKqzlDDFQUBb1xPiH4ZoA2JfJzjKlT9QDFHe17fwnwAQk3MYiM8yl7TF CyDAm0/4GMB0NLAApmOBqmApFr2UKBJ1xEwecPH4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Logan Gunthorpe , renlonglong , Dave Jiang , Jon Mason Subject: [PATCH 4.14 111/186] ntb: Fix calculation ntb_transport_tx_free_entry() Date: Wed, 20 Sep 2023 13:30:14 +0200 Message-ID: <20230920112841.040399297@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230920112836.799946261@linuxfoundation.org> References: <20230920112836.799946261@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dave Jiang 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 Signed-off-by: renlonglong Signed-off-by: Dave Jiang Signed-off-by: Jon Mason Signed-off-by: Greg Kroah-Hartman --- drivers/ntb/ntb_transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/ntb/ntb_transport.c +++ b/drivers/ntb/ntb_transport.c @@ -2199,7 +2199,7 @@ unsigned int ntb_transport_tx_free_entry 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);