From 2b99b05d0a8df85d9a3db36e3912459bb0bba8ef Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Thu, 18 Aug 2022 14:53:51 +0200 Subject: [PATCH] drivers: can: move bitrate limit checks to arbitration/data functions Move the check for the maximum allowed CAN bitrate to the corresponding can_calc_timing()/can_calc_timing_data() function. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_common.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/can/can_common.c b/drivers/can/can_common.c index 113322c69ee..a1deed7b570 100644 --- a/drivers/can/can_common.c +++ b/drivers/can/can_common.c @@ -88,9 +88,7 @@ static int can_calc_timing_int(uint32_t core_clock, struct can_timing *res, int sp_err; struct can_timing tmp_res; - if (bitrate == 0 || sp >= 1000 || - (!IS_ENABLED(CONFIG_CAN_FD_MODE) && bitrate > 1000000) || - (IS_ENABLED(CONFIG_CAN_FD_MODE) && bitrate > 8000000)) { + if (bitrate == 0 || sp >= 1000) { return -EINVAL; } @@ -139,6 +137,10 @@ int z_impl_can_calc_timing(const struct device *dev, struct can_timing *res, uint32_t core_clock; int ret; + if (bitrate > 1000000) { + return -EINVAL; + } + ret = can_get_core_clock(dev, &core_clock); if (ret != 0) { return ret; @@ -156,6 +158,10 @@ int z_impl_can_calc_timing_data(const struct device *dev, struct can_timing *res uint32_t core_clock; int ret; + if (bitrate > 8000000) { + return -EINVAL; + } + ret = can_get_core_clock(dev, &core_clock); if (ret != 0) { return ret;