diff -druN linux-libre-3.0.39-gnu/arch/arm/mach-omap2/opp.c linux-libre-3.0.40-gnu/arch/arm/mach-omap2/opp.c
--- linux-libre-3.0.39-gnu/arch/arm/mach-omap2/opp.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/arch/arm/mach-omap2/opp.c	2012-08-09 11:28:18.000000000 -0400
@@ -53,7 +53,7 @@
 	omap_table_init = 1;
 
 	/* Lets now register with OPP library */
-	for (i = 0; i < opp_def_size; i++) {
+	for (i = 0; i < opp_def_size; i++, opp_def++) {
 		struct omap_hwmod *oh;
 		struct device *dev;
 
@@ -86,7 +86,6 @@
 					__func__, opp_def->freq,
 					opp_def->hwmod_name, i, r);
 		}
-		opp_def++;
 	}
 
 	return 0;
diff -druN linux-libre-3.0.39-gnu/arch/m68k/include/asm/entry_mm.h linux-libre-3.0.40-gnu/arch/m68k/include/asm/entry_mm.h
--- linux-libre-3.0.39-gnu/arch/m68k/include/asm/entry_mm.h	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/arch/m68k/include/asm/entry_mm.h	2012-08-09 11:28:18.000000000 -0400
@@ -35,8 +35,8 @@
 
 /* the following macro is used when enabling interrupts */
 #if defined(MACH_ATARI_ONLY)
-	/* block out HSYNC on the atari */
-#define ALLOWINT	(~0x400)
+	/* block out HSYNC = ipl 2 on the atari */
+#define ALLOWINT	(~0x500)
 #define	MAX_NOINT_IPL	3
 #else
 	/* portable version */
diff -druN linux-libre-3.0.39-gnu/arch/m68k/kernel/sys_m68k.c linux-libre-3.0.40-gnu/arch/m68k/kernel/sys_m68k.c
--- linux-libre-3.0.39-gnu/arch/m68k/kernel/sys_m68k.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/arch/m68k/kernel/sys_m68k.c	2012-08-09 11:28:18.000000000 -0400
@@ -479,9 +479,13 @@
 			goto bad_access;
 		}
 
-		mem_value = *mem;
+		/*
+		 * No need to check for EFAULT; we know that the page is
+		 * present and writable.
+		 */
+		__get_user(mem_value, mem);
 		if (mem_value == oldval)
-			*mem = newval;
+			__put_user(newval, mem);
 
 		pte_unmap_unlock(pte, ptl);
 		up_read(&mm->mmap_sem);
diff -druN linux-libre-3.0.39-gnu/arch/powerpc/include/asm/cputime.h linux-libre-3.0.40-gnu/arch/powerpc/include/asm/cputime.h
--- linux-libre-3.0.39-gnu/arch/powerpc/include/asm/cputime.h	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/arch/powerpc/include/asm/cputime.h	2012-08-09 11:28:18.000000000 -0400
@@ -126,11 +126,11 @@
 /*
  * Convert cputime <-> microseconds
  */
-extern u64 __cputime_msec_factor;
+extern u64 __cputime_usec_factor;
 
 static inline unsigned long cputime_to_usecs(const cputime_t ct)
 {
-	return mulhdu(ct, __cputime_msec_factor) * USEC_PER_MSEC;
+	return mulhdu(ct, __cputime_usec_factor);
 }
 
 static inline cputime_t usecs_to_cputime(const unsigned long us)
@@ -143,7 +143,7 @@
 	sec = us / 1000000;
 	if (ct) {
 		ct *= tb_ticks_per_sec;
-		do_div(ct, 1000);
+		do_div(ct, 1000000);
 	}
 	if (sec)
 		ct += (cputime_t) sec * tb_ticks_per_sec;
diff -druN linux-libre-3.0.39-gnu/arch/powerpc/include/asm/reg.h linux-libre-3.0.40-gnu/arch/powerpc/include/asm/reg.h
--- linux-libre-3.0.39-gnu/arch/powerpc/include/asm/reg.h	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/arch/powerpc/include/asm/reg.h	2012-08-09 11:28:18.000000000 -0400
@@ -1000,7 +1000,8 @@
 /* Macros for setting and retrieving special purpose registers */
 #ifndef __ASSEMBLY__
 #define mfmsr()		({unsigned long rval; \
-			asm volatile("mfmsr %0" : "=r" (rval)); rval;})
+			asm volatile("mfmsr %0" : "=r" (rval) : \
+						: "memory"); rval;})
 #ifdef CONFIG_PPC_BOOK3S_64
 #define __mtmsrd(v, l)	asm volatile("mtmsrd %0," __stringify(l) \
 				     : : "r" (v) : "memory")
diff -druN linux-libre-3.0.39-gnu/arch/powerpc/kernel/ftrace.c linux-libre-3.0.40-gnu/arch/powerpc/kernel/ftrace.c
--- linux-libre-3.0.39-gnu/arch/powerpc/kernel/ftrace.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/arch/powerpc/kernel/ftrace.c	2012-08-09 11:28:18.000000000 -0400
@@ -245,9 +245,9 @@
 
 	/*
 	 * On PPC32 the trampoline looks like:
-	 *  0x3d, 0x60, 0x00, 0x00  lis r11,sym@ha
-	 *  0x39, 0x6b, 0x00, 0x00  addi r11,r11,sym@l
-	 *  0x7d, 0x69, 0x03, 0xa6  mtctr r11
+	 *  0x3d, 0x80, 0x00, 0x00  lis r12,sym@ha
+	 *  0x39, 0x8c, 0x00, 0x00  addi r12,r12,sym@l
+	 *  0x7d, 0x89, 0x03, 0xa6  mtctr r12
 	 *  0x4e, 0x80, 0x04, 0x20  bctr
 	 */
 
@@ -262,9 +262,9 @@
 	pr_devel(" %08x %08x ", jmp[0], jmp[1]);
 
 	/* verify that this is what we expect it to be */
