johnpol@2ka.mipt.ru [PATCH] w1: get rid of the potential problems with atomic operations. ChangeSet 1.2085, 2005/03/02 16:59:41-08:00, johnpol@2ka.mipt.ru [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: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman drivers/w1/w1_family.c | 2 ++ drivers/w1/w1_therm.c | 2 ++ 2 files changed, 4 insertions(+) diff -Nru a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c --- a/drivers/w1/w1_family.c 2005-03-04 12:37:51 -08:00 +++ b/drivers/w1/w1_family.c 2005-03-04 12:37:51 -08:00 @@ -138,7 +138,9 @@ 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); diff -Nru a/drivers/w1/w1_therm.c b/drivers/w1/w1_therm.c --- a/drivers/w1/w1_therm.c 2005-03-04 12:37:51 -08:00 +++ b/drivers/w1/w1_therm.c 2005-03-04 12:37:51 -08:00 @@ -104,6 +104,7 @@ 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 @@ out: up(&dev->mutex); out_dec: + smp_mb__before_atomic_inc(); atomic_dec(&sl->refcnt); return count;