[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20241029-ancient-sepia-tamarin-26e5af-mkl@pengutronix.de>
Date: Tue, 29 Oct 2024 09:57:12 +0100
From: Marc Kleine-Budde <mkl@...gutronix.de>
To: Dario Binacchi <dario.binacchi@...rulasolutions.com>
Cc: linux-kernel@...r.kernel.org, linux-amarula@...rulasolutions.com,
Vincent Mailhol <mailhol.vincent@...adoo.fr>, linux-can@...r.kernel.org
Subject: Re: [RFC PATCH v2 3/6] can: dev: add helpers to setup an error frame
On 29.10.2024 09:44:47, Dario Binacchi wrote:
> These helpers can prevent errors and code duplication when setting up a
> CAN error frame.
>
> Signed-off-by: Dario Binacchi <dario.binacchi@...rulasolutions.com>
AFAICS in the flexcan driver we don't need the "if (cf)" checks, do we?
Having repeated NULL pointer checks don't feel right.
Marc
>
> ---
>
> Changes in v2:
> - Replace macros with static inline functions
> - Update the commit message
>
> include/linux/can/dev.h | 46 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
>
> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> index 0977656b366d..1b09d30dae32 100644
> --- a/include/linux/can/dev.h
> +++ b/include/linux/can/dev.h
> @@ -168,6 +168,52 @@ static inline bool can_dev_dropped_skb(struct net_device *dev, struct sk_buff *s
> return can_dropped_invalid_skb(dev, skb);
> }
>
> +static inline void can_frame_error_init(struct can_frame *cf)
> +{
> + if (cf)
> + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
> +}
> +
> +static inline void can_frame_set_err_bit0(struct can_frame *cf)
> +{
> + if (cf)
> + cf->data[2] |= CAN_ERR_PROT_BIT0;
> +}
> +
> +static inline void can_frame_set_err_bit1(struct can_frame *cf)
> +{
> + if (cf)
> + cf->data[2] |= CAN_ERR_PROT_BIT1;
> +}
> +
> +static inline void can_frame_set_err_ack(struct can_frame *cf)
> +{
> + if (cf) {
> + cf->can_id |= CAN_ERR_ACK;
> + cf->data[3] = CAN_ERR_PROT_LOC_ACK;
> + }
> +}
> +
> +static inline void can_frame_set_err_crc(struct can_frame *cf)
> +{
> + if (cf) {
> + cf->data[2] |= CAN_ERR_PROT_BIT;
> + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ;
> + }
> +}
> +
> +static inline void can_frame_set_err_form(struct can_frame *cf)
> +{
> + if (cf)
> + cf->data[2] |= CAN_ERR_PROT_FORM;
> +}
> +
> +static inline void can_frame_set_err_stuff(struct can_frame *cf)
> +{
> + if (cf)
> + cf->data[2] |= CAN_ERR_PROT_STUFF;
> +}
> +
> void can_setup(struct net_device *dev);
>
> struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
> --
> 2.43.0
>
>
--
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 |
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists