Commit ff1ebf20 authored by Evgeniy Polyakov's avatar Evgeniy Polyakov Committed by Greg Kroah-Hartman

[PATCH] w1: get rid of the potential problems with atomic operations.

Get rid of the potential problems with atomic operations.

According to upcoming atomic_ops.txt by David Miller and Anton Blanchard
some archs may reoder atomic operations with nonatomic, since
the former are always visible but the latter are not, this can lead
to unpredicted behaviour.
Signed-off-by: default avatarEvgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 977f4000
......@@ -138,7 +138,9 @@ void w1_family_get(struct w1_family *f)
void __w1_family_get(struct w1_family *f)
{
smp_mb__before_atomic_inc();
atomic_inc(&f->refcnt);
smp_mb__after_atomic_inc();
}
EXPORT_SYMBOL(w1_family_get);
......
......@@ -104,6 +104,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
int i, max_trying = 10;
atomic_inc(&sl->refcnt);
smp_mb__after_atomic_inc();
if (down_interruptible(&sl->master->mutex)) {
count = 0;
goto out_dec;
......@@ -179,6 +180,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
out:
up(&dev->mutex);
out_dec:
smp_mb__before_atomic_inc();
atomic_dec(&sl->refcnt);
return count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment