From b46b24b34f35b0b8837588da2f42dbcd4ad62fb4 Mon Sep 17 00:00:00 2001 From: smlng Date: Thu, 22 Feb 2018 19:12:41 +0100 Subject: [PATCH 1/2] sys/can: init variables before usage --- sys/can/device.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sys/can/device.c b/sys/can/device.c index 5ff7b72ce8..6e58c60981 100644 --- a/sys/can/device.c +++ b/sys/can/device.c @@ -473,11 +473,10 @@ int can_device_calc_bittiming(uint32_t clock, const struct can_bittiming_const * uint32_t spt_error; uint32_t min_spt_error = UINT32_MAX; uint32_t best_brp = 0; - uint32_t tseg; - uint32_t tseg1; - uint32_t tseg2; + uint32_t tseg = 0; + uint32_t tseg1 = 0; + uint32_t tseg2 = 0; uint32_t best_tseg = 0; - uint32_t rate; /* current bitrate */ uint32_t rate_error; uint32_t min_rate_error; From 18bccb55e321bc01122829757cddedfd67b3933f Mon Sep 17 00:00:00 2001 From: smlng Date: Thu, 22 Feb 2018 19:13:39 +0100 Subject: [PATCH 2/2] sys/can: reduce scope of variable --- sys/can/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/can/device.c b/sys/can/device.c index 6e58c60981..def5273d6b 100644 --- a/sys/can/device.c +++ b/sys/can/device.c @@ -514,8 +514,8 @@ int can_device_calc_bittiming(uint32_t clock, const struct can_bittiming_const * DEBUG("invalid brp\n"); continue; } - - rate = clock / (brp * nbt); + /* current bitrate */ + uint32_t rate = clock / (brp * nbt); rate_error = max(timing->bitrate, rate) - min(timing->bitrate, rate); if (rate_error > min_rate_error) { DEBUG("timing->rate=%" PRIu32 ", rate=%" PRIu32 ", rate_error=%" PRIu32 " > min_rate_error=%" PRIu32 ", continuing\n",