Skip to content

Commit 1a23d45

Browse files
javlandshenrikbrixandersen
authored andcommitted
modbus: serial: Divide by zero check
Check if the baudrate is not 0 before dividing by it to get the rtu_timeout. Signed-off-by: Jaro Van Landschoot <[email protected]>
1 parent 015643d commit 1a23d45

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

subsys/modbus/modbus_serial.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,11 @@ int modbus_serial_init(struct modbus_context *ctx,
602602
}
603603
}
604604

605+
if (param.serial.baud == 0) {
606+
LOG_ERR("Baudrate is 0");
607+
return -EINVAL;
608+
}
609+
605610
if (param.serial.baud <= 38400) {
606611
cfg->rtu_timeout = (numof_bits * if_delay_max) /
607612
param.serial.baud;

0 commit comments

Comments
 (0)