Commit 186615f8 authored by Maciej Grochowski's avatar Maciej Grochowski Committed by Jon Mason
Browse files

ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut



Number of MW LUTs depends on NTB configuration and can be set to zero,
in such scenario rounddown_pow_of_two will cause undefined behaviour and
should not be performed.
This patch ensures that rounddown_pow_of_two is called on valid value.

Signed-off-by: default avatarMaciej Grochowski <Maciej.Grochowski@sony.com>
Signed-off-by: default avatarJon Mason <jdmason@kudzu.us>
parent f39e7d0e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -1202,6 +1202,7 @@ static void switchtec_ntb_init_mw(struct switchtec_ntb *sndev)
				       sndev->mmio_self_ctrl);

	sndev->nr_lut_mw = ioread16(&sndev->mmio_self_ctrl->lut_table_entries);
	if (sndev->nr_lut_mw)
		sndev->nr_lut_mw = rounddown_pow_of_two(sndev->nr_lut_mw);

	dev_dbg(&sndev->stdev->dev, "MWs: %d direct, %d lut\n",
@@ -1212,6 +1213,7 @@ static void switchtec_ntb_init_mw(struct switchtec_ntb *sndev)

	sndev->peer_nr_lut_mw =
		ioread16(&sndev->mmio_peer_ctrl->lut_table_entries);
	if (sndev->peer_nr_lut_mw)
		sndev->peer_nr_lut_mw = rounddown_pow_of_two(sndev->peer_nr_lut_mw);

	dev_dbg(&sndev->stdev->dev, "Peer MWs: %d direct, %d lut\n",