drivers: can: guard against bitrate of zero

Guard against attempts to set a bitrate of zero as this will lead to
division-by-zero.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2022-03-18 10:35:27 +01:00 committed by Carles Cufí
commit 03accdb6a8

View file

@ -85,7 +85,7 @@ static int can_calc_timing_int(uint32_t core_clock, struct can_timing *res,
int sp_err;
struct can_timing tmp_res;
if (sp >= 1000 ||
if (bitrate == 0 || sp >= 1000 ||
(!IS_ENABLED(CONFIG_CAN_FD_MODE) && bitrate > 1000000) ||
(IS_ENABLED(CONFIG_CAN_FD_MODE) && bitrate > 8000000)) {
return -EINVAL;