Thread (4 messages) 4 messages, 2 authors, 2021-01-20

Re: [PATCH v3] can: length: can_fd_len2dlc(): make length calculation readable again

From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: 2021-01-20 08:37:38

On 1/18/21 9:58 PM, Oliver Hartkopp wrote:
quoted
quoted
diff --git a/drivers/net/can/dev/length.c b/drivers/net/can/dev/length.c
index d35c4e82314d..d085cb26d00d 100644
--- a/drivers/net/can/dev/length.c
+++ b/drivers/net/can/dev/length.c
@@ -25,16 +25,21 @@ static const u8 len2dlc[] = {
  	11, 11, 11, 11,			/* 17 - 20 */
  	12, 12, 12, 12,			/* 21 - 24 */
  	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);
                                         ^^^
What about "!="?
"<" makes sure that the table is long enough
"!=" makes sure it has a specific length
From my point of view we want it to have a specific length...
So "<" looks easier to understand to me.

¯\_(ツ)_/¯
...so changed to != why applying to linux-can-next/testing

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help