mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Pavel Herrmann <morpheus.ibis@gmail.com>,
	Russell King <rmk+kernel@arm.linux.org.uk>,
	Pavel Machek <pavel@ucw.cz>, Marek Vasut <marek.vasut@gmail.com>,
	Cyril Hrubis <metan@ucw.cz>, Jean Delvare <khali@linux-fr.org>
Subject: [50/70] hwmon: (max1111) Fix race condition causing NULL pointer exception
Date: Mon, 01 Aug 2011 16:19:05 -0700	[thread overview]
Message-ID: <20110801232055.630132100@clark.kroah.org> (raw)
In-Reply-To: <20110801232124.GA15313@kroah.com>

2.6.39-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Pavel Herrmann <morpheus.ibis@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.ibis@gmail.com>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
Acked-by: Pavel Machek <pavel@ucw.cz>
Acked-by: Marek Vasut <marek.vasut@gmail.com>
Acked-by: Cyril Hrubis <metan@ucw.cz>
Tested-by: Stanislav Brabec <utx@penguin.cz>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

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

--- a/drivers/hwmon/max1111.c
+++ b/drivers/hwmon/max1111.c
@@ -40,6 +40,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)
@@ -48,6 +50,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;
@@ -55,12 +60,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;
 
@@ -176,6 +184,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);
 
