]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
staging: iio: isl29018: fixed race condition in in_illuminance_scale_available_show()
authorBrian Masney <masneyb@onstation.org>
Tue, 27 Sep 2016 00:20:18 +0000 (20:20 -0400)
committerJonathan Cameron <jic23@kernel.org>
Sat, 1 Oct 2016 13:53:51 +0000 (14:53 +0100)
in_illuminance_scale_available_show() references the
isl29018_chip->int_time variable in three places inside a for loop.
The value of the int_time variable can be updated by the
isl29018_set_integration_time() function, which is called by the
isl29018_write_raw() function. isl29018_write_raw() locks a
mutex specific to this driver when the integration time variable is
updated.

Signed-off-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/staging/iio/light/isl29018.c

index 19f282c13651015a1f04abd008ff59e6de4c6d28..990c6e52bafe32b31f5e8d5859ae6bf5ae43f68d 100644 (file)
@@ -277,10 +277,12 @@ static ssize_t in_illuminance_scale_available_show
        unsigned int i;
        int len = 0;
 
+       mutex_lock(&chip->lock);
        for (i = 0; i < ARRAY_SIZE(isl29018_scales[chip->int_time]); ++i)
                len += sprintf(buf + len, "%d.%06d ",
                               isl29018_scales[chip->int_time][i].scale,
                               isl29018_scales[chip->int_time][i].uscale);
+       mutex_unlock(&chip->lock);
 
        buf[len - 1] = '\n';