Skip to content

Commit 186615f

Browse files
Maciej Grochowskijonmason
authored andcommitted
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: Maciej Grochowski <Maciej.Grochowski@sony.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent f39e7d0 commit 186615f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/ntb/hw/mscc/ntb_hw_switchtec.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,8 @@ static void switchtec_ntb_init_mw(struct switchtec_ntb *sndev)
12021202
sndev->mmio_self_ctrl);
12031203

12041204
sndev->nr_lut_mw = ioread16(&sndev->mmio_self_ctrl->lut_table_entries);
1205-
sndev->nr_lut_mw = rounddown_pow_of_two(sndev->nr_lut_mw);
1205+
if (sndev->nr_lut_mw)
1206+
sndev->nr_lut_mw = rounddown_pow_of_two(sndev->nr_lut_mw);
12061207

12071208
dev_dbg(&sndev->stdev->dev, "MWs: %d direct, %d lut\n",
12081209
sndev->nr_direct_mw, sndev->nr_lut_mw);
@@ -1212,7 +1213,8 @@ static void switchtec_ntb_init_mw(struct switchtec_ntb *sndev)
12121213

12131214
sndev->peer_nr_lut_mw =
12141215
ioread16(&sndev->mmio_peer_ctrl->lut_table_entries);
1215-
sndev->peer_nr_lut_mw = rounddown_pow_of_two(sndev->peer_nr_lut_mw);
1216+
if (sndev->peer_nr_lut_mw)
1217+
sndev->peer_nr_lut_mw = rounddown_pow_of_two(sndev->peer_nr_lut_mw);
12161218

12171219
dev_dbg(&sndev->stdev->dev, "Peer MWs: %d direct, %d lut\n",
12181220
sndev->peer_nr_direct_mw, sndev->peer_nr_lut_mw);

0 commit comments

Comments
 (0)