@@ -213,6 +223,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);



  parent reply	other threads:[~2011-08-01 23:26 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-01 23:21 [00/70] 2.6.39.4-stable review Greg KH
2011-08-01 23:18 ` [01/70] USB: serial: add IDs for WinChipHead USB->RS232 adapter Greg KH
2011-08-01 23:18 ` [02/70] drm/radeon/kms: free ib pool on module unloading Greg KH
2011-08-01 23:18 ` [03/70] drm/radeon/kms: fix typo in evergreen disp int status register Greg KH
2011-08-01 23:18 ` [04/70] drm/radeon/kms: fix typo in IH_CNTL swap bitfield Greg KH
2011-08-01 23:18 ` [05/70] mm: vmscan: correct check for kswapd sleeping in sleeping_prematurely Greg KH
2011-08-01 23:18 ` [06/70] mm/nommu.c: fix remap_pfn_range() Greg KH
2011-08-01 23:18 ` [07/70] mm: vmscan: evaluate the watermarks against the correct classzone Greg KH
2011-08-01 23:18 ` [08/70] hwmon: (lm95241) Fix chip detection code Greg KH
2011-08-01 23:18 ` [09/70] hwmon: (lm95241) Fix negative temperature results Greg KH
2011-08-01 23:18 ` [10/70] hwmon: (pmbus) Auto-detect temp2 and temp3 registers/attributes Greg KH
2011-08-01 23:18 ` [11/70] hwmon: (pmbus) Drop check for PMBus revision register in probe function Greg KH
2011-08-01 23:18 ` [12/70] hwmon: (pmbus) Improve fan detection Greg KH
2011-08-01 23:18 ` [13/70] hwmon: (pmbus) Use long variables for register to data conversions Greg KH
2011-08-01 23:18 ` [14/70] ASoC: Fix Blackfin I2S _pointer() implementation return in bounds values Greg KH
2011-08-01 23:18 ` [15/70] ASoC: Ensure we delay long enough for WM8994 FLL to lock when starting Greg KH
2011-08-01 23:18 ` [16/70] ASoC: ak4642: fixup snd_soc_update_bits mask for PW_MGMT2 Greg KH
2011-08-01 23:18 ` [17/70] ARM: 6989/1: perf: do not start the PMU when no events are present Greg KH
2011-08-01 23:18 ` [18/70] ARM: pxa168: correct nand pmu setting Greg KH
2011-08-01 23:18 ` [19/70] ARM: pxa910: " Greg KH
2011-08-01 23:18 ` [20/70] ARM: pxa: fix PGSR register address calculation Greg KH
2011-08-01 23:18 ` [21/70] firewire: ohci: do not bind to Pinnacle cards, avert panic Greg KH
2011-08-01 23:18 ` [22/70] Revert: "dell-laptop: Toggle the unsupported hardware killswitch" Greg KH
2011-08-01 23:18 ` [23/70] [media] v4l2-ioctl.c: prefill tuner type for g_frequency and g/s_tuner Greg KH
2011-08-01 23:18 ` [24/70] [media] tuner-core: fix s_std and s_tuner Greg KH
2011-08-01 23:18 ` [25/70] [media] tuner-core: fix tuner_resume: use t->mode instead of t->type Greg KH
2011-08-01 23:18 ` [26/70] hwmon: (pmbus) Improve auto-detection of temperature status register Greg KH
2011-08-01 23:18 ` [27/70] [media] pvrusb2: fix g/s_tuner support Greg KH
2011-08-01 23:18 ` [28/70] [media] bttv: fix s_tuner for radio Greg KH
2011-08-01 23:18 ` [29/70] fs/partitions/efi.c: corrupted GUID partition tables can cause kernel oops Greg KH
2011-08-01 23:18 ` [30/70] drm/radeon/kms: fix backend map typo on juniper Greg KH
2011-08-01 23:18 ` [31/70] NFSv4.1: update nfs4_fattr_bitmap_maxsz Greg KH
2011-08-01 23:18 ` [32/70] mac80211: fix TKIP replay vulnerability Greg KH
2011-08-01 23:18 ` [33/70] carl9170: add NEC WL300NU-AG usbid Greg KH
2011-08-01 23:18 ` [34/70] rtlwifi: rtl8192cu: Add new USB ID for Netgear WNA1000M Greg KH
2011-08-01 23:18 ` [35/70] SUNRPC: Fix a race between work-queue and rpc_killall_tasks Greg KH
2011-08-01 23:18 ` [36/70] SUNRPC: Fix use of static variable in rpcb_getport_async Greg KH
2011-08-01 23:18 ` [37/70] drm/radeon/kms: add new NI pci ids Greg KH
2011-08-01 23:18 ` [38/70] ath9k: Fix tx throughput drops for AR9003 chips with AES encryption Greg KH
2011-08-01 23:18 ` [39/70] ath5k: fix incorrect use of drvdata in sysfs code Greg KH
2011-08-01 23:18 ` [40/70] ath5k: fix incorrect use of drvdata in PCI suspend/resume code Greg KH
2011-08-01 23:18 ` [41/70] drm/radeon/kms: clean up multiple crtc handling for Greg KH
2011-08-01 23:18 ` [42/70] drm/radeon: fix oops in ttm reserve when pageflipping (v2) Greg KH
2011-08-01 23:18 ` [43/70] GFS2: make sure fallocate bytes is a multiple of blksize Greg KH
2011-08-01 23:18 ` [44/70] [media] Revert "V4L/DVB: cx23885: Enable Message Signaled Interrupts(MSI)" Greg KH
2011-08-01 23:19 ` [45/70] si4713-i2c: avoid potential buffer overflow on si4713 Greg KH
2011-08-01 23:19 ` [46/70] ASoC: Correct WM8994 MICBIAS supply widget hookup Greg KH
2011-08-01 23:19 ` [47/70] ASoC: Fix shift in WM8958 accessory detection default Greg KH
2011-08-01 23:19 ` [48/70] hwmon: (it87) Fix label group removal Greg KH
2011-08-01 23:19 ` [49/70] hwmon: (asus_atk0110) Fix memory leak Greg KH
2011-08-01 23:19 ` Greg KH [this message]
2011-08-01 23:19 ` [51/70] mmc: Added quirks for Ricoh 1180:e823 lower base clock Greg KH
2011-08-01 23:19 ` [52/70] mmc: sdhci-esdhc-imx: SDHCI_CARD_PRESENT does not get Greg KH
2011-08-01 23:19 ` [53/70] x86: Make Dell Latitude E5420 use reboot=pci Greg KH
2011-08-01 23:19 ` [54/70] davinci: DM365 EVM: fix video input mux bits Greg KH
2011-08-01 23:19 ` [55/70] vmscan: fix a livelock in kswapd Greg KH
2011-08-01 23:19 ` [56/70] libata: fix unexpectedly frozen port after ata_eh_reset() Greg KH
2011-08-01 23:19 ` [57/70] ext4: fix oops in ext4_quota_off() Greg KH
2011-08-01 23:19 ` [58/70] mm: compaction: ensure that the compaction free scanner does not move to the next zone Greg KH
2011-08-01 23:19 ` [59/70] mm: vmscan: do not use page_count without a page pin Greg KH
2011-08-01 23:19 ` [60/70] [stable] [PATCH 3/3] mm: compaction: abort compaction if too many pages are isolated and caller is asynchronous V2 Greg KH
2011-08-01 23:19 ` [61/70] xfs [stable only]: restart busy extent search after node removal Greg KH
2011-08-01 23:19 ` [62/70] cifs: clean up wsize negotiation and allow for larger wsize Greg KH
2011-08-01 23:19 ` [63/70] mm: vmscan: do not apply pressure to slab if we are not applying pressure to zone Greg KH
2011-08-01 23:19 ` [64/70] mm: vmscan: only read new_classzone_idx from pgdat when reclaiming successfully Greg KH
2011-08-01 23:19 ` [65/70] Revert "DiBxxxx: get rid of DMA buffer on stack" Greg KH
2011-08-01 23:19 ` [66/70] vfs: fix race in rcu lookup of pruned dentry Greg KH
2011-08-01 23:19 ` [67/70] cifs: fix wsize negotiation to respect max buffer size and Greg KH
2011-08-01 23:19 ` [68/70] cifs: lower default and max wsize to what 2.6.39 can handle Greg KH
2011-08-01 23:19 ` [69/70] bridge: send proper message_age in config BPDU Greg KH
2011-08-01 23:19 ` [70/70] gro: Only reset frag0 when skb can be pulled Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110801232055.630132100@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=khali@linux-fr.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marek.vasut@gmail.com \
    --cc=metan@ucw.cz \
    --cc=morpheus.ibis@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®