projects
/
linux.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
1ea0a52
)
can: length: can_fd_len2dlc(): simplify length calculcation
author
Marc Kleine-Budde
<mkl@pengutronix.de>
Mon, 11 Jan 2021 14:19:23 +0000
(15:19 +0100)
committer
Marc Kleine-Budde
<mkl@pengutronix.de>
Thu, 14 Jan 2021 07:43:41 +0000
(08:43 +0100)
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>
drivers/net/can/dev/length.c
patch
|
blob
|
history
diff --git
a/drivers/net/can/dev/length.c
b/drivers/net/can/dev/length.c
index 5e7d481717ea68cc62b1eb2b74d87efd610f095b..64673a8d1234e03af4a13fb72f8e9284c4eda6a9 100644
(file)
--- a/
drivers/net/can/dev/length.c
+++ b/
drivers/net/can/dev/length.c
@@
-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];
}