Linux CAN drivers development
 help / color / mirror / Atom feed
From: Andrei Lalaev <andrey.lalaev@gmail.com>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: mailhol.vincent@wanadoo.fr, linux-kernel@vger.kernel.org,
	linux-can@vger.kernel.org
Subject: Re: [RFC PATCH] can: gs_usb: fix kernel oops during restart
Date: Tue, 15 Jul 2025 16:24:22 +0200	[thread overview]
Message-ID: <b8221fe9-a167-4bcc-81bf-fb793712b48e@gmail.com> (raw)
In-Reply-To: <20250715-almond-zebra-of-perception-9d2e6c-mkl@pengutronix.de>

On 15.07.2025 11:37, Marc Kleine-Budde wrote:
> On 14.07.2025 19:55:02, Andrei Lalaev wrote:
>> When CAN adapter in BUS_OFF state and "can_restart" is called,
>> it causes the following kernel oops:
> 
> Doh!
> 
> I wonder why no one stumbled over this before. That's a systematic
> problem for all CAN drivers that don't implement this callback.

Hi Mark,

I was also surprised because this callback isn't marked as mandatory
and that there are no additional checks.

> 
> What about this fix?
> 
> diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
> index 13826e8a707b..94603c9eb4aa 100644
> --- a/drivers/net/can/dev/netlink.c
> +++ b/drivers/net/can/dev/netlink.c
> @@ -285,6 +285,12 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],
>          }
>  
>          if (data[IFLA_CAN_RESTART_MS]) {
> +                if (!priv->do_set_mode) {
> +                        NL_SET_ERR_MSG(extack,
> +                                       "device doesn't support restart from Bus Off");
> +                        return -EOPNOTSUPP;
> +                }
> +
>                  /* Do not allow changing restart delay while running */
>                  if (dev->flags & IFF_UP)
>                          return -EBUSY;
> @@ -292,6 +298,12 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],
>          }
>  
>          if (data[IFLA_CAN_RESTART]) {
> +                if (!priv->do_set_mode) {
> +                        NL_SET_ERR_MSG(extack,
> +                                       "device doesn't support restart from Bus Off");
> +                        return -EOPNOTSUPP;
> +                }
> +
>                  /* Do not allow a restart while not running */
>                  if (!(dev->flags & IFF_UP))
>                          return -EINVAL;
> 
> regards,
> Marc
> 

Thanks for the patch. As expected, it fixes the kernel OOPS,
but the interface never leaves the BUS_OFF state.

-- 
Best regards,
Andrei Lalaev

  reply	other threads:[~2025-07-15 14:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-14 17:55 [RFC PATCH] can: gs_usb: fix kernel oops during restart Andrei Lalaev
2025-07-15  9:37 ` Marc Kleine-Budde
2025-07-15 14:24   ` Andrei Lalaev [this message]
2025-07-15 14:29     ` Marc Kleine-Budde
2025-07-16  5:45       ` Andrei Lalaev
2025-07-16  5:55         ` Marc Kleine-Budde
2025-10-20 10:12   ` Marc Kleine-Budde
2025-10-20 10:12   ` Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b8221fe9-a167-4bcc-81bf-fb793712b48e@gmail.com \
    --to=andrey.lalaev@gmail.com \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mkl@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox