From: Bartosz Golaszewski <brgl@bgdev.pl>
To: "Thomas Gleixner" <tglx@linutronix.de>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski <brgl@bgdev.pl>
Subject: [PATCH] irq/irq_sim: add locking
Date: Thu, 8 Nov 2018 17:47:48 +0100 [thread overview]
Message-ID: <20181108164748.31222-1-brgl@bgdev.pl> (raw)
Two threads can try to fire the irq_sim with different offsets and will
end up fighting for the irq_work asignment. To fix it: add a mutex and
lock it before firing.
Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
include/linux/irq_sim.h | 1 +
kernel/irq/irq_sim.c | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h
index 630a57e55db6..676bfa0c12b9 100644
--- a/include/linux/irq_sim.h
+++ b/include/linux/irq_sim.h
@@ -29,6 +29,7 @@ struct irq_sim {
int irq_base;
unsigned int irq_count;
struct irq_sim_irq_ctx *irqs;
+ struct mutex lock;
};
int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs);
diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
index dd20d0d528d4..2f06c24b51a0 100644
--- a/kernel/irq/irq_sim.c
+++ b/kernel/irq/irq_sim.c
@@ -74,6 +74,7 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs)
}
init_irq_work(&sim->work_ctx.work, irq_sim_handle_irq);
+ mutex_init(&sim->lock);
sim->irq_count = num_irqs;
return sim->irq_base;
@@ -142,10 +143,14 @@ EXPORT_SYMBOL_GPL(devm_irq_sim_init);
*/
void irq_sim_fire(struct irq_sim *sim, unsigned int offset)
{
+ mutex_lock(&sim->lock);
+
if (sim->irqs[offset].enabled) {
sim->work_ctx.irq = irq_sim_irqnum(sim, offset);
irq_work_queue(&sim->work_ctx.work);
}
+
+ mutex_unlock(&sim->lock);
}
EXPORT_SYMBOL_GPL(irq_sim_fire);
--
2.19.1
next reply other threads:[~2018-11-08 16:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-08 16:47 Bartosz Golaszewski [this message]
2018-11-08 19:41 ` [PATCH] irq/irq_sim: add locking Uwe Kleine-König
2018-11-08 20:55 ` Bartosz Golaszewski
2018-11-08 21:25 ` Uwe Kleine-König
2018-11-09 10:19 ` Thomas Gleixner
2018-11-09 11:09 ` Bartosz Golaszewski
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=20181108164748.31222-1-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=u.kleine-koenig@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;
as well as URLs for NNTP newsgroup(s).