From: "Prückl Thomas" <T.Prueckl@hainzl.at>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: "rcsekar@samsung.com" <rcsekar@samsung.com>,
"linux-can@vger.kernel.org" <linux-can@vger.kernel.org>
Subject: AW: net: m_can: missing mutexes in tx_work_queue and isr-handler
Date: Tue, 10 Dec 2024 15:04:29 +0000 [thread overview]
Message-ID: <a1de308c7f96475281612c8ffa6fc820@hainzl.at> (raw)
In-Reply-To: <20241210-sly-impressive-kittiwake-aff4f1-mkl@pengutronix.de>
> Can you show us the patch?
My current patch currently just locks the isr and work queue.
I guess that additional locks are necessary too (e.g. in m_can_close)
Subject: [PATCH] can: m_can: added mutex to lock isr and tx work queue
---
drivers/net/can/m_can/m_can.c | 17 ++++++++++++++++-
drivers/net/can/m_can/m_can.h | 1 +
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 2395b1225cc8..34de6be2db76 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1085,7 +1085,7 @@ static int m_can_echo_tx_event(struct net_device *dev)
return err;
}
-static irqreturn_t m_can_isr(int irq, void *dev_id)
+static irqreturn_t m_can_isr2(int irq, void *dev_id)
{
struct net_device *dev = (struct net_device *)dev_id;
struct m_can_classdev *cdev = netdev_priv(dev);
@@ -1150,6 +1150,17 @@ static irqreturn_t m_can_isr(int irq, void *dev_id)
return IRQ_HANDLED;
}
+static irqreturn_t m_can_isr(int irq, void *dev_id)
+{
+ struct net_device *dev = (struct net_device *)dev_id;
+ struct m_can_classdev *cdev = netdev_priv(dev);
+ irqreturn_t ret;
+ mutex_lock(&cdev->lock);
+ ret = m_can_isr2(irq, dev_id);
+ mutex_unlock(&cdev->lock);
+ return ret;
+}
+
static const struct can_bittiming_const m_can_bittiming_const_30X = {
.name = KBUILD_MODNAME,
.tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
@@ -1771,7 +1782,9 @@ static void m_can_tx_work_queue(struct work_struct *ws)
struct m_can_classdev *cdev = container_of(ws, struct m_can_classdev,
tx_work);
+ mutex_lock(&cdev->lock);
m_can_tx_handler(cdev);
+ mutex_unlock(&cdev->lock);
}
static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
@@ -1825,6 +1838,8 @@ static int m_can_open(struct net_device *dev)
struct m_can_classdev *cdev = netdev_priv(dev);
int err;
+ mutex_init(&cdev->lock);
+
err = phy_power_on(cdev->transceiver);
if (err)
return err;
diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
index 520e14277dff..9d7245108e60 100644
--- a/drivers/net/can/m_can/m_can.h
+++ b/drivers/net/can/m_can/m_can.h
@@ -91,6 +91,7 @@ struct m_can_classdev {
int pm_clock_support;
int is_peripheral;
+ struct mutex lock;
struct mram_cfg mcfg[MRAM_CFG_NUM];
--
2.34.1
next prev parent reply other threads:[~2024-12-10 15:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 9:02 net: m_can: missing mutexes in tx_work_queue and isr-handler Prückl Thomas
2024-12-10 13:27 ` Marc Kleine-Budde
2024-12-10 15:04 ` Prückl Thomas [this message]
2024-12-18 12:07 ` AW: " 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=a1de308c7f96475281612c8ffa6fc820@hainzl.at \
--to=t.prueckl@hainzl.at \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=rcsekar@samsung.com \
/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