-	if (((jmp[0] & 0xffff0000) != 0x3d600000) ||
-	    ((jmp[1] & 0xffff0000) != 0x396b0000) ||
-	    (jmp[2] != 0x7d6903a6) ||
+	if (((jmp[0] & 0xffff0000) != 0x3d800000) ||
+	    ((jmp[1] & 0xffff0000) != 0x398c0000) ||
+	    (jmp[2] != 0x7d8903a6) ||
 	    (jmp[3] != 0x4e800420)) {
 		printk(KERN_ERR "Not a trampoline\n");
 		return -EINVAL;
diff -druN linux-libre-3.0.39-gnu/arch/powerpc/kernel/time.c linux-libre-3.0.40-gnu/arch/powerpc/kernel/time.c
--- linux-libre-3.0.39-gnu/arch/powerpc/kernel/time.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/arch/powerpc/kernel/time.c	2012-08-09 11:28:18.000000000 -0400
@@ -168,13 +168,13 @@
 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
 /*
  * Factors for converting from cputime_t (timebase ticks) to
- * jiffies, milliseconds, seconds, and clock_t (1/USER_HZ seconds).
+ * jiffies, microseconds, seconds, and clock_t (1/USER_HZ seconds).
  * These are all stored as 0.64 fixed-point binary fractions.
  */
 u64 __cputime_jiffies_factor;
 EXPORT_SYMBOL(__cputime_jiffies_factor);
-u64 __cputime_msec_factor;
-EXPORT_SYMBOL(__cputime_msec_factor);
+u64 __cputime_usec_factor;
+EXPORT_SYMBOL(__cputime_usec_factor);
 u64 __cputime_sec_factor;
 EXPORT_SYMBOL(__cputime_sec_factor);
 u64 __cputime_clockt_factor;
@@ -192,8 +192,8 @@
 
 	div128_by_32(HZ, 0, tb_ticks_per_sec, &res);
 	__cputime_jiffies_factor = res.result_low;
-	div128_by_32(1000, 0, tb_ticks_per_sec, &res);
-	__cputime_msec_factor = res.result_low;
+	div128_by_32(1000000, 0, tb_ticks_per_sec, &res);
+	__cputime_usec_factor = res.result_low;
 	div128_by_32(1, 0, tb_ticks_per_sec, &res);
 	__cputime_sec_factor = res.result_low;
 	div128_by_32(USER_HZ, 0, tb_ticks_per_sec, &res);
diff -druN linux-libre-3.0.39-gnu/Documentation/stable_kernel_rules.txt linux-libre-3.0.40-gnu/Documentation/stable_kernel_rules.txt
--- linux-libre-3.0.39-gnu/Documentation/stable_kernel_rules.txt	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/Documentation/stable_kernel_rules.txt	2012-08-09 11:28:18.000000000 -0400
@@ -1,4 +1,4 @@
-Everything you ever wanted to know about Linux 2.6 -stable releases.
+Everything you ever wanted to know about Linux -stable releases.
 
 Rules on what kind of patches are accepted, and which ones are not, into the
 "-stable" tree:
@@ -41,10 +41,10 @@
    cherry-picked than this can be specified in the following format in
    the sign-off area:
 
-     Cc: <stable@vger.kernel.org> # .32.x: a1f84a3: sched: Check for idle
-     Cc: <stable@vger.kernel.org> # .32.x: 1b9508f: sched: Rate-limit newidle
-     Cc: <stable@vger.kernel.org> # .32.x: fd21073: sched: Fix affinity logic
-     Cc: <stable@vger.kernel.org> # .32.x
+     Cc: <stable@vger.kernel.org> # 3.3.x: a1f84a3: sched: Check for idle
+     Cc: <stable@vger.kernel.org> # 3.3.x: 1b9508f: sched: Rate-limit newidle
+     Cc: <stable@vger.kernel.org> # 3.3.x: fd21073: sched: Fix affinity logic
+     Cc: <stable@vger.kernel.org> # 3.3.x
     Signed-off-by: Ingo Molnar <mingo@elte.hu>
 
    The tag sequence has the meaning of:
@@ -78,6 +78,15 @@
    security kernel team, and not go through the normal review cycle.
    Contact the kernel security team for more details on this procedure.
 
+Trees:
+
+ - The queues of patches, for both completed versions and in progress
+   versions can be found at:
+	http://git.kernel.org/?p=linux/kernel/git/stable/stable-queue.git
+ - The finalized and tagged releases of all stable kernels can be found
+   in separate branches per version at:
+	http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git
+
 
 Review committee:
 
diff -druN linux-libre-3.0.39-gnu/drivers/acpi/ac.c linux-libre-3.0.40-gnu/drivers/acpi/ac.c
--- linux-libre-3.0.39-gnu/drivers/acpi/ac.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/acpi/ac.c	2012-08-09 11:28:18.000000000 -0400
@@ -292,7 +292,9 @@
 	ac->charger.properties = ac_props;
 	ac->charger.num_properties = ARRAY_SIZE(ac_props);
 	ac->charger.get_property = get_ac_property;
-	power_supply_register(&ac->device->dev, &ac->charger);
+	result = power_supply_register(&ac->device->dev, &ac->charger);
+	if (result)
+		goto end;
 
 	printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
 	       acpi_device_name(device), acpi_device_bid(device),
diff -druN linux-libre-3.0.39-gnu/drivers/gpu/drm/radeon/atombios_dp.c linux-libre-3.0.40-gnu/drivers/gpu/drm/radeon/atombios_dp.c
--- linux-libre-3.0.39-gnu/drivers/gpu/drm/radeon/atombios_dp.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/gpu/drm/radeon/atombios_dp.c	2012-08-09 11:28:18.000000000 -0400
@@ -22,6 +22,7 @@
  *
  * Authors: Dave Airlie
  *          Alex Deucher
+ *          Jerome Glisse
  */
 #include "drmP.h"
 #include "radeon_drm.h"
@@ -624,7 +625,6 @@
 	ret = radeon_dp_aux_native_read(radeon_connector, DP_LANE0_1_STATUS,
 					link_status, DP_LINK_STATUS_SIZE, 100);
 	if (ret <= 0) {
-		DRM_ERROR("displayport link status failed\n");
 		return false;
 	}
 
@@ -797,8 +797,10 @@
 		else
 			mdelay(dp_info->rd_interval * 4);
 
-		if (!radeon_dp_get_link_status(dp_info->radeon_connector, dp_info->link_status))
+		if (!radeon_dp_get_link_status(dp_info->radeon_connector, dp_info->link_status)) {
+			DRM_ERROR("displayport link status failed\n");
 			break;
+		}
 
 		if (dp_clock_recovery_ok(dp_info->link_status, dp_info->dp_lane_count)) {
 			clock_recovery = true;
@@ -860,8 +862,10 @@
 		else
 			mdelay(dp_info->rd_interval * 4);
 
-		if (!radeon_dp_get_link_status(dp_info->radeon_connector, dp_info->link_status))
+		if (!radeon_dp_get_link_status(dp_info->radeon_connector, dp_info->link_status)) {
+			DRM_ERROR("displayport link status failed\n");
 			break;
+		}
 
 		if (dp_channel_eq_ok(dp_info->link_status, dp_info->dp_lane_count)) {
 			channel_eq = true;
diff -druN linux-libre-3.0.39-gnu/drivers/gpu/drm/radeon/radeon_connectors.c linux-libre-3.0.40-gnu/drivers/gpu/drm/radeon/radeon_connectors.c
--- linux-libre-3.0.39-gnu/drivers/gpu/drm/radeon/radeon_connectors.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/gpu/drm/radeon/radeon_connectors.c	2012-08-09 11:28:18.000000000 -0400
@@ -66,14 +66,33 @@
 
 	/* just deal with DP (not eDP) here. */
 	if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
-		int saved_dpms = connector->dpms;
+		struct radeon_connector_atom_dig *dig_connector =
+			radeon_connector->con_priv;
 
-		/* Only turn off the display it it's physically disconnected */
-		if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
-			drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
-		else if (radeon_dp_needs_link_train(radeon_connector))
-			drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
-		connector->dpms = saved_dpms;
+		/* if existing sink type was not DP no need to retrain */
+		if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
+			return;
+
+		/* first get sink type as it may be reset after (un)plug */
+		dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
+		/* don't do anything if sink is not display port, i.e.,
+		 * passive dp->(dvi|hdmi) adaptor
+		 */
+		if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
+			int saved_dpms = connector->dpms;
+			/* Only turn off the display if it's physically disconnected */
+			if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
+				drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
+			} else if (radeon_dp_needs_link_train(radeon_connector)) {
+				/* set it to OFF so that drm_helper_connector_dpms()
+				 * won't return immediately since the current state
+				 * is ON at this point.
+				 */
+				connector->dpms = DRM_MODE_DPMS_OFF;
+				drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
+			}
+			connector->dpms = saved_dpms;
+		}
 	}
 }
 
diff -druN linux-libre-3.0.39-gnu/drivers/gpu/drm/radeon/radeon_cursor.c linux-libre-3.0.40-gnu/drivers/gpu/drm/radeon/radeon_cursor.c
--- linux-libre-3.0.39-gnu/drivers/gpu/drm/radeon/radeon_cursor.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/gpu/drm/radeon/radeon_cursor.c	2012-08-09 11:28:18.000000000 -0400
@@ -257,8 +257,14 @@
 				if (!(cursor_end & 0x7f))
 					w--;
 			}
-			if (w <= 0)
+			if (w <= 0) {
 				w = 1;
+				cursor_end = x - xorigin + w;
+				if (!(cursor_end & 0x7f)) {
+					x--;
+					WARN_ON_ONCE(x < 0);
+				}
+			}
 		}
 	}
 
diff -druN linux-libre-3.0.39-gnu/drivers/mmc/host/sdhci-pci.c linux-libre-3.0.40-gnu/drivers/mmc/host/sdhci-pci.c
--- linux-libre-3.0.39-gnu/drivers/mmc/host/sdhci-pci.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/mmc/host/sdhci-pci.c	2012-08-09 11:28:18.000000000 -0400
@@ -140,6 +140,7 @@
 static const struct sdhci_pci_fixes sdhci_cafe = {
 	.quirks		= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
 			  SDHCI_QUIRK_NO_BUSY_IRQ |
+			  SDHCI_QUIRK_BROKEN_CARD_DETECTION |
 			  SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
 };
 
