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,
	Joakim Tjernlund <Joakim.Tjernlund@transmode.se>,
	Michael Cashwell <mboards@prograde.net>,
	Stefan Bigler <stefan.bigler@keymile.com>,
	Artem Bityutskiy <Artem.Bityutskiy@nokia.com>,
	David Woodhouse <David.Woodhouse@intel.com>
Subject: [06/87] mtd: fix race in cfi_cmdset_0001 driver
Date: Mon, 21 Mar 2011 16:06:05 -0700	[thread overview]
Message-ID: <20110321230709.791490708@clark.kroah.org> (raw)
In-Reply-To: <20110321230732.GA26510@kroah.com>

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

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

From: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>

commit ecf3fde07c8dcb92a1bf3fbdfe70905d85cd00e1 upstream.

As inval_cache_and_wait_for_operation() drop and reclaim the lock
to invalidate the cache, some other thread may suspend the operation
before reaching the for(;;) loop. Therefore the loop must start with
checking the chip->state before reading status from the chip.

Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
Acked-by: Michael Cashwell <mboards@prograde.net>
Acked-by: Stefan Bigler <stefan.bigler@keymile.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/mtd/chips/cfi_cmdset_0001.c |   43 ++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -1229,10 +1229,32 @@ static int inval_cache_and_wait_for_oper
 	sleep_time = chip_op_time / 2;
 
 	for (;;) {
+		if (chip->state != chip_state) {
+			/* Someone's suspended the operation: sleep */
+			DECLARE_WAITQUEUE(wait, current);
+			set_current_state(TASK_UNINTERRUPTIBLE);
+			add_wait_queue(&chip->wq, &wait);
+			mutex_unlock(&chip->mutex);
+			schedule();
+			remove_wait_queue(&chip->wq, &wait);
+			mutex_lock(&chip->mutex);
+			continue;
+		}
+
 		status = map_read(map, cmd_adr);
 		if (map_word_andequal(map, status, status_OK, status_OK))
 			break;
 
+		if (chip->erase_suspended && chip_state == FL_ERASING)  {
+			/* Erase suspend occured while sleep: reset timeout */
+			timeo = reset_timeo;
+			chip->erase_suspended = 0;
+		}
+		if (chip->write_suspended && chip_state == FL_WRITING)  {
+			/* Write suspend occured while sleep: reset timeout */
+			timeo = reset_timeo;
+			chip->write_suspended = 0;
+		}
 		if (!timeo) {
 			map_write(map, CMD(0x70), cmd_adr);
 			chip->state = FL_STATUS;
@@ -1256,27 +1278,6 @@ static int inval_cache_and_wait_for_oper
 			timeo--;
 		}
 		mutex_lock(&chip->mutex);
-
-		while (chip->state != chip_state) {
-			/* Someone's suspended the operation: sleep */
-			DECLARE_WAITQUEUE(wait, current);
-			set_current_state(TASK_UNINTERRUPTIBLE);
-			add_wait_queue(&chip->wq, &wait);
-			mutex_unlock(&chip->mutex);
-			schedule();
-			remove_wait_queue(&chip->wq, &wait);
-			mutex_lock(&chip->mutex);
-		}
-		if (chip->erase_suspended && chip_state == FL_ERASING)  {
-			/* Erase suspend occured while sleep: reset timeout */
-			timeo = reset_timeo;
-			chip->erase_suspended = 0;
-		}
-		if (chip->write_suspended && chip_state == FL_WRITING)  {
-			/* Write suspend occured while sleep: reset timeout */
-			timeo = reset_timeo;
-			chip->write_suspended = 0;
-		}
 	}
 
 	/* Done and happy. */



  parent reply	other threads:[~2011-03-21 23:15 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-21 23:07 [00/87] 2.6.37.5-stable review Greg KH
2011-03-21 23:06 ` [01/87] hwmon/f71882fg: Set platform drvdata to NULL later Greg KH
2011-03-21 23:06 ` [02/87] mtd: jedec_probe: Change variable name from cfi_p to cfi Greg KH
2011-03-21 23:06 ` [03/87] mtd: jedec_probe: initialise make sector erase command variable Greg KH
2011-03-21 23:06 ` [04/87] mtd: add "platform:" prefix for platform modalias Greg KH
2011-03-21 23:06 ` [05/87] mtd: mtd_blkdevs: fix double free on error path Greg KH
2011-03-21 23:06 ` Greg KH [this message]
2011-03-21 23:06 ` [07/87] ASoC: Fix broken bitfield definitions in WM8978 Greg KH
2011-03-21 23:06 ` [08/87] sunrpc: Propagate errors from xs_bind() through xs_create_sock() Greg KH
2011-03-21 23:06 ` [09/87] NFS: NFSROOT should default to "proto=udp" Greg KH
2011-03-21 23:06 ` [10/87] Fix corrupted OSF partition table parsing Greg KH
2011-03-21 23:22   ` Linus Torvalds
2011-03-21 23:38     ` Greg KH
2011-03-21 23:06 ` [11/87] Btrfs: deal with short returns from copy_from_user Greg KH
2011-03-21 23:06 ` [12/87] netfilter: fix export secctx error handling Greg KH
2011-03-21 23:06 ` [13/87] rt2x00: Fix crash on USB unplug Greg KH
2011-03-21 23:06 ` [14/87] rt2x00: fix hang when unplugging USB device in use Greg KH
2011-03-21 23:06 ` [15/87] drm/i915: Fix calculation of backlight value in combined mode Greg KH
2011-03-21 23:06 ` [16/87] block: fix mis-synchronisation in blkdev_issue_zeroout() Greg KH
2011-03-21 23:06 ` [17/87] nfs: fix compilation warning Greg KH
2011-03-21 23:06 ` [18/87] MIPS: MTX-1: Make au1000_eth probe all PHY addresses Greg KH
2011-03-21 23:06 ` [19/87] x86/mm: Fix pgd_lock deadlock Greg KH
2011-03-21 23:06 ` [20/87] x86: Dont check for BIOS corruption in first 64K when theres no need to Greg KH
2011-03-21 23:06 ` [21/87] x86/mm: Handle mm_fault_error() in kernel space Greg KH
2011-03-21 23:06 ` [22/87] ftrace: Fix memory leak with function graph and cpu hotplug Greg KH
2011-03-21 23:06 ` [23/87] x86: Fix panic when handling "mem={invalid}" param Greg KH
2011-03-21 23:06 ` [24/87] x86: Emit "mem=nopentium ignored" warning when not supported Greg KH
2011-03-21 23:06 ` [25/87] ahci: recognize Marvell 88se9125 PCIe SATA 6.0 Gb/s controller Greg KH
2011-03-21 23:06 ` [26/87] ahci: AHCI mode SATA patch for Intel DH89xxCC DeviceIDs Greg KH
2011-03-21 23:06 ` [27/87] ahci: AHCI mode SATA patch for Intel Patsburg SATA RAID controller Greg KH
2011-03-21 23:06 ` [28/87] libata: fix hotplug for drivers which dont implement LPM Greg KH
2011-03-21 23:06 ` [29/87] RDMA/cma: Fix crash in request handlers Greg KH
2011-03-21 23:06 ` [30/87] Increase OSF partition limit from 8 to 18 Greg KH
2011-03-21 23:06 ` [31/87] IB/cm: Bump reference count on cm_id before invoking callback Greg KH
2011-03-21 23:06 ` [32/87] x86, quirk: Fix SB600 revision check Greg KH
2011-03-21 23:06 ` [33/87] microblaze: Fix /dev/zero corruption from __clear_user() Greg KH
2011-03-21 23:06 ` [34/87] x86: stop_machine_text_poke() should issue sync_core() Greg KH
2011-03-21 23:06 ` [35/87] TOMOYO: Fix memory leak upon file open Greg KH
2011-03-21 23:06 ` [36/87] drm: Hold the mode mutex whilst probing for sysfs status Greg KH
2011-03-21 23:06 ` [37/87] ath9k_hw: read and backup AR_WA register value even before chip reset on Greg KH
2011-03-21 23:06 ` [38/87] ath9k_hw: Fix incorrect macversion and macrev checks Greg KH
2011-03-21 23:06 ` [39/87] ath9k: remove support for the FIF_PROMISC_IN_BSS filter flag Greg KH
2011-03-21 23:06 ` [40/87] USB: serial drivers need to use larger bulk-in buffers Greg KH
2011-03-21 23:06 ` [41/87] USB: serial/kobil_sct, fix potential tty NULL dereference Greg KH
2011-03-21 23:06 ` [42/87] USB: serial: option: Apply OPTION_BLACKLIST_SENDSETUP also for ZTE MF626 Greg KH
2011-03-21 23:06 ` [43/87] USB: serial: ch341: add new id Greg KH
2011-03-21 23:06 ` [44/87] staging: winbond: needs <linux/delay.h> for msleep and friends Greg KH
2011-03-21 23:06 ` [45/87] staging: tidspbridge: protect dmm_map properly Greg KH
2011-03-21 23:06 ` [46/87] USB: isp1760: Implement solution for erratum 2 Greg KH
2011-03-21 23:06 ` [47/87] ehci: Check individual port status registers on resume Greg KH
2011-03-21 23:06 ` [48/87] USB: move usbcore away from hcd->state Greg KH
2011-03-21 23:06 ` [49/87] xhci: Update internal dequeue pointers after stalls Greg KH
2011-03-21 23:06 ` [50/87] xhci: Fix cycle bit calculation during stall handling Greg KH
2011-03-21 23:06 ` [51/87] USB: Add support for SuperSpeed isoc endpoints Greg KH
2011-03-21 23:06 ` [52/87] NFS: Fix a decoding problem in nfs3_decode_dirent Greg KH
2011-03-21 23:06 ` [53/87] ALSA: HDA: Realtek ALC88x: Do not over-initialize speakers and hp that are primary outputs Greg KH
2011-03-21 23:06 ` [54/87] ALSA: hda - fix digital mic selection in mixer on 92HD8X codecs Greg KH
2011-03-21 23:06 ` [55/87] ALSA: hda - Initialize special cases for input src in init phase Greg KH
2011-03-21 23:06 ` [56/87] HID: hid-magicmouse: Correct touch orientation direction Greg KH
2011-03-21 23:06 ` [57/87] HID: add support for Ortek PKB-1700 Greg KH
2011-03-21 23:06 ` [58/87] PCI: remove quirk for pre-production systems Greg KH
2011-03-21 23:06 ` [59/87] PCI: add more checking to ICH region quirks Greg KH
2011-03-21 23:06 ` [60/87] PCI: do not create quirk I/O regions below PCIBIOS_MIN_IO for ICH Greg KH
2011-03-21 23:07 ` [61/87] PCI: sysfs: Fix failure path for addition of "vpd" attribute Greg KH
2011-03-21 23:07 ` [62/87] ALSA: sound/pci/asihpi: check adapter index in hpi_ioctl Greg KH
2011-03-21 23:07 ` [63/87] ALSA: aloop - Fix possible IRQ lock inversion Greg KH
2011-03-21 23:07 ` [64/87] ALSA: ctxfi - Fix incorrect SPDIF status bit mask Greg KH
2011-03-21 23:07 ` [65/87] ALSA: ctxfi - Fix SPDIF status retrieval Greg KH
2011-03-21 23:07 ` [66/87] ALSA: ctxfi - Clear input settings before initialization Greg KH
2011-03-21 23:07 ` [67/87] [SCSI] scsi_dh_alua: fix deadlock in stpg_endio Greg KH
2011-03-21 23:07 ` [68/87] SUNRPC: Ensure we always run the tk_callback before tk_action Greg KH
2011-03-21 23:07 ` [69/87] RPC: killing RPC tasks races fixed Greg KH
2011-03-21 23:07 ` [70/87] perf: Fix the software events state check Greg KH
2011-03-21 23:07 ` [71/87] perf: Handle stopped state with tracepoints Greg KH
2011-03-21 23:07 ` [72/87] perf, powerpc: Handle events that raise an exception without overflowing Greg KH
2011-03-21 23:07 ` [73/87] perf tools: Version incorrect with some versions of grep Greg KH
2011-03-21 23:07 ` [74/87] ext3: Always set dx_nodes fake_dirent explicitly Greg KH
2011-03-21 23:07 ` [75/87] call_function_many: fix list delete vs add race Greg KH
2011-03-21 23:07 ` [76/87] call_function_many: add missing ordering Greg KH
2011-03-21 23:07 ` [77/87] smp_call_function_many: handle concurrent clearing of mask Greg KH
2011-03-21 23:07 ` [78/87] x86: Flush TLB if PGD entry is changed in i386 PAE mode Greg KH
2011-03-21 23:07 ` [79/87] ixgbe: limit VF access to network traffic Greg KH
2011-03-21 23:07 ` [80/87] ixgbe: work around for DDP last buffer size Greg KH
2011-03-21 23:07 ` [81/87] [PARISC] fix per-cpu flag problem in the cpu affinity checkers Greg KH
2011-03-21 23:07 ` [82/87] i2c: Fix typo in instantiating-devices document Greg KH
2011-03-21 23:07 ` [83/87] mmc: sdhci: Add Ricoh e823 PCI ID Greg KH
2011-03-21 23:07 ` [84/87] mmc: sdio: remember new card RCA when redetecting card Greg KH
2011-03-21 23:07 ` [85/87] x86, binutils, xen: Fix another wrong size directive Greg KH
2011-03-21 23:07 ` [86/87] davinci: DM644x EVM: register MUSB device earlier Greg KH
2011-03-21 23:07 ` [87/87] hwmon: (sht15) Fix integer overflow in humidity calculation 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=20110321230709.791490708@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=Artem.Bityutskiy@nokia.com \
    --cc=David.Woodhouse@intel.com \
    --cc=Joakim.Tjernlund@transmode.se \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mboards@prograde.net \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --cc=stefan.bigler@keymile.com \
    --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®