Skip to content

Commit 4e5f2c2

Browse files
lsgunthgregkh
authored andcommitted
ntb_transport: fix bug calculating num_qps_mw
commit 8e8496e0e9564b66165f5219a4e8ed20b0d3fc6b upstream. A divide by zero error occurs if qp_count is less than mw_count because num_qps_mw is calculated to be zero. The calculation appears to be incorrect. The requirement is for num_qps_mw to be set to qp_count / mw_count with any remainder divided among the earlier mws. For example, if mw_count is 5 and qp_count is 12 then mws 0 and 1 will have 3 qps per window and mws 2 through 4 will have 2 qps per window. Thus, when mw_num < qp_count % mw_count, num_qps_mw is 1 higher than when mw_num >= qp_count. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Fixes: e26a584 ("NTB: Split ntb_hw_intel and ntb_transport drivers") Acked-by: Allen Hubbe <Allen.Hubbe@dell.com> Signed-off-by: Jon Mason <jdmason@kudzu.us> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1aac8ff commit 4e5f2c2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/ntb/ntb_transport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ static int ntb_transport_setup_qp_mw(struct ntb_transport_ctx *nt,
599599
if (!mw->virt_addr)
600600
return -ENOMEM;
601601

602-
if (qp_count % mw_count && mw_num + 1 < qp_count / mw_count)
602+
if (mw_num < qp_count % mw_count)
603603
num_qps_mw = qp_count / mw_count + 1;
604604
else
605605
num_qps_mw = qp_count / mw_count;
@@ -947,7 +947,7 @@ static int ntb_transport_init_queue(struct ntb_transport_ctx *nt,
947947
qp->event_handler = NULL;
948948
ntb_qp_link_down_reset(qp);
949949

950-
if (qp_count % mw_count && mw_num + 1 < qp_count / mw_count)
950+
if (mw_num < qp_count % mw_count)
951951
num_qps_mw = qp_count / mw_count + 1;
952952
else
953953
num_qps_mw = qp_count / mw_count;

0 commit comments

Comments
 (0)