summaryrefslogtreecommitdiff
path: root/drivers/net/can/dev
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2021-01-17 23:06:28 +0100
committerMarc Kleine-Budde <mkl@pengutronix.de>2021-01-27 10:01:46 +0100
commit54eca60b1c94fb1de3e59a936d428a291879de8a (patch)
tree93013bf68a858a6ce1d35f1bd8ece6d49e1a574a /drivers/net/can/dev
parent6fe27d68b45666381691b6a841a2adbda8c8d153 (diff)
can: length: can_fd_len2dlc(): make legnth calculation readable again
In commit 652562e5ff06 ("can: length: can_fd_len2dlc(): simplify length calculcation") the readability of the code degraded and became more error prone. To counteract this, partially convert that patch and replace open coded values (of the original code) with proper defines. Fixes: 652562e5ff06 ("can: length: can_fd_len2dlc(): simplify length calculcation") Cc: Vincent MAILHOL <mailhol.vincent@wanadoo.fr> Link: https://lore.kernel.org/r/20210118201346.79422-1-socketcan@hartkopp.net Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'drivers/net/can/dev')
-rw-r--r--drivers/net/can/dev/length.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/net/can/dev/length.c b/drivers/net/can/dev/length.c
index d35c4e82314d..b48140b1102e 100644
--- a/drivers/net/can/dev/length.c
+++ b/drivers/net/can/dev/length.c
@@ -27,12 +27,17 @@ static const u8 len2dlc[] = {
13, 13, 13, 13, 13, 13, 13, 13, /* 25 - 32 */
14, 14, 14, 14, 14, 14, 14, 14, /* 33 - 40 */
14, 14, 14, 14, 14, 14, 14, 14, /* 41 - 48 */
+ 15, 15, 15, 15, 15, 15, 15, 15, /* 49 - 56 */
+ 15, 15, 15, 15, 15, 15, 15, 15 /* 57 - 64 */
};
/* map the sanitized data length to an appropriate data length code */
u8 can_fd_len2dlc(u8 len)
{
- if (len >= ARRAY_SIZE(len2dlc))
+ /* check for length mapping table size at build time */
+ BUILD_BUG_ON(ARRAY_SIZE(len2dlc) != CANFD_MAX_DLEN + 1);
+
+ if (unlikely(len > CANFD_MAX_DLEN))
return CANFD_MAX_DLC;
return len2dlc[len];