diff -druN linux-libre-3.0.39-gnu/drivers/net/bnx2.c linux-libre-3.0.40-gnu/drivers/net/bnx2.c
--- linux-libre-3.0.39-gnu/drivers/net/bnx2.c	2012-08-01 17:28:11.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/net/bnx2.c	2012-08-10 15:44:23.000000000 -0400
@@ -5306,7 +5306,7 @@
 			int k, last;
 
 			if (skb == NULL) {
-				j++;
+				j = NEXT_TX_BD(j);
 				continue;
 			}
 
@@ -5318,8 +5318,8 @@
 			tx_buf->skb = NULL;
 
 			last = tx_buf->nr_frags;
-			j++;
-			for (k = 0; k < last; k++, j++) {
+			j = NEXT_TX_BD(j);
+			for (k = 0; k < last; k++, j = NEXT_TX_BD(j)) {
 				tx_buf = &txr->tx_buf_ring[TX_RING_IDX(j)];
 				dma_unmap_page(&bp->pdev->dev,
 					dma_unmap_addr(tx_buf, mapping),
diff -druN linux-libre-3.0.39-gnu/drivers/net/caif/caif_serial.c linux-libre-3.0.40-gnu/drivers/net/caif/caif_serial.c
--- linux-libre-3.0.39-gnu/drivers/net/caif/caif_serial.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/net/caif/caif_serial.c	2012-08-09 11:28:18.000000000 -0400
@@ -325,6 +325,9 @@
 
 	sprintf(name, "cf%s", tty->name);
 	dev = alloc_netdev(sizeof(*ser), name, caifdev_setup);
+	if (!dev)
+		return -ENOMEM;
+
 	ser = netdev_priv(dev);
 	ser->tty = tty_kref_get(tty);
 	ser->dev = dev;
diff -druN linux-libre-3.0.39-gnu/drivers/net/tun.c linux-libre-3.0.40-gnu/drivers/net/tun.c
--- linux-libre-3.0.39-gnu/drivers/net/tun.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/net/tun.c	2012-08-09 11:28:18.000000000 -0400
@@ -1239,10 +1239,12 @@
 	int vnet_hdr_sz;
 	int ret;
 
-	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89)
+	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
 		if (copy_from_user(&ifr, argp, ifreq_len))
 			return -EFAULT;
-
+	} else {
+		memset(&ifr, 0, sizeof(ifr));
+	}
 	if (cmd == TUNGETFEATURES) {
 		/* Currently this just means: "what IFF flags are valid?".
 		 * This is needed because we never checked for invalid flags on
diff -druN linux-libre-3.0.39-gnu/drivers/net/usb/kaweth.c linux-libre-3.0.40-gnu/drivers/net/usb/kaweth.c
--- linux-libre-3.0.39-gnu/drivers/net/usb/kaweth.c	2012-08-01 17:30:26.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/net/usb/kaweth.c	2012-08-10 15:46:19.000000000 -0400
@@ -1305,7 +1305,7 @@
         int retv;
         int length = 0; /* shut up GCC */
 
-        urb = usb_alloc_urb(0, GFP_NOIO);
+	urb = usb_alloc_urb(0, GFP_ATOMIC);
         if (!urb)
                 return -ENOMEM;
 
diff -druN linux-libre-3.0.39-gnu/drivers/scsi/libsas/sas_expander.c linux-libre-3.0.40-gnu/drivers/scsi/libsas/sas_expander.c
--- linux-libre-3.0.39-gnu/drivers/scsi/libsas/sas_expander.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/scsi/libsas/sas_expander.c	2012-08-09 11:28:18.000000000 -0400
@@ -770,7 +770,7 @@
 }
 
 /* See if this phy is part of a wide port */
-static int sas_ex_join_wide_port(struct domain_device *parent, int phy_id)
+static bool sas_ex_join_wide_port(struct domain_device *parent, int phy_id)
 {
 	struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id];
 	int i;
@@ -786,11 +786,11 @@
 			sas_port_add_phy(ephy->port, phy->phy);
 			phy->port = ephy->port;
 			phy->phy_state = PHY_DEVICE_DISCOVERED;
-			return 0;
+			return true;
 		}
 	}
 
-	return -ENODEV;
+	return false;
 }
 
 static struct domain_device *sas_ex_discover_expander(
@@ -928,8 +928,7 @@
 		return res;
 	}
 
-	res = sas_ex_join_wide_port(dev, phy_id);
-	if (!res) {
+	if (sas_ex_join_wide_port(dev, phy_id)) {
 		SAS_DPRINTK("Attaching ex phy%d to wide port %016llx\n",
 			    phy_id, SAS_ADDR(ex_phy->attached_sas_addr));
 		return res;
@@ -974,8 +973,7 @@
 			if (SAS_ADDR(ex->ex_phy[i].attached_sas_addr) ==
 			    SAS_ADDR(child->sas_addr)) {
 				ex->ex_phy[i].phy_state= PHY_DEVICE_DISCOVERED;
-				res = sas_ex_join_wide_port(dev, i);
-				if (!res)
+				if (sas_ex_join_wide_port(dev, i))
 					SAS_DPRINTK("Attaching ex phy%d to wide port %016llx\n",
 						    i, SAS_ADDR(ex->ex_phy[i].attached_sas_addr));
 
@@ -1838,32 +1836,20 @@
 {
 	struct ex_phy *ex_phy = &dev->ex_dev.ex_phy[phy_id];
 	struct domain_device *child;
-	bool found = false;
-	int res, i;
+	int res;
 
 	SAS_DPRINTK("ex %016llx phy%d new device attached\n",
 		    SAS_ADDR(dev->sas_addr), phy_id);
 	res = sas_ex_phy_discover(dev, phy_id);
 	if (res)
-		goto out;
-	/* to support the wide port inserted */
-	for (i = 0; i < dev->ex_dev.num_phys; i++) {
-		struct ex_phy *ex_phy_temp = &dev->ex_dev.ex_phy[i];
-		if (i == phy_id)
-			continue;
-		if (SAS_ADDR(ex_phy_temp->attached_sas_addr) ==
-		    SAS_ADDR(ex_phy->attached_sas_addr)) {
-			found = true;
-			break;
-		}
-	}
-	if (found) {
-		sas_ex_join_wide_port(dev, phy_id);
+		return res;
+
+	if (sas_ex_join_wide_port(dev, phy_id))
 		return 0;
-	}
+
 	res = sas_ex_discover_devices(dev, phy_id);
-	if (!res)
-		goto out;
+	if (res)
+		return res;
 	list_for_each_entry(child, &dev->ex_dev.children, siblings) {
 		if (SAS_ADDR(child->sas_addr) ==
 		    SAS_ADDR(ex_phy->attached_sas_addr)) {
@@ -1873,7 +1859,6 @@
 			break;
 		}
 	}
-out:
 	return res;
 }
 
@@ -1972,9 +1957,7 @@
 	struct domain_device *dev = NULL;
 
 	res = sas_find_bcast_dev(port_dev, &dev);
-	if (res)
-		goto out;
-	if (dev) {
+	while (res == 0 && dev) {
 		struct expander_device *ex = &dev->ex_dev;
 		int i = 0, phy_id;
 
@@ -1986,8 +1969,10 @@
 			res = sas_rediscover(dev, phy_id);
 			i = phy_id + 1;
 		} while (i < ex->num_phys);
+
+		dev = NULL;
+		res = sas_find_bcast_dev(port_dev, &dev);
 	}
-out:
 	return res;
 }
 
diff -druN linux-libre-3.0.39-gnu/drivers/scsi/scsi_error.c linux-libre-3.0.40-gnu/drivers/scsi/scsi_error.c
--- linux-libre-3.0.39-gnu/drivers/scsi/scsi_error.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/scsi/scsi_error.c	2012-08-09 11:28:18.000000000 -0400
@@ -1665,6 +1665,20 @@
 	 * requests are started.
 	 */
 	scsi_run_host_queues(shost);
+
+	/*
+	 * if eh is active and host_eh_scheduled is pending we need to re-run
+	 * recovery.  we do this check after scsi_run_host_queues() to allow
+	 * everything pent up since the last eh run a chance to make forward
+	 * progress before we sync again.  Either we'll immediately re-run
+	 * recovery or scsi_device_unbusy() will wake us again when these
+	 * pending commands complete.
+	 */
+	spin_lock_irqsave(shost->host_lock, flags);
+	if (shost->host_eh_scheduled)
+		if (scsi_host_set_state(shost, SHOST_RECOVERY))
+			WARN_ON(scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY));
+	spin_unlock_irqrestore(shost->host_lock, flags);
 }
 
 /**
diff -druN linux-libre-3.0.39-gnu/drivers/scsi/scsi_lib.c linux-libre-3.0.40-gnu/drivers/scsi/scsi_lib.c
--- linux-libre-3.0.39-gnu/drivers/scsi/scsi_lib.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/scsi/scsi_lib.c	2012-08-09 11:28:18.000000000 -0400
@@ -481,15 +481,26 @@
  */
 static void scsi_requeue_command(struct request_queue *q, struct scsi_cmnd *cmd)
 {
+	struct scsi_device *sdev = cmd->device;
 	struct request *req = cmd->request;
 	unsigned long flags;
 
+	/*
+	 * We need to hold a reference on the device to avoid the queue being
+	 * killed after the unlock and before scsi_run_queue is invoked which
+	 * may happen because scsi_unprep_request() puts the command which
+	 * releases its reference on the device.
+	 */
+	get_device(&sdev->sdev_gendev);
+
 	spin_lock_irqsave(q->queue_lock, flags);
 	scsi_unprep_request(req);
 	blk_requeue_request(q, req);
 	spin_unlock_irqrestore(q->queue_lock, flags);
 
 	scsi_run_queue(q);
+
+	put_device(&sdev->sdev_gendev);
 }
 
 void scsi_next_command(struct scsi_cmnd *cmd)
