This is a note to let you know that I've just added the patch titled

    hwmon: (max1111) Fix race condition causing NULL pointer exception

to the 2.6.32-longterm tree which can be found at:
    
http://www.kernel.org/git/?p=linux/kernel/git/longterm/longterm-queue-2.6.32.git;a=summary

The filename of the patch is:
     hwmon-max1111-fix-race-condition-causing-null-pointer-exception.patch
and it can be found in the queue-2.6.32 subdirectory.

If you, or anyone else, feels it should not be added to the 2.6.32 longterm 
tree,
please let <sta...@kernel.org> know about it.


>From d3f684f2820a7f42acef68bea6622d9032127fb2 Mon Sep 17 00:00:00 2001
From: Pavel Herrmann <morpheus.i...@gmail.com>
Date: Sun, 17 Jul 2011 18:39:19 +0200
Subject: hwmon: (max1111) Fix race condition causing NULL pointer exception

From: Pavel Herrmann <morpheus.i...@gmail.com>

commit d3f684f2820a7f42acef68bea6622d9032127fb2 upstream.

spi_sync call uses its spi_message parameter to keep completion information,
using a drvdata structure is not thread-safe. Use a mutex to prevent
multiple access to shared driver data.

Signed-off-by: Pavel Herrmann <morpheus.i...@gmail.com>
Acked-by: Russell King <rmk+ker...@arm.linux.org.uk>
Acked-by: Pavel Machek <pa...@ucw.cz>
Acked-by: Marek Vasut <marek.va...@gmail.com>
Acked-by: Cyril Hrubis <me...@ucw.cz>
Tested-by: Stanislav Brabec <u...@penguin.cz>
Signed-off-by: Jean Delvare <kh...@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gre...@suse.de>

---
 drivers/hwmon/max1111.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

--- a/drivers/hwmon/max1111.c
+++ b/drivers/hwmon/max1111.c
@@ -39,6 +39,8 @@ struct max1111_data {
        struct spi_transfer     xfer[2];
        uint8_t *tx_buf;
        uint8_t *rx_buf;
+       struct mutex            drvdata_lock;
+       /* protect msg, xfer and buffers from multiple access */
 };
 
 static int max1111_read(struct device *dev, int channel)
@@ -47,6 +49,9 @@ static int max1111_read(struct device *d
        uint8_t v1, v2;
        int err;
 
+       /* writing to drvdata struct is not thread safe, wait on mutex */
+       mutex_lock(&data->drvdata_lock);
+
        data->tx_buf[0] = (channel << MAX1111_CTRL_SEL_SH) |
                MAX1111_CTRL_PD0 | MAX1111_CTRL_PD1 |
                MAX1111_CTRL_SGL | MAX1111_CTRL_UNI | MAX1111_CTRL_STR;
@@ -54,12 +59,15 @@ static int max1111_read(struct device *d
        err = spi_sync(data->spi, &data->msg);
        if (err < 0) {
                dev_err(dev, "spi_sync failed with %d\n", err);
+               mutex_unlock(&data->drvdata_lock);
                return err;
        }
 
        v1 = data->rx_buf[0];
        v2 = data->rx_buf[1];
 
+       mutex_unlock(&data->drvdata_lock);
+
        if ((v1 & 0xc0) || (v2 & 0x3f))
                return -EINVAL;
 
@@ -175,6 +183,8 @@ static int __devinit max1111_probe(struc
        if (err)
                goto err_free_data;
 
+       mutex_init(&data->drvdata_lock);
+
        data->spi = spi;
        spi_set_drvdata(spi, data);
 
@@ -212,6 +222,7 @@ static int __devexit max1111_remove(stru
 
        hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
+       mutex_destroy(&data->drvdata_lock);
        kfree(data->rx_buf);
        kfree(data->tx_buf);
        kfree(data);


Patches currently in longterm-queue-2.6.32 which might be from 
morpheus.i...@gmail.com are

/home/gregkh/linux/longterm/longterm-queue-2.6.32/queue-2.6.32/hwmon-max1111-fix-race-condition-causing-null-pointer-exception.patch

_______________________________________________
stable mailing list
stable@linux.kernel.org
http://linux.kernel.org/mailman/listinfo/stable

Reply via email to