From: mb@bu3sch.de (Michael Buesch)
To: Michael Hanselmann <linux-kernel@hansmi.ch>
Cc: lm-sensors@lm-sensors.org, khali@linux-fr.org,
linux-kernel@killerfox.forkbomb.ch, benh@kernel.crashing.org,
johannes@sipsolutions.net, stelian@popies.net,
chainsaw@gentoo.org, dtor@insightbb.com,
stefanr@s5r6.in-berlin.de, linux-kernel@vger.kernel.org
Subject: [lm-sensors] [RFC] Apple Motion Sensor driver
Date: Tue, 04 Jul 2006 16:45:32 +0000 [thread overview]
Message-ID: <200607041845.33352.mb@bu3sch.de> (raw)
In-Reply-To: <20060703224540.GA3785@hansmi.ch>
On Tuesday 04 July 2006 00:45, you wrote:
> +static void ams_handle_irq(void *data)
> +{
> + enum ams_irq irq = *((enum ams_irq *)data);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ams.irq_lock, flags);
> +
> + ams.worker_irqs |= irq;
> + schedule_work(&ams.worker);
> +
> + spin_unlock_irqrestore(&ams.irq_lock, flags);
> +}
I would say this is racy.
Locks should be added as shown below.
> +static void ams_worker(void *data)
> +{
unsigned long flags;
> + mutex_lock(&ams.lock);
> +
> + if (ams.has_device) {
spin_lock_irqsave(&ams.irq_lock, flags);
> + if (ams.worker_irqs & AMS_IRQ_FREEFALL) {
> + if (verbose)
> + printk(KERN_INFO "ams: freefall detected!\n");
> +
> + ams.worker_irqs &= ~AMS_IRQ_FREEFALL;
> + ams.clear_irq(AMS_IRQ_FREEFALL);
> + }
> +
> + if (ams.worker_irqs & AMS_IRQ_SHOCK) {
> + if (verbose)
> + printk(KERN_INFO "ams: shock detected!\n");
> +
> + ams.worker_irqs &= ~AMS_IRQ_SHOCK;
> + ams.clear_irq(AMS_IRQ_SHOCK);
> +
spin_unlock_irqrestore(&ams.irq_lock, flags);
> + }
> +
> + mutex_unlock(&ams.lock);
> +}
Otherwise an IRQ could trigger while the bottom half is
executing and corrupt the ams.worker_irqs field, because it
is modified non-atomically.
--
Greetings Michael.
WARNING: multiple messages have this Message-ID (diff)
From: Michael Buesch <mb@bu3sch.de>
To: Michael Hanselmann <linux-kernel@hansmi.ch>
Cc: lm-sensors@lm-sensors.org, khali@linux-fr.org,
linux-kernel@killerfox.forkbomb.ch, benh@kernel.crashing.org,
johannes@sipsolutions.net, stelian@popies.net,
chainsaw@gentoo.org, dtor@insightbb.com,
stefanr@s5r6.in-berlin.de, linux-kernel@vger.kernel.org
Subject: Re: [RFC] Apple Motion Sensor driver
Date: Tue, 4 Jul 2006 18:45:32 +0200 [thread overview]
Message-ID: <200607041845.33352.mb@bu3sch.de> (raw)
In-Reply-To: <20060703224540.GA3785@hansmi.ch>
On Tuesday 04 July 2006 00:45, you wrote:
> +static void ams_handle_irq(void *data)
> +{
> + enum ams_irq irq = *((enum ams_irq *)data);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ams.irq_lock, flags);
> +
> + ams.worker_irqs |= irq;
> + schedule_work(&ams.worker);
> +
> + spin_unlock_irqrestore(&ams.irq_lock, flags);
> +}
I would say this is racy.
Locks should be added as shown below.
> +static void ams_worker(void *data)
> +{
unsigned long flags;
> + mutex_lock(&ams.lock);
> +
> + if (ams.has_device) {
spin_lock_irqsave(&ams.irq_lock, flags);
> + if (ams.worker_irqs & AMS_IRQ_FREEFALL) {
> + if (verbose)
> + printk(KERN_INFO "ams: freefall detected!\n");
> +
> + ams.worker_irqs &= ~AMS_IRQ_FREEFALL;
> + ams.clear_irq(AMS_IRQ_FREEFALL);
> + }
> +
> + if (ams.worker_irqs & AMS_IRQ_SHOCK) {
> + if (verbose)
> + printk(KERN_INFO "ams: shock detected!\n");
> +
> + ams.worker_irqs &= ~AMS_IRQ_SHOCK;
> + ams.clear_irq(AMS_IRQ_SHOCK);
> +
spin_unlock_irqrestore(&ams.irq_lock, flags);
> + }
> +
> + mutex_unlock(&ams.lock);
> +}
Otherwise an IRQ could trigger while the bottom half is
executing and corrupt the ams.worker_irqs field, because it
is modified non-atomically.
--
Greetings Michael.
next prev parent reply other threads:[~2006-07-04 16:45 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-02 22:26 [lm-sensors] [RFC] Apple Motion Sensor driver Michael Hanselmann
2006-07-02 22:26 ` Michael Hanselmann
2006-07-03 2:33 ` [lm-sensors] " Dmitry Torokhov
2006-07-03 2:33 ` Dmitry Torokhov
2006-07-03 3:14 ` [lm-sensors] " Andrew Morton
2006-07-03 3:14 ` Andrew Morton
2006-07-03 3:47 ` [lm-sensors] " Benjamin Herrenschmidt
2006-07-03 3:47 ` Benjamin Herrenschmidt
2006-07-03 4:00 ` [lm-sensors] " Andrew Morton
2006-07-03 4:00 ` Andrew Morton
2006-07-03 6:56 ` [lm-sensors] " Michael Hanselmann
2006-07-03 6:56 ` Michael Hanselmann
2006-07-03 9:02 ` [lm-sensors] " Stelian Pop
2006-07-03 9:02 ` Stelian Pop
2006-07-03 7:29 ` Jean Delvare
2006-07-03 8:52 ` Benjamin Herrenschmidt
2006-07-03 10:12 ` [lm-sensors] " Stelian Pop
2006-07-03 10:12 ` Stelian Pop
2006-07-03 10:19 ` [lm-sensors] " Johannes Berg
2006-07-03 10:19 ` Johannes Berg
2006-07-03 10:45 ` [lm-sensors] " Michael Hanselmann
2006-07-03 10:45 ` Michael Hanselmann
2006-07-03 10:49 ` [lm-sensors] " Benjamin Herrenschmidt
2006-07-03 10:49 ` Benjamin Herrenschmidt
2006-07-03 11:31 ` [lm-sensors] " Stelian Pop
2006-07-03 11:31 ` Stelian Pop
2006-07-03 13:16 ` [lm-sensors] " Dmitry Torokhov
2006-07-03 13:16 ` Dmitry Torokhov
2006-07-03 13:25 ` [lm-sensors] " Stefan Richter
2006-07-03 13:25 ` Stefan Richter
2006-07-03 13:44 ` [lm-sensors] " Dmitry Torokhov
2006-07-03 13:44 ` Dmitry Torokhov
2006-07-03 22:45 ` [lm-sensors] " Michael Hanselmann
2006-07-03 22:45 ` Michael Hanselmann
2006-07-04 16:45 ` Michael Buesch [this message]
2006-07-04 16:45 ` Michael Buesch
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=200607041845.33352.mb@bu3sch.de \
--to=mb@bu3sch.de \
--cc=benh@kernel.crashing.org \
--cc=chainsaw@gentoo.org \
--cc=dtor@insightbb.com \
--cc=johannes@sipsolutions.net \
--cc=khali@linux-fr.org \
--cc=linux-kernel@hansmi.ch \
--cc=linux-kernel@killerfox.forkbomb.ch \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
--cc=stefanr@s5r6.in-berlin.de \
--cc=stelian@popies.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.