Skip to content

Commit

Permalink
can: length: can_fd_len2dlc(): simplify length calculcation
Browse files Browse the repository at this point in the history
If the length paramter in len2dlc() exceeds the size of the len2dlc array, we
return 0xF. This is equal to the last 16 members of the array.

This patch removes these members from the array, uses ARRAY_SIZE() for the
length check, and returns CANFD_MAX_DLC (which is 0xf).

Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/r/20210111141930.693847-9-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Marc Kleine-Budde committed Jan 14, 2021
1 parent 1ea0a52 commit 652562e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions drivers/net/can/dev/length.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ 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 (unlikely(len > 64))
return 0xF;
if (len >= ARRAY_SIZE(len2dlc))
return CANFD_MAX_DLC;

return len2dlc[len];
}
Expand Down

0 comments on commit 652562e

Please sign in to comment.