diff -druN linux-libre-3.0.39-gnu/drivers/scsi/scsi_scan.c linux-libre-3.0.40-gnu/drivers/scsi/scsi_scan.c
--- linux-libre-3.0.39-gnu/drivers/scsi/scsi_scan.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/scsi/scsi_scan.c	2012-08-09 11:28:18.000000000 -0400
@@ -1710,6 +1710,9 @@
 {
 	struct scsi_device *sdev;
 	shost_for_each_device(sdev, shost) {
+		/* target removed before the device could be added */
+		if (sdev->sdev_state == SDEV_DEL)
+			continue;
 		if (!scsi_host_scan_allowed(shost) ||
 		    scsi_sysfs_add_sdev(sdev) != 0)
 			__scsi_remove_device(sdev);
diff -druN linux-libre-3.0.39-gnu/drivers/scsi/scsi_sysfs.c linux-libre-3.0.40-gnu/drivers/scsi/scsi_sysfs.c
--- linux-libre-3.0.39-gnu/drivers/scsi/scsi_sysfs.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/scsi/scsi_sysfs.c	2012-08-09 11:28:18.000000000 -0400
@@ -962,7 +962,6 @@
 	struct scsi_device *sdev;
 
 	spin_lock_irqsave(shost->host_lock, flags);
-	starget->reap_ref++;
  restart:
 	list_for_each_entry(sdev, &shost->__devices, siblings) {
 		if (sdev->channel != starget->channel ||
@@ -976,14 +975,6 @@
 		goto restart;
 	}
 	spin_unlock_irqrestore(shost->host_lock, flags);
-	scsi_target_reap(starget);
-}
-
-static int __remove_child (struct device * dev, void * data)
-{
-	if (scsi_is_target_device(dev))
-		__scsi_remove_target(to_scsi_target(dev));
-	return 0;
 }
 
 /**
@@ -996,14 +987,34 @@
  */
 void scsi_remove_target(struct device *dev)
 {
-	if (scsi_is_target_device(dev)) {
-		__scsi_remove_target(to_scsi_target(dev));
-		return;
+	struct Scsi_Host *shost = dev_to_shost(dev->parent);
+	struct scsi_target *starget, *found;
+	unsigned long flags;
+
+ restart:
+	found = NULL;
+	spin_lock_irqsave(shost->host_lock, flags);
+	list_for_each_entry(starget, &shost->__targets, siblings) {
+		if (starget->state == STARGET_DEL)
+			continue;
+		if (starget->dev.parent == dev || &starget->dev == dev) {
+			found = starget;
+			found->reap_ref++;
+			break;
+		}
 	}
+	spin_unlock_irqrestore(shost->host_lock, flags);
 
-	get_device(dev);
-	device_for_each_child(dev, NULL, __remove_child);
-	put_device(dev);
+	if (found) {
+		__scsi_remove_target(found);
+		scsi_target_reap(found);
+		/* in the case where @dev has multiple starget children,
+		 * continue removing.
+		 *
+		 * FIXME: does such a case exist?
+		 */
+		goto restart;
+	}
 }
 EXPORT_SYMBOL(scsi_remove_target);
 
diff -druN linux-libre-3.0.39-gnu/drivers/usb/core/devio.c linux-libre-3.0.40-gnu/drivers/usb/core/devio.c
--- linux-libre-3.0.39-gnu/drivers/usb/core/devio.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/usb/core/devio.c	2012-08-09 11:28:18.000000000 -0400
@@ -1557,10 +1557,14 @@
 	void __user *addr = as->userurb;
 	unsigned int i;
 
-	if (as->userbuffer && urb->actual_length)
-		if (copy_to_user(as->userbuffer, urb->transfer_buffer,
-				 urb->actual_length))
+	if (as->userbuffer && urb->actual_length) {
+		if (urb->number_of_packets > 0)		/* Isochronous */
+			i = urb->transfer_buffer_length;
+		else					/* Non-Isoc */
+			i = urb->actual_length;
+		if (copy_to_user(as->userbuffer, urb->transfer_buffer, i))
 			return -EFAULT;
+	}
 	if (put_user(as->status, &userurb->status))
 		return -EFAULT;
 	if (put_user(urb->actual_length, &userurb->actual_length))
diff -druN linux-libre-3.0.39-gnu/drivers/usb/early/ehci-dbgp.c linux-libre-3.0.40-gnu/drivers/usb/early/ehci-dbgp.c
--- linux-libre-3.0.39-gnu/drivers/usb/early/ehci-dbgp.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/usb/early/ehci-dbgp.c	2012-08-09 11:28:18.000000000 -0400
@@ -450,7 +450,7 @@
 	writel(FLAG_CF, &ehci_regs->configured_flag);
 
 	/* Wait until the controller is no longer halted */
-	loop = 10;
+	loop = 1000;
 	do {
 		status = readl(&ehci_regs->status);
 		if (!(status & STS_HALT))
diff -druN linux-libre-3.0.39-gnu/drivers/usb/gadget/u_ether.c linux-libre-3.0.40-gnu/drivers/usb/gadget/u_ether.c
--- linux-libre-3.0.39-gnu/drivers/usb/gadget/u_ether.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/drivers/usb/gadget/u_ether.c	2012-08-09 11:28:18.000000000 -0400
@@ -803,12 +803,6 @@
 
 	SET_ETHTOOL_OPS(net, &ops);
 
-	/* two kinds of host-initiated state changes:
-	 *  - iff DATA transfer is active, carrier is "on"
-	 *  - tx queueing enabled if open *and* carrier is "on"
-	 */
-	netif_carrier_off(net);
-
 	dev->gadget = g;
 	SET_NETDEV_DEV(net, &g->dev);
 	SET_NETDEV_DEVTYPE(net, &gadget_type);
@@ -822,6 +816,12 @@
 		INFO(dev, "HOST MAC %pM\n", dev->host_mac);
 
 		the_dev = dev;
+
+		/* two kinds of host-initiated state changes:
+		 *  - iff DATA transfer is active, carrier is "on"
+		 *  - tx queueing enabled if open *and* carrier is "on"
+		 */
+		netif_carrier_off(net);
 	}
 
 	return status;
diff -druN linux-libre-3.0.39-gnu/fs/btrfs/async-thread.c linux-libre-3.0.40-gnu/fs/btrfs/async-thread.c
--- linux-libre-3.0.39-gnu/fs/btrfs/async-thread.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/fs/btrfs/async-thread.c	2012-08-09 11:28:18.000000000 -0400
@@ -212,10 +212,17 @@
 
 		work->ordered_func(work);
 
-		/* now take the lock again and call the freeing code */
+		/* now take the lock again and drop our item from the list */
 		spin_lock(&workers->order_lock);
 		list_del(&work->order_list);
+		spin_unlock(&workers->order_lock);
+
+		/*
+		 * we don't want to call the ordered free functions
+		 * with the lock held though
+		 */
 		work->ordered_free(work);
+		spin_lock(&workers->order_lock);
 	}
 
 	spin_unlock(&workers->order_lock);
diff -druN linux-libre-3.0.39-gnu/fs/ext4/balloc.c linux-libre-3.0.40-gnu/fs/ext4/balloc.c
--- linux-libre-3.0.39-gnu/fs/ext4/balloc.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/fs/ext4/balloc.c	2012-08-09 11:28:18.000000000 -0400
@@ -514,7 +514,8 @@
 		if (bitmap_bh == NULL)
 			continue;
 
-		x = ext4_count_free(bitmap_bh, sb->s_blocksize);
+		x = ext4_count_free(bitmap_bh->b_data,
+				    EXT4_BLOCKS_PER_GROUP(sb) / 8);
 		printk(KERN_DEBUG "group %u: stored = %d, counted = %u\n",
 			i, ext4_free_blks_count(sb, gdp), x);
 		bitmap_count += x;
diff -druN linux-libre-3.0.39-gnu/fs/ext4/bitmap.c linux-libre-3.0.40-gnu/fs/ext4/bitmap.c
--- linux-libre-3.0.39-gnu/fs/ext4/bitmap.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/fs/ext4/bitmap.c	2012-08-09 11:28:18.000000000 -0400
@@ -15,15 +15,13 @@
 
 static const int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
 
-unsigned int ext4_count_free(struct buffer_head *map, unsigned int numchars)
+unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
 {
 	unsigned int i, sum = 0;
 
-	if (!map)
-		return 0;
 	for (i = 0; i < numchars; i++)
-		sum += nibblemap[map->b_data[i] & 0xf] +
-			nibblemap[(map->b_data[i] >> 4) & 0xf];
+		sum += nibblemap[bitmap[i] & 0xf] +
+			nibblemap[(bitmap[i] >> 4) & 0xf];
 	return sum;
 }
 
diff -druN linux-libre-3.0.39-gnu/fs/ext4/ext4.h linux-libre-3.0.40-gnu/fs/ext4/ext4.h
--- linux-libre-3.0.39-gnu/fs/ext4/ext4.h	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/fs/ext4/ext4.h	2012-08-09 11:28:18.000000000 -0400
@@ -1713,7 +1713,7 @@
 # define NORET_AND	noreturn,
 
 /* bitmap.c */
-extern unsigned int ext4_count_free(struct buffer_head *, unsigned);
+extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
 
 /* balloc.c */
 extern unsigned int ext4_block_group(struct super_block *sb,
diff -druN linux-libre-3.0.39-gnu/fs/ext4/ialloc.c linux-libre-3.0.40-gnu/fs/ext4/ialloc.c
--- linux-libre-3.0.39-gnu/fs/ext4/ialloc.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/fs/ext4/ialloc.c	2012-08-09 11:28:18.000000000 -0400
@@ -1193,7 +1193,8 @@
 		if (!bitmap_bh)
 			continue;
 
-		x = ext4_count_free(bitmap_bh, EXT4_INODES_PER_GROUP(sb) / 8);
+		x = ext4_count_free(bitmap_bh->b_data,
+				    EXT4_INODES_PER_GROUP(sb) / 8);
 		printk(KERN_DEBUG "group %lu: stored = %d, counted = %lu\n",
 			(unsigned long) i, ext4_free_inodes_count(sb, gdp), x);
 		bitmap_count += x;
diff -druN linux-libre-3.0.39-gnu/fs/ext4/inode.c linux-libre-3.0.40-gnu/fs/ext4/inode.c
--- linux-libre-3.0.39-gnu/fs/ext4/inode.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/fs/ext4/inode.c	2012-08-09 11:28:18.000000000 -0400
@@ -1134,6 +1134,15 @@
 		used = ei->i_reserved_data_blocks;
 	}
 
+	if (unlikely(ei->i_allocated_meta_blocks > ei->i_reserved_meta_blocks)) {
+		ext4_msg(inode->i_sb, KERN_NOTICE, "%s: ino %lu, allocated %d "
+			 "with only %d reserved metadata blocks\n", __func__,
+			 inode->i_ino, ei->i_allocated_meta_blocks,
+			 ei->i_reserved_meta_blocks);
+		WARN_ON(1);
+		ei->i_allocated_meta_blocks = ei->i_reserved_meta_blocks;
+	}
+
 	/* Update per-inode reservations */
 	ei->i_reserved_data_blocks -= used;
 	ei->i_reserved_meta_blocks -= ei->i_allocated_meta_blocks;
diff -druN linux-libre-3.0.39-gnu/fs/locks.c linux-libre-3.0.40-gnu/fs/locks.c
--- linux-libre-3.0.39-gnu/fs/locks.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/fs/locks.c	2012-08-09 11:28:18.000000000 -0400
@@ -315,7 +315,7 @@
 	return 0;
 }
 
-static int assign_type(struct file_lock *fl, int type)
+static int assign_type(struct file_lock *fl, long type)
 {
 	switch (type) {
 	case F_RDLCK:
@@ -452,7 +452,7 @@
 /*
  * Initialize a lease, use the default lock manager operations
  */
-static int lease_init(struct file *filp, int type, struct file_lock *fl)
+static int lease_init(struct file *filp, long type, struct file_lock *fl)
  {
 	if (assign_type(fl, type) != 0)
 		return -EINVAL;
@@ -470,7 +470,7 @@
 }
 
 /* Allocate a file_lock initialised to this type of lease */
-static struct file_lock *lease_alloc(struct file *filp, int type)
+static struct file_lock *lease_alloc(struct file *filp, long type)
 {
 	struct file_lock *fl = locks_alloc_lock();
 	int error = -ENOMEM;
diff -druN linux-libre-3.0.39-gnu/fs/nfs/file.c linux-libre-3.0.40-gnu/fs/nfs/file.c
--- linux-libre-3.0.39-gnu/fs/nfs/file.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/fs/nfs/file.c	2012-08-09 11:28:18.000000000 -0400
@@ -493,8 +493,11 @@
 
 	dfprintk(PAGECACHE, "NFS: release_page(%p)\n", page);
 
-	/* Only do I/O if gfp is a superset of GFP_KERNEL */
-	if (mapping && (gfp & GFP_KERNEL) == GFP_KERNEL) {
+	/* Only do I/O if gfp is a superset of GFP_KERNEL, and we're not
+	 * doing this memory reclaim for a fs-related allocation.
+	 */
+	if (mapping && (gfp & GFP_KERNEL) == GFP_KERNEL &&
+	    !(current->flags & PF_FSTRANS)) {
 		int how = FLUSH_SYNC;
 
 		/* Don't let kswapd deadlock waiting for OOM RPC calls */
diff -druN linux-libre-3.0.39-gnu/fs/nfsd/nfs4xdr.c linux-libre-3.0.40-gnu/fs/nfsd/nfs4xdr.c
--- linux-libre-3.0.39-gnu/fs/nfsd/nfs4xdr.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/fs/nfsd/nfs4xdr.c	2012-08-09 11:28:18.000000000 -0400
@@ -2010,7 +2010,7 @@
 	if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
 		if ((buflen -= 4) < 0)
 			goto out_resource;
-		WRITE32(1);
+		WRITE32(0);
 	}
 	if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
 		if ((buflen -= 4) < 0)
diff -druN linux-libre-3.0.39-gnu/include/linux/cpu.h linux-libre-3.0.40-gnu/include/linux/cpu.h
--- linux-libre-3.0.39-gnu/include/linux/cpu.h	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/include/linux/cpu.h	2012-08-09 11:28:18.000000000 -0400
@@ -66,8 +66,9 @@
 	/* migration should happen before other stuff but after perf */
 	CPU_PRI_PERF		= 20,
 	CPU_PRI_MIGRATION	= 10,
-	/* prepare workqueues for other notifiers */
-	CPU_PRI_WORKQUEUE	= 5,
+	/* bring up workqueues before normal notifiers and down after */
+	CPU_PRI_WORKQUEUE_UP	= 5,
+	CPU_PRI_WORKQUEUE_DOWN	= -5,
 };
 
 #ifdef CONFIG_SMP
diff -druN linux-libre-3.0.39-gnu/kernel/futex.c linux-libre-3.0.40-gnu/kernel/futex.c
--- linux-libre-3.0.39-gnu/kernel/futex.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/kernel/futex.c	2012-08-09 11:28:18.000000000 -0400
@@ -2231,11 +2231,11 @@
  * @uaddr2:	the pi futex we will take prior to returning to user-space
  *
  * The caller will wait on uaddr and will be requeued by futex_requeue() to
- * uaddr2 which must be PI aware.  Normal wakeup will wake on uaddr2 and
- * complete the acquisition of the rt_mutex prior to returning to userspace.
- * This ensures the rt_mutex maintains an owner when it has waiters; without
- * one, the pi logic wouldn't know which task to boost/deboost, if there was a
- * need to.
+ * uaddr2 which must be PI aware and unique from uaddr.  Normal wakeup will wake
+ * on uaddr2 and complete the acquisition of the rt_mutex prior to returning to
+ * userspace.  This ensures the rt_mutex maintains an owner when it has waiters;
+ * without one, the pi logic would not know which task to boost/deboost, if
+ * there was a need to.
  *
  * We call schedule in futex_wait_queue_me() when we enqueue and return there
  * via the following:
@@ -2272,6 +2272,9 @@
 	struct futex_q q = futex_q_init;
 	int res, ret;
 
+	if (uaddr == uaddr2)
+		return -EINVAL;
+
 	if (!bitset)
 		return -EINVAL;
 
@@ -2343,7 +2346,7 @@
 		 * signal.  futex_unlock_pi() will not destroy the lock_ptr nor
 		 * the pi_state.
 		 */
-		WARN_ON(!&q.pi_state);
+		WARN_ON(!q.pi_state);
 		pi_mutex = &q.pi_state->pi_mutex;
 		ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter, 1);
 		debug_rt_mutex_free_waiter(&rt_waiter);
@@ -2370,7 +2373,7 @@
 	 * fault, unlock the rt_mutex and return the fault to userspace.
 	 */
 	if (ret == -EFAULT) {
-		if (rt_mutex_owner(pi_mutex) == current)
+		if (pi_mutex && rt_mutex_owner(pi_mutex) == current)
 			rt_mutex_unlock(pi_mutex);
 	} else if (ret == -EINTR) {
 		/*
diff -druN linux-libre-3.0.39-gnu/kernel/power/hibernate.c linux-libre-3.0.40-gnu/kernel/power/hibernate.c
--- linux-libre-3.0.39-gnu/kernel/power/hibernate.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/kernel/power/hibernate.c	2012-08-09 11:28:18.000000000 -0400
@@ -344,6 +344,7 @@
 		goto Complete_devices;
 
 	suspend_console();
+	ftrace_stop();
 	pm_restrict_gfp_mask();
 	error = dpm_suspend(PMSG_FREEZE);
 	if (error)
@@ -369,6 +370,7 @@
 	if (error || !in_suspend)
 		pm_restore_gfp_mask();
 
+	ftrace_start();
 	resume_console();
 
  Complete_devices:
@@ -471,6 +473,7 @@
 
 	pm_prepare_console();
 	suspend_console();
+	ftrace_stop();
 	pm_restrict_gfp_mask();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
@@ -478,6 +481,7 @@
 		dpm_resume_end(PMSG_RECOVER);
 	}
 	pm_restore_gfp_mask();
+	ftrace_start();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -504,6 +508,7 @@
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	ftrace_stop();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -547,6 +552,7 @@
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	ftrace_start();
 	resume_console();
 
  Close:
diff -druN linux-libre-3.0.39-gnu/kernel/power/suspend.c linux-libre-3.0.40-gnu/kernel/power/suspend.c
--- linux-libre-3.0.39-gnu/kernel/power/suspend.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/kernel/power/suspend.c	2012-08-09 11:28:18.000000000 -0400
@@ -23,6 +23,7 @@
 #include <linux/slab.h>
 #include <linux/suspend.h>
 #include <linux/syscore_ops.h>
+#include <linux/ftrace.h>
 #include <trace/events/power.h>
 
 #include "power.h"
@@ -210,6 +211,7 @@
 			goto Close;
 	}
 	suspend_console();
+	ftrace_stop();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -226,6 +228,7 @@
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	ftrace_start();
 	resume_console();
  Close:
 	if (suspend_ops->end)
diff -druN linux-libre-3.0.39-gnu/kernel/workqueue.c linux-libre-3.0.40-gnu/kernel/workqueue.c
--- linux-libre-3.0.39-gnu/kernel/workqueue.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/kernel/workqueue.c	2012-08-09 11:28:18.000000000 -0400
@@ -3561,6 +3561,41 @@
 	return notifier_from_errno(0);
 }
 
+/*
+ * Workqueues should be brought up before normal priority CPU notifiers.
+ * This will be registered high priority CPU notifier.
+ */
+static int __devinit workqueue_cpu_up_callback(struct notifier_block *nfb,
+					       unsigned long action,
+					       void *hcpu)
+{
+	switch (action & ~CPU_TASKS_FROZEN) {
+	case CPU_UP_PREPARE:
+	case CPU_UP_CANCELED:
+	case CPU_DOWN_FAILED:
+	case CPU_ONLINE:
+		return workqueue_cpu_callback(nfb, action, hcpu);
+	}
+	return NOTIFY_OK;
+}
+
+/*
+ * Workqueues should be brought down after normal priority CPU notifiers.
+ * This will be registered as low priority CPU notifier.
+ */
+static int __devinit workqueue_cpu_down_callback(struct notifier_block *nfb,
+						 unsigned long action,
+						 void *hcpu)
+{
+	switch (action & ~CPU_TASKS_FROZEN) {
+	case CPU_DOWN_PREPARE:
+	case CPU_DYING:
+	case CPU_POST_DEAD:
+		return workqueue_cpu_callback(nfb, action, hcpu);
+	}
+	return NOTIFY_OK;
+}
+
 #ifdef CONFIG_SMP
 
 struct work_for_cpu {
@@ -3754,7 +3789,8 @@
 	unsigned int cpu;
 	int i;
 
-	cpu_notifier(workqueue_cpu_callback, CPU_PRI_WORKQUEUE);
+	cpu_notifier(workqueue_cpu_up_callback, CPU_PRI_WORKQUEUE_UP);
+	cpu_notifier(workqueue_cpu_down_callback, CPU_PRI_WORKQUEUE_DOWN);
 
 	/* initialize gcwqs */
 	for_each_gcwq_cpu(cpu) {
diff -druN linux-libre-3.0.39-gnu/Makefile linux-libre-3.0.40-gnu/Makefile
--- linux-libre-3.0.39-gnu/Makefile	2012-08-01 17:22:48.000000000 -0400
+++ linux-libre-3.0.40-gnu/Makefile	2012-08-10 15:39:54.000000000 -0400
@@ -1,6 +1,6 @@
 VERSION = 3
 PATCHLEVEL = 0
-SUBLEVEL = 39
+SUBLEVEL = 40
 EXTRAVERSION =-gnu
 NAME = Sneaky Weasel
 
diff -druN linux-libre-3.0.39-gnu/net/caif/caif_dev.c linux-libre-3.0.40-gnu/net/caif/caif_dev.c
--- linux-libre-3.0.39-gnu/net/caif/caif_dev.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/caif/caif_dev.c	2012-08-09 11:28:18.000000000 -0400
@@ -424,9 +424,9 @@
 
 static void __exit caif_device_exit(void)
 {
-	unregister_pernet_subsys(&caif_net_ops);
 	unregister_netdevice_notifier(&caif_device_notifier);
 	dev_remove_pack(&caif_packet_type);
+	unregister_pernet_subsys(&caif_net_ops);
 }
 
 module_init(caif_device_init);
diff -druN linux-libre-3.0.39-gnu/net/core/rtnetlink.c linux-libre-3.0.40-gnu/net/core/rtnetlink.c
--- linux-libre-3.0.39-gnu/net/core/rtnetlink.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/core/rtnetlink.c	2012-08-09 11:28:18.000000000 -0400
@@ -647,6 +647,12 @@
 	}
 }
 
+static unsigned int rtnl_dev_get_flags(const struct net_device *dev)
+{
+	return (dev->flags & ~(IFF_PROMISC | IFF_ALLMULTI)) |
+	       (dev->gflags & (IFF_PROMISC | IFF_ALLMULTI));
+}
+
 static unsigned int rtnl_dev_combine_flags(const struct net_device *dev,
 					   const struct ifinfomsg *ifm)
 {
@@ -655,7 +661,7 @@
 	/* bugwards compatibility: ifi_change == 0 is treated as ~0 */
 	if (ifm->ifi_change)
 		flags = (flags & ifm->ifi_change) |
-			(dev->flags & ~ifm->ifi_change);
+			(rtnl_dev_get_flags(dev) & ~ifm->ifi_change);
 
 	return flags;
 }
diff -druN linux-libre-3.0.39-gnu/net/ipv4/cipso_ipv4.c linux-libre-3.0.40-gnu/net/ipv4/cipso_ipv4.c
--- linux-libre-3.0.39-gnu/net/ipv4/cipso_ipv4.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/ipv4/cipso_ipv4.c	2012-08-09 11:28:18.000000000 -0400
@@ -1725,8 +1725,10 @@
 		case CIPSO_V4_TAG_LOCAL:
 			/* This is a non-standard tag that we only allow for
 			 * local connections, so if the incoming interface is
-			 * not the loopback device drop the packet. */
-			if (!(skb->dev->flags & IFF_LOOPBACK)) {
+			 * not the loopback device drop the packet. Further,
+			 * there is no legitimate reason for setting this from
+			 * userspace so reject it if skb is NULL. */
+			if (skb == NULL || !(skb->dev->flags & IFF_LOOPBACK)) {
 				err_offset = opt_iter;
 				goto validate_return_locked;
 			}
diff -druN linux-libre-3.0.39-gnu/net/ipv4/tcp.c linux-libre-3.0.40-gnu/net/ipv4/tcp.c
--- linux-libre-3.0.39-gnu/net/ipv4/tcp.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/ipv4/tcp.c	2012-08-09 11:28:18.000000000 -0400
@@ -2394,7 +2394,10 @@
 		/* Cap the max timeout in ms TCP will retry/retrans
 		 * before giving up and aborting (ETIMEDOUT) a connection.
 		 */
-		icsk->icsk_user_timeout = msecs_to_jiffies(val);
+		if (val < 0)
+			err = -EINVAL;
+		else
+			icsk->icsk_user_timeout = msecs_to_jiffies(val);
 		break;
 	default:
 		err = -ENOPROTOOPT;
diff -druN linux-libre-3.0.39-gnu/net/ipv4/tcp_input.c linux-libre-3.0.40-gnu/net/ipv4/tcp_input.c
--- linux-libre-3.0.39-gnu/net/ipv4/tcp_input.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/ipv4/tcp_input.c	2012-08-09 11:28:18.000000000 -0400
@@ -5340,7 +5340,9 @@
 			if (tp->copied_seq == tp->rcv_nxt &&
 			    len - tcp_header_len <= tp->ucopy.len) {
 #ifdef CONFIG_NET_DMA
-				if (tcp_dma_try_early_copy(sk, skb, tcp_header_len)) {
+				if (tp->ucopy.task == current &&
+				    sock_owned_by_user(sk) &&
+				    tcp_dma_try_early_copy(sk, skb, tcp_header_len)) {
 					copied_early = 1;
 					eaten = 1;
 				}
diff -druN linux-libre-3.0.39-gnu/net/sched/sch_sfb.c linux-libre-3.0.40-gnu/net/sched/sch_sfb.c
--- linux-libre-3.0.39-gnu/net/sched/sch_sfb.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/sched/sch_sfb.c	2012-08-09 11:28:18.000000000 -0400
@@ -556,6 +556,8 @@
 
 	sch->qstats.backlog = q->qdisc->qstats.backlog;
 	opts = nla_nest_start(skb, TCA_OPTIONS);
+	if (opts == NULL)
+		goto nla_put_failure;
 	NLA_PUT(skb, TCA_SFB_PARMS, sizeof(opt), &opt);
 	return nla_nest_end(skb, opts);
 
diff -druN linux-libre-3.0.39-gnu/net/sctp/input.c linux-libre-3.0.40-gnu/net/sctp/input.c
--- linux-libre-3.0.39-gnu/net/sctp/input.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/sctp/input.c	2012-08-09 11:28:18.000000000 -0400
@@ -737,15 +737,12 @@
 
 	epb = &ep->base;
 
-	if (hlist_unhashed(&epb->node))
-		return;
-
 	epb->hashent = sctp_ep_hashfn(epb->bind_addr.port);
 
 	head = &sctp_ep_hashtable[epb->hashent];
 
 	sctp_write_lock(&head->lock);
-	__hlist_del(&epb->node);
+	hlist_del_init(&epb->node);
 	sctp_write_unlock(&head->lock);
 }
 
@@ -826,7 +823,7 @@
 	head = &sctp_assoc_hashtable[epb->hashent];
 
 	sctp_write_lock(&head->lock);
-	__hlist_del(&epb->node);
+	hlist_del_init(&epb->node);
 	sctp_write_unlock(&head->lock);
 }
 
diff -druN linux-libre-3.0.39-gnu/net/sctp/socket.c linux-libre-3.0.40-gnu/net/sctp/socket.c
--- linux-libre-3.0.39-gnu/net/sctp/socket.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/sctp/socket.c	2012-08-09 11:28:18.000000000 -0400
@@ -1160,8 +1160,14 @@
 	SCTP_DEBUG_PRINTK("About to exit __sctp_connect() free asoc: %p"
 			  " kaddrs: %p err: %d\n",
 			  asoc, kaddrs, err);
-	if (asoc)
+	if (asoc) {
+		/* sctp_primitive_ASSOCIATE may have added this association
+		 * To the hash table, try to unhash it, just in case, its a noop
+		 * if it wasn't hashed so we're safe
+		 */
+		sctp_unhash_established(asoc);
 		sctp_association_free(asoc);
+	}
 	return err;
 }
 
@@ -1871,8 +1877,10 @@
 	goto out_unlock;
 
 out_free:
-	if (new_asoc)
+	if (new_asoc) {
+		sctp_unhash_established(asoc);
 		sctp_association_free(asoc);
+	}
 out_unlock:
 	sctp_release_sock(sk);
 
diff -druN linux-libre-3.0.39-gnu/net/sunrpc/sched.c linux-libre-3.0.40-gnu/net/sunrpc/sched.c
--- linux-libre-3.0.39-gnu/net/sunrpc/sched.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/sunrpc/sched.c	2012-08-09 11:28:18.000000000 -0400
@@ -713,7 +713,9 @@
 
 static void rpc_async_schedule(struct work_struct *work)
 {
+	current->flags |= PF_FSTRANS;
 	__rpc_execute(container_of(work, struct rpc_task, u.tk_work));
+	current->flags &= ~PF_FSTRANS;
 }
 
 /**
diff -druN linux-libre-3.0.39-gnu/net/sunrpc/xprtrdma/transport.c linux-libre-3.0.40-gnu/net/sunrpc/xprtrdma/transport.c
--- linux-libre-3.0.39-gnu/net/sunrpc/xprtrdma/transport.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/sunrpc/xprtrdma/transport.c	2012-08-09 11:28:18.000000000 -0400
@@ -200,6 +200,7 @@
 	int rc = 0;
 
 	if (!xprt->shutdown) {
+		current->flags |= PF_FSTRANS;
 		xprt_clear_connected(xprt);
 
 		dprintk("RPC:       %s: %sconnect\n", __func__,
@@ -212,10 +213,10 @@
 
 out:
 	xprt_wake_pending_tasks(xprt, rc);
-
 out_clear:
 	dprintk("RPC:       %s: exit\n", __func__);
 	xprt_clear_connecting(xprt);
+	current->flags &= ~PF_FSTRANS;
 }
 
 /*
diff -druN linux-libre-3.0.39-gnu/net/sunrpc/xprtsock.c linux-libre-3.0.40-gnu/net/sunrpc/xprtsock.c
--- linux-libre-3.0.39-gnu/net/sunrpc/xprtsock.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/sunrpc/xprtsock.c	2012-08-09 11:28:18.000000000 -0400
@@ -1882,6 +1882,8 @@
 	if (xprt->shutdown)
 		goto out;
 
+	current->flags |= PF_FSTRANS;
+
 	clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
 	status = __sock_create(xprt->xprt_net, AF_LOCAL,
 					SOCK_STREAM, 0, &sock, 1);
@@ -1915,6 +1917,7 @@
 out:
 	xprt_clear_connecting(xprt);
 	xprt_wake_pending_tasks(xprt, status);
+	current->flags &= ~PF_FSTRANS;
 }
 
 static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
@@ -1957,6 +1960,8 @@
 	if (xprt->shutdown)
 		goto out;
 
+	current->flags |= PF_FSTRANS;
+
 	/* Start by resetting any existing state */
 	xs_reset_transport(transport);
 	sock = xs_create_sock(xprt, transport,
@@ -1975,6 +1980,7 @@
 out:
 	xprt_clear_connecting(xprt);
 	xprt_wake_pending_tasks(xprt, status);
+	current->flags &= ~PF_FSTRANS;
 }
 
 /*
@@ -2100,6 +2106,8 @@
 	if (xprt->shutdown)
 		goto out;
 
+	current->flags |= PF_FSTRANS;
+
 	if (!sock) {
 		clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
 		sock = xs_create_sock(xprt, transport,
@@ -2149,6 +2157,7 @@
 	case -EINPROGRESS:
 	case -EALREADY:
 		xprt_clear_connecting(xprt);
+		current->flags &= ~PF_FSTRANS;
 		return;
 	case -EINVAL:
 		/* Happens, for instance, if the user specified a link
@@ -2161,6 +2170,7 @@
 out:
 	xprt_clear_connecting(xprt);
 	xprt_wake_pending_tasks(xprt, status);
+	current->flags &= ~PF_FSTRANS;
 }
 
 /**
diff -druN linux-libre-3.0.39-gnu/net/wanrouter/wanmain.c linux-libre-3.0.40-gnu/net/wanrouter/wanmain.c
--- linux-libre-3.0.39-gnu/net/wanrouter/wanmain.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/net/wanrouter/wanmain.c	2012-08-09 11:28:18.000000000 -0400
@@ -602,36 +602,31 @@
 		 * successfully, add it to the interface list.
 		 */
 
-		if (dev->name == NULL) {
-			err = -EINVAL;
-		} else {
-
-			#ifdef WANDEBUG
-			printk(KERN_INFO "%s: registering interface %s...\n",
-				wanrouter_modname, dev->name);
-			#endif
-
-			err = register_netdev(dev);
-			if (!err) {
-				struct net_device *slave = NULL;
-				unsigned long smp_flags=0;
+#ifdef WANDEBUG
+		printk(KERN_INFO "%s: registering interface %s...\n",
+		       wanrouter_modname, dev->name);
+#endif
 
-				lock_adapter_irq(&wandev->lock, &smp_flags);
+		err = register_netdev(dev);
+		if (!err) {
+			struct net_device *slave = NULL;
+			unsigned long smp_flags=0;
 
-				if (wandev->dev == NULL) {
-					wandev->dev = dev;
-				} else {
-					for (slave=wandev->dev;
-					     DEV_TO_SLAVE(slave);
-					     slave = DEV_TO_SLAVE(slave))
-						DEV_TO_SLAVE(slave) = dev;
-				}
-				++wandev->ndev;
+			lock_adapter_irq(&wandev->lock, &smp_flags);
 
-				unlock_adapter_irq(&wandev->lock, &smp_flags);
-				err = 0;	/* done !!! */
-				goto out;
+			if (wandev->dev == NULL) {
+				wandev->dev = dev;
+			} else {
+				for (slave=wandev->dev;
+				     DEV_TO_SLAVE(slave);
+				     slave = DEV_TO_SLAVE(slave))
+					DEV_TO_SLAVE(slave) = dev;
 			}
+			++wandev->ndev;
+
+			unlock_adapter_irq(&wandev->lock, &smp_flags);
+			err = 0;	/* done !!! */
+			goto out;
 		}
 		if (wandev->del_if)
 			wandev->del_if(wandev, dev);
diff -druN linux-libre-3.0.39-gnu/sound/drivers/mpu401/mpu401_uart.c linux-libre-3.0.40-gnu/sound/drivers/mpu401/mpu401_uart.c
--- linux-libre-3.0.39-gnu/sound/drivers/mpu401/mpu401_uart.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/sound/drivers/mpu401/mpu401_uart.c	2012-08-09 11:28:18.000000000 -0400
@@ -554,6 +554,7 @@
 	spin_lock_init(&mpu->output_lock);
 	spin_lock_init(&mpu->timer_lock);
 	mpu->hardware = hardware;
+	mpu->irq = -1;
 	if (! (info_flags & MPU401_INFO_INTEGRATED)) {
 		int res_size = hardware == MPU401_HW_PC98II ? 4 : 2;
 		mpu->res = request_region(port, res_size, "MPU401 UART");
diff -druN linux-libre-3.0.39-gnu/sound/pci/hda/patch_realtek.c linux-libre-3.0.40-gnu/sound/pci/hda/patch_realtek.c
--- linux-libre-3.0.39-gnu/sound/pci/hda/patch_realtek.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/sound/pci/hda/patch_realtek.c	2012-08-09 11:28:18.000000000 -0400
@@ -20133,6 +20133,7 @@
 	{ .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
 	{ .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
 	{ .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
+	{ .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
 	{ .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
 	  .patch = patch_alc861 },
 	{ .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
diff -druN linux-libre-3.0.39-gnu/sound/soc/codecs/wm8962.c linux-libre-3.0.40-gnu/sound/soc/codecs/wm8962.c
--- linux-libre-3.0.39-gnu/sound/soc/codecs/wm8962.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/sound/soc/codecs/wm8962.c	2012-08-09 11:28:18.000000000 -0400
@@ -2890,6 +2890,9 @@
 		/* VMID 2*250k */
 		snd_soc_update_bits(codec, WM8962_PWR_MGMT_1,
 				    WM8962_VMID_SEL_MASK, 0x100);
+
+		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
+			msleep(100);
 		break;
 
 	case SND_SOC_BIAS_OFF:
diff -druN linux-libre-3.0.39-gnu/sound/soc/codecs/wm8994.c linux-libre-3.0.40-gnu/sound/soc/codecs/wm8994.c
--- linux-libre-3.0.39-gnu/sound/soc/codecs/wm8994.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/sound/soc/codecs/wm8994.c	2012-08-09 11:28:18.000000000 -0400
@@ -2127,7 +2127,7 @@
 		return -EINVAL;
 	}
 
-	bclk_rate = params_rate(params) * 2;
+	bclk_rate = params_rate(params) * 4;
 	switch (params_format(params)) {
 	case SNDRV_PCM_FORMAT_S16_LE:
 		bclk_rate *= 16;
diff -druN linux-libre-3.0.39-gnu/sound/usb/clock.c linux-libre-3.0.40-gnu/sound/usb/clock.c
--- linux-libre-3.0.39-gnu/sound/usb/clock.c	2012-08-01 15:28:17.000000000 -0400
+++ linux-libre-3.0.40-gnu/sound/usb/clock.c	2012-08-09 11:28:18.000000000 -0400
@@ -111,7 +111,8 @@
 		return 0;
 
 	/* If a clock source can't tell us whether it's valid, we assume it is */
-	if (!uac2_control_is_readable(cs_desc->bmControls, UAC2_CS_CONTROL_CLOCK_VALID))
+	if (!uac2_control_is_readable(cs_desc->bmControls,
+				      UAC2_CS_CONTROL_CLOCK_VALID - 1))
 		return 1;
 
 	err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
