diff options
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/can/dev/length.c | 7 |
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]; |