Re: [PATCH 1/6] can: esd_usb: Make use of existing kernel macros

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

 



On 17.05.2023 21:22:46, Frank Jungclaus wrote:
> As suggested by Vincent Mailhol make use of existing kernel macros:
> - Use the unit suffixes from linux/units.h for the controller clock
> frequencies
> - Use the BIT() macro to set specific bits in some constants
> - Use CAN_MAX_DLEN (instead of directly using the value 8) for the
> maximum CAN payload length
> 
> Additionally:
> - Spend some commenting for the previously changed constants
> - Add the current year to the copyright notice
> - While adding the header linux/units.h to the list of include files
> also sort that list alphabetically
> 
> Suggested-by: Vincent MAILHOL <mailhol.vincent@xxxxxxxxxx>
> Link: https://lore.kernel.org/all/CAMZ6RqLaDNy-fZ2G0+QMhUEckkXLL+ZyELVSDFmqpd++aBzZQg@xxxxxxxxxxxxxx/
> Signed-off-by: Frank Jungclaus <frank.jungclaus@xxxxxx>
> ---
>  drivers/net/can/usb/esd_usb.c | 38 ++++++++++++++++++-----------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
> index d33bac3a6c10..042dda98b3db 100644
> --- a/drivers/net/can/usb/esd_usb.c
> +++ b/drivers/net/can/usb/esd_usb.c
> @@ -3,19 +3,20 @@
>   * CAN driver for esd electronics gmbh CAN-USB/2 and CAN-USB/Micro
>   *
>   * Copyright (C) 2010-2012 esd electronic system design gmbh, Matthias Fuchs <socketcan@xxxxxx>
> - * Copyright (C) 2022 esd electronics gmbh, Frank Jungclaus <frank.jungclaus@xxxxxx>
> + * Copyright (C) 2022-2023 esd electronics gmbh, Frank Jungclaus <frank.jungclaus@xxxxxx>
>   */
> +#include <linux/can.h>
> +#include <linux/can/dev.h>
> +#include <linux/can/error.h>
> +
>  #include <linux/ethtool.h>
> -#include <linux/signal.h>
> -#include <linux/slab.h>
>  #include <linux/module.h>
>  #include <linux/netdevice.h>
> +#include <linux/signal.h>
> +#include <linux/slab.h>
> +#include <linux/units.h>
>  #include <linux/usb.h>
>  
> -#include <linux/can.h>
> -#include <linux/can/dev.h>
> -#include <linux/can/error.h>
> -
>  MODULE_AUTHOR("Matthias Fuchs <socketcan@xxxxxx>");
>  MODULE_AUTHOR("Frank Jungclaus <frank.jungclaus@xxxxxx>");
>  MODULE_DESCRIPTION("CAN driver for esd electronics gmbh CAN-USB/2 and CAN-USB/Micro interfaces");
> @@ -27,8 +28,8 @@ MODULE_LICENSE("GPL v2");
>  #define USB_CANUSBM_PRODUCT_ID	0x0011
>  
>  /* CAN controller clock frequencies */
> -#define ESD_USB2_CAN_CLOCK	60000000
> -#define ESD_USBM_CAN_CLOCK	36000000
> +#define ESD_USB2_CAN_CLOCK	(60 * MEGA) /* Hz */
> +#define ESD_USBM_CAN_CLOCK	(36 * MEGA) /* Hz */
>  
>  /* Maximum number of CAN nets */
>  #define ESD_USB_MAX_NETS	2
> @@ -42,20 +43,21 @@ MODULE_LICENSE("GPL v2");
>  #define CMD_IDADD		6 /* also used for IDADD_REPLY */
>  
>  /* esd CAN message flags - dlc field */
> -#define ESD_RTR			0x10
> +#define ESD_RTR	BIT(4) /* 0x10 */

Nitpick, personal style preference, maintainability: For me the hex
constant is redundant information, and it's not checked by the compiler,
please remove it.

> +
>  
>  /* esd CAN message flags - id field */
> -#define ESD_EXTID		0x20000000
> -#define ESD_EVENT		0x40000000
> -#define ESD_IDMASK		0x1fffffff
> +#define ESD_EXTID	BIT(29) /* 0x20000000 */
> +#define ESD_EVENT	BIT(30) /* 0x40000000 */
> +#define ESD_IDMASK	0x1fffffff

Please use GEN_MASK.

>  
>  /* esd CAN event ids */
>  #define ESD_EV_CAN_ERROR_EXT	2 /* CAN controller specific diagnostic data */
>  
>  /* baudrate message flags */
> -#define ESD_USB_UBR		0x80000000
> -#define ESD_USB_LOM		0x40000000
> -#define ESD_USB_NO_BAUDRATE	0x7fffffff
> +#define ESD_USB_LOM	BIT(30) /* 0x40000000, Listen Only Mode */
> +#define ESD_USB_UBR	BIT(31) /* 0x80000000, User Bit Rate (controller BTR) in bits 0..27 */
> +#define ESD_USB_NO_BAUDRATE	0x7fffffff /* bit rate unconfigured */

You might use GEN_MASK here, too.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

Attachment: signature.asc
Description: PGP 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