From patchwork Thu May 19 12:51:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Herrmann X-Patchwork-Id: 797582 Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4JCsBP0026091 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 19 May 2011 12:54:32 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by bombadil.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QN2hl-0003a7-H2; Thu, 19 May 2011 12:51:53 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QN2hj-0004b0-PG; Thu, 19 May 2011 12:51:51 +0000 Received: from mail-fx0-f49.google.com ([209.85.161.49]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QN2hg-0004ah-1G for linux-arm-kernel@lists.infradead.org; Thu, 19 May 2011 12:51:49 +0000 Received: by fxm14 with SMTP id 14so2448792fxm.36 for ; Thu, 19 May 2011 05:51:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:date:user-agent:cc:references :in-reply-to:mime-version:content-type:message-id; bh=eK2+tPMnaJv/gdsIggxTlelDSYK6YZngn6A3ZPOPeXQ=; b=sV8FqCwopys3YFxiHqIBhApLrCX9iFUjNHjbfW+uQHpd7n/wQC38eI1n8CMEKbjyQg 2s1IhaBqjHa7WQiDTJC5BatvfMTQWx25fnB6qYq8eknAV2uuPrpoGm415p9kC/IkVD3b ha376F5XOLflnWxgKdNxNfQaBqub9NuauteKc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:message-id; b=avJIc2UkZMlyohqrNu0ghkYlQdWUKxTzU/LUTi5fjQA9uwGYDgk/H0AS7EZdH5E2Nv fpO35+PFj1VtY8w2/WLX8kfhG0jk8o3KSqGcJl5zYzDM+yPd1bzBGb9XD62BdYBxGttA PmTWo1Detdj+5kT9yI5aZ/tR9eXCob2Yqy7+w= Received: by 10.223.57.134 with SMTP id c6mr3795355fah.34.1305809505709; Thu, 19 May 2011 05:51:45 -0700 (PDT) Received: from merom.localnet (pavelherrmann.kolej.mff.cuni.cz [78.128.197.20]) by mx.google.com with ESMTPS id o10sm1025944faa.19.2011.05.19.05.51.43 (version=SSLv3 cipher=OTHER); Thu, 19 May 2011 05:51:44 -0700 (PDT) From: Pavel Herrmann To: Pavel Machek Subject: Re: [PATCH] MAX1111: Fix race condition causing NULL pointer exception Date: Thu, 19 May 2011 14:51:40 +0200 User-Agent: KMail/1.13.6 (Linux/2.6.34-gentoo; KDE/4.6.2; x86_64; ; ) References: <1305731918-20164-1-git-send-email-morpheus.ibis@gmail.com> <20110518152935.GJ5913@n2100.arm.linux.org.uk> <20110519123507.GA4950@elf.ucw.cz> In-Reply-To: <20110519123507.GA4950@elf.ucw.cz> MIME-Version: 1.0 Message-Id: <201105191451.40416.morpheus.ibis@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110519_085148_450870_58E31A0F X-CRM114-Status: GOOD ( 19.40 ) X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.161.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is freemail (morpheus.ibis[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RFC_ABUSE_POST Both abuse and postmaster missing on sender domain Cc: eric.y.miao@gmail.com, metan@ucw.cz, utx@penguin.cz, marek.vasut@gmail.com, Russell King - ARM Linux , zaurus-devel@www.linuxtogo.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 19 May 2011 12:54:32 +0000 (UTC) Hi On Thursday, May 19, 2011 02:35:08 PM Pavel Machek wrote: > > you're potentially doing with this: > In some other mail, you said "just add the locking". Pavel H. > actually produced patch doing so... yes, that was the original version of the patch. while I agree with Marek on locks not being the right way, I was going send a cleaner version of the original locking patch today (locking in probe is not really necessary), you just beat me to it. Pavel Herrmann From 5782df40e6c343b6dc9ff5ca008c1ee8b50cad51 Mon Sep 17 00:00:00 2001 From: Pavel Herrmann Date: Mon, 16 May 2011 14:18:18 +0200 Subject: [PATCH 1/2] Fix NULL pointer exception in max1111 Signed-off-by: Pavel Herrmann --- drivers/hwmon/max1111.c | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c index 12a54aa..c748fa3 100644 --- a/drivers/hwmon/max1111.c +++ b/drivers/hwmon/max1111.c @@ -40,6 +40,7 @@ struct max1111_data { struct spi_transfer xfer[2]; uint8_t *tx_buf; uint8_t *rx_buf; + struct mutex msg_lock_mutex; }; static int max1111_read(struct device *dev, int channel) @@ -52,7 +53,14 @@ static int max1111_read(struct device *dev, int channel) MAX1111_CTRL_PD0 | MAX1111_CTRL_PD1 | MAX1111_CTRL_SGL | MAX1111_CTRL_UNI | MAX1111_CTRL_STR; + /* spi_sync requires data not to be freed before function returns + * for static data, any access is dangerous, use locks + */ + mutex_lock(&data->msg_lock_mutex); + err = spi_sync(data->spi, &data->msg); + + mutex_unlock(&data->msg_lock_mutex); if (err < 0) { dev_err(dev, "spi_sync failed with %d\n", err); return err; @@ -138,6 +146,8 @@ static int setup_transfer(struct max1111_data *data) return -ENOMEM; } + mutex_lock(&data->msg_lock_mutex); + m = &data->msg; x = &data->xfer[0]; @@ -152,6 +162,8 @@ static int setup_transfer(struct max1111_data *data) x->len = 2; spi_message_add_tail(x, m); + mutex_unlock(&data->msg_lock_mutex); + return 0; } @@ -172,6 +184,8 @@ static int __devinit max1111_probe(struct spi_device *spi) return -ENOMEM; } + mutex_init(&data->msg_lock_mutex); + err = setup_transfer(data); if (err) goto err_free_data; @@ -213,6 +227,7 @@ static int __devexit max1111_remove(struct spi_device *spi) hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group); + mutex_destroy(data->msg_lock_mutex); kfree(data->rx_buf); kfree(data->tx_buf); kfree(data); -- 1.7.5.rc1