Skip to content

Commit 4bd5d43

Browse files
authored
Fix: prevent divide-by-zero in mt_srss_init (#1298)
Add validation to check if nb_rx_q is zero before it can be used in division. If nb_rx_q is zero, return -EINVAL with error message. This prevents the divide-by-zero at line 459 where srss->nb_rx_q / srss->schs_cnt could fail if schs_cnt becomes zero (which happens when nb_rx_q is zero).
1 parent 5770478 commit 4bd5d43

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/src/datapath/mt_shared_rss.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ int mt_srss_init(struct mtl_main_impl* impl) {
454454
mt_srss_uinit(impl);
455455
return -ENOMEM;
456456
}
457+
458+
/* making sure schs_cnt is not zero to prevent divide-by-zero */
459+
if (!srss->schs_cnt) {
460+
err("%s(%d), schs_cnt is zero\n", __func__, port);
461+
mt_srss_uinit(impl);
462+
return -EINVAL;
463+
}
457464
mt_sch_mask_t sch_mask = MT_SCH_MASK_ALL;
458465
uint16_t q_idx = 0;
459466
uint16_t q_per_sch = srss->nb_rx_q / srss->schs_cnt;

0 commit comments

Comments
 (0)