Re: [net-next 04/13] can: dev: move length related code into seperate file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/11/21 9:49 AM, Oliver Hartkopp wrote:
>> diff --git a/drivers/net/can/dev/length.c b/drivers/net/can/dev/length.c
>> new file mode 100644
>> index 000000000000..540d40dc0bc2
>> --- /dev/null
>> +++ b/drivers/net/can/dev/length.c
>> @@ -0,0 +1,40 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/* Copyright (C) 2005 Marc Kleine-Budde, Pengutronix
>> + * Copyright (C) 2006 Andrey Volkov, Varma Electronics
>> + * Copyright (C) 2008-2009 Wolfgang Grandegger <wg@xxxxxxxxxxxxxx>
>> + */
> 
> See comment below ...
> 
>> +
>> +#include <linux/can/dev.h>
>> +
>> +/* CAN DLC to real data length conversion helpers */
>> +
>> +static const u8 dlc2len[] = {0, 1, 2, 3, 4, 5, 6, 7,
>> +			     8, 12, 16, 20, 24, 32, 48, 64};
>> +
>> +/* get data length from raw data length code (DLC) */
>> +u8 can_fd_dlc2len(u8 dlc)
>> +{
>> +	return dlc2len[dlc & 0x0F];
>> +}
>> +EXPORT_SYMBOL_GPL(can_fd_dlc2len);
>> +
>> +static const u8 len2dlc[] = {0, 1, 2, 3, 4, 5, 6, 7, 8,		/* 0 - 8 */
>> +			     9, 9, 9, 9,			/* 9 - 12 */
>> +			     10, 10, 10, 10,			/* 13 - 16 */
>> +			     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 (unlikely(len > 64))
>> +		return 0xF;
>> +
>> +	return len2dlc[len];
>> +}
>> +EXPORT_SYMBOL_GPL(can_fd_len2dlc);
>> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
>> index 054c3bed190b..d75fba1d030a 100644
>> --- a/include/linux/can/dev.h
>> +++ b/include/linux/can/dev.h
>> @@ -18,6 +18,7 @@
>>   #include <linux/can/bittiming.h>
>>   #include <linux/can/error.h>
>>   #include <linux/can/led.h>
>> +#include <linux/can/length.h>
>>   #include <linux/can/netlink.h>
>>   #include <linux/can/skb.h>
>>   #include <linux/netdevice.h>
>> @@ -83,15 +84,6 @@ struct can_priv {
> 
> 
> (..)
> 
>> diff --git a/include/linux/can/length.h b/include/linux/can/length.h
>> new file mode 100644
>> index 000000000000..fabd93bcde3e
>> --- /dev/null
>> +++ b/include/linux/can/length.h
>> @@ -0,0 +1,51 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * Copyright (C) 2006 Andrey Volkov <avolkov@xxxxxxxxxxxx>
>> + *               Varma Electronics Oy
>> + * Copyright (C) 2008 Wolfgang Grandegger <wg@xxxxxxxxxxxxxx>
> 
> The CAN FD and len8_dlc length stuff was completely contributed by myself.
> 
> So if this code is now moved to a separate file the former Copyrights 
> should be replaced with
> 
> Copyright (C) 2020 Oliver Hartkopp <socketcan@xxxxxxxxxxxx>

Ok. I carried the copyrights from the files I move the from forward to the new file.

For dev.c -> length.c the code was added with:

> commit 1e0625facab2e871472472b7df87d8fbe6caf75a
> Author: Oliver Hartkopp <socketcan@xxxxxxxxxxxx>
> Date:   Wed Jun 13 20:48:21 2012 +0200
> 
>     candev: add/update helpers for CAN FD
>     
>     - update sanity checks
>     - add DLC to length conversion helpers
>       - can_dlc2len() - get data length from can_dlc with sanitized can_dlc
>       - can_len2dlc() - map the sanitized data length to an appropriate DLC
>     
>     Signed-off-by: Oliver Hartkopp <socketcan@xxxxxxxxxxxx>
>     Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>

and then updated with:

> commit c7b74967799b1af52b3045d69d4c26836b2d41de
> Author: Oliver Hartkopp <socketcan@xxxxxxxxxxxx>
> Date:   Fri Nov 20 11:04:44 2020 +0100
> 
>     can: replace can_dlc as variable/element for payload length
>     
>     The naming of can_dlc as element of struct can_frame and also as variable
>     name is misleading as it claims to be a 'data length CODE' but in reality
>     it always was a plain data length.
>     
>     With the indroduction of a new 'len' element in struct can_frame we can now
>     remove can_dlc as name and make clear which of the former uses was a plain
>     length (-> 'len') or a data length code (-> 'dlc') value.
>     
>     Signed-off-by: Oliver Hartkopp <socketcan@xxxxxxxxxxxx>
>     Link: https://lore.kernel.org/r/20201120100444.3199-1-socketcan@xxxxxxxxxxxx
>     [mkl: gs_usb: keep struct gs_host_frame::can_dlc as is]
>     Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>

> commit 3ab4ce0d6fa8c93d41df4a74ec8d2c9198be2109
> Author: Oliver Hartkopp <socketcan@xxxxxxxxxxxx>
> Date:   Tue Nov 10 11:18:49 2020 +0100
> 
>     can: rename CAN FD related can_len2dlc and can_dlc2len helpers
>     
>     The helper functions can_len2dlc and can_dlc2len are only relevant for
>     CAN FD data length code (DLC) conversion.
>     
>     To fit the introduced can_cc_dlc2len for Classical CAN we rename:
>     
>     can_dlc2len -> can_fd_dlc2len to get the payload length from the DLC
>     can_len2dlc -> can_fd_len2dlc to get the DLC from the payload length
>     
>     Suggested-by: Vincent Mailhol <mailhol.vincent@xxxxxxxxxx>
>     Signed-off-by: Oliver Hartkopp <socketcan@xxxxxxxxxxxx>
>     Link: https://lore.kernel.org/r/20201110101852.1973-6-socketcan@xxxxxxxxxxxx
>     Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>

So I'll make copyright:

Copyright (C) 2012, 2020 Oliver Hartkopp <socketcan@xxxxxxxxxxxx>

The changes in dev.h -> length.h were in 2020 only, using that year only.

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 |

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux