All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: "Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	linux-can@vger.kernel.org,
	"Oliver Hartkopp" <socketcan@hartkopp.net>
Subject: Re: [PATCH net 12/22] can: m_can: m_can_class_suspend(): fix suspend deinit() error path
Date: Tue, 29 Sep 2026 19:33:36 +0000	[thread overview]
Message-ID: <20260929193336.D5E721F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260928193312.553632-13-mkl@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] can: m_can: data race on active_interrupts between suspend error path and ISR
- [Medium] can: tcan4x5x: unbalanced enable_irq_wake() when m_can_class_suspend() fails
- [Medium] can: m_can: polling hrtimer is permanently disabled on suspend failure
--

commit c427425150087d727cfdd3220f1be90e0a87c37e
Author: Markus Schneider-Pargmann (TI) <msp@baylibre.com>

can: m_can: m_can_class_suspend(): fix suspend deinit() error path

This commit modifies m_can_class_suspend() to restore the device to its
previous state and return an error if deinit() fails. Previously, a
deinit() failure would return an error but not restore the interface.

Link: https://patch.msgid.link/20260918-v7-3-topic-mcan-suspend-fix-fix-v1-1-e24fa70c754e@baylibre.com

> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
> index 16f80607e150e..91a0c5eca260c 100644
> --- a/drivers/net/can/m_can/m_can.c
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -2612,8 +2612,14 @@ int m_can_class_suspend(struct device *dev)
>  			hrtimer_cancel(&cdev->hrtimer);
>  			m_can_write(cdev, M_CAN_IE, IR_RF0N);
>  
> -			if (cdev->ops->deinit)
> +			if (cdev->ops->deinit) {
>  				ret = cdev->ops->deinit(cdev);
> +				if (ret) {
> +					netdev_err(cdev->net, "failed to deinit device while suspending %pe\n",
> +						   ERR_PTR(ret));
> +					goto err_restore_interface;
> +				}
> +			}

[Severity: Medium]
Will this error return cause issues for callers that blindly return the result
without cleaning up on error?

For example, in drivers/net/can/m_can/tcan4x5x-core.c:tcan4x5x_suspend():

    if (cdev->pm_wake_source)
        enable_irq_wake(spi->irq);

    return m_can_class_suspend(dev);

If m_can_class_suspend() returns an error here, the PM core aborts the system
suspend and skips calling tcan4x5x_resume() for this device. Does this leave
the IRQ wake_depth counter unbalanced since disable_irq_wake() is never
called, potentially triggering a WARN_ON in the IRQ core and breaking system
wakeup functionality?

[ ... ]

> +	return 0;
> +
> +err_restore_interface:
> +	if (netif_running(ndev)) {
> +		if (cdev->pm_wake_source) {
> +			/* Enable interrupts that trigger immediately if
> +			 * something is there and keep the hrtimer off
> +			 */
> +			cdev->active_interrupts |= IR_RF0N | IR_TEFN;

[Severity: High]
Can this read-modify-write operation corrupt the software-cached interrupt mask
cdev->active_interrupts?

Because suspend_device_irqs() is not called by the PM core until the
suspend_late phase, hardware interrupts are still fully enabled here (and
IR_RF0N was just explicitly re-enabled earlier in this function).

If a hardware interrupt fires concurrently, m_can_isr() runs and calls
m_can_interrupt_enable(), which performs an unprotected assignment:

drivers/net/can/m_can/m_can.c:m_can_interrupt_enable() {
    ...
    cdev->active_interrupts = interrupts;
    ...
}

Will this concurrent modification result in a data race, leading to permanent
misconfiguration of the hardware M_CAN_IE register (such as permanently lost
RX/TX interrupts)?

> +			m_can_write(cdev, M_CAN_IE, cdev->active_interrupts);
> +		}
> +		netif_device_attach(ndev);
> +		netif_start_queue(ndev);
> +	}
> +
>  	return ret;
>  }

[Severity: Medium]
Does this error path need to restart the polling hrtimer?

If a device operates in polling mode (!cdev->net->irq) but has wakeup-source
set in DT, cdev->pm_wake_source is true.

Earlier in this function, the hrtimer is cancelled:

    hrtimer_cancel(&cdev->hrtimer);

However, this error path restores the network queues but completely fails to
restart the hrtimer. Will this cause the CAN interface to completely stall
with no TX/RX processing?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260928193312.553632-1-mkl@pengutronix.de?part=12

  reply	other threads:[~2026-09-29 19:33 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 18:45 [PATCH net 0/22] pull-request: can 2026-09-28 Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 01/22] can: dev: can_dropped_invalid_skb: drop CAN XL frames on non-CAN XL devices Marc Kleine-Budde
2026-09-28 19:36   ` netdev-bot+sinfo
2026-09-28 18:45 ` [PATCH net 02/22] can: skb: make echo skb freeing safe in any IRQ context Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 03/22] can: skb: make CAN skb allocation failure paths IRQ-safe Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 04/22] can: dev: can_put_echo_skb(): free skb on invalid echo index Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 05/22] can: dev: init_can_skb(): restore skb header initialization Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 06/22] can: j1939: j1939_sk_bind(): fix j1939_ecu leak when re-bind failed Marc Kleine-Budde
2026-09-29  8:56   ` Marc Kleine-Budde
2026-09-29  9:07     ` Tetsuo Handa
2026-09-29  9:39       ` Marc Kleine-Budde
2026-09-29  9:48         ` Tetsuo Handa
2026-09-29  9:53           ` Marc Kleine-Budde
2026-09-29  9:46       ` Marc Kleine-Budde
2026-10-04 11:44     ` Tetsuo Handa
2026-09-28 18:45 ` [PATCH net 07/22] can: isotp: check the frame type, not just the length Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 08/22] can: cc770: platform_get_irq(): propagate the error Marc Kleine-Budde
2026-09-29 19:33   ` sashiko-bot
2026-09-28 18:45 ` [PATCH net 09/22] can: cc770: fix the clock divider check on the platform bus Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 10/22] can: kvaser_pciefd: fix use-after-free in bec poll timer Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 11/22] can: m_can: pci: add missing pm_runtime_dont_use_autosuspend() call Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 12/22] can: m_can: m_can_class_suspend(): fix suspend deinit() error path Marc Kleine-Budde
2026-09-29 19:33   ` sashiko-bot [this message]
2026-09-29 20:34     ` Marc Kleine-Budde
2026-10-01 12:44       ` Markus Schneider-Pargmann
2026-10-01 12:57         ` Oliver Hartkopp
2026-09-28 18:45 ` [PATCH net 13/22] can: sun4i_can: sun4ican_probe(): fix clk leak Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 14/22] can: xilinx_can: set CAN FD flags on received frames Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 15/22] can: mcp251xfd: mcp251xfd_probe(): reject devices without match data Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 16/22] can: hi311x: drop hi3110_lock before free_irq() on open failure Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 17/22] can: ems_usb: use usb_kill_urb() to stop the intr URB Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 18/22] usb: f81604: fix struct f81604_int_data size mismatch Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 19/22] can: gs_usb: kill RX URBs before destroying the netdevs Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 20/22] can: gs_usb: add workarounds for HScanT USB to CAN adapter Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 21/22] can: kvaser_usb: validate command format before parsing in hydra receive path Marc Kleine-Budde
2026-09-28 18:45 ` [PATCH net 22/22] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Marc Kleine-Budde
2026-09-29  1:09 ` [PATCH net 0/22] pull-request: can 2026-09-28 Jakub Kicinski
2026-09-29 21: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=20260929193336.D5E721F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=socketcan@hartkopp.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.