From: Stefan Roese Date: Mon, 30 Dec 2013 16:15:30 +0100 Message-Id: <1388416530-5865-1-git-send-email-sr@denx.de> Subject: [Xenomai] [PATCH] hal/arm: Add Zynq v3.5.7 patches List-Id: Discussions about the Xenomai project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: xenomai@xenomai.org Xilinx Zynq is already supported in the mainline Xenomai git repository. This patch adds support for the v3.5.7 Linux Kernel with the latest arm-6 i-pipe patch additionally to the already present v3.8 support. Signed-off-by: Stefan Roese --- ksrc/arch/arm/patches/README | 14 +- .../patches/zynq/ipipe-core-3.5.7-zynq-post.patch | 941 + .../patches/zynq/ipipe-core-3.5.7-zynq-pre.patch | 30351 +++++++++++++++++++ 3 files changed, 31305 insertions(+), 1 deletion(-) create mode 100644 ksrc/arch/arm/patches/zynq/ipipe-core-3.5.7-zynq-post.patch create mode 100644 ksrc/arch/arm/patches/zynq/ipipe-core-3.5.7-zynq-pre.patch diff --git a/ksrc/arch/arm/patches/README b/ksrc/arch/arm/patches/README index de47f32..e3d792b 100644 --- a/ksrc/arch/arm/patches/README +++ b/ksrc/arch/arm/patches/README @@ -76,7 +76,7 @@ From [5]: 2- apply raspberry/ipipe-core-3.8.13-raspberry-post-2.patch 3- you can resume to generic installation instructions. ----- Zynq +---- Zynq (v3.8) 1- Checkout the xilinx-v14.5 tag (6a0bedad60e2bca8d9b50bf81b9895e29e31a6d7) from [6] @@ -85,6 +85,18 @@ From [5]: 4- apply ipipe-core-3.8-zynq-post.patch 5- you can resume to generic installation instructions. +---- Zynq (v3.5.7) + +1- Checkout the git commit ID abfadbffda8e44b4e4a3695b441d10bd82cc0520 + from [6]. + Note: This is intentionally not an official Xilinx tag but a + special commit ID since this is the latest update to the Xilinx + v3.5 kernel. +2- apply ipipe-core-3.5.7-zynq-pre.patch +3- apply ipipe-core-3.5.7-arm-6.patch +4- apply ipipe-core-3.5.7-zynq-post.patch +5- you can resume to generic installation instructions. + -- External links [1] http://opensource.freescale.com/pub/scm/imx/linux-2.6-imx.git diff --git a/ksrc/arch/arm/patches/zynq/ipipe-core-3.5.7-zynq-post.patch b/ksrc/arch/arm/patches/zynq/ipipe-core-3.5.7-zynq-post.patch new file mode 100644 index 0000000..03ef4d4 --- /dev/null +++ b/ksrc/arch/arm/patches/zynq/ipipe-core-3.5.7-zynq-post.patch @@ -0,0 +1,941 @@ +diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig +index eebf8bb..f2b7782 100644 +--- a/arch/arm/Kconfig ++++ b/arch/arm/Kconfig +@@ -992,6 +992,7 @@ config ARCH_ZYNQ + select COMMON_CLK + select ARCH_HAS_CPUFREQ + select ARCH_HAS_OPP ++ select IPIPE_ARM_KUSER_TSC if IPIPE + help + Support for Xilinx Zynq ARM Cortex A9 Platform + endchoice +diff --git a/arch/arm/boot/dts/zynq-zc702.dts b/arch/arm/boot/dts/zynq-zc702.dts +index 85ba299..0d79178 100644 +--- a/arch/arm/boot/dts/zynq-zc702.dts ++++ b/arch/arm/boot/dts/zynq-zc702.dts +@@ -143,11 +143,19 @@ + phy_type = "ulpi"; + }; + +- gpio@e000a000 { ++ gpio: gpio@e000a000 { + compatible = "xlnx,ps7-gpio-1.00.a"; + reg = <0xe000a000 0x1000>; + interrupts = <0 20 4>; + interrupt-parent = <&gic>; ++ interrupt-controller; ++ #interrupt-cells = <2>; ++ }; ++ ++ sw13 { ++ compatible = "sw13-irq-test"; ++ interrupt-parent = <&gpio>; ++ interrupts = <14 1>; + }; + + qspi0: spi@e000d000 { +diff --git a/arch/arm/configs/xilinx_zynq_ipipe_defconfig b/arch/arm/configs/xilinx_zynq_ipipe_defconfig +new file mode 100644 +index 0000000..9b41a0e +--- /dev/null ++++ b/arch/arm/configs/xilinx_zynq_ipipe_defconfig +@@ -0,0 +1,180 @@ ++# CONFIG_ARM_PATCH_PHYS_VIRT is not set ++CONFIG_PHYS_OFFSET=0x0 ++CONFIG_EXPERIMENTAL=y ++CONFIG_LOCALVERSION="" ++CONFIG_SYSVIPC=y ++CONFIG_IRQ_DOMAIN_DEBUG=y ++CONFIG_HIGH_RES_TIMERS=y ++CONFIG_IKCONFIG=y ++CONFIG_IKCONFIG_PROC=y ++CONFIG_LOG_BUF_SHIFT=14 ++CONFIG_SYSFS_DEPRECATED=y ++CONFIG_SYSFS_DEPRECATED_V2=y ++CONFIG_BLK_DEV_INITRD=y ++CONFIG_CC_OPTIMIZE_FOR_SIZE=y ++CONFIG_SYSCTL_SYSCALL=y ++CONFIG_EMBEDDED=y ++CONFIG_PERF_EVENTS=y ++CONFIG_SLAB=y ++CONFIG_MODULES=y ++CONFIG_MODULE_UNLOAD=y ++CONFIG_MODULE_FORCE_UNLOAD=y ++CONFIG_MODVERSIONS=y ++# CONFIG_BLK_DEV_BSG is not set ++CONFIG_ARCH_ZYNQ=y ++CONFIG_ZYNQ_EARLY_UART1=y ++# CONFIG_ZYNQ_EARLY_UART_EP107 is not set ++# CONFIG_XILINX_FIXED_DEVTREE_ADDR is not set ++CONFIG_PL310_ERRATA_588369=y ++CONFIG_PL310_ERRATA_727915=y ++CONFIG_PL310_ERRATA_753970=y ++CONFIG_PL310_ERRATA_769419=y ++CONFIG_SMP=y ++CONFIG_SCHED_MC=y ++CONFIG_SCHED_SMT=y ++CONFIG_PREEMPT=y ++CONFIG_AEABI=y ++# CONFIG_OABI_COMPAT is not set ++CONFIG_HIGHMEM=y ++CONFIG_ZBOOT_ROM_TEXT=0x0 ++CONFIG_ZBOOT_ROM_BSS=0x0 ++CONFIG_CMDLINE="console=ttyPS0,115200n8 root=/dev/ram rw initrd=0x00800000,16M earlyprintk mtdparts=physmap-flash.0:512K(nor-fsbl),512K(nor-u-boot),5M(nor-linux),9M(nor-user),1M(nor-scratch),-(nor-rootfs)" ++CONFIG_VFP=y ++CONFIG_NEON=y ++# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set ++# CONFIG_SUSPEND is not set ++CONFIG_PM_RUNTIME=y ++CONFIG_PM_OPP=y ++CONFIG_NET=y ++CONFIG_PACKET=y ++CONFIG_UNIX=y ++CONFIG_INET=y ++CONFIG_IP_MULTICAST=y ++CONFIG_IP_PNP=y ++CONFIG_IP_PNP_DHCP=y ++CONFIG_IP_PNP_BOOTP=y ++CONFIG_IP_PNP_RARP=y ++CONFIG_NET_IPIP=m ++CONFIG_VLAN_8021Q=m ++CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" ++CONFIG_DEVTMPFS=y ++CONFIG_DEVTMPFS_MOUNT=y ++CONFIG_FW_LOADER=m ++CONFIG_CMA=y ++CONFIG_CONNECTOR=y ++CONFIG_MTD=y ++CONFIG_MTD_CMDLINE_PARTS=y ++CONFIG_MTD_CHAR=y ++CONFIG_MTD_BLOCK=y ++CONFIG_MTD_CFI=y ++CONFIG_MTD_CFI_AMDSTD=y ++CONFIG_MTD_PHYSMAP=y ++CONFIG_MTD_PHYSMAP_OF=y ++CONFIG_MTD_M25P80=y ++# CONFIG_M25PXX_USE_FAST_READ is not set ++CONFIG_MTD_NAND=y ++CONFIG_MTD_NAND_XILINX_PSS=y ++CONFIG_PROC_DEVICETREE=y ++CONFIG_BLK_DEV_LOOP=y ++CONFIG_BLK_DEV_RAM=y ++CONFIG_BLK_DEV_RAM_SIZE=16384 ++CONFIG_EEPROM_AT24=y ++CONFIG_EEPROM_AT25=y ++CONFIG_SCSI=y ++CONFIG_BLK_DEV_SD=y ++CONFIG_CHR_DEV_SG=y ++CONFIG_SCSI_MULTI_LUN=y ++CONFIG_NETDEVICES=y ++CONFIG_XILINX_PS_EMAC=y ++CONFIG_MARVELL_PHY=y ++CONFIG_VITESSE_PHY=y ++CONFIG_MDIO_BITBANG=y ++CONFIG_INPUT_SPARSEKMAP=y ++CONFIG_INPUT_EVDEV=y ++CONFIG_INPUT_EVBUG=y ++CONFIG_VT_HW_CONSOLE_BINDING=y ++# CONFIG_LEGACY_PTYS is not set ++# CONFIG_DEVKMEM is not set ++CONFIG_SERIAL_XILINX_PS_UART=y ++CONFIG_SERIAL_XILINX_PS_UART_CONSOLE=y ++# CONFIG_HW_RANDOM is not set ++CONFIG_XILINX_DEVCFG=y ++CONFIG_I2C_CHARDEV=y ++CONFIG_I2C_MUX=y ++CONFIG_I2C_MUX_PCA954x=y ++CONFIG_I2C_XILINX_PS=y ++CONFIG_SPI=y ++CONFIG_SPI_XILINX_PS_QSPI=y ++CONFIG_SPI_XILINX_PS_SPI=y ++CONFIG_GPIO_SYSFS=y ++CONFIG_GPIO_XILINX_PS=y ++# CONFIG_HWMON is not set ++CONFIG_WATCHDOG=y ++CONFIG_XILINX_PS_WATCHDOG=y ++CONFIG_MEDIA_SUPPORT=y ++CONFIG_VIDEO_DEV=y ++# CONFIG_RC_CORE is not set ++# CONFIG_MEDIA_TUNER_CUSTOMISE is not set ++CONFIG_USB_VIDEO_CLASS=y ++CONFIG_USB_GSPCA=y ++# CONFIG_RADIO_ADAPTERS is not set ++CONFIG_FB=y ++CONFIG_FB_XYLON=y ++CONFIG_FB_XYLON_OF=y ++CONFIG_FB_XYLON_ZC702_PIXCLK=y ++CONFIG_FRAMEBUFFER_CONSOLE=y ++CONFIG_FONTS=y ++CONFIG_FONT_8x8=y ++CONFIG_FONT_8x16=y ++CONFIG_HID_MICROSOFT=y ++CONFIG_USB=y ++CONFIG_USB_SUSPEND=y ++CONFIG_USB_OTG=y ++# CONFIG_USB_OTG_WHITELIST is not set ++CONFIG_USB_EHCI_HCD=y ++# CONFIG_USB_EHCI_TT_NEWSCHED is not set ++CONFIG_USB_EHCI_XUSBPS=y ++CONFIG_USB_STORAGE=y ++CONFIG_USB_GADGET=y ++CONFIG_USB_GADGET_XUSBPS=y ++CONFIG_XUSBPS_ERRATA_DT654401=y ++CONFIG_USB_ZERO=m ++CONFIG_USB_FILE_STORAGE=m ++CONFIG_USB_XUSBPS_OTG=y ++CONFIG_MMC=y ++CONFIG_MMC_SDHCI=y ++CONFIG_MMC_SDHCI_PLTFM=y ++CONFIG_MMC_SDHCI_OF_XILINX_PS=y ++CONFIG_RTC_CLASS=y ++CONFIG_RTC_DRV_PCF8563=y ++CONFIG_UIO=y ++CONFIG_UIO_PDRV=y ++CONFIG_UIO_PDRV_GENIRQ=y ++CONFIG_COMMON_CLK_DEBUG=y ++CONFIG_EXT2_FS=y ++CONFIG_EXT3_FS=y ++# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set ++CONFIG_EXT4_FS=y ++# CONFIG_DNOTIFY is not set ++CONFIG_MSDOS_FS=y ++CONFIG_VFAT_FS=y ++CONFIG_TMPFS=y ++CONFIG_JFFS2_FS=y ++CONFIG_JFFS2_SUMMARY=y ++CONFIG_NFS_FS=y ++CONFIG_ROOT_NFS=y ++CONFIG_NLS_CODEPAGE_437=y ++CONFIG_NLS_ASCII=y ++CONFIG_NLS_ISO8859_1=y ++CONFIG_PRINTK_TIME=y ++# CONFIG_ENABLE_WARN_DEPRECATED is not set ++# CONFIG_ENABLE_MUST_CHECK is not set ++# CONFIG_SCHED_DEBUG is not set ++CONFIG_TIMER_STATS=y ++# CONFIG_DEBUG_PREEMPT is not set ++# CONFIG_DEBUG_BUGVERBOSE is not set ++# CONFIG_RCU_CPU_STALL_VERBOSE is not set ++# CONFIG_FTRACE is not set ++CONFIG_DYNAMIC_DEBUG=y ++CONFIG_DEBUG_LL=y ++CONFIG_EARLY_PRINTK=y +diff --git a/arch/arm/kernel/ipipe.c b/arch/arm/kernel/ipipe.c +index ff4ad1a..cf5f29b 100644 +--- a/arch/arm/kernel/ipipe.c ++++ b/arch/arm/kernel/ipipe.c +@@ -574,8 +574,6 @@ EXPORT_SYMBOL_GPL(__ipipe_serial_debug); + + EXPORT_SYMBOL_GPL(do_munmap); + EXPORT_SYMBOL_GPL(show_stack); +-EXPORT_SYMBOL_GPL(init_mm); +-EXPORT_SYMBOL_GPL(cpu_architecture); + #ifndef MULTI_CPU + EXPORT_SYMBOL_GPL(cpu_do_switch_mm); + #endif +diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c +index f77ef11..1a19807 100644 +--- a/arch/arm/kernel/smp.c ++++ b/arch/arm/kernel/smp.c +@@ -239,6 +239,9 @@ asmlinkage void __cpuinit secondary_start_kernel(void) + { + struct mm_struct *mm = &init_mm; + unsigned int cpu; ++#ifdef CONFIG_ARCH_ZYNQ ++ static bool booted; ++#endif + + cpu_switch_mm(mm->pgd, mm, 1); + enter_lazy_tlb(mm, current); +@@ -266,7 +269,13 @@ asmlinkage void __cpuinit secondary_start_kernel(void) + + notify_cpu_starting(cpu); + ++#ifdef CONFIG_ARCH_ZYNQ ++ if (!booted) ++ calibrate_delay(); ++ booted = true; ++#else + calibrate_delay(); ++#endif + + smp_store_cpu_info(cpu); + +diff --git a/arch/arm/mach-zynq/include/mach/gpio.h b/arch/arm/mach-zynq/include/mach/gpio.h +index df1b13a..1364c30 100755 +--- a/arch/arm/mach-zynq/include/mach/gpio.h ++++ b/arch/arm/mach-zynq/include/mach/gpio.h +@@ -18,8 +18,8 @@ + #define __ASM_ARCH_GPIO_H + + +-#define ARCH_NR_GPIOS 512 +-#define XGPIOPS_IRQBASE 128 ++#define ARCH_NR_GPIOS 256 ++#define XGPIOPS_IRQBASE 256 + + struct xgpio_platform_data { + unsigned int state; +@@ -60,9 +60,6 @@ static inline unsigned int irq_to_gpio(unsigned int irq) + return irq - XGPIOPS_IRQBASE; + } + +-void xgpiodf_set_bypass_mode(struct gpio_chip *chip, unsigned int pin); +-void xgpiodf_set_normal_mode(struct gpio_chip *chip, unsigned int pin); +- + #endif /* __ASM_ARCH_GPIO_H */ + + +diff --git a/arch/arm/mach-zynq/include/mach/irqs.h b/arch/arm/mach-zynq/include/mach/irqs.h +index 33b6af6..d780882 100644 +--- a/arch/arm/mach-zynq/include/mach/irqs.h ++++ b/arch/arm/mach-zynq/include/mach/irqs.h +@@ -15,6 +15,11 @@ + #ifndef __MACH_IRQS_H + #define __MACH_IRQS_H + +-#define NR_IRQS 128 ++#define IRQ_XILINX_MSI_0 128 ++/* ++ * IRQs 128-256 - PCIe ++ * IRQs 256-512 - gpio ++ */ ++#define NR_IRQS 512 + + #endif +diff --git a/arch/arm/mach-zynq/timer.c b/arch/arm/mach-zynq/timer.c +index 38faf0f..6f90595 100644 +--- a/arch/arm/mach-zynq/timer.c ++++ b/arch/arm/mach-zynq/timer.c +@@ -28,6 +28,8 @@ + #include + #include + #include ++#include ++#include + + #include + #include +@@ -73,9 +75,15 @@ + /* Setup the timers to use pre-scaling, using a fixed value for now that will work + * across most input frequency, but it may need to be more dynamic + */ +-#define PRESCALE_EXPONENT 11 /* 2 ^ PRESCALE_EXPONENT = PRESCALE */ +-#define PRESCALE 2048 /* The exponent must match this */ +-#define CLK_CNTRL_PRESCALE (((PRESCALE_EXPONENT - 1) << 1) | 0x1) ++#define PRESCALE_EXPONENT 8 /* 2 ^ PRESCALE_EXPONENT = PRESCALE */ ++#define PRESCALE (2 << (PRESCALE_EXPONENT - 1)) ++#define CLK_CNTRL_PRESCALE (((PRESCALE_EXPONENT - 1) << 1) | 0x1) ++ ++#define PRESCALE_EXPONENT_EV 5 /* 2 ^ PRESCALE_EXPONENT = PRESCALE */ ++#define PRESCALE_EV (2 << (PRESCALE_EXPONENT_EV - 1)) ++#define CLK_CNTRL_PRESCALE_EV (((PRESCALE_EXPONENT_EV - 1) << 1) | 0x1) ++ ++unsigned max_delta_ticks; + + /** + * struct xttcpss_timer - This definition defines local timer structure +@@ -117,6 +125,13 @@ static void xttcpss_set_interval(struct xttcpss_timer *timer, + __raw_writel(ctrl_reg, timer->base_addr + XTTCPSS_CNT_CNTRL_OFFSET); + } + ++static void xttcpss_timer_ack(void) ++{ ++ struct xttcpss_timer *timer = &timers[XTTCPSS_CLOCKEVENT]; ++ ++ __raw_readl(timer->base_addr + XTTCPSS_ISR_OFFSET); ++} ++ + /** + * xttcpss_clock_event_interrupt - Clock event timer interrupt handler + * +@@ -128,11 +143,13 @@ static void xttcpss_set_interval(struct xttcpss_timer *timer, + static irqreturn_t xttcpss_clock_event_interrupt(int irq, void *dev_id) + { + struct clock_event_device *evt = &xttcpss_clockevent; +- struct xttcpss_timer *timer = dev_id; + + /* Acknowledge the interrupt and call event handler */ +- __raw_writel(__raw_readl(timer->base_addr + XTTCPSS_ISR_OFFSET), +- timer->base_addr + XTTCPSS_ISR_OFFSET); ++ if (!clockevent_ipipe_stolen(evt)) ++ xttcpss_timer_ack(); ++ ++ if (num_possible_cpus() == 1) ++ __ipipe_tsc_update(); + + evt->event_handler(evt); + +@@ -145,6 +162,17 @@ static struct irqaction event_timer_irq = { + .handler = xttcpss_clock_event_interrupt, + }; + ++#ifdef CONFIG_IPIPE ++static struct __ipipe_tscinfo tsc_info = { ++ .type = IPIPE_TSC_TYPE_FREERUNNING, ++ .u = { ++ { ++ .mask = 0x0000ffff, ++ }, ++ }, ++}; ++#endif /* CONFIG_IPIPE */ ++ + /** + * xttcpss_timer_hardware_init - Initialize the timer hardware + * +@@ -171,7 +199,7 @@ static void __init xttcpss_timer_hardware_init(void) + */ + __raw_writel(0x23, timers[XTTCPSS_CLOCKEVENT].base_addr + + XTTCPSS_CNT_CNTRL_OFFSET); +- __raw_writel(CLK_CNTRL_PRESCALE, ++ __raw_writel(CLK_CNTRL_PRESCALE_EV, + timers[XTTCPSS_CLOCKEVENT].base_addr + + XTTCPSS_CLK_CNTRL_OFFSET); + __raw_writel(0x1, timers[XTTCPSS_CLOCKEVENT].base_addr + +@@ -216,6 +244,13 @@ static int xttcpss_set_next_event(unsigned long cycles, + { + struct xttcpss_timer *timer = &timers[XTTCPSS_CLOCKEVENT]; + ++#ifdef CONFIG_IPIPE ++ if (cycles > max_delta_ticks) ++ cycles = max_delta_ticks; ++#endif ++ ++ __ipipe_tsc_update(); ++ + xttcpss_set_interval(timer, cycles); + return 0; + } +@@ -255,6 +290,12 @@ static void xttcpss_set_mode(enum clock_event_mode mode, + } + } + ++#ifdef CONFIG_IPIPE ++static struct ipipe_timer xttcpss_itimer = { ++ .ack = xttcpss_timer_ack, ++}; ++#endif /* CONFIG_IPIPE */ ++ + /* + * Instantiate and initialize the clock event structure + */ +@@ -264,6 +305,9 @@ static struct clock_event_device xttcpss_clockevent = { + .set_next_event = xttcpss_set_next_event, + .set_mode = xttcpss_set_mode, + .rating = 200, ++#ifdef CONFIG_IPIPE ++ .ipipe_timer = &xttcpss_itimer, ++#endif /* CONFIG_IPIPE */ + }; + + static int xttcpss_timer_rate_change_cb(struct notifier_block *nb, +@@ -279,7 +323,7 @@ static int xttcpss_timer_rate_change_cb(struct notifier_block *nb, + timers[XTTCPSS_CLOCKSOURCE].frequency = + ndata->new_rate / PRESCALE; + timers[XTTCPSS_CLOCKEVENT].frequency = +- ndata->new_rate / PRESCALE; ++ ndata->new_rate / PRESCALE_EV; + + /* Do whatever is necessare to maintain a proper time base */ + /* +@@ -400,11 +444,11 @@ static void __init xttcpss_timer_init(void) + } + if (prop2) { + timers[XTTCPSS_CLOCKEVENT].frequency = +- be32_to_cpup(prop2) / PRESCALE; ++ be32_to_cpup(prop2) / PRESCALE_EV; + } else { + pr_err("Error, no clock-frequency specified for timer\n"); + timers[XTTCPSS_CLOCKEVENT].frequency = +- PERIPHERAL_CLOCK_RATE / PRESCALE; ++ PERIPHERAL_CLOCK_RATE / PRESCALE_EV; + } + } else { + clk_prepare_enable(clk); +@@ -419,7 +463,7 @@ static void __init xttcpss_timer_init(void) + timers[XTTCPSS_CLOCKSOURCE].frequency = + clk_get_rate(clk) / PRESCALE; + timers[XTTCPSS_CLOCKEVENT].frequency = +- clk_get_rate(clk) / PRESCALE; ++ clk_get_rate(clk) / PRESCALE_EV; + if (clk_notifier_register(clk, + &timers[XTTCPSS_CLOCKSOURCE].clk_rate_change_nb)) + pr_warn("Unable to register clock notifier.\n"); +@@ -429,6 +473,29 @@ static void __init xttcpss_timer_init(void) + clocksource_register_hz(&clocksource_xttcpss, + timers[XTTCPSS_CLOCKSOURCE].frequency); + ++#ifdef CONFIG_IPIPE ++ if (num_possible_cpus() == 1) { ++ struct resource res; ++ ++ tsc_info.freq = timers[XTTCPSS_CLOCKSOURCE].frequency; ++ tsc_info.counter_vaddr = ++ (unsigned long)timers[XTTCPSS_CLOCKSOURCE].base_addr + ++ XTTCPSS_COUNT_VAL_OFFSET; ++ of_address_to_resource(timer, 0, &res); ++ tsc_info.u.counter_paddr = res.start + XTTCPSS_COUNT_VAL_OFFSET; ++ ++ __ipipe_tsc_register(&tsc_info); ++ } ++ ++ xttcpss_itimer.irq = irq; ++ xttcpss_itimer.freq = timers[XTTCPSS_CLOCKEVENT].frequency; ++ max_delta_ticks = 0xffff - xttcpss_itimer.freq / 1000; ++ xttcpss_itimer.min_delay_ticks = 1; ++ printk(KERN_INFO "I-pipe, %lu.%03lu MHz timer\n", ++ xttcpss_itimer.freq / 1000000, ++ (xttcpss_itimer.freq % 1000000) / 1000); ++#endif /* CONFIG_IPIPE */ ++ + /* Indicate that clock event is on 1st CPU as SMP boot needs it */ + xttcpss_clockevent.cpumask = cpumask_of(0); + clockevents_config_and_register(&xttcpss_clockevent, +diff --git a/drivers/gpio/gpio-xilinxps.c b/drivers/gpio/gpio-xilinxps.c +index b89739d..b0c9162 100644 +--- a/drivers/gpio/gpio-xilinxps.c ++++ b/drivers/gpio/gpio-xilinxps.c +@@ -24,12 +24,15 @@ + #include + #include + #include +-#ifdef CONFIG_COMMON_CLK ++#include + #include + #include +-#endif ++#include ++#include ++#include + + #define DRIVER_NAME "xgpiops" ++#define XGPIOPS_NR_GPIOS 118 + + /* Register offsets for the GPIO device */ + +@@ -84,12 +87,13 @@ static unsigned int xgpiops_pin_table[] = { + struct xgpiops { + struct gpio_chip chip; + void __iomem *base_addr; +-#ifdef CONFIG_COMMON_CLK ++ unsigned int irq; + struct clk *clk; +-#endif +- spinlock_t gpio_lock; ++ ipipe_spinlock_t gpio_lock; + }; + ++static struct irq_domain *irq_domain; ++ + /** + * xgpiops_get_bank_pin - Get the bank number and pin number within that bank + * for a given pin in the GPIO device +@@ -236,6 +240,11 @@ static int xgpiops_dir_out(struct gpio_chip *chip, unsigned int pin, int state) + return 0; + } + ++static int xgpiops_to_irq(struct gpio_chip *chip, unsigned offset) ++{ ++ return irq_find_mapping(irq_domain, offset); ++} ++ + /** + * xgpiops_irq_ack - Acknowledge the interrupt of a gpio pin + * @irq_data: irq data containing irq number of gpio pin for the interrupt to ack +@@ -247,15 +256,11 @@ static void xgpiops_irq_ack(struct irq_data *irq_data) + { + struct xgpiops *gpio = (struct xgpiops *)irq_data_get_irq_chip_data(irq_data); + unsigned int device_pin_num, bank_num, bank_pin_num; +- unsigned int irq_sts; + +- device_pin_num = irq_to_gpio(irq_data->irq); /* get pin num within the device */ ++ device_pin_num = irq_data->hwirq; /* get pin num within the device */ + xgpiops_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); +- irq_sts = xgpiops_readreg(gpio->base_addr + +- XGPIOPS_INTSTS_OFFSET(bank_num)) | +- (1 << bank_pin_num); +- xgpiops_writereg(irq_sts, +- gpio->base_addr + (XGPIOPS_INTSTS_OFFSET(bank_num))); ++ xgpiops_writereg(1 << bank_pin_num, gpio->base_addr + ++ (XGPIOPS_INTSTS_OFFSET(bank_num))); + } + + /** +@@ -270,14 +275,10 @@ static void xgpiops_irq_mask(struct irq_data *irq_data) + { + struct xgpiops *gpio = (struct xgpiops *)irq_data_get_irq_chip_data(irq_data); + unsigned int device_pin_num, bank_num, bank_pin_num; +- unsigned int irq_dis; + +- device_pin_num = irq_to_gpio(irq_data->irq); /* get pin num within the device */ ++ device_pin_num = irq_data->hwirq; /* get pin num within the device */ + xgpiops_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); +- irq_dis = xgpiops_readreg(gpio->base_addr + +- XGPIOPS_INTDIS_OFFSET(bank_num)) | +- (1 << bank_pin_num); +- xgpiops_writereg(irq_dis, ++ xgpiops_writereg(1 << bank_pin_num, + gpio->base_addr + XGPIOPS_INTDIS_OFFSET(bank_num)); + } + +@@ -293,20 +294,16 @@ static void xgpiops_irq_unmask(struct irq_data *irq_data) + { + struct xgpiops *gpio = (struct xgpiops *)irq_data_get_irq_chip_data(irq_data); + unsigned int device_pin_num, bank_num, bank_pin_num; +- unsigned int irq_en; + +- device_pin_num = irq_to_gpio(irq_data->irq); /* get pin num within the device */ ++ device_pin_num = irq_data->hwirq; /* get pin num within the device */ + xgpiops_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); +- irq_en = xgpiops_readreg(gpio->base_addr + +- XGPIOPS_INTEN_OFFSET(bank_num)) | +- (1 << bank_pin_num); +- xgpiops_writereg(irq_en, ++ xgpiops_writereg(1 << bank_pin_num, + gpio->base_addr + XGPIOPS_INTEN_OFFSET(bank_num)); + } + + /** + * xgpiops_set_irq_type - Set the irq type for a gpio pin +- * @irq_data: irq data containing irq number of gpio pin ++ * @irq_data: irq data containing irq number of gpio pin + * @type: interrupt type that is to be set for the gpio pin + * + * This function gets the gpio pin number and its bank from the gpio pin number +@@ -324,7 +321,7 @@ static int xgpiops_set_irq_type(struct irq_data *irq_data, unsigned int type) + unsigned int device_pin_num, bank_num, bank_pin_num; + unsigned int int_type, int_pol, int_any; + +- device_pin_num = irq_to_gpio(irq_data->irq); /* get pin num within the device */ ++ device_pin_num = irq_data->hwirq; /* get pin num within the device */ + xgpiops_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); + + int_type = xgpiops_readreg(gpio->base_addr + +@@ -374,6 +371,16 @@ static int xgpiops_set_irq_type(struct irq_data *irq_data, unsigned int type) + return 0; + } + ++static int xgpiops_set_wake(struct irq_data *data, unsigned int on) ++{ ++ if (on) ++ xgpiops_irq_unmask(data); ++ else ++ xgpiops_irq_mask(data); ++ ++ return 0; ++} ++ + /* irq chip descriptor */ + static struct irq_chip xgpiops_irqchip = { + .name = DRIVER_NAME, +@@ -381,6 +388,7 @@ static struct irq_chip xgpiops_irqchip = { + .irq_mask = xgpiops_irq_mask, + .irq_unmask = xgpiops_irq_unmask, + .irq_set_type = xgpiops_set_irq_type, ++ .irq_set_wake = xgpiops_set_wake, + }; + + /** +@@ -401,45 +409,50 @@ void xgpiops_irqhandler(unsigned int irq, struct irq_desc *desc) + unsigned int int_sts, int_enb, bank_num; + struct irq_desc *gpio_irq_desc; + struct irq_chip *chip = irq_desc_get_chip(desc); +- struct irq_data *irq_data = irq_get_chip_data(irq); + +- chip->irq_ack(irq_data); ++ chained_irq_enter(chip, desc); ++ + for (bank_num = 0; bank_num < 4; bank_num++) { + int_sts = xgpiops_readreg(gpio->base_addr + + XGPIOPS_INTSTS_OFFSET(bank_num)); + int_enb = xgpiops_readreg(gpio->base_addr + + XGPIOPS_INTMASK_OFFSET(bank_num)); +- /* +- * handle only the interrupts which are enabled in interrupt +- * mask register +- */ + int_sts &= ~int_enb; ++ + for (; int_sts != 0; int_sts >>= 1, gpio_irq++) { + if ((int_sts & 1) == 0) + continue; +- BUG_ON(!(irq_desc[gpio_irq].handle_irq)); + gpio_irq_desc = irq_to_desc(gpio_irq); +- chip->irq_ack(irq_data); ++ BUG_ON(!gpio_irq_desc); ++ chip = irq_desc_get_chip(gpio_irq_desc); ++ BUG_ON(!chip); ++ chip->irq_ack(&gpio_irq_desc->irq_data); + + /* call the pin specific handler */ +- irq_desc[gpio_irq].handle_irq(gpio_irq, +- &irq_desc[gpio_irq]); ++ ipipe_handle_demuxed_irq(gpio_irq); + } + /* shift to first virtual irq of next bank */ +- gpio_irq = (int)irq_get_handler_data(irq) + ++ gpio_irq = (int)irq_get_handler_data(irq) + + (xgpiops_pin_table[bank_num] + 1); + } +- chip->irq_unmask(irq_data); ++ ++ chip = irq_desc_get_chip(desc); ++ chained_irq_exit(chip, desc); + } + +-#if defined(CONFIG_PM) && defined(CONFIG_COMMON_CLK) ++#ifdef CONFIG_PM_SLEEP + static int xgpiops_suspend(struct device *_dev) + { + struct platform_device *pdev = container_of(_dev, + struct platform_device, dev); + struct xgpiops *gpio = platform_get_drvdata(pdev); + +- clk_disable(gpio->clk); ++ if (!device_may_wakeup(_dev)) { ++ if (!pm_runtime_suspended(_dev)) ++ clk_disable(gpio->clk); ++ return 0; ++ } ++ + return 0; + } + +@@ -449,10 +462,38 @@ static int xgpiops_resume(struct device *_dev) + struct platform_device, dev); + struct xgpiops *gpio = platform_get_drvdata(pdev); + +- return clk_enable(gpio->clk); ++ if (!device_may_wakeup(_dev)) { ++ if (!pm_runtime_suspended(_dev)) ++ return clk_enable(gpio->clk); ++ } ++ ++ return 0; + } ++#endif + + #ifdef CONFIG_PM_RUNTIME ++static int xgpiops_runtime_suspend(struct device *_dev) ++{ ++ struct platform_device *pdev = container_of(_dev, ++ struct platform_device, dev); ++ struct xgpiops *gpio = platform_get_drvdata(pdev); ++ ++ clk_disable(gpio->clk); ++ ++ return 0; ++} ++ ++static int xgpiops_runtime_resume(struct device *_dev) ++{ ++ struct platform_device *pdev = container_of(_dev, ++ struct platform_device, dev); ++ struct xgpiops *gpio = platform_get_drvdata(pdev); ++ ++ return clk_enable(gpio->clk); ++ ++ return 0; ++} ++ + static int xgpiops_idle(struct device *dev) + { + return pm_schedule_suspend(dev, 1); +@@ -460,29 +501,38 @@ static int xgpiops_idle(struct device *dev) + + static int xgpiops_request(struct gpio_chip *chip, unsigned offset) + { +- return pm_runtime_get(chip->dev); ++ int ret; ++ ++ ret = pm_runtime_get_sync(chip->dev); ++ ++ /* ++ * If the device is already active pm_runtime_get() will return 1 on ++ * success, but gpio_request still needs to return 0. ++ */ ++ return ret < 0 ? ret : 0; + } + + static void xgpiops_free(struct gpio_chip *chip, unsigned offset) + { +- pm_runtime_put(chip->dev); ++ pm_runtime_put_sync(chip->dev); + } + +-static UNIVERSAL_DEV_PM_OPS(xgpiops_dev_pm_ops, xgpiops_suspend, xgpiops_resume, +- xgpiops_idle); + #else /* ! CONFIG_PM_RUNTIME */ +-static SIMPLE_DEV_PM_OPS(xgpiops_dev_pm_ops, xgpiops_suspend, xgpiops_resume); + #define xgpiops_request NULL + #define xgpiops_free NULL + #endif /* ! CONFIG_PM_RUNTIME */ + ++#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP) ++static const struct dev_pm_ops xgpiops_dev_pm_ops = { ++ SET_SYSTEM_SLEEP_PM_OPS(xgpiops_suspend, xgpiops_resume) ++ SET_RUNTIME_PM_OPS(xgpiops_runtime_suspend, xgpiops_runtime_resume, ++ xgpiops_idle) ++}; + #define XGPIOPS_PM (&xgpiops_dev_pm_ops) + +-#else /*! CONFIG_PM && ! CONFIG_COMMON_CLK */ ++#else /*! CONFIG_PM_RUNTIME || ! CONFIG_PM_SLEEP */ + #define XGPIOPS_PM NULL +-#define xgpiops_request NULL +-#define xgpiops_free NULL +-#endif /*! CONFIG_PM && ! CONFIG_COMMON_CLK */ ++#endif /*! CONFIG_PM_RUNTIME */ + + /** + * xgpiops_probe - Initialization method for a xgpiops device +@@ -494,7 +544,7 @@ static SIMPLE_DEV_PM_OPS(xgpiops_dev_pm_ops, xgpiops_suspend, xgpiops_resume); + * Note: Interrupts are disabled for all the banks during initialization. + * Returns 0 on success, negative error otherwise. + */ +-static int __init xgpiops_probe(struct platform_device *pdev) ++static int __devinit xgpiops_probe(struct platform_device *pdev) + { + int ret; + unsigned int irq_num; +@@ -502,7 +552,8 @@ static int __init xgpiops_probe(struct platform_device *pdev) + struct gpio_chip *chip; + resource_size_t remap_size; + struct resource *mem_res = NULL; +- int pin_num, bank_num, gpio_irq; ++ int pin_num, bank_num; ++ int irq_base; + + gpio = kzalloc(sizeof(struct xgpiops), GFP_KERNEL); + if (!gpio) { +@@ -538,6 +589,7 @@ static int __init xgpiops_probe(struct platform_device *pdev) + } + + irq_num = platform_get_irq(pdev, 0); ++ gpio->irq = irq_num; + + /* configure the gpio chip */ + chip = &gpio->chip; +@@ -550,9 +602,10 @@ static int __init xgpiops_probe(struct platform_device *pdev) + chip->free = xgpiops_free; + chip->direction_input = xgpiops_dir_in; + chip->direction_output = xgpiops_dir_out; ++ chip->to_irq = xgpiops_to_irq; + chip->dbg_show = NULL; + chip->base = 0; /* default pin base */ +- chip->ngpio = 246; ++ chip->ngpio = XGPIOPS_NR_GPIOS; + chip->can_sleep = 0; + + /* report a bug if gpio chip registration fails */ +@@ -566,20 +619,18 @@ static int __init xgpiops_probe(struct platform_device *pdev) + (unsigned long)gpio->base_addr); + } + +-#ifdef CONFIG_COMMON_CLK + /* Enable GPIO clock */ + gpio->clk = clk_get_sys("GPIO_APER", NULL); + if (IS_ERR(gpio->clk)) { +- pr_err("Xilinx GPIOPS clock not found.\n"); ++ dev_err(&pdev->dev, "Clock not found.\n"); + ret = PTR_ERR(gpio->clk); + goto err_chip_remove; + } + ret = clk_prepare_enable(gpio->clk); + if (ret) { +- pr_err("Xilinx GPIOPS unable to enable clock.\n"); ++ dev_err(&pdev->dev, "Unable to enable clock.\n"); + goto err_clk_put; + } +-#endif + + /* disable interrupts for all banks */ + for (bank_num = 0; bank_num < 4; bank_num++) { +@@ -587,32 +638,43 @@ static int __init xgpiops_probe(struct platform_device *pdev) + XGPIOPS_INTDIS_OFFSET(bank_num)); + } + ++ irq_base = irq_alloc_descs(-1, 0, XGPIOPS_NR_GPIOS, 0); ++ if (irq_base < 0) { ++ dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); ++ goto err_clk_put; ++ } ++ ++ irq_domain = irq_domain_add_legacy(pdev->dev.of_node, XGPIOPS_NR_GPIOS, ++ irq_base, 0, &irq_domain_simple_ops, ++ NULL); ++ + /* + * set the irq chip, handler and irq chip data for callbacks for + * each pin + */ +- gpio_irq = XGPIOPS_IRQBASE; +- for (pin_num = 0; pin_num < ARCH_NR_GPIOS; pin_num++, gpio_irq++) { +- irq_set_chip(gpio_irq, &xgpiops_irqchip); ++ for (pin_num = 0; pin_num < XGPIOPS_NR_GPIOS; pin_num++) { ++ int gpio_irq = irq_find_mapping(irq_domain, pin_num); ++ ++ irq_set_chip_and_handler(gpio_irq, &xgpiops_irqchip, ++ handle_simple_irq); + irq_set_chip_data(gpio_irq, (void *)gpio); +- irq_set_handler(gpio_irq, handle_simple_irq); +- irq_set_status_flags(gpio_irq, IRQF_VALID); ++ set_irq_flags(gpio_irq, IRQF_VALID); + } + +- irq_set_handler_data(irq_num, (void *)(XGPIOPS_IRQBASE)); ++ irq_set_handler_data(irq_num, (void *)irq_base); + irq_set_chained_handler(irq_num, xgpiops_irqhandler); + +- pm_runtime_set_active(&pdev->dev); ++ clk_disable(gpio->clk); + pm_runtime_enable(&pdev->dev); + ++ device_set_wakeup_capable(&pdev->dev, 1); ++ + return 0; + +-#ifdef CONFIG_COMMON_CLK + err_clk_put: + clk_put(gpio->clk); + err_chip_remove: + gpiochip_remove(chip); +-#endif + err_iounmap: + iounmap(gpio->base_addr); + err_release_region: +@@ -626,31 +688,26 @@ err_free_gpio: + + static int xgpiops_remove(struct platform_device *pdev) + { +-#ifdef CONFIG_COMMON_CLK + struct xgpiops *gpio = platform_get_drvdata(pdev); + + clk_disable_unprepare(gpio->clk); + clk_put(gpio->clk); +-#endif ++ device_set_wakeup_capable(&pdev->dev, 0); + return 0; + } + +-#ifdef CONFIG_OF + static struct of_device_id xgpiops_of_match[] __devinitdata = { + { .compatible = "xlnx,ps7-gpio-1.00.a", }, + { /* end of table */} + }; + MODULE_DEVICE_TABLE(of, xgpiops_of_match); +-#endif + + static struct platform_driver xgpiops_driver = { + .driver = { + .name = DRIVER_NAME, + .owner = THIS_MODULE, + .pm = XGPIOPS_PM, +-#ifdef CONFIG_OF + .of_match_table = xgpiops_of_match, +-#endif + }, + .probe = xgpiops_probe, + .remove = xgpiops_remove, diff --git a/ksrc/arch/arm/patches/zynq/ipipe-core-3.5.7-zynq-pre.patch b/ksrc/arch/arm/patches/zynq/ipipe-core-3.5.7-zynq-pre.patch new file mode 100644 index 0000000..76796d0 --- /dev/null +++ b/ksrc/arch/arm/patches/zynq/ipipe-core-3.5.7-zynq-pre.patch @@ -0,0 +1,30351 @@ +diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801 +index 71f55bb..99d4e44 100644 +--- a/Documentation/i2c/busses/i2c-i801 ++++ b/Documentation/i2c/busses/i2c-i801 +@@ -21,6 +21,7 @@ Supported adapters: + * Intel DH89xxCC (PCH) + * Intel Panther Point (PCH) + * Intel Lynx Point (PCH) ++ * Intel Lynx Point-LP (PCH) + Datasheets: Publicly available at the Intel website + + On Intel Patsburg and later chipsets, both the normal host SMBus controller +diff --git a/Documentation/security/Yama.txt b/Documentation/security/Yama.txt +index e369de2..dd908cf 100644 +--- a/Documentation/security/Yama.txt ++++ b/Documentation/security/Yama.txt +@@ -46,14 +46,13 @@ restrictions, it can call prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, ...) + so that any otherwise allowed process (even those in external pid namespaces) + may attach. + +-These restrictions do not change how ptrace via PTRACE_TRACEME operates. +- +-The sysctl settings are: ++The sysctl settings (writable only with CAP_SYS_PTRACE) are: + + 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other + process running under the same uid, as long as it is dumpable (i.e. + did not transition uids, start privileged, or have called +- prctl(PR_SET_DUMPABLE...) already). ++ prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is ++ unchanged. + + 1 - restricted ptrace: a process must have a predefined relationship + with the inferior it wants to call PTRACE_ATTACH on. By default, +@@ -61,12 +60,13 @@ The sysctl settings are: + classic criteria is also met. To change the relationship, an + inferior can call prctl(PR_SET_PTRACER, debugger, ...) to declare + an allowed debugger PID to call PTRACE_ATTACH on the inferior. ++ Using PTRACE_TRACEME is unchanged. + + 2 - admin-only attach: only processes with CAP_SYS_PTRACE may use ptrace +- with PTRACE_ATTACH. ++ with PTRACE_ATTACH, or through children calling PTRACE_TRACEME. + +-3 - no attach: no processes may use ptrace with PTRACE_ATTACH. Once set, +- this sysctl cannot be changed to a lower value. ++3 - no attach: no processes may use ptrace with PTRACE_ATTACH nor via ++ PTRACE_TRACEME. Once set, this sysctl value cannot be changed. + + The original children-only logic was based on the restrictions in grsecurity. + +diff --git a/Documentation/sound/alsa/HD-Audio-Models.txt b/Documentation/sound/alsa/HD-Audio-Models.txt +index 03f7897..82dd174 100644 +--- a/Documentation/sound/alsa/HD-Audio-Models.txt ++++ b/Documentation/sound/alsa/HD-Audio-Models.txt +@@ -21,10 +21,11 @@ ALC267/268 + ========== + N/A + +-ALC269 ++ALC269/270/275/276/280/282 + ====== + laptop-amic Laptops with analog-mic input + laptop-dmic Laptops with digital-mic input ++ lenovo-dock Enables docking station I/O for some Lenovos + + ALC662/663/272 + ============== +@@ -46,6 +47,7 @@ ALC882/883/885/888/889 + acer-aspire-4930g Acer Aspire 4930G/5930G/6530G/6930G/7730G + acer-aspire-8930g Acer Aspire 8330G/6935G + acer-aspire Acer Aspire others ++ no-primary-hp VAIO Z workaround (for fixed speaker DAC) + + ALC861/660 + ========== +diff --git a/Documentation/stable_kernel_rules.txt b/Documentation/stable_kernel_rules.txt +index 4a7b54b..b0714d8 100644 +--- a/Documentation/stable_kernel_rules.txt ++++ b/Documentation/stable_kernel_rules.txt +@@ -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: +@@ -42,10 +42,10 @@ Procedure for submitting patches to the -stable tree: + cherry-picked than this can be specified in the following format in + the sign-off area: + +- Cc: # .32.x: a1f84a3: sched: Check for idle +- Cc: # .32.x: 1b9508f: sched: Rate-limit newidle +- Cc: # .32.x: fd21073: sched: Fix affinity logic +- Cc: # .32.x ++ Cc: # 3.3.x: a1f84a3: sched: Check for idle ++ Cc: # 3.3.x: 1b9508f: sched: Rate-limit newidle ++ Cc: # 3.3.x: fd21073: sched: Fix affinity logic ++ Cc: # 3.3.x + Signed-off-by: Ingo Molnar + + The tag sequence has the meaning of: +@@ -79,6 +79,15 @@ Review cycle: + 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 --git a/MAINTAINERS b/MAINTAINERS +index fe643e7..0d67d1b 100644 +--- a/MAINTAINERS ++++ b/MAINTAINERS +@@ -5635,7 +5635,7 @@ F: Documentation/blockdev/ramdisk.txt + F: drivers/block/brd.c + + RANDOM NUMBER DRIVER +-M: Matt Mackall ++M: Theodore Ts'o" + S: Maintained + F: drivers/char/random.c + +diff --git a/Makefile b/Makefile +index 021dcfe..b8f1666 100644 +--- a/Makefile ++++ b/Makefile +@@ -1,6 +1,6 @@ + VERSION = 3 + PATCHLEVEL = 5 +-SUBLEVEL = 0 ++SUBLEVEL = 7 + EXTRAVERSION = -14.3-build2 + NAME = Saber-toothed Squirrel + +diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h +index 3bb7ffe..c2cbe4f 100644 +--- a/arch/alpha/include/asm/atomic.h ++++ b/arch/alpha/include/asm/atomic.h +@@ -14,8 +14,8 @@ + */ + + +-#define ATOMIC_INIT(i) ( (atomic_t) { (i) } ) +-#define ATOMIC64_INIT(i) ( (atomic64_t) { (i) } ) ++#define ATOMIC_INIT(i) { (i) } ++#define ATOMIC64_INIT(i) { (i) } + + #define atomic_read(v) (*(volatile int *)&(v)->counter) + #define atomic64_read(v) (*(volatile long *)&(v)->counter) +diff --git a/arch/alpha/include/asm/fpu.h b/arch/alpha/include/asm/fpu.h +index db00f78..e477bcd 100644 +--- a/arch/alpha/include/asm/fpu.h ++++ b/arch/alpha/include/asm/fpu.h +@@ -1,7 +1,9 @@ + #ifndef __ASM_ALPHA_FPU_H + #define __ASM_ALPHA_FPU_H + ++#ifdef __KERNEL__ + #include ++#endif + + /* + * Alpha floating-point control register defines: +diff --git a/arch/alpha/include/asm/socket.h b/arch/alpha/include/asm/socket.h +index dcb221a..7d2f75b 100644 +--- a/arch/alpha/include/asm/socket.h ++++ b/arch/alpha/include/asm/socket.h +@@ -76,9 +76,11 @@ + /* Instruct lower device to use last 4-bytes of skb data as FCS */ + #define SO_NOFCS 43 + ++#ifdef __KERNEL__ + /* O_NONBLOCK clashes with the bits used for socket types. Therefore we + * have to define SOCK_NONBLOCK to a different value here. + */ + #define SOCK_NONBLOCK 0x40000000 ++#endif /* __KERNEL__ */ + + #endif /* _ASM_SOCKET_H */ +diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c +index 153d3fc..668d4c7 100644 +--- a/arch/alpha/kernel/process.c ++++ b/arch/alpha/kernel/process.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -54,8 +55,10 @@ cpu_idle(void) + /* FIXME -- EV6 and LCA45 know how to power down + the CPU. */ + ++ rcu_idle_enter(); + while (!need_resched()) + cpu_relax(); ++ rcu_idle_exit(); + schedule(); + } + } +diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig +index c4b2a0f..ffb4c4f 100644 +--- a/arch/arm/Kconfig ++++ b/arch/arm/Kconfig +@@ -2092,6 +2092,7 @@ source "drivers/cpufreq/Kconfig" + config CPU_FREQ_IMX + tristate "CPUfreq driver for i.MX CPUs" + depends on ARCH_MXC && CPU_FREQ ++ select CPU_FREQ_TABLE + help + This enables the CPUfreq driver for i.MX CPUs. + +diff --git a/arch/arm/Makefile b/arch/arm/Makefile +index 2e1583d..587f1ae 100644 +--- a/arch/arm/Makefile ++++ b/arch/arm/Makefile +@@ -278,10 +278,10 @@ zImage Image xipImage bootpImage uImage: vmlinux + zinstall uinstall install: vmlinux + $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $@ + +-%.dtb: ++%.dtb: scripts + $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ + +-dtbs: ++dtbs: scripts + $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ + + # We use MRPROPER_FILES and CLEAN_FILES now +diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S +index b8c64b8..bc67cbf 100644 +--- a/arch/arm/boot/compressed/head.S ++++ b/arch/arm/boot/compressed/head.S +@@ -653,16 +653,21 @@ __armv7_mmu_cache_on: + mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs + #endif + mrc p15, 0, r0, c1, c0, 0 @ read control reg ++ bic r0, r0, #1 << 28 @ clear SCTLR.TRE + orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement + orr r0, r0, #0x003c @ write buffer + #ifdef CONFIG_MMU + #ifdef CONFIG_CPU_ENDIAN_BE8 + orr r0, r0, #1 << 25 @ big-endian page tables + #endif ++ mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg + orrne r0, r0, #1 @ MMU enabled + movne r1, #0xfffffffd @ domain 0 = client ++ bic r6, r6, #1 << 31 @ 32-bit translation system ++ bic r6, r6, #3 << 0 @ use only ttbr0 + mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer + mcrne p15, 0, r1, c3, c0, 0 @ load domain access control ++ mcrne p15, 0, r6, c2, c0, 2 @ load ttb control + #endif + mcr p15, 0, r0, c7, c5, 4 @ ISB + mcr p15, 0, r0, c1, c0, 0 @ load control register +diff --git a/arch/arm/boot/dts/imx53-ard.dts b/arch/arm/boot/dts/imx53-ard.dts +index 5b8eafc..fa95f4a 100644 +--- a/arch/arm/boot/dts/imx53-ard.dts ++++ b/arch/arm/boot/dts/imx53-ard.dts +@@ -66,10 +66,30 @@ + interrupt-parent = <&gpio2>; + interrupts = <31>; + reg-io-width = <4>; ++ /* ++ * VDD33A and VDDVARIO of LAN9220 are supplied by ++ * SW4_3V3 of LTC3589. Before the regulator driver ++ * for this PMIC is available, we use a fixed dummy ++ * 3V3 regulator to get LAN9220 driver probing work. ++ */ ++ vdd33a-supply = <®_3p3v>; ++ vddvario-supply = <®_3p3v>; + smsc,irq-push-pull; + }; + }; + ++ regulators { ++ compatible = "simple-bus"; ++ ++ reg_3p3v: 3p3v { ++ compatible = "regulator-fixed"; ++ regulator-name = "3P3V"; ++ regulator-min-microvolt = <3300000>; ++ regulator-max-microvolt = <3300000>; ++ regulator-always-on; ++ }; ++ }; ++ + gpio-keys { + compatible = "gpio-keys"; + +diff --git a/arch/arm/boot/dts/tegra-trimslice.dts b/arch/arm/boot/dts/tegra-trimslice.dts +index 9de5636..27fb8a6 100644 +--- a/arch/arm/boot/dts/tegra-trimslice.dts ++++ b/arch/arm/boot/dts/tegra-trimslice.dts +@@ -276,9 +276,11 @@ + + usb@c5000000 { + status = "okay"; ++ nvidia,vbus-gpio = <&gpio 170 0>; /* gpio PV2 */ + }; + + usb@c5004000 { ++ status = "okay"; + nvidia,phy-reset-gpio = <&gpio 168 0>; /* gpio PV0 */ + }; + +diff --git a/arch/arm/configs/mxs_defconfig b/arch/arm/configs/mxs_defconfig +index 5406c23..82f42df 100644 +--- a/arch/arm/configs/mxs_defconfig ++++ b/arch/arm/configs/mxs_defconfig +@@ -33,7 +33,6 @@ CONFIG_NO_HZ=y + CONFIG_HIGH_RES_TIMERS=y + CONFIG_PREEMPT_VOLUNTARY=y + CONFIG_AEABI=y +-CONFIG_DEFAULT_MMAP_MIN_ADDR=65536 + CONFIG_AUTO_ZRELADDR=y + CONFIG_FPE_NWFPE=y + CONFIG_NET=y +diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h +index 03fb936..5c8b3bf4 100644 +--- a/arch/arm/include/asm/assembler.h ++++ b/arch/arm/include/asm/assembler.h +@@ -320,4 +320,12 @@ + .size \name , . - \name + .endm + ++ .macro check_uaccess, addr:req, size:req, limit:req, tmp:req, bad:req ++#ifndef CONFIG_CPU_USE_DOMAINS ++ adds \tmp, \addr, #\size - 1 ++ sbcccs \tmp, \tmp, \limit ++ bcs \bad ++#endif ++ .endm ++ + #endif /* __ASM_ASSEMBLER_H__ */ +diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h +index 004c1bc..e4448e1 100644 +--- a/arch/arm/include/asm/cacheflush.h ++++ b/arch/arm/include/asm/cacheflush.h +@@ -215,7 +215,9 @@ static inline void vivt_flush_cache_mm(struct mm_struct *mm) + static inline void + vivt_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end) + { +- if (cpumask_test_cpu(smp_processor_id(), mm_cpumask(vma->vm_mm))) ++ struct mm_struct *mm = vma->vm_mm; ++ ++ if (!mm || cpumask_test_cpu(smp_processor_id(), mm_cpumask(mm))) + __cpuc_flush_user_range(start & PAGE_MASK, PAGE_ALIGN(end), + vma->vm_flags); + } +@@ -223,7 +225,9 @@ vivt_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned + static inline void + vivt_flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn) + { +- if (cpumask_test_cpu(smp_processor_id(), mm_cpumask(vma->vm_mm))) { ++ struct mm_struct *mm = vma->vm_mm; ++ ++ if (!mm || cpumask_test_cpu(smp_processor_id(), mm_cpumask(mm))) { + unsigned long addr = user_addr & PAGE_MASK; + __cpuc_flush_user_range(addr, addr + PAGE_SIZE, vma->vm_flags); + } +diff --git a/arch/arm/include/asm/mutex.h b/arch/arm/include/asm/mutex.h +index bcbca2c..24327e9 100644 +--- a/arch/arm/include/asm/mutex.h ++++ b/arch/arm/include/asm/mutex.h +@@ -7,121 +7,5 @@ + */ + #ifndef _ASM_MUTEX_H + #define _ASM_MUTEX_H +- +-#if __LINUX_ARM_ARCH__ < 6 || defined(CONFIG_CPU_DCACHE_DISABLE) +-/* On pre-ARMv6 hardware the swp based implementation is the most efficient. */ +-# include +-#else +- +-/* +- * Attempting to lock a mutex on ARMv6+ can be done with a bastardized +- * atomic decrement (it is not a reliable atomic decrement but it satisfies +- * the defined semantics for our purpose, while being smaller and faster +- * than a real atomic decrement or atomic swap. The idea is to attempt +- * decrementing the lock value only once. If once decremented it isn't zero, +- * or if its store-back fails due to a dispute on the exclusive store, we +- * simply bail out immediately through the slow path where the lock will be +- * reattempted until it succeeds. +- */ +-static inline void +-__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *)) +-{ +- int __ex_flag, __res; +- +- __asm__ ( +- +- "ldrex %0, [%2] \n\t" +- "sub %0, %0, #1 \n\t" +- "strex %1, %0, [%2] " +- +- : "=&r" (__res), "=&r" (__ex_flag) +- : "r" (&(count)->counter) +- : "cc","memory" ); +- +- __res |= __ex_flag; +- if (unlikely(__res != 0)) +- fail_fn(count); +-} +- +-static inline int +-__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) +-{ +- int __ex_flag, __res; +- +- __asm__ ( +- +- "ldrex %0, [%2] \n\t" +- "sub %0, %0, #1 \n\t" +- "strex %1, %0, [%2] " +- +- : "=&r" (__res), "=&r" (__ex_flag) +- : "r" (&(count)->counter) +- : "cc","memory" ); +- +- __res |= __ex_flag; +- if (unlikely(__res != 0)) +- __res = fail_fn(count); +- return __res; +-} +- +-/* +- * Same trick is used for the unlock fast path. However the original value, +- * rather than the result, is used to test for success in order to have +- * better generated assembly. +- */ +-static inline void +-__mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *)) +-{ +- int __ex_flag, __res, __orig; +- +- __asm__ ( +- +- "ldrex %0, [%3] \n\t" +- "add %1, %0, #1 \n\t" +- "strex %2, %1, [%3] " +- +- : "=&r" (__orig), "=&r" (__res), "=&r" (__ex_flag) +- : "r" (&(count)->counter) +- : "cc","memory" ); +- +- __orig |= __ex_flag; +- if (unlikely(__orig != 0)) +- fail_fn(count); +-} +- +-/* +- * If the unlock was done on a contended lock, or if the unlock simply fails +- * then the mutex remains locked. +- */ +-#define __mutex_slowpath_needs_to_unlock() 1 +- +-/* +- * For __mutex_fastpath_trylock we use another construct which could be +- * described as a "single value cmpxchg". +- * +- * This provides the needed trylock semantics like cmpxchg would, but it is +- * lighter and less generic than a true cmpxchg implementation. +- */ +-static inline int +-__mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *)) +-{ +- int __ex_flag, __res, __orig; +- +- __asm__ ( +- +- "1: ldrex %0, [%3] \n\t" +- "subs %1, %0, #1 \n\t" +- "strexeq %2, %1, [%3] \n\t" +- "movlt %0, #0 \n\t" +- "cmpeq %2, #0 \n\t" +- "bgt 1b " +- +- : "=&r" (__orig), "=&r" (__res), "=&r" (__ex_flag) +- : "r" (&count->counter) +- : "cc", "memory" ); +- +- return __orig; +-} +- +-#endif ++#include + #endif +diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h +index f66626d..41dc31f 100644 +--- a/arch/arm/include/asm/pgtable.h ++++ b/arch/arm/include/asm/pgtable.h +@@ -195,6 +195,18 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd) + + #define pte_clear(mm,addr,ptep) set_pte_ext(ptep, __pte(0), 0) + ++#define pte_none(pte) (!pte_val(pte)) ++#define pte_present(pte) (pte_val(pte) & L_PTE_PRESENT) ++#define pte_write(pte) (!(pte_val(pte) & L_PTE_RDONLY)) ++#define pte_dirty(pte) (pte_val(pte) & L_PTE_DIRTY) ++#define pte_young(pte) (pte_val(pte) & L_PTE_YOUNG) ++#define pte_exec(pte) (!(pte_val(pte) & L_PTE_XN)) ++#define pte_special(pte) (0) ++ ++#define pte_present_user(pte) \ ++ ((pte_val(pte) & (L_PTE_PRESENT | L_PTE_USER)) == \ ++ (L_PTE_PRESENT | L_PTE_USER)) ++ + #if __LINUX_ARM_ARCH__ < 6 + static inline void __sync_icache_dcache(pte_t pteval) + { +@@ -206,25 +218,15 @@ extern void __sync_icache_dcache(pte_t pteval); + static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pteval) + { +- if (addr >= TASK_SIZE) +- set_pte_ext(ptep, pteval, 0); +- else { ++ unsigned long ext = 0; ++ ++ if (addr < TASK_SIZE && pte_present_user(pteval)) { + __sync_icache_dcache(pteval); +- set_pte_ext(ptep, pteval, PTE_EXT_NG); ++ ext |= PTE_EXT_NG; + } +-} + +-#define pte_none(pte) (!pte_val(pte)) +-#define pte_present(pte) (pte_val(pte) & L_PTE_PRESENT) +-#define pte_write(pte) (!(pte_val(pte) & L_PTE_RDONLY)) +-#define pte_dirty(pte) (pte_val(pte) & L_PTE_DIRTY) +-#define pte_young(pte) (pte_val(pte) & L_PTE_YOUNG) +-#define pte_exec(pte) (!(pte_val(pte) & L_PTE_XN)) +-#define pte_special(pte) (0) +- +-#define pte_present_user(pte) \ +- ((pte_val(pte) & (L_PTE_PRESENT | L_PTE_USER)) == \ +- (L_PTE_PRESENT | L_PTE_USER)) ++ set_pte_ext(ptep, pteval, ext); ++} + + #define PTE_BIT_FUNC(fn,op) \ + static inline pte_t pte_##fn(pte_t pte) { pte_val(pte) op; return pte; } +@@ -251,13 +253,13 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) + * + * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 +- * <--------------- offset --------------------> <- type --> 0 0 0 ++ * <--------------- offset ----------------------> < type -> 0 0 0 + * +- * This gives us up to 63 swap files and 32GB per swap file. Note that ++ * This gives us up to 31 swap files and 64GB per swap file. Note that + * the offset field is always non-zero. + */ + #define __SWP_TYPE_SHIFT 3 +-#define __SWP_TYPE_BITS 6 ++#define __SWP_TYPE_BITS 5 + #define __SWP_TYPE_MASK ((1 << __SWP_TYPE_BITS) - 1) + #define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) + +diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h +index c334a23..fce38a6 100644 +--- a/arch/arm/include/asm/syscall.h ++++ b/arch/arm/include/asm/syscall.h +@@ -8,6 +8,7 @@ + #define _ASM_ARM_SYSCALL_H + + #include ++#include + + extern const unsigned long sys_call_table[]; + +diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h +index 71f6536..0a070e9 100644 +--- a/arch/arm/include/asm/uaccess.h ++++ b/arch/arm/include/asm/uaccess.h +@@ -101,28 +101,39 @@ extern int __get_user_1(void *); + extern int __get_user_2(void *); + extern int __get_user_4(void *); + +-#define __get_user_x(__r2,__p,__e,__s,__i...) \ ++#define __GUP_CLOBBER_1 "lr", "cc" ++#ifdef CONFIG_CPU_USE_DOMAINS ++#define __GUP_CLOBBER_2 "ip", "lr", "cc" ++#else ++#define __GUP_CLOBBER_2 "lr", "cc" ++#endif ++#define __GUP_CLOBBER_4 "lr", "cc" ++ ++#define __get_user_x(__r2,__p,__e,__l,__s) \ + __asm__ __volatile__ ( \ + __asmeq("%0", "r0") __asmeq("%1", "r2") \ ++ __asmeq("%3", "r1") \ + "bl __get_user_" #__s \ + : "=&r" (__e), "=r" (__r2) \ +- : "0" (__p) \ +- : __i, "cc") ++ : "0" (__p), "r" (__l) \ ++ : __GUP_CLOBBER_##__s) + + #define get_user(x,p) \ + ({ \ ++ unsigned long __limit = current_thread_info()->addr_limit - 1; \ + register const typeof(*(p)) __user *__p asm("r0") = (p);\ + register unsigned long __r2 asm("r2"); \ ++ register unsigned long __l asm("r1") = __limit; \ + register int __e asm("r0"); \ + switch (sizeof(*(__p))) { \ + case 1: \ +- __get_user_x(__r2, __p, __e, 1, "lr"); \ +- break; \ ++ __get_user_x(__r2, __p, __e, __l, 1); \ ++ break; \ + case 2: \ +- __get_user_x(__r2, __p, __e, 2, "r3", "lr"); \ ++ __get_user_x(__r2, __p, __e, __l, 2); \ + break; \ + case 4: \ +- __get_user_x(__r2, __p, __e, 4, "lr"); \ ++ __get_user_x(__r2, __p, __e, __l, 4); \ + break; \ + default: __e = __get_user_bad(); break; \ + } \ +@@ -135,31 +146,34 @@ extern int __put_user_2(void *, unsigned int); + extern int __put_user_4(void *, unsigned int); + extern int __put_user_8(void *, unsigned long long); + +-#define __put_user_x(__r2,__p,__e,__s) \ ++#define __put_user_x(__r2,__p,__e,__l,__s) \ + __asm__ __volatile__ ( \ + __asmeq("%0", "r0") __asmeq("%2", "r2") \ ++ __asmeq("%3", "r1") \ + "bl __put_user_" #__s \ + : "=&r" (__e) \ +- : "0" (__p), "r" (__r2) \ ++ : "0" (__p), "r" (__r2), "r" (__l) \ + : "ip", "lr", "cc") + + #define put_user(x,p) \ + ({ \ ++ unsigned long __limit = current_thread_info()->addr_limit - 1; \ + register const typeof(*(p)) __r2 asm("r2") = (x); \ + register const typeof(*(p)) __user *__p asm("r0") = (p);\ ++ register unsigned long __l asm("r1") = __limit; \ + register int __e asm("r0"); \ + switch (sizeof(*(__p))) { \ + case 1: \ +- __put_user_x(__r2, __p, __e, 1); \ ++ __put_user_x(__r2, __p, __e, __l, 1); \ + break; \ + case 2: \ +- __put_user_x(__r2, __p, __e, 2); \ ++ __put_user_x(__r2, __p, __e, __l, 2); \ + break; \ + case 4: \ +- __put_user_x(__r2, __p, __e, 4); \ ++ __put_user_x(__r2, __p, __e, __l, 4); \ + break; \ + case 8: \ +- __put_user_x(__r2, __p, __e, 8); \ ++ __put_user_x(__r2, __p, __e, __l, 8); \ + break; \ + default: __e = __put_user_bad(); break; \ + } \ +diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S +index 60d53f4..442763d 100644 +--- a/arch/arm/kernel/entry-armv.S ++++ b/arch/arm/kernel/entry-armv.S +@@ -244,6 +244,19 @@ svc_preempt: + b 1b + #endif + ++__und_fault: ++ @ Correct the PC such that it is pointing at the instruction ++ @ which caused the fault. If the faulting instruction was ARM ++ @ the PC will be pointing at the next instruction, and have to ++ @ subtract 4. Otherwise, it is Thumb, and the PC will be ++ @ pointing at the second half of the Thumb instruction. We ++ @ have to subtract 2. ++ ldr r2, [r0, #S_PC] ++ sub r2, r2, r1 ++ str r2, [r0, #S_PC] ++ b do_undefinstr ++ENDPROC(__und_fault) ++ + .align 5 + __und_svc: + #ifdef CONFIG_KPROBES +@@ -261,25 +274,32 @@ __und_svc: + @ + @ r0 - instruction + @ +-#ifndef CONFIG_THUMB2_KERNEL ++#ifndef CONFIG_THUMB2_KERNEL + ldr r0, [r4, #-4] + #else ++ mov r1, #2 + ldrh r0, [r4, #-2] @ Thumb instruction at LR - 2 + cmp r0, #0xe800 @ 32-bit instruction if xx >= 0 +- ldrhhs r9, [r4] @ bottom 16 bits +- orrhs r0, r9, r0, lsl #16 ++ blo __und_svc_fault ++ ldrh r9, [r4] @ bottom 16 bits ++ add r4, r4, #2 ++ str r4, [sp, #S_PC] ++ orr r0, r9, r0, lsl #16 + #endif +- adr r9, BSYM(1f) ++ adr r9, BSYM(__und_svc_finish) + mov r2, r4 + bl call_fpe + ++ mov r1, #4 @ PC correction to apply ++__und_svc_fault: + mov r0, sp @ struct pt_regs *regs +- bl do_undefinstr ++ bl __und_fault + + @ + @ IRQs off again before pulling preserved data off the stack + @ +-1: disable_irq_notrace ++__und_svc_finish: ++ disable_irq_notrace + + @ + @ restore SPSR and restart the instruction +@@ -423,25 +443,33 @@ __und_usr: + mov r2, r4 + mov r3, r5 + ++ @ r2 = regs->ARM_pc, which is either 2 or 4 bytes ahead of the ++ @ faulting instruction depending on Thumb mode. ++ @ r3 = regs->ARM_cpsr + @ +- @ fall through to the emulation code, which returns using r9 if +- @ it has emulated the instruction, or the more conventional lr +- @ if we are to treat this as a real undefined instruction +- @ +- @ r0 - instruction ++ @ The emulation code returns using r9 if it has emulated the ++ @ instruction, or the more conventional lr if we are to treat ++ @ this as a real undefined instruction + @ + adr r9, BSYM(ret_from_exception) +- adr lr, BSYM(__und_usr_unknown) ++ + tst r3, #PSR_T_BIT @ Thumb mode? +- itet eq @ explicit IT needed for the 1f label +- subeq r4, r2, #4 @ ARM instr at LR - 4 +- subne r4, r2, #2 @ Thumb instr at LR - 2 +-1: ldreqt r0, [r4] ++ bne __und_usr_thumb ++ sub r4, r2, #4 @ ARM instr at LR - 4 ++1: ldrt r0, [r4] + #ifdef CONFIG_CPU_ENDIAN_BE8 +- reveq r0, r0 @ little endian instruction ++ rev r0, r0 @ little endian instruction + #endif +- beq call_fpe ++ @ r0 = 32-bit ARM instruction which caused the exception ++ @ r2 = PC value for the following instruction (:= regs->ARM_pc) ++ @ r4 = PC value for the faulting instruction ++ @ lr = 32-bit undefined instruction function ++ adr lr, BSYM(__und_usr_fault_32) ++ b call_fpe ++ ++__und_usr_thumb: + @ Thumb instruction ++ sub r4, r2, #2 @ First half of thumb instr at LR - 2 + #if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7 + /* + * Thumb-2 instruction handling. Note that because pre-v6 and >= v6 platforms +@@ -455,7 +483,7 @@ __und_usr: + ldr r5, .LCcpu_architecture + ldr r5, [r5] + cmp r5, #CPU_ARCH_ARMv7 +- blo __und_usr_unknown ++ blo __und_usr_fault_16 @ 16bit undefined instruction + /* + * The following code won't get run unless the running CPU really is v7, so + * coding round the lack of ldrht on older arches is pointless. Temporarily +@@ -463,15 +491,18 @@ __und_usr: + */ + .arch armv6t2 + #endif +-2: +- ARM( ldrht r5, [r4], #2 ) +- THUMB( ldrht r5, [r4] ) +- THUMB( add r4, r4, #2 ) ++2: ldrht r5, [r4] + cmp r5, #0xe800 @ 32bit instruction if xx != 0 +- blo __und_usr_unknown +-3: ldrht r0, [r4] ++ blo __und_usr_fault_16 @ 16bit undefined instruction ++3: ldrht r0, [r2] + add r2, r2, #2 @ r2 is PC + 2, make it PC + 4 ++ str r2, [sp, #S_PC] @ it's a 2x16bit instr, update + orr r0, r0, r5, lsl #16 ++ adr lr, BSYM(__und_usr_fault_32) ++ @ r0 = the two 16-bit Thumb instructions which caused the exception ++ @ r2 = PC value for the following Thumb instruction (:= regs->ARM_pc) ++ @ r4 = PC value for the first 16-bit Thumb instruction ++ @ lr = 32bit undefined instruction function + + #if __LINUX_ARM_ARCH__ < 7 + /* If the target arch was overridden, change it back: */ +@@ -482,17 +513,13 @@ __und_usr: + #endif + #endif /* __LINUX_ARM_ARCH__ < 7 */ + #else /* !(CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7) */ +- b __und_usr_unknown ++ b __und_usr_fault_16 + #endif +- UNWIND(.fnend ) ++ UNWIND(.fnend) + ENDPROC(__und_usr) + +- @ +- @ fallthrough to call_fpe +- @ +- + /* +- * The out of line fixup for the ldrt above. ++ * The out of line fixup for the ldrt instructions above. + */ + .pushsection .fixup, "ax" + .align 2 +@@ -524,11 +551,12 @@ ENDPROC(__und_usr) + * NEON handler code. + * + * Emulators may wish to make use of the following registers: +- * r0 = instruction opcode. +- * r2 = PC+4 ++ * r0 = instruction opcode (32-bit ARM or two 16-bit Thumb) ++ * r2 = PC value to resume execution after successful emulation + * r9 = normal "successful" return address +- * r10 = this threads thread_info structure. ++ * r10 = this threads thread_info structure + * lr = unrecognised instruction return address ++ * IRQs disabled, FIQs enabled. + */ + @ + @ Fall-through from Thumb-2 __und_usr +@@ -659,12 +687,17 @@ ENTRY(no_fp) + mov pc, lr + ENDPROC(no_fp) + +-__und_usr_unknown: +- enable_irq ++__und_usr_fault_32: ++ mov r1, #4 ++ b 1f ++__und_usr_fault_16: ++ mov r1, #2 ++1: enable_irq + mov r0, sp + adr lr, BSYM(ret_from_exception) +- b do_undefinstr +-ENDPROC(__und_usr_unknown) ++ b __und_fault ++ENDPROC(__und_usr_fault_32) ++ENDPROC(__und_usr_fault_16) + + .align 5 + __pabt_usr: +diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c +index ba386bd..18d39ea 100644 +--- a/arch/arm/kernel/hw_breakpoint.c ++++ b/arch/arm/kernel/hw_breakpoint.c +@@ -159,6 +159,12 @@ static int debug_arch_supported(void) + arch >= ARM_DEBUG_ARCH_V7_1; + } + ++/* Can we determine the watchpoint access type from the fsr? */ ++static int debug_exception_updates_fsr(void) ++{ ++ return 0; ++} ++ + /* Determine number of WRP registers available. */ + static int get_num_wrp_resources(void) + { +@@ -619,18 +625,35 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp) + info->address &= ~alignment_mask; + info->ctrl.len <<= offset; + +- /* +- * Currently we rely on an overflow handler to take +- * care of single-stepping the breakpoint when it fires. +- * In the case of userspace breakpoints on a core with V7 debug, +- * we can use the mismatch feature as a poor-man's hardware +- * single-step, but this only works for per-task breakpoints. +- */ +- if (!bp->overflow_handler && (arch_check_bp_in_kernelspace(bp) || +- !core_has_mismatch_brps() || !bp->hw.bp_target)) { +- pr_warning("overflow handler required but none found\n"); +- ret = -EINVAL; ++ if (!bp->overflow_handler) { ++ /* ++ * Mismatch breakpoints are required for single-stepping ++ * breakpoints. ++ */ ++ if (!core_has_mismatch_brps()) ++ return -EINVAL; ++ ++ /* We don't allow mismatch breakpoints in kernel space. */ ++ if (arch_check_bp_in_kernelspace(bp)) ++ return -EPERM; ++ ++ /* ++ * Per-cpu breakpoints are not supported by our stepping ++ * mechanism. ++ */ ++ if (!bp->hw.bp_target) ++ return -EINVAL; ++ ++ /* ++ * We only support specific access types if the fsr ++ * reports them. ++ */ ++ if (!debug_exception_updates_fsr() && ++ (info->ctrl.type == ARM_BREAKPOINT_LOAD || ++ info->ctrl.type == ARM_BREAKPOINT_STORE)) ++ return -EINVAL; + } ++ + out: + return ret; + } +@@ -706,10 +729,12 @@ static void watchpoint_handler(unsigned long addr, unsigned int fsr, + goto unlock; + + /* Check that the access type matches. */ +- access = (fsr & ARM_FSR_ACCESS_MASK) ? HW_BREAKPOINT_W : +- HW_BREAKPOINT_R; +- if (!(access & hw_breakpoint_type(wp))) +- goto unlock; ++ if (debug_exception_updates_fsr()) { ++ access = (fsr & ARM_FSR_ACCESS_MASK) ? ++ HW_BREAKPOINT_W : HW_BREAKPOINT_R; ++ if (!(access & hw_breakpoint_type(wp))) ++ goto unlock; ++ } + + /* We have a winner. */ + info->trigger = addr; +diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c +index 19c95ea6..693b744 100644 +--- a/arch/arm/kernel/process.c ++++ b/arch/arm/kernel/process.c +@@ -247,6 +247,7 @@ void machine_shutdown(void) + void machine_halt(void) + { + machine_shutdown(); ++ local_irq_disable(); + while (1); + } + +@@ -268,6 +269,7 @@ void machine_restart(char *cmd) + + /* Whoops - the platform was unable to reboot. Tell the user! */ + printk("Reboot failed -- System halted\n"); ++ local_irq_disable(); + while (1); + } + +diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c +index 5121f8a..ea73045 100644 +--- a/arch/arm/kernel/smp.c ++++ b/arch/arm/kernel/smp.c +@@ -223,9 +223,6 @@ asmlinkage void __cpuinit secondary_start_kernel(void) + { + struct mm_struct *mm = &init_mm; + unsigned int cpu = smp_processor_id(); +-#ifdef CONFIG_ARCH_ZYNQ +- static bool booted; +-#endif + + /* + * All kernel threads share the same mm context; grab a +@@ -251,13 +248,7 @@ asmlinkage void __cpuinit secondary_start_kernel(void) + + notify_cpu_starting(cpu); + +-#ifdef CONFIG_ARCH_ZYNQ +- if (!booted) +- calibrate_delay(); +- booted = true; +-#else + calibrate_delay(); +-#endif + + smp_store_cpu_info(cpu); + +@@ -572,7 +563,8 @@ void smp_send_stop(void) + + cpumask_copy(&mask, cpu_online_mask); + cpumask_clear_cpu(smp_processor_id(), &mask); +- smp_cross_call(&mask, IPI_CPU_STOP); ++ if (!cpumask_empty(&mask)) ++ smp_cross_call(&mask, IPI_CPU_STOP); + + /* Wait up to one second for other CPUs to stop */ + timeout = USEC_PER_SEC; +diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c +index 3647170..eeb7520 100644 +--- a/arch/arm/kernel/traps.c ++++ b/arch/arm/kernel/traps.c +@@ -370,18 +370,10 @@ static int call_undef_hook(struct pt_regs *regs, unsigned int instr) + + asmlinkage void __exception do_undefinstr(struct pt_regs *regs) + { +- unsigned int correction = thumb_mode(regs) ? 2 : 4; + unsigned int instr; + siginfo_t info; + void __user *pc; + +- /* +- * According to the ARM ARM, PC is 2 or 4 bytes ahead, +- * depending whether we're in Thumb mode or not. +- * Correct this offset. +- */ +- regs->ARM_pc -= correction; +- + pc = (void __user *)instruction_pointer(regs); + + if (processor_mode(regs) == SVC_MODE) { +@@ -396,20 +388,23 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs) + #endif + instr = *(u32 *) pc; + } else if (thumb_mode(regs)) { +- get_user(instr, (u16 __user *)pc); ++ if (get_user(instr, (u16 __user *)pc)) ++ goto die_sig; + if (is_wide_instruction(instr)) { + unsigned int instr2; +- get_user(instr2, (u16 __user *)pc+1); ++ if (get_user(instr2, (u16 __user *)pc+1)) ++ goto die_sig; + instr <<= 16; + instr |= instr2; + } +- } else { +- get_user(instr, (u32 __user *)pc); ++ } else if (get_user(instr, (u32 __user *)pc)) { ++ goto die_sig; + } + + if (call_undef_hook(regs, instr) == 0) + return; + ++die_sig: + #ifdef CONFIG_DEBUG_USER + if (user_debug & UDBG_UNDEFINED) { + printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n", +diff --git a/arch/arm/lib/getuser.S b/arch/arm/lib/getuser.S +index 11093a7..9b06bb4 100644 +--- a/arch/arm/lib/getuser.S ++++ b/arch/arm/lib/getuser.S +@@ -16,8 +16,9 @@ + * __get_user_X + * + * Inputs: r0 contains the address ++ * r1 contains the address limit, which must be preserved + * Outputs: r0 is the error code +- * r2, r3 contains the zero-extended value ++ * r2 contains the zero-extended value + * lr corrupted + * + * No other registers must be altered. (see +@@ -27,33 +28,39 @@ + * Note also that it is intended that __get_user_bad is not global. + */ + #include ++#include + #include + #include + + ENTRY(__get_user_1) ++ check_uaccess r0, 1, r1, r2, __get_user_bad + 1: TUSER(ldrb) r2, [r0] + mov r0, #0 + mov pc, lr + ENDPROC(__get_user_1) + + ENTRY(__get_user_2) +-#ifdef CONFIG_THUMB2_KERNEL +-2: TUSER(ldrb) r2, [r0] +-3: TUSER(ldrb) r3, [r0, #1] ++ check_uaccess r0, 2, r1, r2, __get_user_bad ++#ifdef CONFIG_CPU_USE_DOMAINS ++rb .req ip ++2: ldrbt r2, [r0], #1 ++3: ldrbt rb, [r0], #0 + #else +-2: TUSER(ldrb) r2, [r0], #1 +-3: TUSER(ldrb) r3, [r0] ++rb .req r0 ++2: ldrb r2, [r0] ++3: ldrb rb, [r0, #1] + #endif + #ifndef __ARMEB__ +- orr r2, r2, r3, lsl #8 ++ orr r2, r2, rb, lsl #8 + #else +- orr r2, r3, r2, lsl #8 ++ orr r2, rb, r2, lsl #8 + #endif + mov r0, #0 + mov pc, lr + ENDPROC(__get_user_2) + + ENTRY(__get_user_4) ++ check_uaccess r0, 4, r1, r2, __get_user_bad + 4: TUSER(ldr) r2, [r0] + mov r0, #0 + mov pc, lr +diff --git a/arch/arm/lib/putuser.S b/arch/arm/lib/putuser.S +index 7db2599..3d73dcb 100644 +--- a/arch/arm/lib/putuser.S ++++ b/arch/arm/lib/putuser.S +@@ -16,6 +16,7 @@ + * __put_user_X + * + * Inputs: r0 contains the address ++ * r1 contains the address limit, which must be preserved + * r2, r3 contains the value + * Outputs: r0 is the error code + * lr corrupted +@@ -27,16 +28,19 @@ + * Note also that it is intended that __put_user_bad is not global. + */ + #include ++#include + #include + #include + + ENTRY(__put_user_1) ++ check_uaccess r0, 1, r1, ip, __put_user_bad + 1: TUSER(strb) r2, [r0] + mov r0, #0 + mov pc, lr + ENDPROC(__put_user_1) + + ENTRY(__put_user_2) ++ check_uaccess r0, 2, r1, ip, __put_user_bad + mov ip, r2, lsr #8 + #ifdef CONFIG_THUMB2_KERNEL + #ifndef __ARMEB__ +@@ -60,12 +64,14 @@ ENTRY(__put_user_2) + ENDPROC(__put_user_2) + + ENTRY(__put_user_4) ++ check_uaccess r0, 4, r1, ip, __put_user_bad + 4: TUSER(str) r2, [r0] + mov r0, #0 + mov pc, lr + ENDPROC(__put_user_4) + + ENTRY(__put_user_8) ++ check_uaccess r0, 8, r1, ip, __put_user_bad + #ifdef CONFIG_THUMB2_KERNEL + 5: TUSER(str) r2, [r0] + 6: TUSER(str) r3, [r0, #4] +diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile +index ff29421..d272b00 100644 +--- a/arch/arm/mach-imx/Makefile ++++ b/arch/arm/mach-imx/Makefile +@@ -9,7 +9,8 @@ obj-$(CONFIG_SOC_IMX27) += clk-imx27.o mm-imx27.o ehci-imx27.o + obj-$(CONFIG_SOC_IMX31) += mm-imx3.o cpu-imx31.o clk-imx31.o iomux-imx31.o ehci-imx31.o pm-imx3.o + obj-$(CONFIG_SOC_IMX35) += mm-imx3.o cpu-imx35.o clk-imx35.o ehci-imx35.o pm-imx3.o + +-obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o mm-imx5.o clk-imx51-imx53.o ehci-imx5.o pm-imx5.o cpu_op-mx51.o ++imx5-pm-$(CONFIG_PM) += pm-imx5.o ++obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o mm-imx5.o clk-imx51-imx53.o ehci-imx5.o $(imx5-pm-y) cpu_op-mx51.o + + obj-$(CONFIG_COMMON_CLK) += clk-pllv1.o clk-pllv2.o clk-pllv3.o clk-gate2.o \ + clk-pfd.o clk-busy.o +@@ -69,14 +70,13 @@ obj-$(CONFIG_DEBUG_LL) += lluart.o + obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o + obj-$(CONFIG_HAVE_IMX_MMDC) += mmdc.o + obj-$(CONFIG_HAVE_IMX_SRC) += src.o +-obj-$(CONFIG_CPU_V7) += head-v7.o +-AFLAGS_head-v7.o :=-Wa,-march=armv7-a +-obj-$(CONFIG_SMP) += platsmp.o ++AFLAGS_headsmp.o :=-Wa,-march=armv7-a ++obj-$(CONFIG_SMP) += headsmp.o platsmp.o + obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o + obj-$(CONFIG_SOC_IMX6Q) += clk-imx6q.o mach-imx6q.o + + ifeq ($(CONFIG_PM),y) +-obj-$(CONFIG_SOC_IMX6Q) += pm-imx6q.o ++obj-$(CONFIG_SOC_IMX6Q) += pm-imx6q.o headsmp.o + endif + + # i.MX5 based machines +diff --git a/arch/arm/mach-imx/clk-imx25.c b/arch/arm/mach-imx/clk-imx25.c +index fdd8cc8..4431a62 100644 +--- a/arch/arm/mach-imx/clk-imx25.c ++++ b/arch/arm/mach-imx/clk-imx25.c +@@ -222,10 +222,8 @@ int __init mx25_clocks_init(void) + clk_register_clkdev(clk[lcdc_ipg], "ipg", "imx-fb.0"); + clk_register_clkdev(clk[lcdc_ahb], "ahb", "imx-fb.0"); + clk_register_clkdev(clk[wdt_ipg], NULL, "imx2-wdt.0"); +- clk_register_clkdev(clk[ssi1_ipg_per], "per", "imx-ssi.0"); +- clk_register_clkdev(clk[ssi1_ipg], "ipg", "imx-ssi.0"); +- clk_register_clkdev(clk[ssi2_ipg_per], "per", "imx-ssi.1"); +- clk_register_clkdev(clk[ssi2_ipg], "ipg", "imx-ssi.1"); ++ clk_register_clkdev(clk[ssi1_ipg], NULL, "imx-ssi.0"); ++ clk_register_clkdev(clk[ssi2_ipg], NULL, "imx-ssi.1"); + clk_register_clkdev(clk[esdhc1_ipg_per], "per", "sdhci-esdhc-imx25.0"); + clk_register_clkdev(clk[esdhc1_ipg], "ipg", "sdhci-esdhc-imx25.0"); + clk_register_clkdev(clk[esdhc1_ahb], "ahb", "sdhci-esdhc-imx25.0"); +diff --git a/arch/arm/mach-imx/clk-imx31.c b/arch/arm/mach-imx/clk-imx31.c +index c9a06d8..4bcb3a1 100644 +--- a/arch/arm/mach-imx/clk-imx31.c ++++ b/arch/arm/mach-imx/clk-imx31.c +@@ -129,7 +129,7 @@ int __init mx31_clocks_init(unsigned long fref) + clk_register_clkdev(clk[nfc], NULL, "mxc_nand.0"); + clk_register_clkdev(clk[ipu_gate], NULL, "ipu-core"); + clk_register_clkdev(clk[ipu_gate], NULL, "mx3_sdc_fb"); +- clk_register_clkdev(clk[kpp_gate], "kpp", NULL); ++ clk_register_clkdev(clk[kpp_gate], NULL, "imx-keypad"); + clk_register_clkdev(clk[usb_div_post], "per", "mxc-ehci.0"); + clk_register_clkdev(clk[usb_gate], "ahb", "mxc-ehci.0"); + clk_register_clkdev(clk[ipg], "ipg", "mxc-ehci.0"); +diff --git a/arch/arm/mach-imx/clk-imx35.c b/arch/arm/mach-imx/clk-imx35.c +index c6422fb..65fb8bc 100644 +--- a/arch/arm/mach-imx/clk-imx35.c ++++ b/arch/arm/mach-imx/clk-imx35.c +@@ -230,10 +230,8 @@ int __init mx35_clocks_init() + clk_register_clkdev(clk[ipu_gate], NULL, "mx3_sdc_fb"); + clk_register_clkdev(clk[owire_gate], NULL, "mxc_w1"); + clk_register_clkdev(clk[sdma_gate], NULL, "imx35-sdma"); +- clk_register_clkdev(clk[ipg], "ipg", "imx-ssi.0"); +- clk_register_clkdev(clk[ssi1_div_post], "per", "imx-ssi.0"); +- clk_register_clkdev(clk[ipg], "ipg", "imx-ssi.1"); +- clk_register_clkdev(clk[ssi2_div_post], "per", "imx-ssi.1"); ++ clk_register_clkdev(clk[ssi1_gate], NULL, "imx-ssi.0"); ++ clk_register_clkdev(clk[ssi2_gate], NULL, "imx-ssi.1"); + /* i.mx35 has the i.mx21 type uart */ + clk_register_clkdev(clk[uart1_gate], "per", "imx21-uart.0"); + clk_register_clkdev(clk[ipg], "ipg", "imx21-uart.0"); +diff --git a/arch/arm/mach-imx/clk-imx51-imx53.c b/arch/arm/mach-imx/clk-imx51-imx53.c +index a2200c7..ae3d802 100644 +--- a/arch/arm/mach-imx/clk-imx51-imx53.c ++++ b/arch/arm/mach-imx/clk-imx51-imx53.c +@@ -293,6 +293,7 @@ static void __init mx5_clocks_common_init(unsigned long rate_ckil, + clk_prepare_enable(clk[aips_tz2]); /* fec */ + clk_prepare_enable(clk[spba]); + clk_prepare_enable(clk[emi_fast_gate]); /* fec */ ++ clk_prepare_enable(clk[emi_slow_gate]); /* eim */ + clk_prepare_enable(clk[tmax1]); + clk_prepare_enable(clk[tmax2]); /* esdhc2, fec */ + clk_prepare_enable(clk[tmax3]); /* esdhc1, esdhc4 */ +diff --git a/arch/arm/mach-imx/head-v7.S b/arch/arm/mach-imx/head-v7.S +deleted file mode 100644 +index 7e49deb..0000000 +--- a/arch/arm/mach-imx/head-v7.S ++++ /dev/null +@@ -1,106 +0,0 @@ +-/* +- * Copyright 2011 Freescale Semiconductor, Inc. +- * Copyright 2011 Linaro Ltd. +- * +- * The code contained herein is licensed under the GNU General Public +- * License. You may obtain a copy of the GNU General Public License +- * Version 2 or later at the following locations: +- * +- * http://www.opensource.org/licenses/gpl-license.html +- * http://www.gnu.org/copyleft/gpl.html +- */ +- +-#include +-#include +-#include +-#include +- +- .section ".text.head", "ax" +- +-/* +- * The secondary kernel init calls v7_flush_dcache_all before it enables +- * the L1; however, the L1 comes out of reset in an undefined state, so +- * the clean + invalidate performed by v7_flush_dcache_all causes a bunch +- * of cache lines with uninitialized data and uninitialized tags to get +- * written out to memory, which does really unpleasant things to the main +- * processor. We fix this by performing an invalidate, rather than a +- * clean + invalidate, before jumping into the kernel. +- * +- * This funciton is cloned from arch/arm/mach-tegra/headsmp.S, and needs +- * to be called for both secondary cores startup and primary core resume +- * procedures. Ideally, it should be moved into arch/arm/mm/cache-v7.S. +- */ +-ENTRY(v7_invalidate_l1) +- mov r0, #0 +- mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache +- mcr p15, 2, r0, c0, c0, 0 +- mrc p15, 1, r0, c0, c0, 0 +- +- ldr r1, =0x7fff +- and r2, r1, r0, lsr #13 +- +- ldr r1, =0x3ff +- +- and r3, r1, r0, lsr #3 @ NumWays - 1 +- add r2, r2, #1 @ NumSets +- +- and r0, r0, #0x7 +- add r0, r0, #4 @ SetShift +- +- clz r1, r3 @ WayShift +- add r4, r3, #1 @ NumWays +-1: sub r2, r2, #1 @ NumSets-- +- mov r3, r4 @ Temp = NumWays +-2: subs r3, r3, #1 @ Temp-- +- mov r5, r3, lsl r1 +- mov r6, r2, lsl r0 +- orr r5, r5, r6 @ Reg = (Temp< ++#include ++#include ++#include ++ ++ .section ".text.head", "ax" ++ ++/* ++ * The secondary kernel init calls v7_flush_dcache_all before it enables ++ * the L1; however, the L1 comes out of reset in an undefined state, so ++ * the clean + invalidate performed by v7_flush_dcache_all causes a bunch ++ * of cache lines with uninitialized data and uninitialized tags to get ++ * written out to memory, which does really unpleasant things to the main ++ * processor. We fix this by performing an invalidate, rather than a ++ * clean + invalidate, before jumping into the kernel. ++ * ++ * This funciton is cloned from arch/arm/mach-tegra/headsmp.S, and needs ++ * to be called for both secondary cores startup and primary core resume ++ * procedures. Ideally, it should be moved into arch/arm/mm/cache-v7.S. ++ */ ++ENTRY(v7_invalidate_l1) ++ mov r0, #0 ++ mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache ++ mcr p15, 2, r0, c0, c0, 0 ++ mrc p15, 1, r0, c0, c0, 0 ++ ++ ldr r1, =0x7fff ++ and r2, r1, r0, lsr #13 ++ ++ ldr r1, =0x3ff ++ ++ and r3, r1, r0, lsr #3 @ NumWays - 1 ++ add r2, r2, #1 @ NumSets ++ ++ and r0, r0, #0x7 ++ add r0, r0, #4 @ SetShift ++ ++ clz r1, r3 @ WayShift ++ add r4, r3, #1 @ NumWays ++1: sub r2, r2, #1 @ NumSets-- ++ mov r3, r4 @ Temp = NumWays ++2: subs r3, r3, #1 @ Temp-- ++ mov r5, r3, lsl r1 ++ mov r6, r2, lsl r0 ++ orr r5, r5, r6 @ Reg = (Temp<freq, + opp_def->hwmod_name, i, r); + } +- opp_def++; + } + + return 0; +diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c +index 840929b..2cdbcc76 100644 +--- a/arch/arm/mach-omap2/timer.c ++++ b/arch/arm/mach-omap2/timer.c +@@ -263,6 +263,7 @@ static u32 notrace dmtimer_read_sched_clock(void) + return 0; + } + ++#ifdef CONFIG_OMAP_32K_TIMER + /* Setup free-running counter for clocksource */ + static int __init omap2_sync32k_clocksource_init(void) + { +@@ -302,6 +303,12 @@ static int __init omap2_sync32k_clocksource_init(void) + + return ret; + } ++#else ++static inline int omap2_sync32k_clocksource_init(void) ++{ ++ return -ENODEV; ++} ++#endif + + static void __init omap2_gptimer_clocksource_init(int gptimer_id, + const char *fck_source) +diff --git a/arch/arm/mach-pxa/raumfeld.c b/arch/arm/mach-pxa/raumfeld.c +index 5905ed1..d89d87ae 100644 +--- a/arch/arm/mach-pxa/raumfeld.c ++++ b/arch/arm/mach-pxa/raumfeld.c +@@ -953,12 +953,12 @@ static struct i2c_board_info raumfeld_connector_i2c_board_info __initdata = { + + static struct eeti_ts_platform_data eeti_ts_pdata = { + .irq_active_high = 1, ++ .irq_gpio = GPIO_TOUCH_IRQ, + }; + + static struct i2c_board_info raumfeld_controller_i2c_board_info __initdata = { + .type = "eeti_ts", + .addr = 0x0a, +- .irq = PXA_GPIO_TO_IRQ(GPIO_TOUCH_IRQ), + .platform_data = &eeti_ts_pdata, + }; + +diff --git a/arch/arm/mach-s3c24xx/include/mach/dma.h b/arch/arm/mach-s3c24xx/include/mach/dma.h +index 454831b..ee99fd5 100644 +--- a/arch/arm/mach-s3c24xx/include/mach/dma.h ++++ b/arch/arm/mach-s3c24xx/include/mach/dma.h +@@ -24,7 +24,8 @@ + */ + + enum dma_ch { +- DMACH_XD0, ++ DMACH_DT_PROP = -1, /* not yet supported, do not use */ ++ DMACH_XD0 = 0, + DMACH_XD1, + DMACH_SDI, + DMACH_SPI0, +diff --git a/arch/arm/mm/flush.c b/arch/arm/mm/flush.c +index 9b43e2c..d0ef23f 100644 +--- a/arch/arm/mm/flush.c ++++ b/arch/arm/mm/flush.c +@@ -231,8 +231,6 @@ void __sync_icache_dcache(pte_t pteval) + struct page *page; + struct address_space *mapping; + +- if (!pte_present_user(pteval)) +- return; + if (cache_is_vipt_nonaliasing() && !pte_exec(pteval)) + /* only flush non-aliasing VIPT caches for exec mappings */ + return; +diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h +index 2e8a1ef..87fa3f2 100644 +--- a/arch/arm/mm/mm.h ++++ b/arch/arm/mm/mm.h +@@ -55,6 +55,9 @@ extern void __flush_dcache_page(struct address_space *mapping, struct page *page + /* permanent static mappings from iotable_init() */ + #define VM_ARM_STATIC_MAPPING 0x40000000 + ++/* empty mapping */ ++#define VM_ARM_EMPTY_MAPPING 0x20000000 ++ + /* mapping type (attributes) for permanent static mappings */ + #define VM_ARM_MTYPE(mt) ((mt) << 20) + #define VM_ARM_MTYPE_MASK (0x1f << 20) +diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c +index cf4528d..15c6abe 100644 +--- a/arch/arm/mm/mmu.c ++++ b/arch/arm/mm/mmu.c +@@ -813,7 +813,7 @@ static void __init pmd_empty_section_gap(unsigned long addr) + vm = early_alloc_aligned(sizeof(*vm), __alignof__(*vm)); + vm->addr = (void *)addr; + vm->size = SECTION_SIZE; +- vm->flags = VM_IOREMAP | VM_ARM_STATIC_MAPPING; ++ vm->flags = VM_IOREMAP | VM_ARM_EMPTY_MAPPING; + vm->caller = pmd_empty_section_gap; + vm_area_add_early(vm); + } +@@ -826,7 +826,7 @@ static void __init fill_pmd_gaps(void) + + /* we're still single threaded hence no lock needed here */ + for (vm = vmlist; vm; vm = vm->next) { +- if (!(vm->flags & VM_ARM_STATIC_MAPPING)) ++ if (!(vm->flags & (VM_ARM_STATIC_MAPPING | VM_ARM_EMPTY_MAPPING))) + continue; + addr = (unsigned long)vm->addr; + if (addr < next) +diff --git a/arch/arm/mm/tlb-v7.S b/arch/arm/mm/tlb-v7.S +index 845f461..ea94765 100644 +--- a/arch/arm/mm/tlb-v7.S ++++ b/arch/arm/mm/tlb-v7.S +@@ -39,10 +39,18 @@ ENTRY(v7wbi_flush_user_tlb_range) + mov r0, r0, lsr #PAGE_SHIFT @ align address + mov r1, r1, lsr #PAGE_SHIFT + asid r3, r3 @ mask ASID ++#ifdef CONFIG_ARM_ERRATA_720789 ++ ALT_SMP(W(mov) r3, #0 ) ++ ALT_UP(W(nop) ) ++#endif + orr r0, r3, r0, lsl #PAGE_SHIFT @ Create initial MVA + mov r1, r1, lsl #PAGE_SHIFT + 1: ++#ifdef CONFIG_ARM_ERRATA_720789 ++ ALT_SMP(mcr p15, 0, r0, c8, c3, 3) @ TLB invalidate U MVA all ASID (shareable) ++#else + ALT_SMP(mcr p15, 0, r0, c8, c3, 1) @ TLB invalidate U MVA (shareable) ++#endif + ALT_UP(mcr p15, 0, r0, c8, c7, 1) @ TLB invalidate U MVA + + add r0, r0, #PAGE_SZ +@@ -67,7 +75,11 @@ ENTRY(v7wbi_flush_kern_tlb_range) + mov r0, r0, lsl #PAGE_SHIFT + mov r1, r1, lsl #PAGE_SHIFT + 1: ++#ifdef CONFIG_ARM_ERRATA_720789 ++ ALT_SMP(mcr p15, 0, r0, c8, c3, 3) @ TLB invalidate U MVA all ASID (shareable) ++#else + ALT_SMP(mcr p15, 0, r0, c8, c3, 1) @ TLB invalidate U MVA (shareable) ++#endif + ALT_UP(mcr p15, 0, r0, c8, c7, 1) @ TLB invalidate U MVA + add r0, r0, #PAGE_SZ + cmp r0, r1 +diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c +index 3b0cfeb..9359310 100644 +--- a/arch/arm/plat-omap/dmtimer.c ++++ b/arch/arm/plat-omap/dmtimer.c +@@ -236,7 +236,7 @@ EXPORT_SYMBOL_GPL(omap_dm_timer_enable); + + void omap_dm_timer_disable(struct omap_dm_timer *timer) + { +- pm_runtime_put(&timer->pdev->dev); ++ pm_runtime_put_sync(&timer->pdev->dev); + } + EXPORT_SYMBOL_GPL(omap_dm_timer_disable); + +diff --git a/arch/arm/plat-omap/include/plat/omap-serial.h b/arch/arm/plat-omap/include/plat/omap-serial.h +index 1a52725..3a57644 100644 +--- a/arch/arm/plat-omap/include/plat/omap-serial.h ++++ b/arch/arm/plat-omap/include/plat/omap-serial.h +@@ -42,10 +42,10 @@ + #define OMAP_UART_WER_MOD_WKUP 0X7F + + /* Enable XON/XOFF flow control on output */ +-#define OMAP_UART_SW_TX 0x04 ++#define OMAP_UART_SW_TX 0x8 + + /* Enable XON/XOFF flow control on input */ +-#define OMAP_UART_SW_RX 0x04 ++#define OMAP_UART_SW_RX 0x2 + + #define OMAP_UART_SYSC_RESET 0X07 + #define OMAP_UART_TCR_TRIG 0X0F +diff --git a/arch/arm/plat-s3c24xx/dma.c b/arch/arm/plat-s3c24xx/dma.c +index 28f898f..db98e70 100644 +--- a/arch/arm/plat-s3c24xx/dma.c ++++ b/arch/arm/plat-s3c24xx/dma.c +@@ -430,7 +430,7 @@ s3c2410_dma_canload(struct s3c2410_dma_chan *chan) + * when necessary. + */ + +-int s3c2410_dma_enqueue(unsigned int channel, void *id, ++int s3c2410_dma_enqueue(enum dma_ch channel, void *id, + dma_addr_t data, int size) + { + struct s3c2410_dma_chan *chan = s3c_dma_lookup_channel(channel); +diff --git a/arch/arm/vfp/entry.S b/arch/arm/vfp/entry.S +index 4fa9903..cc926c9 100644 +--- a/arch/arm/vfp/entry.S ++++ b/arch/arm/vfp/entry.S +@@ -7,18 +7,20 @@ + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. +- * +- * Basic entry code, called from the kernel's undefined instruction trap. +- * r0 = faulted instruction +- * r5 = faulted PC+4 +- * r9 = successful return +- * r10 = thread_info structure +- * lr = failure return + */ + #include + #include + #include "../kernel/entry-header.S" + ++@ VFP entry point. ++@ ++@ r0 = instruction opcode (32-bit ARM or two 16-bit Thumb) ++@ r2 = PC value to resume execution after successful emulation ++@ r9 = normal "successful" return address ++@ r10 = this threads thread_info structure ++@ lr = unrecognised instruction return address ++@ IRQs disabled. ++@ + ENTRY(do_vfp) + #ifdef CONFIG_PREEMPT + ldr r4, [r10, #TI_PREEMPT] @ get preempt count +diff --git a/arch/arm/vfp/vfphw.S b/arch/arm/vfp/vfphw.S +index 2d30c7f..3a0efaa 100644 +--- a/arch/arm/vfp/vfphw.S ++++ b/arch/arm/vfp/vfphw.S +@@ -61,13 +61,13 @@ + + @ VFP hardware support entry point. + @ +-@ r0 = faulted instruction +-@ r2 = faulted PC+4 +-@ r9 = successful return ++@ r0 = instruction opcode (32-bit ARM or two 16-bit Thumb) ++@ r2 = PC value to resume execution after successful emulation ++@ r9 = normal "successful" return address + @ r10 = vfp_state union + @ r11 = CPU number +-@ lr = failure return +- ++@ lr = unrecognised instruction return address ++@ IRQs enabled. + ENTRY(vfp_support_entry) + DBGSTR3 "instr %08x pc %08x state %p", r0, r2, r10 + +@@ -161,9 +161,12 @@ vfp_hw_state_valid: + @ exception before retrying branch + @ out before setting an FPEXC that + @ stops us reading stuff +- VFPFMXR FPEXC, r1 @ restore FPEXC last +- sub r2, r2, #4 +- str r2, [sp, #S_PC] @ retry the instruction ++ VFPFMXR FPEXC, r1 @ Restore FPEXC last ++ sub r2, r2, #4 @ Retry current instruction - if Thumb ++ str r2, [sp, #S_PC] @ mode it's two 16-bit instructions, ++ @ else it's one 32-bit instruction, so ++ @ always subtract 4 from the following ++ @ instruction address. + #ifdef CONFIG_PREEMPT + get_thread_info r10 + ldr r4, [r10, #TI_PREEMPT] @ get preempt count +diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c +index 58696192..c834b32 100644 +--- a/arch/arm/vfp/vfpmodule.c ++++ b/arch/arm/vfp/vfpmodule.c +@@ -457,10 +457,16 @@ static int vfp_pm_suspend(void) + + /* disable, just in case */ + fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN); ++ } else if (vfp_current_hw_state[ti->cpu]) { ++#ifndef CONFIG_SMP ++ fmxr(FPEXC, fpexc | FPEXC_EN); ++ vfp_save_state(vfp_current_hw_state[ti->cpu], fpexc); ++ fmxr(FPEXC, fpexc); ++#endif + } + + /* clear any information we had about last context state */ +- memset(vfp_current_hw_state, 0, sizeof(vfp_current_hw_state)); ++ vfp_current_hw_state[ti->cpu] = NULL; + + return 0; + } +@@ -713,8 +719,10 @@ static int __init vfp_init(void) + if ((fmrx(MVFR1) & 0x000fff00) == 0x00011100) + elf_hwcap |= HWCAP_NEON; + #endif ++#ifdef CONFIG_VFPv3 + if ((fmrx(MVFR1) & 0xf0000000) == 0x10000000) + elf_hwcap |= HWCAP_VFPv4; ++#endif + } + } + return 0; +diff --git a/arch/cris/kernel/process.c b/arch/cris/kernel/process.c +index 66fd017..7f65be6 100644 +--- a/arch/cris/kernel/process.c ++++ b/arch/cris/kernel/process.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + //#define DEBUG + +@@ -74,6 +75,7 @@ void cpu_idle (void) + { + /* endless idle loop with no priority at all */ + while (1) { ++ rcu_idle_enter(); + while (!need_resched()) { + void (*idle)(void); + /* +@@ -86,6 +88,7 @@ void cpu_idle (void) + idle = default_idle; + idle(); + } ++ rcu_idle_exit(); + schedule_preempt_disabled(); + } + } +diff --git a/arch/frv/kernel/process.c b/arch/frv/kernel/process.c +index ff95f50..2eb7fa5 100644 +--- a/arch/frv/kernel/process.c ++++ b/arch/frv/kernel/process.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -69,12 +70,14 @@ void cpu_idle(void) + { + /* endless idle loop with no priority at all */ + while (1) { ++ rcu_idle_enter(); + while (!need_resched()) { + check_pgt_cache(); + + if (!frv_dma_inprogress && idle) + idle(); + } ++ rcu_idle_exit(); + + schedule_preempt_disabled(); + } +diff --git a/arch/h8300/kernel/process.c b/arch/h8300/kernel/process.c +index 0e9c315..f153ed1 100644 +--- a/arch/h8300/kernel/process.c ++++ b/arch/h8300/kernel/process.c +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -78,8 +79,10 @@ void (*idle)(void) = default_idle; + void cpu_idle(void) + { + while (1) { ++ rcu_idle_enter(); + while (!need_resched()) + idle(); ++ rcu_idle_exit(); + schedule_preempt_disabled(); + } + } +diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h +index 7d91166..6e6fe18 100644 +--- a/arch/ia64/include/asm/atomic.h ++++ b/arch/ia64/include/asm/atomic.h +@@ -17,8 +17,8 @@ + #include + + +-#define ATOMIC_INIT(i) ((atomic_t) { (i) }) +-#define ATOMIC64_INIT(i) ((atomic64_t) { (i) }) ++#define ATOMIC_INIT(i) { (i) } ++#define ATOMIC64_INIT(i) { (i) } + + #define atomic_read(v) (*(volatile int *)&(v)->counter) + #define atomic64_read(v) (*(volatile long *)&(v)->counter) +diff --git a/arch/ia64/kernel/irq_ia64.c b/arch/ia64/kernel/irq_ia64.c +index 5c3e088..1034884 100644 +--- a/arch/ia64/kernel/irq_ia64.c ++++ b/arch/ia64/kernel/irq_ia64.c +@@ -23,7 +23,6 @@ + #include + #include + #include +-#include /* for rand_initialize_irq() */ + #include + #include + #include +diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c +index dd6fc14..3e316ec 100644 +--- a/arch/ia64/kernel/process.c ++++ b/arch/ia64/kernel/process.c +@@ -29,6 +29,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -279,6 +280,7 @@ cpu_idle (void) + + /* endless idle loop with no priority at all */ + while (1) { ++ rcu_idle_enter(); + if (can_do_pal_halt) { + current_thread_info()->status &= ~TS_POLLING; + /* +@@ -309,6 +311,7 @@ cpu_idle (void) + normal_xtp(); + #endif + } ++ rcu_idle_exit(); + schedule_preempt_disabled(); + check_pgt_cache(); + if (cpu_is_offline(cpu)) +diff --git a/arch/m32r/kernel/process.c b/arch/m32r/kernel/process.c +index 3a4a32b2..384e63f 100644 +--- a/arch/m32r/kernel/process.c ++++ b/arch/m32r/kernel/process.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -82,6 +83,7 @@ void cpu_idle (void) + { + /* endless idle loop with no priority at all */ + while (1) { ++ rcu_idle_enter(); + while (!need_resched()) { + void (*idle)(void) = pm_idle; + +@@ -90,6 +92,7 @@ void cpu_idle (void) + + idle(); + } ++ rcu_idle_exit(); + schedule_preempt_disabled(); + } + } +diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c +index c488e3c..ac2892e 100644 +--- a/arch/m68k/kernel/process.c ++++ b/arch/m68k/kernel/process.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -75,8 +76,10 @@ void cpu_idle(void) + { + /* endless idle loop with no priority at all */ + while (1) { ++ rcu_idle_enter(); + while (!need_resched()) + idle(); ++ rcu_idle_exit(); + schedule_preempt_disabled(); + } + } +diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c +index 8623f8d..9a5932e 100644 +--- a/arch/m68k/kernel/sys_m68k.c ++++ b/arch/m68k/kernel/sys_m68k.c +@@ -479,9 +479,13 @@ sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5, + 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 --git a/arch/mips/Makefile b/arch/mips/Makefile +index 764e37a..654b1ad 100644 +--- a/arch/mips/Makefile ++++ b/arch/mips/Makefile +@@ -225,7 +225,7 @@ KBUILD_CPPFLAGS += -DDATAOFFSET=$(if $(dataoffset-y),$(dataoffset-y),0) + LDFLAGS += -m $(ld-emul) + + ifdef CONFIG_MIPS +-CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -xc /dev/null | \ ++CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ + egrep -vw '__GNUC_(|MINOR_|PATCHLEVEL_)_' | \ + sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/") + ifdef CONFIG_64BIT +diff --git a/arch/mips/ath79/clock.c b/arch/mips/ath79/clock.c +index b91ad3e..d272857 100644 +--- a/arch/mips/ath79/clock.c ++++ b/arch/mips/ath79/clock.c +@@ -189,7 +189,7 @@ static void __init ar934x_clocks_init(void) + AR934X_PLL_CPU_CONFIG_NFRAC_MASK; + + cpu_pll = nint * ath79_ref_clk.rate / ref_div; +- cpu_pll += frac * ath79_ref_clk.rate / (ref_div * (2 << 6)); ++ cpu_pll += frac * ath79_ref_clk.rate / (ref_div * (1 << 6)); + cpu_pll /= (1 << out_div); + + pll = ath79_pll_rr(AR934X_PLL_DDR_CONFIG_REG); +@@ -203,7 +203,7 @@ static void __init ar934x_clocks_init(void) + AR934X_PLL_DDR_CONFIG_NFRAC_MASK; + + ddr_pll = nint * ath79_ref_clk.rate / ref_div; +- ddr_pll += frac * ath79_ref_clk.rate / (ref_div * (2 << 10)); ++ ddr_pll += frac * ath79_ref_clk.rate / (ref_div * (1 << 10)); + ddr_pll /= (1 << out_div); + + clk_ctrl = ath79_pll_rr(AR934X_PLL_CPU_DDR_CLK_CTRL_REG); +diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile +index fdaf65e..c6136cb 100644 +--- a/arch/mips/kernel/Makefile ++++ b/arch/mips/kernel/Makefile +@@ -104,7 +104,7 @@ obj-$(CONFIG_MIPS_MACHINE) += mips_machine.o + + obj-$(CONFIG_OF) += prom.o + +-CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi) ++CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/null -x c /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi) + + obj-$(CONFIG_HAVE_STD_PC_SERIAL_PORT) += 8250-platform.o + +diff --git a/arch/mips/kernel/kspd.c b/arch/mips/kernel/kspd.c +index 84d0639..b77f56b 100644 +--- a/arch/mips/kernel/kspd.c ++++ b/arch/mips/kernel/kspd.c +@@ -323,7 +323,7 @@ static void sp_cleanup(void) + fdt = files_fdtable(files); + for (;;) { + unsigned long set; +- i = j * __NFDBITS; ++ i = j * BITS_PER_LONG; + if (i >= fdt->max_fds) + break; + set = fdt->open_fds[j++]; +diff --git a/arch/mips/mm/gup.c b/arch/mips/mm/gup.c +index 33aadbc..dcfd573 100644 +--- a/arch/mips/mm/gup.c ++++ b/arch/mips/mm/gup.c +@@ -152,6 +152,8 @@ static int gup_huge_pud(pud_t pud, unsigned long addr, unsigned long end, + do { + VM_BUG_ON(compound_head(page) != head); + pages[*nr] = page; ++ if (PageTail(page)) ++ get_huge_page_tail(page); + (*nr)++; + page++; + refs++; +diff --git a/arch/mips/pci/pci-ar724x.c b/arch/mips/pci/pci-ar724x.c +index 414a745..86d77a6 100644 +--- a/arch/mips/pci/pci-ar724x.c ++++ b/arch/mips/pci/pci-ar724x.c +@@ -23,9 +23,12 @@ + #define AR724X_PCI_MEM_BASE 0x10000000 + #define AR724X_PCI_MEM_SIZE 0x08000000 + ++#define AR724X_PCI_REG_RESET 0x18 + #define AR724X_PCI_REG_INT_STATUS 0x4c + #define AR724X_PCI_REG_INT_MASK 0x50 + ++#define AR724X_PCI_RESET_LINK_UP BIT(0) ++ + #define AR724X_PCI_INT_DEV0 BIT(14) + + #define AR724X_PCI_IRQ_COUNT 1 +@@ -38,6 +41,15 @@ static void __iomem *ar724x_pci_ctrl_base; + + static u32 ar724x_pci_bar0_value; + static bool ar724x_pci_bar0_is_cached; ++static bool ar724x_pci_link_up; ++ ++static inline bool ar724x_pci_check_link(void) ++{ ++ u32 reset; ++ ++ reset = __raw_readl(ar724x_pci_ctrl_base + AR724X_PCI_REG_RESET); ++ return reset & AR724X_PCI_RESET_LINK_UP; ++} + + static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where, + int size, uint32_t *value) +@@ -46,6 +58,9 @@ static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where, + void __iomem *base; + u32 data; + ++ if (!ar724x_pci_link_up) ++ return PCIBIOS_DEVICE_NOT_FOUND; ++ + if (devfn) + return PCIBIOS_DEVICE_NOT_FOUND; + +@@ -96,6 +111,9 @@ static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where, + u32 data; + int s; + ++ if (!ar724x_pci_link_up) ++ return PCIBIOS_DEVICE_NOT_FOUND; ++ + if (devfn) + return PCIBIOS_DEVICE_NOT_FOUND; + +@@ -280,6 +298,10 @@ int __init ar724x_pcibios_init(int irq) + if (ar724x_pci_ctrl_base == NULL) + goto err_unmap_devcfg; + ++ ar724x_pci_link_up = ar724x_pci_check_link(); ++ if (!ar724x_pci_link_up) ++ pr_warn("ar724x: PCIe link is down\n"); ++ + ar724x_pci_irq_init(irq); + register_pci_controller(&ar724x_pci_controller); + +diff --git a/arch/mn10300/Makefile b/arch/mn10300/Makefile +index 33188b6..a3d0fef 100644 +--- a/arch/mn10300/Makefile ++++ b/arch/mn10300/Makefile +@@ -26,7 +26,7 @@ CHECKFLAGS += + PROCESSOR := unset + UNIT := unset + +-KBUILD_CFLAGS += -mam33 -mmem-funcs -DCPU=AM33 ++KBUILD_CFLAGS += -mam33 -DCPU=AM33 $(call cc-option,-mmem-funcs,) + KBUILD_AFLAGS += -mam33 -DCPU=AM33 + + ifeq ($(CONFIG_MN10300_CURRENT_IN_E2),y) +diff --git a/arch/mn10300/kernel/process.c b/arch/mn10300/kernel/process.c +index 7dab0cd..e9cceba 100644 +--- a/arch/mn10300/kernel/process.c ++++ b/arch/mn10300/kernel/process.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -107,6 +108,7 @@ void cpu_idle(void) + { + /* endless idle loop with no priority at all */ + for (;;) { ++ rcu_idle_enter(); + while (!need_resched()) { + void (*idle)(void); + +@@ -121,6 +123,7 @@ void cpu_idle(void) + } + idle(); + } ++ rcu_idle_exit(); + + schedule_preempt_disabled(); + } +diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h +index 6c6defc..af9cf30 100644 +--- a/arch/parisc/include/asm/atomic.h ++++ b/arch/parisc/include/asm/atomic.h +@@ -141,7 +141,7 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u) + + #define atomic_sub_and_test(i,v) (atomic_sub_return((i),(v)) == 0) + +-#define ATOMIC_INIT(i) ((atomic_t) { (i) }) ++#define ATOMIC_INIT(i) { (i) } + + #define smp_mb__before_atomic_dec() smp_mb() + #define smp_mb__after_atomic_dec() smp_mb() +@@ -150,7 +150,7 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u) + + #ifdef CONFIG_64BIT + +-#define ATOMIC64_INIT(i) ((atomic64_t) { (i) }) ++#define ATOMIC64_INIT(i) { (i) } + + static __inline__ s64 + __atomic64_add_return(s64 i, atomic64_t *v) +diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c +index d4b94b3..c54a4db 100644 +--- a/arch/parisc/kernel/process.c ++++ b/arch/parisc/kernel/process.c +@@ -48,6 +48,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -69,8 +70,10 @@ void cpu_idle(void) + + /* endless idle loop with no priority at all */ + while (1) { ++ rcu_idle_enter(); + while (!need_resched()) + barrier(); ++ rcu_idle_exit(); + schedule_preempt_disabled(); + check_pgt_cache(); + } +diff --git a/arch/powerpc/boot/dts/p1022ds.dtsi b/arch/powerpc/boot/dts/p1022ds.dtsi +index 7cdb505..1b0673e 100644 +--- a/arch/powerpc/boot/dts/p1022ds.dtsi ++++ b/arch/powerpc/boot/dts/p1022ds.dtsi +@@ -33,22 +33,6 @@ + */ + + &board_lbc { +- /* +- * This node is used to access the pixis via "indirect" mode, +- * which is done by writing the pixis register index to chip +- * select 0 and the value to/from chip select 1. Indirect +- * mode is the only way to access the pixis when DIU video +- * is enabled. Note that this assumes that the first column +- * of the 'ranges' property above is the chip select number. +- */ +- board-control@0,0 { +- compatible = "fsl,p1022ds-indirect-pixis"; +- reg = <0x0 0x0 1 /* CS0 */ +- 0x1 0x0 1>; /* CS1 */ +- interrupt-parent = <&mpic>; +- interrupts = <8 0 0 0>; +- }; +- + nor@0,0 { + #address-cells = <1>; + #size-cells = <1>; +diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h +index ac39e6a..2974edd 100644 +--- a/arch/powerpc/include/asm/pci-bridge.h ++++ b/arch/powerpc/include/asm/pci-bridge.h +@@ -181,6 +181,14 @@ static inline int pci_device_from_OF_node(struct device_node *np, + #if defined(CONFIG_EEH) + static inline struct eeh_dev *of_node_to_eeh_dev(struct device_node *dn) + { ++ /* ++ * For those OF nodes whose parent isn't PCI bridge, they ++ * don't have PCI_DN actually. So we have to skip them for ++ * any EEH operations. ++ */ ++ if (!dn || !PCI_DN(dn)) ++ return NULL; ++ + return PCI_DN(dn)->edev; + } + #endif +diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h +index f0cb7f4..360585d 100644 +--- a/arch/powerpc/include/asm/reg.h ++++ b/arch/powerpc/include/asm/reg.h +@@ -1024,7 +1024,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 --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c +index 52c7ad7..05f8329 100644 +--- a/arch/powerpc/kernel/asm-offsets.c ++++ b/arch/powerpc/kernel/asm-offsets.c +@@ -76,6 +76,7 @@ int main(void) + DEFINE(SIGSEGV, SIGSEGV); + DEFINE(NMI_MASK, NMI_MASK); + DEFINE(THREAD_DSCR, offsetof(struct thread_struct, dscr)); ++ DEFINE(THREAD_DSCR_INHERIT, offsetof(struct thread_struct, dscr_inherit)); + #else + DEFINE(THREAD_INFO, offsetof(struct task_struct, stack)); + #endif /* CONFIG_PPC64 */ +diff --git a/arch/powerpc/kernel/dbell.c b/arch/powerpc/kernel/dbell.c +index 5b25c80..a892680 100644 +--- a/arch/powerpc/kernel/dbell.c ++++ b/arch/powerpc/kernel/dbell.c +@@ -28,6 +28,8 @@ void doorbell_setup_this_cpu(void) + + void doorbell_cause_ipi(int cpu, unsigned long data) + { ++ /* Order previous accesses vs. msgsnd, which is treated as a store */ ++ mb(); + ppc_msgsnd(PPC_DBELL, 0, data); + } + +diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S +index 5971c85..8d2fa24 100644 +--- a/arch/powerpc/kernel/entry_64.S ++++ b/arch/powerpc/kernel/entry_64.S +@@ -369,6 +369,12 @@ _GLOBAL(ret_from_fork) + li r3,0 + b syscall_exit + ++ .section ".toc","aw" ++DSCR_DEFAULT: ++ .tc dscr_default[TC],dscr_default ++ ++ .section ".text" ++ + /* + * This routine switches between two different tasks. The process + * state of one is saved on its kernel stack. Then the state +@@ -508,9 +514,6 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT) + mr r1,r8 /* start using new stack pointer */ + std r7,PACAKSAVE(r13) + +- ld r6,_CCR(r1) +- mtcrf 0xFF,r6 +- + #ifdef CONFIG_ALTIVEC + BEGIN_FTR_SECTION + ld r0,THREAD_VRSAVE(r4) +@@ -519,14 +522,22 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) + #endif /* CONFIG_ALTIVEC */ + #ifdef CONFIG_PPC64 + BEGIN_FTR_SECTION ++ lwz r6,THREAD_DSCR_INHERIT(r4) ++ ld r7,DSCR_DEFAULT@toc(2) + ld r0,THREAD_DSCR(r4) +- cmpd r0,r25 +- beq 1f ++ cmpwi r6,0 ++ bne 1f ++ ld r0,0(r7) ++1: cmpd r0,r25 ++ beq 2f + mtspr SPRN_DSCR,r0 +-1: ++2: + END_FTR_SECTION_IFSET(CPU_FTR_DSCR) + #endif + ++ ld r6,_CCR(r1) ++ mtcrf 0xFF,r6 ++ + /* r3-r13 are destroyed -- Cort */ + REST_8GPRS(14, r1) + REST_10GPRS(22, r1) +diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c +index bf99cfa..6324008 100644 +--- a/arch/powerpc/kernel/ftrace.c ++++ b/arch/powerpc/kernel/ftrace.c +@@ -245,9 +245,9 @@ __ftrace_make_nop(struct module *mod, + + /* + * 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 @@ __ftrace_make_nop(struct module *mod, + 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 --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c +index 710f400..1a1f2dd 100644 +--- a/arch/powerpc/kernel/process.c ++++ b/arch/powerpc/kernel/process.c +@@ -802,16 +802,8 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, + #endif /* CONFIG_PPC_STD_MMU_64 */ + #ifdef CONFIG_PPC64 + if (cpu_has_feature(CPU_FTR_DSCR)) { +- if (current->thread.dscr_inherit) { +- p->thread.dscr_inherit = 1; +- p->thread.dscr = current->thread.dscr; +- } else if (0 != dscr_default) { +- p->thread.dscr_inherit = 1; +- p->thread.dscr = dscr_default; +- } else { +- p->thread.dscr_inherit = 0; +- p->thread.dscr = 0; +- } ++ p->thread.dscr_inherit = current->thread.dscr_inherit; ++ p->thread.dscr = current->thread.dscr; + } + #endif + +diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c +index e4cb343..8d7c119 100644 +--- a/arch/powerpc/kernel/smp.c ++++ b/arch/powerpc/kernel/smp.c +@@ -197,8 +197,15 @@ void smp_muxed_ipi_message_pass(int cpu, int msg) + struct cpu_messages *info = &per_cpu(ipi_message, cpu); + char *message = (char *)&info->messages; + ++ /* ++ * Order previous accesses before accesses in the IPI handler. ++ */ ++ smp_mb(); + message[msg] = 1; +- mb(); ++ /* ++ * cause_ipi functions are required to include a full barrier ++ * before doing whatever causes the IPI. ++ */ + smp_ops->cause_ipi(cpu, info->data); + } + +@@ -210,7 +217,7 @@ irqreturn_t smp_ipi_demux(void) + mb(); /* order any irq clear */ + + do { +- all = xchg_local(&info->messages, 0); ++ all = xchg(&info->messages, 0); + + #ifdef __BIG_ENDIAN + if (all & (1 << (24 - 8 * PPC_MSG_CALL_FUNCTION))) +diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c +index 3529446..8302af6 100644 +--- a/arch/powerpc/kernel/sysfs.c ++++ b/arch/powerpc/kernel/sysfs.c +@@ -194,6 +194,14 @@ static ssize_t show_dscr_default(struct device *dev, + return sprintf(buf, "%lx\n", dscr_default); + } + ++static void update_dscr(void *dummy) ++{ ++ if (!current->thread.dscr_inherit) { ++ current->thread.dscr = dscr_default; ++ mtspr(SPRN_DSCR, dscr_default); ++ } ++} ++ + static ssize_t __used store_dscr_default(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +@@ -206,6 +214,8 @@ static ssize_t __used store_dscr_default(struct device *dev, + return -EINVAL; + dscr_default = val; + ++ on_each_cpu(update_dscr, NULL, 1); ++ + return count; + } + +diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c +index 427f046..514f0ca 100644 +--- a/arch/powerpc/kernel/traps.c ++++ b/arch/powerpc/kernel/traps.c +@@ -976,8 +976,9 @@ static int emulate_instruction(struct pt_regs *regs) + cpu_has_feature(CPU_FTR_DSCR)) { + PPC_WARN_EMULATED(mtdscr, regs); + rd = (instword >> 21) & 0x1f; +- mtspr(SPRN_DSCR, regs->gpr[rd]); ++ current->thread.dscr = regs->gpr[rd]; + current->thread.dscr_inherit = 1; ++ mtspr(SPRN_DSCR, current->thread.dscr); + return 0; + } + #endif +diff --git a/arch/powerpc/platforms/85xx/p1022_ds.c b/arch/powerpc/platforms/85xx/p1022_ds.c +index f700c81..f80887f 100644 +--- a/arch/powerpc/platforms/85xx/p1022_ds.c ++++ b/arch/powerpc/platforms/85xx/p1022_ds.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + #include "smp.h" + + #include "mpc85xx.h" +@@ -142,17 +143,74 @@ static void p1022ds_set_gamma_table(enum fsl_diu_monitor_port port, + { + } + ++struct fsl_law { ++ u32 lawbar; ++ u32 reserved1; ++ u32 lawar; ++ u32 reserved[5]; ++}; ++ ++#define LAWBAR_MASK 0x00F00000 ++#define LAWBAR_SHIFT 12 ++ ++#define LAWAR_EN 0x80000000 ++#define LAWAR_TGT_MASK 0x01F00000 ++#define LAW_TRGT_IF_LBC (0x04 << 20) ++ ++#define LAWAR_MASK (LAWAR_EN | LAWAR_TGT_MASK) ++#define LAWAR_MATCH (LAWAR_EN | LAW_TRGT_IF_LBC) ++ ++#define BR_BA 0xFFFF8000 ++ ++/* ++ * Map a BRx value to a physical address ++ * ++ * The localbus BRx registers only store the lower 32 bits of the address. To ++ * obtain the upper four bits, we need to scan the LAW table. The entry which ++ * maps to the localbus will contain the upper four bits. ++ */ ++static phys_addr_t lbc_br_to_phys(const void *ecm, unsigned int count, u32 br) ++{ ++#ifndef CONFIG_PHYS_64BIT ++ /* ++ * If we only have 32-bit addressing, then the BRx address *is* the ++ * physical address. ++ */ ++ return br & BR_BA; ++#else ++ const struct fsl_law *law = ecm + 0xc08; ++ unsigned int i; ++ ++ for (i = 0; i < count; i++) { ++ u64 lawbar = in_be32(&law[i].lawbar); ++ u32 lawar = in_be32(&law[i].lawar); ++ ++ if ((lawar & LAWAR_MASK) == LAWAR_MATCH) ++ /* Extract the upper four bits */ ++ return (br & BR_BA) | ((lawbar & LAWBAR_MASK) << 12); ++ } ++ ++ return 0; ++#endif ++} ++ + /** + * p1022ds_set_monitor_port: switch the output to a different monitor port +- * + */ + static void p1022ds_set_monitor_port(enum fsl_diu_monitor_port port) + { + struct device_node *guts_node; +- struct device_node *indirect_node = NULL; ++ struct device_node *lbc_node = NULL; ++ struct device_node *law_node = NULL; + struct ccsr_guts __iomem *guts; ++ struct fsl_lbc_regs *lbc = NULL; ++ void *ecm = NULL; + u8 __iomem *lbc_lcs0_ba = NULL; + u8 __iomem *lbc_lcs1_ba = NULL; ++ phys_addr_t cs0_addr, cs1_addr; ++ u32 br0, or0, br1, or1; ++ const __be32 *iprop; ++ unsigned int num_laws; + u8 b; + + /* Map the global utilities registers. */ +@@ -168,22 +226,99 @@ static void p1022ds_set_monitor_port(enum fsl_diu_monitor_port port) + goto exit; + } + +- indirect_node = of_find_compatible_node(NULL, NULL, +- "fsl,p1022ds-indirect-pixis"); +- if (!indirect_node) { +- pr_err("p1022ds: missing pixis indirect mode node\n"); ++ lbc_node = of_find_compatible_node(NULL, NULL, "fsl,p1022-elbc"); ++ if (!lbc_node) { ++ pr_err("p1022ds: missing localbus node\n"); + goto exit; + } + +- lbc_lcs0_ba = of_iomap(indirect_node, 0); +- if (!lbc_lcs0_ba) { +- pr_err("p1022ds: could not map localbus chip select 0\n"); ++ lbc = of_iomap(lbc_node, 0); ++ if (!lbc) { ++ pr_err("p1022ds: could not map localbus node\n"); ++ goto exit; ++ } ++ ++ law_node = of_find_compatible_node(NULL, NULL, "fsl,ecm-law"); ++ if (!law_node) { ++ pr_err("p1022ds: missing local access window node\n"); ++ goto exit; ++ } ++ ++ ecm = of_iomap(law_node, 0); ++ if (!ecm) { ++ pr_err("p1022ds: could not map local access window node\n"); ++ goto exit; ++ } ++ ++ iprop = of_get_property(law_node, "fsl,num-laws", 0); ++ if (!iprop) { ++ pr_err("p1022ds: LAW node is missing fsl,num-laws property\n"); + goto exit; + } ++ num_laws = be32_to_cpup(iprop); + +- lbc_lcs1_ba = of_iomap(indirect_node, 1); ++ /* ++ * Indirect mode requires both BR0 and BR1 to be set to "GPCM", ++ * otherwise writes to these addresses won't actually appear on the ++ * local bus, and so the PIXIS won't see them. ++ * ++ * In FCM mode, writes go to the NAND controller, which does not pass ++ * them to the localbus directly. So we force BR0 and BR1 into GPCM ++ * mode, since we don't care about what's behind the localbus any ++ * more. ++ */ ++ br0 = in_be32(&lbc->bank[0].br); ++ br1 = in_be32(&lbc->bank[1].br); ++ or0 = in_be32(&lbc->bank[0].or); ++ or1 = in_be32(&lbc->bank[1].or); ++ ++ /* Make sure CS0 and CS1 are programmed */ ++ if (!(br0 & BR_V) || !(br1 & BR_V)) { ++ pr_err("p1022ds: CS0 and/or CS1 is not programmed\n"); ++ goto exit; ++ } ++ ++ /* ++ * Use the existing BRx/ORx values if it's already GPCM. Otherwise, ++ * force the values to simple 32KB GPCM windows with the most ++ * conservative timing. ++ */ ++ if ((br0 & BR_MSEL) != BR_MS_GPCM) { ++ br0 = (br0 & BR_BA) | BR_V; ++ or0 = 0xFFFF8000 | 0xFF7; ++ out_be32(&lbc->bank[0].br, br0); ++ out_be32(&lbc->bank[0].or, or0); ++ } ++ if ((br1 & BR_MSEL) != BR_MS_GPCM) { ++ br1 = (br1 & BR_BA) | BR_V; ++ or1 = 0xFFFF8000 | 0xFF7; ++ out_be32(&lbc->bank[1].br, br1); ++ out_be32(&lbc->bank[1].or, or1); ++ } ++ ++ cs0_addr = lbc_br_to_phys(ecm, num_laws, br0); ++ if (!cs0_addr) { ++ pr_err("p1022ds: could not determine physical address for CS0" ++ " (BR0=%08x)\n", br0); ++ goto exit; ++ } ++ cs1_addr = lbc_br_to_phys(ecm, num_laws, br1); ++ if (!cs0_addr) { ++ pr_err("p1022ds: could not determine physical address for CS1" ++ " (BR1=%08x)\n", br1); ++ goto exit; ++ } ++ ++ lbc_lcs0_ba = ioremap(cs0_addr, 1); ++ if (!lbc_lcs0_ba) { ++ pr_err("p1022ds: could not ioremap CS0 address %llx\n", ++ (unsigned long long)cs0_addr); ++ goto exit; ++ } ++ lbc_lcs1_ba = ioremap(cs1_addr, 1); + if (!lbc_lcs1_ba) { +- pr_err("p1022ds: could not map localbus chip select 1\n"); ++ pr_err("p1022ds: could not ioremap CS1 address %llx\n", ++ (unsigned long long)cs1_addr); + goto exit; + } + +@@ -254,10 +389,15 @@ exit: + iounmap(lbc_lcs1_ba); + if (lbc_lcs0_ba) + iounmap(lbc_lcs0_ba); ++ if (lbc) ++ iounmap(lbc); ++ if (ecm) ++ iounmap(ecm); + if (guts) + iounmap(guts); + +- of_node_put(indirect_node); ++ of_node_put(law_node); ++ of_node_put(lbc_node); + of_node_put(guts_node); + } + +@@ -355,6 +495,8 @@ static void __init disable_one_node(struct device_node *np, struct property *new + prom_update_property(np, new, old); + else + prom_add_property(np, new); ++ ++ pr_info("p1022ds: disabling %s node\n", np->full_name); + } + + /* TRUE if there is a "video=fslfb" command-line parameter. */ +@@ -419,28 +561,46 @@ static void __init p1022_ds_setup_arch(void) + diu_ops.valid_monitor_port = p1022ds_valid_monitor_port; + + /* +- * Disable the NOR flash node if there is video=fslfb... command-line +- * parameter. When the DIU is active, NOR flash is unavailable, so we +- * have to disable the node before the MTD driver loads. ++ * Disable the NOR and NAND flash nodes if there is video=fslfb... ++ * command-line parameter. When the DIU is active, the localbus is ++ * unavailable, so we have to disable these nodes before the MTD ++ * driver loads. + */ + if (fslfb) { + struct device_node *np = + of_find_compatible_node(NULL, NULL, "fsl,p1022-elbc"); + + if (np) { +- np = of_find_compatible_node(np, NULL, "cfi-flash"); +- if (np) { ++ struct device_node *np2; ++ ++ of_node_get(np); ++ np2 = of_find_compatible_node(np, NULL, "cfi-flash"); ++ if (np2) { + static struct property nor_status = { + .name = "status", + .value = "disabled", + .length = sizeof("disabled"), + }; + +- pr_info("p1022ds: disabling %s node", +- np->full_name); +- disable_one_node(np, &nor_status); +- of_node_put(np); ++ disable_one_node(np2, &nor_status); ++ of_node_put(np2); ++ } ++ ++ of_node_get(np); ++ np2 = of_find_compatible_node(np, NULL, ++ "fsl,elbc-fcm-nand"); ++ if (np2) { ++ static struct property nand_status = { ++ .name = "status", ++ .value = "disabled", ++ .length = sizeof("disabled"), ++ }; ++ ++ disable_one_node(np2, &nand_status); ++ of_node_put(np2); + } ++ ++ of_node_put(np); + } + + } +diff --git a/arch/powerpc/platforms/pseries/eeh.c b/arch/powerpc/platforms/pseries/eeh.c +index ecd394c..9a0b5f5 100644 +--- a/arch/powerpc/platforms/pseries/eeh.c ++++ b/arch/powerpc/platforms/pseries/eeh.c +@@ -1029,7 +1029,7 @@ static void eeh_add_device_early(struct device_node *dn) + { + struct pci_controller *phb; + +- if (!dn || !of_node_to_eeh_dev(dn)) ++ if (!of_node_to_eeh_dev(dn)) + return; + phb = of_node_to_eeh_dev(dn)->phb; + +diff --git a/arch/powerpc/platforms/pseries/eeh_event.c b/arch/powerpc/platforms/pseries/eeh_event.c +index 4cb375c..fb50631 100644 +--- a/arch/powerpc/platforms/pseries/eeh_event.c ++++ b/arch/powerpc/platforms/pseries/eeh_event.c +@@ -85,8 +85,10 @@ static int eeh_event_handler(void * dummy) + set_current_state(TASK_INTERRUPTIBLE); /* Don't add to load average */ + edev = handle_eeh_events(event); + +- eeh_clear_slot(eeh_dev_to_of_node(edev), EEH_MODE_RECOVERING); +- pci_dev_put(edev->pdev); ++ if (edev) { ++ eeh_clear_slot(eeh_dev_to_of_node(edev), EEH_MODE_RECOVERING); ++ pci_dev_put(edev->pdev); ++ } + + kfree(event); + mutex_unlock(&eeh_event_mutex); +diff --git a/arch/powerpc/sysdev/xics/icp-hv.c b/arch/powerpc/sysdev/xics/icp-hv.c +index 253dce9..762c5ca 100644 +--- a/arch/powerpc/sysdev/xics/icp-hv.c ++++ b/arch/powerpc/sysdev/xics/icp-hv.c +@@ -65,7 +65,11 @@ static inline void icp_hv_set_xirr(unsigned int value) + static inline void icp_hv_set_qirr(int n_cpu , u8 value) + { + int hw_cpu = get_hard_smp_processor_id(n_cpu); +- long rc = plpar_hcall_norets(H_IPI, hw_cpu, value); ++ long rc; ++ ++ /* Make sure all previous accesses are ordered before IPI sending */ ++ mb(); ++ rc = plpar_hcall_norets(H_IPI, hw_cpu, value); + if (rc != H_SUCCESS) { + pr_err("%s: bad return code qirr cpu=%d hw_cpu=%d mfrr=0x%x " + "returned %ld\n", __func__, n_cpu, hw_cpu, value, rc); +diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h +index 69bdf72..89b0b39 100644 +--- a/arch/s390/include/asm/mmu_context.h ++++ b/arch/s390/include/asm/mmu_context.h +@@ -13,7 +13,6 @@ + #include + #include + #include +-#include + + static inline int init_new_context(struct task_struct *tsk, + struct mm_struct *mm) +@@ -93,4 +92,17 @@ static inline void activate_mm(struct mm_struct *prev, + switch_mm(prev, next, current); + } + ++static inline void arch_dup_mmap(struct mm_struct *oldmm, ++ struct mm_struct *mm) ++{ ++#ifdef CONFIG_64BIT ++ if (oldmm->context.asce_limit < mm->context.asce_limit) ++ crst_table_downgrade(mm, oldmm->context.asce_limit); ++#endif ++} ++ ++static inline void arch_exit_mmap(struct mm_struct *mm) ++{ ++} ++ + #endif /* __S390_MMU_CONTEXT_H */ +diff --git a/arch/s390/include/asm/processor.h b/arch/s390/include/asm/processor.h +index 20d0585..3987b2f 100644 +--- a/arch/s390/include/asm/processor.h ++++ b/arch/s390/include/asm/processor.h +@@ -122,7 +122,9 @@ struct stack_frame { + regs->psw.mask = psw_user_bits | PSW_MASK_BA; \ + regs->psw.addr = new_psw | PSW_ADDR_AMODE; \ + regs->gprs[15] = new_stackp; \ ++ __tlb_flush_mm(current->mm); \ + crst_table_downgrade(current->mm, 1UL << 31); \ ++ update_mm(current->mm, current); \ + } while (0) + + /* Forward declaration, a strange C thing */ +diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c +index 6542652..a1a5aca 100644 +--- a/arch/s390/kernel/compat_linux.c ++++ b/arch/s390/kernel/compat_linux.c +@@ -622,7 +622,6 @@ asmlinkage unsigned long old32_mmap(struct mmap_arg_struct_emu31 __user *arg) + return -EFAULT; + if (a.offset & ~PAGE_MASK) + return -EINVAL; +- a.addr = (unsigned long) compat_ptr(a.addr); + return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, + a.offset >> PAGE_SHIFT); + } +@@ -633,7 +632,6 @@ asmlinkage long sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg) + + if (copy_from_user(&a, arg, sizeof(a))) + return -EFAULT; +- a.addr = (unsigned long) compat_ptr(a.addr); + return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); + } + +diff --git a/arch/s390/kernel/compat_wrapper.S b/arch/s390/kernel/compat_wrapper.S +index ff605a3..cfe3efd 100644 +--- a/arch/s390/kernel/compat_wrapper.S ++++ b/arch/s390/kernel/compat_wrapper.S +@@ -1636,7 +1636,7 @@ ENTRY(compat_sys_process_vm_readv_wrapper) + llgfr %r6,%r6 # unsigned long + llgf %r0,164(%r15) # unsigned long + stg %r0,160(%r15) +- jg sys_process_vm_readv ++ jg compat_sys_process_vm_readv + + ENTRY(compat_sys_process_vm_writev_wrapper) + lgfr %r2,%r2 # compat_pid_t +@@ -1646,4 +1646,4 @@ ENTRY(compat_sys_process_vm_writev_wrapper) + llgfr %r6,%r6 # unsigned long + llgf %r0,164(%r15) # unsigned long + stg %r0,160(%r15) +- jg sys_process_vm_writev ++ jg compat_sys_process_vm_writev +diff --git a/arch/s390/kernel/processor.c b/arch/s390/kernel/processor.c +index 6e0073e..07c7bf4 100644 +--- a/arch/s390/kernel/processor.c ++++ b/arch/s390/kernel/processor.c +@@ -26,12 +26,14 @@ static DEFINE_PER_CPU(struct cpuid, cpu_id); + void __cpuinit cpu_init(void) + { + struct cpuid *id = &per_cpu(cpu_id, smp_processor_id()); ++ struct s390_idle_data *idle = &__get_cpu_var(s390_idle); + + get_cpu_id(id); + atomic_inc(&init_mm.mm_count); + current->active_mm = &init_mm; + BUG_ON(current->mm); + enter_lazy_tlb(&init_mm, current); ++ memset(idle, 0, sizeof(*idle)); + } + + /* +diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c +index 15cca26..25e3f3e 100644 +--- a/arch/s390/kernel/smp.c ++++ b/arch/s390/kernel/smp.c +@@ -984,14 +984,11 @@ static int __cpuinit smp_cpu_notify(struct notifier_block *self, + unsigned int cpu = (unsigned int)(long)hcpu; + struct cpu *c = &pcpu_devices[cpu].cpu; + struct device *s = &c->dev; +- struct s390_idle_data *idle; + int err = 0; + + switch (action) { + case CPU_ONLINE: + case CPU_ONLINE_FROZEN: +- idle = &per_cpu(s390_idle, cpu); +- memset(idle, 0, sizeof(struct s390_idle_data)); + err = sysfs_create_group(&s->kobj, &cpu_online_attr_group); + break; + case CPU_DEAD: +diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c +index 72cec9e..470651f 100644 +--- a/arch/s390/mm/fault.c ++++ b/arch/s390/mm/fault.c +@@ -443,6 +443,7 @@ int __handle_fault(unsigned long uaddr, unsigned long pgm_int_code, int write) + struct pt_regs regs; + int access, fault; + ++ /* Emulate a uaccess fault from kernel mode. */ + regs.psw.mask = psw_kernel_bits | PSW_MASK_DAT | PSW_MASK_MCHECK; + if (!irqs_disabled()) + regs.psw.mask |= PSW_MASK_IO | PSW_MASK_EXT; +@@ -452,12 +453,12 @@ int __handle_fault(unsigned long uaddr, unsigned long pgm_int_code, int write) + regs.int_parm_long = (uaddr & PAGE_MASK) | 2; + access = write ? VM_WRITE : VM_READ; + fault = do_exception(®s, access); +- if (unlikely(fault)) { +- if (fault & VM_FAULT_OOM) +- return -EFAULT; +- else if (fault & VM_FAULT_SIGBUS) +- do_sigbus(®s); +- } ++ /* ++ * Since the fault happened in kernel mode while performing a uaccess ++ * all we need to do now is emulating a fixup in case "fault" is not ++ * zero. ++ * For the calling uaccess functions this results always in -EFAULT. ++ */ + return fault ? -EFAULT : 0; + } + +diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c +index 2857c48..a64fe53 100644 +--- a/arch/s390/mm/mmap.c ++++ b/arch/s390/mm/mmap.c +@@ -105,9 +105,15 @@ void arch_pick_mmap_layout(struct mm_struct *mm) + + int s390_mmap_check(unsigned long addr, unsigned long len) + { ++ int rc; ++ + if (!is_compat_task() && +- len >= TASK_SIZE && TASK_SIZE < (1UL << 53)) +- return crst_table_upgrade(current->mm, 1UL << 53); ++ len >= TASK_SIZE && TASK_SIZE < (1UL << 53)) { ++ rc = crst_table_upgrade(current->mm, 1UL << 53); ++ if (rc) ++ return rc; ++ update_mm(current->mm, current); ++ } + return 0; + } + +@@ -127,6 +133,7 @@ s390_get_unmapped_area(struct file *filp, unsigned long addr, + rc = crst_table_upgrade(mm, 1UL << 53); + if (rc) + return (unsigned long) rc; ++ update_mm(mm, current); + area = arch_get_unmapped_area(filp, addr, len, pgoff, flags); + } + return area; +@@ -149,6 +156,7 @@ s390_get_unmapped_area_topdown(struct file *filp, const unsigned long addr, + rc = crst_table_upgrade(mm, 1UL << 53); + if (rc) + return (unsigned long) rc; ++ update_mm(mm, current); + area = arch_get_unmapped_area_topdown(filp, addr, len, + pgoff, flags); + } +diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c +index a3db5a3..56e6fd5 100644 +--- a/arch/s390/mm/pgtable.c ++++ b/arch/s390/mm/pgtable.c +@@ -85,7 +85,6 @@ repeat: + crst_table_free(mm, table); + if (mm->context.asce_limit < limit) + goto repeat; +- update_mm(mm, current); + return 0; + } + +@@ -93,9 +92,6 @@ void crst_table_downgrade(struct mm_struct *mm, unsigned long limit) + { + pgd_t *pgd; + +- if (mm->context.asce_limit <= limit) +- return; +- __tlb_flush_mm(mm); + while (mm->context.asce_limit > limit) { + pgd = mm->pgd; + switch (pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) { +@@ -118,7 +114,6 @@ void crst_table_downgrade(struct mm_struct *mm, unsigned long limit) + mm->task_size = mm->context.asce_limit; + crst_table_free(mm, (unsigned long *) pgd); + } +- update_mm(mm, current); + } + #endif + +diff --git a/arch/s390/oprofile/init.c b/arch/s390/oprofile/init.c +index 2297be4..abe8722 100644 +--- a/arch/s390/oprofile/init.c ++++ b/arch/s390/oprofile/init.c +@@ -171,7 +171,7 @@ static ssize_t hw_interval_write(struct file *file, char const __user *buf, + if (*offset) + return -EINVAL; + retval = oprofilefs_ulong_from_user(&val, buf, count); +- if (retval) ++ if (retval <= 0) + return retval; + if (val < oprofile_min_interval) + oprofile_hw_interval = oprofile_min_interval; +@@ -214,7 +214,7 @@ static ssize_t hwsampler_zero_write(struct file *file, char const __user *buf, + return -EINVAL; + + retval = oprofilefs_ulong_from_user(&val, buf, count); +- if (retval) ++ if (retval <= 0) + return retval; + if (val != 0) + return -EINVAL; +@@ -245,7 +245,7 @@ static ssize_t hwsampler_kernel_write(struct file *file, char const __user *buf, + return -EINVAL; + + retval = oprofilefs_ulong_from_user(&val, buf, count); +- if (retval) ++ if (retval <= 0) + return retval; + + if (val != 0 && val != 1) +@@ -280,7 +280,7 @@ static ssize_t hwsampler_user_write(struct file *file, char const __user *buf, + return -EINVAL; + + retval = oprofilefs_ulong_from_user(&val, buf, count); +- if (retval) ++ if (retval <= 0) + return retval; + + if (val != 0 && val != 1) +@@ -319,7 +319,7 @@ static ssize_t timer_enabled_write(struct file *file, char const __user *buf, + return -EINVAL; + + retval = oprofilefs_ulong_from_user(&val, buf, count); +- if (retval) ++ if (retval <= 0) + return retval; + + if (val != 0 && val != 1) +diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c +index 2707023..637970c 100644 +--- a/arch/score/kernel/process.c ++++ b/arch/score/kernel/process.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + + void (*pm_power_off)(void); + EXPORT_SYMBOL(pm_power_off); +@@ -50,9 +51,10 @@ void __noreturn cpu_idle(void) + { + /* endless idle loop with no priority at all */ + while (1) { ++ rcu_idle_enter(); + while (!need_resched()) + barrier(); +- ++ rcu_idle_exit(); + schedule_preempt_disabled(); + } + } +diff --git a/arch/sh/mm/fault.c b/arch/sh/mm/fault.c +index 1fc25d8..3bdc1ad 100644 +--- a/arch/sh/mm/fault.c ++++ b/arch/sh/mm/fault.c +@@ -58,11 +58,15 @@ static void show_pte(struct mm_struct *mm, unsigned long addr) + { + pgd_t *pgd; + +- if (mm) ++ if (mm) { + pgd = mm->pgd; +- else ++ } else { + pgd = get_TTB(); + ++ if (unlikely(!pgd)) ++ pgd = swapper_pg_dir; ++ } ++ + printk(KERN_ALERT "pgd = %p\n", pgd); + pgd += pgd_index(addr); + printk(KERN_ALERT "[%08lx] *pgd=%0*Lx", addr, +diff --git a/arch/x86/Makefile b/arch/x86/Makefile +index 1f25214..d3d8198 100644 +--- a/arch/x86/Makefile ++++ b/arch/x86/Makefile +@@ -85,7 +85,7 @@ endif + ifdef CONFIG_X86_X32 + x32_ld_ok := $(call try-run,\ + /bin/echo -e '1: .quad 1b' | \ +- $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" - && \ ++ $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" - && \ + $(OBJCOPY) -O elf32-x86-64 "$$TMP" "$$TMPO" && \ + $(LD) -m elf32_x86_64 "$$TMPO" -o "$$TMP",y,n) + ifeq ($(x32_ld_ok),y) +diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile +index e398bb5..8a84501 100644 +--- a/arch/x86/boot/compressed/Makefile ++++ b/arch/x86/boot/compressed/Makefile +@@ -28,6 +28,9 @@ VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ + $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \ + $(obj)/piggy.o + ++$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone ++$(obj)/efi_stub_$(BITS).o: KBUILD_CLFAGS += -fshort-wchar -mno-red-zone ++ + ifeq ($(CONFIG_EFI_STUB), y) + VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o + endif +diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h +index 49afb3f..c3520d7 100644 +--- a/arch/x86/include/asm/pgtable.h ++++ b/arch/x86/include/asm/pgtable.h +@@ -146,8 +146,7 @@ static inline unsigned long pmd_pfn(pmd_t pmd) + + static inline int pmd_large(pmd_t pte) + { +- return (pmd_flags(pte) & (_PAGE_PSE | _PAGE_PRESENT)) == +- (_PAGE_PSE | _PAGE_PRESENT); ++ return pmd_flags(pte) & _PAGE_PSE; + } + + #ifdef CONFIG_TRANSPARENT_HUGEPAGE +@@ -415,7 +414,13 @@ static inline int pte_hidden(pte_t pte) + + static inline int pmd_present(pmd_t pmd) + { +- return pmd_flags(pmd) & _PAGE_PRESENT; ++ /* ++ * Checking for _PAGE_PSE is needed too because ++ * split_huge_page will temporarily clear the present bit (but ++ * the _PAGE_PSE flag will remain set at all times while the ++ * _PAGE_PRESENT bit is clear). ++ */ ++ return pmd_flags(pmd) & (_PAGE_PRESENT | _PAGE_PROTNONE | _PAGE_PSE); + } + + static inline int pmd_none(pmd_t pmd) +diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h +index 93971e8..472b9b7 100644 +--- a/arch/x86/include/asm/xen/page.h ++++ b/arch/x86/include/asm/xen/page.h +@@ -51,7 +51,8 @@ extern unsigned long set_phys_range_identity(unsigned long pfn_s, + + extern int m2p_add_override(unsigned long mfn, struct page *page, + struct gnttab_map_grant_ref *kmap_op); +-extern int m2p_remove_override(struct page *page, bool clear_pte); ++extern int m2p_remove_override(struct page *page, ++ struct gnttab_map_grant_ref *kmap_op); + extern struct page *m2p_find_override(unsigned long mfn); + extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn); + +diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c +index 1f84794..bda833c 100644 +--- a/arch/x86/kernel/alternative.c ++++ b/arch/x86/kernel/alternative.c +@@ -160,7 +160,7 @@ static const unsigned char * const k7_nops[ASM_NOP_MAX+2] = + #endif + + #ifdef P6_NOP1 +-static const unsigned char __initconst_or_module p6nops[] = ++static const unsigned char p6nops[] = + { + P6_NOP1, + P6_NOP2, +@@ -219,7 +219,7 @@ void __init arch_init_ideal_nops(void) + ideal_nops = intel_nops; + #endif + } +- ++ break; + default: + #ifdef CONFIG_X86_64 + ideal_nops = k8_nops; +diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c +index 6b9333b..cc9c146 100644 +--- a/arch/x86/kernel/cpu/common.c ++++ b/arch/x86/kernel/cpu/common.c +@@ -144,6 +144,8 @@ static int __init x86_xsave_setup(char *s) + { + setup_clear_cpu_cap(X86_FEATURE_XSAVE); + setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); ++ setup_clear_cpu_cap(X86_FEATURE_AVX); ++ setup_clear_cpu_cap(X86_FEATURE_AVX2); + return 1; + } + __setup("noxsave", x86_xsave_setup); +diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c +index da27c5d..c46ed49 100644 +--- a/arch/x86/kernel/cpu/mcheck/mce.c ++++ b/arch/x86/kernel/cpu/mcheck/mce.c +@@ -1186,6 +1186,7 @@ void mce_notify_process(void) + { + unsigned long pfn; + struct mce_info *mi = mce_find_info(); ++ int flags = MF_ACTION_REQUIRED; + + if (!mi) + mce_panic("Lost physical address for unconsumed uncorrectable error", NULL, NULL); +@@ -1200,8 +1201,9 @@ void mce_notify_process(void) + * doomed. We still need to mark the page as poisoned and alert any + * other users of the page. + */ +- if (memory_failure(pfn, MCE_VECTOR, MF_ACTION_REQUIRED) < 0 || +- mi->restartable == 0) { ++ if (!mi->restartable) ++ flags |= MF_MUST_KILL; ++ if (memory_failure(pfn, MCE_VECTOR, flags) < 0) { + pr_err("Memory error not recovered"); + force_sig(SIGBUS, current); + } +diff --git a/arch/x86/kernel/cpu/perf_event_amd_ibs.c b/arch/x86/kernel/cpu/perf_event_amd_ibs.c +index da9bcdc..4018f6e 100644 +--- a/arch/x86/kernel/cpu/perf_event_amd_ibs.c ++++ b/arch/x86/kernel/cpu/perf_event_amd_ibs.c +@@ -207,6 +207,15 @@ static int perf_ibs_precise_event(struct perf_event *event, u64 *config) + return -EOPNOTSUPP; + } + ++static const struct perf_event_attr ibs_notsupp = { ++ .exclude_user = 1, ++ .exclude_kernel = 1, ++ .exclude_hv = 1, ++ .exclude_idle = 1, ++ .exclude_host = 1, ++ .exclude_guest = 1, ++}; ++ + static int perf_ibs_init(struct perf_event *event) + { + struct hw_perf_event *hwc = &event->hw; +@@ -227,6 +236,9 @@ static int perf_ibs_init(struct perf_event *event) + if (event->pmu != &perf_ibs->pmu) + return -ENOENT; + ++ if (perf_flags(&event->attr) & perf_flags(&ibs_notsupp)) ++ return -EINVAL; ++ + if (config & ~perf_ibs->config_mask) + return -EINVAL; + +diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c +index 8a2ce8f..82746f9 100644 +--- a/arch/x86/kernel/microcode_amd.c ++++ b/arch/x86/kernel/microcode_amd.c +@@ -143,11 +143,12 @@ static int get_matching_microcode(int cpu, const u8 *ucode_ptr, + unsigned int *current_size) + { + struct microcode_header_amd *mc_hdr; +- unsigned int actual_size; ++ unsigned int actual_size, patch_size; + u16 equiv_cpu_id; + + /* size of the current patch we're staring at */ +- *current_size = *(u32 *)(ucode_ptr + 4) + SECTION_HDR_SIZE; ++ patch_size = *(u32 *)(ucode_ptr + 4); ++ *current_size = patch_size + SECTION_HDR_SIZE; + + equiv_cpu_id = find_equiv_id(); + if (!equiv_cpu_id) +@@ -174,7 +175,7 @@ static int get_matching_microcode(int cpu, const u8 *ucode_ptr, + /* + * now that the header looks sane, verify its size + */ +- actual_size = verify_ucode_size(cpu, *current_size, leftover_size); ++ actual_size = verify_ucode_size(cpu, patch_size, leftover_size); + if (!actual_size) + return 0; + +diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c +index fbdfc69..24b852b 100644 +--- a/arch/x86/kernel/microcode_core.c ++++ b/arch/x86/kernel/microcode_core.c +@@ -298,19 +298,31 @@ static ssize_t reload_store(struct device *dev, + const char *buf, size_t size) + { + unsigned long val; +- int cpu = dev->id; +- ssize_t ret = 0; ++ int cpu; ++ ssize_t ret = 0, tmp_ret; ++ ++ /* allow reload only from the BSP */ ++ if (boot_cpu_data.cpu_index != dev->id) ++ return -EINVAL; + + ret = kstrtoul(buf, 0, &val); + if (ret) + return ret; + +- if (val == 1) { +- get_online_cpus(); +- if (cpu_online(cpu)) +- ret = reload_for_cpu(cpu); +- put_online_cpus(); ++ if (val != 1) ++ return size; ++ ++ get_online_cpus(); ++ for_each_online_cpu(cpu) { ++ tmp_ret = reload_for_cpu(cpu); ++ if (tmp_ret != 0) ++ pr_warn("Error reloading microcode on CPU %d\n", cpu); ++ ++ /* save retval of the first encountered reload error */ ++ if (!ret) ++ ret = tmp_ret; + } ++ put_online_cpus(); + + if (!ret) + ret = size; +diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c +index f95d242..4837375 100644 +--- a/arch/x86/kvm/emulate.c ++++ b/arch/x86/kvm/emulate.c +@@ -4426,12 +4426,12 @@ twobyte_insn: + break; + case 0xb6 ... 0xb7: /* movzx */ + ctxt->dst.bytes = ctxt->op_bytes; +- ctxt->dst.val = (ctxt->d & ByteOp) ? (u8) ctxt->src.val ++ ctxt->dst.val = (ctxt->src.bytes == 1) ? (u8) ctxt->src.val + : (u16) ctxt->src.val; + break; + case 0xbe ... 0xbf: /* movsx */ + ctxt->dst.bytes = ctxt->op_bytes; +- ctxt->dst.val = (ctxt->d & ByteOp) ? (s8) ctxt->src.val : ++ ctxt->dst.val = (ctxt->src.bytes == 1) ? (s8) ctxt->src.val : + (s16) ctxt->src.val; + break; + case 0xc0 ... 0xc1: /* xadd */ +diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c +index 81cf4fa..0147d16 100644 +--- a/arch/x86/kvm/i8259.c ++++ b/arch/x86/kvm/i8259.c +@@ -305,6 +305,11 @@ static void pic_ioport_write(void *opaque, u32 addr, u32 val) + addr &= 1; + if (addr == 0) { + if (val & 0x10) { ++ u8 edge_irr = s->irr & ~s->elcr; ++ int i; ++ bool found; ++ struct kvm_vcpu *vcpu; ++ + s->init4 = val & 1; + s->last_irr = 0; + s->irr &= s->elcr; +@@ -322,6 +327,18 @@ static void pic_ioport_write(void *opaque, u32 addr, u32 val) + if (val & 0x08) + pr_pic_unimpl( + "level sensitive irq not supported"); ++ ++ kvm_for_each_vcpu(i, vcpu, s->pics_state->kvm) ++ if (kvm_apic_accept_pic_intr(vcpu)) { ++ found = true; ++ break; ++ } ++ ++ ++ if (found) ++ for (irq = 0; irq < PIC_NUM_PINS/2; irq++) ++ if (edge_irr & (1 << irq)) ++ pic_clear_isr(s, irq); + } else if (val & 0x08) { + if (val & 0x04) + s->poll = 1; +diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c +index 32eb588..61593fd 100644 +--- a/arch/x86/kvm/vmx.c ++++ b/arch/x86/kvm/vmx.c +@@ -1470,13 +1470,6 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx) + loadsegment(ds, vmx->host_state.ds_sel); + loadsegment(es, vmx->host_state.es_sel); + } +-#else +- /* +- * The sysexit path does not restore ds/es, so we must set them to +- * a reasonable value ourselves. +- */ +- loadsegment(ds, __USER_DS); +- loadsegment(es, __USER_DS); + #endif + reload_tss(); + #ifdef CONFIG_X86_64 +@@ -6273,6 +6266,19 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) + #endif + ); + ++#ifndef CONFIG_X86_64 ++ /* ++ * The sysexit path does not restore ds/es, so we must set them to ++ * a reasonable value ourselves. ++ * ++ * We can't defer this to vmx_load_host_state() since that function ++ * may be executed in interrupt context, which saves and restore segments ++ * around it, nullifying its effect. ++ */ ++ loadsegment(ds, __USER_DS); ++ loadsegment(es, __USER_DS); ++#endif ++ + vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP) + | (1 << VCPU_EXREG_RFLAGS) + | (1 << VCPU_EXREG_CPL) +diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c +index be6d549..14c290d 100644 +--- a/arch/x86/kvm/x86.c ++++ b/arch/x86/kvm/x86.c +@@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) + */ + getboottime(&boot); + ++ if (kvm->arch.kvmclock_offset) { ++ struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset); ++ boot = timespec_sub(boot, ts); ++ } + wc.sec = boot.tv_sec; + wc.nsec = boot.tv_nsec; + wc.version = version; +diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c +index f6679a7..b91e485 100644 +--- a/arch/x86/mm/hugetlbpage.c ++++ b/arch/x86/mm/hugetlbpage.c +@@ -56,9 +56,16 @@ static int vma_shareable(struct vm_area_struct *vma, unsigned long addr) + } + + /* +- * search for a shareable pmd page for hugetlb. ++ * Search for a shareable pmd page for hugetlb. In any case calls pmd_alloc() ++ * and returns the corresponding pte. While this is not necessary for the ++ * !shared pmd case because we can allocate the pmd later as well, it makes the ++ * code much cleaner. pmd allocation is essential for the shared case because ++ * pud has to be populated inside the same i_mmap_mutex section - otherwise ++ * racing tasks could either miss the sharing (see huge_pte_offset) or select a ++ * bad pmd for sharing. + */ +-static void huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) ++static pte_t * ++huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) + { + struct vm_area_struct *vma = find_vma(mm, addr); + struct address_space *mapping = vma->vm_file->f_mapping; +@@ -68,9 +75,10 @@ static void huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) + struct vm_area_struct *svma; + unsigned long saddr; + pte_t *spte = NULL; ++ pte_t *pte; + + if (!vma_shareable(vma, addr)) +- return; ++ return (pte_t *)pmd_alloc(mm, pud, addr); + + mutex_lock(&mapping->i_mmap_mutex); + vma_prio_tree_foreach(svma, &iter, &mapping->i_mmap, idx, idx) { +@@ -97,7 +105,9 @@ static void huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) + put_page(virt_to_page(spte)); + spin_unlock(&mm->page_table_lock); + out: ++ pte = (pte_t *)pmd_alloc(mm, pud, addr); + mutex_unlock(&mapping->i_mmap_mutex); ++ return pte; + } + + /* +@@ -142,8 +152,9 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, + } else { + BUG_ON(sz != PMD_SIZE); + if (pud_none(*pud)) +- huge_pmd_share(mm, addr, pud); +- pte = (pte_t *) pmd_alloc(mm, pud, addr); ++ pte = huge_pmd_share(mm, addr, pud); ++ else ++ pte = (pte_t *)pmd_alloc(mm, pud, addr); + } + } + BUG_ON(pte && !pte_none(*pte) && !pte_huge(*pte)); +diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c +index 92660eda..f55a4ce 100644 +--- a/arch/x86/platform/efi/efi.c ++++ b/arch/x86/platform/efi/efi.c +@@ -890,6 +890,7 @@ void __init efi_enter_virtual_mode(void) + * + * Call EFI services through wrapper functions. + */ ++ efi.runtime_version = efi_systab.fw_revision; + efi.get_time = virt_efi_get_time; + efi.set_time = virt_efi_set_time; + efi.get_wakeup_time = virt_efi_get_wakeup_time; +diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl +index 51171ae..a582bfe 100644 +--- a/arch/x86/syscalls/syscall_64.tbl ++++ b/arch/x86/syscalls/syscall_64.tbl +@@ -60,8 +60,8 @@ + 51 common getsockname sys_getsockname + 52 common getpeername sys_getpeername + 53 common socketpair sys_socketpair +-54 common setsockopt sys_setsockopt +-55 common getsockopt sys_getsockopt ++54 64 setsockopt sys_setsockopt ++55 64 getsockopt sys_getsockopt + 56 common clone stub_clone + 57 common fork stub_fork + 58 common vfork stub_vfork +@@ -318,7 +318,7 @@ + 309 common getcpu sys_getcpu + 310 64 process_vm_readv sys_process_vm_readv + 311 64 process_vm_writev sys_process_vm_writev +-312 64 kcmp sys_kcmp ++312 common kcmp sys_kcmp + + # + # x32-specific system call numbers start at 512 to avoid cache impact +@@ -353,3 +353,5 @@ + 538 x32 sendmmsg compat_sys_sendmmsg + 539 x32 process_vm_readv compat_sys_process_vm_readv + 540 x32 process_vm_writev compat_sys_process_vm_writev ++541 x32 setsockopt compat_sys_setsockopt ++542 x32 getsockopt compat_sys_getsockopt +diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c +index ff962d4..405307f 100644 +--- a/arch/x86/xen/enlighten.c ++++ b/arch/x86/xen/enlighten.c +@@ -1422,6 +1422,10 @@ asmlinkage void __init xen_start_kernel(void) + pci_request_acs(); + + xen_acpi_sleep_register(); ++ ++ /* Avoid searching for BIOS MP tables */ ++ x86_init.mpparse.find_smp_config = x86_init_noop; ++ x86_init.mpparse.get_smp_config = x86_init_uint_noop; + } + #ifdef CONFIG_PCI + /* PCI BIOS service won't work from a PV guest. */ +diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c +index 64effdc..72213da 100644 +--- a/arch/x86/xen/p2m.c ++++ b/arch/x86/xen/p2m.c +@@ -194,6 +194,13 @@ RESERVE_BRK(p2m_mid_mfn, PAGE_SIZE * (MAX_DOMAIN_PAGES / (P2M_PER_PAGE * P2M_MID + * boundary violation will require three middle nodes. */ + RESERVE_BRK(p2m_mid_identity, PAGE_SIZE * 2 * 3); + ++/* When we populate back during bootup, the amount of pages can vary. The ++ * max we have is seen is 395979, but that does not mean it can't be more. ++ * Some machines can have 3GB I/O holes even. With early_can_reuse_p2m_middle ++ * it can re-use Xen provided mfn_list array, so we only need to allocate at ++ * most three P2M top nodes. */ ++RESERVE_BRK(p2m_populated, PAGE_SIZE * 3); ++ + static inline unsigned p2m_top_index(unsigned long pfn) + { + BUG_ON(pfn >= MAX_P2M_PFN); +@@ -570,12 +577,99 @@ static bool __init early_alloc_p2m(unsigned long pfn) + } + return true; + } ++ ++/* ++ * Skim over the P2M tree looking at pages that are either filled with ++ * INVALID_P2M_ENTRY or with 1:1 PFNs. If found, re-use that page and ++ * replace the P2M leaf with a p2m_missing or p2m_identity. ++ * Stick the old page in the new P2M tree location. ++ */ ++bool __init early_can_reuse_p2m_middle(unsigned long set_pfn, unsigned long set_mfn) ++{ ++ unsigned topidx; ++ unsigned mididx; ++ unsigned ident_pfns; ++ unsigned inv_pfns; ++ unsigned long *p2m; ++ unsigned long *mid_mfn_p; ++ unsigned idx; ++ unsigned long pfn; ++ ++ /* We only look when this entails a P2M middle layer */ ++ if (p2m_index(set_pfn)) ++ return false; ++ ++ for (pfn = 0; pfn < MAX_DOMAIN_PAGES; pfn += P2M_PER_PAGE) { ++ topidx = p2m_top_index(pfn); ++ ++ if (!p2m_top[topidx]) ++ continue; ++ ++ if (p2m_top[topidx] == p2m_mid_missing) ++ continue; ++ ++ mididx = p2m_mid_index(pfn); ++ p2m = p2m_top[topidx][mididx]; ++ if (!p2m) ++ continue; ++ ++ if ((p2m == p2m_missing) || (p2m == p2m_identity)) ++ continue; ++ ++ if ((unsigned long)p2m == INVALID_P2M_ENTRY) ++ continue; ++ ++ ident_pfns = 0; ++ inv_pfns = 0; ++ for (idx = 0; idx < P2M_PER_PAGE; idx++) { ++ /* IDENTITY_PFNs are 1:1 */ ++ if (p2m[idx] == IDENTITY_FRAME(pfn + idx)) ++ ident_pfns++; ++ else if (p2m[idx] == INVALID_P2M_ENTRY) ++ inv_pfns++; ++ else ++ break; ++ } ++ if ((ident_pfns == P2M_PER_PAGE) || (inv_pfns == P2M_PER_PAGE)) ++ goto found; ++ } ++ return false; ++found: ++ /* Found one, replace old with p2m_identity or p2m_missing */ ++ p2m_top[topidx][mididx] = (ident_pfns ? p2m_identity : p2m_missing); ++ /* And the other for save/restore.. */ ++ mid_mfn_p = p2m_top_mfn_p[topidx]; ++ /* NOTE: Even if it is a p2m_identity it should still be point to ++ * a page filled with INVALID_P2M_ENTRY entries. */ ++ mid_mfn_p[mididx] = virt_to_mfn(p2m_missing); ++ ++ /* Reset where we want to stick the old page in. */ ++ topidx = p2m_top_index(set_pfn); ++ mididx = p2m_mid_index(set_pfn); ++ ++ /* This shouldn't happen */ ++ if (WARN_ON(p2m_top[topidx] == p2m_mid_missing)) ++ early_alloc_p2m(set_pfn); ++ ++ if (WARN_ON(p2m_top[topidx][mididx] != p2m_missing)) ++ return false; ++ ++ p2m_init(p2m); ++ p2m_top[topidx][mididx] = p2m; ++ mid_mfn_p = p2m_top_mfn_p[topidx]; ++ mid_mfn_p[mididx] = virt_to_mfn(p2m); ++ ++ return true; ++} + bool __init early_set_phys_to_machine(unsigned long pfn, unsigned long mfn) + { + if (unlikely(!__set_phys_to_machine(pfn, mfn))) { + if (!early_alloc_p2m(pfn)) + return false; + ++ if (early_can_reuse_p2m_middle(pfn, mfn)) ++ return __set_phys_to_machine(pfn, mfn); ++ + if (!early_alloc_p2m_middle(pfn, false /* boundary crossover OK!*/)) + return false; + +@@ -734,9 +828,6 @@ int m2p_add_override(unsigned long mfn, struct page *page, + + xen_mc_issue(PARAVIRT_LAZY_MMU); + } +- /* let's use dev_bus_addr to record the old mfn instead */ +- kmap_op->dev_bus_addr = page->index; +- page->index = (unsigned long) kmap_op; + } + spin_lock_irqsave(&m2p_override_lock, flags); + list_add(&page->lru, &m2p_overrides[mfn_hash(mfn)]); +@@ -763,7 +854,8 @@ int m2p_add_override(unsigned long mfn, struct page *page, + return 0; + } + EXPORT_SYMBOL_GPL(m2p_add_override); +-int m2p_remove_override(struct page *page, bool clear_pte) ++int m2p_remove_override(struct page *page, ++ struct gnttab_map_grant_ref *kmap_op) + { + unsigned long flags; + unsigned long mfn; +@@ -793,10 +885,8 @@ int m2p_remove_override(struct page *page, bool clear_pte) + WARN_ON(!PagePrivate(page)); + ClearPagePrivate(page); + +- if (clear_pte) { +- struct gnttab_map_grant_ref *map_op = +- (struct gnttab_map_grant_ref *) page->index; +- set_phys_to_machine(pfn, map_op->dev_bus_addr); ++ set_phys_to_machine(pfn, page->index); ++ if (kmap_op != NULL) { + if (!PageHighMem(page)) { + struct multicall_space mcs; + struct gnttab_unmap_grant_ref *unmap_op; +@@ -808,13 +898,13 @@ int m2p_remove_override(struct page *page, bool clear_pte) + * issued. In this case handle is going to -1 because + * it hasn't been modified yet. + */ +- if (map_op->handle == -1) ++ if (kmap_op->handle == -1) + xen_mc_flush(); + /* +- * Now if map_op->handle is negative it means that the ++ * Now if kmap_op->handle is negative it means that the + * hypercall actually returned an error. + */ +- if (map_op->handle == GNTST_general_error) { ++ if (kmap_op->handle == GNTST_general_error) { + printk(KERN_WARNING "m2p_remove_override: " + "pfn %lx mfn %lx, failed to modify kernel mappings", + pfn, mfn); +@@ -824,8 +914,8 @@ int m2p_remove_override(struct page *page, bool clear_pte) + mcs = xen_mc_entry( + sizeof(struct gnttab_unmap_grant_ref)); + unmap_op = mcs.args; +- unmap_op->host_addr = map_op->host_addr; +- unmap_op->handle = map_op->handle; ++ unmap_op->host_addr = kmap_op->host_addr; ++ unmap_op->handle = kmap_op->handle; + unmap_op->dev_bus_addr = 0; + + MULTI_grant_table_op(mcs.mc, +@@ -836,10 +926,9 @@ int m2p_remove_override(struct page *page, bool clear_pte) + set_pte_at(&init_mm, address, ptep, + pfn_pte(pfn, PAGE_KERNEL)); + __flush_tlb_single(address); +- map_op->host_addr = 0; ++ kmap_op->host_addr = 0; + } +- } else +- set_phys_to_machine(pfn, page->index); ++ } + + /* p2m(m2p(mfn)) == FOREIGN_FRAME(mfn): the mfn is already present + * somewhere in this domain, even before being added to the +diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c +index a4790bf..c207fdb 100644 +--- a/arch/x86/xen/setup.c ++++ b/arch/x86/xen/setup.c +@@ -17,6 +17,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -78,9 +79,16 @@ static void __init xen_add_extra_mem(u64 start, u64 size) + memblock_reserve(start, size); + + xen_max_p2m_pfn = PFN_DOWN(start + size); ++ for (pfn = PFN_DOWN(start); pfn < xen_max_p2m_pfn; pfn++) { ++ unsigned long mfn = pfn_to_mfn(pfn); ++ ++ if (WARN(mfn == pfn, "Trying to over-write 1-1 mapping (pfn: %lx)\n", pfn)) ++ continue; ++ WARN(mfn != INVALID_P2M_ENTRY, "Trying to remove %lx which has %lx mfn!\n", ++ pfn, mfn); + +- for (pfn = PFN_DOWN(start); pfn <= xen_max_p2m_pfn; pfn++) + __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); ++ } + } + + static unsigned long __init xen_do_chunk(unsigned long start, +@@ -542,4 +550,7 @@ void __init xen_arch_setup(void) + disable_cpufreq(); + WARN_ON(set_pm_idle_to_default()); + fiddle_vdso(); ++#ifdef CONFIG_NUMA ++ numa_off = 1; ++#endif + } +diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c +index 2c8d6a3..bc44311 100644 +--- a/arch/xtensa/kernel/process.c ++++ b/arch/xtensa/kernel/process.c +@@ -31,6 +31,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -110,8 +111,10 @@ void cpu_idle(void) + + /* endless idle loop with no priority at all */ + while (1) { ++ rcu_idle_enter(); + while (!need_resched()) + platform_idle(); ++ rcu_idle_exit(); + schedule_preempt_disabled(); + } + } +diff --git a/block/blk-ioc.c b/block/blk-ioc.c +index 893b800..fab4cdd 100644 +--- a/block/blk-ioc.c ++++ b/block/blk-ioc.c +@@ -244,6 +244,7 @@ int create_task_io_context(struct task_struct *task, gfp_t gfp_flags, int node) + + /* initialize */ + atomic_long_set(&ioc->refcount, 1); ++ atomic_set(&ioc->nr_tasks, 1); + atomic_set(&ioc->active_ref, 1); + spin_lock_init(&ioc->lock); + INIT_RADIX_TREE(&ioc->icq_tree, GFP_ATOMIC | __GFP_HIGH); +diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c +index 6512b20..d1fcbc0 100644 +--- a/drivers/acpi/ac.c ++++ b/drivers/acpi/ac.c +@@ -292,7 +292,9 @@ static int acpi_ac_add(struct acpi_device *device) + 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 --git a/drivers/acpi/acpica/tbxface.c b/drivers/acpi/acpica/tbxface.c +index abcc641..33214d7 100644 +--- a/drivers/acpi/acpica/tbxface.c ++++ b/drivers/acpi/acpica/tbxface.c +@@ -436,6 +436,7 @@ acpi_get_table_with_size(char *signature, + + return (AE_NOT_FOUND); + } ++ACPI_EXPORT_SYMBOL(acpi_get_table_with_size) + + acpi_status + acpi_get_table(char *signature, +diff --git a/drivers/acpi/apei/apei-base.c b/drivers/acpi/apei/apei-base.c +index 6686b1e..00a7836 100644 +--- a/drivers/acpi/apei/apei-base.c ++++ b/drivers/acpi/apei/apei-base.c +@@ -586,6 +586,11 @@ static int apei_check_gar(struct acpi_generic_address *reg, u64 *paddr, + } + *access_bit_width = 1UL << (access_size_code + 2); + ++ /* Fixup common BIOS bug */ ++ if (bit_width == 32 && bit_offset == 0 && (*paddr & 0x03) == 0 && ++ *access_bit_width < 32) ++ *access_bit_width = 32; ++ + if ((bit_width + bit_offset) > *access_bit_width) { + pr_warning(FW_BUG APEI_PFX + "Invalid bit width + offset in GAR [0x%llx/%u/%u/%u/%u]\n", +diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c +index adceafd..54a5732 100644 +--- a/drivers/acpi/bus.c ++++ b/drivers/acpi/bus.c +@@ -237,6 +237,16 @@ static int __acpi_bus_get_power(struct acpi_device *device, int *state) + } else if (result == ACPI_STATE_D3_HOT) { + result = ACPI_STATE_D3; + } ++ ++ /* ++ * If we were unsure about the device parent's power state up to this ++ * point, the fact that the device is in D0 implies that the parent has ++ * to be in D0 too. ++ */ ++ if (device->parent && device->parent->power.state == ACPI_STATE_UNKNOWN ++ && result == ACPI_STATE_D0) ++ device->parent->power.state = ACPI_STATE_D0; ++ + *state = result; + + out: +@@ -980,8 +990,6 @@ static int __init acpi_bus_init(void) + status = acpi_ec_ecdt_probe(); + /* Ignore result. Not having an ECDT is not fatal. */ + +- acpi_bus_osc_support(); +- + status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION); + if (ACPI_FAILURE(status)) { + printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n"); +@@ -989,6 +997,12 @@ static int __init acpi_bus_init(void) + } + + /* ++ * _OSC method may exist in module level code, ++ * so it must be run after ACPI_FULL_INITIALIZATION ++ */ ++ acpi_bus_osc_support(); ++ ++ /* + * _PDC control method may load dynamic SSDT tables, + * and we need to install the table handler before that. + */ +diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c +index dd6d6a3..fe71911 100644 +--- a/drivers/acpi/power.c ++++ b/drivers/acpi/power.c +@@ -103,6 +103,7 @@ struct acpi_power_resource { + + /* List of devices relying on this power resource */ + struct acpi_power_resource_device *devices; ++ struct mutex devices_lock; + }; + + static struct list_head acpi_power_resource_list; +@@ -221,7 +222,6 @@ static void acpi_power_on_device(struct acpi_power_managed_device *device) + + static int __acpi_power_on(struct acpi_power_resource *resource) + { +- struct acpi_power_resource_device *device_list = resource->devices; + acpi_status status = AE_OK; + + status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL); +@@ -234,19 +234,15 @@ static int __acpi_power_on(struct acpi_power_resource *resource) + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n", + resource->name)); + +- while (device_list) { +- acpi_power_on_device(device_list->device); +- +- device_list = device_list->next; +- } +- + return 0; + } + + static int acpi_power_on(acpi_handle handle) + { + int result = 0; ++ bool resume_device = false; + struct acpi_power_resource *resource = NULL; ++ struct acpi_power_resource_device *device_list; + + result = acpi_power_get_context(handle, &resource); + if (result) +@@ -262,10 +258,25 @@ static int acpi_power_on(acpi_handle handle) + result = __acpi_power_on(resource); + if (result) + resource->ref_count--; ++ else ++ resume_device = true; + } + + mutex_unlock(&resource->resource_lock); + ++ if (!resume_device) ++ return result; ++ ++ mutex_lock(&resource->devices_lock); ++ ++ device_list = resource->devices; ++ while (device_list) { ++ acpi_power_on_device(device_list->device); ++ device_list = device_list->next; ++ } ++ ++ mutex_unlock(&resource->devices_lock); ++ + return result; + } + +@@ -351,7 +362,7 @@ static void __acpi_power_resource_unregister_device(struct device *dev, + if (acpi_power_get_context(res_handle, &resource)) + return; + +- mutex_lock(&resource->resource_lock); ++ mutex_lock(&resource->devices_lock); + prev = NULL; + curr = resource->devices; + while (curr) { +@@ -368,7 +379,7 @@ static void __acpi_power_resource_unregister_device(struct device *dev, + prev = curr; + curr = curr->next; + } +- mutex_unlock(&resource->resource_lock); ++ mutex_unlock(&resource->devices_lock); + } + + /* Unlink dev from all power resources in _PR0 */ +@@ -409,10 +420,10 @@ static int __acpi_power_resource_register_device( + + power_resource_device->device = powered_device; + +- mutex_lock(&resource->resource_lock); ++ mutex_lock(&resource->devices_lock); + power_resource_device->next = resource->devices; + resource->devices = power_resource_device; +- mutex_unlock(&resource->resource_lock); ++ mutex_unlock(&resource->devices_lock); + + return 0; + } +@@ -457,7 +468,7 @@ int acpi_power_resource_register_device(struct device *dev, acpi_handle handle) + return ret; + + no_power_resource: +- printk(KERN_WARNING PREFIX "Invalid Power Resource to register!"); ++ printk(KERN_DEBUG PREFIX "Invalid Power Resource to register!"); + return -ENODEV; + } + +@@ -715,6 +726,7 @@ static int acpi_power_add(struct acpi_device *device) + + resource->device = device; + mutex_init(&resource->resource_lock); ++ mutex_init(&resource->devices_lock); + strcpy(resource->name, device->pnp.bus_id); + strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); + strcpy(acpi_device_class(device), ACPI_POWER_CLASS); +diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c +index 0734086..bbac51e 100644 +--- a/drivers/acpi/processor_driver.c ++++ b/drivers/acpi/processor_driver.c +@@ -442,7 +442,7 @@ static int acpi_cpu_soft_notify(struct notifier_block *nfb, + /* Normal CPU soft online event */ + } else { + acpi_processor_ppc_has_changed(pr, 0); +- acpi_processor_cst_has_changed(pr); ++ acpi_processor_hotplug(pr); + acpi_processor_reevaluate_tstate(pr, action); + acpi_processor_tstate_has_changed(pr); + } +diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c +index ebaf67e..93cbc44 100644 +--- a/drivers/ata/ahci.c ++++ b/drivers/ata/ahci.c +@@ -396,6 +396,8 @@ static const struct pci_device_id ahci_pci_tbl[] = { + .driver_data = board_ahci_yes_fbs }, /* 88se9125 */ + { PCI_DEVICE(0x1b4b, 0x917a), + .driver_data = board_ahci_yes_fbs }, /* 88se9172 */ ++ { PCI_DEVICE(0x1b4b, 0x9192), ++ .driver_data = board_ahci_yes_fbs }, /* 88se9172 on some Gigabyte */ + { PCI_DEVICE(0x1b4b, 0x91a3), + .driver_data = board_ahci_yes_fbs }, + +diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c +index cece3a4..71e8385 100644 +--- a/drivers/ata/libata-core.c ++++ b/drivers/ata/libata-core.c +@@ -4126,6 +4126,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = { + + /* Devices which aren't very happy with higher link speeds */ + { "WD My Book", NULL, ATA_HORKAGE_1_5_GBPS, }, ++ { "Seagate FreeAgent GoFlex", NULL, ATA_HORKAGE_1_5_GBPS, }, + + /* + * Devices which choke on SETXFER. Applies only if both the +diff --git a/drivers/base/core.c b/drivers/base/core.c +index 346be8b..b18138a 100644 +--- a/drivers/base/core.c ++++ b/drivers/base/core.c +@@ -1848,6 +1848,7 @@ int __dev_printk(const char *level, const struct device *dev, + struct va_format *vaf) + { + char dict[128]; ++ const char *level_extra = ""; + size_t dictlen = 0; + const char *subsys; + +@@ -1894,10 +1895,14 @@ int __dev_printk(const char *level, const struct device *dev, + "DEVICE=+%s:%s", subsys, dev_name(dev)); + } + skip: ++ if (level[3]) ++ level_extra = &level[3]; /* skip past "" */ ++ + return printk_emit(0, level[1] - '0', + dictlen ? dict : NULL, dictlen, +- "%s %s: %pV", +- dev_driver_string(dev), dev_name(dev), vaf); ++ "%s %s: %s%pV", ++ dev_driver_string(dev), dev_name(dev), ++ level_extra, vaf); + } + EXPORT_SYMBOL(__dev_printk); + +diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c +index 9cb845e..9d54dce 100644 +--- a/drivers/base/power/main.c ++++ b/drivers/base/power/main.c +@@ -989,8 +989,16 @@ static int dpm_suspend_late(pm_message_t state) + int dpm_suspend_end(pm_message_t state) + { + int error = dpm_suspend_late(state); ++ if (error) ++ return error; ++ ++ error = dpm_suspend_noirq(state); ++ if (error) { ++ dpm_resume_early(resume_event(state)); ++ return error; ++ } + +- return error ? : dpm_suspend_noirq(state); ++ return 0; + } + EXPORT_SYMBOL_GPL(dpm_suspend_end); + +diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c +index 5989487..7d9c1cb 100644 +--- a/drivers/base/power/runtime.c ++++ b/drivers/base/power/runtime.c +@@ -147,6 +147,8 @@ static int rpm_check_suspend_allowed(struct device *dev) + || (dev->power.request_pending + && dev->power.request == RPM_REQ_RESUME)) + retval = -EAGAIN; ++ else if (__dev_pm_qos_read_value(dev) < 0) ++ retval = -EPERM; + else if (dev->power.runtime_status == RPM_SUSPENDED) + retval = 1; + +@@ -388,7 +390,6 @@ static int rpm_suspend(struct device *dev, int rpmflags) + goto repeat; + } + +- dev->power.deferred_resume = false; + if (dev->power.no_callbacks) + goto no_callback; /* Assume success. */ + +@@ -403,12 +404,6 @@ static int rpm_suspend(struct device *dev, int rpmflags) + goto out; + } + +- if (__dev_pm_qos_read_value(dev) < 0) { +- /* Negative PM QoS constraint means "never suspend". */ +- retval = -EPERM; +- goto out; +- } +- + __update_runtime_status(dev, RPM_SUSPENDING); + + if (dev->pm_domain) +@@ -440,6 +435,7 @@ static int rpm_suspend(struct device *dev, int rpmflags) + wake_up_all(&dev->power.wait_queue); + + if (dev->power.deferred_resume) { ++ dev->power.deferred_resume = false; + rpm_resume(dev, 0); + retval = -EAGAIN; + goto out; +@@ -584,6 +580,7 @@ static int rpm_resume(struct device *dev, int rpmflags) + || dev->parent->power.runtime_status == RPM_ACTIVE) { + atomic_inc(&dev->parent->power.child_count); + spin_unlock(&dev->parent->power.lock); ++ retval = 1; + goto no_callback; /* Assume success. */ + } + spin_unlock(&dev->parent->power.lock); +@@ -664,7 +661,7 @@ static int rpm_resume(struct device *dev, int rpmflags) + } + wake_up_all(&dev->power.wait_queue); + +- if (!retval) ++ if (retval >= 0) + rpm_idle(dev, RPM_ASYNC); + + out: +diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c +index de0435e..887f68f 100644 +--- a/drivers/block/aoe/aoecmd.c ++++ b/drivers/block/aoe/aoecmd.c +@@ -35,6 +35,7 @@ new_skb(ulong len) + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb->protocol = __constant_htons(ETH_P_AOE); ++ skb_checksum_none_assert(skb); + } + return skb; + } +diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c +index acda773..da33111 100644 +--- a/drivers/block/cciss_scsi.c ++++ b/drivers/block/cciss_scsi.c +@@ -763,16 +763,7 @@ static void complete_scsi_command(CommandList_struct *c, int timeout, + { + case CMD_TARGET_STATUS: + /* Pass it up to the upper layers... */ +- if( ei->ScsiStatus) +- { +-#if 0 +- printk(KERN_WARNING "cciss: cmd %p " +- "has SCSI Status = %x\n", +- c, ei->ScsiStatus); +-#endif +- cmd->result |= (ei->ScsiStatus << 1); +- } +- else { /* scsi status is zero??? How??? */ ++ if (!ei->ScsiStatus) { + + /* Ordinarily, this case should never happen, but there is a bug + in some released firmware revisions that allows it to happen +@@ -804,6 +795,7 @@ static void complete_scsi_command(CommandList_struct *c, int timeout, + } + break; + case CMD_PROTOCOL_ERR: ++ cmd->result = DID_ERROR << 16; + dev_warn(&h->pdev->dev, + "%p has protocol error\n", c); + break; +diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c +index 061427a75d..3c4c225 100644 +--- a/drivers/block/nbd.c ++++ b/drivers/block/nbd.c +@@ -445,6 +445,14 @@ static void nbd_clear_que(struct nbd_device *nbd) + req->errors++; + nbd_end_request(req); + } ++ ++ while (!list_empty(&nbd->waiting_queue)) { ++ req = list_entry(nbd->waiting_queue.next, struct request, ++ queuelist); ++ list_del_init(&req->queuelist); ++ req->errors++; ++ nbd_end_request(req); ++ } + } + + +@@ -594,6 +602,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd, + nbd->file = NULL; + nbd_clear_que(nbd); + BUG_ON(!list_empty(&nbd->queue_head)); ++ BUG_ON(!list_empty(&nbd->waiting_queue)); + if (file) + fput(file); + return 0; +diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c +index 693187d..774c31d 100644 +--- a/drivers/block/virtio_blk.c ++++ b/drivers/block/virtio_blk.c +@@ -21,8 +21,6 @@ struct workqueue_struct *virtblk_wq; + + struct virtio_blk + { +- spinlock_t lock; +- + struct virtio_device *vdev; + struct virtqueue *vq; + +@@ -65,7 +63,7 @@ static void blk_done(struct virtqueue *vq) + unsigned int len; + unsigned long flags; + +- spin_lock_irqsave(&vblk->lock, flags); ++ spin_lock_irqsave(vblk->disk->queue->queue_lock, flags); + while ((vbr = virtqueue_get_buf(vblk->vq, &len)) != NULL) { + int error; + +@@ -99,7 +97,7 @@ static void blk_done(struct virtqueue *vq) + } + /* In case queue is stopped waiting for more buffers. */ + blk_start_queue(vblk->disk->queue); +- spin_unlock_irqrestore(&vblk->lock, flags); ++ spin_unlock_irqrestore(vblk->disk->queue->queue_lock, flags); + } + + static bool do_req(struct request_queue *q, struct virtio_blk *vblk, +@@ -431,7 +429,6 @@ static int __devinit virtblk_probe(struct virtio_device *vdev) + goto out_free_index; + } + +- spin_lock_init(&vblk->lock); + vblk->vdev = vdev; + vblk->sg_elems = sg_elems; + sg_init_table(vblk->sg, vblk->sg_elems); +@@ -456,7 +453,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev) + goto out_mempool; + } + +- q = vblk->disk->queue = blk_init_queue(do_virtblk_request, &vblk->lock); ++ q = vblk->disk->queue = blk_init_queue(do_virtblk_request, NULL); + if (!q) { + err = -ENOMEM; + goto out_put_disk; +@@ -576,30 +573,20 @@ static void __devexit virtblk_remove(struct virtio_device *vdev) + { + struct virtio_blk *vblk = vdev->priv; + int index = vblk->index; +- struct virtblk_req *vbr; +- unsigned long flags; + + /* Prevent config work handler from accessing the device. */ + mutex_lock(&vblk->config_lock); + vblk->config_enable = false; + mutex_unlock(&vblk->config_lock); + ++ del_gendisk(vblk->disk); ++ blk_cleanup_queue(vblk->disk->queue); ++ + /* Stop all the virtqueues. */ + vdev->config->reset(vdev); + + flush_work(&vblk->config_work); + +- del_gendisk(vblk->disk); +- +- /* Abort requests dispatched to driver. */ +- spin_lock_irqsave(&vblk->lock, flags); +- while ((vbr = virtqueue_detach_unused_buf(vblk->vq))) { +- __blk_end_request_all(vbr->req, -EIO); +- mempool_free(vbr, vblk->pool); +- } +- spin_unlock_irqrestore(&vblk->lock, flags); +- +- blk_cleanup_queue(vblk->disk->queue); + put_disk(vblk->disk); + mempool_destroy(vblk->pool); + vdev->config->del_vqs(vdev); +diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c +index 73f196c..c6decb9 100644 +--- a/drivers/block/xen-blkback/blkback.c ++++ b/drivers/block/xen-blkback/blkback.c +@@ -337,7 +337,7 @@ static void xen_blkbk_unmap(struct pending_req *req) + invcount++; + } + +- ret = gnttab_unmap_refs(unmap, pages, invcount, false); ++ ret = gnttab_unmap_refs(unmap, NULL, pages, invcount); + BUG_ON(ret); + } + +diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c +index 10308cd..fc2de55 100644 +--- a/drivers/bluetooth/ath3k.c ++++ b/drivers/bluetooth/ath3k.c +@@ -79,12 +79,14 @@ static struct usb_device_id ath3k_table[] = { + { USB_DEVICE(0x13d3, 0x3362) }, + { USB_DEVICE(0x0CF3, 0xE004) }, + { USB_DEVICE(0x0930, 0x0219) }, ++ { USB_DEVICE(0x0489, 0xe057) }, + + /* Atheros AR5BBU12 with sflash firmware */ + { USB_DEVICE(0x0489, 0xE02C) }, + + /* Atheros AR5BBU22 with sflash firmware */ + { USB_DEVICE(0x0489, 0xE03C) }, ++ { USB_DEVICE(0x0489, 0xE036) }, + + { } /* Terminating entry */ + }; +@@ -104,9 +106,11 @@ static struct usb_device_id ath3k_blist_tbl[] = { + { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 }, + { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 }, + { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 }, ++ { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 }, + + /* Atheros AR5BBU22 with sflash firmware */ + { USB_DEVICE(0x0489, 0xE03C), .driver_info = BTUSB_ATH3012 }, ++ { USB_DEVICE(0x0489, 0xE036), .driver_info = BTUSB_ATH3012 }, + + { } /* Terminating entry */ + }; +diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c +index 83ebb24..b5f008c 100644 +--- a/drivers/bluetooth/btusb.c ++++ b/drivers/bluetooth/btusb.c +@@ -60,6 +60,9 @@ static struct usb_device_id btusb_table[] = { + /* Generic Bluetooth USB device */ + { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, + ++ /* Apple-specific (Broadcom) devices */ ++ { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01) }, ++ + /* Broadcom SoftSailing reporting vendor specific */ + { USB_DEVICE(0x0a5c, 0x21e1) }, + +@@ -102,15 +105,14 @@ static struct usb_device_id btusb_table[] = { + + /* Broadcom BCM20702A0 */ + { USB_DEVICE(0x0489, 0xe042) }, +- { USB_DEVICE(0x0a5c, 0x21e3) }, +- { USB_DEVICE(0x0a5c, 0x21e6) }, +- { USB_DEVICE(0x0a5c, 0x21e8) }, +- { USB_DEVICE(0x0a5c, 0x21f3) }, + { USB_DEVICE(0x413c, 0x8197) }, + + /* Foxconn - Hon Hai */ + { USB_DEVICE(0x0489, 0xe033) }, + ++ /*Broadcom devices with vendor specific id */ ++ { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01) }, ++ + { } /* Terminating entry */ + }; + +@@ -141,12 +143,14 @@ static struct usb_device_id blacklist_table[] = { + { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 }, + { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 }, + { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 }, ++ { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 }, + + /* Atheros AR5BBU12 with sflash firmware */ + { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE }, + + /* Atheros AR5BBU12 with sflash firmware */ + { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, ++ { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 }, + + /* Broadcom BCM2035 */ + { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU }, +diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c +index 8b78750..845f97f 100644 +--- a/drivers/char/mspec.c ++++ b/drivers/char/mspec.c +@@ -283,7 +283,7 @@ mspec_mmap(struct file *file, struct vm_area_struct *vma, + vdata->flags = flags; + vdata->type = type; + spin_lock_init(&vdata->lock); +- vdata->refcnt = ATOMIC_INIT(1); ++ atomic_set(&vdata->refcnt, 1); + vma->vm_private_data = vdata; + + vma->vm_flags |= (VM_IO | VM_RESERVED | VM_PFNMAP | VM_DONTEXPAND); +diff --git a/drivers/char/random.c b/drivers/char/random.c +index 4ec04a7..d98b2a6 100644 +--- a/drivers/char/random.c ++++ b/drivers/char/random.c +@@ -125,21 +125,26 @@ + * The current exported interfaces for gathering environmental noise + * from the devices are: + * ++ * void add_device_randomness(const void *buf, unsigned int size); + * void add_input_randomness(unsigned int type, unsigned int code, + * unsigned int value); +- * void add_interrupt_randomness(int irq); ++ * void add_interrupt_randomness(int irq, int irq_flags); + * void add_disk_randomness(struct gendisk *disk); + * ++ * add_device_randomness() is for adding data to the random pool that ++ * is likely to differ between two devices (or possibly even per boot). ++ * This would be things like MAC addresses or serial numbers, or the ++ * read-out of the RTC. This does *not* add any actual entropy to the ++ * pool, but it initializes the pool to different values for devices ++ * that might otherwise be identical and have very little entropy ++ * available to them (particularly common in the embedded world). ++ * + * add_input_randomness() uses the input layer interrupt timing, as well as + * the event type information from the hardware. + * +- * add_interrupt_randomness() uses the inter-interrupt timing as random +- * inputs to the entropy pool. Note that not all interrupts are good +- * sources of randomness! For example, the timer interrupts is not a +- * good choice, because the periodicity of the interrupts is too +- * regular, and hence predictable to an attacker. Network Interface +- * Controller interrupts are a better measure, since the timing of the +- * NIC interrupts are more unpredictable. ++ * add_interrupt_randomness() uses the interrupt timing as random ++ * inputs to the entropy pool. Using the cycle counters and the irq source ++ * as inputs, it feeds the randomness roughly once a second. + * + * add_disk_randomness() uses what amounts to the seek time of block + * layer request events, on a per-disk_devt basis, as input to the +@@ -248,6 +253,8 @@ + #include + #include + #include ++#include ++#include + + #ifdef CONFIG_GENERIC_HARDIRQS + # include +@@ -256,8 +263,12 @@ + #include + #include + #include ++#include + #include + ++#define CREATE_TRACE_POINTS ++#include ++ + /* + * Configuration information + */ +@@ -266,6 +277,8 @@ + #define SEC_XFER_SIZE 512 + #define EXTRACT_SIZE 10 + ++#define LONGS(x) (((x) + sizeof(unsigned long) - 1)/sizeof(unsigned long)) ++ + /* + * The minimum number of bits of entropy before we wake up a read on + * /dev/random. Should be enough to do a significant reseed. +@@ -420,8 +433,10 @@ struct entropy_store { + /* read-write data: */ + spinlock_t lock; + unsigned add_ptr; ++ unsigned input_rotate; + int entropy_count; +- int input_rotate; ++ int entropy_total; ++ unsigned int initialized:1; + __u8 last_data[EXTRACT_SIZE]; + }; + +@@ -454,6 +469,10 @@ static struct entropy_store nonblocking_pool = { + .pool = nonblocking_pool_data + }; + ++static __u32 const twist_table[8] = { ++ 0x00000000, 0x3b6e20c8, 0x76dc4190, 0x4db26158, ++ 0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 }; ++ + /* + * This function adds bytes into the entropy "pool". It does not + * update the entropy estimate. The caller should call +@@ -464,29 +483,24 @@ static struct entropy_store nonblocking_pool = { + * it's cheap to do so and helps slightly in the expected case where + * the entropy is concentrated in the low-order bits. + */ +-static void mix_pool_bytes_extract(struct entropy_store *r, const void *in, +- int nbytes, __u8 out[64]) ++static void _mix_pool_bytes(struct entropy_store *r, const void *in, ++ int nbytes, __u8 out[64]) + { +- static __u32 const twist_table[8] = { +- 0x00000000, 0x3b6e20c8, 0x76dc4190, 0x4db26158, +- 0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 }; + unsigned long i, j, tap1, tap2, tap3, tap4, tap5; + int input_rotate; + int wordmask = r->poolinfo->poolwords - 1; + const char *bytes = in; + __u32 w; +- unsigned long flags; + +- /* Taps are constant, so we can load them without holding r->lock. */ + tap1 = r->poolinfo->tap1; + tap2 = r->poolinfo->tap2; + tap3 = r->poolinfo->tap3; + tap4 = r->poolinfo->tap4; + tap5 = r->poolinfo->tap5; + +- spin_lock_irqsave(&r->lock, flags); +- input_rotate = r->input_rotate; +- i = r->add_ptr; ++ smp_rmb(); ++ input_rotate = ACCESS_ONCE(r->input_rotate); ++ i = ACCESS_ONCE(r->add_ptr); + + /* mix one byte at a time to simplify size handling and churn faster */ + while (nbytes--) { +@@ -513,19 +527,61 @@ static void mix_pool_bytes_extract(struct entropy_store *r, const void *in, + input_rotate += i ? 7 : 14; + } + +- r->input_rotate = input_rotate; +- r->add_ptr = i; ++ ACCESS_ONCE(r->input_rotate) = input_rotate; ++ ACCESS_ONCE(r->add_ptr) = i; ++ smp_wmb(); + + if (out) + for (j = 0; j < 16; j++) + ((__u32 *)out)[j] = r->pool[(i - j) & wordmask]; ++} ++ ++static void __mix_pool_bytes(struct entropy_store *r, const void *in, ++ int nbytes, __u8 out[64]) ++{ ++ trace_mix_pool_bytes_nolock(r->name, nbytes, _RET_IP_); ++ _mix_pool_bytes(r, in, nbytes, out); ++} ++ ++static void mix_pool_bytes(struct entropy_store *r, const void *in, ++ int nbytes, __u8 out[64]) ++{ ++ unsigned long flags; + ++ trace_mix_pool_bytes(r->name, nbytes, _RET_IP_); ++ spin_lock_irqsave(&r->lock, flags); ++ _mix_pool_bytes(r, in, nbytes, out); + spin_unlock_irqrestore(&r->lock, flags); + } + +-static void mix_pool_bytes(struct entropy_store *r, const void *in, int bytes) ++struct fast_pool { ++ __u32 pool[4]; ++ unsigned long last; ++ unsigned short count; ++ unsigned char rotate; ++ unsigned char last_timer_intr; ++}; ++ ++/* ++ * This is a fast mixing routine used by the interrupt randomness ++ * collector. It's hardcoded for an 128 bit pool and assumes that any ++ * locks that might be needed are taken by the caller. ++ */ ++static void fast_mix(struct fast_pool *f, const void *in, int nbytes) + { +- mix_pool_bytes_extract(r, in, bytes, NULL); ++ const char *bytes = in; ++ __u32 w; ++ unsigned i = f->count; ++ unsigned input_rotate = f->rotate; ++ ++ while (nbytes--) { ++ w = rol32(*bytes++, input_rotate & 31) ^ f->pool[i & 3] ^ ++ f->pool[(i + 1) & 3]; ++ f->pool[i & 3] = (w >> 3) ^ twist_table[w & 7]; ++ input_rotate += (i++ & 3) ? 7 : 14; ++ } ++ f->count = i; ++ f->rotate = input_rotate; + } + + /* +@@ -533,30 +589,38 @@ static void mix_pool_bytes(struct entropy_store *r, const void *in, int bytes) + */ + static void credit_entropy_bits(struct entropy_store *r, int nbits) + { +- unsigned long flags; +- int entropy_count; ++ int entropy_count, orig; + + if (!nbits) + return; + +- spin_lock_irqsave(&r->lock, flags); +- + DEBUG_ENT("added %d entropy credits to %s\n", nbits, r->name); +- entropy_count = r->entropy_count; ++retry: ++ entropy_count = orig = ACCESS_ONCE(r->entropy_count); + entropy_count += nbits; ++ + if (entropy_count < 0) { + DEBUG_ENT("negative entropy/overflow\n"); + entropy_count = 0; + } else if (entropy_count > r->poolinfo->POOLBITS) + entropy_count = r->poolinfo->POOLBITS; +- r->entropy_count = entropy_count; ++ if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig) ++ goto retry; ++ ++ if (!r->initialized && nbits > 0) { ++ r->entropy_total += nbits; ++ if (r->entropy_total > 128) ++ r->initialized = 1; ++ } ++ ++ trace_credit_entropy_bits(r->name, nbits, entropy_count, ++ r->entropy_total, _RET_IP_); + + /* should we wake readers? */ + if (r == &input_pool && entropy_count >= random_read_wakeup_thresh) { + wake_up_interruptible(&random_read_wait); + kill_fasync(&fasync, SIGIO, POLL_IN); + } +- spin_unlock_irqrestore(&r->lock, flags); + } + + /********************************************************************* +@@ -572,42 +636,24 @@ struct timer_rand_state { + unsigned dont_count_entropy:1; + }; + +-#ifndef CONFIG_GENERIC_HARDIRQS +- +-static struct timer_rand_state *irq_timer_state[NR_IRQS]; +- +-static struct timer_rand_state *get_timer_rand_state(unsigned int irq) +-{ +- return irq_timer_state[irq]; +-} +- +-static void set_timer_rand_state(unsigned int irq, +- struct timer_rand_state *state) +-{ +- irq_timer_state[irq] = state; +-} +- +-#else +- +-static struct timer_rand_state *get_timer_rand_state(unsigned int irq) +-{ +- struct irq_desc *desc; +- +- desc = irq_to_desc(irq); +- +- return desc->timer_rand_state; +-} +- +-static void set_timer_rand_state(unsigned int irq, +- struct timer_rand_state *state) ++/* ++ * Add device- or boot-specific data to the input and nonblocking ++ * pools to help initialize them to unique values. ++ * ++ * None of this adds any entropy, it is meant to avoid the ++ * problem of the nonblocking pool having similar initial state ++ * across largely identical devices. ++ */ ++void add_device_randomness(const void *buf, unsigned int size) + { +- struct irq_desc *desc; ++ unsigned long time = get_cycles() ^ jiffies; + +- desc = irq_to_desc(irq); +- +- desc->timer_rand_state = state; ++ mix_pool_bytes(&input_pool, buf, size, NULL); ++ mix_pool_bytes(&input_pool, &time, sizeof(time), NULL); ++ mix_pool_bytes(&nonblocking_pool, buf, size, NULL); ++ mix_pool_bytes(&nonblocking_pool, &time, sizeof(time), NULL); + } +-#endif ++EXPORT_SYMBOL(add_device_randomness); + + static struct timer_rand_state input_timer_state; + +@@ -637,13 +683,9 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num) + goto out; + + sample.jiffies = jiffies; +- +- /* Use arch random value, fall back to cycles */ +- if (!arch_get_random_int(&sample.cycles)) +- sample.cycles = get_cycles(); +- ++ sample.cycles = get_cycles(); + sample.num = num; +- mix_pool_bytes(&input_pool, &sample, sizeof(sample)); ++ mix_pool_bytes(&input_pool, &sample, sizeof(sample), NULL); + + /* + * Calculate number of bits of randomness we probably added. +@@ -700,17 +742,48 @@ void add_input_randomness(unsigned int type, unsigned int code, + } + EXPORT_SYMBOL_GPL(add_input_randomness); + +-void add_interrupt_randomness(int irq) ++static DEFINE_PER_CPU(struct fast_pool, irq_randomness); ++ ++void add_interrupt_randomness(int irq, int irq_flags) + { +- struct timer_rand_state *state; ++ struct entropy_store *r; ++ struct fast_pool *fast_pool = &__get_cpu_var(irq_randomness); ++ struct pt_regs *regs = get_irq_regs(); ++ unsigned long now = jiffies; ++ __u32 input[4], cycles = get_cycles(); ++ ++ input[0] = cycles ^ jiffies; ++ input[1] = irq; ++ if (regs) { ++ __u64 ip = instruction_pointer(regs); ++ input[2] = ip; ++ input[3] = ip >> 32; ++ } + +- state = get_timer_rand_state(irq); ++ fast_mix(fast_pool, input, sizeof(input)); + +- if (state == NULL) ++ if ((fast_pool->count & 1023) && ++ !time_after(now, fast_pool->last + HZ)) + return; + +- DEBUG_ENT("irq event %d\n", irq); +- add_timer_randomness(state, 0x100 + irq); ++ fast_pool->last = now; ++ ++ r = nonblocking_pool.initialized ? &input_pool : &nonblocking_pool; ++ __mix_pool_bytes(r, &fast_pool->pool, sizeof(fast_pool->pool), NULL); ++ /* ++ * If we don't have a valid cycle counter, and we see ++ * back-to-back timer interrupts, then skip giving credit for ++ * any entropy. ++ */ ++ if (cycles == 0) { ++ if (irq_flags & __IRQF_TIMER) { ++ if (fast_pool->last_timer_intr) ++ return; ++ fast_pool->last_timer_intr = 1; ++ } else ++ fast_pool->last_timer_intr = 0; ++ } ++ credit_entropy_bits(r, 1); + } + + #ifdef CONFIG_BLOCK +@@ -742,7 +815,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf, + */ + static void xfer_secondary_pool(struct entropy_store *r, size_t nbytes) + { +- __u32 tmp[OUTPUT_POOL_WORDS]; ++ __u32 tmp[OUTPUT_POOL_WORDS]; + + if (r->pull && r->entropy_count < nbytes * 8 && + r->entropy_count < r->poolinfo->POOLBITS) { +@@ -761,7 +834,7 @@ static void xfer_secondary_pool(struct entropy_store *r, size_t nbytes) + + bytes = extract_entropy(r->pull, tmp, bytes, + random_read_wakeup_thresh / 8, rsvd); +- mix_pool_bytes(r, tmp, bytes); ++ mix_pool_bytes(r, tmp, bytes, NULL); + credit_entropy_bits(r, bytes*8); + } + } +@@ -820,13 +893,19 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min, + static void extract_buf(struct entropy_store *r, __u8 *out) + { + int i; +- __u32 hash[5], workspace[SHA_WORKSPACE_WORDS]; ++ union { ++ __u32 w[5]; ++ unsigned long l[LONGS(EXTRACT_SIZE)]; ++ } hash; ++ __u32 workspace[SHA_WORKSPACE_WORDS]; + __u8 extract[64]; ++ unsigned long flags; + + /* Generate a hash across the pool, 16 words (512 bits) at a time */ +- sha_init(hash); ++ sha_init(hash.w); ++ spin_lock_irqsave(&r->lock, flags); + for (i = 0; i < r->poolinfo->poolwords; i += 16) +- sha_transform(hash, (__u8 *)(r->pool + i), workspace); ++ sha_transform(hash.w, (__u8 *)(r->pool + i), workspace); + + /* + * We mix the hash back into the pool to prevent backtracking +@@ -837,13 +916,14 @@ static void extract_buf(struct entropy_store *r, __u8 *out) + * brute-forcing the feedback as hard as brute-forcing the + * hash. + */ +- mix_pool_bytes_extract(r, hash, sizeof(hash), extract); ++ __mix_pool_bytes(r, hash.w, sizeof(hash.w), extract); ++ spin_unlock_irqrestore(&r->lock, flags); + + /* + * To avoid duplicates, we atomically extract a portion of the + * pool while mixing, and hash one final time. + */ +- sha_transform(hash, extract, workspace); ++ sha_transform(hash.w, extract, workspace); + memset(extract, 0, sizeof(extract)); + memset(workspace, 0, sizeof(workspace)); + +@@ -852,20 +932,32 @@ static void extract_buf(struct entropy_store *r, __u8 *out) + * pattern, we fold it in half. Thus, we always feed back + * twice as much data as we output. + */ +- hash[0] ^= hash[3]; +- hash[1] ^= hash[4]; +- hash[2] ^= rol32(hash[2], 16); +- memcpy(out, hash, EXTRACT_SIZE); +- memset(hash, 0, sizeof(hash)); ++ hash.w[0] ^= hash.w[3]; ++ hash.w[1] ^= hash.w[4]; ++ hash.w[2] ^= rol32(hash.w[2], 16); ++ ++ /* ++ * If we have a architectural hardware random number ++ * generator, mix that in, too. ++ */ ++ for (i = 0; i < LONGS(EXTRACT_SIZE); i++) { ++ unsigned long v; ++ if (!arch_get_random_long(&v)) ++ break; ++ hash.l[i] ^= v; ++ } ++ ++ memcpy(out, &hash, EXTRACT_SIZE); ++ memset(&hash, 0, sizeof(hash)); + } + + static ssize_t extract_entropy(struct entropy_store *r, void *buf, +- size_t nbytes, int min, int reserved) ++ size_t nbytes, int min, int reserved) + { + ssize_t ret = 0, i; + __u8 tmp[EXTRACT_SIZE]; +- unsigned long flags; + ++ trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_); + xfer_secondary_pool(r, nbytes); + nbytes = account(r, nbytes, min, reserved); + +@@ -873,6 +965,8 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf, + extract_buf(r, tmp); + + if (fips_enabled) { ++ unsigned long flags; ++ + spin_lock_irqsave(&r->lock, flags); + if (!memcmp(tmp, r->last_data, EXTRACT_SIZE)) + panic("Hardware RNG duplicated output!\n"); +@@ -898,6 +992,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf, + ssize_t ret = 0, i; + __u8 tmp[EXTRACT_SIZE]; + ++ trace_extract_entropy_user(r->name, nbytes, r->entropy_count, _RET_IP_); + xfer_secondary_pool(r, nbytes); + nbytes = account(r, nbytes, 0, 0); + +@@ -931,17 +1026,35 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf, + + /* + * This function is the exported kernel interface. It returns some +- * number of good random numbers, suitable for seeding TCP sequence +- * numbers, etc. ++ * number of good random numbers, suitable for key generation, seeding ++ * TCP sequence numbers, etc. It does not use the hw random number ++ * generator, if available; use get_random_bytes_arch() for that. + */ + void get_random_bytes(void *buf, int nbytes) + { ++ extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0); ++} ++EXPORT_SYMBOL(get_random_bytes); ++ ++/* ++ * This function will use the architecture-specific hardware random ++ * number generator if it is available. The arch-specific hw RNG will ++ * almost certainly be faster than what we can do in software, but it ++ * is impossible to verify that it is implemented securely (as ++ * opposed, to, say, the AES encryption of a sequence number using a ++ * key known by the NSA). So it's useful if we need the speed, but ++ * only if we're willing to trust the hardware manufacturer not to ++ * have put in a back door. ++ */ ++void get_random_bytes_arch(void *buf, int nbytes) ++{ + char *p = buf; + ++ trace_get_random_bytes(nbytes, _RET_IP_); + while (nbytes) { + unsigned long v; + int chunk = min(nbytes, (int)sizeof(unsigned long)); +- ++ + if (!arch_get_random_long(&v)) + break; + +@@ -950,9 +1063,11 @@ void get_random_bytes(void *buf, int nbytes) + nbytes -= chunk; + } + +- extract_entropy(&nonblocking_pool, p, nbytes, 0, 0); ++ if (nbytes) ++ extract_entropy(&nonblocking_pool, p, nbytes, 0, 0); + } +-EXPORT_SYMBOL(get_random_bytes); ++EXPORT_SYMBOL(get_random_bytes_arch); ++ + + /* + * init_std_data - initialize pool with system data +@@ -966,23 +1081,30 @@ EXPORT_SYMBOL(get_random_bytes); + static void init_std_data(struct entropy_store *r) + { + int i; +- ktime_t now; +- unsigned long flags; ++ ktime_t now = ktime_get_real(); ++ unsigned long rv; + +- spin_lock_irqsave(&r->lock, flags); + r->entropy_count = 0; +- spin_unlock_irqrestore(&r->lock, flags); +- +- now = ktime_get_real(); +- mix_pool_bytes(r, &now, sizeof(now)); +- for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof flags) { +- if (!arch_get_random_long(&flags)) ++ r->entropy_total = 0; ++ mix_pool_bytes(r, &now, sizeof(now), NULL); ++ for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) { ++ if (!arch_get_random_long(&rv)) + break; +- mix_pool_bytes(r, &flags, sizeof(flags)); ++ mix_pool_bytes(r, &rv, sizeof(rv), NULL); + } +- mix_pool_bytes(r, utsname(), sizeof(*(utsname()))); ++ mix_pool_bytes(r, utsname(), sizeof(*(utsname())), NULL); + } + ++/* ++ * Note that setup_arch() may call add_device_randomness() ++ * long before we get here. This allows seeding of the pools ++ * with some platform dependent data very early in the boot ++ * process. But it limits our options here. We must use ++ * statically allocated structures that already have all ++ * initializations complete at compile time. We should also ++ * take care not to overwrite the precious per platform data ++ * we were given. ++ */ + static int rand_initialize(void) + { + init_std_data(&input_pool); +@@ -992,24 +1114,6 @@ static int rand_initialize(void) + } + module_init(rand_initialize); + +-void rand_initialize_irq(int irq) +-{ +- struct timer_rand_state *state; +- +- state = get_timer_rand_state(irq); +- +- if (state) +- return; +- +- /* +- * If kzalloc returns null, we just won't use that entropy +- * source. +- */ +- state = kzalloc(sizeof(struct timer_rand_state), GFP_KERNEL); +- if (state) +- set_timer_rand_state(irq, state); +-} +- + #ifdef CONFIG_BLOCK + void rand_initialize_disk(struct gendisk *disk) + { +@@ -1117,7 +1221,7 @@ write_pool(struct entropy_store *r, const char __user *buffer, size_t count) + count -= bytes; + p += bytes; + +- mix_pool_bytes(r, buf, bytes); ++ mix_pool_bytes(r, buf, bytes, NULL); + cond_resched(); + } + +diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c +index ad7c732..08427ab 100644 +--- a/drivers/char/tpm/tpm.c ++++ b/drivers/char/tpm/tpm.c +@@ -827,10 +827,10 @@ EXPORT_SYMBOL_GPL(tpm_pcr_extend); + int tpm_do_selftest(struct tpm_chip *chip) + { + int rc; +- u8 digest[TPM_DIGEST_SIZE]; + unsigned int loops; + unsigned int delay_msec = 1000; + unsigned long duration; ++ struct tpm_cmd_t cmd; + + duration = tpm_calc_ordinal_duration(chip, + TPM_ORD_CONTINUE_SELFTEST); +@@ -845,7 +845,15 @@ int tpm_do_selftest(struct tpm_chip *chip) + return rc; + + do { +- rc = __tpm_pcr_read(chip, 0, digest); ++ /* Attempt to read a PCR value */ ++ cmd.header.in = pcrread_header; ++ cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0); ++ rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE); ++ ++ if (rc < TPM_HEADER_SIZE) ++ return -EFAULT; ++ ++ rc = be32_to_cpu(cmd.header.out.return_code); + if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) { + dev_info(chip->dev, + "TPM is disabled/deactivated (0x%X)\n", rc); +diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c +index 46b77ed..a7c6d6a 100644 +--- a/drivers/char/ttyprintk.c ++++ b/drivers/char/ttyprintk.c +@@ -67,7 +67,7 @@ static int tpk_printk(const unsigned char *buf, int count) + tmp[tpk_curr + 1] = '\0'; + printk(KERN_INFO "%s%s", tpk_tag, tmp); + tpk_curr = 0; +- if (buf[i + 1] == '\n') ++ if ((i + 1) < count && buf[i + 1] == '\n') + i++; + break; + case '\n': +diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c +index c0e8164..1a40935 100644 +--- a/drivers/cpufreq/powernow-k8.c ++++ b/drivers/cpufreq/powernow-k8.c +@@ -35,7 +35,6 @@ + #include + #include + #include +-#include /* for current / set_cpus_allowed() */ + #include + #include + +@@ -1139,16 +1138,23 @@ static int transition_frequency_pstate(struct powernow_k8_data *data, + return res; + } + +-/* Driver entry point to switch to the target frequency */ +-static int powernowk8_target(struct cpufreq_policy *pol, +- unsigned targfreq, unsigned relation) ++struct powernowk8_target_arg { ++ struct cpufreq_policy *pol; ++ unsigned targfreq; ++ unsigned relation; ++}; ++ ++static long powernowk8_target_fn(void *arg) + { +- cpumask_var_t oldmask; ++ struct powernowk8_target_arg *pta = arg; ++ struct cpufreq_policy *pol = pta->pol; ++ unsigned targfreq = pta->targfreq; ++ unsigned relation = pta->relation; + struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); + u32 checkfid; + u32 checkvid; + unsigned int newstate; +- int ret = -EIO; ++ int ret; + + if (!data) + return -EINVAL; +@@ -1156,29 +1162,16 @@ static int powernowk8_target(struct cpufreq_policy *pol, + checkfid = data->currfid; + checkvid = data->currvid; + +- /* only run on specific CPU from here on. */ +- /* This is poor form: use a workqueue or smp_call_function_single */ +- if (!alloc_cpumask_var(&oldmask, GFP_KERNEL)) +- return -ENOMEM; +- +- cpumask_copy(oldmask, tsk_cpus_allowed(current)); +- set_cpus_allowed_ptr(current, cpumask_of(pol->cpu)); +- +- if (smp_processor_id() != pol->cpu) { +- printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu); +- goto err_out; +- } +- + if (pending_bit_stuck()) { + printk(KERN_ERR PFX "failing targ, change pending bit set\n"); +- goto err_out; ++ return -EIO; + } + + pr_debug("targ: cpu %d, %d kHz, min %d, max %d, relation %d\n", + pol->cpu, targfreq, pol->min, pol->max, relation); + + if (query_current_values_with_pending_wait(data)) +- goto err_out; ++ return -EIO; + + if (cpu_family != CPU_HW_PSTATE) { + pr_debug("targ: curr fid 0x%x, vid 0x%x\n", +@@ -1196,7 +1189,7 @@ static int powernowk8_target(struct cpufreq_policy *pol, + + if (cpufreq_frequency_table_target(pol, data->powernow_table, + targfreq, relation, &newstate)) +- goto err_out; ++ return -EIO; + + mutex_lock(&fidvid_mutex); + +@@ -1209,9 +1202,8 @@ static int powernowk8_target(struct cpufreq_policy *pol, + ret = transition_frequency_fidvid(data, newstate); + if (ret) { + printk(KERN_ERR PFX "transition frequency failed\n"); +- ret = 1; + mutex_unlock(&fidvid_mutex); +- goto err_out; ++ return 1; + } + mutex_unlock(&fidvid_mutex); + +@@ -1220,12 +1212,25 @@ static int powernowk8_target(struct cpufreq_policy *pol, + data->powernow_table[newstate].index); + else + pol->cur = find_khz_freq_from_fid(data->currfid); +- ret = 0; + +-err_out: +- set_cpus_allowed_ptr(current, oldmask); +- free_cpumask_var(oldmask); +- return ret; ++ return 0; ++} ++ ++/* Driver entry point to switch to the target frequency */ ++static int powernowk8_target(struct cpufreq_policy *pol, ++ unsigned targfreq, unsigned relation) ++{ ++ struct powernowk8_target_arg pta = { .pol = pol, .targfreq = targfreq, ++ .relation = relation }; ++ ++ /* ++ * Must run on @pol->cpu. cpufreq core is responsible for ensuring ++ * that we're bound to the current CPU and pol->cpu stays online. ++ */ ++ if (smp_processor_id() == pol->cpu) ++ return powernowk8_target_fn(&pta); ++ else ++ return work_on_cpu(pol->cpu, powernowk8_target_fn, &pta); + } + + /* Driver entry point to verify the policy and range of frequencies */ +diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c +index 7292aa8..4058430 100644 +--- a/drivers/dma/at_hdmac.c ++++ b/drivers/dma/at_hdmac.c +@@ -662,7 +662,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, + flags); + + if (unlikely(!atslave || !sg_len)) { +- dev_dbg(chan2dev(chan), "prep_dma_memcpy: length is zero!\n"); ++ dev_dbg(chan2dev(chan), "prep_slave_sg: sg length is zero!\n"); + return NULL; + } + +@@ -690,6 +690,11 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, + + mem = sg_dma_address(sg); + len = sg_dma_len(sg); ++ if (unlikely(!len)) { ++ dev_dbg(chan2dev(chan), ++ "prep_slave_sg: sg(%d) data length is zero\n", i); ++ goto err; ++ } + mem_width = 2; + if (unlikely(mem & 3 || len & 3)) + mem_width = 0; +@@ -725,6 +730,11 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, + + mem = sg_dma_address(sg); + len = sg_dma_len(sg); ++ if (unlikely(!len)) { ++ dev_dbg(chan2dev(chan), ++ "prep_slave_sg: sg(%d) data length is zero\n", i); ++ goto err; ++ } + mem_width = 2; + if (unlikely(mem & 3 || len & 3)) + mem_width = 0; +@@ -758,6 +768,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, + + err_desc_get: + dev_err(chan2dev(chan), "not enough descriptors available\n"); ++err: + atc_desc_put(atchan, first); + return NULL; + } +diff --git a/drivers/dma/imx-dma.c b/drivers/dma/imx-dma.c +index fcfeb3c..5084975 100644 +--- a/drivers/dma/imx-dma.c ++++ b/drivers/dma/imx-dma.c +@@ -172,7 +172,8 @@ struct imxdma_engine { + struct device_dma_parameters dma_parms; + struct dma_device dma_device; + void __iomem *base; +- struct clk *dma_clk; ++ struct clk *dma_ahb; ++ struct clk *dma_ipg; + spinlock_t lock; + struct imx_dma_2d_config slots_2d[IMX_DMA_2D_SLOTS]; + struct imxdma_channel channel[IMX_DMA_CHANNELS]; +@@ -976,10 +977,20 @@ static int __init imxdma_probe(struct platform_device *pdev) + return 0; + } + +- imxdma->dma_clk = clk_get(NULL, "dma"); +- if (IS_ERR(imxdma->dma_clk)) +- return PTR_ERR(imxdma->dma_clk); +- clk_enable(imxdma->dma_clk); ++ imxdma->dma_ipg = devm_clk_get(&pdev->dev, "ipg"); ++ if (IS_ERR(imxdma->dma_ipg)) { ++ ret = PTR_ERR(imxdma->dma_ipg); ++ goto err_clk; ++ } ++ ++ imxdma->dma_ahb = devm_clk_get(&pdev->dev, "ahb"); ++ if (IS_ERR(imxdma->dma_ahb)) { ++ ret = PTR_ERR(imxdma->dma_ahb); ++ goto err_clk; ++ } ++ ++ clk_prepare_enable(imxdma->dma_ipg); ++ clk_prepare_enable(imxdma->dma_ahb); + + /* reset DMA module */ + imx_dmav1_writel(imxdma, DCR_DRST, DMA_DCR); +@@ -988,16 +999,14 @@ static int __init imxdma_probe(struct platform_device *pdev) + ret = request_irq(MX1_DMA_INT, dma_irq_handler, 0, "DMA", imxdma); + if (ret) { + dev_warn(imxdma->dev, "Can't register IRQ for DMA\n"); +- kfree(imxdma); +- return ret; ++ goto err_enable; + } + + ret = request_irq(MX1_DMA_ERR, imxdma_err_handler, 0, "DMA", imxdma); + if (ret) { + dev_warn(imxdma->dev, "Can't register ERRIRQ for DMA\n"); + free_irq(MX1_DMA_INT, NULL); +- kfree(imxdma); +- return ret; ++ goto err_enable; + } + } + +@@ -1094,7 +1103,10 @@ err_init: + free_irq(MX1_DMA_INT, NULL); + free_irq(MX1_DMA_ERR, NULL); + } +- ++err_enable: ++ clk_disable_unprepare(imxdma->dma_ipg); ++ clk_disable_unprepare(imxdma->dma_ahb); ++err_clk: + kfree(imxdma); + return ret; + } +@@ -1114,7 +1126,9 @@ static int __exit imxdma_remove(struct platform_device *pdev) + free_irq(MX1_DMA_ERR, NULL); + } + +- kfree(imxdma); ++ clk_disable_unprepare(imxdma->dma_ipg); ++ clk_disable_unprepare(imxdma->dma_ahb); ++ kfree(imxdma); + + return 0; + } +diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c +index e4feba6..f5843bc 100644 +--- a/drivers/dma/pl330.c ++++ b/drivers/dma/pl330.c +@@ -1567,17 +1567,19 @@ static int pl330_submit_req(void *ch_id, struct pl330_req *r) + goto xfer_exit; + } + +- /* Prefer Secure Channel */ +- if (!_manager_ns(thrd)) +- r->cfg->nonsecure = 0; +- else +- r->cfg->nonsecure = 1; + + /* Use last settings, if not provided */ +- if (r->cfg) ++ if (r->cfg) { ++ /* Prefer Secure Channel */ ++ if (!_manager_ns(thrd)) ++ r->cfg->nonsecure = 0; ++ else ++ r->cfg->nonsecure = 1; ++ + ccr = _prepare_ccr(r->cfg); +- else ++ } else { + ccr = readl(regs + CC(thrd->id)); ++ } + + /* If this req doesn't have valid xfer settings */ + if (!_is_valid(ccr)) { +@@ -2928,6 +2930,11 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id) + num_chan = max_t(int, pi->pcfg.num_peri, pi->pcfg.num_chan); + + pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL); ++ if (!pdmac->peripherals) { ++ ret = -ENOMEM; ++ dev_err(&adev->dev, "unable to allocate pdmac->peripherals\n"); ++ goto probe_err5; ++ } + + for (i = 0; i < num_chan; i++) { + pch = &pdmac->peripherals[i]; +diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c +index 153980b..b298158 100644 +--- a/drivers/firmware/dmi_scan.c ++++ b/drivers/firmware/dmi_scan.c +@@ -6,6 +6,7 @@ + #include + #include + #include ++#include + #include + + /* +@@ -111,6 +112,8 @@ static int __init dmi_walk_early(void (*decode)(const struct dmi_header *, + + dmi_table(buf, dmi_len, dmi_num, decode, NULL); + ++ add_device_randomness(buf, dmi_len); ++ + dmi_iounmap(buf, dmi_len); + return 0; + } +diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c +index 47408e8..d10c987 100644 +--- a/drivers/firmware/efivars.c ++++ b/drivers/firmware/efivars.c +@@ -435,12 +435,23 @@ efivar_attr_read(struct efivar_entry *entry, char *buf) + if (status != EFI_SUCCESS) + return -EIO; + +- if (var->Attributes & 0x1) ++ if (var->Attributes & EFI_VARIABLE_NON_VOLATILE) + str += sprintf(str, "EFI_VARIABLE_NON_VOLATILE\n"); +- if (var->Attributes & 0x2) ++ if (var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) + str += sprintf(str, "EFI_VARIABLE_BOOTSERVICE_ACCESS\n"); +- if (var->Attributes & 0x4) ++ if (var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) + str += sprintf(str, "EFI_VARIABLE_RUNTIME_ACCESS\n"); ++ if (var->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) ++ str += sprintf(str, "EFI_VARIABLE_HARDWARE_ERROR_RECORD\n"); ++ if (var->Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) ++ str += sprintf(str, ++ "EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS\n"); ++ if (var->Attributes & ++ EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) ++ str += sprintf(str, ++ "EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS\n"); ++ if (var->Attributes & EFI_VARIABLE_APPEND_WRITE) ++ str += sprintf(str, "EFI_VARIABLE_APPEND_WRITE\n"); + return str - buf; + } + +diff --git a/drivers/firmware/pcdp.c b/drivers/firmware/pcdp.c +index 51e0e2d..a330492 100644 +--- a/drivers/firmware/pcdp.c ++++ b/drivers/firmware/pcdp.c +@@ -95,7 +95,7 @@ efi_setup_pcdp_console(char *cmdline) + if (efi.hcdp == EFI_INVALID_TABLE_ADDR) + return -ENODEV; + +- pcdp = ioremap(efi.hcdp, 4096); ++ pcdp = early_ioremap(efi.hcdp, 4096); + printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp); + + if (strstr(cmdline, "console=hcdp")) { +@@ -131,6 +131,6 @@ efi_setup_pcdp_console(char *cmdline) + } + + out: +- iounmap(pcdp); ++ early_iounmap(pcdp, 4096); + return rc; + } +diff --git a/drivers/gpio/gpio-lpc32xx.c b/drivers/gpio/gpio-lpc32xx.c +index c2199be..6cee3a6 100644 +--- a/drivers/gpio/gpio-lpc32xx.c ++++ b/drivers/gpio/gpio-lpc32xx.c +@@ -307,6 +307,7 @@ static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin, + { + struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); + ++ __set_gpio_level_p012(group, pin, value); + __set_gpio_dir_p012(group, pin, 0); + + return 0; +@@ -317,6 +318,7 @@ static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin, + { + struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); + ++ __set_gpio_level_p3(group, pin, value); + __set_gpio_dir_p3(group, pin, 0); + + return 0; +@@ -325,6 +327,9 @@ static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin, + static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin, + int value) + { ++ struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); ++ ++ __set_gpo_level_p3(group, pin, value); + return 0; + } + +diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c +index 08a7aa7..af81f77 100644 +--- a/drivers/gpu/drm/drm_crtc.c ++++ b/drivers/gpu/drm/drm_crtc.c +@@ -1034,15 +1034,15 @@ void drm_mode_config_cleanup(struct drm_device *dev) + fb->funcs->destroy(fb); + } + +- list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) { +- crtc->funcs->destroy(crtc); +- } +- + list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list, + head) { + plane->funcs->destroy(plane); + } + ++ list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) { ++ crtc->funcs->destroy(crtc); ++ } ++ + idr_remove_all(&dev->mode_config.crtc_idr); + idr_destroy(&dev->mode_config.crtc_idr); + } +@@ -1981,7 +1981,7 @@ int drm_mode_cursor_ioctl(struct drm_device *dev, + if (!drm_core_check_feature(dev, DRIVER_MODESET)) + return -EINVAL; + +- if (!req->flags) ++ if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) + return -EINVAL; + + mutex_lock(&dev->mode_config.mutex); +diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c +index a8743c3..b7ee230 100644 +--- a/drivers/gpu/drm/drm_edid.c ++++ b/drivers/gpu/drm/drm_edid.c +@@ -87,6 +87,9 @@ static struct edid_quirk { + int product_id; + u32 quirks; + } edid_quirk_list[] = { ++ /* ASUS VW222S */ ++ { "ACI", 0x22a2, EDID_QUIRK_FORCE_REDUCED_BLANKING }, ++ + /* Acer AL1706 */ + { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 }, + /* Acer F51 */ +diff --git a/drivers/gpu/drm/gma500/oaktrail_device.c b/drivers/gpu/drm/gma500/oaktrail_device.c +index 0f9b7db..cf49ba5 100644 +--- a/drivers/gpu/drm/gma500/oaktrail_device.c ++++ b/drivers/gpu/drm/gma500/oaktrail_device.c +@@ -476,6 +476,7 @@ static const struct psb_offset oaktrail_regmap[2] = { + .pos = DSPAPOS, + .surf = DSPASURF, + .addr = MRST_DSPABASE, ++ .base = MRST_DSPABASE, + .status = PIPEASTAT, + .linoff = DSPALINOFF, + .tileoff = DSPATILEOFF, +@@ -499,6 +500,7 @@ static const struct psb_offset oaktrail_regmap[2] = { + .pos = DSPBPOS, + .surf = DSPBSURF, + .addr = DSPBBASE, ++ .base = DSPBBASE, + .status = PIPEBSTAT, + .linoff = DSPBLINOFF, + .tileoff = DSPBTILEOFF, +diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c b/drivers/gpu/drm/gma500/psb_intel_display.c +index 36c3c99..73e44a8 100644 +--- a/drivers/gpu/drm/gma500/psb_intel_display.c ++++ b/drivers/gpu/drm/gma500/psb_intel_display.c +@@ -1362,6 +1362,9 @@ void psb_intel_crtc_init(struct drm_device *dev, int pipe, + (struct drm_connector **) (psb_intel_crtc + 1); + psb_intel_crtc->mode_set.num_connectors = 0; + psb_intel_cursor_init(dev, psb_intel_crtc); ++ ++ /* Set to true so that the pipe is forced off on initial config. */ ++ psb_intel_crtc->active = true; + } + + int psb_intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, +diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c +index 288d7b8..35926ad 100644 +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -3044,7 +3044,8 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj, + { + int ret; + +- BUG_ON(obj->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT); ++ if (WARN_ON(obj->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT)) ++ return -EBUSY; + + if (obj->gtt_space != NULL) { + if ((alignment && obj->gtt_offset & (alignment - 1)) || +diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c +index ed3224c..972a32f 100644 +--- a/drivers/gpu/drm/i915/i915_irq.c ++++ b/drivers/gpu/drm/i915/i915_irq.c +@@ -605,12 +605,12 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS) + intel_opregion_gse_intr(dev); + + for (i = 0; i < 3; i++) { ++ if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i))) ++ drm_handle_vblank(dev, i); + if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) { + intel_prepare_page_flip(dev, i); + intel_finish_page_flip_plane(dev, i); + } +- if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i))) +- drm_handle_vblank(dev, i); + } + + /* check event from PCH */ +@@ -692,6 +692,12 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS) + if (de_iir & DE_GSE) + intel_opregion_gse_intr(dev); + ++ if (de_iir & DE_PIPEA_VBLANK) ++ drm_handle_vblank(dev, 0); ++ ++ if (de_iir & DE_PIPEB_VBLANK) ++ drm_handle_vblank(dev, 1); ++ + if (de_iir & DE_PLANEA_FLIP_DONE) { + intel_prepare_page_flip(dev, 0); + intel_finish_page_flip_plane(dev, 0); +@@ -702,12 +708,6 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS) + intel_finish_page_flip_plane(dev, 1); + } + +- if (de_iir & DE_PIPEA_VBLANK) +- drm_handle_vblank(dev, 0); +- +- if (de_iir & DE_PIPEB_VBLANK) +- drm_handle_vblank(dev, 1); +- + /* check event from PCH */ + if (de_iir & DE_PCH_EVENT) { + if (pch_iir & hotplug_mask) +@@ -2626,9 +2626,6 @@ void intel_irq_init(struct drm_device *dev) + dev->driver->irq_handler = i8xx_irq_handler; + dev->driver->irq_uninstall = i8xx_irq_uninstall; + } else if (INTEL_INFO(dev)->gen == 3) { +- /* IIR "flip pending" means done if this bit is set */ +- I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); +- + dev->driver->irq_preinstall = i915_irq_preinstall; + dev->driver->irq_postinstall = i915_irq_postinstall; + dev->driver->irq_uninstall = i915_irq_uninstall; +diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h +index 48d5e8e..4cad908 100644 +--- a/drivers/gpu/drm/i915/i915_reg.h ++++ b/drivers/gpu/drm/i915/i915_reg.h +@@ -514,6 +514,9 @@ + # define VS_TIMER_DISPATCH (1 << 6) + # define MI_FLUSH_ENABLE (1 << 12) + ++#define GEN6_GT_MODE 0x20d0 ++#define GEN6_GT_MODE_HI (1 << 9) ++ + #define GFX_MODE 0x02520 + #define GFX_MODE_GEN7 0x0229c + #define RING_MODE_GEN7(ring) ((ring)->mmio_base+0x29c) +diff --git a/drivers/gpu/drm/i915/i915_sysfs.c b/drivers/gpu/drm/i915/i915_sysfs.c +index 79f8344..6d4b001 100644 +--- a/drivers/gpu/drm/i915/i915_sysfs.c ++++ b/drivers/gpu/drm/i915/i915_sysfs.c +@@ -31,6 +31,7 @@ + #include + #include "i915_drv.h" + ++#ifdef CONFIG_PM + static u32 calc_residency(struct drm_device *dev, const u32 reg) + { + struct drm_i915_private *dev_priv = dev->dev_private; +@@ -109,3 +110,14 @@ void i915_teardown_sysfs(struct drm_device *dev) + { + sysfs_unmerge_group(&dev->primary->kdev.kobj, &rc6_attr_group); + } ++#else ++void i915_setup_sysfs(struct drm_device *dev) ++{ ++ return; ++} ++ ++void i915_teardown_sysfs(struct drm_device *dev) ++{ ++ return; ++} ++#endif /* CONFIG_PM */ +diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c +index 75a70c4..1f0741f 100644 +--- a/drivers/gpu/drm/i915/intel_crt.c ++++ b/drivers/gpu/drm/i915/intel_crt.c +@@ -284,6 +284,36 @@ static bool intel_crt_detect_hotplug(struct drm_connector *connector) + return ret; + } + ++static struct edid *intel_crt_get_edid(struct drm_connector *connector, ++ struct i2c_adapter *i2c) ++{ ++ struct edid *edid; ++ ++ edid = drm_get_edid(connector, i2c); ++ ++ if (!edid && !intel_gmbus_is_forced_bit(i2c)) { ++ DRM_DEBUG_KMS("CRT GMBUS EDID read failed, retry using GPIO bit-banging\n"); ++ intel_gmbus_force_bit(i2c, true); ++ edid = drm_get_edid(connector, i2c); ++ intel_gmbus_force_bit(i2c, false); ++ } ++ ++ return edid; ++} ++ ++/* local version of intel_ddc_get_modes() to use intel_crt_get_edid() */ ++static int intel_crt_ddc_get_modes(struct drm_connector *connector, ++ struct i2c_adapter *adapter) ++{ ++ struct edid *edid; ++ ++ edid = intel_crt_get_edid(connector, adapter); ++ if (!edid) ++ return 0; ++ ++ return intel_connector_update_modes(connector, edid); ++} ++ + static bool intel_crt_detect_ddc(struct drm_connector *connector) + { + struct intel_crt *crt = intel_attached_crt(connector); +@@ -299,7 +329,7 @@ static bool intel_crt_detect_ddc(struct drm_connector *connector) + struct i2c_adapter *i2c; + + i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->crt_ddc_pin); +- edid = drm_get_edid(connector, i2c); ++ edid = intel_crt_get_edid(connector, i2c); + /* + * This may be a DVI-I connector with a shared DDC + * link between analog and digital outputs, so we +@@ -498,13 +528,13 @@ static int intel_crt_get_modes(struct drm_connector *connector) + struct i2c_adapter *i2c; + + i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->crt_ddc_pin); +- ret = intel_ddc_get_modes(connector, i2c); ++ ret = intel_crt_ddc_get_modes(connector, i2c); + if (ret || !IS_G4X(dev)) + return ret; + + /* Try to probe digital port for output in DVI-I -> VGA mode. */ + i2c = intel_gmbus_get_adapter(dev_priv, GMBUS_PORT_DPB); +- return intel_ddc_get_modes(connector, i2c); ++ return intel_crt_ddc_get_modes(connector, i2c); + } + + static int intel_crt_set_property(struct drm_connector *connector, +diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c +index a8538ac..6f0d039 100644 +--- a/drivers/gpu/drm/i915/intel_display.c ++++ b/drivers/gpu/drm/i915/intel_display.c +@@ -1238,7 +1238,7 @@ static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, + enum pipe pipe, int reg) + { + u32 val = I915_READ(reg); +- WARN(hdmi_pipe_enabled(dev_priv, val, pipe), ++ WARN(hdmi_pipe_enabled(dev_priv, pipe, val), + "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", + reg, pipe_name(pipe)); + } +@@ -1255,13 +1255,13 @@ static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, + + reg = PCH_ADPA; + val = I915_READ(reg); +- WARN(adpa_pipe_enabled(dev_priv, val, pipe), ++ WARN(adpa_pipe_enabled(dev_priv, pipe, val), + "PCH VGA enabled on transcoder %c, should be disabled\n", + pipe_name(pipe)); + + reg = PCH_LVDS; + val = I915_READ(reg); +- WARN(lvds_pipe_enabled(dev_priv, val, pipe), ++ WARN(lvds_pipe_enabled(dev_priv, pipe, val), + "PCH LVDS enabled on transcoder %c, should be disabled\n", + pipe_name(pipe)); + +@@ -1723,7 +1723,7 @@ static void disable_pch_hdmi(struct drm_i915_private *dev_priv, + enum pipe pipe, int reg) + { + u32 val = I915_READ(reg); +- if (hdmi_pipe_enabled(dev_priv, val, pipe)) { ++ if (hdmi_pipe_enabled(dev_priv, pipe, val)) { + DRM_DEBUG_KMS("Disabling pch HDMI %x on pipe %d\n", + reg, pipe); + I915_WRITE(reg, val & ~PORT_ENABLE); +@@ -1745,12 +1745,12 @@ static void intel_disable_pch_ports(struct drm_i915_private *dev_priv, + + reg = PCH_ADPA; + val = I915_READ(reg); +- if (adpa_pipe_enabled(dev_priv, val, pipe)) ++ if (adpa_pipe_enabled(dev_priv, pipe, val)) + I915_WRITE(reg, val & ~ADPA_DAC_ENABLE); + + reg = PCH_LVDS; + val = I915_READ(reg); +- if (lvds_pipe_enabled(dev_priv, val, pipe)) { ++ if (lvds_pipe_enabled(dev_priv, pipe, val)) { + DRM_DEBUG_KMS("disable lvds on pipe %d val 0x%08x\n", pipe, val); + I915_WRITE(reg, val & ~LVDS_PORT_EN); + POSTING_READ(reg); +@@ -2641,13 +2641,34 @@ static void ironlake_fdi_disable(struct drm_crtc *crtc) + udelay(100); + } + ++static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) ++{ ++ struct drm_device *dev = crtc->dev; ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ unsigned long flags; ++ bool pending; ++ ++ if (atomic_read(&dev_priv->mm.wedged)) ++ return false; ++ ++ spin_lock_irqsave(&dev->event_lock, flags); ++ pending = to_intel_crtc(crtc)->unpin_work != NULL; ++ spin_unlock_irqrestore(&dev->event_lock, flags); ++ ++ return pending; ++} ++ + static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) + { + struct drm_device *dev = crtc->dev; ++ struct drm_i915_private *dev_priv = dev->dev_private; + + if (crtc->fb == NULL) + return; + ++ wait_event(dev_priv->pending_flip_queue, ++ !intel_crtc_has_pending_flip(crtc)); ++ + mutex_lock(&dev->struct_mutex); + intel_finish_fb(crtc->fb); + mutex_unlock(&dev->struct_mutex); +@@ -3581,17 +3602,6 @@ static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc, + continue; + } + +- if (intel_encoder->type == INTEL_OUTPUT_EDP) { +- /* Use VBT settings if we have an eDP panel */ +- unsigned int edp_bpc = dev_priv->edp.bpp / 3; +- +- if (edp_bpc < display_bpc) { +- DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc); +- display_bpc = edp_bpc; +- } +- continue; +- } +- + /* Not one of the known troublemakers, check the EDID */ + list_for_each_entry(connector, &dev->mode_config.connector_list, + head) { +@@ -3937,12 +3947,6 @@ static void i8xx_update_pll(struct drm_crtc *crtc, + POSTING_READ(DPLL(pipe)); + udelay(150); + +- I915_WRITE(DPLL(pipe), dpll); +- +- /* Wait for the clocks to stabilize. */ +- POSTING_READ(DPLL(pipe)); +- udelay(150); +- + /* The LVDS pin pair needs to be on before the DPLLs are enabled. + * This is an exception to the general rule that mode_set doesn't turn + * things on. +@@ -3950,6 +3954,12 @@ static void i8xx_update_pll(struct drm_crtc *crtc, + if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) + intel_update_lvds(crtc, clock, adjusted_mode); + ++ I915_WRITE(DPLL(pipe), dpll); ++ ++ /* Wait for the clocks to stabilize. */ ++ POSTING_READ(DPLL(pipe)); ++ udelay(150); ++ + /* The pixel multiplier can only be updated once the + * DPLL is enabled and the clocks are stable. + * +@@ -5927,9 +5937,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev, + + atomic_clear_mask(1 << intel_crtc->plane, + &obj->pending_flip.counter); +- if (atomic_read(&obj->pending_flip) == 0) +- wake_up(&dev_priv->pending_flip_queue); + ++ wake_up(&dev_priv->pending_flip_queue); + schedule_work(&work->work); + + trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj); +@@ -6178,7 +6187,7 @@ static int intel_gen7_queue_flip(struct drm_device *dev, + default: + WARN_ONCE(1, "unknown plane in flip command\n"); + ret = -ENODEV; +- goto err; ++ goto err_unpin; + } + + ret = intel_ring_begin(ring, 4); +diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c +index c044932..0abe7ec 100644 +--- a/drivers/gpu/drm/i915/intel_dp.c ++++ b/drivers/gpu/drm/i915/intel_dp.c +@@ -726,8 +726,8 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode, + bpp = adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC ? 18 : 24; + mode_rate = intel_dp_link_required(mode->clock, bpp); + +- for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) { +- for (clock = 0; clock <= max_clock; clock++) { ++ for (clock = 0; clock <= max_clock; clock++) { ++ for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) { + int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count); + + if (mode_rate <= link_avail) { +@@ -1171,10 +1171,14 @@ static void ironlake_edp_panel_off(struct intel_dp *intel_dp) + WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n"); + + pp = ironlake_get_pp_control(dev_priv); +- pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_BLC_ENABLE); ++ /* We need to switch off panel power _and_ force vdd, for otherwise some ++ * panels get very unhappy and cease to work. */ ++ pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE); + I915_WRITE(PCH_PP_CONTROL, pp); + POSTING_READ(PCH_PP_CONTROL); + ++ intel_dp->want_panel_vdd = false; ++ + ironlake_wait_panel_off(intel_dp); + } + +@@ -1284,11 +1288,9 @@ static void intel_dp_prepare(struct drm_encoder *encoder) + * ensure that we have vdd while we switch off the panel. */ + ironlake_edp_panel_vdd_on(intel_dp); + ironlake_edp_backlight_off(intel_dp); +- ironlake_edp_panel_off(intel_dp); +- + intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); ++ ironlake_edp_panel_off(intel_dp); + intel_dp_link_down(intel_dp); +- ironlake_edp_panel_vdd_off(intel_dp, false); + } + + static void intel_dp_commit(struct drm_encoder *encoder) +@@ -1323,11 +1325,9 @@ intel_dp_dpms(struct drm_encoder *encoder, int mode) + /* Switching the panel off requires vdd. */ + ironlake_edp_panel_vdd_on(intel_dp); + ironlake_edp_backlight_off(intel_dp); +- ironlake_edp_panel_off(intel_dp); +- + intel_dp_sink_dpms(intel_dp, mode); ++ ironlake_edp_panel_off(intel_dp); + intel_dp_link_down(intel_dp); +- ironlake_edp_panel_vdd_off(intel_dp, false); + + if (is_cpu_edp(intel_dp)) + ironlake_edp_pll_off(encoder); +diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h +index 3e09188..9040191 100644 +--- a/drivers/gpu/drm/i915/intel_drv.h ++++ b/drivers/gpu/drm/i915/intel_drv.h +@@ -334,6 +334,8 @@ struct intel_fbc_work { + int interval; + }; + ++int intel_connector_update_modes(struct drm_connector *connector, ++ struct edid *edid); + int intel_ddc_get_modes(struct drm_connector *c, struct i2c_adapter *adapter); + extern bool intel_ddc_probe(struct intel_encoder *intel_encoder, int ddc_bus); + +diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c +index 2ead3bf..bc1f0f2 100644 +--- a/drivers/gpu/drm/i915/intel_hdmi.c ++++ b/drivers/gpu/drm/i915/intel_hdmi.c +@@ -400,7 +400,7 @@ static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) + u32 temp; + u32 enable_bits = SDVO_ENABLE; + +- if (intel_hdmi->has_audio) ++ if (intel_hdmi->has_audio || mode != DRM_MODE_DPMS_ON) + enable_bits |= SDVO_AUDIO_ENABLE; + + temp = I915_READ(intel_hdmi->sdvox_reg); +diff --git a/drivers/gpu/drm/i915/intel_modes.c b/drivers/gpu/drm/i915/intel_modes.c +index d67ec3a..e019146 100644 +--- a/drivers/gpu/drm/i915/intel_modes.c ++++ b/drivers/gpu/drm/i915/intel_modes.c +@@ -61,6 +61,25 @@ bool intel_ddc_probe(struct intel_encoder *intel_encoder, int ddc_bus) + } + + /** ++ * intel_connector_update_modes - update connector from edid ++ * @connector: DRM connector device to use ++ * @edid: previously read EDID information ++ */ ++int intel_connector_update_modes(struct drm_connector *connector, ++ struct edid *edid) ++{ ++ int ret; ++ ++ drm_mode_connector_update_edid_property(connector, edid); ++ ret = drm_add_edid_modes(connector, edid); ++ drm_edid_to_eld(connector, edid); ++ connector->display_info.raw_edid = NULL; ++ kfree(edid); ++ ++ return ret; ++} ++ ++/** + * intel_ddc_get_modes - get modelist from monitor + * @connector: DRM connector device to use + * @adapter: i2c adapter +@@ -71,18 +90,12 @@ int intel_ddc_get_modes(struct drm_connector *connector, + struct i2c_adapter *adapter) + { + struct edid *edid; +- int ret = 0; + + edid = drm_get_edid(connector, adapter); +- if (edid) { +- drm_mode_connector_update_edid_property(connector, edid); +- ret = drm_add_edid_modes(connector, edid); +- drm_edid_to_eld(connector, edid); +- connector->display_info.raw_edid = NULL; +- kfree(edid); +- } ++ if (!edid) ++ return 0; + +- return ret; ++ return intel_connector_update_modes(connector, edid); + } + + static const struct drm_prop_enum_list force_audio_names[] = { +diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c +index d0ce2a5..b55aa0e 100644 +--- a/drivers/gpu/drm/i915/intel_pm.c ++++ b/drivers/gpu/drm/i915/intel_pm.c +@@ -2431,10 +2431,10 @@ void gen6_enable_rps(struct drm_i915_private *dev_priv) + I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, + dev_priv->max_delay << 24 | + dev_priv->min_delay << 16); +- I915_WRITE(GEN6_RP_UP_THRESHOLD, 10000); +- I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 1000000); +- I915_WRITE(GEN6_RP_UP_EI, 100000); +- I915_WRITE(GEN6_RP_DOWN_EI, 5000000); ++ I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); ++ I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); ++ I915_WRITE(GEN6_RP_UP_EI, 66000); ++ I915_WRITE(GEN6_RP_DOWN_EI, 350000); + I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); + I915_WRITE(GEN6_RP_CONTROL, + GEN6_RP_MEDIA_TURBO | +@@ -3363,6 +3363,11 @@ static void gen6_init_clock_gating(struct drm_device *dev) + DISPPLANE_TRICKLE_FEED_DISABLE); + intel_flush_display_plane(dev_priv, pipe); + } ++ ++ /* The default value should be 0x200 according to docs, but the two ++ * platforms I checked have a 0 for this. (Maybe BIOS overrides?) */ ++ I915_WRITE(GEN6_GT_MODE, _MASKED_BIT_DISABLE(0xffff)); ++ I915_WRITE(GEN6_GT_MODE, _MASKED_BIT_ENABLE(GEN6_GT_MODE_HI)); + } + + static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) +@@ -3528,6 +3533,9 @@ static void gen3_init_clock_gating(struct drm_device *dev) + + if (IS_PINEVIEW(dev)) + I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); ++ ++ /* IIR "flip pending" means done if this bit is set */ ++ I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); + } + + static void i85x_init_clock_gating(struct drm_device *dev) +diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c +index b6a9d45..74d47a3 100644 +--- a/drivers/gpu/drm/i915/intel_sdvo.c ++++ b/drivers/gpu/drm/i915/intel_sdvo.c +@@ -2552,25 +2552,12 @@ bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob) + } + } + +- if (intel_sdvo->is_sdvob) +- dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; +- else +- dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; +- + drm_encoder_helper_add(&intel_encoder->base, &intel_sdvo_helper_funcs); + + /* In default case sdvo lvds is false */ + if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps)) + goto err; + +- /* Set up hotplug command - note paranoia about contents of reply. +- * We assume that the hardware is in a sane state, and only touch +- * the bits we think we understand. +- */ +- intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ACTIVE_HOT_PLUG, +- &intel_sdvo->hotplug_active, 2); +- intel_sdvo->hotplug_active[0] &= ~0x3; +- + if (intel_sdvo_output_setup(intel_sdvo, + intel_sdvo->caps.output_flags) != true) { + DRM_DEBUG_KMS("SDVO output failed to setup on %s\n", +@@ -2578,6 +2565,16 @@ bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob) + goto err; + } + ++ /* Only enable the hotplug irq if we need it, to work around noisy ++ * hotplug lines. ++ */ ++ if (intel_sdvo->hotplug_active[0]) { ++ if (intel_sdvo->is_sdvob) ++ dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; ++ else ++ dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; ++ } ++ + intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg); + + /* Set the input timing to the screen. Assume always input 0. */ +diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c +index d303061..0201d1d 100644 +--- a/drivers/gpu/drm/mgag200/mgag200_mode.c ++++ b/drivers/gpu/drm/mgag200/mgag200_mode.c +@@ -468,10 +468,11 @@ static int mga_g200er_set_plls(struct mga_device *mdev, long clock) + { + unsigned int vcomax, vcomin, pllreffreq; + unsigned int delta, tmpdelta; +- unsigned int testr, testn, testm, testo; ++ int testr, testn, testm, testo; + unsigned int p, m, n; +- unsigned int computed; ++ unsigned int computed, vco; + int tmp; ++ const unsigned int m_div_val[] = { 1, 2, 4, 8 }; + + m = n = p = 0; + vcomax = 1488000; +@@ -490,12 +491,13 @@ static int mga_g200er_set_plls(struct mga_device *mdev, long clock) + if (delta == 0) + break; + for (testo = 5; testo < 33; testo++) { +- computed = pllreffreq * (testn + 1) / ++ vco = pllreffreq * (testn + 1) / + (testr + 1); +- if (computed < vcomin) ++ if (vco < vcomin) + continue; +- if (computed > vcomax) ++ if (vco > vcomax) + continue; ++ computed = vco / (m_div_val[testm] * (testo + 1)); + if (computed > clock) + tmpdelta = computed - clock; + else +diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c +index 69688ef..7e16dc5 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_display.c ++++ b/drivers/gpu/drm/nouveau/nouveau_display.c +@@ -598,7 +598,7 @@ nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev, + args->size = args->pitch * args->height; + args->size = roundup(args->size, PAGE_SIZE); + +- ret = nouveau_gem_new(dev, args->size, 0, TTM_PL_FLAG_VRAM, 0, 0, &bo); ++ ret = nouveau_gem_new(dev, args->size, 0, NOUVEAU_GEM_DOMAIN_VRAM, 0, 0, &bo); + if (ret) + return ret; + +diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h +index 8613cb2..b863a3a 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_drv.h ++++ b/drivers/gpu/drm/nouveau/nouveau_drv.h +@@ -689,8 +689,6 @@ struct drm_nouveau_private { + void (*irq_handler[32])(struct drm_device *); + bool msi_enabled; + +- struct list_head vbl_waiting; +- + struct { + struct drm_global_reference mem_global_ref; + struct ttm_bo_global_ref bo_global_ref; +diff --git a/drivers/gpu/drm/nouveau/nouveau_irq.c b/drivers/gpu/drm/nouveau/nouveau_irq.c +index 868c7fd..b2c2937 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_irq.c ++++ b/drivers/gpu/drm/nouveau/nouveau_irq.c +@@ -41,12 +41,8 @@ + void + nouveau_irq_preinstall(struct drm_device *dev) + { +- struct drm_nouveau_private *dev_priv = dev->dev_private; +- + /* Master disable */ + nv_wr32(dev, NV03_PMC_INTR_EN_0, 0); +- +- INIT_LIST_HEAD(&dev_priv->vbl_waiting); + } + + int +diff --git a/drivers/gpu/drm/nouveau/nouveau_software.h b/drivers/gpu/drm/nouveau/nouveau_software.h +index e60bc6c..b507a92 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_software.h ++++ b/drivers/gpu/drm/nouveau/nouveau_software.h +@@ -38,6 +38,7 @@ static inline void + nouveau_software_context_new(struct nouveau_software_chan *pch) + { + INIT_LIST_HEAD(&pch->flip); ++ INIT_LIST_HEAD(&pch->vblank.list); + } + + static inline void +diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c +index 19706f0..22a90a0 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_state.c ++++ b/drivers/gpu/drm/nouveau/nouveau_state.c +@@ -737,9 +737,11 @@ nouveau_card_init(struct drm_device *dev) + } + break; + case NV_C0: +- nvc0_copy_create(dev, 1); ++ if (!(nv_rd32(dev, 0x022500) & 0x00000200)) ++ nvc0_copy_create(dev, 1); + case NV_D0: +- nvc0_copy_create(dev, 0); ++ if (!(nv_rd32(dev, 0x022500) & 0x00000100)) ++ nvc0_copy_create(dev, 0); + break; + default: + break; +diff --git a/drivers/gpu/drm/nouveau/nv84_fifo.c b/drivers/gpu/drm/nouveau/nv84_fifo.c +index cc82d79..c564c5e 100644 +--- a/drivers/gpu/drm/nouveau/nv84_fifo.c ++++ b/drivers/gpu/drm/nouveau/nv84_fifo.c +@@ -117,17 +117,22 @@ nv84_fifo_context_del(struct nouveau_channel *chan, int engine) + struct drm_device *dev = chan->dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + unsigned long flags; ++ u32 save; + + /* remove channel from playlist, will context switch if active */ + spin_lock_irqsave(&dev_priv->context_switch_lock, flags); + nv_mask(dev, 0x002600 + (chan->id * 4), 0x80000000, 0x00000000); + nv50_fifo_playlist_update(dev); + ++ save = nv_mask(dev, 0x002520, 0x0000003f, 0x15); ++ + /* tell any engines on this channel to unload their contexts */ + nv_wr32(dev, 0x0032fc, chan->ramin->vinst >> 12); + if (!nv_wait_ne(dev, 0x0032fc, 0xffffffff, 0xffffffff)) + NV_INFO(dev, "PFIFO: channel %d unload timeout\n", chan->id); + ++ nv_wr32(dev, 0x002520, save); ++ + nv_wr32(dev, 0x002600 + (chan->id * 4), 0x00000000); + spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); + +@@ -184,10 +189,13 @@ nv84_fifo_fini(struct drm_device *dev, int engine, bool suspend) + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nv84_fifo_priv *priv = nv_engine(dev, engine); + int i; ++ u32 save; + + /* set playlist length to zero, fifo will unload context */ + nv_wr32(dev, 0x0032ec, 0); + ++ save = nv_mask(dev, 0x002520, 0x0000003f, 0x15); ++ + /* tell all connected engines to unload their contexts */ + for (i = 0; i < priv->base.channels; i++) { + struct nouveau_channel *chan = dev_priv->channels.ptr[i]; +@@ -199,6 +207,7 @@ nv84_fifo_fini(struct drm_device *dev, int engine, bool suspend) + } + } + ++ nv_wr32(dev, 0x002520, save); + nv_wr32(dev, 0x002140, 0); + return 0; + } +diff --git a/drivers/gpu/drm/nouveau/nva3_copy.fuc b/drivers/gpu/drm/nouveau/nva3_copy.fuc +index abc3662..219850d 100644 +--- a/drivers/gpu/drm/nouveau/nva3_copy.fuc ++++ b/drivers/gpu/drm/nouveau/nva3_copy.fuc +@@ -119,9 +119,9 @@ dispatch_dma: + // mthd 0x030c-0x0340, various stuff + .b16 0xc3 14 + .b32 #ctx_src_address_high ~0x000000ff +-.b32 #ctx_src_address_low ~0xfffffff0 ++.b32 #ctx_src_address_low ~0xffffffff + .b32 #ctx_dst_address_high ~0x000000ff +-.b32 #ctx_dst_address_low ~0xfffffff0 ++.b32 #ctx_dst_address_low ~0xffffffff + .b32 #ctx_src_pitch ~0x0007ffff + .b32 #ctx_dst_pitch ~0x0007ffff + .b32 #ctx_xcnt ~0x0000ffff +diff --git a/drivers/gpu/drm/nouveau/nva3_copy.fuc.h b/drivers/gpu/drm/nouveau/nva3_copy.fuc.h +index 1f33fbd..37d6de3 100644 +--- a/drivers/gpu/drm/nouveau/nva3_copy.fuc.h ++++ b/drivers/gpu/drm/nouveau/nva3_copy.fuc.h +@@ -1,37 +1,72 @@ +-uint32_t nva3_pcopy_data[] = { ++u32 nva3_pcopy_data[] = { ++/* 0x0000: ctx_object */ + 0x00000000, ++/* 0x0004: ctx_dma */ ++/* 0x0004: ctx_dma_query */ + 0x00000000, ++/* 0x0008: ctx_dma_src */ + 0x00000000, ++/* 0x000c: ctx_dma_dst */ + 0x00000000, ++/* 0x0010: ctx_query_address_high */ + 0x00000000, ++/* 0x0014: ctx_query_address_low */ + 0x00000000, ++/* 0x0018: ctx_query_counter */ + 0x00000000, ++/* 0x001c: ctx_src_address_high */ + 0x00000000, ++/* 0x0020: ctx_src_address_low */ + 0x00000000, ++/* 0x0024: ctx_src_pitch */ + 0x00000000, ++/* 0x0028: ctx_src_tile_mode */ + 0x00000000, ++/* 0x002c: ctx_src_xsize */ + 0x00000000, ++/* 0x0030: ctx_src_ysize */ + 0x00000000, ++/* 0x0034: ctx_src_zsize */ + 0x00000000, ++/* 0x0038: ctx_src_zoff */ + 0x00000000, ++/* 0x003c: ctx_src_xoff */ + 0x00000000, ++/* 0x0040: ctx_src_yoff */ + 0x00000000, ++/* 0x0044: ctx_src_cpp */ + 0x00000000, ++/* 0x0048: ctx_dst_address_high */ + 0x00000000, ++/* 0x004c: ctx_dst_address_low */ + 0x00000000, ++/* 0x0050: ctx_dst_pitch */ + 0x00000000, ++/* 0x0054: ctx_dst_tile_mode */ + 0x00000000, ++/* 0x0058: ctx_dst_xsize */ + 0x00000000, ++/* 0x005c: ctx_dst_ysize */ + 0x00000000, ++/* 0x0060: ctx_dst_zsize */ + 0x00000000, ++/* 0x0064: ctx_dst_zoff */ + 0x00000000, ++/* 0x0068: ctx_dst_xoff */ + 0x00000000, ++/* 0x006c: ctx_dst_yoff */ + 0x00000000, ++/* 0x0070: ctx_dst_cpp */ + 0x00000000, ++/* 0x0074: ctx_format */ + 0x00000000, ++/* 0x0078: ctx_swz_const0 */ + 0x00000000, ++/* 0x007c: ctx_swz_const1 */ + 0x00000000, ++/* 0x0080: ctx_xcnt */ + 0x00000000, ++/* 0x0084: ctx_ycnt */ + 0x00000000, + 0x00000000, + 0x00000000, +@@ -63,6 +98,7 @@ uint32_t nva3_pcopy_data[] = { + 0x00000000, + 0x00000000, + 0x00000000, ++/* 0x0100: dispatch_table */ + 0x00010000, + 0x00000000, + 0x00000000, +@@ -73,6 +109,7 @@ uint32_t nva3_pcopy_data[] = { + 0x00010162, + 0x00000000, + 0x00030060, ++/* 0x0128: dispatch_dma */ + 0x00010170, + 0x00000000, + 0x00010170, +@@ -118,11 +155,11 @@ uint32_t nva3_pcopy_data[] = { + 0x0000001c, + 0xffffff00, + 0x00000020, +- 0x0000000f, ++ 0x00000000, + 0x00000048, + 0xffffff00, + 0x0000004c, +- 0x0000000f, ++ 0x00000000, + 0x00000024, + 0xfff80000, + 0x00000050, +@@ -146,7 +183,8 @@ uint32_t nva3_pcopy_data[] = { + 0x00000800, + }; + +-uint32_t nva3_pcopy_code[] = { ++u32 nva3_pcopy_code[] = { ++/* 0x0000: main */ + 0x04fe04bd, + 0x3517f000, + 0xf10010fe, +@@ -158,23 +196,31 @@ uint32_t nva3_pcopy_code[] = { + 0x17f11031, + 0x27f01200, + 0x0012d003, ++/* 0x002f: spin */ + 0xf40031f4, + 0x0ef40028, ++/* 0x0035: ih */ + 0x8001cffd, + 0xf40812c4, + 0x21f4060b, ++/* 0x0041: ih_no_chsw */ + 0x0412c472, + 0xf4060bf4, ++/* 0x004a: ih_no_cmd */ + 0x11c4c321, + 0x4001d00c, ++/* 0x0052: swctx */ + 0x47f101f8, + 0x4bfe7700, + 0x0007fe00, + 0xf00204b9, + 0x01f40643, + 0x0604fa09, ++/* 0x006b: swctx_load */ + 0xfa060ef4, ++/* 0x006e: swctx_done */ + 0x03f80504, ++/* 0x0072: chsw */ + 0x27f100f8, + 0x23cf1400, + 0x1e3fc800, +@@ -183,18 +229,22 @@ uint32_t nva3_pcopy_code[] = { + 0x1e3af052, + 0xf00023d0, + 0x24d00147, ++/* 0x0093: chsw_no_unload */ + 0xcf00f880, + 0x3dc84023, + 0x220bf41e, + 0xf40131f4, + 0x57f05221, + 0x0367f004, ++/* 0x00a8: chsw_load_ctx_dma */ + 0xa07856bc, + 0xb6018068, + 0x87d00884, + 0x0162b600, ++/* 0x00bb: chsw_finish_load */ + 0xf0f018f4, + 0x23d00237, ++/* 0x00c3: dispatch */ + 0xf100f880, + 0xcf190037, + 0x33cf4032, +@@ -202,6 +252,7 @@ uint32_t nva3_pcopy_code[] = { + 0x1024b607, + 0x010057f1, + 0x74bd64bd, ++/* 0x00dc: dispatch_loop */ + 0x58005658, + 0x50b60157, + 0x0446b804, +@@ -211,6 +262,7 @@ uint32_t nva3_pcopy_code[] = { + 0xb60276bb, + 0x57bb0374, + 0xdf0ef400, ++/* 0x0100: dispatch_valid_mthd */ + 0xb60246bb, + 0x45bb0344, + 0x01459800, +@@ -220,31 +272,41 @@ uint32_t nva3_pcopy_code[] = { + 0xb0014658, + 0x1bf40064, + 0x00538009, ++/* 0x0127: dispatch_cmd */ + 0xf4300ef4, + 0x55f90132, + 0xf40c01f4, ++/* 0x0132: dispatch_invalid_bitfield */ + 0x25f0250e, ++/* 0x0135: dispatch_illegal_mthd */ + 0x0125f002, ++/* 0x0138: dispatch_error */ + 0x100047f1, + 0xd00042d0, + 0x27f04043, + 0x0002d040, ++/* 0x0148: hostirq_wait */ + 0xf08002cf, + 0x24b04024, + 0xf71bf400, ++/* 0x0154: dispatch_done */ + 0x1d0027f1, + 0xd00137f0, + 0x00f80023, ++/* 0x0160: cmd_nop */ ++/* 0x0162: cmd_pm_trigger */ + 0x27f100f8, + 0x34bd2200, + 0xd00233f0, + 0x00f80023, ++/* 0x0170: cmd_dma */ + 0x012842b7, + 0xf00145b6, + 0x43801e39, + 0x0040b701, + 0x0644b606, + 0xf80043d0, ++/* 0x0189: cmd_exec_set_format */ + 0xf030f400, + 0xb00001b0, + 0x01b00101, +@@ -256,20 +318,26 @@ uint32_t nva3_pcopy_code[] = { + 0x70b63847, + 0x0232f401, + 0x94bd84bd, ++/* 0x01b4: ncomp_loop */ + 0xb60f4ac4, + 0xb4bd0445, ++/* 0x01bc: bpc_loop */ + 0xf404a430, + 0xa5ff0f18, + 0x00cbbbc0, + 0xf40231f4, ++/* 0x01ce: cmp_c0 */ + 0x1bf4220e, + 0x10c7f00c, + 0xf400cbbb, ++/* 0x01da: cmp_c1 */ + 0xa430160e, + 0x0c18f406, + 0xbb14c7f0, + 0x0ef400cb, ++/* 0x01e9: cmp_zero */ + 0x80c7f107, ++/* 0x01ed: bpc_next */ + 0x01c83800, + 0xb60180b6, + 0xb5b801b0, +@@ -280,6 +348,7 @@ uint32_t nva3_pcopy_code[] = { + 0x98110680, + 0x68fd2008, + 0x0502f400, ++/* 0x0216: dst_xcnt */ + 0x75fd64bd, + 0x1c078000, + 0xf10078fd, +@@ -304,6 +373,7 @@ uint32_t nva3_pcopy_code[] = { + 0x980056d0, + 0x56d01f06, + 0x1030f440, ++/* 0x0276: cmd_exec_set_surface_tiled */ + 0x579800f8, + 0x6879c70a, + 0xb66478c7, +@@ -311,9 +381,11 @@ uint32_t nva3_pcopy_code[] = { + 0x0e76b060, + 0xf0091bf4, + 0x0ef40477, ++/* 0x0291: xtile64 */ + 0x027cf00f, + 0xfd1170b6, + 0x77f00947, ++/* 0x029d: xtileok */ + 0x0f5a9806, + 0xfd115b98, + 0xb7f000ab, +@@ -371,6 +443,7 @@ uint32_t nva3_pcopy_code[] = { + 0x67d00600, + 0x0060b700, + 0x0068d004, ++/* 0x0382: cmd_exec_set_surface_linear */ + 0x6cf000f8, + 0x0260b702, + 0x0864b602, +@@ -381,13 +454,16 @@ uint32_t nva3_pcopy_code[] = { + 0xb70067d0, + 0x98040060, + 0x67d00957, ++/* 0x03ab: cmd_exec_wait */ + 0xf900f800, + 0xf110f900, + 0xb6080007, ++/* 0x03b6: loop */ + 0x01cf0604, + 0x0114f000, + 0xfcfa1bf4, + 0xf800fc10, ++/* 0x03c5: cmd_exec_query */ + 0x0d34c800, + 0xf5701bf4, + 0xf103ab21, +@@ -417,6 +493,7 @@ uint32_t nva3_pcopy_code[] = { + 0x47f10153, + 0x44b60800, + 0x0045d006, ++/* 0x0438: query_counter */ + 0x03ab21f5, + 0x080c47f1, + 0x980644b6, +@@ -439,11 +516,13 @@ uint32_t nva3_pcopy_code[] = { + 0x47f10153, + 0x44b60800, + 0x0045d006, ++/* 0x0492: cmd_exec */ + 0x21f500f8, + 0x3fc803ab, + 0x0e0bf400, + 0x018921f5, + 0x020047f1, ++/* 0x04a7: cmd_exec_no_format */ + 0xf11e0ef4, + 0xb6081067, + 0x77f00664, +@@ -451,19 +530,24 @@ uint32_t nva3_pcopy_code[] = { + 0x981c0780, + 0x67d02007, + 0x4067d000, ++/* 0x04c2: cmd_exec_init_src_surface */ + 0x32f444bd, + 0xc854bd02, + 0x0bf4043f, + 0x8221f50a, + 0x0a0ef403, ++/* 0x04d4: src_tiled */ + 0x027621f5, ++/* 0x04db: cmd_exec_init_dst_surface */ + 0xf40749f0, + 0x57f00231, + 0x083fc82c, + 0xf50a0bf4, + 0xf4038221, ++/* 0x04ee: dst_tiled */ + 0x21f50a0e, + 0x49f00276, ++/* 0x04f5: cmd_exec_kick */ + 0x0057f108, + 0x0654b608, + 0xd0210698, +@@ -473,6 +557,8 @@ uint32_t nva3_pcopy_code[] = { + 0xc80054d0, + 0x0bf40c3f, + 0xc521f507, ++/* 0x0519: cmd_exec_done */ ++/* 0x051b: cmd_wrcache_flush */ + 0xf100f803, + 0xbd220027, + 0x0133f034, +diff --git a/drivers/gpu/drm/nouveau/nvc0_copy.fuc.h b/drivers/gpu/drm/nouveau/nvc0_copy.fuc.h +index a8d1745..cd879f3 100644 +--- a/drivers/gpu/drm/nouveau/nvc0_copy.fuc.h ++++ b/drivers/gpu/drm/nouveau/nvc0_copy.fuc.h +@@ -1,34 +1,65 @@ +-uint32_t nvc0_pcopy_data[] = { ++u32 nvc0_pcopy_data[] = { ++/* 0x0000: ctx_object */ + 0x00000000, ++/* 0x0004: ctx_query_address_high */ + 0x00000000, ++/* 0x0008: ctx_query_address_low */ + 0x00000000, ++/* 0x000c: ctx_query_counter */ + 0x00000000, ++/* 0x0010: ctx_src_address_high */ + 0x00000000, ++/* 0x0014: ctx_src_address_low */ + 0x00000000, ++/* 0x0018: ctx_src_pitch */ + 0x00000000, ++/* 0x001c: ctx_src_tile_mode */ + 0x00000000, ++/* 0x0020: ctx_src_xsize */ + 0x00000000, ++/* 0x0024: ctx_src_ysize */ + 0x00000000, ++/* 0x0028: ctx_src_zsize */ + 0x00000000, ++/* 0x002c: ctx_src_zoff */ + 0x00000000, ++/* 0x0030: ctx_src_xoff */ + 0x00000000, ++/* 0x0034: ctx_src_yoff */ + 0x00000000, ++/* 0x0038: ctx_src_cpp */ + 0x00000000, ++/* 0x003c: ctx_dst_address_high */ + 0x00000000, ++/* 0x0040: ctx_dst_address_low */ + 0x00000000, ++/* 0x0044: ctx_dst_pitch */ + 0x00000000, ++/* 0x0048: ctx_dst_tile_mode */ + 0x00000000, ++/* 0x004c: ctx_dst_xsize */ + 0x00000000, ++/* 0x0050: ctx_dst_ysize */ + 0x00000000, ++/* 0x0054: ctx_dst_zsize */ + 0x00000000, ++/* 0x0058: ctx_dst_zoff */ + 0x00000000, ++/* 0x005c: ctx_dst_xoff */ + 0x00000000, ++/* 0x0060: ctx_dst_yoff */ + 0x00000000, ++/* 0x0064: ctx_dst_cpp */ + 0x00000000, ++/* 0x0068: ctx_format */ + 0x00000000, ++/* 0x006c: ctx_swz_const0 */ + 0x00000000, ++/* 0x0070: ctx_swz_const1 */ + 0x00000000, ++/* 0x0074: ctx_xcnt */ + 0x00000000, ++/* 0x0078: ctx_ycnt */ + 0x00000000, + 0x00000000, + 0x00000000, +@@ -63,6 +94,7 @@ uint32_t nvc0_pcopy_data[] = { + 0x00000000, + 0x00000000, + 0x00000000, ++/* 0x0100: dispatch_table */ + 0x00010000, + 0x00000000, + 0x00000000, +@@ -111,11 +143,11 @@ uint32_t nvc0_pcopy_data[] = { + 0x00000010, + 0xffffff00, + 0x00000014, +- 0x0000000f, ++ 0x00000000, + 0x0000003c, + 0xffffff00, + 0x00000040, +- 0x0000000f, ++ 0x00000000, + 0x00000018, + 0xfff80000, + 0x00000044, +@@ -139,7 +171,8 @@ uint32_t nvc0_pcopy_data[] = { + 0x00000800, + }; + +-uint32_t nvc0_pcopy_code[] = { ++u32 nvc0_pcopy_code[] = { ++/* 0x0000: main */ + 0x04fe04bd, + 0x3517f000, + 0xf10010fe, +@@ -151,15 +184,20 @@ uint32_t nvc0_pcopy_code[] = { + 0x17f11031, + 0x27f01200, + 0x0012d003, ++/* 0x002f: spin */ + 0xf40031f4, + 0x0ef40028, ++/* 0x0035: ih */ + 0x8001cffd, + 0xf40812c4, + 0x21f4060b, ++/* 0x0041: ih_no_chsw */ + 0x0412c4ca, + 0xf5070bf4, ++/* 0x004b: ih_no_cmd */ + 0xc4010221, + 0x01d00c11, ++/* 0x0053: swctx */ + 0xf101f840, + 0xfe770047, + 0x47f1004b, +@@ -188,8 +226,11 @@ uint32_t nvc0_pcopy_code[] = { + 0xf00204b9, + 0x01f40643, + 0x0604fa09, ++/* 0x00c3: swctx_load */ + 0xfa060ef4, ++/* 0x00c6: swctx_done */ + 0x03f80504, ++/* 0x00ca: chsw */ + 0x27f100f8, + 0x23cf1400, + 0x1e3fc800, +@@ -198,18 +239,22 @@ uint32_t nvc0_pcopy_code[] = { + 0x1e3af053, + 0xf00023d0, + 0x24d00147, ++/* 0x00eb: chsw_no_unload */ + 0xcf00f880, + 0x3dc84023, + 0x090bf41e, + 0xf40131f4, ++/* 0x00fa: chsw_finish_load */ + 0x37f05321, + 0x8023d002, ++/* 0x0102: dispatch */ + 0x37f100f8, + 0x32cf1900, + 0x0033cf40, + 0x07ff24e4, + 0xf11024b6, + 0xbd010057, ++/* 0x011b: dispatch_loop */ + 0x5874bd64, + 0x57580056, + 0x0450b601, +@@ -219,6 +264,7 @@ uint32_t nvc0_pcopy_code[] = { + 0xbb0f08f4, + 0x74b60276, + 0x0057bb03, ++/* 0x013f: dispatch_valid_mthd */ + 0xbbdf0ef4, + 0x44b60246, + 0x0045bb03, +@@ -229,24 +275,33 @@ uint32_t nvc0_pcopy_code[] = { + 0x64b00146, + 0x091bf400, + 0xf4005380, ++/* 0x0166: dispatch_cmd */ + 0x32f4300e, + 0xf455f901, + 0x0ef40c01, ++/* 0x0171: dispatch_invalid_bitfield */ + 0x0225f025, ++/* 0x0174: dispatch_illegal_mthd */ ++/* 0x0177: dispatch_error */ + 0xf10125f0, + 0xd0100047, + 0x43d00042, + 0x4027f040, ++/* 0x0187: hostirq_wait */ + 0xcf0002d0, + 0x24f08002, + 0x0024b040, ++/* 0x0193: dispatch_done */ + 0xf1f71bf4, + 0xf01d0027, + 0x23d00137, ++/* 0x019f: cmd_nop */ + 0xf800f800, ++/* 0x01a1: cmd_pm_trigger */ + 0x0027f100, + 0xf034bd22, + 0x23d00233, ++/* 0x01af: cmd_exec_set_format */ + 0xf400f800, + 0x01b0f030, + 0x0101b000, +@@ -258,20 +313,26 @@ uint32_t nvc0_pcopy_code[] = { + 0x3847c701, + 0xf40170b6, + 0x84bd0232, ++/* 0x01da: ncomp_loop */ + 0x4ac494bd, + 0x0445b60f, ++/* 0x01e2: bpc_loop */ + 0xa430b4bd, + 0x0f18f404, + 0xbbc0a5ff, + 0x31f400cb, + 0x220ef402, ++/* 0x01f4: cmp_c0 */ + 0xf00c1bf4, + 0xcbbb10c7, + 0x160ef400, ++/* 0x0200: cmp_c1 */ + 0xf406a430, + 0xc7f00c18, + 0x00cbbb14, ++/* 0x020f: cmp_zero */ + 0xf1070ef4, ++/* 0x0213: bpc_next */ + 0x380080c7, + 0x80b601c8, + 0x01b0b601, +@@ -283,6 +344,7 @@ uint32_t nvc0_pcopy_code[] = { + 0x1d08980e, + 0xf40068fd, + 0x64bd0502, ++/* 0x023c: dst_xcnt */ + 0x800075fd, + 0x78fd1907, + 0x1057f100, +@@ -307,15 +369,18 @@ uint32_t nvc0_pcopy_code[] = { + 0x1c069800, + 0xf44056d0, + 0x00f81030, ++/* 0x029c: cmd_exec_set_surface_tiled */ + 0xc7075798, + 0x78c76879, + 0x0380b664, + 0xb06077c7, + 0x1bf40e76, + 0x0477f009, ++/* 0x02b7: xtile64 */ + 0xf00f0ef4, + 0x70b6027c, + 0x0947fd11, ++/* 0x02c3: xtileok */ + 0x980677f0, + 0x5b980c5a, + 0x00abfd0e, +@@ -374,6 +439,7 @@ uint32_t nvc0_pcopy_code[] = { + 0xb70067d0, + 0xd0040060, + 0x00f80068, ++/* 0x03a8: cmd_exec_set_surface_linear */ + 0xb7026cf0, + 0xb6020260, + 0x57980864, +@@ -384,12 +450,15 @@ uint32_t nvc0_pcopy_code[] = { + 0x0060b700, + 0x06579804, + 0xf80067d0, ++/* 0x03d1: cmd_exec_wait */ + 0xf900f900, + 0x0007f110, + 0x0604b608, ++/* 0x03dc: loop */ + 0xf00001cf, + 0x1bf40114, + 0xfc10fcfa, ++/* 0x03eb: cmd_exec_query */ + 0xc800f800, + 0x1bf40d34, + 0xd121f570, +@@ -419,6 +488,7 @@ uint32_t nvc0_pcopy_code[] = { + 0x0153f026, + 0x080047f1, + 0xd00644b6, ++/* 0x045e: query_counter */ + 0x21f50045, + 0x47f103d1, + 0x44b6080c, +@@ -442,11 +512,13 @@ uint32_t nvc0_pcopy_code[] = { + 0x080047f1, + 0xd00644b6, + 0x00f80045, ++/* 0x04b8: cmd_exec */ + 0x03d121f5, + 0xf4003fc8, + 0x21f50e0b, + 0x47f101af, + 0x0ef40200, ++/* 0x04cd: cmd_exec_no_format */ + 0x1067f11e, + 0x0664b608, + 0x800177f0, +@@ -454,18 +526,23 @@ uint32_t nvc0_pcopy_code[] = { + 0x1d079819, + 0xd00067d0, + 0x44bd4067, ++/* 0x04e8: cmd_exec_init_src_surface */ + 0xbd0232f4, + 0x043fc854, + 0xf50a0bf4, + 0xf403a821, ++/* 0x04fa: src_tiled */ + 0x21f50a0e, + 0x49f0029c, ++/* 0x0501: cmd_exec_init_dst_surface */ + 0x0231f407, + 0xc82c57f0, + 0x0bf4083f, + 0xa821f50a, + 0x0a0ef403, ++/* 0x0514: dst_tiled */ + 0x029c21f5, ++/* 0x051b: cmd_exec_kick */ + 0xf10849f0, + 0xb6080057, + 0x06980654, +@@ -475,7 +552,9 @@ uint32_t nvc0_pcopy_code[] = { + 0x54d00546, + 0x0c3fc800, + 0xf5070bf4, ++/* 0x053f: cmd_exec_done */ + 0xf803eb21, ++/* 0x0541: cmd_wrcache_flush */ + 0x0027f100, + 0xf034bd22, + 0x23d00133, +diff --git a/drivers/gpu/drm/nouveau/nvc0_fence.c b/drivers/gpu/drm/nouveau/nvc0_fence.c +index 47ab388..8e5a2f4 100644 +--- a/drivers/gpu/drm/nouveau/nvc0_fence.c ++++ b/drivers/gpu/drm/nouveau/nvc0_fence.c +@@ -32,6 +32,7 @@ + struct nvc0_fence_priv { + struct nouveau_fence_priv base; + struct nouveau_bo *bo; ++ u32 *suspend; + }; + + struct nvc0_fence_chan { +@@ -125,12 +126,36 @@ nvc0_fence_context_new(struct nouveau_channel *chan, int engine) + static int + nvc0_fence_fini(struct drm_device *dev, int engine, bool suspend) + { ++ struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO); ++ struct nvc0_fence_priv *priv = nv_engine(dev, engine); ++ int i; ++ ++ if (suspend) { ++ priv->suspend = vmalloc(pfifo->channels * sizeof(u32)); ++ if (!priv->suspend) ++ return -ENOMEM; ++ ++ for (i = 0; i < pfifo->channels; i++) ++ priv->suspend[i] = nouveau_bo_rd32(priv->bo, i); ++ } ++ + return 0; + } + + static int + nvc0_fence_init(struct drm_device *dev, int engine) + { ++ struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO); ++ struct nvc0_fence_priv *priv = nv_engine(dev, engine); ++ int i; ++ ++ if (priv->suspend) { ++ for (i = 0; i < pfifo->channels; i++) ++ nouveau_bo_wr32(priv->bo, i, priv->suspend[i]); ++ vfree(priv->suspend); ++ priv->suspend = NULL; ++ } ++ + return 0; + } + +diff --git a/drivers/gpu/drm/nouveau/nvc0_pm.c b/drivers/gpu/drm/nouveau/nvc0_pm.c +index 7c95c44..4e712b1 100644 +--- a/drivers/gpu/drm/nouveau/nvc0_pm.c ++++ b/drivers/gpu/drm/nouveau/nvc0_pm.c +@@ -557,7 +557,7 @@ prog_mem(struct drm_device *dev, struct nvc0_pm_state *info) + nouveau_mem_exec(&exec, info->perflvl); + + if (dev_priv->chipset < 0xd0) +- nv_wr32(dev, 0x611200, 0x00003300); ++ nv_wr32(dev, 0x611200, 0x00003330); + else + nv_wr32(dev, 0x62c000, 0x03030300); + } +diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c +index c486d3c..c50b075 100644 +--- a/drivers/gpu/drm/nouveau/nvd0_display.c ++++ b/drivers/gpu/drm/nouveau/nvd0_display.c +@@ -790,7 +790,7 @@ nvd0_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) + struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); + int ch = EVO_CURS(nv_crtc->index); + +- evo_piow(crtc->dev, ch, 0x0084, (y << 16) | x); ++ evo_piow(crtc->dev, ch, 0x0084, (y << 16) | (x & 0xffff)); + evo_piow(crtc->dev, ch, 0x0080, 0x00000000); + return 0; + } +diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c +index 3904d79..25b8014 100644 +--- a/drivers/gpu/drm/radeon/atombios_crtc.c ++++ b/drivers/gpu/drm/radeon/atombios_crtc.c +@@ -258,8 +258,7 @@ void atombios_crtc_dpms(struct drm_crtc *crtc, int mode) + radeon_crtc->enabled = true; + /* adjust pm to dpms changes BEFORE enabling crtcs */ + radeon_pm_compute_clocks(rdev); +- /* disable crtc pair power gating before programming */ +- if (ASIC_IS_DCE6(rdev)) ++ if (ASIC_IS_DCE6(rdev) && !radeon_crtc->in_mode_set) + atombios_powergate_crtc(crtc, ATOM_DISABLE); + atombios_enable_crtc(crtc, ATOM_ENABLE); + if (ASIC_IS_DCE3(rdev) && !ASIC_IS_DCE6(rdev)) +@@ -278,25 +277,8 @@ void atombios_crtc_dpms(struct drm_crtc *crtc, int mode) + atombios_enable_crtc_memreq(crtc, ATOM_DISABLE); + atombios_enable_crtc(crtc, ATOM_DISABLE); + radeon_crtc->enabled = false; +- /* power gating is per-pair */ +- if (ASIC_IS_DCE6(rdev)) { +- struct drm_crtc *other_crtc; +- struct radeon_crtc *other_radeon_crtc; +- list_for_each_entry(other_crtc, &rdev->ddev->mode_config.crtc_list, head) { +- other_radeon_crtc = to_radeon_crtc(other_crtc); +- if (((radeon_crtc->crtc_id == 0) && (other_radeon_crtc->crtc_id == 1)) || +- ((radeon_crtc->crtc_id == 1) && (other_radeon_crtc->crtc_id == 0)) || +- ((radeon_crtc->crtc_id == 2) && (other_radeon_crtc->crtc_id == 3)) || +- ((radeon_crtc->crtc_id == 3) && (other_radeon_crtc->crtc_id == 2)) || +- ((radeon_crtc->crtc_id == 4) && (other_radeon_crtc->crtc_id == 5)) || +- ((radeon_crtc->crtc_id == 5) && (other_radeon_crtc->crtc_id == 4))) { +- /* if both crtcs in the pair are off, enable power gating */ +- if (other_radeon_crtc->enabled == false) +- atombios_powergate_crtc(crtc, ATOM_ENABLE); +- break; +- } +- } +- } ++ if (ASIC_IS_DCE6(rdev) && !radeon_crtc->in_mode_set) ++ atombios_powergate_crtc(crtc, ATOM_ENABLE); + /* adjust pm to dpms changes AFTER disabling crtcs */ + radeon_pm_compute_clocks(rdev); + break; +@@ -444,11 +426,28 @@ union atom_enable_ss { + static void atombios_crtc_program_ss(struct radeon_device *rdev, + int enable, + int pll_id, ++ int crtc_id, + struct radeon_atom_ss *ss) + { ++ unsigned i; + int index = GetIndexIntoMasterTable(COMMAND, EnableSpreadSpectrumOnPPLL); + union atom_enable_ss args; + ++ if (!enable) { ++ for (i = 0; i < rdev->num_crtc; i++) { ++ if (rdev->mode_info.crtcs[i] && ++ rdev->mode_info.crtcs[i]->enabled && ++ i != crtc_id && ++ pll_id == rdev->mode_info.crtcs[i]->pll_id) { ++ /* one other crtc is using this pll don't turn ++ * off spread spectrum as it might turn off ++ * display on active crtc ++ */ ++ return; ++ } ++ } ++ } ++ + memset(&args, 0, sizeof(args)); + + if (ASIC_IS_DCE5(rdev)) { +@@ -1036,7 +1035,7 @@ static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode + radeon_compute_pll_legacy(pll, adjusted_clock, &pll_clock, &fb_div, &frac_fb_div, + &ref_div, &post_div); + +- atombios_crtc_program_ss(rdev, ATOM_DISABLE, radeon_crtc->pll_id, &ss); ++ atombios_crtc_program_ss(rdev, ATOM_DISABLE, radeon_crtc->pll_id, radeon_crtc->crtc_id, &ss); + + atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, + encoder_mode, radeon_encoder->encoder_id, mode->clock, +@@ -1059,7 +1058,7 @@ static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode + ss.step = step_size; + } + +- atombios_crtc_program_ss(rdev, ATOM_ENABLE, radeon_crtc->pll_id, &ss); ++ atombios_crtc_program_ss(rdev, ATOM_ENABLE, radeon_crtc->pll_id, radeon_crtc->crtc_id, &ss); + } + } + +@@ -1576,11 +1575,11 @@ void radeon_atom_disp_eng_pll_init(struct radeon_device *rdev) + ASIC_INTERNAL_SS_ON_DCPLL, + rdev->clock.default_dispclk); + if (ss_enabled) +- atombios_crtc_program_ss(rdev, ATOM_DISABLE, ATOM_DCPLL, &ss); ++ atombios_crtc_program_ss(rdev, ATOM_DISABLE, ATOM_DCPLL, -1, &ss); + /* XXX: DCE5, make sure voltage, dispclk is high enough */ + atombios_crtc_set_disp_eng_pll(rdev, rdev->clock.default_dispclk); + if (ss_enabled) +- atombios_crtc_program_ss(rdev, ATOM_ENABLE, ATOM_DCPLL, &ss); ++ atombios_crtc_program_ss(rdev, ATOM_ENABLE, ATOM_DCPLL, -1, &ss); + } + + } +@@ -1639,18 +1638,28 @@ static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc, + static void atombios_crtc_prepare(struct drm_crtc *crtc) + { + struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); ++ struct drm_device *dev = crtc->dev; ++ struct radeon_device *rdev = dev->dev_private; + ++ radeon_crtc->in_mode_set = true; + /* pick pll */ + radeon_crtc->pll_id = radeon_atom_pick_pll(crtc); + ++ /* disable crtc pair power gating before programming */ ++ if (ASIC_IS_DCE6(rdev)) ++ atombios_powergate_crtc(crtc, ATOM_DISABLE); ++ + atombios_lock_crtc(crtc, ATOM_ENABLE); + atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); + } + + static void atombios_crtc_commit(struct drm_crtc *crtc) + { ++ struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); ++ + atombios_crtc_dpms(crtc, DRM_MODE_DPMS_ON); + atombios_lock_crtc(crtc, ATOM_DISABLE); ++ radeon_crtc->in_mode_set = false; + } + + static void atombios_crtc_disable(struct drm_crtc *crtc) +@@ -1659,9 +1668,22 @@ static void atombios_crtc_disable(struct drm_crtc *crtc) + struct drm_device *dev = crtc->dev; + struct radeon_device *rdev = dev->dev_private; + struct radeon_atom_ss ss; ++ int i; + + atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); + ++ for (i = 0; i < rdev->num_crtc; i++) { ++ if (rdev->mode_info.crtcs[i] && ++ rdev->mode_info.crtcs[i]->enabled && ++ i != radeon_crtc->crtc_id && ++ radeon_crtc->pll_id == rdev->mode_info.crtcs[i]->pll_id) { ++ /* one other crtc is using this pll don't turn ++ * off the pll ++ */ ++ goto done; ++ } ++ } ++ + switch (radeon_crtc->pll_id) { + case ATOM_PPLL1: + case ATOM_PPLL2: +@@ -1678,6 +1700,7 @@ static void atombios_crtc_disable(struct drm_crtc *crtc) + default: + break; + } ++done: + radeon_crtc->pll_id = -1; + } + +diff --git a/drivers/gpu/drm/radeon/atombios_dp.c b/drivers/gpu/drm/radeon/atombios_dp.c +index 5131b3b..500cced 100644 +--- a/drivers/gpu/drm/radeon/atombios_dp.c ++++ b/drivers/gpu/drm/radeon/atombios_dp.c +@@ -22,6 +22,7 @@ + * + * Authors: Dave Airlie + * Alex Deucher ++ * Jerome Glisse + */ + #include "drmP.h" + #include "radeon_drm.h" +@@ -654,7 +655,6 @@ static bool radeon_dp_get_link_status(struct radeon_connector *radeon_connector, + 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; + } + +@@ -833,8 +833,10 @@ static int radeon_dp_link_train_cr(struct radeon_dp_link_train_info *dp_info) + 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; +@@ -896,8 +898,10 @@ static int radeon_dp_link_train_ce(struct radeon_dp_link_train_info *dp_info) + 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 --git a/drivers/gpu/drm/radeon/atombios_encoders.c b/drivers/gpu/drm/radeon/atombios_encoders.c +index 486ccdf..700dfab 100644 +--- a/drivers/gpu/drm/radeon/atombios_encoders.c ++++ b/drivers/gpu/drm/radeon/atombios_encoders.c +@@ -1379,6 +1379,8 @@ radeon_atom_encoder_dpms_dig(struct drm_encoder *encoder, int mode) + struct drm_device *dev = encoder->dev; + struct radeon_device *rdev = dev->dev_private; + struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); ++ struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder); ++ struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; + struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); + struct radeon_connector *radeon_connector = NULL; + struct radeon_connector_atom_dig *radeon_dig_connector = NULL; +@@ -1390,12 +1392,38 @@ radeon_atom_encoder_dpms_dig(struct drm_encoder *encoder, int mode) + + switch (mode) { + case DRM_MODE_DPMS_ON: +- /* some early dce3.2 boards have a bug in their transmitter control table */ +- if ((rdev->family == CHIP_RV710) || (rdev->family == CHIP_RV730) || +- ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) ++ if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) { ++ if (!connector) ++ dig->panel_mode = DP_PANEL_MODE_EXTERNAL_DP_MODE; ++ else ++ dig->panel_mode = radeon_dp_get_panel_mode(encoder, connector); ++ ++ /* setup and enable the encoder */ ++ atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0); ++ atombios_dig_encoder_setup(encoder, ++ ATOM_ENCODER_CMD_SETUP_PANEL_MODE, ++ dig->panel_mode); ++ if (ext_encoder) { ++ if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)) ++ atombios_external_encoder_setup(encoder, ext_encoder, ++ EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP); ++ } ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0); ++ } else if (ASIC_IS_DCE4(rdev)) { ++ /* setup and enable the encoder */ ++ atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0); ++ /* enable the transmitter */ + atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0); +- else + atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0); ++ } else { ++ /* setup and enable the encoder and transmitter */ ++ atombios_dig_encoder_setup(encoder, ATOM_ENABLE, 0); ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0); ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0); ++ /* some early dce3.2 boards have a bug in their transmitter control table */ ++ if ((rdev->family != CHIP_RV710) || (rdev->family != CHIP_RV730)) ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0); ++ } + if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) { + if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) { + atombios_set_edp_panel_power(connector, +@@ -1412,10 +1440,19 @@ radeon_atom_encoder_dpms_dig(struct drm_encoder *encoder, int mode) + case DRM_MODE_DPMS_STANDBY: + case DRM_MODE_DPMS_SUSPEND: + case DRM_MODE_DPMS_OFF: +- if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) ++ if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) { ++ /* disable the transmitter */ + atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); +- else ++ } else if (ASIC_IS_DCE4(rdev)) { ++ /* disable the transmitter */ + atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0); ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); ++ } else { ++ /* disable the encoder and transmitter */ ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0); ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); ++ atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0); ++ } + if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) { + if (ASIC_IS_DCE4(rdev)) + atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0); +@@ -1732,13 +1769,34 @@ static int radeon_atom_pick_dig_encoder(struct drm_encoder *encoder) + struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); + struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); + struct drm_encoder *test_encoder; +- struct radeon_encoder_atom_dig *dig; ++ struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; + uint32_t dig_enc_in_use = 0; + +- /* DCE4/5 */ +- if (ASIC_IS_DCE4(rdev)) { +- dig = radeon_encoder->enc_priv; +- if (ASIC_IS_DCE41(rdev)) { ++ if (ASIC_IS_DCE6(rdev)) { ++ /* DCE6 */ ++ switch (radeon_encoder->encoder_id) { ++ case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: ++ if (dig->linkb) ++ return 1; ++ else ++ return 0; ++ break; ++ case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: ++ if (dig->linkb) ++ return 3; ++ else ++ return 2; ++ break; ++ case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: ++ if (dig->linkb) ++ return 5; ++ else ++ return 4; ++ break; ++ } ++ } else if (ASIC_IS_DCE4(rdev)) { ++ /* DCE4/5 */ ++ if (ASIC_IS_DCE41(rdev) && !ASIC_IS_DCE61(rdev)) { + /* ontario follows DCE4 */ + if (rdev->family == CHIP_PALM) { + if (dig->linkb) +@@ -1840,10 +1898,12 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder, + struct drm_device *dev = encoder->dev; + struct radeon_device *rdev = dev->dev_private; + struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); +- struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder); + + radeon_encoder->pixel_clock = adjusted_mode->clock; + ++ /* need to call this here rather than in prepare() since we need some crtc info */ ++ radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); ++ + if (ASIC_IS_AVIVO(rdev) && !ASIC_IS_DCE4(rdev)) { + if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT)) + atombios_yuv_setup(encoder, true); +@@ -1862,38 +1922,7 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder, + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: + case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: +- if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) { +- struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); +- struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; +- +- if (!connector) +- dig->panel_mode = DP_PANEL_MODE_EXTERNAL_DP_MODE; +- else +- dig->panel_mode = radeon_dp_get_panel_mode(encoder, connector); +- +- /* setup and enable the encoder */ +- atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0); +- atombios_dig_encoder_setup(encoder, +- ATOM_ENCODER_CMD_SETUP_PANEL_MODE, +- dig->panel_mode); +- } else if (ASIC_IS_DCE4(rdev)) { +- /* disable the transmitter */ +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); +- /* setup and enable the encoder */ +- atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0); +- +- /* enable the transmitter */ +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0); +- } else { +- /* disable the encoder and transmitter */ +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); +- atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0); +- +- /* setup and enable the encoder and transmitter */ +- atombios_dig_encoder_setup(encoder, ATOM_ENABLE, 0); +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0); +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0); +- } ++ /* handled in dpms */ + break; + case ENCODER_OBJECT_ID_INTERNAL_DDI: + case ENCODER_OBJECT_ID_INTERNAL_DVO1: +@@ -1914,14 +1943,6 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder, + break; + } + +- if (ext_encoder) { +- if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)) +- atombios_external_encoder_setup(encoder, ext_encoder, +- EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP); +- else +- atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE); +- } +- + atombios_apply_encoder_quirks(encoder, adjusted_mode); + + if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) { +@@ -2108,7 +2129,6 @@ static void radeon_atom_encoder_prepare(struct drm_encoder *encoder) + } + + radeon_atom_output_lock(encoder, true); +- radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); + + if (connector) { + struct radeon_connector *radeon_connector = to_radeon_connector(connector); +@@ -2129,6 +2149,7 @@ static void radeon_atom_encoder_prepare(struct drm_encoder *encoder) + + static void radeon_atom_encoder_commit(struct drm_encoder *encoder) + { ++ /* need to call this here as we need the crtc set up */ + radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON); + radeon_atom_output_lock(encoder, false); + } +@@ -2169,14 +2190,7 @@ static void radeon_atom_encoder_disable(struct drm_encoder *encoder) + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: + case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: +- if (ASIC_IS_DCE4(rdev)) +- /* disable the transmitter */ +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); +- else { +- /* disable the encoder and transmitter */ +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); +- atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0); +- } ++ /* handled in dpms */ + break; + case ENCODER_OBJECT_ID_INTERNAL_DDI: + case ENCODER_OBJECT_ID_INTERNAL_DVO1: +diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c +index 7fb3d2e..e98dc9c 100644 +--- a/drivers/gpu/drm/radeon/evergreen.c ++++ b/drivers/gpu/drm/radeon/evergreen.c +@@ -1117,24 +1117,8 @@ void evergreen_agp_enable(struct radeon_device *rdev) + + void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save) + { +- save->vga_control[0] = RREG32(D1VGA_CONTROL); +- save->vga_control[1] = RREG32(D2VGA_CONTROL); + save->vga_render_control = RREG32(VGA_RENDER_CONTROL); + save->vga_hdp_control = RREG32(VGA_HDP_CONTROL); +- save->crtc_control[0] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET); +- save->crtc_control[1] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET); +- if (rdev->num_crtc >= 4) { +- save->vga_control[2] = RREG32(EVERGREEN_D3VGA_CONTROL); +- save->vga_control[3] = RREG32(EVERGREEN_D4VGA_CONTROL); +- save->crtc_control[2] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET); +- save->crtc_control[3] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET); +- } +- if (rdev->num_crtc >= 6) { +- save->vga_control[4] = RREG32(EVERGREEN_D5VGA_CONTROL); +- save->vga_control[5] = RREG32(EVERGREEN_D6VGA_CONTROL); +- save->crtc_control[4] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET); +- save->crtc_control[5] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); +- } + + /* Stop all video */ + WREG32(VGA_RENDER_CONTROL, 0); +@@ -1245,47 +1229,6 @@ void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *s + /* Unlock host access */ + WREG32(VGA_HDP_CONTROL, save->vga_hdp_control); + mdelay(1); +- /* Restore video state */ +- WREG32(D1VGA_CONTROL, save->vga_control[0]); +- WREG32(D2VGA_CONTROL, save->vga_control[1]); +- if (rdev->num_crtc >= 4) { +- WREG32(EVERGREEN_D3VGA_CONTROL, save->vga_control[2]); +- WREG32(EVERGREEN_D4VGA_CONTROL, save->vga_control[3]); +- } +- if (rdev->num_crtc >= 6) { +- WREG32(EVERGREEN_D5VGA_CONTROL, save->vga_control[4]); +- WREG32(EVERGREEN_D6VGA_CONTROL, save->vga_control[5]); +- } +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC0_REGISTER_OFFSET, 1); +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC1_REGISTER_OFFSET, 1); +- if (rdev->num_crtc >= 4) { +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC2_REGISTER_OFFSET, 1); +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC3_REGISTER_OFFSET, 1); +- } +- if (rdev->num_crtc >= 6) { +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC4_REGISTER_OFFSET, 1); +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC5_REGISTER_OFFSET, 1); +- } +- WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, save->crtc_control[0]); +- WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, save->crtc_control[1]); +- if (rdev->num_crtc >= 4) { +- WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, save->crtc_control[2]); +- WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, save->crtc_control[3]); +- } +- if (rdev->num_crtc >= 6) { +- WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, save->crtc_control[4]); +- WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, save->crtc_control[5]); +- } +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0); +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0); +- if (rdev->num_crtc >= 4) { +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0); +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0); +- } +- if (rdev->num_crtc >= 6) { +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0); +- WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0); +- } + WREG32(VGA_RENDER_CONTROL, save->vga_render_control); + } + +@@ -1858,10 +1801,18 @@ static void evergreen_gpu_init(struct radeon_device *rdev) + if (rdev->flags & RADEON_IS_IGP) + rdev->config.evergreen.tile_config |= 1 << 4; + else { +- if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) +- rdev->config.evergreen.tile_config |= 1 << 4; +- else ++ switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) { ++ case 0: /* four banks */ + rdev->config.evergreen.tile_config |= 0 << 4; ++ break; ++ case 1: /* eight banks */ ++ rdev->config.evergreen.tile_config |= 1 << 4; ++ break; ++ case 2: /* sixteen banks */ ++ default: ++ rdev->config.evergreen.tile_config |= 2 << 4; ++ break; ++ } + } + rdev->config.evergreen.tile_config |= 0 << 8; + rdev->config.evergreen.tile_config |= +diff --git a/drivers/gpu/drm/radeon/evergreen_cs.c b/drivers/gpu/drm/radeon/evergreen_cs.c +index c1655412..f2e5c54 100644 +--- a/drivers/gpu/drm/radeon/evergreen_cs.c ++++ b/drivers/gpu/drm/radeon/evergreen_cs.c +@@ -961,13 +961,15 @@ static int evergreen_cs_track_check(struct radeon_cs_parser *p) + + if (track->db_dirty) { + /* Check stencil buffer */ +- if (G_028800_STENCIL_ENABLE(track->db_depth_control)) { ++ if (G_028044_FORMAT(track->db_s_info) != V_028044_STENCIL_INVALID && ++ G_028800_STENCIL_ENABLE(track->db_depth_control)) { + r = evergreen_cs_track_validate_stencil(p); + if (r) + return r; + } + /* Check depth buffer */ +- if (G_028800_Z_ENABLE(track->db_depth_control)) { ++ if (G_028040_FORMAT(track->db_z_info) != V_028040_Z_INVALID && ++ G_028800_Z_ENABLE(track->db_depth_control)) { + r = evergreen_cs_track_validate_depth(p); + if (r) + return r; +diff --git a/drivers/gpu/drm/radeon/evergreend.h b/drivers/gpu/drm/radeon/evergreend.h +index b50b15c..4a43b46 100644 +--- a/drivers/gpu/drm/radeon/evergreend.h ++++ b/drivers/gpu/drm/radeon/evergreend.h +@@ -1273,6 +1273,8 @@ + #define S_028044_FORMAT(x) (((x) & 0x1) << 0) + #define G_028044_FORMAT(x) (((x) >> 0) & 0x1) + #define C_028044_FORMAT 0xFFFFFFFE ++#define V_028044_STENCIL_INVALID 0 ++#define V_028044_STENCIL_8 1 + #define G_028044_TILE_SPLIT(x) (((x) >> 8) & 0x7) + #define DB_Z_READ_BASE 0x28048 + #define DB_STENCIL_READ_BASE 0x2804c +diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c +index b7bf18e..2732a70 100644 +--- a/drivers/gpu/drm/radeon/ni.c ++++ b/drivers/gpu/drm/radeon/ni.c +@@ -574,10 +574,18 @@ static void cayman_gpu_init(struct radeon_device *rdev) + if (rdev->flags & RADEON_IS_IGP) + rdev->config.cayman.tile_config |= 1 << 4; + else { +- if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) +- rdev->config.cayman.tile_config |= 1 << 4; +- else ++ switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) { ++ case 0: /* four banks */ + rdev->config.cayman.tile_config |= 0 << 4; ++ break; ++ case 1: /* eight banks */ ++ rdev->config.cayman.tile_config |= 1 << 4; ++ break; ++ case 2: /* sixteen banks */ ++ default: ++ rdev->config.cayman.tile_config |= 2 << 4; ++ break; ++ } + } + rdev->config.cayman.tile_config |= + ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8; +diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c +index ca87f7a..1119e31 100644 +--- a/drivers/gpu/drm/radeon/r600_cs.c ++++ b/drivers/gpu/drm/radeon/r600_cs.c +@@ -764,8 +764,10 @@ static int r600_cs_track_check(struct radeon_cs_parser *p) + } + + /* Check depth buffer */ +- if (track->db_dirty && (G_028800_STENCIL_ENABLE(track->db_depth_control) || +- G_028800_Z_ENABLE(track->db_depth_control))) { ++ if (track->db_dirty && ++ G_028010_FORMAT(track->db_depth_info) != V_028010_DEPTH_INVALID && ++ (G_028800_STENCIL_ENABLE(track->db_depth_control) || ++ G_028800_Z_ENABLE(track->db_depth_control))) { + r = r600_cs_track_validate_db(p); + if (r) + return r; +diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h +index fefcca5..5c8a0bf 100644 +--- a/drivers/gpu/drm/radeon/radeon.h ++++ b/drivers/gpu/drm/radeon/radeon.h +@@ -143,21 +143,6 @@ struct radeon_device; + /* + * BIOS. + */ +-#define ATRM_BIOS_PAGE 4096 +- +-#if defined(CONFIG_VGA_SWITCHEROO) +-bool radeon_atrm_supported(struct pci_dev *pdev); +-int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len); +-#else +-static inline bool radeon_atrm_supported(struct pci_dev *pdev) +-{ +- return false; +-} +- +-static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){ +- return -EINVAL; +-} +-#endif + bool radeon_get_bios(struct radeon_device *rdev); + + +@@ -323,6 +308,7 @@ struct radeon_bo_va { + uint64_t soffset; + uint64_t eoffset; + uint32_t flags; ++ struct radeon_fence *fence; + bool valid; + }; + +diff --git a/drivers/gpu/drm/radeon/radeon_asic.h b/drivers/gpu/drm/radeon/radeon_asic.h +index e76a941..476c68d 100644 +--- a/drivers/gpu/drm/radeon/radeon_asic.h ++++ b/drivers/gpu/drm/radeon/radeon_asic.h +@@ -256,13 +256,10 @@ extern int rs690_mc_wait_for_idle(struct radeon_device *rdev); + * rv515 + */ + struct rv515_mc_save { +- u32 d1vga_control; +- u32 d2vga_control; + u32 vga_render_control; + u32 vga_hdp_control; +- u32 d1crtc_control; +- u32 d2crtc_control; + }; ++ + int rv515_init(struct radeon_device *rdev); + void rv515_fini(struct radeon_device *rdev); + uint32_t rv515_mc_rreg(struct radeon_device *rdev, uint32_t reg); +@@ -389,11 +386,10 @@ void r700_cp_fini(struct radeon_device *rdev); + * evergreen + */ + struct evergreen_mc_save { +- u32 vga_control[6]; + u32 vga_render_control; + u32 vga_hdp_control; +- u32 crtc_control[6]; + }; ++ + void evergreen_pcie_gart_tlb_flush(struct radeon_device *rdev); + int evergreen_init(struct radeon_device *rdev); + void evergreen_fini(struct radeon_device *rdev); +diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c +index b1e3820..5e30e12 100644 +--- a/drivers/gpu/drm/radeon/radeon_atombios.c ++++ b/drivers/gpu/drm/radeon/radeon_atombios.c +@@ -452,7 +452,7 @@ static bool radeon_atom_apply_quirks(struct drm_device *dev, + } + + /* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */ +- if ((dev->pdev->device == 0x9802) && ++ if (((dev->pdev->device == 0x9802) || (dev->pdev->device == 0x9806)) && + (dev->pdev->subsystem_vendor == 0x1734) && + (dev->pdev->subsystem_device == 0x11bd)) { + if (*connector_type == DRM_MODE_CONNECTOR_VGA) { +diff --git a/drivers/gpu/drm/radeon/radeon_atpx_handler.c b/drivers/gpu/drm/radeon/radeon_atpx_handler.c +index 98724fc..2a2cf0b 100644 +--- a/drivers/gpu/drm/radeon/radeon_atpx_handler.c ++++ b/drivers/gpu/drm/radeon/radeon_atpx_handler.c +@@ -30,57 +30,8 @@ static struct radeon_atpx_priv { + /* handle for device - and atpx */ + acpi_handle dhandle; + acpi_handle atpx_handle; +- acpi_handle atrm_handle; + } radeon_atpx_priv; + +-/* retrieve the ROM in 4k blocks */ +-static int radeon_atrm_call(acpi_handle atrm_handle, uint8_t *bios, +- int offset, int len) +-{ +- acpi_status status; +- union acpi_object atrm_arg_elements[2], *obj; +- struct acpi_object_list atrm_arg; +- struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL}; +- +- atrm_arg.count = 2; +- atrm_arg.pointer = &atrm_arg_elements[0]; +- +- atrm_arg_elements[0].type = ACPI_TYPE_INTEGER; +- atrm_arg_elements[0].integer.value = offset; +- +- atrm_arg_elements[1].type = ACPI_TYPE_INTEGER; +- atrm_arg_elements[1].integer.value = len; +- +- status = acpi_evaluate_object(atrm_handle, NULL, &atrm_arg, &buffer); +- if (ACPI_FAILURE(status)) { +- printk("failed to evaluate ATRM got %s\n", acpi_format_exception(status)); +- return -ENODEV; +- } +- +- obj = (union acpi_object *)buffer.pointer; +- memcpy(bios+offset, obj->buffer.pointer, obj->buffer.length); +- len = obj->buffer.length; +- kfree(buffer.pointer); +- return len; +-} +- +-bool radeon_atrm_supported(struct pci_dev *pdev) +-{ +- /* get the discrete ROM only via ATRM */ +- if (!radeon_atpx_priv.atpx_detected) +- return false; +- +- if (radeon_atpx_priv.dhandle == DEVICE_ACPI_HANDLE(&pdev->dev)) +- return false; +- return true; +-} +- +- +-int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len) +-{ +- return radeon_atrm_call(radeon_atpx_priv.atrm_handle, bios, offset, len); +-} +- + static int radeon_atpx_get_version(acpi_handle handle) + { + acpi_status status; +@@ -198,7 +149,7 @@ static int radeon_atpx_power_state(enum vga_switcheroo_client_id id, + + static bool radeon_atpx_pci_probe_handle(struct pci_dev *pdev) + { +- acpi_handle dhandle, atpx_handle, atrm_handle; ++ acpi_handle dhandle, atpx_handle; + acpi_status status; + + dhandle = DEVICE_ACPI_HANDLE(&pdev->dev); +@@ -209,13 +160,8 @@ static bool radeon_atpx_pci_probe_handle(struct pci_dev *pdev) + if (ACPI_FAILURE(status)) + return false; + +- status = acpi_get_handle(dhandle, "ATRM", &atrm_handle); +- if (ACPI_FAILURE(status)) +- return false; +- + radeon_atpx_priv.dhandle = dhandle; + radeon_atpx_priv.atpx_handle = atpx_handle; +- radeon_atpx_priv.atrm_handle = atrm_handle; + return true; + } + +diff --git a/drivers/gpu/drm/radeon/radeon_bios.c b/drivers/gpu/drm/radeon/radeon_bios.c +index 501f488..d306cc8 100644 +--- a/drivers/gpu/drm/radeon/radeon_bios.c ++++ b/drivers/gpu/drm/radeon/radeon_bios.c +@@ -32,6 +32,7 @@ + + #include + #include ++#include + /* + * BIOS. + */ +@@ -98,16 +99,81 @@ static bool radeon_read_bios(struct radeon_device *rdev) + return true; + } + ++#ifdef CONFIG_ACPI + /* ATRM is used to get the BIOS on the discrete cards in + * dual-gpu systems. + */ ++/* retrieve the ROM in 4k blocks */ ++#define ATRM_BIOS_PAGE 4096 ++/** ++ * radeon_atrm_call - fetch a chunk of the vbios ++ * ++ * @atrm_handle: acpi ATRM handle ++ * @bios: vbios image pointer ++ * @offset: offset of vbios image data to fetch ++ * @len: length of vbios image data to fetch ++ * ++ * Executes ATRM to fetch a chunk of the discrete ++ * vbios image on PX systems (all asics). ++ * Returns the length of the buffer fetched. ++ */ ++static int radeon_atrm_call(acpi_handle atrm_handle, uint8_t *bios, ++ int offset, int len) ++{ ++ acpi_status status; ++ union acpi_object atrm_arg_elements[2], *obj; ++ struct acpi_object_list atrm_arg; ++ struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL}; ++ ++ atrm_arg.count = 2; ++ atrm_arg.pointer = &atrm_arg_elements[0]; ++ ++ atrm_arg_elements[0].type = ACPI_TYPE_INTEGER; ++ atrm_arg_elements[0].integer.value = offset; ++ ++ atrm_arg_elements[1].type = ACPI_TYPE_INTEGER; ++ atrm_arg_elements[1].integer.value = len; ++ ++ status = acpi_evaluate_object(atrm_handle, NULL, &atrm_arg, &buffer); ++ if (ACPI_FAILURE(status)) { ++ printk("failed to evaluate ATRM got %s\n", acpi_format_exception(status)); ++ return -ENODEV; ++ } ++ ++ obj = (union acpi_object *)buffer.pointer; ++ memcpy(bios+offset, obj->buffer.pointer, obj->buffer.length); ++ len = obj->buffer.length; ++ kfree(buffer.pointer); ++ return len; ++} ++ + static bool radeon_atrm_get_bios(struct radeon_device *rdev) + { + int ret; + int size = 256 * 1024; + int i; ++ struct pci_dev *pdev = NULL; ++ acpi_handle dhandle, atrm_handle; ++ acpi_status status; ++ bool found = false; ++ ++ /* ATRM is for the discrete card only */ ++ if (rdev->flags & RADEON_IS_IGP) ++ return false; ++ ++ while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) { ++ dhandle = DEVICE_ACPI_HANDLE(&pdev->dev); ++ if (!dhandle) ++ continue; ++ ++ status = acpi_get_handle(dhandle, "ATRM", &atrm_handle); ++ if (!ACPI_FAILURE(status)) { ++ found = true; ++ break; ++ } ++ } + +- if (!radeon_atrm_supported(rdev->pdev)) ++ if (!found) + return false; + + rdev->bios = kmalloc(size, GFP_KERNEL); +@@ -117,9 +183,10 @@ static bool radeon_atrm_get_bios(struct radeon_device *rdev) + } + + for (i = 0; i < size / ATRM_BIOS_PAGE; i++) { +- ret = radeon_atrm_get_bios_chunk(rdev->bios, +- (i * ATRM_BIOS_PAGE), +- ATRM_BIOS_PAGE); ++ ret = radeon_atrm_call(atrm_handle, ++ rdev->bios, ++ (i * ATRM_BIOS_PAGE), ++ ATRM_BIOS_PAGE); + if (ret < ATRM_BIOS_PAGE) + break; + } +@@ -130,6 +197,12 @@ static bool radeon_atrm_get_bios(struct radeon_device *rdev) + } + return true; + } ++#else ++static inline bool radeon_atrm_get_bios(struct radeon_device *rdev) ++{ ++ return false; ++} ++#endif + + static bool ni_read_disabled_bios(struct radeon_device *rdev) + { +@@ -476,6 +549,61 @@ static bool radeon_read_disabled_bios(struct radeon_device *rdev) + return legacy_read_disabled_bios(rdev); + } + ++#ifdef CONFIG_ACPI ++static bool radeon_acpi_vfct_bios(struct radeon_device *rdev) ++{ ++ bool ret = false; ++ struct acpi_table_header *hdr; ++ acpi_size tbl_size; ++ UEFI_ACPI_VFCT *vfct; ++ GOP_VBIOS_CONTENT *vbios; ++ VFCT_IMAGE_HEADER *vhdr; ++ ++ if (!ACPI_SUCCESS(acpi_get_table_with_size("VFCT", 1, &hdr, &tbl_size))) ++ return false; ++ if (tbl_size < sizeof(UEFI_ACPI_VFCT)) { ++ DRM_ERROR("ACPI VFCT table present but broken (too short #1)\n"); ++ goto out_unmap; ++ } ++ ++ vfct = (UEFI_ACPI_VFCT *)hdr; ++ if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) > tbl_size) { ++ DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n"); ++ goto out_unmap; ++ } ++ ++ vbios = (GOP_VBIOS_CONTENT *)((char *)hdr + vfct->VBIOSImageOffset); ++ vhdr = &vbios->VbiosHeader; ++ DRM_INFO("ACPI VFCT contains a BIOS for %02x:%02x.%d %04x:%04x, size %d\n", ++ vhdr->PCIBus, vhdr->PCIDevice, vhdr->PCIFunction, ++ vhdr->VendorID, vhdr->DeviceID, vhdr->ImageLength); ++ ++ if (vhdr->PCIBus != rdev->pdev->bus->number || ++ vhdr->PCIDevice != PCI_SLOT(rdev->pdev->devfn) || ++ vhdr->PCIFunction != PCI_FUNC(rdev->pdev->devfn) || ++ vhdr->VendorID != rdev->pdev->vendor || ++ vhdr->DeviceID != rdev->pdev->device) { ++ DRM_INFO("ACPI VFCT table is not for this card\n"); ++ goto out_unmap; ++ }; ++ ++ if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) + vhdr->ImageLength > tbl_size) { ++ DRM_ERROR("ACPI VFCT image truncated\n"); ++ goto out_unmap; ++ } ++ ++ rdev->bios = kmemdup(&vbios->VbiosContent, vhdr->ImageLength, GFP_KERNEL); ++ ret = !!rdev->bios; ++ ++out_unmap: ++ return ret; ++} ++#else ++static inline bool radeon_acpi_vfct_bios(struct radeon_device *rdev) ++{ ++ return false; ++} ++#endif + + bool radeon_get_bios(struct radeon_device *rdev) + { +@@ -484,6 +612,8 @@ bool radeon_get_bios(struct radeon_device *rdev) + + r = radeon_atrm_get_bios(rdev); + if (r == false) ++ r = radeon_acpi_vfct_bios(rdev); ++ if (r == false) + r = igp_read_bios_from_vram(rdev); + if (r == false) + r = radeon_read_bios(rdev); +diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c +index 2914c57..895e628 100644 +--- a/drivers/gpu/drm/radeon/radeon_connectors.c ++++ b/drivers/gpu/drm/radeon/radeon_connectors.c +@@ -64,14 +64,33 @@ void radeon_connector_hotplug(struct drm_connector *connector) + + /* just deal with DP (not eDP) here. */ + if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) { +- int saved_dpms = connector->dpms; +- +- /* 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; ++ struct radeon_connector_atom_dig *dig_connector = ++ radeon_connector->con_priv; ++ ++ /* 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 --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c +index 142f894..c84eb1a 100644 +--- a/drivers/gpu/drm/radeon/radeon_cs.c ++++ b/drivers/gpu/drm/radeon/radeon_cs.c +@@ -294,6 +294,28 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) + return 0; + } + ++static void radeon_bo_vm_fence_va(struct radeon_cs_parser *parser, ++ struct radeon_fence *fence) ++{ ++ struct radeon_fpriv *fpriv = parser->filp->driver_priv; ++ struct radeon_vm *vm = &fpriv->vm; ++ struct radeon_bo_list *lobj; ++ ++ if (parser->chunk_ib_idx == -1) ++ return; ++ if ((parser->cs_flags & RADEON_CS_USE_VM) == 0) ++ return; ++ ++ list_for_each_entry(lobj, &parser->validated, tv.head) { ++ struct radeon_bo_va *bo_va; ++ struct radeon_bo *rbo = lobj->bo; ++ ++ bo_va = radeon_bo_va(rbo, vm); ++ radeon_fence_unref(&bo_va->fence); ++ bo_va->fence = radeon_fence_ref(fence); ++ } ++} ++ + /** + * cs_parser_fini() - clean parser states + * @parser: parser structure holding parsing context. +@@ -306,11 +328,14 @@ static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error) + { + unsigned i; + +- if (!error) ++ if (!error) { ++ /* fence all bo va before ttm_eu_fence_buffer_objects so bo are still reserved */ ++ radeon_bo_vm_fence_va(parser, parser->ib.fence); + ttm_eu_fence_buffer_objects(&parser->validated, + parser->ib.fence); +- else ++ } else { + ttm_eu_backoff_reservation(&parser->validated); ++ } + + if (parser->relocs != NULL) { + for (i = 0; i < parser->nrelocs; i++) { +@@ -377,7 +402,7 @@ static int radeon_cs_ib_chunk(struct radeon_device *rdev, + if (r) { + DRM_ERROR("Failed to schedule IB !\n"); + } +- return 0; ++ return r; + } + + static int radeon_bo_vm_update_pte(struct radeon_cs_parser *parser, +@@ -407,7 +432,6 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev, + + if (parser->chunk_ib_idx == -1) + return 0; +- + if ((parser->cs_flags & RADEON_CS_USE_VM) == 0) + return 0; + +diff --git a/drivers/gpu/drm/radeon/radeon_cursor.c b/drivers/gpu/drm/radeon/radeon_cursor.c +index 42acc64..711e95a 100644 +--- a/drivers/gpu/drm/radeon/radeon_cursor.c ++++ b/drivers/gpu/drm/radeon/radeon_cursor.c +@@ -262,8 +262,14 @@ int radeon_crtc_cursor_move(struct drm_crtc *crtc, + 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 --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c +index 066c98b..8867400 100644 +--- a/drivers/gpu/drm/radeon/radeon_device.c ++++ b/drivers/gpu/drm/radeon/radeon_device.c +@@ -774,7 +774,7 @@ int radeon_device_init(struct radeon_device *rdev, + if (rdev->flags & RADEON_IS_AGP) + rdev->need_dma32 = true; + if ((rdev->flags & RADEON_IS_PCI) && +- (rdev->family < CHIP_RS400)) ++ (rdev->family <= CHIP_RS740)) + rdev->need_dma32 = true; + + dma_bits = rdev->need_dma32 ? 32 : 40; +diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c +index 2c4d53f..ed13538 100644 +--- a/drivers/gpu/drm/radeon/radeon_drv.c ++++ b/drivers/gpu/drm/radeon/radeon_drv.c +@@ -59,9 +59,10 @@ + * 2.15.0 - add max_pipes query + * 2.16.0 - fix evergreen 2D tiled surface calculation + * 2.17.0 - add STRMOUT_BASE_UPDATE for r7xx ++ * 2.18.0 - r600-eg: allow "invalid" DB formats + */ + #define KMS_DRIVER_MAJOR 2 +-#define KMS_DRIVER_MINOR 17 ++#define KMS_DRIVER_MINOR 18 + #define KMS_DRIVER_PATCHLEVEL 0 + int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags); + int radeon_driver_unload_kms(struct drm_device *dev); +diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c +index 11f5f40..71298ce 100644 +--- a/drivers/gpu/drm/radeon/radeon_fence.c ++++ b/drivers/gpu/drm/radeon/radeon_fence.c +@@ -75,7 +75,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence) + + void radeon_fence_process(struct radeon_device *rdev, int ring) + { +- uint64_t seq, last_seq; ++ uint64_t seq, last_seq, last_emitted; + unsigned count_loop = 0; + bool wake = false; + +@@ -102,13 +102,15 @@ void radeon_fence_process(struct radeon_device *rdev, int ring) + */ + last_seq = atomic64_read(&rdev->fence_drv[ring].last_seq); + do { ++ last_emitted = rdev->fence_drv[ring].seq; + seq = radeon_fence_read(rdev, ring); + seq |= last_seq & 0xffffffff00000000LL; + if (seq < last_seq) { +- seq += 0x100000000LL; ++ seq &= 0xffffffff; ++ seq |= last_emitted & 0xffffffff00000000LL; + } + +- if (seq == last_seq) { ++ if (seq <= last_seq || seq > last_emitted) { + break; + } + /* If we loop over we don't want to return without +diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c +index 84b648a..f651f22 100644 +--- a/drivers/gpu/drm/radeon/radeon_gart.c ++++ b/drivers/gpu/drm/radeon/radeon_gart.c +@@ -564,7 +564,7 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev, + return -EINVAL; + } + +- if (bo_va->valid) ++ if (bo_va->valid && mem) + return 0; + + ngpu_pages = radeon_bo_ngpu_pages(bo); +@@ -597,11 +597,27 @@ int radeon_vm_bo_rmv(struct radeon_device *rdev, + struct radeon_bo *bo) + { + struct radeon_bo_va *bo_va; ++ int r; + + bo_va = radeon_bo_va(bo, vm); + if (bo_va == NULL) + return 0; + ++ /* wait for va use to end */ ++ while (bo_va->fence) { ++ r = radeon_fence_wait(bo_va->fence, false); ++ if (r) { ++ DRM_ERROR("error while waiting for fence: %d\n", r); ++ } ++ if (r == -EDEADLK) { ++ r = radeon_gpu_reset(rdev); ++ if (!r) ++ continue; ++ } ++ break; ++ } ++ radeon_fence_unref(&bo_va->fence); ++ + radeon_mutex_lock(&rdev->cs_mutex); + mutex_lock(&vm->mutex); + radeon_vm_bo_update_pte(rdev, vm, bo, NULL); +@@ -661,12 +677,15 @@ void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm) + radeon_vm_unbind_locked(rdev, vm); + radeon_mutex_unlock(&rdev->cs_mutex); + +- /* remove all bo */ ++ /* remove all bo at this point non are busy any more because unbind ++ * waited for the last vm fence to signal ++ */ + r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false); + if (!r) { + bo_va = radeon_bo_va(rdev->ring_tmp_bo.bo, vm); + list_del_init(&bo_va->bo_list); + list_del_init(&bo_va->vm_list); ++ radeon_fence_unref(&bo_va->fence); + radeon_bo_unreserve(rdev->ring_tmp_bo.bo); + kfree(bo_va); + } +@@ -678,6 +697,7 @@ void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm) + r = radeon_bo_reserve(bo_va->bo, false); + if (!r) { + list_del_init(&bo_va->bo_list); ++ radeon_fence_unref(&bo_va->fence); + radeon_bo_unreserve(bo_va->bo); + kfree(bo_va); + } +diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c +index 21ec9f5..12207d9 100644 +--- a/drivers/gpu/drm/radeon/radeon_gem.c ++++ b/drivers/gpu/drm/radeon/radeon_gem.c +@@ -134,25 +134,16 @@ void radeon_gem_object_close(struct drm_gem_object *obj, + struct radeon_device *rdev = rbo->rdev; + struct radeon_fpriv *fpriv = file_priv->driver_priv; + struct radeon_vm *vm = &fpriv->vm; +- struct radeon_bo_va *bo_va, *tmp; + + if (rdev->family < CHIP_CAYMAN) { + return; + } + + if (radeon_bo_reserve(rbo, false)) { ++ dev_err(rdev->dev, "leaking bo va because we fail to reserve bo\n"); + return; + } +- list_for_each_entry_safe(bo_va, tmp, &rbo->va, bo_list) { +- if (bo_va->vm == vm) { +- /* remove from this vm address space */ +- mutex_lock(&vm->mutex); +- list_del(&bo_va->vm_list); +- mutex_unlock(&vm->mutex); +- list_del(&bo_va->bo_list); +- kfree(bo_va); +- } +- } ++ radeon_vm_bo_rmv(rdev, vm, rbo); + radeon_bo_unreserve(rbo); + } + +diff --git a/drivers/gpu/drm/radeon/radeon_irq_kms.c b/drivers/gpu/drm/radeon/radeon_irq_kms.c +index 5df58d1..d13a348 100644 +--- a/drivers/gpu/drm/radeon/radeon_irq_kms.c ++++ b/drivers/gpu/drm/radeon/radeon_irq_kms.c +@@ -149,6 +149,16 @@ static bool radeon_msi_ok(struct radeon_device *rdev) + (rdev->pdev->subsystem_device == 0x01fd)) + return true; + ++ /* Gateway RS690 only seems to work with MSIs. */ ++ if ((rdev->pdev->device == 0x791f) && ++ (rdev->pdev->subsystem_vendor == 0x107b) && ++ (rdev->pdev->subsystem_device == 0x0185)) ++ return true; ++ ++ /* try and enable MSIs by default on all RS690s */ ++ if (rdev->family == CHIP_RS690) ++ return true; ++ + /* RV515 seems to have MSI issues where it loses + * MSI rearms occasionally. This leads to lockups and freezes. + * disable it by default. +diff --git a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c +index 210317c..9760e5a 100644 +--- a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c ++++ b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c +@@ -1025,9 +1025,11 @@ static int radeon_crtc_mode_set(struct drm_crtc *crtc, + + static void radeon_crtc_prepare(struct drm_crtc *crtc) + { ++ struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); + struct drm_device *dev = crtc->dev; + struct drm_crtc *crtci; + ++ radeon_crtc->in_mode_set = true; + /* + * The hardware wedges sometimes if you reconfigure one CRTC + * whilst another is running (see fdo bug #24611). +@@ -1038,6 +1040,7 @@ static void radeon_crtc_prepare(struct drm_crtc *crtc) + + static void radeon_crtc_commit(struct drm_crtc *crtc) + { ++ struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); + struct drm_device *dev = crtc->dev; + struct drm_crtc *crtci; + +@@ -1048,6 +1051,7 @@ static void radeon_crtc_commit(struct drm_crtc *crtc) + if (crtci->enabled) + radeon_crtc_dpms(crtci, DRM_MODE_DPMS_ON); + } ++ radeon_crtc->in_mode_set = false; + } + + static const struct drm_crtc_helper_funcs legacy_helper_funcs = { +diff --git a/drivers/gpu/drm/radeon/radeon_mode.h b/drivers/gpu/drm/radeon/radeon_mode.h +index 5b10ffd..ce32fa9 100644 +--- a/drivers/gpu/drm/radeon/radeon_mode.h ++++ b/drivers/gpu/drm/radeon/radeon_mode.h +@@ -275,6 +275,7 @@ struct radeon_crtc { + u16 lut_r[256], lut_g[256], lut_b[256]; + bool enabled; + bool can_tile; ++ bool in_mode_set; + uint32_t crtc_offset; + struct drm_gem_object *cursor_bo; + uint64_t cursor_addr; +diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c +index 830f1a7..1b2289f 100644 +--- a/drivers/gpu/drm/radeon/radeon_object.c ++++ b/drivers/gpu/drm/radeon/radeon_object.c +@@ -52,11 +52,7 @@ void radeon_bo_clear_va(struct radeon_bo *bo) + + list_for_each_entry_safe(bo_va, tmp, &bo->va, bo_list) { + /* remove from all vm address space */ +- mutex_lock(&bo_va->vm->mutex); +- list_del(&bo_va->vm_list); +- mutex_unlock(&bo_va->vm->mutex); +- list_del(&bo_va->bo_list); +- kfree(bo_va); ++ radeon_vm_bo_rmv(bo->rdev, bo_va->vm, bo); + } + } + +diff --git a/drivers/gpu/drm/radeon/radeon_pm.c b/drivers/gpu/drm/radeon/radeon_pm.c +index 5b37e28..0c4ca48 100644 +--- a/drivers/gpu/drm/radeon/radeon_pm.c ++++ b/drivers/gpu/drm/radeon/radeon_pm.c +@@ -555,7 +555,9 @@ void radeon_pm_suspend(struct radeon_device *rdev) + void radeon_pm_resume(struct radeon_device *rdev) + { + /* set up the default clocks if the MC ucode is loaded */ +- if (ASIC_IS_DCE5(rdev) && rdev->mc_fw) { ++ if ((rdev->family >= CHIP_BARTS) && ++ (rdev->family <= CHIP_CAYMAN) && ++ rdev->mc_fw) { + if (rdev->pm.default_vddc) + radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, + SET_VOLTAGE_TYPE_ASIC_VDDC); +@@ -610,7 +612,9 @@ int radeon_pm_init(struct radeon_device *rdev) + radeon_pm_print_states(rdev); + radeon_pm_init_profile(rdev); + /* set up the default clocks if the MC ucode is loaded */ +- if (ASIC_IS_DCE5(rdev) && rdev->mc_fw) { ++ if ((rdev->family >= CHIP_BARTS) && ++ (rdev->family <= CHIP_CAYMAN) && ++ rdev->mc_fw) { + if (rdev->pm.default_vddc) + radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, + SET_VOLTAGE_TYPE_ASIC_VDDC); +diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c +index 983658c..7843b36 100644 +--- a/drivers/gpu/drm/radeon/radeon_ring.c ++++ b/drivers/gpu/drm/radeon/radeon_ring.c +@@ -394,6 +394,7 @@ int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsig + if (radeon_debugfs_ring_init(rdev, ring)) { + DRM_ERROR("Failed to register debugfs file for rings !\n"); + } ++ radeon_ring_lockup_update(ring); + return 0; + } + +diff --git a/drivers/gpu/drm/radeon/rv515.c b/drivers/gpu/drm/radeon/rv515.c +index 7f08ced..5e70fcb 100644 +--- a/drivers/gpu/drm/radeon/rv515.c ++++ b/drivers/gpu/drm/radeon/rv515.c +@@ -281,12 +281,8 @@ int rv515_debugfs_ga_info_init(struct radeon_device *rdev) + + void rv515_mc_stop(struct radeon_device *rdev, struct rv515_mc_save *save) + { +- save->d1vga_control = RREG32(R_000330_D1VGA_CONTROL); +- save->d2vga_control = RREG32(R_000338_D2VGA_CONTROL); + save->vga_render_control = RREG32(R_000300_VGA_RENDER_CONTROL); + save->vga_hdp_control = RREG32(R_000328_VGA_HDP_CONTROL); +- save->d1crtc_control = RREG32(R_006080_D1CRTC_CONTROL); +- save->d2crtc_control = RREG32(R_006880_D2CRTC_CONTROL); + + /* Stop all video */ + WREG32(R_0068E8_D2CRTC_UPDATE_LOCK, 0); +@@ -311,15 +307,6 @@ void rv515_mc_resume(struct radeon_device *rdev, struct rv515_mc_save *save) + /* Unlock host access */ + WREG32(R_000328_VGA_HDP_CONTROL, save->vga_hdp_control); + mdelay(1); +- /* Restore video state */ +- WREG32(R_000330_D1VGA_CONTROL, save->d1vga_control); +- WREG32(R_000338_D2VGA_CONTROL, save->d2vga_control); +- WREG32(R_0060E8_D1CRTC_UPDATE_LOCK, 1); +- WREG32(R_0068E8_D2CRTC_UPDATE_LOCK, 1); +- WREG32(R_006080_D1CRTC_CONTROL, save->d1crtc_control); +- WREG32(R_006880_D2CRTC_CONTROL, save->d2crtc_control); +- WREG32(R_0060E8_D1CRTC_UPDATE_LOCK, 0); +- WREG32(R_0068E8_D2CRTC_UPDATE_LOCK, 0); + WREG32(R_000300_VGA_RENDER_CONTROL, save->vga_render_control); + } + +diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c +index 0b02792..bb9ea23 100644 +--- a/drivers/gpu/drm/radeon/si.c ++++ b/drivers/gpu/drm/radeon/si.c +@@ -1640,10 +1640,18 @@ static void si_gpu_init(struct radeon_device *rdev) + rdev->config.si.tile_config |= (3 << 0); + break; + } +- if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) +- rdev->config.si.tile_config |= 1 << 4; +- else ++ switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) { ++ case 0: /* four banks */ + rdev->config.si.tile_config |= 0 << 4; ++ break; ++ case 1: /* eight banks */ ++ rdev->config.si.tile_config |= 1 << 4; ++ break; ++ case 2: /* sixteen banks */ ++ default: ++ rdev->config.si.tile_config |= 2 << 4; ++ break; ++ } + rdev->config.si.tile_config |= + ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8; + rdev->config.si.tile_config |= +diff --git a/drivers/gpu/drm/savage/savage_bci.c b/drivers/gpu/drm/savage/savage_bci.c +index 6eb507a..7d3f0f0 100644 +--- a/drivers/gpu/drm/savage/savage_bci.c ++++ b/drivers/gpu/drm/savage/savage_bci.c +@@ -547,6 +547,8 @@ int savage_driver_load(struct drm_device *dev, unsigned long chipset) + + dev_priv->chipset = (enum savage_family)chipset; + ++ pci_set_master(dev->pdev); ++ + return 0; + } + +diff --git a/drivers/gpu/drm/udl/udl_connector.c b/drivers/gpu/drm/udl/udl_connector.c +index ba055e9..8d9dc44 100644 +--- a/drivers/gpu/drm/udl/udl_connector.c ++++ b/drivers/gpu/drm/udl/udl_connector.c +@@ -69,6 +69,13 @@ static int udl_get_modes(struct drm_connector *connector) + static int udl_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) + { ++ struct udl_device *udl = connector->dev->dev_private; ++ if (!udl->sku_pixel_limit) ++ return 0; ++ ++ if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit) ++ return MODE_VIRTUAL_Y; ++ + return 0; + } + +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +index ee24d21..3a4b15a 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +@@ -182,6 +182,7 @@ static struct pci_device_id vmw_pci_id_list[] = { + {0x15ad, 0x0405, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VMWGFX_CHIP_SVGAII}, + {0, 0, 0} + }; ++MODULE_DEVICE_TABLE(pci, vmw_pci_id_list); + + static int enable_fbdev; + +@@ -1158,6 +1159,11 @@ static struct drm_driver driver = { + .open = vmw_driver_open, + .preclose = vmw_preclose, + .postclose = vmw_postclose, ++ ++ .dumb_create = vmw_dumb_create, ++ .dumb_map_offset = vmw_dumb_map_offset, ++ .dumb_destroy = vmw_dumb_destroy, ++ + .fops = &vmwgfx_driver_fops, + .name = VMWGFX_DRIVER_NAME, + .desc = VMWGFX_DRIVER_DESC, +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +index d0f2c07..29c984f 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +@@ -645,6 +645,16 @@ int vmw_kms_readback(struct vmw_private *dev_priv, + int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); + ++int vmw_dumb_create(struct drm_file *file_priv, ++ struct drm_device *dev, ++ struct drm_mode_create_dumb *args); ++ ++int vmw_dumb_map_offset(struct drm_file *file_priv, ++ struct drm_device *dev, uint32_t handle, ++ uint64_t *offset); ++int vmw_dumb_destroy(struct drm_file *file_priv, ++ struct drm_device *dev, ++ uint32_t handle); + /** + * Overlay control - vmwgfx_overlay.c + */ +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +index f2fb8f1..7e07433 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +@@ -1018,7 +1018,7 @@ int vmw_event_fence_action_create(struct drm_file *file_priv, + } + + +- event = kzalloc(sizeof(event->event), GFP_KERNEL); ++ event = kzalloc(sizeof(*event), GFP_KERNEL); + if (unlikely(event == NULL)) { + DRM_ERROR("Failed to allocate an event.\n"); + ret = -ENOMEM; +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +index 6b0078f..c50724b 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +@@ -1688,15 +1688,19 @@ int vmw_du_page_flip(struct drm_crtc *crtc, + struct vmw_private *dev_priv = vmw_priv(crtc->dev); + struct drm_framebuffer *old_fb = crtc->fb; + struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(fb); +- struct drm_file *file_priv = event->base.file_priv; ++ struct drm_file *file_priv ; + struct vmw_fence_obj *fence = NULL; + struct drm_clip_rect clips; + int ret; + ++ if (event == NULL) ++ return -EINVAL; ++ + /* require ScreenObject support for page flipping */ + if (!dev_priv->sou_priv) + return -ENOSYS; + ++ file_priv = event->base.file_priv; + if (!vmw_kms_screen_object_flippable(dev_priv, crtc)) + return -EINVAL; + +diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +index 22bf9a2..2c6ffe0 100644 +--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c ++++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +@@ -1917,3 +1917,76 @@ err_ref: + vmw_resource_unreference(&res); + return ret; + } ++ ++ ++int vmw_dumb_create(struct drm_file *file_priv, ++ struct drm_device *dev, ++ struct drm_mode_create_dumb *args) ++{ ++ struct vmw_private *dev_priv = vmw_priv(dev); ++ struct vmw_master *vmaster = vmw_master(file_priv->master); ++ struct vmw_user_dma_buffer *vmw_user_bo; ++ struct ttm_buffer_object *tmp; ++ int ret; ++ ++ args->pitch = args->width * ((args->bpp + 7) / 8); ++ args->size = args->pitch * args->height; ++ ++ vmw_user_bo = kzalloc(sizeof(*vmw_user_bo), GFP_KERNEL); ++ if (vmw_user_bo == NULL) ++ return -ENOMEM; ++ ++ ret = ttm_read_lock(&vmaster->lock, true); ++ if (ret != 0) { ++ kfree(vmw_user_bo); ++ return ret; ++ } ++ ++ ret = vmw_dmabuf_init(dev_priv, &vmw_user_bo->dma, args->size, ++ &vmw_vram_sys_placement, true, ++ &vmw_user_dmabuf_destroy); ++ if (ret != 0) ++ goto out_no_dmabuf; ++ ++ tmp = ttm_bo_reference(&vmw_user_bo->dma.base); ++ ret = ttm_base_object_init(vmw_fpriv(file_priv)->tfile, ++ &vmw_user_bo->base, ++ false, ++ ttm_buffer_type, ++ &vmw_user_dmabuf_release, NULL); ++ if (unlikely(ret != 0)) ++ goto out_no_base_object; ++ ++ args->handle = vmw_user_bo->base.hash.key; ++ ++out_no_base_object: ++ ttm_bo_unref(&tmp); ++out_no_dmabuf: ++ ttm_read_unlock(&vmaster->lock); ++ return ret; ++} ++ ++int vmw_dumb_map_offset(struct drm_file *file_priv, ++ struct drm_device *dev, uint32_t handle, ++ uint64_t *offset) ++{ ++ struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; ++ struct vmw_dma_buffer *out_buf; ++ int ret; ++ ++ ret = vmw_user_dmabuf_lookup(tfile, handle, &out_buf); ++ if (ret != 0) ++ return -EINVAL; ++ ++ *offset = out_buf->base.addr_space_offset; ++ vmw_dmabuf_unreference(&out_buf); ++ return 0; ++} ++ ++int vmw_dumb_destroy(struct drm_file *file_priv, ++ struct drm_device *dev, ++ uint32_t handle) ++{ ++ return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile, ++ handle, TTM_REF_USAGE); ++} +diff --git a/drivers/hid/hid-chicony.c b/drivers/hid/hid-chicony.c +index b99af34..a2abb8e 100644 +--- a/drivers/hid/hid-chicony.c ++++ b/drivers/hid/hid-chicony.c +@@ -60,6 +60,7 @@ static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi, + static const struct hid_device_id ch_devices[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, ++ { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) }, + { } + }; + MODULE_DEVICE_TABLE(hid, ch_devices); +diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c +index 4c87276..0e4d41e 100644 +--- a/drivers/hid/hid-core.c ++++ b/drivers/hid/hid-core.c +@@ -757,6 +757,7 @@ int hid_open_report(struct hid_device *device) + struct hid_item item; + unsigned int size; + __u8 *start; ++ __u8 *buf; + __u8 *end; + int ret; + static int (*dispatch_type[])(struct hid_parser *parser, +@@ -775,12 +776,21 @@ int hid_open_report(struct hid_device *device) + return -ENODEV; + size = device->dev_rsize; + ++ buf = kmemdup(start, size, GFP_KERNEL); ++ if (buf == NULL) ++ return -ENOMEM; ++ + if (device->driver->report_fixup) +- start = device->driver->report_fixup(device, start, &size); ++ start = device->driver->report_fixup(device, buf, &size); ++ else ++ start = buf; + +- device->rdesc = kmemdup(start, size, GFP_KERNEL); +- if (device->rdesc == NULL) ++ start = kmemdup(start, size, GFP_KERNEL); ++ kfree(buf); ++ if (start == NULL) + return -ENOMEM; ++ ++ device->rdesc = start; + device->rsize = size; + + parser = vzalloc(sizeof(struct hid_parser)); +@@ -1521,10 +1531,12 @@ static const struct hid_device_id hid_have_special_driver[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, ++ { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, ++ { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) }, + { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) }, +diff --git a/drivers/hid/hid-cypress.c b/drivers/hid/hid-cypress.c +index 2f0be4c..9e43aac 100644 +--- a/drivers/hid/hid-cypress.c ++++ b/drivers/hid/hid-cypress.c +@@ -129,6 +129,8 @@ static const struct hid_device_id cp_devices[] = { + .driver_data = CP_RDESC_SWAPPED_MIN_MAX }, + { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3), + .driver_data = CP_RDESC_SWAPPED_MIN_MAX }, ++ { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4), ++ .driver_data = CP_RDESC_SWAPPED_MIN_MAX }, + { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE), + .driver_data = CP_2WHEEL_MOUSE_HACK }, + { } +diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h +index 3203923..9d9bb9a 100644 +--- a/drivers/hid/hid-ids.h ++++ b/drivers/hid/hid-ids.h +@@ -208,6 +208,7 @@ + #define USB_DEVICE_ID_CHICONY_MULTI_TOUCH 0xb19d + #define USB_DEVICE_ID_CHICONY_WIRELESS 0x0618 + #define USB_DEVICE_ID_CHICONY_WIRELESS2 0x1123 ++#define USB_DEVICE_ID_CHICONY_AK1D 0x1125 + + #define USB_VENDOR_ID_CHUNGHWAT 0x2247 + #define USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH 0x0001 +@@ -237,6 +238,7 @@ + #define USB_DEVICE_ID_CYPRESS_BARCODE_1 0xde61 + #define USB_DEVICE_ID_CYPRESS_BARCODE_2 0xde64 + #define USB_DEVICE_ID_CYPRESS_BARCODE_3 0xbca1 ++#define USB_DEVICE_ID_CYPRESS_BARCODE_4 0xed81 + #define USB_DEVICE_ID_CYPRESS_TRUETOUCH 0xc001 + + #define USB_VENDOR_ID_DEALEXTREAME 0x10c5 +@@ -573,6 +575,9 @@ + #define USB_VENDOR_ID_NINTENDO 0x057e + #define USB_DEVICE_ID_NINTENDO_WIIMOTE 0x0306 + ++#define USB_VENDOR_ID_NOVATEK 0x0603 ++#define USB_DEVICE_ID_NOVATEK_PCT 0x0600 ++ + #define USB_VENDOR_ID_NTRIG 0x1b96 + #define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN 0x0001 + #define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1 0x0003 +diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c +index 0f9c146..9500f2f 100644 +--- a/drivers/hid/hid-logitech-dj.c ++++ b/drivers/hid/hid-logitech-dj.c +@@ -193,6 +193,7 @@ static struct hid_ll_driver logi_dj_ll_driver; + static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf, + size_t count, + unsigned char report_type); ++static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev); + + static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev, + struct dj_report *dj_report) +@@ -233,6 +234,7 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev, + if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] & + SPFUNCTION_DEVICE_LIST_EMPTY) { + dbg_hid("%s: device list is empty\n", __func__); ++ djrcv_dev->querying_devices = false; + return; + } + +@@ -243,6 +245,12 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev, + return; + } + ++ if (djrcv_dev->paired_dj_devices[dj_report->device_index]) { ++ /* The device is already known. No need to reallocate it. */ ++ dbg_hid("%s: device is already known\n", __func__); ++ return; ++ } ++ + dj_hiddev = hid_allocate_device(); + if (IS_ERR(dj_hiddev)) { + dev_err(&djrcv_hdev->dev, "%s: hid_allocate_device failed\n", +@@ -306,6 +314,7 @@ static void delayedwork_callback(struct work_struct *work) + struct dj_report dj_report; + unsigned long flags; + int count; ++ int retval; + + dbg_hid("%s\n", __func__); + +@@ -338,6 +347,25 @@ static void delayedwork_callback(struct work_struct *work) + logi_dj_recv_destroy_djhid_device(djrcv_dev, &dj_report); + break; + default: ++ /* A normal report (i. e. not belonging to a pair/unpair notification) ++ * arriving here, means that the report arrived but we did not have a ++ * paired dj_device associated to the report's device_index, this ++ * means that the original "device paired" notification corresponding ++ * to this dj_device never arrived to this driver. The reason is that ++ * hid-core discards all packets coming from a device while probe() is ++ * executing. */ ++ if (!djrcv_dev->paired_dj_devices[dj_report.device_index]) { ++ /* ok, we don't know the device, just re-ask the ++ * receiver for the list of connected devices. */ ++ retval = logi_dj_recv_query_paired_devices(djrcv_dev); ++ if (!retval) { ++ /* everything went fine, so just leave */ ++ break; ++ } ++ dev_err(&djrcv_dev->hdev->dev, ++ "%s:logi_dj_recv_query_paired_devices " ++ "error:%d\n", __func__, retval); ++ } + dbg_hid("%s: unexpected report type\n", __func__); + } + } +@@ -368,6 +396,12 @@ static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, + if (!djdev) { + dbg_hid("djrcv_dev->paired_dj_devices[dj_report->device_index]" + " is NULL, index %d\n", dj_report->device_index); ++ kfifo_in(&djrcv_dev->notif_fifo, dj_report, sizeof(struct dj_report)); ++ ++ if (schedule_work(&djrcv_dev->work) == 0) { ++ dbg_hid("%s: did not schedule the work item, was already " ++ "queued\n", __func__); ++ } + return; + } + +@@ -398,6 +432,12 @@ static void logi_dj_recv_forward_report(struct dj_receiver_dev *djrcv_dev, + if (dj_device == NULL) { + dbg_hid("djrcv_dev->paired_dj_devices[dj_report->device_index]" + " is NULL, index %d\n", dj_report->device_index); ++ kfifo_in(&djrcv_dev->notif_fifo, dj_report, sizeof(struct dj_report)); ++ ++ if (schedule_work(&djrcv_dev->work) == 0) { ++ dbg_hid("%s: did not schedule the work item, was already " ++ "queued\n", __func__); ++ } + return; + } + +@@ -439,7 +479,11 @@ static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev) + struct dj_report *dj_report; + int retval; + +- dj_report = kzalloc(sizeof(dj_report), GFP_KERNEL); ++ /* no need to protect djrcv_dev->querying_devices */ ++ if (djrcv_dev->querying_devices) ++ return 0; ++ ++ dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL); + if (!dj_report) + return -ENOMEM; + dj_report->report_id = REPORT_ID_DJ_SHORT; +@@ -450,13 +494,14 @@ static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev) + return retval; + } + ++ + static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev, + unsigned timeout) + { + struct dj_report *dj_report; + int retval; + +- dj_report = kzalloc(sizeof(dj_report), GFP_KERNEL); ++ dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL); + if (!dj_report) + return -ENOMEM; + dj_report->report_id = REPORT_ID_DJ_SHORT; +diff --git a/drivers/hid/hid-logitech-dj.h b/drivers/hid/hid-logitech-dj.h +index fd28a5e..4a40003 100644 +--- a/drivers/hid/hid-logitech-dj.h ++++ b/drivers/hid/hid-logitech-dj.h +@@ -101,6 +101,7 @@ struct dj_receiver_dev { + struct work_struct work; + struct kfifo notif_fifo; + spinlock_t lock; ++ bool querying_devices; + }; + + struct dj_device { +diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c +index 7647924..348550a 100644 +--- a/drivers/hid/hid-multitouch.c ++++ b/drivers/hid/hid-multitouch.c +@@ -83,6 +83,7 @@ struct mt_device { + unsigned last_field_index; /* last field index of the report */ + unsigned last_slot_field; /* the last field of a slot */ + __s8 inputmode; /* InputMode HID feature, -1 if non-existent */ ++ __s8 inputmode_index; /* InputMode HID feature index in the report */ + __s8 maxcontact_report_id; /* Maximum Contact Number HID feature, + -1 if non-existent */ + __u8 num_received; /* how many contacts we received */ +@@ -260,10 +261,20 @@ static void mt_feature_mapping(struct hid_device *hdev, + struct hid_field *field, struct hid_usage *usage) + { + struct mt_device *td = hid_get_drvdata(hdev); ++ int i; + + switch (usage->hid) { + case HID_DG_INPUTMODE: + td->inputmode = field->report->id; ++ td->inputmode_index = 0; /* has to be updated below */ ++ ++ for (i=0; i < field->maxusage; i++) { ++ if (field->usage[i].hid == usage->hid) { ++ td->inputmode_index = i; ++ break; ++ } ++ } ++ + break; + case HID_DG_CONTACTMAX: + td->maxcontact_report_id = field->report->id; +@@ -618,7 +629,7 @@ static void mt_set_input_mode(struct hid_device *hdev) + re = &(hdev->report_enum[HID_FEATURE_REPORT]); + r = re->report_id_hash[td->inputmode]; + if (r) { +- r->field[0]->value[0] = 0x02; ++ r->field[0]->value[td->inputmode_index] = 0x02; + usbhid_submit_report(hdev, r, USB_DIR_OUT); + } + } +@@ -951,6 +962,11 @@ static const struct hid_device_id mt_devices[] = { + MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC, + USB_DEVICE_ID_PANABOARD_UBT880) }, + ++ /* Novatek Panel */ ++ { .driver_data = MT_CLS_DEFAULT, ++ HID_USB_DEVICE(USB_VENDOR_ID_NOVATEK, ++ USB_DEVICE_ID_NOVATEK_PCT) }, ++ + /* PenMount panels */ + { .driver_data = MT_CLS_CONFIDENCE, + MT_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, +diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c +index 482f936..a4f9681 100644 +--- a/drivers/hid/usbhid/hid-core.c ++++ b/drivers/hid/usbhid/hid-core.c +@@ -1423,20 +1423,20 @@ static int hid_post_reset(struct usb_interface *intf) + * configuration descriptors passed, we already know that + * the size of the HID report descriptor has not changed. + */ +- rdesc = kmalloc(hid->rsize, GFP_KERNEL); ++ rdesc = kmalloc(hid->dev_rsize, GFP_KERNEL); + if (!rdesc) { + dbg_hid("couldn't allocate rdesc memory (post_reset)\n"); + return 1; + } + status = hid_get_class_descriptor(dev, + interface->desc.bInterfaceNumber, +- HID_DT_REPORT, rdesc, hid->rsize); ++ HID_DT_REPORT, rdesc, hid->dev_rsize); + if (status < 0) { + dbg_hid("reading report descriptor failed (post_reset)\n"); + kfree(rdesc); + return 1; + } +- status = memcmp(rdesc, hid->rdesc, hid->rsize); ++ status = memcmp(rdesc, hid->dev_rdesc, hid->dev_rsize); + kfree(rdesc); + if (status != 0) { + dbg_hid("report descriptor changed\n"); +diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c +index 903eef3..991e85c 100644 +--- a/drivers/hid/usbhid/hid-quirks.c ++++ b/drivers/hid/usbhid/hid-quirks.c +@@ -70,6 +70,7 @@ static const struct hid_blacklist { + { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_AXIS_295, HID_QUIRK_NOGET }, + { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET }, + { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, ++ { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET }, + { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS }, + { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS }, + { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2, HID_QUIRK_NO_INIT_REPORTS }, +diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c +index cfec802..f915eb1 100644 +--- a/drivers/hwmon/ad7314.c ++++ b/drivers/hwmon/ad7314.c +@@ -87,10 +87,18 @@ static ssize_t ad7314_show_temperature(struct device *dev, + } + } + ++static ssize_t ad7314_show_name(struct device *dev, ++ struct device_attribute *devattr, char *buf) ++{ ++ return sprintf(buf, "%s\n", to_spi_device(dev)->modalias); ++} ++ ++static DEVICE_ATTR(name, S_IRUGO, ad7314_show_name, NULL); + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, + ad7314_show_temperature, NULL, 0); + + static struct attribute *ad7314_attributes[] = { ++ &dev_attr_name.attr, + &sensor_dev_attr_temp1_input.dev_attr.attr, + NULL, + }; +diff --git a/drivers/hwmon/ads7871.c b/drivers/hwmon/ads7871.c +index e65c6e4..7bf4ce3 100644 +--- a/drivers/hwmon/ads7871.c ++++ b/drivers/hwmon/ads7871.c +@@ -139,6 +139,12 @@ static ssize_t show_voltage(struct device *dev, + } + } + ++static ssize_t ads7871_show_name(struct device *dev, ++ struct device_attribute *devattr, char *buf) ++{ ++ return sprintf(buf, "%s\n", to_spi_device(dev)->modalias); ++} ++ + static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_voltage, NULL, 0); + static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 1); + static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 2); +@@ -148,6 +154,8 @@ static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 5); + static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 6); + static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 7); + ++static DEVICE_ATTR(name, S_IRUGO, ads7871_show_name, NULL); ++ + static struct attribute *ads7871_attributes[] = { + &sensor_dev_attr_in0_input.dev_attr.attr, + &sensor_dev_attr_in1_input.dev_attr.attr, +@@ -157,6 +165,7 @@ static struct attribute *ads7871_attributes[] = { + &sensor_dev_attr_in5_input.dev_attr.attr, + &sensor_dev_attr_in6_input.dev_attr.attr, + &sensor_dev_attr_in7_input.dev_attr.attr, ++ &dev_attr_name.attr, + NULL + }; + +diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c +index 351d1f4..4ee5789 100644 +--- a/drivers/hwmon/asus_atk0110.c ++++ b/drivers/hwmon/asus_atk0110.c +@@ -34,6 +34,12 @@ static const struct dmi_system_id __initconst atk_force_new_if[] = { + .matches = { + DMI_MATCH(DMI_BOARD_NAME, "SABERTOOTH X58") + } ++ }, { ++ /* Old interface reads the same sensor for fan0 and fan1 */ ++ .ident = "Asus M5A78L", ++ .matches = { ++ DMI_MATCH(DMI_BOARD_NAME, "M5A78L") ++ } + }, + { } + }; +diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c +index 6b13f1a..49dadf4 100644 +--- a/drivers/hwmon/fam15h_power.c ++++ b/drivers/hwmon/fam15h_power.c +@@ -128,12 +128,12 @@ static bool __devinit fam15h_power_is_internal_node0(struct pci_dev *f4) + * counter saturations resulting in bogus power readings. + * We correct this value ourselves to cope with older BIOSes. + */ +-static DEFINE_PCI_DEVICE_TABLE(affected_device) = { ++static const struct pci_device_id affected_device[] = { + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) }, + { 0 } + }; + +-static void __devinit tweak_runavg_range(struct pci_dev *pdev) ++static void tweak_runavg_range(struct pci_dev *pdev) + { + u32 val; + +@@ -157,6 +157,16 @@ static void __devinit tweak_runavg_range(struct pci_dev *pdev) + REG_TDP_RUNNING_AVERAGE, val); + } + ++#ifdef CONFIG_PM ++static int fam15h_power_resume(struct pci_dev *pdev) ++{ ++ tweak_runavg_range(pdev); ++ return 0; ++} ++#else ++#define fam15h_power_resume NULL ++#endif ++ + static void __devinit fam15h_power_init_data(struct pci_dev *f4, + struct fam15h_power_data *data) + { +@@ -255,6 +265,7 @@ static struct pci_driver fam15h_power_driver = { + .id_table = fam15h_power_id_table, + .probe = fam15h_power_probe, + .remove = __devexit_p(fam15h_power_remove), ++ .resume = fam15h_power_resume, + }; + + module_pci_driver(fam15h_power_driver); +diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c +index 7f3f4a3..6021482 100644 +--- a/drivers/hwmon/ina2xx.c ++++ b/drivers/hwmon/ina2xx.c +@@ -69,22 +69,6 @@ struct ina2xx_data { + u16 regs[INA2XX_MAX_REGISTERS]; + }; + +-int ina2xx_read_word(struct i2c_client *client, int reg) +-{ +- int val = i2c_smbus_read_word_data(client, reg); +- if (unlikely(val < 0)) { +- dev_dbg(&client->dev, +- "Failed to read register: %d\n", reg); +- return val; +- } +- return be16_to_cpu(val); +-} +- +-void ina2xx_write_word(struct i2c_client *client, int reg, int data) +-{ +- i2c_smbus_write_word_data(client, reg, cpu_to_be16(data)); +-} +- + static struct ina2xx_data *ina2xx_update_device(struct device *dev) + { + struct i2c_client *client = to_i2c_client(dev); +@@ -102,7 +86,7 @@ static struct ina2xx_data *ina2xx_update_device(struct device *dev) + + /* Read all registers */ + for (i = 0; i < data->registers; i++) { +- int rv = ina2xx_read_word(client, i); ++ int rv = i2c_smbus_read_word_swapped(client, i); + if (rv < 0) { + ret = ERR_PTR(rv); + goto abort; +@@ -279,22 +263,26 @@ static int ina2xx_probe(struct i2c_client *client, + switch (data->kind) { + case ina219: + /* device configuration */ +- ina2xx_write_word(client, INA2XX_CONFIG, INA219_CONFIG_DEFAULT); ++ i2c_smbus_write_word_swapped(client, INA2XX_CONFIG, ++ INA219_CONFIG_DEFAULT); + + /* set current LSB to 1mA, shunt is in uOhms */ + /* (equation 13 in datasheet) */ +- ina2xx_write_word(client, INA2XX_CALIBRATION, 40960000 / shunt); ++ i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION, ++ 40960000 / shunt); + dev_info(&client->dev, + "power monitor INA219 (Rshunt = %li uOhm)\n", shunt); + data->registers = INA219_REGISTERS; + break; + case ina226: + /* device configuration */ +- ina2xx_write_word(client, INA2XX_CONFIG, INA226_CONFIG_DEFAULT); ++ i2c_smbus_write_word_swapped(client, INA2XX_CONFIG, ++ INA226_CONFIG_DEFAULT); + + /* set current LSB to 1mA, shunt is in uOhms */ + /* (equation 1 in datasheet)*/ +- ina2xx_write_word(client, INA2XX_CALIBRATION, 5120000 / shunt); ++ i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION, ++ 5120000 / shunt); + dev_info(&client->dev, + "power monitor INA226 (Rshunt = %li uOhm)\n", shunt); + data->registers = INA226_REGISTERS; +diff --git a/drivers/hwmon/twl4030-madc-hwmon.c b/drivers/hwmon/twl4030-madc-hwmon.c +index 0018c7d..1a174f0 100644 +--- a/drivers/hwmon/twl4030-madc-hwmon.c ++++ b/drivers/hwmon/twl4030-madc-hwmon.c +@@ -44,12 +44,13 @@ static ssize_t madc_read(struct device *dev, + struct device_attribute *devattr, char *buf) + { + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); +- struct twl4030_madc_request req; ++ struct twl4030_madc_request req = { ++ .channels = 1 << attr->index, ++ .method = TWL4030_MADC_SW2, ++ .type = TWL4030_MADC_WAIT, ++ }; + long val; + +- req.channels = (1 << attr->index); +- req.method = TWL4030_MADC_SW2; +- req.func_cb = NULL; + val = twl4030_madc_conversion(&req); + if (val < 0) + return val; +diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig +index afc0508..19556c4 100644 +--- a/drivers/i2c/busses/Kconfig ++++ b/drivers/i2c/busses/Kconfig +@@ -104,6 +104,7 @@ config I2C_I801 + DH89xxCC (PCH) + Panther Point (PCH) + Lynx Point (PCH) ++ Lynx Point-LP (PCH) + + This driver can also be built as a module. If so, the module + will be called i2c-i801. +@@ -350,9 +351,13 @@ config I2C_DAVINCI + devices such as DaVinci NIC. + For details please see http://www.ti.com/davinci + ++config I2C_DESIGNWARE_CORE ++ tristate ++ + config I2C_DESIGNWARE_PLATFORM + tristate "Synopsys DesignWare Platform" + depends on HAVE_CLK ++ select I2C_DESIGNWARE_CORE + help + If you say yes to this option, support will be included for the + Synopsys DesignWare I2C adapter. Only master mode is supported. +@@ -363,6 +368,7 @@ config I2C_DESIGNWARE_PLATFORM + config I2C_DESIGNWARE_PCI + tristate "Synopsys DesignWare PCI" + depends on PCI ++ select I2C_DESIGNWARE_CORE + help + If you say yes to this option, support will be included for the + Synopsys DesignWare I2C adapter. Only master mode is supported. +diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile +index 512b140..a4bedae 100644 +--- a/drivers/i2c/busses/Makefile ++++ b/drivers/i2c/busses/Makefile +@@ -33,10 +33,11 @@ obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o + obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o + obj-$(CONFIG_I2C_CPM) += i2c-cpm.o + obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o ++obj-$(CONFIG_I2C_DESIGNWARE_CORE) += i2c-designware-core.o + obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o +-i2c-designware-platform-objs := i2c-designware-platdrv.o i2c-designware-core.o ++i2c-designware-platform-objs := i2c-designware-platdrv.o + obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o +-i2c-designware-pci-objs := i2c-designware-pcidrv.o i2c-designware-core.o ++i2c-designware-pci-objs := i2c-designware-pcidrv.o + obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o + obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o + obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o +diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c +index 1e48bec..7b8ebbe 100644 +--- a/drivers/i2c/busses/i2c-designware-core.c ++++ b/drivers/i2c/busses/i2c-designware-core.c +@@ -25,6 +25,7 @@ + * ---------------------------------------------------------------------------- + * + */ ++#include + #include + #include + #include +@@ -316,6 +317,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev) + dw_writel(dev, dev->master_cfg , DW_IC_CON); + return 0; + } ++EXPORT_SYMBOL_GPL(i2c_dw_init); + + /* + * Waiting for bus not busy +@@ -568,12 +570,14 @@ done: + + return ret; + } ++EXPORT_SYMBOL_GPL(i2c_dw_xfer); + + u32 i2c_dw_func(struct i2c_adapter *adap) + { + struct dw_i2c_dev *dev = i2c_get_adapdata(adap); + return dev->functionality; + } ++EXPORT_SYMBOL_GPL(i2c_dw_func); + + static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) + { +@@ -678,17 +682,20 @@ tx_aborted: + + return IRQ_HANDLED; + } ++EXPORT_SYMBOL_GPL(i2c_dw_isr); + + void i2c_dw_enable(struct dw_i2c_dev *dev) + { + /* Enable the adapter */ + dw_writel(dev, 1, DW_IC_ENABLE); + } ++EXPORT_SYMBOL_GPL(i2c_dw_enable); + + u32 i2c_dw_is_enabled(struct dw_i2c_dev *dev) + { + return dw_readl(dev, DW_IC_ENABLE); + } ++EXPORT_SYMBOL_GPL(i2c_dw_is_enabled); + + void i2c_dw_disable(struct dw_i2c_dev *dev) + { +@@ -699,18 +706,22 @@ void i2c_dw_disable(struct dw_i2c_dev *dev) + dw_writel(dev, 0, DW_IC_INTR_MASK); + dw_readl(dev, DW_IC_CLR_INTR); + } ++EXPORT_SYMBOL_GPL(i2c_dw_disable); + + void i2c_dw_clear_int(struct dw_i2c_dev *dev) + { + dw_readl(dev, DW_IC_CLR_INTR); + } ++EXPORT_SYMBOL_GPL(i2c_dw_clear_int); + + void i2c_dw_disable_int(struct dw_i2c_dev *dev) + { + dw_writel(dev, 0, DW_IC_INTR_MASK); + } ++EXPORT_SYMBOL_GPL(i2c_dw_disable_int); + + u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev) + { + return dw_readl(dev, DW_IC_COMP_PARAM_1); + } ++EXPORT_SYMBOL_GPL(i2c_dw_read_comp_param); +diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c +index ae2945a..d88ec81 100644 +--- a/drivers/i2c/busses/i2c-i801.c ++++ b/drivers/i2c/busses/i2c-i801.c +@@ -52,6 +52,7 @@ + DH89xxCC (PCH) 0x2330 32 hard yes yes yes + Panther Point (PCH) 0x1e22 32 hard yes yes yes + Lynx Point (PCH) 0x8c22 32 hard yes yes yes ++ Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes + + Features supported by this driver: + Software PEC no +@@ -147,6 +148,7 @@ + #define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330 + #define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30 + #define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22 ++#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22 + + struct i801_priv { + struct i2c_adapter adapter; +@@ -636,6 +638,7 @@ static DEFINE_PCI_DEVICE_TABLE(i801_ids) = { + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) }, ++ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) }, + { 0, } + }; + +diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c +index 31c47e1..5285f85 100644 +--- a/drivers/i2c/busses/i2c-powermac.c ++++ b/drivers/i2c/busses/i2c-powermac.c +@@ -227,28 +227,138 @@ static int __devexit i2c_powermac_remove(struct platform_device *dev) + return 0; + } + ++static u32 __devinit i2c_powermac_get_addr(struct i2c_adapter *adap, ++ struct pmac_i2c_bus *bus, ++ struct device_node *node) ++{ ++ const __be32 *prop; ++ int len; ++ ++ /* First check for valid "reg" */ ++ prop = of_get_property(node, "reg", &len); ++ if (prop && (len >= sizeof(int))) ++ return (be32_to_cpup(prop) & 0xff) >> 1; ++ ++ /* Then check old-style "i2c-address" */ ++ prop = of_get_property(node, "i2c-address", &len); ++ if (prop && (len >= sizeof(int))) ++ return (be32_to_cpup(prop) & 0xff) >> 1; ++ ++ /* Now handle some devices with missing "reg" properties */ ++ if (!strcmp(node->name, "cereal")) ++ return 0x60; ++ else if (!strcmp(node->name, "deq")) ++ return 0x34; ++ ++ dev_warn(&adap->dev, "No i2c address for %s\n", node->full_name); ++ ++ return 0xffffffff; ++} ++ ++static void __devinit i2c_powermac_create_one(struct i2c_adapter *adap, ++ const char *type, ++ u32 addr) ++{ ++ struct i2c_board_info info = {}; ++ struct i2c_client *newdev; ++ ++ strncpy(info.type, type, sizeof(info.type)); ++ info.addr = addr; ++ newdev = i2c_new_device(adap, &info); ++ if (!newdev) ++ dev_err(&adap->dev, ++ "i2c-powermac: Failure to register missing %s\n", ++ type); ++} ++ ++static void __devinit i2c_powermac_add_missing(struct i2c_adapter *adap, ++ struct pmac_i2c_bus *bus, ++ bool found_onyx) ++{ ++ struct device_node *busnode = pmac_i2c_get_bus_node(bus); ++ int rc; ++ ++ /* Check for the onyx audio codec */ ++#define ONYX_REG_CONTROL 67 ++ if (of_device_is_compatible(busnode, "k2-i2c") && !found_onyx) { ++ union i2c_smbus_data data; ++ ++ rc = i2c_smbus_xfer(adap, 0x46, 0, I2C_SMBUS_READ, ++ ONYX_REG_CONTROL, I2C_SMBUS_BYTE_DATA, ++ &data); ++ if (rc >= 0) ++ i2c_powermac_create_one(adap, "MAC,pcm3052", 0x46); ++ ++ rc = i2c_smbus_xfer(adap, 0x47, 0, I2C_SMBUS_READ, ++ ONYX_REG_CONTROL, I2C_SMBUS_BYTE_DATA, ++ &data); ++ if (rc >= 0) ++ i2c_powermac_create_one(adap, "MAC,pcm3052", 0x47); ++ } ++} ++ ++static bool __devinit i2c_powermac_get_type(struct i2c_adapter *adap, ++ struct device_node *node, ++ u32 addr, char *type, int type_size) ++{ ++ char tmp[16]; ++ ++ /* Note: we to _NOT_ want the standard ++ * i2c drivers to match with any of our powermac stuff ++ * unless they have been specifically modified to handle ++ * it on a case by case basis. For example, for thermal ++ * control, things like lm75 etc... shall match with their ++ * corresponding windfarm drivers, _NOT_ the generic ones, ++ * so we force a prefix of AAPL, onto the modalias to ++ * make that happen ++ */ ++ ++ /* First try proper modalias */ ++ if (of_modalias_node(node, tmp, sizeof(tmp)) >= 0) { ++ snprintf(type, type_size, "MAC,%s", tmp); ++ return true; ++ } ++ ++ /* Now look for known workarounds */ ++ if (!strcmp(node->name, "deq")) { ++ /* Apple uses address 0x34 for TAS3001 and 0x35 for TAS3004 */ ++ if (addr == 0x34) { ++ snprintf(type, type_size, "MAC,tas3001"); ++ return true; ++ } else if (addr == 0x35) { ++ snprintf(type, type_size, "MAC,tas3004"); ++ return true; ++ } ++ } ++ ++ dev_err(&adap->dev, "i2c-powermac: modalias failure" ++ " on %s\n", node->full_name); ++ return false; ++} ++ + static void __devinit i2c_powermac_register_devices(struct i2c_adapter *adap, + struct pmac_i2c_bus *bus) + { + struct i2c_client *newdev; + struct device_node *node; ++ bool found_onyx = 0; ++ ++ /* ++ * In some cases we end up with the via-pmu node itself, in this ++ * case we skip this function completely as the device-tree will ++ * not contain anything useful. ++ */ ++ if (!strcmp(adap->dev.of_node->name, "via-pmu")) ++ return; + + for_each_child_of_node(adap->dev.of_node, node) { + struct i2c_board_info info = {}; +- struct dev_archdata dev_ad = {}; +- const __be32 *reg; +- char tmp[16]; + u32 addr; +- int len; + + /* Get address & channel */ +- reg = of_get_property(node, "reg", &len); +- if (!reg || (len < sizeof(int))) { +- dev_err(&adap->dev, "i2c-powermac: invalid reg on %s\n", +- node->full_name); ++ addr = i2c_powermac_get_addr(adap, bus, node); ++ if (addr == 0xffffffff) + continue; +- } +- addr = be32_to_cpup(reg); + + /* Multibus setup, check channel */ + if (!pmac_i2c_match_adapter(node, adap)) +@@ -257,27 +367,23 @@ static void __devinit i2c_powermac_register_devices(struct i2c_adapter *adap, + dev_dbg(&adap->dev, "i2c-powermac: register %s\n", + node->full_name); + +- /* Make up a modalias. Note: we to _NOT_ want the standard +- * i2c drivers to match with any of our powermac stuff +- * unless they have been specifically modified to handle +- * it on a case by case basis. For example, for thermal +- * control, things like lm75 etc... shall match with their +- * corresponding windfarm drivers, _NOT_ the generic ones, +- * so we force a prefix of AAPL, onto the modalias to +- * make that happen ++ /* ++ * Keep track of some device existence to handle ++ * workarounds later. + */ +- if (of_modalias_node(node, tmp, sizeof(tmp)) < 0) { +- dev_err(&adap->dev, "i2c-powermac: modalias failure" +- " on %s\n", node->full_name); ++ if (of_device_is_compatible(node, "pcm3052")) ++ found_onyx = true; ++ ++ /* Make up a modalias */ ++ if (!i2c_powermac_get_type(adap, node, addr, ++ info.type, sizeof(info.type))) { + continue; + } +- snprintf(info.type, sizeof(info.type), "MAC,%s", tmp); + + /* Fill out the rest of the info structure */ +- info.addr = (addr & 0xff) >> 1; ++ info.addr = addr; + info.irq = irq_of_parse_and_map(node, 0); + info.of_node = of_node_get(node); +- info.archdata = &dev_ad; + + newdev = i2c_new_device(adap, &info); + if (!newdev) { +@@ -292,6 +398,9 @@ static void __devinit i2c_powermac_register_devices(struct i2c_adapter *adap, + continue; + } + } ++ ++ /* Additional workarounds */ ++ i2c_powermac_add_missing(adap, bus, found_onyx); + } + + static int __devinit i2c_powermac_probe(struct platform_device *dev) +diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c +index 3974c29..69b23c2 100644 +--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c ++++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c +@@ -148,7 +148,7 @@ static int ipoib_stop(struct net_device *dev) + + netif_stop_queue(dev); + +- ipoib_ib_dev_down(dev, 0); ++ ipoib_ib_dev_down(dev, 1); + ipoib_ib_dev_stop(dev, 0); + + if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) { +diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c +index 20ebc6f..213965d 100644 +--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c ++++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c +@@ -190,7 +190,9 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast, + + mcast->mcmember = *mcmember; + +- /* Set the cached Q_Key before we attach if it's the broadcast group */ ++ /* Set the multicast MTU and cached Q_Key before we attach if it's ++ * the broadcast group. ++ */ + if (!memcmp(mcast->mcmember.mgid.raw, priv->dev->broadcast + 4, + sizeof (union ib_gid))) { + spin_lock_irq(&priv->lock); +@@ -198,10 +200,17 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast, + spin_unlock_irq(&priv->lock); + return -EAGAIN; + } ++ priv->mcast_mtu = IPOIB_UD_MTU(ib_mtu_enum_to_int(priv->broadcast->mcmember.mtu)); + priv->qkey = be32_to_cpu(priv->broadcast->mcmember.qkey); + spin_unlock_irq(&priv->lock); + priv->tx_wr.wr.ud.remote_qkey = priv->qkey; + set_qkey = 1; ++ ++ if (!ipoib_cm_admin_enabled(dev)) { ++ rtnl_lock(); ++ dev_set_mtu(dev, min(priv->mcast_mtu, priv->admin_mtu)); ++ rtnl_unlock(); ++ } + } + + if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) { +@@ -589,14 +598,6 @@ void ipoib_mcast_join_task(struct work_struct *work) + return; + } + +- priv->mcast_mtu = IPOIB_UD_MTU(ib_mtu_enum_to_int(priv->broadcast->mcmember.mtu)); +- +- if (!ipoib_cm_admin_enabled(dev)) { +- rtnl_lock(); +- dev_set_mtu(dev, min(priv->mcast_mtu, priv->admin_mtu)); +- rtnl_unlock(); +- } +- + ipoib_dbg_mcast(priv, "successfully joined all multicast groups\n"); + + clear_bit(IPOIB_MCAST_RUN, &priv->flags); +diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c +index bcbf22e..922d845 100644 +--- a/drivers/infiniband/ulp/srp/ib_srp.c ++++ b/drivers/infiniband/ulp/srp/ib_srp.c +@@ -586,24 +586,62 @@ static void srp_unmap_data(struct scsi_cmnd *scmnd, + scmnd->sc_data_direction); + } + +-static void srp_remove_req(struct srp_target_port *target, +- struct srp_request *req, s32 req_lim_delta) ++/** ++ * srp_claim_req - Take ownership of the scmnd associated with a request. ++ * @target: SRP target port. ++ * @req: SRP request. ++ * @scmnd: If NULL, take ownership of @req->scmnd. If not NULL, only take ++ * ownership of @req->scmnd if it equals @scmnd. ++ * ++ * Return value: ++ * Either NULL or a pointer to the SCSI command the caller became owner of. ++ */ ++static struct scsi_cmnd *srp_claim_req(struct srp_target_port *target, ++ struct srp_request *req, ++ struct scsi_cmnd *scmnd) ++{ ++ unsigned long flags; ++ ++ spin_lock_irqsave(&target->lock, flags); ++ if (!scmnd) { ++ scmnd = req->scmnd; ++ req->scmnd = NULL; ++ } else if (req->scmnd == scmnd) { ++ req->scmnd = NULL; ++ } else { ++ scmnd = NULL; ++ } ++ spin_unlock_irqrestore(&target->lock, flags); ++ ++ return scmnd; ++} ++ ++/** ++ * srp_free_req() - Unmap data and add request to the free request list. ++ */ ++static void srp_free_req(struct srp_target_port *target, ++ struct srp_request *req, struct scsi_cmnd *scmnd, ++ s32 req_lim_delta) + { + unsigned long flags; + +- srp_unmap_data(req->scmnd, target, req); ++ srp_unmap_data(scmnd, target, req); ++ + spin_lock_irqsave(&target->lock, flags); + target->req_lim += req_lim_delta; +- req->scmnd = NULL; + list_add_tail(&req->list, &target->free_reqs); + spin_unlock_irqrestore(&target->lock, flags); + } + + static void srp_reset_req(struct srp_target_port *target, struct srp_request *req) + { +- req->scmnd->result = DID_RESET << 16; +- req->scmnd->scsi_done(req->scmnd); +- srp_remove_req(target, req, 0); ++ struct scsi_cmnd *scmnd = srp_claim_req(target, req, NULL); ++ ++ if (scmnd) { ++ srp_free_req(target, req, scmnd, 0); ++ scmnd->result = DID_RESET << 16; ++ scmnd->scsi_done(scmnd); ++ } + } + + static int srp_reconnect_target(struct srp_target_port *target) +@@ -1073,11 +1111,18 @@ static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp) + complete(&target->tsk_mgmt_done); + } else { + req = &target->req_ring[rsp->tag]; +- scmnd = req->scmnd; +- if (!scmnd) ++ scmnd = srp_claim_req(target, req, NULL); ++ if (!scmnd) { + shost_printk(KERN_ERR, target->scsi_host, + "Null scmnd for RSP w/tag %016llx\n", + (unsigned long long) rsp->tag); ++ ++ spin_lock_irqsave(&target->lock, flags); ++ target->req_lim += be32_to_cpu(rsp->req_lim_delta); ++ spin_unlock_irqrestore(&target->lock, flags); ++ ++ return; ++ } + scmnd->result = rsp->status; + + if (rsp->flags & SRP_RSP_FLAG_SNSVALID) { +@@ -1092,7 +1137,9 @@ static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp) + else if (rsp->flags & (SRP_RSP_FLAG_DIOVER | SRP_RSP_FLAG_DIUNDER)) + scsi_set_resid(scmnd, be32_to_cpu(rsp->data_in_res_cnt)); + +- srp_remove_req(target, req, be32_to_cpu(rsp->req_lim_delta)); ++ srp_free_req(target, req, scmnd, ++ be32_to_cpu(rsp->req_lim_delta)); ++ + scmnd->host_scribble = NULL; + scmnd->scsi_done(scmnd); + } +@@ -1631,25 +1678,18 @@ static int srp_abort(struct scsi_cmnd *scmnd) + { + struct srp_target_port *target = host_to_target(scmnd->device->host); + struct srp_request *req = (struct srp_request *) scmnd->host_scribble; +- int ret = SUCCESS; + + shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n"); + +- if (!req || target->qp_in_error) ++ if (!req || target->qp_in_error || !srp_claim_req(target, req, scmnd)) + return FAILED; +- if (srp_send_tsk_mgmt(target, req->index, scmnd->device->lun, +- SRP_TSK_ABORT_TASK)) +- return FAILED; +- +- if (req->scmnd) { +- if (!target->tsk_mgmt_status) { +- srp_remove_req(target, req, 0); +- scmnd->result = DID_ABORT << 16; +- } else +- ret = FAILED; +- } ++ srp_send_tsk_mgmt(target, req->index, scmnd->device->lun, ++ SRP_TSK_ABORT_TASK); ++ srp_free_req(target, req, scmnd, 0); ++ scmnd->result = DID_ABORT << 16; ++ scmnd->scsi_done(scmnd); + +- return ret; ++ return SUCCESS; + } + + static int srp_reset_device(struct scsi_cmnd *scmnd) +diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c +index c703d53..4dc7136 100644 +--- a/drivers/input/mouse/synaptics.c ++++ b/drivers/input/mouse/synaptics.c +@@ -40,11 +40,27 @@ + * Note that newer firmware allows querying device for maximum useable + * coordinates. + */ ++#define XMIN 0 ++#define XMAX 6143 ++#define YMIN 0 ++#define YMAX 6143 + #define XMIN_NOMINAL 1472 + #define XMAX_NOMINAL 5472 + #define YMIN_NOMINAL 1408 + #define YMAX_NOMINAL 4448 + ++/* Size in bits of absolute position values reported by the hardware */ ++#define ABS_POS_BITS 13 ++ ++/* ++ * Any position values from the hardware above the following limits are ++ * treated as "wrapped around negative" values that have been truncated to ++ * the 13-bit reporting range of the hardware. These are just reasonable ++ * guesses and can be adjusted if hardware is found that operates outside ++ * of these parameters. ++ */ ++#define X_MAX_POSITIVE (((1 << ABS_POS_BITS) + XMAX) / 2) ++#define Y_MAX_POSITIVE (((1 << ABS_POS_BITS) + YMAX) / 2) + + /***************************************************************************** + * Stuff we need even when we do not want native Synaptics support +@@ -555,6 +571,12 @@ static int synaptics_parse_hw_state(const unsigned char buf[], + hw->right = (buf[0] & 0x02) ? 1 : 0; + } + ++ /* Convert wrap-around values to negative */ ++ if (hw->x > X_MAX_POSITIVE) ++ hw->x -= 1 << ABS_POS_BITS; ++ if (hw->y > Y_MAX_POSITIVE) ++ hw->y -= 1 << ABS_POS_BITS; ++ + return 0; + } + +diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h +index 5ec774d..d6cc77a 100644 +--- a/drivers/input/serio/i8042-x86ia64io.h ++++ b/drivers/input/serio/i8042-x86ia64io.h +@@ -177,6 +177,20 @@ static const struct dmi_system_id __initconst i8042_dmi_noloop_table[] = { + }, + }, + { ++ /* Gigabyte T1005 - defines wrong chassis type ("Other") */ ++ .matches = { ++ DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"), ++ DMI_MATCH(DMI_PRODUCT_NAME, "T1005"), ++ }, ++ }, ++ { ++ /* Gigabyte T1005M/P - defines wrong chassis type ("Other") */ ++ .matches = { ++ DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"), ++ DMI_MATCH(DMI_PRODUCT_NAME, "T1005M/P"), ++ }, ++ }, ++ { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), + DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv9700"), +@@ -321,6 +335,12 @@ static const struct dmi_system_id __initconst i8042_dmi_nomux_table[] = { + }, + { + .matches = { ++ DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), ++ DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE C850D"), ++ }, ++ }, ++ { ++ .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "ALIENWARE"), + DMI_MATCH(DMI_PRODUCT_NAME, "Sentia"), + }, +diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c +index 8b31473..824abc7 100644 +--- a/drivers/input/tablet/wacom_sys.c ++++ b/drivers/input/tablet/wacom_sys.c +@@ -445,8 +445,7 @@ static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_feat + /* ask to report Wacom data */ + if (features->device_type == BTN_TOOL_FINGER) { + /* if it is an MT Tablet PC touch */ +- if (features->type == TABLETPC2FG || +- features->type == MTSCREEN) { ++ if (features->type > TABLETPC) { + do { + rep_data[0] = 3; + rep_data[1] = 4; +@@ -465,7 +464,7 @@ static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_feat + } while ((error < 0 || rep_data[1] != 4) && + limit++ < WAC_MSG_RETRIES); + } +- } else if (features->type != TABLETPC && ++ } else if (features->type <= BAMBOO_PT && + features->type != WIRELESS && + features->device_type == BTN_TOOL_PEN) { + do { +@@ -515,10 +514,7 @@ static int wacom_retrieve_hid_descriptor(struct usb_interface *intf, + } + + /* only devices that support touch need to retrieve the info */ +- if (features->type != TABLETPC && +- features->type != TABLETPC2FG && +- features->type != BAMBOO_PT && +- features->type != MTSCREEN) { ++ if (features->type < BAMBOO_PT) { + goto out; + } + +diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c +index 004bc1b..05e8cb3 100644 +--- a/drivers/input/tablet/wacom_wac.c ++++ b/drivers/input/tablet/wacom_wac.c +@@ -248,7 +248,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom) + input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2])); + input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4])); + if (wacom->tool[0] != BTN_TOOL_MOUSE) { +- input_report_abs(input, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8)); ++ input_report_abs(input, ABS_PRESSURE, data[6] | ((data[7] & 0x03) << 8)); + input_report_key(input, BTN_TOUCH, data[1] & 0x01); + input_report_key(input, BTN_STYLUS, data[1] & 0x02); + input_report_key(input, BTN_STYLUS2, data[1] & 0x04); +@@ -464,7 +464,7 @@ static void wacom_intuos_general(struct wacom_wac *wacom) + t = (data[6] << 2) | ((data[7] >> 6) & 3); + if ((features->type >= INTUOS4S && features->type <= INTUOS4L) || + (features->type >= INTUOS5S && features->type <= INTUOS5L) || +- features->type == WACOM_21UX2 || features->type == WACOM_24HD) { ++ (features->type >= WACOM_21UX2 && features->type <= WACOM_24HD)) { + t = (t << 1) | (data[1] & 1); + } + input_report_abs(input, ABS_PRESSURE, t); +@@ -614,7 +614,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) + input_report_abs(input, ABS_MISC, 0); + } + } else { +- if (features->type == WACOM_21UX2) { ++ if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) { + input_report_key(input, BTN_0, (data[5] & 0x01)); + input_report_key(input, BTN_1, (data[6] & 0x01)); + input_report_key(input, BTN_2, (data[6] & 0x02)); +@@ -633,6 +633,12 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) + input_report_key(input, BTN_Z, (data[8] & 0x20)); + input_report_key(input, BTN_BASE, (data[8] & 0x40)); + input_report_key(input, BTN_BASE2, (data[8] & 0x80)); ++ ++ if (features->type == WACOM_22HD) { ++ input_report_key(input, KEY_PROG1, data[9] & 0x01); ++ input_report_key(input, KEY_PROG2, data[9] & 0x02); ++ input_report_key(input, KEY_PROG3, data[9] & 0x04); ++ } + } else { + input_report_key(input, BTN_0, (data[5] & 0x01)); + input_report_key(input, BTN_1, (data[5] & 0x02)); +@@ -1230,6 +1236,7 @@ void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len) + case CINTIQ: + case WACOM_BEE: + case WACOM_21UX2: ++ case WACOM_22HD: + case WACOM_24HD: + sync = wacom_intuos_irq(wacom_wac); + break; +@@ -1317,10 +1324,8 @@ void wacom_setup_device_quirks(struct wacom_features *features) + } + + /* these device have multiple inputs */ +- if (features->type == TABLETPC || features->type == TABLETPC2FG || +- features->type == BAMBOO_PT || features->type == WIRELESS || +- (features->type >= INTUOS5S && features->type <= INTUOS5L) || +- features->type == MTSCREEN) ++ if (features->type >= WIRELESS || ++ (features->type >= INTUOS5S && features->type <= INTUOS5L)) + features->quirks |= WACOM_QUIRK_MULTI_INPUT; + + /* quirk for bamboo touch with 2 low res touches */ +@@ -1432,6 +1437,12 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev, + wacom_setup_cintiq(wacom_wac); + break; + ++ case WACOM_22HD: ++ __set_bit(KEY_PROG1, input_dev->keybit); ++ __set_bit(KEY_PROG2, input_dev->keybit); ++ __set_bit(KEY_PROG3, input_dev->keybit); ++ /* fall through */ ++ + case WACOM_21UX2: + __set_bit(BTN_A, input_dev->keybit); + __set_bit(BTN_B, input_dev->keybit); +@@ -1855,6 +1866,9 @@ static const struct wacom_features wacom_features_0xF0 = + static const struct wacom_features wacom_features_0xCC = + { "Wacom Cintiq 21UX2", WACOM_PKGLEN_INTUOS, 87200, 65600, 2047, + 63, WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES }; ++static const struct wacom_features wacom_features_0xFA = ++ { "Wacom Cintiq 22HD", WACOM_PKGLEN_INTUOS, 95840, 54260, 2047, ++ 63, WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES }; + static const struct wacom_features wacom_features_0x90 = + { "Wacom ISDv4 90", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255, + 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; +@@ -2064,6 +2078,7 @@ const struct usb_device_id wacom_ids[] = { + { USB_DEVICE_WACOM(0xEC) }, + { USB_DEVICE_WACOM(0x47) }, + { USB_DEVICE_WACOM(0xF4) }, ++ { USB_DEVICE_WACOM(0xFA) }, + { USB_DEVICE_LENOVO(0x6004) }, + { } + }; +diff --git a/drivers/input/tablet/wacom_wac.h b/drivers/input/tablet/wacom_wac.h +index 78fbd3f..9ae9118 100644 +--- a/drivers/input/tablet/wacom_wac.h ++++ b/drivers/input/tablet/wacom_wac.h +@@ -62,8 +62,6 @@ enum { + PTU, + PL, + DTU, +- BAMBOO_PT, +- WIRELESS, + INTUOS, + INTUOS3S, + INTUOS3, +@@ -74,12 +72,15 @@ enum { + INTUOS5S, + INTUOS5, + INTUOS5L, +- WACOM_24HD, + WACOM_21UX2, ++ WACOM_22HD, ++ WACOM_24HD, + CINTIQ, + WACOM_BEE, + WACOM_MO, +- TABLETPC, ++ WIRELESS, ++ BAMBOO_PT, ++ TABLETPC, /* add new TPC below */ + TABLETPC2FG, + MTSCREEN, + MAX_TYPE +diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c +index 503c709..908407e 100644 +--- a/drivers/input/touchscreen/eeti_ts.c ++++ b/drivers/input/touchscreen/eeti_ts.c +@@ -48,7 +48,7 @@ struct eeti_ts_priv { + struct input_dev *input; + struct work_struct work; + struct mutex mutex; +- int irq, irq_active_high; ++ int irq_gpio, irq, irq_active_high; + }; + + #define EETI_TS_BITDEPTH (11) +@@ -62,7 +62,7 @@ struct eeti_ts_priv { + + static inline int eeti_ts_irq_active(struct eeti_ts_priv *priv) + { +- return gpio_get_value(irq_to_gpio(priv->irq)) == priv->irq_active_high; ++ return gpio_get_value(priv->irq_gpio) == priv->irq_active_high; + } + + static void eeti_ts_read(struct work_struct *work) +@@ -157,7 +157,7 @@ static void eeti_ts_close(struct input_dev *dev) + static int __devinit eeti_ts_probe(struct i2c_client *client, + const struct i2c_device_id *idp) + { +- struct eeti_ts_platform_data *pdata; ++ struct eeti_ts_platform_data *pdata = client->dev.platform_data; + struct eeti_ts_priv *priv; + struct input_dev *input; + unsigned int irq_flags; +@@ -199,9 +199,12 @@ static int __devinit eeti_ts_probe(struct i2c_client *client, + + priv->client = client; + priv->input = input; +- priv->irq = client->irq; ++ priv->irq_gpio = pdata->irq_gpio; ++ priv->irq = gpio_to_irq(pdata->irq_gpio); + +- pdata = client->dev.platform_data; ++ err = gpio_request_one(pdata->irq_gpio, GPIOF_IN, client->name); ++ if (err < 0) ++ goto err1; + + if (pdata) + priv->irq_active_high = pdata->irq_active_high; +@@ -215,13 +218,13 @@ static int __devinit eeti_ts_probe(struct i2c_client *client, + + err = input_register_device(input); + if (err) +- goto err1; ++ goto err2; + + err = request_irq(priv->irq, eeti_ts_isr, irq_flags, + client->name, priv); + if (err) { + dev_err(&client->dev, "Unable to request touchscreen IRQ.\n"); +- goto err2; ++ goto err3; + } + + /* +@@ -233,9 +236,11 @@ static int __devinit eeti_ts_probe(struct i2c_client *client, + device_init_wakeup(&client->dev, 0); + return 0; + +-err2: ++err3: + input_unregister_device(input); + input = NULL; /* so we dont try to free it below */ ++err2: ++ gpio_free(pdata->irq_gpio); + err1: + input_free_device(input); + kfree(priv); +diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c +index 6256263..3f365ab 100644 +--- a/drivers/iommu/amd_iommu.c ++++ b/drivers/iommu/amd_iommu.c +@@ -2254,6 +2254,18 @@ static int device_change_notifier(struct notifier_block *nb, + + iommu_init_device(dev); + ++ /* ++ * dev_data is still NULL and ++ * got initialized in iommu_init_device ++ */ ++ dev_data = get_dev_data(dev); ++ ++ if (iommu_pass_through || dev_data->iommu_v2) { ++ dev_data->passthrough = true; ++ attach_device(dev, pt_domain); ++ break; ++ } ++ + domain = domain_for_device(dev); + + /* allocate a protection domain if a device is added */ +@@ -2271,10 +2283,7 @@ static int device_change_notifier(struct notifier_block *nb, + + dev_data = get_dev_data(dev); + +- if (!dev_data->passthrough) +- dev->archdata.dma_ops = &amd_iommu_dma_ops; +- else +- dev->archdata.dma_ops = &nommu_dma_ops; ++ dev->archdata.dma_ops = &amd_iommu_dma_ops; + + break; + case BUS_NOTIFY_DEL_DEVICE: +diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c +index 036fe9b..a1f1bc8 100644 +--- a/drivers/iommu/amd_iommu_v2.c ++++ b/drivers/iommu/amd_iommu_v2.c +@@ -681,6 +681,8 @@ int amd_iommu_bind_pasid(struct pci_dev *pdev, int pasid, + + atomic_set(&pasid_state->count, 1); + init_waitqueue_head(&pasid_state->wq); ++ spin_lock_init(&pasid_state->lock); ++ + pasid_state->task = task; + pasid_state->mm = get_task_mm(task); + pasid_state->device_state = dev_state; +diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c +index b12af2f..3e1bdc1 100644 +--- a/drivers/iommu/intel-iommu.c ++++ b/drivers/iommu/intel-iommu.c +@@ -589,7 +589,9 @@ static void domain_update_iommu_coherency(struct dmar_domain *domain) + { + int i; + +- domain->iommu_coherency = 1; ++ i = find_first_bit(domain->iommu_bmp, g_num_of_iommus); ++ ++ domain->iommu_coherency = i < g_num_of_iommus ? 1 : 0; + + for_each_set_bit(i, domain->iommu_bmp, g_num_of_iommus) { + if (!ecap_coherent(g_iommus[i]->ecap)) { +diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c +index 6d34706..55fe60d 100644 +--- a/drivers/iommu/intel_irq_remapping.c ++++ b/drivers/iommu/intel_irq_remapping.c +@@ -736,6 +736,7 @@ int __init parse_ioapics_under_ir(void) + { + struct dmar_drhd_unit *drhd; + int ir_supported = 0; ++ int ioapic_idx; + + for_each_drhd_unit(drhd) { + struct intel_iommu *iommu = drhd->iommu; +@@ -748,13 +749,20 @@ int __init parse_ioapics_under_ir(void) + } + } + +- if (ir_supported && ir_ioapic_num != nr_ioapics) { +- printk(KERN_WARNING +- "Not all IO-APIC's listed under remapping hardware\n"); +- return -1; ++ if (!ir_supported) ++ return 0; ++ ++ for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++) { ++ int ioapic_id = mpc_ioapic_id(ioapic_idx); ++ if (!map_ioapic_to_ir(ioapic_id)) { ++ pr_err(FW_BUG "ioapic %d has no mapping iommu, " ++ "interrupt remapping will be disabled\n", ++ ioapic_id); ++ return -1; ++ } + } + +- return ir_supported; ++ return 1; + } + + int __init ir_dev_scope_init(void) +diff --git a/drivers/isdn/hardware/mISDN/avmfritz.c b/drivers/isdn/hardware/mISDN/avmfritz.c +index c08fc60..dceaec8 100644 +--- a/drivers/isdn/hardware/mISDN/avmfritz.c ++++ b/drivers/isdn/hardware/mISDN/avmfritz.c +@@ -449,7 +449,8 @@ hdlc_fill_fifo(struct bchannel *bch) + { + struct fritzcard *fc = bch->hw; + struct hdlc_hw *hdlc; +- int count, fs, cnt = 0, idx, fillempty = 0; ++ int count, fs, cnt = 0, idx; ++ bool fillempty = false; + u8 *p; + u32 *ptr, val, addr; + +@@ -462,7 +463,7 @@ hdlc_fill_fifo(struct bchannel *bch) + return; + count = fs; + p = bch->fill; +- fillempty = 1; ++ fillempty = true; + } else { + count = bch->tx_skb->len - bch->tx_idx; + if (count <= 0) +@@ -477,7 +478,7 @@ hdlc_fill_fifo(struct bchannel *bch) + hdlc->ctrl.sr.cmd |= HDLC_CMD_XME; + } + ptr = (u32 *)p; +- if (fillempty) { ++ if (!fillempty) { + pr_debug("%s.B%d: %d/%d/%d", fc->name, bch->nr, count, + bch->tx_idx, bch->tx_skb->len); + bch->tx_idx += count; +@@ -856,8 +857,9 @@ avm_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg) + switch (cmd) { + case CLOSE_CHANNEL: + test_and_clear_bit(FLG_OPEN, &bch->Flags); ++ cancel_work_sync(&bch->workq); + spin_lock_irqsave(&fc->lock, flags); +- mISDN_freebchannel(bch); ++ mISDN_clear_bchannel(bch); + modehdlc(bch, ISDN_P_NONE); + spin_unlock_irqrestore(&fc->lock, flags); + ch->protocol = ISDN_P_NONE; +diff --git a/drivers/isdn/hardware/mISDN/mISDNipac.c b/drivers/isdn/hardware/mISDN/mISDNipac.c +index 752e082..ccd7d85 100644 +--- a/drivers/isdn/hardware/mISDN/mISDNipac.c ++++ b/drivers/isdn/hardware/mISDN/mISDNipac.c +@@ -1406,8 +1406,9 @@ hscx_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg) + switch (cmd) { + case CLOSE_CHANNEL: + test_and_clear_bit(FLG_OPEN, &bch->Flags); ++ cancel_work_sync(&bch->workq); + spin_lock_irqsave(hx->ip->hwlock, flags); +- mISDN_freebchannel(bch); ++ mISDN_clear_bchannel(bch); + hscx_mode(hx, ISDN_P_NONE); + spin_unlock_irqrestore(hx->ip->hwlock, flags); + ch->protocol = ISDN_P_NONE; +diff --git a/drivers/isdn/hardware/mISDN/mISDNisar.c b/drivers/isdn/hardware/mISDN/mISDNisar.c +index be5973d..182ecf0 100644 +--- a/drivers/isdn/hardware/mISDN/mISDNisar.c ++++ b/drivers/isdn/hardware/mISDN/mISDNisar.c +@@ -1588,8 +1588,9 @@ isar_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg) + switch (cmd) { + case CLOSE_CHANNEL: + test_and_clear_bit(FLG_OPEN, &bch->Flags); ++ cancel_work_sync(&bch->workq); + spin_lock_irqsave(ich->is->hwlock, flags); +- mISDN_freebchannel(bch); ++ mISDN_clear_bchannel(bch); + modeisar(ich, ISDN_P_NONE); + spin_unlock_irqrestore(ich->is->hwlock, flags); + ch->protocol = ISDN_P_NONE; +diff --git a/drivers/isdn/hardware/mISDN/netjet.c b/drivers/isdn/hardware/mISDN/netjet.c +index c3e3e76..9bcade5 100644 +--- a/drivers/isdn/hardware/mISDN/netjet.c ++++ b/drivers/isdn/hardware/mISDN/netjet.c +@@ -812,8 +812,9 @@ nj_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg) + switch (cmd) { + case CLOSE_CHANNEL: + test_and_clear_bit(FLG_OPEN, &bch->Flags); ++ cancel_work_sync(&bch->workq); + spin_lock_irqsave(&card->lock, flags); +- mISDN_freebchannel(bch); ++ mISDN_clear_bchannel(bch); + mode_tiger(bc, ISDN_P_NONE); + spin_unlock_irqrestore(&card->lock, flags); + ch->protocol = ISDN_P_NONE; +diff --git a/drivers/isdn/hardware/mISDN/w6692.c b/drivers/isdn/hardware/mISDN/w6692.c +index 26a86b8..335fe64 100644 +--- a/drivers/isdn/hardware/mISDN/w6692.c ++++ b/drivers/isdn/hardware/mISDN/w6692.c +@@ -1054,8 +1054,9 @@ w6692_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg) + switch (cmd) { + case CLOSE_CHANNEL: + test_and_clear_bit(FLG_OPEN, &bch->Flags); ++ cancel_work_sync(&bch->workq); + spin_lock_irqsave(&card->lock, flags); +- mISDN_freebchannel(bch); ++ mISDN_clear_bchannel(bch); + w6692_mode(bc, ISDN_P_NONE); + spin_unlock_irqrestore(&card->lock, flags); + ch->protocol = ISDN_P_NONE; +diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c +index 5405ec6..baf2686 100644 +--- a/drivers/isdn/isdnloop/isdnloop.c ++++ b/drivers/isdn/isdnloop/isdnloop.c +@@ -16,7 +16,6 @@ + #include + #include "isdnloop.h" + +-static char *revision = "$Revision: 1.11.6.7 $"; + static char *isdnloop_id = "loop0"; + + MODULE_DESCRIPTION("ISDN4Linux: Pseudo Driver that simulates an ISDN card"); +@@ -1494,17 +1493,6 @@ isdnloop_addcard(char *id1) + static int __init + isdnloop_init(void) + { +- char *p; +- char rev[10]; +- +- if ((p = strchr(revision, ':'))) { +- strcpy(rev, p + 1); +- p = strchr(rev, '$'); +- *p = 0; +- } else +- strcpy(rev, " ??? "); +- printk(KERN_NOTICE "isdnloop-ISDN-driver Rev%s\n", rev); +- + if (isdnloop_id) + return (isdnloop_addcard(isdnloop_id)); + +diff --git a/drivers/isdn/mISDN/hwchannel.c b/drivers/isdn/mISDN/hwchannel.c +index ef34fd4..2602be2 100644 +--- a/drivers/isdn/mISDN/hwchannel.c ++++ b/drivers/isdn/mISDN/hwchannel.c +@@ -148,17 +148,16 @@ mISDN_clear_bchannel(struct bchannel *ch) + ch->next_minlen = ch->init_minlen; + ch->maxlen = ch->init_maxlen; + ch->next_maxlen = ch->init_maxlen; ++ skb_queue_purge(&ch->rqueue); ++ ch->rcount = 0; + } + EXPORT_SYMBOL(mISDN_clear_bchannel); + +-int ++void + mISDN_freebchannel(struct bchannel *ch) + { ++ cancel_work_sync(&ch->workq); + mISDN_clear_bchannel(ch); +- skb_queue_purge(&ch->rqueue); +- ch->rcount = 0; +- flush_work_sync(&ch->workq); +- return 0; + } + EXPORT_SYMBOL(mISDN_freebchannel); + +diff --git a/drivers/isdn/mISDN/layer2.c b/drivers/isdn/mISDN/layer2.c +index 0dc8abc..949cabb 100644 +--- a/drivers/isdn/mISDN/layer2.c ++++ b/drivers/isdn/mISDN/layer2.c +@@ -2222,7 +2222,7 @@ create_l2(struct mISDNchannel *ch, u_int protocol, u_long options, int tei, + InitWin(l2); + l2->l2m.fsm = &l2fsm; + if (test_bit(FLG_LAPB, &l2->flag) || +- test_bit(FLG_PTP, &l2->flag) || ++ test_bit(FLG_FIXED_TEI, &l2->flag) || + test_bit(FLG_LAPD_NET, &l2->flag)) + l2->l2m.state = ST_L2_4; + else +diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c +index 638dae0..1ca41d2 100644 +--- a/drivers/md/dm-mpath.c ++++ b/drivers/md/dm-mpath.c +@@ -1520,6 +1520,7 @@ static int multipath_ioctl(struct dm_target *ti, unsigned int cmd, + unsigned long arg) + { + struct multipath *m = ti->private; ++ struct pgpath *pgpath; + struct block_device *bdev; + fmode_t mode; + unsigned long flags; +@@ -1535,12 +1536,14 @@ again: + if (!m->current_pgpath) + __choose_pgpath(m, 0); + +- if (m->current_pgpath) { +- bdev = m->current_pgpath->path.dev->bdev; +- mode = m->current_pgpath->path.dev->mode; ++ pgpath = m->current_pgpath; ++ ++ if (pgpath) { ++ bdev = pgpath->path.dev->bdev; ++ mode = pgpath->path.dev->mode; + } + +- if (m->queue_io) ++ if ((pgpath && m->queue_io) || (!pgpath && m->queue_if_no_path)) + r = -EAGAIN; + else if (!bdev) + r = -EIO; +diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c +index 2e227fb..f220a69 100644 +--- a/drivers/md/dm-table.c ++++ b/drivers/md/dm-table.c +@@ -1351,17 +1351,25 @@ static int device_is_nonrot(struct dm_target *ti, struct dm_dev *dev, + return q && blk_queue_nonrot(q); + } + +-static bool dm_table_is_nonrot(struct dm_table *t) ++static int device_is_not_random(struct dm_target *ti, struct dm_dev *dev, ++ sector_t start, sector_t len, void *data) ++{ ++ struct request_queue *q = bdev_get_queue(dev->bdev); ++ ++ return q && !blk_queue_add_random(q); ++} ++ ++static bool dm_table_all_devices_attribute(struct dm_table *t, ++ iterate_devices_callout_fn func) + { + struct dm_target *ti; + unsigned i = 0; + +- /* Ensure that all underlying device are non-rotational. */ + while (i < dm_table_get_num_targets(t)) { + ti = dm_table_get_target(t, i++); + + if (!ti->type->iterate_devices || +- !ti->type->iterate_devices(ti, device_is_nonrot, NULL)) ++ !ti->type->iterate_devices(ti, func, NULL)) + return 0; + } + +@@ -1393,7 +1401,8 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, + if (!dm_table_discard_zeroes_data(t)) + q->limits.discard_zeroes_data = 0; + +- if (dm_table_is_nonrot(t)) ++ /* Ensure that all underlying devices are non-rotational. */ ++ if (dm_table_all_devices_attribute(t, device_is_nonrot)) + queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q); + else + queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, q); +@@ -1401,6 +1410,15 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, + dm_table_set_integrity(t); + + /* ++ * Determine whether or not this queue's I/O timings contribute ++ * to the entropy pool, Only request-based targets use this. ++ * Clear QUEUE_FLAG_ADD_RANDOM if any underlying device does not ++ * have it set. ++ */ ++ if (blk_queue_add_random(q) && dm_table_all_devices_attribute(t, device_is_not_random)) ++ queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, q); ++ ++ /* + * QUEUE_FLAG_STACKABLE must be set after all queue settings are + * visible to other CPUs because, once the flag is set, incoming bios + * are processed by request-based dm, which refers to the queue +diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c +index 68694da..e1bce79 100644 +--- a/drivers/md/dm-thin.c ++++ b/drivers/md/dm-thin.c +@@ -19,7 +19,7 @@ + /* + * Tunable constants + */ +-#define ENDIO_HOOK_POOL_SIZE 10240 ++#define ENDIO_HOOK_POOL_SIZE 1024 + #define DEFERRED_SET_SIZE 64 + #define MAPPING_POOL_SIZE 1024 + #define PRISON_CELLS 1024 +@@ -859,7 +859,7 @@ static void process_prepared_mapping(struct dm_thin_new_mapping *m) + + if (m->err) { + cell_error(m->cell); +- return; ++ goto out; + } + + /* +@@ -871,7 +871,7 @@ static void process_prepared_mapping(struct dm_thin_new_mapping *m) + if (r) { + DMERR("dm_thin_insert_block() failed"); + cell_error(m->cell); +- return; ++ goto out; + } + + /* +@@ -886,6 +886,7 @@ static void process_prepared_mapping(struct dm_thin_new_mapping *m) + } else + cell_defer(tc, m->cell, m->data_block); + ++out: + list_del(&m->list); + mempool_free(m, tc->pool->mapping_pool); + } +diff --git a/drivers/md/dm-verity.c b/drivers/md/dm-verity.c +index fa365d3..68bf5c3 100644 +--- a/drivers/md/dm-verity.c ++++ b/drivers/md/dm-verity.c +@@ -718,8 +718,8 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) + v->hash_dev_block_bits = ffs(num) - 1; + + if (sscanf(argv[5], "%llu%c", &num_ll, &dummy) != 1 || +- num_ll << (v->data_dev_block_bits - SECTOR_SHIFT) != +- (sector_t)num_ll << (v->data_dev_block_bits - SECTOR_SHIFT)) { ++ (sector_t)(num_ll << (v->data_dev_block_bits - SECTOR_SHIFT)) ++ >> (v->data_dev_block_bits - SECTOR_SHIFT) != num_ll) { + ti->error = "Invalid data blocks"; + r = -EINVAL; + goto bad; +@@ -733,8 +733,8 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) + } + + if (sscanf(argv[6], "%llu%c", &num_ll, &dummy) != 1 || +- num_ll << (v->hash_dev_block_bits - SECTOR_SHIFT) != +- (sector_t)num_ll << (v->hash_dev_block_bits - SECTOR_SHIFT)) { ++ (sector_t)(num_ll << (v->hash_dev_block_bits - SECTOR_SHIFT)) ++ >> (v->hash_dev_block_bits - SECTOR_SHIFT) != num_ll) { + ti->error = "Invalid hash start"; + r = -EINVAL; + goto bad; +diff --git a/drivers/md/dm.c b/drivers/md/dm.c +index e24143c..9ff3019 100644 +--- a/drivers/md/dm.c ++++ b/drivers/md/dm.c +@@ -865,10 +865,14 @@ static void dm_done(struct request *clone, int error, bool mapped) + { + int r = error; + struct dm_rq_target_io *tio = clone->end_io_data; +- dm_request_endio_fn rq_end_io = tio->ti->type->rq_end_io; ++ dm_request_endio_fn rq_end_io = NULL; + +- if (mapped && rq_end_io) +- r = rq_end_io(tio->ti, clone, error, &tio->info); ++ if (tio->ti) { ++ rq_end_io = tio->ti->type->rq_end_io; ++ ++ if (mapped && rq_end_io) ++ r = rq_end_io(tio->ti, clone, error, &tio->info); ++ } + + if (r <= 0) + /* The target wants to complete the I/O */ +@@ -1566,15 +1570,6 @@ static int map_request(struct dm_target *ti, struct request *clone, + int r, requeued = 0; + struct dm_rq_target_io *tio = clone->end_io_data; + +- /* +- * Hold the md reference here for the in-flight I/O. +- * We can't rely on the reference count by device opener, +- * because the device may be closed during the request completion +- * when all bios are completed. +- * See the comment in rq_completed() too. +- */ +- dm_get(md); +- + tio->ti = ti; + r = ti->type->map_rq(ti, clone, &tio->info); + switch (r) { +@@ -1606,6 +1601,26 @@ static int map_request(struct dm_target *ti, struct request *clone, + return requeued; + } + ++static struct request *dm_start_request(struct mapped_device *md, struct request *orig) ++{ ++ struct request *clone; ++ ++ blk_start_request(orig); ++ clone = orig->special; ++ atomic_inc(&md->pending[rq_data_dir(clone)]); ++ ++ /* ++ * Hold the md reference here for the in-flight I/O. ++ * We can't rely on the reference count by device opener, ++ * because the device may be closed during the request completion ++ * when all bios are completed. ++ * See the comment in rq_completed() too. ++ */ ++ dm_get(md); ++ ++ return clone; ++} ++ + /* + * q->request_fn for request-based dm. + * Called with the queue lock held. +@@ -1635,14 +1650,21 @@ static void dm_request_fn(struct request_queue *q) + pos = blk_rq_pos(rq); + + ti = dm_table_find_target(map, pos); +- BUG_ON(!dm_target_is_valid(ti)); ++ if (!dm_target_is_valid(ti)) { ++ /* ++ * Must perform setup, that dm_done() requires, ++ * before calling dm_kill_unmapped_request ++ */ ++ DMERR_LIMIT("request attempted access beyond the end of device"); ++ clone = dm_start_request(md, rq); ++ dm_kill_unmapped_request(clone, -EIO); ++ continue; ++ } + + if (ti->type->busy && ti->type->busy(ti)) + goto delay_and_out; + +- blk_start_request(rq); +- clone = rq->special; +- atomic_inc(&md->pending[rq_data_dir(clone)]); ++ clone = dm_start_request(md, rq); + + spin_unlock(q->queue_lock); + if (map_request(ti, clone, md)) +@@ -1662,8 +1684,6 @@ delay_and_out: + blk_delay_queue(q, HZ / 10); + out: + dm_table_put(map); +- +- return; + } + + int dm_underlying_device_busy(struct request_queue *q) +diff --git a/drivers/md/md.c b/drivers/md/md.c +index d5ab449..6fc0c26 100644 +--- a/drivers/md/md.c ++++ b/drivers/md/md.c +@@ -1157,8 +1157,11 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor + ret = 0; + } + rdev->sectors = rdev->sb_start; +- /* Limit to 4TB as metadata cannot record more than that */ +- if (rdev->sectors >= (2ULL << 32)) ++ /* Limit to 4TB as metadata cannot record more than that. ++ * (not needed for Linear and RAID0 as metadata doesn't ++ * record this size) ++ */ ++ if (rdev->sectors >= (2ULL << 32) && sb->level >= 1) + rdev->sectors = (2ULL << 32) - 2; + + if (rdev->sectors < ((sector_t)sb->size) * 2 && sb->level >= 1) +@@ -1449,7 +1452,7 @@ super_90_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors) + /* Limit to 4TB as metadata cannot record more than that. + * 4TB == 2^32 KB, or 2*2^32 sectors. + */ +- if (num_sectors >= (2ULL << 32)) ++ if (num_sectors >= (2ULL << 32) && rdev->mddev->level >= 1) + num_sectors = (2ULL << 32) - 2; + md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, + rdev->sb_page); +@@ -7669,6 +7672,8 @@ static int remove_and_add_spares(struct mddev *mddev) + } + } + } ++ if (removed) ++ set_bit(MD_CHANGE_DEVS, &mddev->flags); + return spares; + } + +@@ -7682,9 +7687,11 @@ static void reap_sync_thread(struct mddev *mddev) + !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { + /* success...*/ + /* activate any spares */ +- if (mddev->pers->spare_active(mddev)) ++ if (mddev->pers->spare_active(mddev)) { + sysfs_notify(&mddev->kobj, NULL, + "degraded"); ++ set_bit(MD_CHANGE_DEVS, &mddev->flags); ++ } + } + if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && + mddev->pers->finish_reshape) +diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c +index cacd008..53aec45 100644 +--- a/drivers/md/raid1.c ++++ b/drivers/md/raid1.c +@@ -2428,7 +2428,10 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp + /* There is nowhere to write, so all non-sync + * drives must be failed - so we are finished + */ +- sector_t rv = max_sector - sector_nr; ++ sector_t rv; ++ if (min_bad > 0) ++ max_sector = sector_nr + min_bad; ++ rv = max_sector - sector_nr; + *skipped = 1; + put_buf(r1_bio); + return rv; +diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c +index 8da6282..e987da4 100644 +--- a/drivers/md/raid10.c ++++ b/drivers/md/raid10.c +@@ -645,7 +645,11 @@ static int raid10_mergeable_bvec(struct request_queue *q, + max = biovec->bv_len; + + if (mddev->merge_check_needed) { +- struct r10bio r10_bio; ++ struct { ++ struct r10bio r10_bio; ++ struct r10dev devs[conf->copies]; ++ } on_stack; ++ struct r10bio *r10_bio = &on_stack.r10_bio; + int s; + if (conf->reshape_progress != MaxSector) { + /* Cannot give any guidance during reshape */ +@@ -653,18 +657,18 @@ static int raid10_mergeable_bvec(struct request_queue *q, + return biovec->bv_len; + return 0; + } +- r10_bio.sector = sector; +- raid10_find_phys(conf, &r10_bio); ++ r10_bio->sector = sector; ++ raid10_find_phys(conf, r10_bio); + rcu_read_lock(); + for (s = 0; s < conf->copies; s++) { +- int disk = r10_bio.devs[s].devnum; ++ int disk = r10_bio->devs[s].devnum; + struct md_rdev *rdev = rcu_dereference( + conf->mirrors[disk].rdev); + if (rdev && !test_bit(Faulty, &rdev->flags)) { + struct request_queue *q = + bdev_get_queue(rdev->bdev); + if (q->merge_bvec_fn) { +- bvm->bi_sector = r10_bio.devs[s].addr ++ bvm->bi_sector = r10_bio->devs[s].addr + + rdev->data_offset; + bvm->bi_bdev = rdev->bdev; + max = min(max, q->merge_bvec_fn( +@@ -676,7 +680,7 @@ static int raid10_mergeable_bvec(struct request_queue *q, + struct request_queue *q = + bdev_get_queue(rdev->bdev); + if (q->merge_bvec_fn) { +- bvm->bi_sector = r10_bio.devs[s].addr ++ bvm->bi_sector = r10_bio->devs[s].addr + + rdev->data_offset; + bvm->bi_bdev = rdev->bdev; + max = min(max, q->merge_bvec_fn( +@@ -1488,14 +1492,16 @@ static int _enough(struct r10conf *conf, struct geom *geo, int ignore) + do { + int n = conf->copies; + int cnt = 0; ++ int this = first; + while (n--) { +- if (conf->mirrors[first].rdev && +- first != ignore) ++ if (conf->mirrors[this].rdev && ++ this != ignore) + cnt++; +- first = (first+1) % geo->raid_disks; ++ this = (this+1) % geo->raid_disks; + } + if (cnt == 0) + return 0; ++ first = (first + geo->near_copies) % geo->raid_disks; + } while (first != 0); + return 1; + } +@@ -4389,14 +4395,18 @@ static int handle_reshape_read_error(struct mddev *mddev, + { + /* Use sync reads to get the blocks from somewhere else */ + int sectors = r10_bio->sectors; +- struct r10bio r10b; + struct r10conf *conf = mddev->private; ++ struct { ++ struct r10bio r10_bio; ++ struct r10dev devs[conf->copies]; ++ } on_stack; ++ struct r10bio *r10b = &on_stack.r10_bio; + int slot = 0; + int idx = 0; + struct bio_vec *bvec = r10_bio->master_bio->bi_io_vec; + +- r10b.sector = r10_bio->sector; +- __raid10_find_phys(&conf->prev, &r10b); ++ r10b->sector = r10_bio->sector; ++ __raid10_find_phys(&conf->prev, r10b); + + while (sectors) { + int s = sectors; +@@ -4407,7 +4417,7 @@ static int handle_reshape_read_error(struct mddev *mddev, + s = PAGE_SIZE >> 9; + + while (!success) { +- int d = r10b.devs[slot].devnum; ++ int d = r10b->devs[slot].devnum; + struct md_rdev *rdev = conf->mirrors[d].rdev; + sector_t addr; + if (rdev == NULL || +@@ -4415,7 +4425,7 @@ static int handle_reshape_read_error(struct mddev *mddev, + !test_bit(In_sync, &rdev->flags)) + goto failed; + +- addr = r10b.devs[slot].addr + idx * PAGE_SIZE; ++ addr = r10b->devs[slot].addr + idx * PAGE_SIZE; + success = sync_page_io(rdev, + addr, + s << 9, +diff --git a/drivers/md/raid10.h b/drivers/md/raid10.h +index 135b1b0..d2effe7 100644 +--- a/drivers/md/raid10.h ++++ b/drivers/md/raid10.h +@@ -110,7 +110,7 @@ struct r10bio { + * We choose the number when they are allocated. + * We sometimes need an extra bio to write to the replacement. + */ +- struct { ++ struct r10dev { + struct bio *bio; + union { + struct bio *repl_bio; /* used for resync and +diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c +index 04348d7..bcd096b 100644 +--- a/drivers/md/raid5.c ++++ b/drivers/md/raid5.c +@@ -380,6 +380,8 @@ static int calc_degraded(struct r5conf *conf) + degraded = 0; + for (i = 0; i < conf->previous_raid_disks; i++) { + struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); ++ if (rdev && test_bit(Faulty, &rdev->flags)) ++ rdev = rcu_dereference(conf->disks[i].replacement); + if (!rdev || test_bit(Faulty, &rdev->flags)) + degraded++; + else if (test_bit(In_sync, &rdev->flags)) +@@ -404,6 +406,8 @@ static int calc_degraded(struct r5conf *conf) + degraded2 = 0; + for (i = 0; i < conf->raid_disks; i++) { + struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); ++ if (rdev && test_bit(Faulty, &rdev->flags)) ++ rdev = rcu_dereference(conf->disks[i].replacement); + if (!rdev || test_bit(Faulty, &rdev->flags)) + degraded2++; + else if (test_bit(In_sync, &rdev->flags)) +diff --git a/drivers/media/dvb/siano/smsusb.c b/drivers/media/dvb/siano/smsusb.c +index 664e460..aac6222 100644 +--- a/drivers/media/dvb/siano/smsusb.c ++++ b/drivers/media/dvb/siano/smsusb.c +@@ -481,7 +481,7 @@ static int smsusb_resume(struct usb_interface *intf) + return 0; + } + +-static const struct usb_device_id smsusb_id_table[] __devinitconst = { ++static const struct usb_device_id smsusb_id_table[] = { + { USB_DEVICE(0x187f, 0x0010), + .driver_info = SMS1XXX_BOARD_SIANO_STELLAR }, + { USB_DEVICE(0x187f, 0x0100), +diff --git a/drivers/media/rc/ene_ir.c b/drivers/media/rc/ene_ir.c +index bef5296..647dd95 100644 +--- a/drivers/media/rc/ene_ir.c ++++ b/drivers/media/rc/ene_ir.c +@@ -1018,6 +1018,8 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) + + spin_lock_init(&dev->hw_lock); + ++ dev->hw_io = pnp_port_start(pnp_dev, 0); ++ + pnp_set_drvdata(pnp_dev, dev); + dev->pnp_dev = pnp_dev; + +@@ -1072,7 +1074,6 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) + + /* claim the resources */ + error = -EBUSY; +- dev->hw_io = pnp_port_start(pnp_dev, 0); + if (!request_region(dev->hw_io, ENE_IO_SIZE, ENE_DRIVER_NAME)) { + dev->hw_io = -1; + dev->irq = -1; +diff --git a/drivers/media/rc/ite-cir.c b/drivers/media/rc/ite-cir.c +index 36fe5a3..24c77a4 100644 +--- a/drivers/media/rc/ite-cir.c ++++ b/drivers/media/rc/ite-cir.c +@@ -1473,6 +1473,7 @@ static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id + rdev = rc_allocate_device(); + if (!rdev) + goto failure; ++ itdev->rdev = rdev; + + ret = -ENODEV; + +@@ -1604,7 +1605,6 @@ static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id + if (ret) + goto failure3; + +- itdev->rdev = rdev; + ite_pr(KERN_NOTICE, "driver has been successfully loaded\n"); + + return 0; +diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c +index 6e16b09..cabc19c 100644 +--- a/drivers/media/rc/rc-main.c ++++ b/drivers/media/rc/rc-main.c +@@ -775,10 +775,11 @@ static ssize_t show_protocols(struct device *device, + if (dev->driver_type == RC_DRIVER_SCANCODE) { + enabled = dev->rc_map.rc_type; + allowed = dev->allowed_protos; +- } else { ++ } else if (dev->raw) { + enabled = dev->raw->enabled_protocols; + allowed = ir_raw_get_allowed_protocols(); +- } ++ } else ++ return -ENODEV; + + IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n", + (long long)allowed, +diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c +index 862c657..9c65a54 100644 +--- a/drivers/media/video/em28xx/em28xx-cards.c ++++ b/drivers/media/video/em28xx/em28xx-cards.c +@@ -2880,12 +2880,20 @@ static void em28xx_card_setup(struct em28xx *dev) + } + + +-#if defined(CONFIG_MODULES) && defined(MODULE) + static void request_module_async(struct work_struct *work) + { + struct em28xx *dev = container_of(work, + struct em28xx, request_module_wk); + ++ /* ++ * The em28xx extensions can be modules or builtin. If the ++ * modules are already loaded or are built in, those extensions ++ * can be initialised right now. Otherwise, the module init ++ * code will do it. ++ */ ++ em28xx_init_extension(dev); ++ ++#if defined(CONFIG_MODULES) && defined(MODULE) + if (dev->has_audio_class) + request_module("snd-usb-audio"); + else if (dev->has_alsa_audio) +@@ -2895,6 +2903,7 @@ static void request_module_async(struct work_struct *work) + request_module("em28xx-dvb"); + if (dev->board.ir_codes && !disable_ir) + request_module("em28xx-rc"); ++#endif /* CONFIG_MODULES */ + } + + static void request_modules(struct em28xx *dev) +@@ -2907,10 +2916,6 @@ static void flush_request_modules(struct em28xx *dev) + { + flush_work_sync(&dev->request_module_wk); + } +-#else +-#define request_modules(dev) +-#define flush_request_modules(dev) +-#endif /* CONFIG_MODULES */ + + /* + * em28xx_release_resources() +@@ -3329,13 +3334,6 @@ static int em28xx_usb_probe(struct usb_interface *interface, + */ + mutex_unlock(&dev->lock); + +- /* +- * These extensions can be modules. If the modules are already +- * loaded then we can initialise the device now, otherwise we +- * will initialise it when the modules load instead. +- */ +- em28xx_init_extension(dev); +- + return 0; + + unlock_and_free: +diff --git a/drivers/media/video/gspca/jl2005bcd.c b/drivers/media/video/gspca/jl2005bcd.c +index 9c591c7..33e5d1f 100644 +--- a/drivers/media/video/gspca/jl2005bcd.c ++++ b/drivers/media/video/gspca/jl2005bcd.c +@@ -514,7 +514,7 @@ static const struct sd_desc sd_desc = { + }; + + /* -- module initialisation -- */ +-static const __devinitdata struct usb_device_id device_table[] = { ++static const struct usb_device_id device_table[] = { + {USB_DEVICE(0x0979, 0x0227)}, + {} + }; +diff --git a/drivers/media/video/gspca/pac7302.c b/drivers/media/video/gspca/pac7302.c +index a0369a5..97c2e59 100644 +--- a/drivers/media/video/gspca/pac7302.c ++++ b/drivers/media/video/gspca/pac7302.c +@@ -978,6 +978,7 @@ static const struct usb_device_id device_table[] = { + {USB_DEVICE(0x093a, 0x262a)}, + {USB_DEVICE(0x093a, 0x262c)}, + {USB_DEVICE(0x145f, 0x013c)}, ++ {USB_DEVICE(0x1ae7, 0x2001)}, /* SpeedLink Snappy Mic SL-6825-SBK */ + {} + }; + MODULE_DEVICE_TABLE(usb, device_table); +diff --git a/drivers/media/video/gspca/spca506.c b/drivers/media/video/gspca/spca506.c +index 54eed87..21e6a37 100644 +--- a/drivers/media/video/gspca/spca506.c ++++ b/drivers/media/video/gspca/spca506.c +@@ -685,7 +685,7 @@ static const struct sd_desc sd_desc = { + }; + + /* -- module initialisation -- */ +-static const struct usb_device_id device_table[] __devinitconst = { ++static const struct usb_device_id device_table[] = { + {USB_DEVICE(0x06e1, 0xa190)}, + /*fixme: may be IntelPCCameraPro BRIDGE_SPCA505 + {USB_DEVICE(0x0733, 0x0430)}, */ +diff --git a/drivers/media/video/m5mols/m5mols_controls.c b/drivers/media/video/m5mols/m5mols_controls.c +index 392a0287..fdbc205 100644 +--- a/drivers/media/video/m5mols/m5mols_controls.c ++++ b/drivers/media/video/m5mols/m5mols_controls.c +@@ -527,8 +527,8 @@ static const struct v4l2_ctrl_ops m5mols_ctrl_ops = { + + /* Supported manual ISO values */ + static const s64 iso_qmenu[] = { +- /* AE_ISO: 0x01...0x07 */ +- 50, 100, 200, 400, 800, 1600, 3200 ++ /* AE_ISO: 0x01...0x07 (ISO: 50...3200) */ ++ 50000, 100000, 200000, 400000, 800000, 1600000, 3200000 + }; + + /* Supported Exposure Bias values, -2.0EV...+2.0EV */ +diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c +index 9288fbd..5577381 100644 +--- a/drivers/media/video/uvc/uvc_queue.c ++++ b/drivers/media/video/uvc/uvc_queue.c +@@ -338,6 +338,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, + if ((queue->flags & UVC_QUEUE_DROP_CORRUPTED) && buf->error) { + buf->error = 0; + buf->state = UVC_BUF_STATE_QUEUED; ++ buf->bytesused = 0; + vb2_set_plane_payload(&buf->buf, 0, 0); + return buf; + } +diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c +index b6b5cc1..358f4c0 100644 +--- a/drivers/media/video/videobuf-dma-contig.c ++++ b/drivers/media/video/videobuf-dma-contig.c +@@ -359,32 +359,43 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q, + size = vma->vm_end - vma->vm_start; + size = (size < mem->size) ? size : mem->size; + +- if (!mem->cached) ++ if (!mem->cached) { + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); +- +- pos = (unsigned long)mem->vaddr; +- +- while (size > 0) { +- page = virt_to_page((void *)pos); +- if (NULL == page) { +- dev_err(q->dev, "mmap: virt_to_page failed\n"); +- __videobuf_dc_free(q->dev, mem); +- goto error; +- } +- retval = vm_insert_page(vma, start, page); ++ retval = remap_pfn_range(vma, vma->vm_start, ++ mem->dma_handle >> PAGE_SHIFT, ++ size, vma->vm_page_prot); + if (retval) { +- dev_err(q->dev, "mmap: insert failed with error %d\n", +- retval); +- __videobuf_dc_free(q->dev, mem); ++ dev_err(q->dev, "mmap: remap failed with error %d. ", ++ retval); ++ dma_free_coherent(q->dev, mem->size, ++ mem->vaddr, mem->dma_handle); + goto error; + } +- start += PAGE_SIZE; +- pos += PAGE_SIZE; ++ } else { ++ pos = (unsigned long)mem->vaddr; ++ ++ while (size > 0) { ++ page = virt_to_page((void *)pos); ++ if (NULL == page) { ++ dev_err(q->dev, "mmap: virt_to_page failed\n"); ++ __videobuf_dc_free(q->dev, mem); ++ goto error; ++ } ++ retval = vm_insert_page(vma, start, page); ++ if (retval) { ++ dev_err(q->dev, "mmap: insert failed with error %d\n", ++ retval); ++ __videobuf_dc_free(q->dev, mem); ++ goto error; ++ } ++ start += PAGE_SIZE; ++ pos += PAGE_SIZE; + +- if (size > PAGE_SIZE) +- size -= PAGE_SIZE; +- else +- size = 0; ++ if (size > PAGE_SIZE) ++ size -= PAGE_SIZE; ++ else ++ size = 0; ++ } + } + + vma->vm_ops = &videobuf_vm_ops; +diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c +index 1efad20..1287645 100644 +--- a/drivers/mfd/ab3100-core.c ++++ b/drivers/mfd/ab3100-core.c +@@ -409,8 +409,6 @@ static irqreturn_t ab3100_irq_handler(int irq, void *data) + u32 fatevent; + int err; + +- add_interrupt_randomness(irq); +- + err = ab3100_get_register_page_interruptible(ab3100, AB3100_EVENTA1, + event_regs, 3); + if (err) +@@ -933,9 +931,6 @@ static int __devinit ab3100_probe(struct i2c_client *client, + + err = request_threaded_irq(client->irq, NULL, ab3100_irq_handler, + IRQF_ONESHOT, "ab3100-core", ab3100); +- /* This real unpredictable IRQ is of course sampled for entropy */ +- rand_initialize_irq(client->irq); +- + if (err) + goto exit_no_irq; + +diff --git a/drivers/mfd/ezx-pcap.c b/drivers/mfd/ezx-pcap.c +index 43a76c4..db662e2 100644 +--- a/drivers/mfd/ezx-pcap.c ++++ b/drivers/mfd/ezx-pcap.c +@@ -202,7 +202,7 @@ static void pcap_isr_work(struct work_struct *work) + } + local_irq_enable(); + ezx_pcap_write(pcap, PCAP_REG_MSR, pcap->msr); +- } while (gpio_get_value(irq_to_gpio(pcap->spi->irq))); ++ } while (gpio_get_value(pdata->gpio)); + } + + static void pcap_irq_handler(unsigned int irq, struct irq_desc *desc) +diff --git a/drivers/mfd/max8925-core.c b/drivers/mfd/max8925-core.c +index ca881ef..746a59c 100644 +--- a/drivers/mfd/max8925-core.c ++++ b/drivers/mfd/max8925-core.c +@@ -18,12 +18,19 @@ + #include + #include + ++static struct resource io_parent = { ++ .start = 0, ++ .end = 0xffffffff, ++ .flags = IORESOURCE_IO, ++}; ++ + static struct resource backlight_resources[] = { + { + .name = "max8925-backlight", + .start = MAX8925_WLED_MODE_CNTL, + .end = MAX8925_WLED_CNTL, + .flags = IORESOURCE_IO, ++ .parent = &io_parent, + }, + }; + +@@ -42,6 +49,7 @@ static struct resource touch_resources[] = { + .start = MAX8925_TSC_IRQ, + .end = MAX8925_ADC_RES_END, + .flags = IORESOURCE_IO, ++ .parent = &io_parent, + }, + }; + +@@ -60,6 +68,7 @@ static struct resource power_supply_resources[] = { + .start = MAX8925_CHG_IRQ1, + .end = MAX8925_CHG_IRQ1_MASK, + .flags = IORESOURCE_IO, ++ .parent = &io_parent, + }, + }; + +@@ -118,6 +127,7 @@ static struct mfd_cell onkey_devs[] = { + .start = MAX8925_##_start, \ + .end = MAX8925_##_end, \ + .flags = IORESOURCE_IO, \ ++ .parent = &io_parent, \ + } + + static struct resource regulator_resources[] = { +diff --git a/drivers/mfd/wm831x-otp.c b/drivers/mfd/wm831x-otp.c +index f742745..b90f3e0 100644 +--- a/drivers/mfd/wm831x-otp.c ++++ b/drivers/mfd/wm831x-otp.c +@@ -18,6 +18,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -66,6 +67,7 @@ static DEVICE_ATTR(unique_id, 0444, wm831x_unique_id_show, NULL); + + int wm831x_otp_init(struct wm831x *wm831x) + { ++ char uuid[WM831X_UNIQUE_ID_LEN]; + int ret; + + ret = device_create_file(wm831x->dev, &dev_attr_unique_id); +@@ -73,6 +75,12 @@ int wm831x_otp_init(struct wm831x *wm831x) + dev_err(wm831x->dev, "Unique ID attribute not created: %d\n", + ret); + ++ ret = wm831x_unique_id_read(wm831x, uuid); ++ if (ret == 0) ++ add_device_randomness(uuid, sizeof(uuid)); ++ else ++ dev_err(wm831x->dev, "Failed to read UUID: %d\n", ret); ++ + return ret; + } + +diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c +index 87b251a..b9e2000 100644 +--- a/drivers/misc/sgi-xp/xpc_uv.c ++++ b/drivers/misc/sgi-xp/xpc_uv.c +@@ -18,6 +18,8 @@ + #include + #include + #include ++#include ++#include + #include + #include + #include +@@ -59,6 +61,8 @@ static struct xpc_heartbeat_uv *xpc_heartbeat_uv; + XPC_NOTIFY_MSG_SIZE_UV) + #define XPC_NOTIFY_IRQ_NAME "xpc_notify" + ++static int xpc_mq_node = -1; ++ + static struct xpc_gru_mq_uv *xpc_activate_mq_uv; + static struct xpc_gru_mq_uv *xpc_notify_mq_uv; + +@@ -109,11 +113,8 @@ xpc_get_gru_mq_irq_uv(struct xpc_gru_mq_uv *mq, int cpu, char *irq_name) + #if defined CONFIG_X86_64 + mq->irq = uv_setup_irq(irq_name, cpu, mq->mmr_blade, mq->mmr_offset, + UV_AFFINITY_CPU); +- if (mq->irq < 0) { +- dev_err(xpc_part, "uv_setup_irq() returned error=%d\n", +- -mq->irq); ++ if (mq->irq < 0) + return mq->irq; +- } + + mq->mmr_value = uv_read_global_mmr64(mmr_pnode, mq->mmr_offset); + +@@ -238,8 +239,9 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name, + mq->mmr_blade = uv_cpu_to_blade_id(cpu); + + nid = cpu_to_node(cpu); +- page = alloc_pages_exact_node(nid, GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, +- pg_order); ++ page = alloc_pages_exact_node(nid, ++ GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, ++ pg_order); + if (page == NULL) { + dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d " + "bytes of memory on nid=%d for GRU mq\n", mq_size, nid); +@@ -1731,9 +1733,50 @@ static struct xpc_arch_operations xpc_arch_ops_uv = { + .notify_senders_of_disconnect = xpc_notify_senders_of_disconnect_uv, + }; + ++static int ++xpc_init_mq_node(int nid) ++{ ++ int cpu; ++ ++ get_online_cpus(); ++ ++ for_each_cpu(cpu, cpumask_of_node(nid)) { ++ xpc_activate_mq_uv = ++ xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, nid, ++ XPC_ACTIVATE_IRQ_NAME, ++ xpc_handle_activate_IRQ_uv); ++ if (!IS_ERR(xpc_activate_mq_uv)) ++ break; ++ } ++ if (IS_ERR(xpc_activate_mq_uv)) { ++ put_online_cpus(); ++ return PTR_ERR(xpc_activate_mq_uv); ++ } ++ ++ for_each_cpu(cpu, cpumask_of_node(nid)) { ++ xpc_notify_mq_uv = ++ xpc_create_gru_mq_uv(XPC_NOTIFY_MQ_SIZE_UV, nid, ++ XPC_NOTIFY_IRQ_NAME, ++ xpc_handle_notify_IRQ_uv); ++ if (!IS_ERR(xpc_notify_mq_uv)) ++ break; ++ } ++ if (IS_ERR(xpc_notify_mq_uv)) { ++ xpc_destroy_gru_mq_uv(xpc_activate_mq_uv); ++ put_online_cpus(); ++ return PTR_ERR(xpc_notify_mq_uv); ++ } ++ ++ put_online_cpus(); ++ return 0; ++} ++ + int + xpc_init_uv(void) + { ++ int nid; ++ int ret = 0; ++ + xpc_arch_ops = xpc_arch_ops_uv; + + if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) { +@@ -1742,21 +1785,21 @@ xpc_init_uv(void) + return -E2BIG; + } + +- xpc_activate_mq_uv = xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, 0, +- XPC_ACTIVATE_IRQ_NAME, +- xpc_handle_activate_IRQ_uv); +- if (IS_ERR(xpc_activate_mq_uv)) +- return PTR_ERR(xpc_activate_mq_uv); ++ if (xpc_mq_node < 0) ++ for_each_online_node(nid) { ++ ret = xpc_init_mq_node(nid); + +- xpc_notify_mq_uv = xpc_create_gru_mq_uv(XPC_NOTIFY_MQ_SIZE_UV, 0, +- XPC_NOTIFY_IRQ_NAME, +- xpc_handle_notify_IRQ_uv); +- if (IS_ERR(xpc_notify_mq_uv)) { +- xpc_destroy_gru_mq_uv(xpc_activate_mq_uv); +- return PTR_ERR(xpc_notify_mq_uv); +- } ++ if (!ret) ++ break; ++ } ++ else ++ ret = xpc_init_mq_node(xpc_mq_node); + +- return 0; ++ if (ret < 0) ++ dev_err(xpc_part, "xpc_init_mq_node() returned error=%d\n", ++ -ret); ++ ++ return ret; + } + + void +@@ -1765,3 +1808,6 @@ xpc_exit_uv(void) + xpc_destroy_gru_mq_uv(xpc_notify_mq_uv); + xpc_destroy_gru_mq_uv(xpc_activate_mq_uv); + } ++ ++module_param(xpc_mq_node, int, 0); ++MODULE_PARM_DESC(xpc_mq_node, "Node number on which to allocate message queues."); +diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c +index 276d21c..7b66292 100644 +--- a/drivers/mmc/card/block.c ++++ b/drivers/mmc/card/block.c +@@ -1429,7 +1429,8 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) + /* complete ongoing async transfer before issuing discard */ + if (card->host->areq) + mmc_blk_issue_rw_rq(mq, NULL); +- if (req->cmd_flags & REQ_SECURE) ++ if (req->cmd_flags & REQ_SECURE && ++ !(card->quirks & MMC_QUIRK_SEC_ERASE_TRIM_BROKEN)) + ret = mmc_blk_issue_secdiscard_rq(mq, req); + else + ret = mmc_blk_issue_discard_rq(mq, req); +@@ -1734,6 +1735,7 @@ force_ro_fail: + #define CID_MANFID_SANDISK 0x2 + #define CID_MANFID_TOSHIBA 0x11 + #define CID_MANFID_MICRON 0x13 ++#define CID_MANFID_SAMSUNG 0x15 + + static const struct mmc_fixup blk_fixups[] = + { +@@ -1770,6 +1772,28 @@ static const struct mmc_fixup blk_fixups[] = + MMC_FIXUP(CID_NAME_ANY, CID_MANFID_MICRON, 0x200, add_quirk_mmc, + MMC_QUIRK_LONG_READ_TIME), + ++ /* ++ * On these Samsung MoviNAND parts, performing secure erase or ++ * secure trim can result in unrecoverable corruption due to a ++ * firmware bug. ++ */ ++ MMC_FIXUP("M8G2FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, ++ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), ++ MMC_FIXUP("MAG4FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, ++ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), ++ MMC_FIXUP("MBG8FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, ++ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), ++ MMC_FIXUP("MCGAFA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, ++ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), ++ MMC_FIXUP("VAL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, ++ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), ++ MMC_FIXUP("VYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, ++ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), ++ MMC_FIXUP("KYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, ++ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), ++ MMC_FIXUP("VZL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, ++ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), ++ + END_FIXUP + }; + +diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c +index f2c115e..1a69c63 100644 +--- a/drivers/mmc/host/atmel-mci.c ++++ b/drivers/mmc/host/atmel-mci.c +@@ -81,6 +81,7 @@ struct atmel_mci_caps { + bool has_bad_data_ordering; + bool need_reset_after_xfer; + bool need_blksz_mul_4; ++ bool need_notbusy_for_read_ops; + }; + + struct atmel_mci_dma { +@@ -1619,7 +1620,8 @@ static void atmci_tasklet_func(unsigned long priv) + __func__); + atmci_set_completed(host, EVENT_XFER_COMPLETE); + +- if (host->data->flags & MMC_DATA_WRITE) { ++ if (host->caps.need_notbusy_for_read_ops || ++ (host->data->flags & MMC_DATA_WRITE)) { + atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); + state = STATE_WAITING_NOTBUSY; + } else if (host->mrq->stop) { +@@ -2212,6 +2214,7 @@ static void __init atmci_get_cap(struct atmel_mci *host) + host->caps.has_bad_data_ordering = 1; + host->caps.need_reset_after_xfer = 1; + host->caps.need_blksz_mul_4 = 1; ++ host->caps.need_notbusy_for_read_ops = 0; + + /* keep only major version number */ + switch (version & 0xf00) { +@@ -2232,6 +2235,7 @@ static void __init atmci_get_cap(struct atmel_mci *host) + case 0x200: + host->caps.has_rwproof = 1; + host->caps.need_blksz_mul_4 = 0; ++ host->caps.need_notbusy_for_read_ops = 1; + case 0x100: + host->caps.has_bad_data_ordering = 0; + host->caps.need_reset_after_xfer = 0; +diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c +index 277161d..e1fd2c8 100644 +--- a/drivers/mmc/host/mxs-mmc.c ++++ b/drivers/mmc/host/mxs-mmc.c +@@ -278,11 +278,11 @@ static irqreturn_t mxs_mmc_irq_handler(int irq, void *dev_id) + writel(stat & MXS_MMC_IRQ_BITS, + host->base + HW_SSP_CTRL1(host) + STMP_OFFSET_REG_CLR); + ++ spin_unlock(&host->lock); ++ + if ((stat & BM_SSP_CTRL1_SDIO_IRQ) && (stat & BM_SSP_CTRL1_SDIO_IRQ_EN)) + mmc_signal_sdio_irq(host->mmc); + +- spin_unlock(&host->lock); +- + if (stat & BM_SSP_CTRL1_RESP_TIMEOUT_IRQ) + cmd->error = -ETIMEDOUT; + else if (stat & BM_SSP_CTRL1_RESP_ERR_IRQ) +@@ -637,11 +637,6 @@ static void mxs_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable) + host->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); + writel(BM_SSP_CTRL1_SDIO_IRQ_EN, + host->base + HW_SSP_CTRL1(host) + STMP_OFFSET_REG_SET); +- +- if (readl(host->base + HW_SSP_STATUS(host)) & +- BM_SSP_STATUS_SDIO_IRQ) +- mmc_signal_sdio_irq(host->mmc); +- + } else { + writel(BM_SSP_CTRL0_SDIO_IRQ_CHECK, + host->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR); +@@ -650,6 +645,11 @@ static void mxs_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable) + } + + spin_unlock_irqrestore(&host->lock, flags); ++ ++ if (enable && readl(host->base + HW_SSP_STATUS(host)) & ++ BM_SSP_STATUS_SDIO_IRQ) ++ mmc_signal_sdio_irq(host->mmc); ++ + } + + static const struct mmc_host_ops mxs_mmc_ops = { +diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c +index 389a3ee..c4de776 100644 +--- a/drivers/mmc/host/omap_hsmmc.c ++++ b/drivers/mmc/host/omap_hsmmc.c +@@ -2102,8 +2102,7 @@ static int omap_hsmmc_suspend(struct device *dev) + if (ret) { + host->suspended = 0; + if (host->pdata->resume) { +- ret = host->pdata->resume(dev, host->slot_id); +- if (ret) ++ if (host->pdata->resume(dev, host->slot_id)) + dev_dbg(dev, "Unmask interrupt failed\n"); + } + goto err; +diff --git a/drivers/mmc/host/sdhci-esdhc.h b/drivers/mmc/host/sdhci-esdhc.h +index b97b2f5..d25f9ab 100644 +--- a/drivers/mmc/host/sdhci-esdhc.h ++++ b/drivers/mmc/host/sdhci-esdhc.h +@@ -48,14 +48,14 @@ static inline void esdhc_set_clock(struct sdhci_host *host, unsigned int clock) + int div = 1; + u32 temp; + ++ if (clock == 0) ++ goto out; ++ + temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); + temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN + | ESDHC_CLOCK_MASK); + sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); + +- if (clock == 0) +- goto out; +- + while (host->max_clk / pre_div / 16 > clock && pre_div < 256) + pre_div *= 2; + +diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c +index 69ef0be..504da715 100644 +--- a/drivers/mmc/host/sdhci-pci.c ++++ b/drivers/mmc/host/sdhci-pci.c +@@ -157,6 +157,7 @@ static const struct sdhci_pci_fixes sdhci_ene_714 = { + 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 --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c +index e0688fb..4d46968 100644 +--- a/drivers/mmc/host/sdhci.c ++++ b/drivers/mmc/host/sdhci.c +@@ -27,6 +27,7 @@ + + #include + #include ++#include + + #include "sdhci.h" + +@@ -1245,6 +1246,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) + struct sdhci_host *host; + bool present; + unsigned long flags; ++ u32 tuning_opcode; + + host = mmc_priv(mmc); + +@@ -1292,8 +1294,12 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) + */ + if ((host->flags & SDHCI_NEEDS_RETUNING) && + !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) { ++ /* eMMC uses cmd21 while sd and sdio use cmd19 */ ++ tuning_opcode = mmc->card->type == MMC_TYPE_MMC ? ++ MMC_SEND_TUNING_BLOCK_HS200 : ++ MMC_SEND_TUNING_BLOCK; + spin_unlock_irqrestore(&host->lock, flags); +- sdhci_execute_tuning(mmc, mrq->cmd->opcode); ++ sdhci_execute_tuning(mmc, tuning_opcode); + spin_lock_irqsave(&host->lock, flags); + + /* Restore original mmc_request structure */ +diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c +index 724b35e..3b8236b 100644 +--- a/drivers/mmc/host/sh_mmcif.c ++++ b/drivers/mmc/host/sh_mmcif.c +@@ -1191,6 +1191,10 @@ static irqreturn_t sh_mmcif_intr(int irq, void *dev_id) + host->sd_error = true; + dev_dbg(&host->pd->dev, "int err state = %08x\n", state); + } ++ if (host->state == STATE_IDLE) { ++ dev_info(&host->pd->dev, "Spurious IRQ status 0x%x", state); ++ return IRQ_HANDLED; ++ } + if (state & ~(INT_CMD12RBE | INT_CMD12CRE)) { + if (!host->dma_active) + return IRQ_WAKE_THREAD; +diff --git a/drivers/mtd/maps/autcpu12-nvram.c b/drivers/mtd/maps/autcpu12-nvram.c +index e5bfd0e..0598d52 100644 +--- a/drivers/mtd/maps/autcpu12-nvram.c ++++ b/drivers/mtd/maps/autcpu12-nvram.c +@@ -43,7 +43,8 @@ struct map_info autcpu12_sram_map = { + + static int __init init_autcpu12_sram (void) + { +- int err, save0, save1; ++ map_word tmp, save0, save1; ++ int err; + + autcpu12_sram_map.virt = ioremap(0x12000000, SZ_128K); + if (!autcpu12_sram_map.virt) { +@@ -51,7 +52,7 @@ static int __init init_autcpu12_sram (void) + err = -EIO; + goto out; + } +- simple_map_init(&autcpu_sram_map); ++ simple_map_init(&autcpu12_sram_map); + + /* + * Check for 32K/128K +@@ -61,20 +62,22 @@ static int __init init_autcpu12_sram (void) + * Read and check result on ofs 0x0 + * Restore contents + */ +- save0 = map_read32(&autcpu12_sram_map,0); +- save1 = map_read32(&autcpu12_sram_map,0x10000); +- map_write32(&autcpu12_sram_map,~save0,0x10000); ++ save0 = map_read(&autcpu12_sram_map, 0); ++ save1 = map_read(&autcpu12_sram_map, 0x10000); ++ tmp.x[0] = ~save0.x[0]; ++ map_write(&autcpu12_sram_map, tmp, 0x10000); + /* if we find this pattern on 0x0, we have 32K size + * restore contents and exit + */ +- if ( map_read32(&autcpu12_sram_map,0) != save0) { +- map_write32(&autcpu12_sram_map,save0,0x0); ++ tmp = map_read(&autcpu12_sram_map, 0); ++ if (!map_word_equal(&autcpu12_sram_map, tmp, save0)) { ++ map_write(&autcpu12_sram_map, save0, 0x0); + goto map; + } + /* We have a 128K found, restore 0x10000 and set size + * to 128K + */ +- map_write32(&autcpu12_sram_map,save1,0x10000); ++ map_write(&autcpu12_sram_map, save1, 0x10000); + autcpu12_sram_map.size = SZ_128K; + + map: +diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c +index d518e4d..f8c08ec 100644 +--- a/drivers/mtd/mtdpart.c ++++ b/drivers/mtd/mtdpart.c +@@ -711,6 +711,8 @@ static const char *default_mtd_part_types[] = { + * partition parsers, specified in @types. However, if @types is %NULL, then + * the default list of parsers is used. The default list contains only the + * "cmdlinepart" and "ofpart" parsers ATM. ++ * Note: If there are more then one parser in @types, the kernel only takes the ++ * partitions parsed out by the first parser. + * + * This function may return: + * o a negative error code in case of failure +@@ -735,11 +737,12 @@ int parse_mtd_partitions(struct mtd_info *master, const char **types, + if (!parser) + continue; + ret = (*parser->parse_fn)(master, pparts, data); ++ put_partition_parser(parser); + if (ret > 0) { + printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", + ret, parser->name, master->name); ++ break; + } +- put_partition_parser(parser); + } + return ret; + } +diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c +index 30d1319..c126469 100644 +--- a/drivers/mtd/nand/nand_bbt.c ++++ b/drivers/mtd/nand/nand_bbt.c +@@ -390,7 +390,7 @@ static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, + /* Read the mirror version, if available */ + if (md && (md->options & NAND_BBT_VERSION)) { + scan_read_raw(mtd, buf, (loff_t)md->pages[0] << this->page_shift, +- mtd->writesize, td); ++ mtd->writesize, md); + md->version[0] = buf[bbt_get_ver_offs(mtd, md)]; + pr_info("Bad block table at page %d, version 0x%02X\n", + md->pages[0], md->version[0]); +diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c +index cf0cd31..5d8811809 100644 +--- a/drivers/mtd/nand/nandsim.c ++++ b/drivers/mtd/nand/nandsim.c +@@ -2333,6 +2333,7 @@ static int __init ns_init_module(void) + uint64_t new_size = (uint64_t)nsmtd->erasesize << overridesize; + if (new_size >> overridesize != nsmtd->erasesize) { + NS_ERR("overridesize is too big\n"); ++ retval = -EINVAL; + goto err_exit; + } + /* N.B. This relies on nand_scan not doing anything with the size before we change it */ +diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c +index d7f681d..a7e0c8f 100644 +--- a/drivers/mtd/nand/omap2.c ++++ b/drivers/mtd/nand/omap2.c +@@ -1382,7 +1382,8 @@ static int omap_nand_remove(struct platform_device *pdev) + /* Release NAND device, its internal structures and partitions */ + nand_release(&info->mtd); + iounmap(info->nand.IO_ADDR_R); +- kfree(&info->mtd); ++ release_mem_region(info->phys_base, NAND_IO_SIZE); ++ kfree(info); + return 0; + } + +diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c +index bd27cbb..68d4d1f 100644 +--- a/drivers/mtd/ubi/attach.c ++++ b/drivers/mtd/ubi/attach.c +@@ -975,7 +975,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, + return err; + goto adjust_mean_ec; + case UBI_IO_FF: +- if (ec_err) ++ if (ec_err || bitflips) + err = add_to_list(ai, pnum, UBI_UNKNOWN, + UBI_UNKNOWN, ec, 1, &ai->erase); + else +diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c +index 2c5ed5c..da052ed 100644 +--- a/drivers/mtd/ubi/build.c ++++ b/drivers/mtd/ubi/build.c +@@ -759,6 +759,11 @@ static int autoresize(struct ubi_device *ubi, int vol_id) + struct ubi_volume *vol = ubi->volumes[vol_id]; + int err, old_reserved_pebs = vol->reserved_pebs; + ++ if (ubi->ro_mode) { ++ ubi_warn("skip auto-resize because of R/O mode"); ++ return 0; ++ } ++ + /* + * Clear the auto-resize flag in the volume in-memory copy of the + * volume table, and 'ubi_resize_volume()' will propagate this change +diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c +index 437bc19..568307c 100644 +--- a/drivers/mtd/ubi/vtbl.c ++++ b/drivers/mtd/ubi/vtbl.c +@@ -340,7 +340,7 @@ retry: + * of this LEB as it will be deleted and freed in 'ubi_add_to_av()'. + */ + err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0); +- kfree(new_aeb); ++ kmem_cache_free(ai->aeb_slab_cache, new_aeb); + ubi_free_vid_hdr(ubi, vid_hdr); + return err; + +@@ -353,7 +353,7 @@ write_error: + list_add(&new_aeb->u.list, &ai->erase); + goto retry; + } +- kfree(new_aeb); ++ kmem_cache_free(ai->aeb_slab_cache, new_aeb); + out_free: + ubi_free_vid_hdr(ubi, vid_hdr); + return err; +diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c +index 8a3054b..5de74e7 100644 +--- a/drivers/net/caif/caif_serial.c ++++ b/drivers/net/caif/caif_serial.c +@@ -325,6 +325,9 @@ static int ldisc_open(struct tty_struct *tty) + + 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 --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c +index 08c893c..e7823dd 100644 +--- a/drivers/net/can/janz-ican3.c ++++ b/drivers/net/can/janz-ican3.c +@@ -1250,7 +1250,6 @@ static irqreturn_t ican3_irq(int irq, void *dev_id) + */ + static int ican3_reset_module(struct ican3_dev *mod) + { +- u8 val = 1 << mod->num; + unsigned long start; + u8 runold, runnew; + +@@ -1264,8 +1263,7 @@ static int ican3_reset_module(struct ican3_dev *mod) + runold = ioread8(mod->dpm + TARGET_RUNNING); + + /* reset the module */ +- iowrite8(val, &mod->ctrl->reset_assert); +- iowrite8(val, &mod->ctrl->reset_deassert); ++ iowrite8(0x00, &mod->dpmctrl->hwreset); + + /* wait until the module has finished resetting and is running */ + start = jiffies; +diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c +index 346785c..9d60742 100644 +--- a/drivers/net/can/mcp251x.c ++++ b/drivers/net/can/mcp251x.c +@@ -83,6 +83,11 @@ + #define INSTRUCTION_LOAD_TXB(n) (0x40 + 2 * (n)) + #define INSTRUCTION_READ_RXB(n) (((n) == 0) ? 0x90 : 0x94) + #define INSTRUCTION_RESET 0xC0 ++#define RTS_TXB0 0x01 ++#define RTS_TXB1 0x02 ++#define RTS_TXB2 0x04 ++#define INSTRUCTION_RTS(n) (0x80 | ((n) & 0x07)) ++ + + /* MPC251x registers */ + #define CANSTAT 0x0e +@@ -397,6 +402,7 @@ static void mcp251x_hw_tx_frame(struct spi_device *spi, u8 *buf, + static void mcp251x_hw_tx(struct spi_device *spi, struct can_frame *frame, + int tx_buf_idx) + { ++ struct mcp251x_priv *priv = dev_get_drvdata(&spi->dev); + u32 sid, eid, exide, rtr; + u8 buf[SPI_TRANSFER_BUF_LEN]; + +@@ -418,7 +424,10 @@ static void mcp251x_hw_tx(struct spi_device *spi, struct can_frame *frame, + buf[TXBDLC_OFF] = (rtr << DLC_RTR_SHIFT) | frame->can_dlc; + memcpy(buf + TXBDAT_OFF, frame->data, frame->can_dlc); + mcp251x_hw_tx_frame(spi, buf, frame->can_dlc, tx_buf_idx); +- mcp251x_write_reg(spi, TXBCTRL(tx_buf_idx), TXBCTRL_TXREQ); ++ ++ /* use INSTRUCTION_RTS, to avoid "repeated frame problem" */ ++ priv->spi_tx_buf[0] = INSTRUCTION_RTS(1 << tx_buf_idx); ++ mcp251x_spi_trans(priv->spi, 1); + } + + static void mcp251x_hw_rx_frame(struct spi_device *spi, u8 *buf, +diff --git a/drivers/net/can/mscan/mpc5xxx_can.c b/drivers/net/can/mscan/mpc5xxx_can.c +index 5caa572..957f000 100644 +--- a/drivers/net/can/mscan/mpc5xxx_can.c ++++ b/drivers/net/can/mscan/mpc5xxx_can.c +@@ -181,7 +181,7 @@ static u32 __devinit mpc512x_can_get_clock(struct platform_device *ofdev, + + if (!clock_name || !strcmp(clock_name, "sys")) { + sys_clk = clk_get(&ofdev->dev, "sys_clk"); +- if (!sys_clk) { ++ if (IS_ERR(sys_clk)) { + dev_err(&ofdev->dev, "couldn't get sys_clk\n"); + goto exit_unmap; + } +@@ -204,7 +204,7 @@ static u32 __devinit mpc512x_can_get_clock(struct platform_device *ofdev, + + if (clocksrc < 0) { + ref_clk = clk_get(&ofdev->dev, "ref_clk"); +- if (!ref_clk) { ++ if (IS_ERR(ref_clk)) { + dev_err(&ofdev->dev, "couldn't get ref_clk\n"); + goto exit_unmap; + } +diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c +index 4accd7e..5ec2700 100644 +--- a/drivers/net/can/ti_hecc.c ++++ b/drivers/net/can/ti_hecc.c +@@ -984,12 +984,12 @@ static int __devexit ti_hecc_remove(struct platform_device *pdev) + struct net_device *ndev = platform_get_drvdata(pdev); + struct ti_hecc_priv *priv = netdev_priv(ndev); + ++ unregister_candev(ndev); + clk_disable(priv->clk); + clk_put(priv->clk); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + iounmap(priv->base); + release_mem_region(res->start, resource_size(res)); +- unregister_candev(ndev); + free_candev(ndev); + platform_set_drvdata(pdev, NULL); + +diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_hw.h b/drivers/net/ethernet/atheros/atl1c/atl1c_hw.h +index 17d935b..21d8c4d 100644 +--- a/drivers/net/ethernet/atheros/atl1c/atl1c_hw.h ++++ b/drivers/net/ethernet/atheros/atl1c/atl1c_hw.h +@@ -74,6 +74,8 @@ void atl1c_post_phy_linkchg(struct atl1c_hw *hw, u16 link_speed); + #define PCI_DEVICE_ID_ATHEROS_L1D_2_0 0x1083 /* AR8151 v2.0 Gigabit 1000 */ + #define L2CB_V10 0xc0 + #define L2CB_V11 0xc1 ++#define L2CB_V20 0xc0 ++#define L2CB_V21 0xc1 + + /* register definition */ + #define REG_DEVICE_CAP 0x5C +@@ -87,6 +89,9 @@ void atl1c_post_phy_linkchg(struct atl1c_hw *hw, u16 link_speed); + #define LINK_CTRL_L1_EN 0x02 + #define LINK_CTRL_EXT_SYNC 0x80 + ++#define REG_PCIE_IND_ACC_ADDR 0x80 ++#define REG_PCIE_IND_ACC_DATA 0x84 ++ + #define REG_DEV_SERIALNUM_CTRL 0x200 + #define REG_DEV_MAC_SEL_MASK 0x0 /* 0:EUI; 1:MAC */ + #define REG_DEV_MAC_SEL_SHIFT 0 +diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c +index 1f78b63..f602623f 100644 +--- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c ++++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c +@@ -739,6 +739,8 @@ static const struct atl1c_platform_patch plats[] __devinitdata = { + + static void __devinit atl1c_patch_assign(struct atl1c_hw *hw) + { ++ struct pci_dev *pdev = hw->adapter->pdev; ++ u32 misc_ctrl; + int i = 0; + + hw->msi_lnkpatch = false; +@@ -753,6 +755,18 @@ static void __devinit atl1c_patch_assign(struct atl1c_hw *hw) + } + i++; + } ++ ++ if (hw->device_id == PCI_DEVICE_ID_ATHEROS_L2C_B2 && ++ hw->revision_id == L2CB_V21) { ++ /* config acess mode */ ++ pci_write_config_dword(pdev, REG_PCIE_IND_ACC_ADDR, ++ REG_PCIE_DEV_MISC_CTRL); ++ pci_read_config_dword(pdev, REG_PCIE_IND_ACC_DATA, &misc_ctrl); ++ misc_ctrl &= ~0x100; ++ pci_write_config_dword(pdev, REG_PCIE_IND_ACC_ADDR, ++ REG_PCIE_DEV_MISC_CTRL); ++ pci_write_config_dword(pdev, REG_PCIE_IND_ACC_DATA, misc_ctrl); ++ } + } + /* + * atl1c_sw_init - Initialize general software structures (struct atl1c_adapter) +@@ -780,7 +794,7 @@ static int __devinit atl1c_sw_init(struct atl1c_adapter *adapter) + hw->device_id = pdev->device; + hw->subsystem_vendor_id = pdev->subsystem_vendor; + hw->subsystem_id = pdev->subsystem_device; +- AT_READ_REG(hw, PCI_CLASS_REVISION, &revision); ++ pci_read_config_dword(pdev, PCI_CLASS_REVISION, &revision); + hw->revision_id = revision & 0xFF; + /* before link up, we assume hibernate is true */ + hw->hibernate = true; +diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +index 8098eea..2364f66 100644 +--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c ++++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +@@ -620,14 +620,16 @@ static int bnx2x_alloc_rx_data(struct bnx2x *bp, + static void bnx2x_csum_validate(struct sk_buff *skb, union eth_rx_cqe *cqe, + struct bnx2x_fastpath *fp) + { +- /* Do nothing if no IP/L4 csum validation was done */ +- ++ /* Do nothing if no L4 csum validation was done. ++ * We do not check whether IP csum was validated. For IPv4 we assume ++ * that if the card got as far as validating the L4 csum, it also ++ * validated the IP csum. IPv6 has no IP csum. ++ */ + if (cqe->fast_path_cqe.status_flags & +- (ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG | +- ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG)) ++ ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG) + return; + +- /* If both IP/L4 validation were done, check if an error was found. */ ++ /* If L4 validation was done, check if an error was found. */ + + if (cqe->fast_path_cqe.type_error_flags & + (ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG | +diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c +index e47ff8b..15f8b00 100644 +--- a/drivers/net/ethernet/broadcom/tg3.c ++++ b/drivers/net/ethernet/broadcom/tg3.c +@@ -298,6 +298,7 @@ static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { + {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, + {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, + {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, ++ {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57762)}, + {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, + {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, + {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, +@@ -8974,8 +8975,7 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy) + GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || + tg3_flag(tp, 57765_PLUS)) { + val = tr32(TG3_RDMA_RSRVCTRL_REG); +- if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || +- GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { ++ if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0) { + val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | + TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | + TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); +@@ -12282,10 +12282,12 @@ static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, + { + struct tg3 *tp = netdev_priv(dev); + +- if (!tp->hw_stats) ++ spin_lock_bh(&tp->lock); ++ if (!tp->hw_stats) { ++ spin_unlock_bh(&tp->lock); + return &tp->net_stats_prev; ++ } + +- spin_lock_bh(&tp->lock); + tg3_get_nstats(tp, stats); + spin_unlock_bh(&tp->lock); + +diff --git a/drivers/net/ethernet/cirrus/cs89x0.c b/drivers/net/ethernet/cirrus/cs89x0.c +index 845b202..1384469 100644 +--- a/drivers/net/ethernet/cirrus/cs89x0.c ++++ b/drivers/net/ethernet/cirrus/cs89x0.c +@@ -1243,6 +1243,7 @@ static void set_multicast_list(struct net_device *dev) + { + struct net_local *lp = netdev_priv(dev); + unsigned long flags; ++ u16 cfg; + + spin_lock_irqsave(&lp->lock, flags); + if (dev->flags & IFF_PROMISC) +@@ -1260,11 +1261,10 @@ static void set_multicast_list(struct net_device *dev) + /* in promiscuous mode, we accept errored packets, + * so we have to enable interrupts on them also + */ +- writereg(dev, PP_RxCFG, +- (lp->curr_rx_cfg | +- (lp->rx_mode == RX_ALL_ACCEPT) +- ? (RX_CRC_ERROR_ENBL | RX_RUNT_ENBL | RX_EXTRA_DATA_ENBL) +- : 0)); ++ cfg = lp->curr_rx_cfg; ++ if (lp->rx_mode == RX_ALL_ACCEPT) ++ cfg |= RX_CRC_ERROR_ENBL | RX_RUNT_ENBL | RX_EXTRA_DATA_ENBL; ++ writereg(dev, PP_RxCFG, cfg); + spin_unlock_irqrestore(&lp->lock, flags); + } + +diff --git a/drivers/net/ethernet/emulex/benet/be_ethtool.c b/drivers/net/ethernet/emulex/benet/be_ethtool.c +index 63e51d4..59ee51a 100644 +--- a/drivers/net/ethernet/emulex/benet/be_ethtool.c ++++ b/drivers/net/ethernet/emulex/benet/be_ethtool.c +@@ -910,8 +910,9 @@ static void be_set_fw_log_level(struct be_adapter *adapter, u32 level) + if (!status) { + cfgs = (struct be_fat_conf_params *)(extfat_cmd.va + + sizeof(struct be_cmd_resp_hdr)); +- for (i = 0; i < cfgs->num_modules; i++) { +- for (j = 0; j < cfgs->module[i].num_modes; j++) { ++ for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) { ++ u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes); ++ for (j = 0; j < num_modes; j++) { + if (cfgs->module[i].trace_lvl[j].mode == + MODE_UART) + cfgs->module[i].trace_lvl[j].dbg_lvl = +diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c +index 501dfa9..bd5cf7e 100644 +--- a/drivers/net/ethernet/emulex/benet/be_main.c ++++ b/drivers/net/ethernet/emulex/benet/be_main.c +@@ -3479,7 +3479,7 @@ u32 be_get_fw_log_level(struct be_adapter *adapter) + if (!status) { + cfgs = (struct be_fat_conf_params *)(extfat_cmd.va + + sizeof(struct be_cmd_resp_hdr)); +- for (j = 0; j < cfgs->module[0].num_modes; j++) { ++ for (j = 0; j < le32_to_cpu(cfgs->module[0].num_modes); j++) { + if (cfgs->module[0].trace_lvl[j].mode == MODE_UART) + level = cfgs->module[0].trace_lvl[j].dbg_lvl; + } +diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c +index ab1d80f..7f0183e 100644 +--- a/drivers/net/ethernet/freescale/gianfar.c ++++ b/drivers/net/ethernet/freescale/gianfar.c +@@ -1037,7 +1037,7 @@ static int gfar_probe(struct platform_device *ofdev) + + if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) { + dev->hw_features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; +- dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; ++ dev->features |= NETIF_F_HW_VLAN_RX; + } + + if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) { +diff --git a/drivers/net/ethernet/freescale/gianfar_ethtool.c b/drivers/net/ethernet/freescale/gianfar_ethtool.c +index 8a02557..4ca75ee 100644 +--- a/drivers/net/ethernet/freescale/gianfar_ethtool.c ++++ b/drivers/net/ethernet/freescale/gianfar_ethtool.c +@@ -1741,6 +1741,7 @@ static int gfar_get_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd, + } + + int gfar_phc_index = -1; ++EXPORT_SYMBOL(gfar_phc_index); + + static int gfar_get_ts_info(struct net_device *dev, + struct ethtool_ts_info *info) +diff --git a/drivers/net/ethernet/freescale/gianfar_ptp.c b/drivers/net/ethernet/freescale/gianfar_ptp.c +index c08e5d4..0daa66b 100644 +--- a/drivers/net/ethernet/freescale/gianfar_ptp.c ++++ b/drivers/net/ethernet/freescale/gianfar_ptp.c +@@ -515,7 +515,7 @@ static int gianfar_ptp_probe(struct platform_device *dev) + err = PTR_ERR(etsects->clock); + goto no_clock; + } +- gfar_phc_clock = ptp_clock_index(etsects->clock); ++ gfar_phc_index = ptp_clock_index(etsects->clock); + + dev_set_drvdata(&dev->dev, etsects); + +@@ -539,7 +539,7 @@ static int gianfar_ptp_remove(struct platform_device *dev) + gfar_write(&etsects->regs->tmr_temask, 0); + gfar_write(&etsects->regs->tmr_ctrl, 0); + +- gfar_phc_clock = -1; ++ gfar_phc_index = -1; + ptp_clock_unregister(etsects->clock); + iounmap(etsects->regs); + release_resource(etsects->rsrc); +diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c +index 9010cea..b68d28a 100644 +--- a/drivers/net/ethernet/ibm/ibmveth.c ++++ b/drivers/net/ethernet/ibm/ibmveth.c +@@ -472,14 +472,9 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter) + } + + if (adapter->rx_queue.queue_addr != NULL) { +- if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) { +- dma_unmap_single(dev, +- adapter->rx_queue.queue_dma, +- adapter->rx_queue.queue_len, +- DMA_BIDIRECTIONAL); +- adapter->rx_queue.queue_dma = DMA_ERROR_CODE; +- } +- kfree(adapter->rx_queue.queue_addr); ++ dma_free_coherent(dev, adapter->rx_queue.queue_len, ++ adapter->rx_queue.queue_addr, ++ adapter->rx_queue.queue_dma); + adapter->rx_queue.queue_addr = NULL; + } + +@@ -556,10 +551,13 @@ static int ibmveth_open(struct net_device *netdev) + goto err_out; + } + ++ dev = &adapter->vdev->dev; ++ + adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * + rxq_entries; +- adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, +- GFP_KERNEL); ++ adapter->rx_queue.queue_addr = ++ dma_alloc_coherent(dev, adapter->rx_queue.queue_len, ++ &adapter->rx_queue.queue_dma, GFP_KERNEL); + + if (!adapter->rx_queue.queue_addr) { + netdev_err(netdev, "unable to allocate rx queue pages\n"); +@@ -567,19 +565,13 @@ static int ibmveth_open(struct net_device *netdev) + goto err_out; + } + +- dev = &adapter->vdev->dev; +- + adapter->buffer_list_dma = dma_map_single(dev, + adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL); + adapter->filter_list_dma = dma_map_single(dev, + adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL); +- adapter->rx_queue.queue_dma = dma_map_single(dev, +- adapter->rx_queue.queue_addr, +- adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL); + + if ((dma_mapping_error(dev, adapter->buffer_list_dma)) || +- (dma_mapping_error(dev, adapter->filter_list_dma)) || +- (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) { ++ (dma_mapping_error(dev, adapter->filter_list_dma))) { + netdev_err(netdev, "unable to map filter or buffer list " + "pages\n"); + rc = -ENOMEM; +diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c +index 1f063dc..b8e4fcb 100644 +--- a/drivers/net/ethernet/intel/e1000e/82571.c ++++ b/drivers/net/ethernet/intel/e1000e/82571.c +@@ -1601,10 +1601,8 @@ static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw) + * auto-negotiation in the TXCW register and disable + * forced link in the Device Control register in an + * attempt to auto-negotiate with our link partner. +- * If the partner code word is null, stop forcing +- * and restart auto negotiation. + */ +- if ((rxcw & E1000_RXCW_C) || !(rxcw & E1000_RXCW_CW)) { ++ if (rxcw & E1000_RXCW_C) { + /* Enable autoneg, and unforce link up */ + ew32(TXCW, mac->txcw); + ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); +diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h +index 6e6fffb..fa47b85 100644 +--- a/drivers/net/ethernet/intel/e1000e/e1000.h ++++ b/drivers/net/ethernet/intel/e1000e/e1000.h +@@ -310,6 +310,7 @@ struct e1000_adapter { + */ + struct e1000_ring *tx_ring /* One per active queue */ + ____cacheline_aligned_in_smp; ++ u32 tx_fifo_limit; + + struct napi_struct napi; + +diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c +index 623e30b..9bbfa1d 100644 +--- a/drivers/net/ethernet/intel/e1000e/netdev.c ++++ b/drivers/net/ethernet/intel/e1000e/netdev.c +@@ -3477,6 +3477,15 @@ void e1000e_reset(struct e1000_adapter *adapter) + } + + /* ++ * Alignment of Tx data is on an arbitrary byte boundary with the ++ * maximum size per Tx descriptor limited only to the transmit ++ * allocation of the packet buffer minus 96 bytes with an upper ++ * limit of 24KB due to receive synchronization limitations. ++ */ ++ adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96, ++ 24 << 10); ++ ++ /* + * Disable Adaptive Interrupt Moderation if 2 full packets cannot + * fit in receive buffer. + */ +@@ -4745,12 +4754,9 @@ static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb) + return 1; + } + +-#define E1000_MAX_PER_TXD 8192 +-#define E1000_MAX_TXD_PWR 12 +- + static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb, + unsigned int first, unsigned int max_per_txd, +- unsigned int nr_frags, unsigned int mss) ++ unsigned int nr_frags) + { + struct e1000_adapter *adapter = tx_ring->adapter; + struct pci_dev *pdev = adapter->pdev; +@@ -4983,20 +4989,19 @@ static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size) + + static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size) + { ++ BUG_ON(size > tx_ring->count); ++ + if (e1000_desc_unused(tx_ring) >= size) + return 0; + return __e1000_maybe_stop_tx(tx_ring, size); + } + +-#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1) + static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, + struct net_device *netdev) + { + struct e1000_adapter *adapter = netdev_priv(netdev); + struct e1000_ring *tx_ring = adapter->tx_ring; + unsigned int first; +- unsigned int max_per_txd = E1000_MAX_PER_TXD; +- unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; + unsigned int tx_flags = 0; + unsigned int len = skb_headlen(skb); + unsigned int nr_frags; +@@ -5016,18 +5021,8 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, + } + + mss = skb_shinfo(skb)->gso_size; +- /* +- * The controller does a simple calculation to +- * make sure there is enough room in the FIFO before +- * initiating the DMA for each buffer. The calc is: +- * 4 = ceil(buffer len/mss). To make sure we don't +- * overrun the FIFO, adjust the max buffer len if mss +- * drops. +- */ + if (mss) { + u8 hdr_len; +- max_per_txd = min(mss << 2, max_per_txd); +- max_txd_pwr = fls(max_per_txd) - 1; + + /* + * TSO Workaround for 82571/2/3 Controllers -- if skb->data +@@ -5057,12 +5052,12 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, + count++; + count++; + +- count += TXD_USE_COUNT(len, max_txd_pwr); ++ count += DIV_ROUND_UP(len, adapter->tx_fifo_limit); + + nr_frags = skb_shinfo(skb)->nr_frags; + for (f = 0; f < nr_frags; f++) +- count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]), +- max_txd_pwr); ++ count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]), ++ adapter->tx_fifo_limit); + + if (adapter->hw.mac.tx_pkt_filtering) + e1000_transfer_dhcp_info(adapter, skb); +@@ -5104,15 +5099,18 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, + tx_flags |= E1000_TX_FLAGS_NO_FCS; + + /* if count is 0 then mapping error has occurred */ +- count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss); ++ count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit, ++ nr_frags); + if (count) { + skb_tx_timestamp(skb); + + netdev_sent_queue(netdev, skb->len); + e1000_tx_queue(tx_ring, tx_flags, count); + /* Make sure there is space in the ring for the next send. */ +- e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2); +- ++ e1000_maybe_stop_tx(tx_ring, ++ (MAX_SKB_FRAGS * ++ DIV_ROUND_UP(PAGE_SIZE, ++ adapter->tx_fifo_limit) + 2)); + } else { + dev_kfree_skb_any(skb); + tx_ring->buffer_info[first].time_stamp = 0; +@@ -6284,8 +6282,8 @@ static int __devinit e1000_probe(struct pci_dev *pdev, + adapter->hw.phy.autoneg_advertised = 0x2f; + + /* ring size defaults */ +- adapter->rx_ring->count = 256; +- adapter->tx_ring->count = 256; ++ adapter->rx_ring->count = E1000_DEFAULT_RXD; ++ adapter->tx_ring->count = E1000_DEFAULT_TXD; + + /* + * Initial Wake on LAN setting - If APM wake is enabled in +diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +index 3178f1e..9b20170 100644 +--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c ++++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +@@ -2723,10 +2723,7 @@ static int ixgbe_get_ts_info(struct net_device *dev, + (1 << HWTSTAMP_FILTER_NONE) | + (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | + (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | +- (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) | +- (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | +- (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) | +- (1 << HWTSTAMP_FILTER_SOME); ++ (1 << HWTSTAMP_FILTER_PTP_V2_EVENT); + break; + #endif /* CONFIG_IXGBE_PTP */ + default: +diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c +index 342b3a7..a77c558 100644 +--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c ++++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c +@@ -1378,6 +1378,10 @@ static void netxen_mask_aer_correctable(struct netxen_adapter *adapter) + struct pci_dev *root = pdev->bus->self; + u32 aer_pos; + ++ /* root bus? */ ++ if (!root) ++ return; ++ + if (adapter->ahw.board_type != NETXEN_BRDTYPE_P3_4_GB_MM && + adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP) + return; +diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c +index d7a04e0..eb81da4 100644 +--- a/drivers/net/ethernet/realtek/r8169.c ++++ b/drivers/net/ethernet/realtek/r8169.c +@@ -5380,7 +5380,6 @@ static void rtl8169_tx_clear(struct rtl8169_private *tp) + { + rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); + tp->cur_tx = tp->dirty_tx = 0; +- netdev_reset_queue(tp->dev); + } + + static void rtl_reset_work(struct rtl8169_private *tp) +@@ -5535,8 +5534,6 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, + + txd->opts2 = cpu_to_le32(opts[1]); + +- netdev_sent_queue(dev, skb->len); +- + skb_tx_timestamp(skb); + + wmb(); +@@ -5633,16 +5630,9 @@ static void rtl8169_pcierr_interrupt(struct net_device *dev) + rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); + } + +-struct rtl_txc { +- int packets; +- int bytes; +-}; +- + static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) + { +- struct rtl8169_stats *tx_stats = &tp->tx_stats; + unsigned int dirty_tx, tx_left; +- struct rtl_txc txc = { 0, 0 }; + + dirty_tx = tp->dirty_tx; + smp_rmb(); +@@ -5661,24 +5651,17 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) + rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, + tp->TxDescArray + entry); + if (status & LastFrag) { +- struct sk_buff *skb = tx_skb->skb; +- +- txc.packets++; +- txc.bytes += skb->len; +- dev_kfree_skb(skb); ++ u64_stats_update_begin(&tp->tx_stats.syncp); ++ tp->tx_stats.packets++; ++ tp->tx_stats.bytes += tx_skb->skb->len; ++ u64_stats_update_end(&tp->tx_stats.syncp); ++ dev_kfree_skb(tx_skb->skb); + tx_skb->skb = NULL; + } + dirty_tx++; + tx_left--; + } + +- u64_stats_update_begin(&tx_stats->syncp); +- tx_stats->packets += txc.packets; +- tx_stats->bytes += txc.bytes; +- u64_stats_update_end(&tx_stats->syncp); +- +- netdev_completed_queue(dev, txc.packets, txc.bytes); +- + if (tp->dirty_tx != dirty_tx) { + tp->dirty_tx = dirty_tx; + /* Sync with rtl8169_start_xmit: +diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c +index b95f2e1..16c4634 100644 +--- a/drivers/net/ethernet/sfc/efx.c ++++ b/drivers/net/ethernet/sfc/efx.c +@@ -1503,6 +1503,11 @@ static int efx_probe_all(struct efx_nic *efx) + goto fail2; + } + ++ BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT); ++ if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) { ++ rc = -EINVAL; ++ goto fail3; ++ } + efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE; + + rc = efx_probe_filters(efx); +@@ -2070,6 +2075,7 @@ static int efx_register_netdev(struct efx_nic *efx) + net_dev->irq = efx->pci_dev->irq; + net_dev->netdev_ops = &efx_netdev_ops; + SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops); ++ net_dev->gso_max_segs = EFX_TSO_MAX_SEGS; + + rtnl_lock(); + +diff --git a/drivers/net/ethernet/sfc/efx.h b/drivers/net/ethernet/sfc/efx.h +index be8f915..70755c9 100644 +--- a/drivers/net/ethernet/sfc/efx.h ++++ b/drivers/net/ethernet/sfc/efx.h +@@ -30,6 +30,7 @@ extern netdev_tx_t + efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb); + extern void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index); + extern int efx_setup_tc(struct net_device *net_dev, u8 num_tc); ++extern unsigned int efx_tx_max_skb_descs(struct efx_nic *efx); + + /* RX */ + extern int efx_probe_rx_queue(struct efx_rx_queue *rx_queue); +@@ -52,10 +53,15 @@ extern void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue); + #define EFX_MAX_EVQ_SIZE 16384UL + #define EFX_MIN_EVQ_SIZE 512UL + +-/* The smallest [rt]xq_entries that the driver supports. Callers of +- * efx_wake_queue() assume that they can subsequently send at least one +- * skb. Falcon/A1 may require up to three descriptors per skb_frag. */ +-#define EFX_MIN_RING_SIZE (roundup_pow_of_two(2 * 3 * MAX_SKB_FRAGS)) ++/* Maximum number of TCP segments we support for soft-TSO */ ++#define EFX_TSO_MAX_SEGS 100 ++ ++/* The smallest [rt]xq_entries that the driver supports. RX minimum ++ * is a bit arbitrary. For TX, we must have space for at least 2 ++ * TSO skbs. ++ */ ++#define EFX_RXQ_MIN_ENT 128U ++#define EFX_TXQ_MIN_ENT(efx) (2 * efx_tx_max_skb_descs(efx)) + + /* Filters */ + extern int efx_probe_filters(struct efx_nic *efx); +diff --git a/drivers/net/ethernet/sfc/ethtool.c b/drivers/net/ethernet/sfc/ethtool.c +index 03ded36..b1287f8 100644 +--- a/drivers/net/ethernet/sfc/ethtool.c ++++ b/drivers/net/ethernet/sfc/ethtool.c +@@ -680,21 +680,27 @@ static int efx_ethtool_set_ringparam(struct net_device *net_dev, + struct ethtool_ringparam *ring) + { + struct efx_nic *efx = netdev_priv(net_dev); ++ u32 txq_entries; + + if (ring->rx_mini_pending || ring->rx_jumbo_pending || + ring->rx_pending > EFX_MAX_DMAQ_SIZE || + ring->tx_pending > EFX_MAX_DMAQ_SIZE) + return -EINVAL; + +- if (ring->rx_pending < EFX_MIN_RING_SIZE || +- ring->tx_pending < EFX_MIN_RING_SIZE) { ++ if (ring->rx_pending < EFX_RXQ_MIN_ENT) { + netif_err(efx, drv, efx->net_dev, +- "TX and RX queues cannot be smaller than %ld\n", +- EFX_MIN_RING_SIZE); ++ "RX queues cannot be smaller than %u\n", ++ EFX_RXQ_MIN_ENT); + return -EINVAL; + } + +- return efx_realloc_channels(efx, ring->rx_pending, ring->tx_pending); ++ txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx)); ++ if (txq_entries != ring->tx_pending) ++ netif_warn(efx, drv, efx->net_dev, ++ "increasing TX queue size to minimum of %u\n", ++ txq_entries); ++ ++ return efx_realloc_channels(efx, ring->rx_pending, txq_entries); + } + + static int efx_ethtool_set_pauseparam(struct net_device *net_dev, +@@ -857,8 +863,8 @@ static int efx_ethtool_get_class_rule(struct efx_nic *efx, + &ip_entry->ip4dst, &ip_entry->pdst); + if (rc != 0) { + rc = efx_filter_get_ipv4_full( +- &spec, &proto, &ip_entry->ip4src, &ip_entry->psrc, +- &ip_entry->ip4dst, &ip_entry->pdst); ++ &spec, &proto, &ip_entry->ip4dst, &ip_entry->pdst, ++ &ip_entry->ip4src, &ip_entry->psrc); + EFX_WARN_ON_PARANOID(rc); + ip_mask->ip4src = ~0; + ip_mask->psrc = ~0; +diff --git a/drivers/net/ethernet/sfc/tx.c b/drivers/net/ethernet/sfc/tx.c +index 94d0365..305430d 100644 +--- a/drivers/net/ethernet/sfc/tx.c ++++ b/drivers/net/ethernet/sfc/tx.c +@@ -119,6 +119,25 @@ efx_max_tx_len(struct efx_nic *efx, dma_addr_t dma_addr) + return len; + } + ++unsigned int efx_tx_max_skb_descs(struct efx_nic *efx) ++{ ++ /* Header and payload descriptor for each output segment, plus ++ * one for every input fragment boundary within a segment ++ */ ++ unsigned int max_descs = EFX_TSO_MAX_SEGS * 2 + MAX_SKB_FRAGS; ++ ++ /* Possibly one more per segment for the alignment workaround */ ++ if (EFX_WORKAROUND_5391(efx)) ++ max_descs += EFX_TSO_MAX_SEGS; ++ ++ /* Possibly more for PCIe page boundaries within input fragments */ ++ if (PAGE_SIZE > EFX_PAGE_SIZE) ++ max_descs += max_t(unsigned int, MAX_SKB_FRAGS, ++ DIV_ROUND_UP(GSO_MAX_SIZE, EFX_PAGE_SIZE)); ++ ++ return max_descs; ++} ++ + /* + * Add a socket buffer to a TX queue + * +diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c +index 3b5c457..28892eb 100644 +--- a/drivers/net/ethernet/ti/davinci_cpdma.c ++++ b/drivers/net/ethernet/ti/davinci_cpdma.c +@@ -862,6 +862,7 @@ int cpdma_chan_stop(struct cpdma_chan *chan) + + next_dma = desc_read(desc, hw_next); + chan->head = desc_from_phys(pool, next_dma); ++ chan->count--; + chan->stats.teardown_dequeue++; + + /* issue callback without locks held */ +diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c +index f9347ea..63ffbdf 100644 +--- a/drivers/net/netconsole.c ++++ b/drivers/net/netconsole.c +@@ -648,7 +648,6 @@ static int netconsole_netdev_event(struct notifier_block *this, + flags); + dev_put(nt->np.dev); + nt->np.dev = NULL; +- netconsole_target_put(nt); + } + nt->enabled = 0; + stopped = true; +diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c +index cbf7047..20f31d0 100644 +--- a/drivers/net/ppp/pppoe.c ++++ b/drivers/net/ppp/pppoe.c +@@ -570,7 +570,7 @@ static int pppoe_release(struct socket *sock) + + po = pppox_sk(sk); + +- if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) { ++ if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND | PPPOX_ZOMBIE)) { + dev_put(po->pppoe_dev); + po->pppoe_dev = NULL; + } +diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c +index 1c98321..162464f 100644 +--- a/drivers/net/ppp/pptp.c ++++ b/drivers/net/ppp/pptp.c +@@ -189,7 +189,7 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb) + if (sk_pppox(po)->sk_state & PPPOX_DEAD) + goto tx_error; + +- rt = ip_route_output_ports(&init_net, &fl4, NULL, ++ rt = ip_route_output_ports(sock_net(sk), &fl4, NULL, + opt->dst_addr.sin_addr.s_addr, + opt->src_addr.sin_addr.s_addr, + 0, 0, IPPROTO_GRE, +@@ -468,7 +468,7 @@ static int pptp_connect(struct socket *sock, struct sockaddr *uservaddr, + po->chan.private = sk; + po->chan.ops = &pptp_chan_ops; + +- rt = ip_route_output_ports(&init_net, &fl4, sk, ++ rt = ip_route_output_ports(sock_net(sk), &fl4, sk, + opt->dst_addr.sin_addr.s_addr, + opt->src_addr.sin_addr.s_addr, + 0, 0, +diff --git a/drivers/net/rionet.c b/drivers/net/rionet.c +index 91d2588..1470d3e 100644 +--- a/drivers/net/rionet.c ++++ b/drivers/net/rionet.c +@@ -79,6 +79,7 @@ static int rionet_capable = 1; + * on system trade-offs. + */ + static struct rio_dev **rionet_active; ++static int nact; /* total number of active rionet peers */ + + #define is_rionet_capable(src_ops, dst_ops) \ + ((src_ops & RIO_SRC_OPS_DATA_MSG) && \ +@@ -175,6 +176,7 @@ static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev) + struct ethhdr *eth = (struct ethhdr *)skb->data; + u16 destid; + unsigned long flags; ++ int add_num = 1; + + local_irq_save(flags); + if (!spin_trylock(&rnet->tx_lock)) { +@@ -182,7 +184,10 @@ static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev) + return NETDEV_TX_LOCKED; + } + +- if ((rnet->tx_cnt + 1) > RIONET_TX_RING_SIZE) { ++ if (is_multicast_ether_addr(eth->h_dest)) ++ add_num = nact; ++ ++ if ((rnet->tx_cnt + add_num) > RIONET_TX_RING_SIZE) { + netif_stop_queue(ndev); + spin_unlock_irqrestore(&rnet->tx_lock, flags); + printk(KERN_ERR "%s: BUG! Tx Ring full when queue awake!\n", +@@ -191,11 +196,16 @@ static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev) + } + + if (is_multicast_ether_addr(eth->h_dest)) { ++ int count = 0; + for (i = 0; i < RIO_MAX_ROUTE_ENTRIES(rnet->mport->sys_size); + i++) +- if (rionet_active[i]) ++ if (rionet_active[i]) { + rionet_queue_tx_msg(skb, ndev, + rionet_active[i]); ++ if (count) ++ atomic_inc(&skb->users); ++ count++; ++ } + } else if (RIONET_MAC_MATCH(eth->h_dest)) { + destid = RIONET_GET_DESTID(eth->h_dest); + if (rionet_active[destid]) +@@ -220,14 +230,17 @@ static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u + if (info == RIONET_DOORBELL_JOIN) { + if (!rionet_active[sid]) { + list_for_each_entry(peer, &rionet_peers, node) { +- if (peer->rdev->destid == sid) ++ if (peer->rdev->destid == sid) { + rionet_active[sid] = peer->rdev; ++ nact++; ++ } + } + rio_mport_send_doorbell(mport, sid, + RIONET_DOORBELL_JOIN); + } + } else if (info == RIONET_DOORBELL_LEAVE) { + rionet_active[sid] = NULL; ++ nact--; + } else { + if (netif_msg_intr(rnet)) + printk(KERN_WARNING "%s: unhandled doorbell\n", +@@ -523,6 +536,7 @@ static int rionet_probe(struct rio_dev *rdev, const struct rio_device_id *id) + + rc = rionet_setup_netdev(rdev->net->hport, ndev); + rionet_check = 1; ++ nact = 0; + } + + /* +diff --git a/drivers/net/tun.c b/drivers/net/tun.c +index 987aeef..5fb59ae 100644 +--- a/drivers/net/tun.c ++++ b/drivers/net/tun.c +@@ -185,7 +185,6 @@ static void __tun_detach(struct tun_struct *tun) + netif_tx_lock_bh(tun->dev); + netif_carrier_off(tun->dev); + tun->tfile = NULL; +- tun->socket.file = NULL; + netif_tx_unlock_bh(tun->dev); + + /* Drop read queue */ +@@ -358,6 +357,8 @@ static void tun_free_netdev(struct net_device *dev) + { + struct tun_struct *tun = netdev_priv(dev); + ++ BUG_ON(!test_bit(SOCK_EXTERNALLY_ALLOCATED, &tun->socket.flags)); ++ + sk_release_kernel(tun->socket.sk); + } + +@@ -1115,6 +1116,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) + tun->flags = flags; + tun->txflt.count = 0; + tun->vnet_hdr_sz = sizeof(struct virtio_net_hdr); ++ set_bit(SOCK_EXTERNALLY_ALLOCATED, &tun->socket.flags); + + err = -ENOMEM; + sk = sk_alloc(&init_net, AF_UNSPEC, GFP_KERNEL, &tun_proto); +@@ -1252,10 +1254,12 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, + 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 --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c +index 3ae80ec..ebcb7d4 100644 +--- a/drivers/net/usb/asix.c ++++ b/drivers/net/usb/asix.c +@@ -1604,6 +1604,10 @@ static const struct usb_device_id products [] = { + USB_DEVICE (0x2001, 0x3c05), + .driver_info = (unsigned long) &ax88772_info, + }, { ++ // DLink DUB-E100 H/W Ver C1 ++ USB_DEVICE (0x2001, 0x1a02), ++ .driver_info = (unsigned long) &ax88772_info, ++}, { + // Linksys USB1000 + USB_DEVICE (0x1737, 0x0039), + .driver_info = (unsigned long) &ax88178_info, +diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c +index d8ad552..c3d0349 100644 +--- a/drivers/net/usb/kaweth.c ++++ b/drivers/net/usb/kaweth.c +@@ -1314,7 +1314,7 @@ static int kaweth_internal_control_msg(struct usb_device *usb_dev, + 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 --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c +index a051ced..d124bdd 100644 +--- a/drivers/net/usb/qmi_wwan.c ++++ b/drivers/net/usb/qmi_wwan.c +@@ -444,6 +444,15 @@ static const struct usb_device_id products[] = { + .bInterfaceProtocol = 0xff, + .driver_info = (unsigned long)&qmi_wwan_shared, + }, ++ { /* Pantech UML290 - newer firmware */ ++ .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x106c, ++ .idProduct = 0x3718, ++ .bInterfaceClass = 0xff, ++ .bInterfaceSubClass = 0xf1, ++ .bInterfaceProtocol = 0xff, ++ .driver_info = (unsigned long)&qmi_wwan_shared, ++ }, + { /* ZTE MF820D */ + .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x19d2, +@@ -453,6 +462,15 @@ static const struct usb_device_id products[] = { + .bInterfaceProtocol = 0xff, + .driver_info = (unsigned long)&qmi_wwan_force_int4, + }, ++ { /* ZTE MF821D */ ++ .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x19d2, ++ .idProduct = 0x0326, ++ .bInterfaceClass = 0xff, ++ .bInterfaceSubClass = 0xff, ++ .bInterfaceProtocol = 0xff, ++ .driver_info = (unsigned long)&qmi_wwan_force_int4, ++ }, + { /* ZTE (Vodafone) K3520-Z */ + .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x19d2, +@@ -507,6 +525,15 @@ static const struct usb_device_id products[] = { + .bInterfaceProtocol = 0xff, + .driver_info = (unsigned long)&qmi_wwan_force_int4, + }, ++ { /* ZTE (Vodafone) K5006-Z */ ++ .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x19d2, ++ .idProduct = 0x1018, ++ .bInterfaceClass = 0xff, ++ .bInterfaceSubClass = 0xff, ++ .bInterfaceProtocol = 0xff, ++ .driver_info = (unsigned long)&qmi_wwan_force_int3, ++ }, + { /* ZTE MF60 */ + .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x19d2, +@@ -525,6 +552,33 @@ static const struct usb_device_id products[] = { + .bInterfaceProtocol = 0xff, + .driver_info = (unsigned long)&qmi_wwan_sierra, + }, ++ { /* Sierra Wireless MC7700 */ ++ .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x0f3d, ++ .idProduct = 0x68a2, ++ .bInterfaceClass = 0xff, ++ .bInterfaceSubClass = 0xff, ++ .bInterfaceProtocol = 0xff, ++ .driver_info = (unsigned long)&qmi_wwan_sierra, ++ }, ++ { /* Sierra Wireless MC7750 */ ++ .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x114f, ++ .idProduct = 0x68a2, ++ .bInterfaceClass = 0xff, ++ .bInterfaceSubClass = 0xff, ++ .bInterfaceProtocol = 0xff, ++ .driver_info = (unsigned long)&qmi_wwan_sierra, ++ }, ++ { /* Sierra Wireless EM7700 */ ++ .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x1199, ++ .idProduct = 0x901c, ++ .bInterfaceClass = 0xff, ++ .bInterfaceSubClass = 0xff, ++ .bInterfaceProtocol = 0xff, ++ .driver_info = (unsigned long)&qmi_wwan_sierra, ++ }, + + /* Gobi 1000 devices */ + {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */ +@@ -552,6 +606,8 @@ static const struct usb_device_id products[] = { + {QMI_GOBI_DEVICE(0x05c6, 0x9265)}, /* Asus Gobi 2000 Modem device (VR305) */ + {QMI_GOBI_DEVICE(0x05c6, 0x9235)}, /* Top Global Gobi 2000 Modem device (VR306) */ + {QMI_GOBI_DEVICE(0x05c6, 0x9275)}, /* iRex Technologies Gobi 2000 Modem device (VR307) */ ++ {QMI_GOBI_DEVICE(0x1199, 0x68a5)}, /* Sierra Wireless Modem */ ++ {QMI_GOBI_DEVICE(0x1199, 0x68a9)}, /* Sierra Wireless Modem */ + {QMI_GOBI_DEVICE(0x1199, 0x9001)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ + {QMI_GOBI_DEVICE(0x1199, 0x9002)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ + {QMI_GOBI_DEVICE(0x1199, 0x9003)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ +@@ -568,6 +624,8 @@ static const struct usb_device_id products[] = { + {QMI_GOBI_DEVICE(0x1199, 0x9013)}, /* Sierra Wireless Gobi 3000 Modem device (MC8355) */ + {QMI_GOBI_DEVICE(0x1199, 0x9015)}, /* Sierra Wireless Gobi 3000 Modem device */ + {QMI_GOBI_DEVICE(0x1199, 0x9019)}, /* Sierra Wireless Gobi 3000 Modem device */ ++ {QMI_GOBI_DEVICE(0x1199, 0x901b)}, /* Sierra Wireless MC7770 */ ++ + { } /* END */ + }; + MODULE_DEVICE_TABLE(usb, products); +diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c +index d75d1f5..e43f1cf 100644 +--- a/drivers/net/usb/sierra_net.c ++++ b/drivers/net/usb/sierra_net.c +@@ -678,7 +678,7 @@ static int sierra_net_get_fw_attr(struct usbnet *dev, u16 *datap) + return -EIO; + } + +- *datap = *attrdata; ++ *datap = le16_to_cpu(*attrdata); + + kfree(attrdata); + return result; +diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c +index aba769d..f2716a4 100644 +--- a/drivers/net/usb/usbnet.c ++++ b/drivers/net/usb/usbnet.c +@@ -1204,19 +1204,26 @@ deferred: + } + EXPORT_SYMBOL_GPL(usbnet_start_xmit); + +-static void rx_alloc_submit(struct usbnet *dev, gfp_t flags) ++static int rx_alloc_submit(struct usbnet *dev, gfp_t flags) + { + struct urb *urb; + int i; ++ int ret = 0; + + /* don't refill the queue all at once */ + for (i = 0; i < 10 && dev->rxq.qlen < RX_QLEN(dev); i++) { + urb = usb_alloc_urb(0, flags); + if (urb != NULL) { +- if (rx_submit(dev, urb, flags) == -ENOLINK) +- return; ++ ret = rx_submit(dev, urb, flags); ++ if (ret) ++ goto err; ++ } else { ++ ret = -ENOMEM; ++ goto err; + } + } ++err: ++ return ret; + } + + /*-------------------------------------------------------------------------*/ +@@ -1260,7 +1267,8 @@ static void usbnet_bh (unsigned long param) + int temp = dev->rxq.qlen; + + if (temp < RX_QLEN(dev)) { +- rx_alloc_submit(dev, GFP_ATOMIC); ++ if (rx_alloc_submit(dev, GFP_ATOMIC) == -ENOLINK) ++ return; + if (temp != dev->rxq.qlen) + netif_dbg(dev, link, dev->net, + "rxqlen %d --> %d\n", +@@ -1580,7 +1588,7 @@ int usbnet_resume (struct usb_interface *intf) + netif_device_present(dev->net) && + !timer_pending(&dev->delay) && + !test_bit(EVENT_RX_HALT, &dev->flags)) +- rx_alloc_submit(dev, GFP_KERNEL); ++ rx_alloc_submit(dev, GFP_NOIO); + + if (!(dev->txq.qlen >= TX_QLEN(dev))) + netif_tx_wake_all_queues(dev->net); +diff --git a/drivers/net/wan/ixp4xx_hss.c b/drivers/net/wan/ixp4xx_hss.c +index aaaca9a..3f575af 100644 +--- a/drivers/net/wan/ixp4xx_hss.c ++++ b/drivers/net/wan/ixp4xx_hss.c +@@ -10,6 +10,7 @@ + + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + ++#include + #include + #include + #include +diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c +index 995ca8e..988b1f3 100644 +--- a/drivers/net/wireless/ath/ath9k/hw.c ++++ b/drivers/net/wireless/ath/ath9k/hw.c +@@ -740,6 +740,7 @@ int ath9k_hw_init(struct ath_hw *ah) + case AR9300_DEVID_AR9340: + case AR9300_DEVID_AR9580: + case AR9300_DEVID_AR9462: ++ case AR9485_DEVID_AR1111: + break; + default: + if (common->bus_ops->ath_bus_type == ATH_USB) +diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h +index b620c55..02f50074 100644 +--- a/drivers/net/wireless/ath/ath9k/hw.h ++++ b/drivers/net/wireless/ath/ath9k/hw.h +@@ -48,6 +48,7 @@ + #define AR9300_DEVID_AR9580 0x0033 + #define AR9300_DEVID_AR9462 0x0034 + #define AR9300_DEVID_AR9330 0x0035 ++#define AR9485_DEVID_AR1111 0x0037 + + #define AR5416_AR9100_DEVID 0x000b + +diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c +index a856b51..5ea8565 100644 +--- a/drivers/net/wireless/ath/ath9k/pci.c ++++ b/drivers/net/wireless/ath/ath9k/pci.c +@@ -37,6 +37,7 @@ static DEFINE_PCI_DEVICE_TABLE(ath_pci_id_table) = { + { PCI_VDEVICE(ATHEROS, 0x0032) }, /* PCI-E AR9485 */ + { PCI_VDEVICE(ATHEROS, 0x0033) }, /* PCI-E AR9580 */ + { PCI_VDEVICE(ATHEROS, 0x0034) }, /* PCI-E AR9462 */ ++ { PCI_VDEVICE(ATHEROS, 0x0037) }, /* PCI-E AR1111/AR9485 */ + { 0 } + }; + +@@ -123,8 +124,9 @@ static void ath_pci_aspm_init(struct ath_common *common) + if (!parent) + return; + +- if (ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) { +- /* Bluetooth coexistance requires disabling ASPM. */ ++ if ((ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) && ++ (AR_SREV_9285(ah))) { ++ /* Bluetooth coexistance requires disabling ASPM for AR9285. */ + pci_read_config_byte(pdev, pos + PCI_EXP_LNKCTL, &aspm); + aspm &= ~(PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1); + pci_write_config_byte(pdev, pos + PCI_EXP_LNKCTL, aspm); +@@ -312,6 +314,7 @@ static int ath_pci_suspend(struct device *device) + * Otherwise the chip never moved to full sleep, + * when no interface is up. + */ ++ ath9k_stop_btcoex(sc); + ath9k_hw_disable(sc->sc_ah); + ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP); + +diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c +index 0735aeb..af3bbf2 100644 +--- a/drivers/net/wireless/ath/ath9k/recv.c ++++ b/drivers/net/wireless/ath/ath9k/recv.c +@@ -1781,7 +1781,6 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) + struct ieee80211_hw *hw = sc->hw; + struct ieee80211_hdr *hdr; + int retval; +- bool decrypt_error = false; + struct ath_rx_status rs; + enum ath9k_rx_qtype qtype; + bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); +@@ -1803,6 +1802,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) + tsf_lower = tsf & 0xffffffff; + + do { ++ bool decrypt_error = false; + /* If handling rx interrupt and flush is in progress => exit */ + if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0)) + break; +diff --git a/drivers/net/wireless/b43/b43.h b/drivers/net/wireless/b43/b43.h +index c06b6cb..7c899fc 100644 +--- a/drivers/net/wireless/b43/b43.h ++++ b/drivers/net/wireless/b43/b43.h +@@ -870,13 +870,6 @@ struct b43_wl { + * handler, only. This basically is just the IRQ mask register. */ + spinlock_t hardirq_lock; + +- /* The number of queues that were registered with the mac80211 subsystem +- * initially. This is a backup copy of hw->queues in case hw->queues has +- * to be dynamically lowered at runtime (Firmware does not support QoS). +- * hw->queues has to be restored to the original value before unregistering +- * from the mac80211 subsystem. */ +- u16 mac80211_initially_registered_queues; +- + /* Set this if we call ieee80211_register_hw() and check if we call + * ieee80211_unregister_hw(). */ + bool hw_registred; +diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c +index 1b988f2..b80352b 100644 +--- a/drivers/net/wireless/b43/main.c ++++ b/drivers/net/wireless/b43/main.c +@@ -2359,6 +2359,8 @@ static int b43_try_request_fw(struct b43_request_fw_context *ctx) + if (err) + goto err_load; + ++ fw->opensource = (ctx->req_type == B43_FWTYPE_OPENSOURCE); ++ + return 0; + + err_no_ucode: +@@ -2434,6 +2436,10 @@ static void b43_request_firmware(struct work_struct *work) + goto out; + + start_ieee80211: ++ wl->hw->queues = B43_QOS_QUEUE_NUM; ++ if (!modparam_qos || dev->fw.opensource) ++ wl->hw->queues = 1; ++ + err = ieee80211_register_hw(wl->hw); + if (err) + goto err_one_core_detach; +@@ -2537,11 +2543,9 @@ static int b43_upload_microcode(struct b43_wldev *dev) + dev->fw.hdr_format = B43_FW_HDR_410; + else + dev->fw.hdr_format = B43_FW_HDR_351; +- dev->fw.opensource = (fwdate == 0xFFFF); ++ WARN_ON(dev->fw.opensource != (fwdate == 0xFFFF)); + +- /* Default to use-all-queues. */ +- dev->wl->hw->queues = dev->wl->mac80211_initially_registered_queues; +- dev->qos_enabled = !!modparam_qos; ++ dev->qos_enabled = dev->wl->hw->queues > 1; + /* Default to firmware/hardware crypto acceleration. */ + dev->hwcrypto_enabled = true; + +@@ -2559,14 +2563,8 @@ static int b43_upload_microcode(struct b43_wldev *dev) + /* Disable hardware crypto and fall back to software crypto. */ + dev->hwcrypto_enabled = false; + } +- if (!(fwcapa & B43_FWCAPA_QOS)) { +- b43info(dev->wl, "QoS not supported by firmware\n"); +- /* Disable QoS. Tweak hw->queues to 1. It will be restored before +- * ieee80211_unregister to make sure the networking core can +- * properly free possible resources. */ +- dev->wl->hw->queues = 1; +- dev->qos_enabled = false; +- } ++ /* adding QoS support should use an offline discovery mechanism */ ++ WARN(fwcapa & B43_FWCAPA_QOS, "QoS in OpenFW not supported\n"); + } else { + b43info(dev->wl, "Loading firmware version %u.%u " + "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n", +@@ -5298,8 +5296,6 @@ static struct b43_wl *b43_wireless_init(struct b43_bus_dev *dev) + + hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; + +- hw->queues = modparam_qos ? B43_QOS_QUEUE_NUM : 1; +- wl->mac80211_initially_registered_queues = hw->queues; + wl->hw_registred = false; + hw->max_rates = 2; + SET_IEEE80211_DEV(hw, dev->dev); +@@ -5374,10 +5370,6 @@ static void b43_bcma_remove(struct bcma_device *core) + + B43_WARN_ON(!wl); + if (wl->current_dev == wldev && wl->hw_registred) { +- /* Restore the queues count before unregistering, because firmware detect +- * might have modified it. Restoring is important, so the networking +- * stack can properly free resources. */ +- wl->hw->queues = wl->mac80211_initially_registered_queues; + b43_leds_stop(wldev); + ieee80211_unregister_hw(wl->hw); + } +@@ -5452,10 +5444,6 @@ static void b43_ssb_remove(struct ssb_device *sdev) + + B43_WARN_ON(!wl); + if (wl->current_dev == wldev && wl->hw_registred) { +- /* Restore the queues count before unregistering, because firmware detect +- * might have modified it. Restoring is important, so the networking +- * stack can properly free resources. */ +- wl->hw->queues = wl->mac80211_initially_registered_queues; + b43_leds_stop(wldev); + ieee80211_unregister_hw(wl->hw); + } +diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c +index eae691e..de1d9d5 100644 +--- a/drivers/net/wireless/b43legacy/main.c ++++ b/drivers/net/wireless/b43legacy/main.c +@@ -3894,6 +3894,8 @@ static void b43legacy_remove(struct ssb_device *dev) + cancel_work_sync(&wl->firmware_load); + + B43legacy_WARN_ON(!wl); ++ if (!wldev->fw.ucode) ++ return; /* NULL if fw never loaded */ + if (wl->current_dev == wldev) + ieee80211_unregister_hw(wl->hw); + +diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c +index 236cb9f..3ae938f 100644 +--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c ++++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c +@@ -764,8 +764,11 @@ static void brcmf_c_arp_offload_set(struct brcmf_pub *drvr, int arp_mode) + { + char iovbuf[32]; + int retcode; ++ __le32 arp_mode_le; + +- brcmf_c_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf)); ++ arp_mode_le = cpu_to_le32(arp_mode); ++ brcmf_c_mkiovar("arp_ol", (char *)&arp_mode_le, 4, iovbuf, ++ sizeof(iovbuf)); + retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, + iovbuf, sizeof(iovbuf)); + retcode = retcode >= 0 ? 0 : retcode; +@@ -781,8 +784,11 @@ static void brcmf_c_arp_offload_enable(struct brcmf_pub *drvr, int arp_enable) + { + char iovbuf[32]; + int retcode; ++ __le32 arp_enable_le; + +- brcmf_c_mkiovar("arpoe", (char *)&arp_enable, 4, ++ arp_enable_le = cpu_to_le32(arp_enable); ++ ++ brcmf_c_mkiovar("arpoe", (char *)&arp_enable_le, 4, + iovbuf, sizeof(iovbuf)); + retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, + iovbuf, sizeof(iovbuf)); +@@ -802,10 +808,10 @@ int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr) + char buf[128], *ptr; + u32 dongle_align = drvr->bus_if->align; + u32 glom = 0; +- u32 roaming = 1; +- uint bcn_timeout = 3; +- int scan_assoc_time = 40; +- int scan_unassoc_time = 40; ++ __le32 roaming_le = cpu_to_le32(1); ++ __le32 bcn_timeout_le = cpu_to_le32(3); ++ __le32 scan_assoc_time_le = cpu_to_le32(40); ++ __le32 scan_unassoc_time_le = cpu_to_le32(40); + int i; + + mutex_lock(&drvr->proto_block); +@@ -840,14 +846,14 @@ int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr) + + /* Setup timeout if Beacons are lost and roam is off to report + link down */ +- brcmf_c_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf, ++ brcmf_c_mkiovar("bcn_timeout", (char *)&bcn_timeout_le, 4, iovbuf, + sizeof(iovbuf)); + brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf, + sizeof(iovbuf)); + + /* Enable/Disable build-in roaming to allowed ext supplicant to take + of romaing */ +- brcmf_c_mkiovar("roam_off", (char *)&roaming, 4, ++ brcmf_c_mkiovar("roam_off", (char *)&roaming_le, 4, + iovbuf, sizeof(iovbuf)); + brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf, + sizeof(iovbuf)); +@@ -859,9 +865,9 @@ int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr) + sizeof(iovbuf)); + + brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_CHANNEL_TIME, +- (char *)&scan_assoc_time, sizeof(scan_assoc_time)); ++ (char *)&scan_assoc_time_le, sizeof(scan_assoc_time_le)); + brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_UNASSOC_TIME, +- (char *)&scan_unassoc_time, sizeof(scan_unassoc_time)); ++ (char *)&scan_unassoc_time_le, sizeof(scan_unassoc_time_le)); + + /* Set and enable ARP offload feature */ + brcmf_c_arp_offload_set(drvr, BRCMF_ARPOL_MODE); +diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c +index d13ae9c..e360939 100644 +--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c ++++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c +@@ -500,8 +500,10 @@ static void wl_iscan_prep(struct brcmf_scan_params_le *params_le, + params_le->active_time = cpu_to_le32(-1); + params_le->passive_time = cpu_to_le32(-1); + params_le->home_time = cpu_to_le32(-1); +- if (ssid && ssid->SSID_len) +- memcpy(¶ms_le->ssid_le, ssid, sizeof(struct brcmf_ssid)); ++ if (ssid && ssid->SSID_len) { ++ params_le->ssid_le.SSID_len = cpu_to_le32(ssid->SSID_len); ++ memcpy(¶ms_le->ssid_le.SSID, ssid->SSID, ssid->SSID_len); ++ } + } + + static s32 +diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c +index e55ec6c..c31072d 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c ++++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c +@@ -617,6 +617,11 @@ static bool iwlagn_fill_txpower_mode(struct iwl_priv *priv, + struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; + int ave_rssi; + ++ if (!ctx->vif || (ctx->vif->type != NL80211_IFTYPE_STATION)) { ++ IWL_DEBUG_INFO(priv, "BSS ctx not active or not in sta mode\n"); ++ return false; ++ } ++ + ave_rssi = ieee80211_ave_rssi(ctx->vif); + if (!ave_rssi) { + /* no rssi data, no changes to reduce tx power */ +diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c +index 8cebd7c..745ce42 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c ++++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c +@@ -709,11 +709,14 @@ static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags, + */ + static bool rs_use_green(struct ieee80211_sta *sta) + { +- struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; +- struct iwl_rxon_context *ctx = sta_priv->ctx; +- +- return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) && +- !(ctx->ht.non_gf_sta_present); ++ /* ++ * There's a bug somewhere in this code that causes the ++ * scaling to get stuck because GF+SGI can't be combined ++ * in SISO rates. Until we find that bug, disable GF, it ++ * has only limited benefit and we still interoperate with ++ * GF APs since we can always receive GF transmissions. ++ */ ++ return false; + } + + /** +diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-sta.c b/drivers/net/wireless/iwlwifi/iwl-agn-sta.c +index eb6a8ea..287fdd0 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-agn-sta.c ++++ b/drivers/net/wireless/iwlwifi/iwl-agn-sta.c +@@ -236,6 +236,7 @@ static void iwl_sta_calc_ht_flags(struct iwl_priv *priv, + mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; + + IWL_DEBUG_INFO(priv, "STA %pM SM PS mode: %s\n", ++ sta->addr, + (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ? + "static" : + (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ? +diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c +index 7f97dec..5000690 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c ++++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c +@@ -128,6 +128,9 @@ static ssize_t iwl_dbgfs_sram_read(struct file *file, + const struct fw_img *img; + size_t bufsz; + ++ if (!iwl_is_ready_rf(priv)) ++ return -EAGAIN; ++ + /* default is to dump the entire data segment */ + if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) { + priv->dbgfs_sram_offset = 0x800000; +diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-int.h b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-int.h +index e959207..8215fad 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-int.h ++++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-int.h +@@ -355,7 +355,7 @@ int iwl_queue_space(const struct iwl_queue *q); + /***************************************************** + * Error handling + ******************************************************/ +-int iwl_dump_fh(struct iwl_trans *trans, char **buf, bool display); ++int iwl_dump_fh(struct iwl_trans *trans, char **buf); + void iwl_dump_csr(struct iwl_trans *trans); + + /***************************************************** +diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c +index 08517d3..5e18ff9 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c ++++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c +@@ -559,7 +559,7 @@ static void iwl_irq_handle_error(struct iwl_trans *trans) + } + + iwl_dump_csr(trans); +- iwl_dump_fh(trans, NULL, false); ++ iwl_dump_fh(trans, NULL); + + iwl_op_mode_nic_error(trans->op_mode); + } +diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c +index 79c6b91..a1fb025 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c ++++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c +@@ -1437,6 +1437,7 @@ static int iwl_trans_pcie_start_hw(struct iwl_trans *trans) + return err; + + err_free_irq: ++ trans_pcie->irq_requested = false; + free_irq(trans_pcie->irq, trans); + error: + iwl_free_isr_ict(trans); +@@ -1654,13 +1655,9 @@ static const char *get_fh_string(int cmd) + #undef IWL_CMD + } + +-int iwl_dump_fh(struct iwl_trans *trans, char **buf, bool display) ++int iwl_dump_fh(struct iwl_trans *trans, char **buf) + { + int i; +-#ifdef CONFIG_IWLWIFI_DEBUG +- int pos = 0; +- size_t bufsz = 0; +-#endif + static const u32 fh_tbl[] = { + FH_RSCSR_CHNL0_STTS_WPTR_REG, + FH_RSCSR_CHNL0_RBDCB_BASE_REG, +@@ -1672,29 +1669,35 @@ int iwl_dump_fh(struct iwl_trans *trans, char **buf, bool display) + FH_TSSR_TX_STATUS_REG, + FH_TSSR_TX_ERROR_REG + }; +-#ifdef CONFIG_IWLWIFI_DEBUG +- if (display) { +- bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40; ++ ++#ifdef CONFIG_IWLWIFI_DEBUGFS ++ if (buf) { ++ int pos = 0; ++ size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40; ++ + *buf = kmalloc(bufsz, GFP_KERNEL); + if (!*buf) + return -ENOMEM; ++ + pos += scnprintf(*buf + pos, bufsz - pos, + "FH register values:\n"); +- for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) { ++ ++ for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) + pos += scnprintf(*buf + pos, bufsz - pos, + " %34s: 0X%08x\n", + get_fh_string(fh_tbl[i]), + iwl_read_direct32(trans, fh_tbl[i])); +- } ++ + return pos; + } + #endif ++ + IWL_ERR(trans, "FH register values:\n"); +- for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) { ++ for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) + IWL_ERR(trans, " %34s: 0X%08x\n", + get_fh_string(fh_tbl[i]), + iwl_read_direct32(trans, fh_tbl[i])); +- } ++ + return 0; + } + +@@ -1989,11 +1992,11 @@ static ssize_t iwl_dbgfs_fh_reg_read(struct file *file, + size_t count, loff_t *ppos) + { + struct iwl_trans *trans = file->private_data; +- char *buf; ++ char *buf = NULL; + int pos = 0; + ssize_t ret = -EFAULT; + +- ret = pos = iwl_dump_fh(trans, &buf, true); ++ ret = pos = iwl_dump_fh(trans, &buf); + if (buf) { + ret = simple_read_from_buffer(user_buf, + count, ppos, buf, pos); +diff --git a/drivers/net/wireless/mwifiex/cfg80211.c b/drivers/net/wireless/mwifiex/cfg80211.c +index 5c7fd18..76b5c0f 100644 +--- a/drivers/net/wireless/mwifiex/cfg80211.c ++++ b/drivers/net/wireless/mwifiex/cfg80211.c +@@ -634,9 +634,9 @@ mwifiex_dump_station_info(struct mwifiex_private *priv, + + /* + * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid +- * MCS index values for us are 0 to 7. ++ * MCS index values for us are 0 to 15. + */ +- if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 8)) { ++ if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) { + sinfo->txrate.mcs = priv->tx_rate; + sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; + /* 40MHz rate */ +diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c +index 7f207b6..effb044 100644 +--- a/drivers/net/wireless/p54/p54usb.c ++++ b/drivers/net/wireless/p54/p54usb.c +@@ -42,7 +42,7 @@ MODULE_FIRMWARE("isl3887usb"); + * whenever you add a new device. + */ + +-static struct usb_device_id p54u_table[] __devinitdata = { ++static struct usb_device_id p54u_table[] = { + /* Version 1 devices (pci chip + net2280) */ + {USB_DEVICE(0x0411, 0x0050)}, /* Buffalo WLI2-USB2-G54 */ + {USB_DEVICE(0x045e, 0x00c2)}, /* Microsoft MN-710 */ +diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c +index 5e6b501..d8594a2 100644 +--- a/drivers/net/wireless/rt2x00/rt2400pci.c ++++ b/drivers/net/wireless/rt2x00/rt2400pci.c +@@ -1611,6 +1611,7 @@ static int rt2400pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev) + static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev) + { + int retval; ++ u32 reg; + + /* + * Allocate eeprom data. +@@ -1624,6 +1625,14 @@ static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev) + return retval; + + /* ++ * Enable rfkill polling by setting GPIO direction of the ++ * rfkill switch GPIO pin correctly. ++ */ ++ rt2x00pci_register_read(rt2x00dev, GPIOCSR, ®); ++ rt2x00_set_field32(®, GPIOCSR_BIT8, 1); ++ rt2x00pci_register_write(rt2x00dev, GPIOCSR, reg); ++ ++ /* + * Initialize hw specifications. + */ + retval = rt2400pci_probe_hw_mode(rt2x00dev); +diff --git a/drivers/net/wireless/rt2x00/rt2400pci.h b/drivers/net/wireless/rt2x00/rt2400pci.h +index d3a4a68..7564ae9 100644 +--- a/drivers/net/wireless/rt2x00/rt2400pci.h ++++ b/drivers/net/wireless/rt2x00/rt2400pci.h +@@ -670,6 +670,7 @@ + #define GPIOCSR_BIT5 FIELD32(0x00000020) + #define GPIOCSR_BIT6 FIELD32(0x00000040) + #define GPIOCSR_BIT7 FIELD32(0x00000080) ++#define GPIOCSR_BIT8 FIELD32(0x00000100) + + /* + * BBPPCSR: BBP Pin control register. +diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c +index 136b849..2223e35 100644 +--- a/drivers/net/wireless/rt2x00/rt2500pci.c ++++ b/drivers/net/wireless/rt2x00/rt2500pci.c +@@ -1929,6 +1929,7 @@ static int rt2500pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev) + static int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev) + { + int retval; ++ u32 reg; + + /* + * Allocate eeprom data. +@@ -1942,6 +1943,14 @@ static int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev) + return retval; + + /* ++ * Enable rfkill polling by setting GPIO direction of the ++ * rfkill switch GPIO pin correctly. ++ */ ++ rt2x00pci_register_read(rt2x00dev, GPIOCSR, ®); ++ rt2x00_set_field32(®, GPIOCSR_DIR0, 1); ++ rt2x00pci_register_write(rt2x00dev, GPIOCSR, reg); ++ ++ /* + * Initialize hw specifications. + */ + retval = rt2500pci_probe_hw_mode(rt2x00dev); +diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c +index 669aecd..d6e87c0 100644 +--- a/drivers/net/wireless/rt2x00/rt2500usb.c ++++ b/drivers/net/wireless/rt2x00/rt2500usb.c +@@ -283,7 +283,7 @@ static int rt2500usb_rfkill_poll(struct rt2x00_dev *rt2x00dev) + u16 reg; + + rt2500usb_register_read(rt2x00dev, MAC_CSR19, ®); +- return rt2x00_get_field32(reg, MAC_CSR19_BIT7); ++ return rt2x00_get_field16(reg, MAC_CSR19_BIT7); + } + + #ifdef CONFIG_RT2X00_LIB_LEDS +@@ -1768,6 +1768,7 @@ static int rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev) + static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev) + { + int retval; ++ u16 reg; + + /* + * Allocate eeprom data. +@@ -1781,6 +1782,14 @@ static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev) + return retval; + + /* ++ * Enable rfkill polling by setting GPIO direction of the ++ * rfkill switch GPIO pin correctly. ++ */ ++ rt2500usb_register_read(rt2x00dev, MAC_CSR19, ®); ++ rt2x00_set_field16(®, MAC_CSR19_BIT8, 0); ++ rt2500usb_register_write(rt2x00dev, MAC_CSR19, reg); ++ ++ /* + * Initialize hw specifications. + */ + retval = rt2500usb_probe_hw_mode(rt2x00dev); +diff --git a/drivers/net/wireless/rt2x00/rt2500usb.h b/drivers/net/wireless/rt2x00/rt2500usb.h +index b493306..196bd51 100644 +--- a/drivers/net/wireless/rt2x00/rt2500usb.h ++++ b/drivers/net/wireless/rt2x00/rt2500usb.h +@@ -189,14 +189,15 @@ + * MAC_CSR19: GPIO control register. + */ + #define MAC_CSR19 0x0426 +-#define MAC_CSR19_BIT0 FIELD32(0x0001) +-#define MAC_CSR19_BIT1 FIELD32(0x0002) +-#define MAC_CSR19_BIT2 FIELD32(0x0004) +-#define MAC_CSR19_BIT3 FIELD32(0x0008) +-#define MAC_CSR19_BIT4 FIELD32(0x0010) +-#define MAC_CSR19_BIT5 FIELD32(0x0020) +-#define MAC_CSR19_BIT6 FIELD32(0x0040) +-#define MAC_CSR19_BIT7 FIELD32(0x0080) ++#define MAC_CSR19_BIT0 FIELD16(0x0001) ++#define MAC_CSR19_BIT1 FIELD16(0x0002) ++#define MAC_CSR19_BIT2 FIELD16(0x0004) ++#define MAC_CSR19_BIT3 FIELD16(0x0008) ++#define MAC_CSR19_BIT4 FIELD16(0x0010) ++#define MAC_CSR19_BIT5 FIELD16(0x0020) ++#define MAC_CSR19_BIT6 FIELD16(0x0040) ++#define MAC_CSR19_BIT7 FIELD16(0x0080) ++#define MAC_CSR19_BIT8 FIELD16(0x0100) + + /* + * MAC_CSR20: LED control register. +diff --git a/drivers/net/wireless/rt2x00/rt2800pci.c b/drivers/net/wireless/rt2x00/rt2800pci.c +index cad25bf..0f26ffb 100644 +--- a/drivers/net/wireless/rt2x00/rt2800pci.c ++++ b/drivers/net/wireless/rt2x00/rt2800pci.c +@@ -977,6 +977,7 @@ static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev) + static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev) + { + int retval; ++ u32 reg; + + /* + * Allocate eeprom data. +@@ -990,6 +991,14 @@ static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev) + return retval; + + /* ++ * Enable rfkill polling by setting GPIO direction of the ++ * rfkill switch GPIO pin correctly. ++ */ ++ rt2x00pci_register_read(rt2x00dev, GPIO_CTRL_CFG, ®); ++ rt2x00_set_field32(®, GPIO_CTRL_CFG_GPIOD_BIT2, 1); ++ rt2x00pci_register_write(rt2x00dev, GPIO_CTRL_CFG, reg); ++ ++ /* + * Initialize hw specifications. + */ + retval = rt2800_probe_hw_mode(rt2x00dev); +diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c +index bf78317..6b4226b 100644 +--- a/drivers/net/wireless/rt2x00/rt2800usb.c ++++ b/drivers/net/wireless/rt2x00/rt2800usb.c +@@ -667,8 +667,16 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry, + skb_pull(entry->skb, RXINFO_DESC_SIZE); + + /* +- * FIXME: we need to check for rx_pkt_len validity ++ * Check for rx_pkt_len validity. Return if invalid, leaving ++ * rxdesc->size zeroed out by the upper level. + */ ++ if (unlikely(rx_pkt_len == 0 || ++ rx_pkt_len > entry->queue->data_size)) { ++ ERROR(entry->queue->rt2x00dev, ++ "Bad frame size %d, forcing to 0\n", rx_pkt_len); ++ return; ++ } ++ + rxd = (__le32 *)(entry->skb->data + rx_pkt_len); + + /* +@@ -736,6 +744,7 @@ static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev) + static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev) + { + int retval; ++ u32 reg; + + /* + * Allocate eeprom data. +@@ -749,6 +758,14 @@ static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev) + return retval; + + /* ++ * Enable rfkill polling by setting GPIO direction of the ++ * rfkill switch GPIO pin correctly. ++ */ ++ rt2x00usb_register_read(rt2x00dev, GPIO_CTRL_CFG, ®); ++ rt2x00_set_field32(®, GPIO_CTRL_CFG_GPIOD_BIT2, 1); ++ rt2x00usb_register_write(rt2x00dev, GPIO_CTRL_CFG, reg); ++ ++ /* + * Initialize hw specifications. + */ + retval = rt2800_probe_hw_mode(rt2x00dev); +@@ -971,6 +988,7 @@ static struct usb_device_id rt2800usb_device_table[] = { + { USB_DEVICE(0x0411, 0x015d) }, + { USB_DEVICE(0x0411, 0x016f) }, + { USB_DEVICE(0x0411, 0x01a2) }, ++ { USB_DEVICE(0x0411, 0x01ee) }, + /* Corega */ + { USB_DEVICE(0x07aa, 0x002f) }, + { USB_DEVICE(0x07aa, 0x003c) }, +@@ -1137,6 +1155,8 @@ static struct usb_device_id rt2800usb_device_table[] = { + #ifdef CONFIG_RT2800USB_RT33XX + /* Belkin */ + { USB_DEVICE(0x050d, 0x945b) }, ++ /* D-Link */ ++ { USB_DEVICE(0x2001, 0x3c17) }, + /* Panasonic */ + { USB_DEVICE(0x083a, 0xb511) }, + /* Philips */ +@@ -1154,6 +1174,8 @@ static struct usb_device_id rt2800usb_device_table[] = { + { USB_DEVICE(0x1690, 0x0744) }, + { USB_DEVICE(0x1690, 0x0761) }, + { USB_DEVICE(0x1690, 0x0764) }, ++ /* ASUS */ ++ { USB_DEVICE(0x0b05, 0x179d) }, + /* Cisco */ + { USB_DEVICE(0x167b, 0x4001) }, + /* EnGenius */ +@@ -1219,7 +1241,6 @@ static struct usb_device_id rt2800usb_device_table[] = { + { USB_DEVICE(0x0b05, 0x1760) }, + { USB_DEVICE(0x0b05, 0x1761) }, + { USB_DEVICE(0x0b05, 0x1790) }, +- { USB_DEVICE(0x0b05, 0x179d) }, + /* AzureWave */ + { USB_DEVICE(0x13d3, 0x3262) }, + { USB_DEVICE(0x13d3, 0x3284) }, +@@ -1237,7 +1258,6 @@ static struct usb_device_id rt2800usb_device_table[] = { + /* D-Link */ + { USB_DEVICE(0x07d1, 0x3c0b) }, + { USB_DEVICE(0x07d1, 0x3c17) }, +- { USB_DEVICE(0x2001, 0x3c17) }, + /* Encore */ + { USB_DEVICE(0x203d, 0x14a1) }, + /* Gemtek */ +diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c +index e5404e5..8ac4482 100644 +--- a/drivers/net/wireless/rt2x00/rt2x00dev.c ++++ b/drivers/net/wireless/rt2x00/rt2x00dev.c +@@ -629,7 +629,7 @@ void rt2x00lib_rxdone(struct queue_entry *entry, gfp_t gfp) + */ + if (unlikely(rxdesc.size == 0 || + rxdesc.size > entry->queue->data_size)) { +- WARNING(rt2x00dev, "Wrong frame size %d max %d.\n", ++ ERROR(rt2x00dev, "Wrong frame size %d max %d.\n", + rxdesc.size, entry->queue->data_size); + dev_kfree_skb(entry->skb); + goto renew_skb; +diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c +index ee22bd7..02ba3cf 100644 +--- a/drivers/net/wireless/rt2x00/rt61pci.c ++++ b/drivers/net/wireless/rt2x00/rt61pci.c +@@ -2243,8 +2243,7 @@ static void rt61pci_txdone(struct rt2x00_dev *rt2x00dev) + + static void rt61pci_wakeup(struct rt2x00_dev *rt2x00dev) + { +- struct ieee80211_conf conf = { .flags = 0 }; +- struct rt2x00lib_conf libconf = { .conf = &conf }; ++ struct rt2x00lib_conf libconf = { .conf = &rt2x00dev->hw->conf }; + + rt61pci_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS); + } +@@ -2833,6 +2832,7 @@ static int rt61pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev) + static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev) + { + int retval; ++ u32 reg; + + /* + * Disable power saving. +@@ -2851,6 +2851,14 @@ static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev) + return retval; + + /* ++ * Enable rfkill polling by setting GPIO direction of the ++ * rfkill switch GPIO pin correctly. ++ */ ++ rt2x00pci_register_read(rt2x00dev, MAC_CSR13, ®); ++ rt2x00_set_field32(®, MAC_CSR13_BIT13, 1); ++ rt2x00pci_register_write(rt2x00dev, MAC_CSR13, reg); ++ ++ /* + * Initialize hw specifications. + */ + retval = rt61pci_probe_hw_mode(rt2x00dev); +diff --git a/drivers/net/wireless/rt2x00/rt61pci.h b/drivers/net/wireless/rt2x00/rt61pci.h +index e3cd6db..8f3da5a 100644 +--- a/drivers/net/wireless/rt2x00/rt61pci.h ++++ b/drivers/net/wireless/rt2x00/rt61pci.h +@@ -372,6 +372,7 @@ struct hw_pairwise_ta_entry { + #define MAC_CSR13_BIT10 FIELD32(0x00000400) + #define MAC_CSR13_BIT11 FIELD32(0x00000800) + #define MAC_CSR13_BIT12 FIELD32(0x00001000) ++#define MAC_CSR13_BIT13 FIELD32(0x00002000) + + /* + * MAC_CSR14: LED control register. +diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c +index 77ccbbc..ceb1c4f 100644 +--- a/drivers/net/wireless/rt2x00/rt73usb.c ++++ b/drivers/net/wireless/rt2x00/rt73usb.c +@@ -2177,6 +2177,7 @@ static int rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev) + static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev) + { + int retval; ++ u32 reg; + + /* + * Allocate eeprom data. +@@ -2190,6 +2191,14 @@ static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev) + return retval; + + /* ++ * Enable rfkill polling by setting GPIO direction of the ++ * rfkill switch GPIO pin correctly. ++ */ ++ rt2x00usb_register_read(rt2x00dev, MAC_CSR13, ®); ++ rt2x00_set_field32(®, MAC_CSR13_BIT15, 0); ++ rt2x00usb_register_write(rt2x00dev, MAC_CSR13, reg); ++ ++ /* + * Initialize hw specifications. + */ + retval = rt73usb_probe_hw_mode(rt2x00dev); +diff --git a/drivers/net/wireless/rt2x00/rt73usb.h b/drivers/net/wireless/rt2x00/rt73usb.h +index 9f6b470..df1cc11 100644 +--- a/drivers/net/wireless/rt2x00/rt73usb.h ++++ b/drivers/net/wireless/rt2x00/rt73usb.h +@@ -282,6 +282,9 @@ struct hw_pairwise_ta_entry { + #define MAC_CSR13_BIT10 FIELD32(0x00000400) + #define MAC_CSR13_BIT11 FIELD32(0x00000800) + #define MAC_CSR13_BIT12 FIELD32(0x00001000) ++#define MAC_CSR13_BIT13 FIELD32(0x00002000) ++#define MAC_CSR13_BIT14 FIELD32(0x00004000) ++#define MAC_CSR13_BIT15 FIELD32(0x00008000) + + /* + * MAC_CSR14: LED control register. +diff --git a/drivers/net/wireless/rtl818x/rtl8187/dev.c b/drivers/net/wireless/rtl818x/rtl8187/dev.c +index 4fb1ca1..96bab89 100644 +--- a/drivers/net/wireless/rtl818x/rtl8187/dev.c ++++ b/drivers/net/wireless/rtl818x/rtl8187/dev.c +@@ -44,7 +44,7 @@ MODULE_AUTHOR("Larry Finger "); + MODULE_DESCRIPTION("RTL8187/RTL8187B USB wireless driver"); + MODULE_LICENSE("GPL"); + +-static struct usb_device_id rtl8187_table[] __devinitdata = { ++static struct usb_device_id rtl8187_table[] = { + /* Asus */ + {USB_DEVICE(0x0b05, 0x171d), .driver_info = DEVICE_RTL8187}, + /* Belkin */ +diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/def.h b/drivers/net/wireless/rtlwifi/rtl8192ce/def.h +index 04c3aef..2925094 100644 +--- a/drivers/net/wireless/rtlwifi/rtl8192ce/def.h ++++ b/drivers/net/wireless/rtlwifi/rtl8192ce/def.h +@@ -117,6 +117,7 @@ + + #define CHIP_VER_B BIT(4) + #define CHIP_92C_BITMASK BIT(0) ++#define CHIP_UNKNOWN BIT(7) + #define CHIP_92C_1T2R 0x03 + #define CHIP_92C 0x01 + #define CHIP_88C 0x00 +diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c +index 5c4d9bc..509f661 100644 +--- a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c ++++ b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c +@@ -995,8 +995,16 @@ static enum version_8192c _rtl92ce_read_chip_version(struct ieee80211_hw *hw) + version = (value32 & TYPE_ID) ? VERSION_A_CHIP_92C : + VERSION_A_CHIP_88C; + } else { +- version = (value32 & TYPE_ID) ? VERSION_B_CHIP_92C : +- VERSION_B_CHIP_88C; ++ version = (enum version_8192c) (CHIP_VER_B | ++ ((value32 & TYPE_ID) ? CHIP_92C_BITMASK : 0) | ++ ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0)); ++ if ((!IS_CHIP_VENDOR_UMC(version)) && (value32 & ++ CHIP_VER_RTL_MASK)) { ++ version = (enum version_8192c)(version | ++ ((((value32 & CHIP_VER_RTL_MASK) == BIT(12)) ++ ? CHIP_VENDOR_UMC_B_CUT : CHIP_UNKNOWN) | ++ CHIP_VENDOR_UMC)); ++ } + } + + switch (version) { +diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c +index 3aa927f..7d8f964 100644 +--- a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c ++++ b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c +@@ -162,10 +162,12 @@ int rtl92c_init_sw_vars(struct ieee80211_hw *hw) + + /* request fw */ + if (IS_VENDOR_UMC_A_CUT(rtlhal->version) && +- !IS_92C_SERIAL(rtlhal->version)) ++ !IS_92C_SERIAL(rtlhal->version)) { + rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cfwU.bin"; +- else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version)) ++ } else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version)) { + rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cfwU_B.bin"; ++ pr_info("****** This B_CUT device may not work with kernels 3.6 and earlier\n"); ++ } + + rtlpriv->max_fw_size = 0x4000; + pr_info("Using firmware %s\n", rtlpriv->cfg->fw_name); +diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/phy.c b/drivers/net/wireless/rtlwifi/rtl8192de/phy.c +index 18380a7..4420312 100644 +--- a/drivers/net/wireless/rtlwifi/rtl8192de/phy.c ++++ b/drivers/net/wireless/rtlwifi/rtl8192de/phy.c +@@ -3345,21 +3345,21 @@ void rtl92d_phy_config_macphymode_info(struct ieee80211_hw *hw) + switch (rtlhal->macphymode) { + case DUALMAC_SINGLEPHY: + rtlphy->rf_type = RF_2T2R; +- rtlhal->version |= CHIP_92D_SINGLEPHY; ++ rtlhal->version |= RF_TYPE_2T2R; + rtlhal->bandset = BAND_ON_BOTH; + rtlhal->current_bandtype = BAND_ON_2_4G; + break; + + case SINGLEMAC_SINGLEPHY: + rtlphy->rf_type = RF_2T2R; +- rtlhal->version |= CHIP_92D_SINGLEPHY; ++ rtlhal->version |= RF_TYPE_2T2R; + rtlhal->bandset = BAND_ON_BOTH; + rtlhal->current_bandtype = BAND_ON_2_4G; + break; + + case DUALMAC_DUALPHY: + rtlphy->rf_type = RF_1T1R; +- rtlhal->version &= (~CHIP_92D_SINGLEPHY); ++ rtlhal->version &= RF_TYPE_1T1R; + /* Now we let MAC0 run on 5G band. */ + if (rtlhal->interfaceindex == 0) { + rtlhal->bandset = BAND_ON_5G; +diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c +index a6049d7..aa970fc 100644 +--- a/drivers/net/wireless/rtlwifi/usb.c ++++ b/drivers/net/wireless/rtlwifi/usb.c +@@ -131,15 +131,19 @@ static u32 _usb_read_sync(struct rtl_priv *rtlpriv, u32 addr, u16 len) + u8 request; + u16 wvalue; + u16 index; +- __le32 *data = &rtlpriv->usb_data[rtlpriv->usb_data_index]; ++ __le32 *data; ++ unsigned long flags; + ++ spin_lock_irqsave(&rtlpriv->locks.usb_lock, flags); ++ if (++rtlpriv->usb_data_index >= RTL_USB_MAX_RX_COUNT) ++ rtlpriv->usb_data_index = 0; ++ data = &rtlpriv->usb_data[rtlpriv->usb_data_index]; ++ spin_unlock_irqrestore(&rtlpriv->locks.usb_lock, flags); + request = REALTEK_USB_VENQT_CMD_REQ; + index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */ + + wvalue = (u16)addr; + _usbctrl_vendorreq_sync_read(udev, request, wvalue, index, data, len); +- if (++rtlpriv->usb_data_index >= RTL_USB_MAX_RX_COUNT) +- rtlpriv->usb_data_index = 0; + return le32_to_cpu(*data); + } + +@@ -951,6 +955,10 @@ int __devinit rtl_usb_probe(struct usb_interface *intf, + GFP_KERNEL); + if (!rtlpriv->usb_data) + return -ENOMEM; ++ ++ /* this spin lock must be initialized early */ ++ spin_lock_init(&rtlpriv->locks.usb_lock); ++ + rtlpriv->usb_data_index = 0; + init_completion(&rtlpriv->firmware_loading_complete); + SET_IEEE80211_DEV(hw, &intf->dev); +diff --git a/drivers/net/wireless/rtlwifi/wifi.h b/drivers/net/wireless/rtlwifi/wifi.h +index bd816ae..cdaa21f 100644 +--- a/drivers/net/wireless/rtlwifi/wifi.h ++++ b/drivers/net/wireless/rtlwifi/wifi.h +@@ -1555,6 +1555,7 @@ struct rtl_locks { + spinlock_t rf_ps_lock; + spinlock_t rf_lock; + spinlock_t waitq_lock; ++ spinlock_t usb_lock; + + /*Dual mac*/ + spinlock_t cck_and_rw_pagea_lock; +diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c +index 806c44f..09bf377 100644 +--- a/drivers/pci/hotplug/acpiphp_glue.c ++++ b/drivers/pci/hotplug/acpiphp_glue.c +@@ -132,6 +132,15 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) + if (!acpi_pci_check_ejectable(pbus, handle) && !is_dock_device(handle)) + return AE_OK; + ++ status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); ++ if (ACPI_FAILURE(status)) { ++ warn("can't evaluate _ADR (%#x)\n", status); ++ return AE_OK; ++ } ++ ++ device = (adr >> 16) & 0xffff; ++ function = adr & 0xffff; ++ + pdev = pbus->self; + if (pdev && pci_is_pcie(pdev)) { + tmp = acpi_find_root_bridge_handle(pdev); +@@ -144,10 +153,6 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) + } + } + +- acpi_evaluate_integer(handle, "_ADR", NULL, &adr); +- device = (adr >> 16) & 0xffff; +- function = adr & 0xffff; +- + newfunc = kzalloc(sizeof(struct acpiphp_func), GFP_KERNEL); + if (!newfunc) + return AE_NO_MEMORY; +diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c +index 099f46c..3389387 100644 +--- a/drivers/pci/pci-driver.c ++++ b/drivers/pci/pci-driver.c +@@ -958,6 +958,13 @@ static int pci_pm_poweroff_noirq(struct device *dev) + if (!pci_dev->state_saved && !pci_is_bridge(pci_dev)) + pci_prepare_to_sleep(pci_dev); + ++ /* ++ * The reason for doing this here is the same as for the analogous code ++ * in pci_pm_suspend_noirq(). ++ */ ++ if (pci_dev->class == PCI_CLASS_SERIAL_USB_EHCI) ++ pci_write_config_word(pci_dev, PCI_COMMAND, 0); ++ + return 0; + } + +diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c +index 658ac97..9319aa1 100644 +--- a/drivers/pci/probe.c ++++ b/drivers/pci/probe.c +@@ -684,8 +684,10 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, + + /* Check if setup is sensible at all */ + if (!pass && +- (primary != bus->number || secondary <= bus->number)) { +- dev_dbg(&dev->dev, "bus configuration invalid, reconfiguring\n"); ++ (primary != bus->number || secondary <= bus->number || ++ secondary > subordinate)) { ++ dev_info(&dev->dev, "bridge configuration invalid ([bus %02x-%02x]), reconfiguring\n", ++ secondary, subordinate); + broken = 1; + } + +diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c +index e38f91b..110c777 100644 +--- a/drivers/platform/x86/asus-laptop.c ++++ b/drivers/platform/x86/asus-laptop.c +@@ -863,9 +863,9 @@ static ssize_t show_infos(struct device *dev, + * The significance of others is yet to be found. + * If we don't find the method, we assume the device are present. + */ +- rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp); ++ rv = acpi_evaluate_integer(asus->handle, "HWRS", NULL, &temp); + if (!ACPI_FAILURE(rv)) +- len += sprintf(page + len, "HRWS value : %#x\n", ++ len += sprintf(page + len, "HWRS value : %#x\n", + (uint) temp); + /* + * Another value for userspace: the ASYM method returns 0x02 for +@@ -1751,9 +1751,9 @@ static int asus_laptop_get_info(struct asus_laptop *asus) + * The significance of others is yet to be found. + */ + status = +- acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result); ++ acpi_evaluate_integer(asus->handle, "HWRS", NULL, &hwrs_result); + if (!ACPI_FAILURE(status)) +- pr_notice(" HRWS returned %x", (int)hwrs_result); ++ pr_notice(" HWRS returned %x", (int)hwrs_result); + + if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL)) + asus->have_rsts = true; +diff --git a/drivers/platform/x86/asus-nb-wmi.c b/drivers/platform/x86/asus-nb-wmi.c +index 99a30b5..6de14fd 100644 +--- a/drivers/platform/x86/asus-nb-wmi.c ++++ b/drivers/platform/x86/asus-nb-wmi.c +@@ -94,6 +94,10 @@ static const struct key_entry asus_nb_wmi_keymap[] = { + { KE_KEY, 0x8A, { KEY_PROG1 } }, + { KE_KEY, 0x95, { KEY_MEDIA } }, + { KE_KEY, 0x99, { KEY_PHONE } }, ++ { KE_KEY, 0xA0, { KEY_SWITCHVIDEOMODE } }, /* SDSP HDMI only */ ++ { KE_KEY, 0xA1, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + HDMI */ ++ { KE_KEY, 0xA2, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT + HDMI */ ++ { KE_KEY, 0xA3, { KEY_SWITCHVIDEOMODE } }, /* SDSP TV + HDMI */ + { KE_KEY, 0xb5, { KEY_CALC } }, + { KE_KEY, 0xc4, { KEY_KBDILLUMUP } }, + { KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } }, +diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c +index 77aadde..556cbb4 100644 +--- a/drivers/platform/x86/asus-wmi.c ++++ b/drivers/platform/x86/asus-wmi.c +@@ -1467,14 +1467,9 @@ static int asus_wmi_platform_init(struct asus_wmi *asus) + */ + if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, 0, 0, NULL)) + asus->dsts_id = ASUS_WMI_METHODID_DSTS; +- else if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS2, 0, 0, NULL)) ++ else + asus->dsts_id = ASUS_WMI_METHODID_DSTS2; + +- if (!asus->dsts_id) { +- pr_err("Can't find DSTS"); +- return -ENODEV; +- } +- + /* CWAP allow to define the behavior of the Fn+F2 key, + * this method doesn't seems to be present on Eee PCs */ + if (asus->driver->quirks->wapf >= 0) +diff --git a/drivers/rapidio/devices/tsi721.c b/drivers/rapidio/devices/tsi721.c +index 722246c..5d44252 100644 +--- a/drivers/rapidio/devices/tsi721.c ++++ b/drivers/rapidio/devices/tsi721.c +@@ -435,6 +435,9 @@ static void tsi721_db_dpc(struct work_struct *work) + " info %4.4x\n", DBELL_SID(idb.bytes), + DBELL_TID(idb.bytes), DBELL_INF(idb.bytes)); + } ++ ++ wr_ptr = ioread32(priv->regs + ++ TSI721_IDQ_WP(IDB_QUEUE)) % IDB_QSIZE; + } + + iowrite32(rd_ptr & (IDB_QSIZE - 1), +@@ -445,6 +448,10 @@ static void tsi721_db_dpc(struct work_struct *work) + regval |= TSI721_SR_CHINT_IDBQRCV; + iowrite32(regval, + priv->regs + TSI721_SR_CHINTE(IDB_QUEUE)); ++ ++ wr_ptr = ioread32(priv->regs + TSI721_IDQ_WP(IDB_QUEUE)) % IDB_QSIZE; ++ if (wr_ptr != rd_ptr) ++ schedule_work(&priv->idb_work); + } + + /** +@@ -2212,7 +2219,7 @@ static int __devinit tsi721_probe(struct pci_dev *pdev, + const struct pci_device_id *id) + { + struct tsi721_device *priv; +- int i, cap; ++ int cap; + int err; + u32 regval; + +@@ -2232,12 +2239,15 @@ static int __devinit tsi721_probe(struct pci_dev *pdev, + priv->pdev = pdev; + + #ifdef DEBUG ++ { ++ int i; + for (i = 0; i <= PCI_STD_RESOURCE_END; i++) { + dev_dbg(&pdev->dev, "res[%d] @ 0x%llx (0x%lx, 0x%lx)\n", + i, (unsigned long long)pci_resource_start(pdev, i), + (unsigned long)pci_resource_len(pdev, i), + pci_resource_flags(pdev, i)); + } ++ } + #endif + /* + * Verify BAR configuration +diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c +index c739071..7a2d26f 100644 +--- a/drivers/regulator/twl-regulator.c ++++ b/drivers/regulator/twl-regulator.c +@@ -1065,7 +1065,7 @@ TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300); + TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300); + TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300); + TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300); +-TWL4030_FIXED_LDO(VINTANA2, 0x3f, 1500, 11, 100, 0x08); ++TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08); + TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08); + TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08); + TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08); +@@ -1146,7 +1146,7 @@ static const struct of_device_id twl_of_match[] __devinitconst = { + TWL6025_OF_MATCH("ti,twl6025-ldo6", LDO6), + TWL6025_OF_MATCH("ti,twl6025-ldoln", LDOLN), + TWL6025_OF_MATCH("ti,twl6025-ldousb", LDOUSB), +- TWLFIXED_OF_MATCH("ti,twl4030-vintana2", VINTANA2), ++ TWLFIXED_OF_MATCH("ti,twl4030-vintana1", VINTANA1), + TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG), + TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5), + TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8), +diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig +index f8d818a..811ff72 100644 +--- a/drivers/remoteproc/Kconfig ++++ b/drivers/remoteproc/Kconfig +@@ -5,6 +5,7 @@ config REMOTEPROC + tristate + depends on EXPERIMENTAL + select FW_CONFIG ++ select VIRTIO + + config OMAP_REMOTEPROC + tristate "OMAP remoteproc support" +diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c +index 66324ee..99b6ee7 100644 +--- a/drivers/remoteproc/remoteproc_core.c ++++ b/drivers/remoteproc/remoteproc_core.c +@@ -643,17 +643,10 @@ static int rproc_handle_carveout(struct rproc *rproc, + dev_dbg(dev, "carveout rsc: da %x, pa %x, len %x, flags %x\n", + rsc->da, rsc->pa, rsc->len, rsc->flags); + +- mapping = kzalloc(sizeof(*mapping), GFP_KERNEL); +- if (!mapping) { +- dev_err(dev, "kzalloc mapping failed\n"); +- return -ENOMEM; +- } +- + carveout = kzalloc(sizeof(*carveout), GFP_KERNEL); + if (!carveout) { + dev_err(dev, "kzalloc carveout failed\n"); +- ret = -ENOMEM; +- goto free_mapping; ++ return -ENOMEM; + } + + va = dma_alloc_coherent(dev, rsc->len, &dma, GFP_KERNEL); +@@ -683,11 +676,18 @@ static int rproc_handle_carveout(struct rproc *rproc, + * physical address in this case. + */ + if (rproc->domain) { ++ mapping = kzalloc(sizeof(*mapping), GFP_KERNEL); ++ if (!mapping) { ++ dev_err(dev, "kzalloc mapping failed\n"); ++ ret = -ENOMEM; ++ goto dma_free; ++ } ++ + ret = iommu_map(rproc->domain, rsc->da, dma, rsc->len, + rsc->flags); + if (ret) { + dev_err(dev, "iommu_map failed: %d\n", ret); +- goto dma_free; ++ goto free_mapping; + } + + /* +@@ -728,12 +728,12 @@ static int rproc_handle_carveout(struct rproc *rproc, + + return 0; + ++free_mapping: ++ kfree(mapping); + dma_free: + dma_free_coherent(dev, rsc->len, va, dma); + free_carv: + kfree(carveout); +-free_mapping: +- kfree(mapping); + return ret; + } + +diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c +index 77074cc..fd5c7af 100644 +--- a/drivers/rtc/rtc-rs5c348.c ++++ b/drivers/rtc/rtc-rs5c348.c +@@ -122,9 +122,12 @@ rs5c348_rtc_read_time(struct device *dev, struct rtc_time *tm) + tm->tm_min = bcd2bin(rxbuf[RS5C348_REG_MINS] & RS5C348_MINS_MASK); + tm->tm_hour = bcd2bin(rxbuf[RS5C348_REG_HOURS] & RS5C348_HOURS_MASK); + if (!pdata->rtc_24h) { +- tm->tm_hour %= 12; +- if (rxbuf[RS5C348_REG_HOURS] & RS5C348_BIT_PM) ++ if (rxbuf[RS5C348_REG_HOURS] & RS5C348_BIT_PM) { ++ tm->tm_hour -= 20; ++ tm->tm_hour %= 12; + tm->tm_hour += 12; ++ } else ++ tm->tm_hour %= 12; + } + tm->tm_wday = bcd2bin(rxbuf[RS5C348_REG_WDAY] & RS5C348_WDAY_MASK); + tm->tm_mday = bcd2bin(rxbuf[RS5C348_REG_DAY] & RS5C348_DAY_MASK); +diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c +index c5d06fe..9277d94 100644 +--- a/drivers/rtc/rtc-twl.c ++++ b/drivers/rtc/rtc-twl.c +@@ -495,6 +495,11 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev) + if (ret < 0) + goto out1; + ++ /* ensure interrupts are disabled, bootloaders can be strange */ ++ ret = twl_rtc_write_u8(0, REG_RTC_INTERRUPTS_REG); ++ if (ret < 0) ++ dev_warn(&pdev->dev, "unable to disable interrupt\n"); ++ + /* init cached IRQ enable bits */ + ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG); + if (ret < 0) +diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c +index 59c6245..ea5c6f8 100644 +--- a/drivers/rtc/rtc-wm831x.c ++++ b/drivers/rtc/rtc-wm831x.c +@@ -24,7 +24,7 @@ + #include + #include + #include +- ++#include + + /* + * R16416 (0x4020) - RTC Write Counter +@@ -96,6 +96,26 @@ struct wm831x_rtc { + unsigned int alarm_enabled:1; + }; + ++static void wm831x_rtc_add_randomness(struct wm831x *wm831x) ++{ ++ int ret; ++ u16 reg; ++ ++ /* ++ * The write counter contains a pseudo-random number which is ++ * regenerated every time we set the RTC so it should be a ++ * useful per-system source of entropy. ++ */ ++ ret = wm831x_reg_read(wm831x, WM831X_RTC_WRITE_COUNTER); ++ if (ret >= 0) { ++ reg = ret; ++ add_device_randomness(®, sizeof(reg)); ++ } else { ++ dev_warn(wm831x->dev, "Failed to read RTC write counter: %d\n", ++ ret); ++ } ++} ++ + /* + * Read current time and date in RTC + */ +@@ -431,6 +451,8 @@ static int wm831x_rtc_probe(struct platform_device *pdev) + alm_irq, ret); + } + ++ wm831x_rtc_add_randomness(wm831x); ++ + return 0; + + err: +diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c +index 7be5e97..c390c91 100644 +--- a/drivers/s390/net/qeth_l3_main.c ++++ b/drivers/s390/net/qeth_l3_main.c +@@ -1760,6 +1760,8 @@ static void qeth_l3_free_vlan_addresses4(struct qeth_card *card, + QETH_CARD_TEXT(card, 4, "frvaddr4"); + + netdev = __vlan_find_dev_deep(card->dev, vid); ++ if (!netdev) ++ return; + in_dev = in_dev_get(netdev); + if (!in_dev) + return; +@@ -1788,6 +1790,8 @@ static void qeth_l3_free_vlan_addresses6(struct qeth_card *card, + QETH_CARD_TEXT(card, 4, "frvaddr6"); + + netdev = __vlan_find_dev_deep(card->dev, vid); ++ if (!netdev) ++ return; + in6_dev = in6_dev_get(netdev); + if (!in6_dev) + return; +diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c +index 0860181..4f1b10b 100644 +--- a/drivers/s390/scsi/zfcp_aux.c ++++ b/drivers/s390/scsi/zfcp_aux.c +@@ -519,6 +519,7 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn, + + rwlock_init(&port->unit_list_lock); + INIT_LIST_HEAD(&port->unit_list); ++ atomic_set(&port->units, 0); + + INIT_WORK(&port->gid_pn_work, zfcp_fc_port_did_lookup); + INIT_WORK(&port->test_link_work, zfcp_fc_link_test_work); +diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c +index 96f13ad8..79a6afe 100644 +--- a/drivers/s390/scsi/zfcp_ccw.c ++++ b/drivers/s390/scsi/zfcp_ccw.c +@@ -39,17 +39,23 @@ void zfcp_ccw_adapter_put(struct zfcp_adapter *adapter) + spin_unlock_irqrestore(&zfcp_ccw_adapter_ref_lock, flags); + } + +-static int zfcp_ccw_activate(struct ccw_device *cdev) +- ++/** ++ * zfcp_ccw_activate - activate adapter and wait for it to finish ++ * @cdev: pointer to belonging ccw device ++ * @clear: Status flags to clear. ++ * @tag: s390dbf trace record tag ++ */ ++static int zfcp_ccw_activate(struct ccw_device *cdev, int clear, char *tag) + { + struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); + + if (!adapter) + return 0; + ++ zfcp_erp_clear_adapter_status(adapter, clear); + zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING); + zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, +- "ccresu2"); ++ tag); + zfcp_erp_wait(adapter); + flush_work(&adapter->scan_work); + +@@ -164,26 +170,29 @@ static int zfcp_ccw_set_online(struct ccw_device *cdev) + BUG_ON(!zfcp_reqlist_isempty(adapter->req_list)); + adapter->req_no = 0; + +- zfcp_ccw_activate(cdev); ++ zfcp_ccw_activate(cdev, 0, "ccsonl1"); + zfcp_ccw_adapter_put(adapter); + return 0; + } + + /** +- * zfcp_ccw_set_offline - set_offline function of zfcp driver ++ * zfcp_ccw_offline_sync - shut down adapter and wait for it to finish + * @cdev: pointer to belonging ccw device ++ * @set: Status flags to set. ++ * @tag: s390dbf trace record tag + * + * This function gets called by the common i/o layer and sets an adapter + * into state offline. + */ +-static int zfcp_ccw_set_offline(struct ccw_device *cdev) ++static int zfcp_ccw_offline_sync(struct ccw_device *cdev, int set, char *tag) + { + struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); + + if (!adapter) + return 0; + +- zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1"); ++ zfcp_erp_set_adapter_status(adapter, set); ++ zfcp_erp_adapter_shutdown(adapter, 0, tag); + zfcp_erp_wait(adapter); + + zfcp_ccw_adapter_put(adapter); +@@ -191,6 +200,18 @@ static int zfcp_ccw_set_offline(struct ccw_device *cdev) + } + + /** ++ * zfcp_ccw_set_offline - set_offline function of zfcp driver ++ * @cdev: pointer to belonging ccw device ++ * ++ * This function gets called by the common i/o layer and sets an adapter ++ * into state offline. ++ */ ++static int zfcp_ccw_set_offline(struct ccw_device *cdev) ++{ ++ return zfcp_ccw_offline_sync(cdev, 0, "ccsoff1"); ++} ++ ++/** + * zfcp_ccw_notify - ccw notify function + * @cdev: pointer to belonging ccw device + * @event: indicates if adapter was detached or attached +@@ -207,6 +228,11 @@ static int zfcp_ccw_notify(struct ccw_device *cdev, int event) + + switch (event) { + case CIO_GONE: ++ if (atomic_read(&adapter->status) & ++ ZFCP_STATUS_ADAPTER_SUSPENDED) { /* notification ignore */ ++ zfcp_dbf_hba_basic("ccnigo1", adapter); ++ break; ++ } + dev_warn(&cdev->dev, "The FCP device has been detached\n"); + zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1"); + break; +@@ -216,6 +242,11 @@ static int zfcp_ccw_notify(struct ccw_device *cdev, int event) + zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2"); + break; + case CIO_OPER: ++ if (atomic_read(&adapter->status) & ++ ZFCP_STATUS_ADAPTER_SUSPENDED) { /* notification ignore */ ++ zfcp_dbf_hba_basic("ccniop1", adapter); ++ break; ++ } + dev_info(&cdev->dev, "The FCP device is operational again\n"); + zfcp_erp_set_adapter_status(adapter, + ZFCP_STATUS_COMMON_RUNNING); +@@ -251,6 +282,28 @@ static void zfcp_ccw_shutdown(struct ccw_device *cdev) + zfcp_ccw_adapter_put(adapter); + } + ++static int zfcp_ccw_suspend(struct ccw_device *cdev) ++{ ++ zfcp_ccw_offline_sync(cdev, ZFCP_STATUS_ADAPTER_SUSPENDED, "ccsusp1"); ++ return 0; ++} ++ ++static int zfcp_ccw_thaw(struct ccw_device *cdev) ++{ ++ /* trace records for thaw and final shutdown during suspend ++ can only be found in system dump until the end of suspend ++ but not after resume because it's based on the memory image ++ right after the very first suspend (freeze) callback */ ++ zfcp_ccw_activate(cdev, 0, "ccthaw1"); ++ return 0; ++} ++ ++static int zfcp_ccw_resume(struct ccw_device *cdev) ++{ ++ zfcp_ccw_activate(cdev, ZFCP_STATUS_ADAPTER_SUSPENDED, "ccresu1"); ++ return 0; ++} ++ + struct ccw_driver zfcp_ccw_driver = { + .driver = { + .owner = THIS_MODULE, +@@ -263,7 +316,7 @@ struct ccw_driver zfcp_ccw_driver = { + .set_offline = zfcp_ccw_set_offline, + .notify = zfcp_ccw_notify, + .shutdown = zfcp_ccw_shutdown, +- .freeze = zfcp_ccw_set_offline, +- .thaw = zfcp_ccw_activate, +- .restore = zfcp_ccw_activate, ++ .freeze = zfcp_ccw_suspend, ++ .thaw = zfcp_ccw_thaw, ++ .restore = zfcp_ccw_resume, + }; +diff --git a/drivers/s390/scsi/zfcp_cfdc.c b/drivers/s390/scsi/zfcp_cfdc.c +index fab2c25..8ed63aa 100644 +--- a/drivers/s390/scsi/zfcp_cfdc.c ++++ b/drivers/s390/scsi/zfcp_cfdc.c +@@ -293,7 +293,7 @@ void zfcp_cfdc_adapter_access_changed(struct zfcp_adapter *adapter) + } + read_unlock_irqrestore(&adapter->port_list_lock, flags); + +- shost_for_each_device(sdev, port->adapter->scsi_host) { ++ shost_for_each_device(sdev, adapter->scsi_host) { + zfcp_sdev = sdev_to_zfcp(sdev); + status = atomic_read(&zfcp_sdev->status); + if ((status & ZFCP_STATUS_COMMON_ACCESS_DENIED) || +diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c +index a9a816e..79b9848 100644 +--- a/drivers/s390/scsi/zfcp_dbf.c ++++ b/drivers/s390/scsi/zfcp_dbf.c +@@ -191,7 +191,7 @@ void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount, + length = min((u16)sizeof(struct qdio_buffer), + (u16)ZFCP_DBF_PAY_MAX_REC); + +- while ((char *)pl[payload->counter] && payload->counter < scount) { ++ while (payload->counter < scount && (char *)pl[payload->counter]) { + memcpy(payload->data, (char *)pl[payload->counter], length); + debug_event(dbf->pay, 1, payload, zfcp_dbf_plen(length)); + payload->counter++; +@@ -200,6 +200,26 @@ void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount, + spin_unlock_irqrestore(&dbf->pay_lock, flags); + } + ++/** ++ * zfcp_dbf_hba_basic - trace event for basic adapter events ++ * @adapter: pointer to struct zfcp_adapter ++ */ ++void zfcp_dbf_hba_basic(char *tag, struct zfcp_adapter *adapter) ++{ ++ struct zfcp_dbf *dbf = adapter->dbf; ++ struct zfcp_dbf_hba *rec = &dbf->hba_buf; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&dbf->hba_lock, flags); ++ memset(rec, 0, sizeof(*rec)); ++ ++ memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); ++ rec->id = ZFCP_DBF_HBA_BASIC; ++ ++ debug_event(dbf->hba, 1, rec, sizeof(*rec)); ++ spin_unlock_irqrestore(&dbf->hba_lock, flags); ++} ++ + static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec, + struct zfcp_adapter *adapter, + struct zfcp_port *port, +diff --git a/drivers/s390/scsi/zfcp_dbf.h b/drivers/s390/scsi/zfcp_dbf.h +index 714f087..3ac7a4b 100644 +--- a/drivers/s390/scsi/zfcp_dbf.h ++++ b/drivers/s390/scsi/zfcp_dbf.h +@@ -154,6 +154,7 @@ enum zfcp_dbf_hba_id { + ZFCP_DBF_HBA_RES = 1, + ZFCP_DBF_HBA_USS = 2, + ZFCP_DBF_HBA_BIT = 3, ++ ZFCP_DBF_HBA_BASIC = 4, + }; + + /** +diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h +index ed5d921..f172b84 100644 +--- a/drivers/s390/scsi/zfcp_def.h ++++ b/drivers/s390/scsi/zfcp_def.h +@@ -77,6 +77,7 @@ struct zfcp_reqlist; + #define ZFCP_STATUS_ADAPTER_SIOSL_ISSUED 0x00000004 + #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008 + #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010 ++#define ZFCP_STATUS_ADAPTER_SUSPENDED 0x00000040 + #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100 + #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200 + #define ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED 0x00000400 +@@ -204,6 +205,7 @@ struct zfcp_port { + struct zfcp_adapter *adapter; /* adapter used to access port */ + struct list_head unit_list; /* head of logical unit list */ + rwlock_t unit_list_lock; /* unit list lock */ ++ atomic_t units; /* zfcp_unit count */ + atomic_t status; /* status of this remote port */ + u64 wwnn; /* WWNN if known */ + u64 wwpn; /* WWPN */ +diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h +index 2302e1c..ef9e5022 100644 +--- a/drivers/s390/scsi/zfcp_ext.h ++++ b/drivers/s390/scsi/zfcp_ext.h +@@ -54,6 +54,7 @@ extern void zfcp_dbf_hba_fsf_res(char *, struct zfcp_fsf_req *); + extern void zfcp_dbf_hba_bit_err(char *, struct zfcp_fsf_req *); + extern void zfcp_dbf_hba_berr(struct zfcp_dbf *, struct zfcp_fsf_req *); + extern void zfcp_dbf_hba_def_err(struct zfcp_adapter *, u64, u16, void **); ++extern void zfcp_dbf_hba_basic(char *, struct zfcp_adapter *); + extern void zfcp_dbf_san_req(char *, struct zfcp_fsf_req *, u32); + extern void zfcp_dbf_san_res(char *, struct zfcp_fsf_req *); + extern void zfcp_dbf_san_in_els(char *, struct zfcp_fsf_req *); +@@ -158,6 +159,7 @@ extern void zfcp_scsi_dif_sense_error(struct scsi_cmnd *, int); + extern struct attribute_group zfcp_sysfs_unit_attrs; + extern struct attribute_group zfcp_sysfs_adapter_attrs; + extern struct attribute_group zfcp_sysfs_port_attrs; ++extern struct mutex zfcp_sysfs_port_units_mutex; + extern struct device_attribute *zfcp_sysfs_sdev_attrs[]; + extern struct device_attribute *zfcp_sysfs_shost_attrs[]; + +diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c +index e9a787e..2136fc2 100644 +--- a/drivers/s390/scsi/zfcp_fsf.c ++++ b/drivers/s390/scsi/zfcp_fsf.c +@@ -219,7 +219,7 @@ static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req) + return; + } + +- zfcp_dbf_hba_fsf_uss("fssrh_2", req); ++ zfcp_dbf_hba_fsf_uss("fssrh_4", req); + + switch (sr_buf->status_type) { + case FSF_STATUS_READ_PORT_CLOSED: +@@ -437,6 +437,34 @@ void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) + } + } + ++#define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0) ++#define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1) ++#define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2) ++#define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3) ++#define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4) ++#define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5) ++#define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15) ++ ++static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed) ++{ ++ u32 fdmi_speed = 0; ++ if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT) ++ fdmi_speed |= FC_PORTSPEED_1GBIT; ++ if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT) ++ fdmi_speed |= FC_PORTSPEED_2GBIT; ++ if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT) ++ fdmi_speed |= FC_PORTSPEED_4GBIT; ++ if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT) ++ fdmi_speed |= FC_PORTSPEED_10GBIT; ++ if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT) ++ fdmi_speed |= FC_PORTSPEED_8GBIT; ++ if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT) ++ fdmi_speed |= FC_PORTSPEED_16GBIT; ++ if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED) ++ fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED; ++ return fdmi_speed; ++} ++ + static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req) + { + struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config; +@@ -456,7 +484,8 @@ static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req) + fc_host_port_name(shost) = nsp->fl_wwpn; + fc_host_node_name(shost) = nsp->fl_wwnn; + fc_host_port_id(shost) = ntoh24(bottom->s_id); +- fc_host_speed(shost) = bottom->fc_link_speed; ++ fc_host_speed(shost) = ++ zfcp_fsf_convert_portspeed(bottom->fc_link_speed); + fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3; + + adapter->hydra_version = bottom->adapter_type; +@@ -580,7 +609,8 @@ static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req) + } else + fc_host_permanent_port_name(shost) = fc_host_port_name(shost); + fc_host_maxframe_size(shost) = bottom->maximum_frame_size; +- fc_host_supported_speeds(shost) = bottom->supported_speed; ++ fc_host_supported_speeds(shost) = ++ zfcp_fsf_convert_portspeed(bottom->supported_speed); + memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types, + FC_FC4_LIST_SIZE); + memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types, +@@ -771,12 +801,14 @@ out: + static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req) + { + struct scsi_device *sdev = req->data; +- struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); ++ struct zfcp_scsi_dev *zfcp_sdev; + union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual; + + if (req->status & ZFCP_STATUS_FSFREQ_ERROR) + return; + ++ zfcp_sdev = sdev_to_zfcp(sdev); ++ + switch (req->qtcb->header.fsf_status) { + case FSF_PORT_HANDLE_NOT_VALID: + if (fsq->word[0] == fsq->word[1]) { +@@ -885,7 +917,7 @@ static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req) + + switch (header->fsf_status) { + case FSF_GOOD: +- zfcp_dbf_san_res("fsscth1", req); ++ zfcp_dbf_san_res("fsscth2", req); + ct->status = 0; + break; + case FSF_SERVICE_CLASS_NOT_SUPPORTED: +@@ -1739,13 +1771,15 @@ static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req) + { + struct zfcp_adapter *adapter = req->adapter; + struct scsi_device *sdev = req->data; +- struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); ++ struct zfcp_scsi_dev *zfcp_sdev; + struct fsf_qtcb_header *header = &req->qtcb->header; + struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support; + + if (req->status & ZFCP_STATUS_FSFREQ_ERROR) + return; + ++ zfcp_sdev = sdev_to_zfcp(sdev); ++ + atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | + ZFCP_STATUS_COMMON_ACCESS_BOXED | + ZFCP_STATUS_LUN_SHARED | +@@ -1856,11 +1890,13 @@ out: + static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req) + { + struct scsi_device *sdev = req->data; +- struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); ++ struct zfcp_scsi_dev *zfcp_sdev; + + if (req->status & ZFCP_STATUS_FSFREQ_ERROR) + return; + ++ zfcp_sdev = sdev_to_zfcp(sdev); ++ + switch (req->qtcb->header.fsf_status) { + case FSF_PORT_HANDLE_NOT_VALID: + zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1"); +@@ -1950,7 +1986,7 @@ static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi) + { + struct fsf_qual_latency_info *lat_in; + struct latency_cont *lat = NULL; +- struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scsi->device); ++ struct zfcp_scsi_dev *zfcp_sdev; + struct zfcp_blk_drv_data blktrc; + int ticks = req->adapter->timer_ticks; + +@@ -1965,6 +2001,7 @@ static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi) + + if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA && + !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { ++ zfcp_sdev = sdev_to_zfcp(scsi->device); + blktrc.flags |= ZFCP_BLK_LAT_VALID; + blktrc.channel_lat = lat_in->channel_lat * ticks; + blktrc.fabric_lat = lat_in->fabric_lat * ticks; +@@ -2002,12 +2039,14 @@ static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req) + { + struct scsi_cmnd *scmnd = req->data; + struct scsi_device *sdev = scmnd->device; +- struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); ++ struct zfcp_scsi_dev *zfcp_sdev; + struct fsf_qtcb_header *header = &req->qtcb->header; + + if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) + return; + ++ zfcp_sdev = sdev_to_zfcp(sdev); ++ + switch (header->fsf_status) { + case FSF_HANDLE_MISMATCH: + case FSF_PORT_HANDLE_NOT_VALID: +diff --git a/drivers/s390/scsi/zfcp_qdio.c b/drivers/s390/scsi/zfcp_qdio.c +index e14da57..e76d003 100644 +--- a/drivers/s390/scsi/zfcp_qdio.c ++++ b/drivers/s390/scsi/zfcp_qdio.c +@@ -102,18 +102,22 @@ static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int qdio_err, + { + struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm; + struct zfcp_adapter *adapter = qdio->adapter; +- struct qdio_buffer_element *sbale; + int sbal_no, sbal_idx; +- void *pl[ZFCP_QDIO_MAX_SBALS_PER_REQ + 1]; +- u64 req_id; +- u8 scount; + + if (unlikely(qdio_err)) { +- memset(pl, 0, ZFCP_QDIO_MAX_SBALS_PER_REQ * sizeof(void *)); + if (zfcp_adapter_multi_buffer_active(adapter)) { ++ void *pl[ZFCP_QDIO_MAX_SBALS_PER_REQ + 1]; ++ struct qdio_buffer_element *sbale; ++ u64 req_id; ++ u8 scount; ++ ++ memset(pl, 0, ++ ZFCP_QDIO_MAX_SBALS_PER_REQ * sizeof(void *)); + sbale = qdio->res_q[idx]->element; + req_id = (u64) sbale->addr; +- scount = sbale->scount + 1; /* incl. signaling SBAL */ ++ scount = min(sbale->scount + 1, ++ ZFCP_QDIO_MAX_SBALS_PER_REQ + 1); ++ /* incl. signaling SBAL */ + + for (sbal_no = 0; sbal_no < scount; sbal_no++) { + sbal_idx = (idx + sbal_no) % +diff --git a/drivers/s390/scsi/zfcp_sysfs.c b/drivers/s390/scsi/zfcp_sysfs.c +index cdc4ff7..9e62210 100644 +--- a/drivers/s390/scsi/zfcp_sysfs.c ++++ b/drivers/s390/scsi/zfcp_sysfs.c +@@ -227,6 +227,8 @@ static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev, + static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL, + zfcp_sysfs_port_rescan_store); + ++DEFINE_MUTEX(zfcp_sysfs_port_units_mutex); ++ + static ssize_t zfcp_sysfs_port_remove_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +@@ -249,6 +251,16 @@ static ssize_t zfcp_sysfs_port_remove_store(struct device *dev, + else + retval = 0; + ++ mutex_lock(&zfcp_sysfs_port_units_mutex); ++ if (atomic_read(&port->units) > 0) { ++ retval = -EBUSY; ++ mutex_unlock(&zfcp_sysfs_port_units_mutex); ++ goto out; ++ } ++ /* port is about to be removed, so no more unit_add */ ++ atomic_set(&port->units, -1); ++ mutex_unlock(&zfcp_sysfs_port_units_mutex); ++ + write_lock_irq(&adapter->port_list_lock); + list_del(&port->list); + write_unlock_irq(&adapter->port_list_lock); +@@ -289,12 +301,14 @@ static ssize_t zfcp_sysfs_unit_add_store(struct device *dev, + { + struct zfcp_port *port = container_of(dev, struct zfcp_port, dev); + u64 fcp_lun; ++ int retval; + + if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun)) + return -EINVAL; + +- if (zfcp_unit_add(port, fcp_lun)) +- return -EINVAL; ++ retval = zfcp_unit_add(port, fcp_lun); ++ if (retval) ++ return retval; + + return count; + } +diff --git a/drivers/s390/scsi/zfcp_unit.c b/drivers/s390/scsi/zfcp_unit.c +index 20796eb..4e6a535 100644 +--- a/drivers/s390/scsi/zfcp_unit.c ++++ b/drivers/s390/scsi/zfcp_unit.c +@@ -104,7 +104,7 @@ static void zfcp_unit_release(struct device *dev) + { + struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev); + +- put_device(&unit->port->dev); ++ atomic_dec(&unit->port->units); + kfree(unit); + } + +@@ -119,16 +119,27 @@ static void zfcp_unit_release(struct device *dev) + int zfcp_unit_add(struct zfcp_port *port, u64 fcp_lun) + { + struct zfcp_unit *unit; ++ int retval = 0; ++ ++ mutex_lock(&zfcp_sysfs_port_units_mutex); ++ if (atomic_read(&port->units) == -1) { ++ /* port is already gone */ ++ retval = -ENODEV; ++ goto out; ++ } + + unit = zfcp_unit_find(port, fcp_lun); + if (unit) { + put_device(&unit->dev); +- return -EEXIST; ++ retval = -EEXIST; ++ goto out; + } + + unit = kzalloc(sizeof(struct zfcp_unit), GFP_KERNEL); +- if (!unit) +- return -ENOMEM; ++ if (!unit) { ++ retval = -ENOMEM; ++ goto out; ++ } + + unit->port = port; + unit->fcp_lun = fcp_lun; +@@ -139,28 +150,33 @@ int zfcp_unit_add(struct zfcp_port *port, u64 fcp_lun) + if (dev_set_name(&unit->dev, "0x%016llx", + (unsigned long long) fcp_lun)) { + kfree(unit); +- return -ENOMEM; ++ retval = -ENOMEM; ++ goto out; + } + +- get_device(&port->dev); +- + if (device_register(&unit->dev)) { + put_device(&unit->dev); +- return -ENOMEM; ++ retval = -ENOMEM; ++ goto out; + } + + if (sysfs_create_group(&unit->dev.kobj, &zfcp_sysfs_unit_attrs)) { + device_unregister(&unit->dev); +- return -EINVAL; ++ retval = -EINVAL; ++ goto out; + } + ++ atomic_inc(&port->units); /* under zfcp_sysfs_port_units_mutex ! */ ++ + write_lock_irq(&port->unit_list_lock); + list_add_tail(&unit->list, &port->unit_list); + write_unlock_irq(&port->unit_list_lock); + + zfcp_unit_scsi_scan(unit); + +- return 0; ++out: ++ mutex_unlock(&zfcp_sysfs_port_units_mutex); ++ return retval; + } + + /** +diff --git a/drivers/scsi/atp870u.c b/drivers/scsi/atp870u.c +index 68ce085..a540162 100644 +--- a/drivers/scsi/atp870u.c ++++ b/drivers/scsi/atp870u.c +@@ -1173,7 +1173,16 @@ wait_io1: + outw(val, tmport); + outb(2, 0x80); + TCM_SYNC: +- udelay(0x800); ++ /* ++ * The funny division into multiple delays is to accomodate ++ * arches like ARM where udelay() multiplies its argument by ++ * a large number to initialize a loop counter. To avoid ++ * overflow, the maximum supported udelay is 2000 microseconds. ++ * ++ * XXX it would be more polite to find a way to use msleep() ++ */ ++ mdelay(2); ++ udelay(48); + if ((inb(tmport) & 0x80) == 0x00) { /* bsy ? */ + outw(0, tmport--); + outb(0, tmport); +diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c +index 86a12b4..3878e62 100644 +--- a/drivers/scsi/bnx2i/bnx2i_hwi.c ++++ b/drivers/scsi/bnx2i/bnx2i_hwi.c +@@ -1264,6 +1264,9 @@ int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba) + int rc = 0; + u64 mask64; + ++ memset(&iscsi_init, 0x00, sizeof(struct iscsi_kwqe_init1)); ++ memset(&iscsi_init2, 0x00, sizeof(struct iscsi_kwqe_init2)); ++ + bnx2i_adjust_qp_size(hba); + + iscsi_init.flags = +diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c +index fda9cde..78c79cb 100644 +--- a/drivers/scsi/device_handler/scsi_dh_alua.c ++++ b/drivers/scsi/device_handler/scsi_dh_alua.c +@@ -590,8 +590,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_dh_data *h) + h->state = TPGS_STATE_STANDBY; + break; + case TPGS_STATE_OFFLINE: +- case TPGS_STATE_UNAVAILABLE: +- /* Path unusable for unavailable/offline */ ++ /* Path unusable */ + err = SCSI_DH_DEV_OFFLINED; + break; + default: +diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c +index a3a056a..b48c24f 100644 +--- a/drivers/scsi/hosts.c ++++ b/drivers/scsi/hosts.c +@@ -290,6 +290,7 @@ static void scsi_host_dev_release(struct device *dev) + struct Scsi_Host *shost = dev_to_shost(dev); + struct device *parent = dev->parent; + struct request_queue *q; ++ void *queuedata; + + scsi_proc_hostdir_rm(shost->hostt); + +@@ -299,9 +300,9 @@ static void scsi_host_dev_release(struct device *dev) + destroy_workqueue(shost->work_q); + q = shost->uspace_req_q; + if (q) { +- kfree(q->queuedata); +- q->queuedata = NULL; +- scsi_free_queue(q); ++ queuedata = q->queuedata; ++ blk_cleanup_queue(q); ++ kfree(queuedata); + } + + scsi_destroy_command_freelist(shost); +diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c +index 796482b..f9823f2 100644 +--- a/drivers/scsi/hpsa.c ++++ b/drivers/scsi/hpsa.c +@@ -1315,8 +1315,9 @@ static void complete_scsi_command(struct CommandList *cp) + } + break; + case CMD_PROTOCOL_ERR: ++ cmd->result = DID_ERROR << 16; + dev_warn(&h->pdev->dev, "cp %p has " +- "protocol error \n", cp); ++ "protocol error\n", cp); + break; + case CMD_HARDWARE_ERR: + cmd->result = DID_ERROR << 16; +@@ -3265,7 +3266,7 @@ static void fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h, + c->Request.Timeout = 0; /* Don't time out */ + memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); + c->Request.CDB[0] = cmd; +- c->Request.CDB[1] = 0x03; /* Reset target above */ ++ c->Request.CDB[1] = HPSA_RESET_TYPE_LUN; + /* If bytes 4-7 are zero, it means reset the */ + /* LunID device */ + c->Request.CDB[4] = 0x00; +diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c +index 3a6c474..337e8b3 100644 +--- a/drivers/scsi/ibmvscsi/ibmvscsi.c ++++ b/drivers/scsi/ibmvscsi/ibmvscsi.c +@@ -1541,6 +1541,9 @@ static int ibmvscsi_do_host_config(struct ibmvscsi_host_data *hostdata, + + host_config = &evt_struct->iu.mad.host_config; + ++ /* The transport length field is only 16-bit */ ++ length = min(0xffff, length); ++ + /* Set up a lun reset SRP command */ + memset(host_config, 0x00, sizeof(*host_config)); + host_config->common.type = VIOSRP_HOST_CONFIG_TYPE; +diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c +index 47e28b5..8870bd3 100644 +--- a/drivers/scsi/isci/init.c ++++ b/drivers/scsi/isci/init.c +@@ -641,7 +641,6 @@ static int __devinit isci_pci_probe(struct pci_dev *pdev, const struct pci_devic + orom->hdr.version)) { + dev_warn(&pdev->dev, + "[%d]: invalid oem parameters detected, falling back to firmware\n", i); +- devm_kfree(&pdev->dev, orom); + orom = NULL; + break; + } +diff --git a/drivers/scsi/isci/probe_roms.c b/drivers/scsi/isci/probe_roms.c +index 4d95654..8ac646e 100644 +--- a/drivers/scsi/isci/probe_roms.c ++++ b/drivers/scsi/isci/probe_roms.c +@@ -104,7 +104,6 @@ struct isci_orom *isci_request_oprom(struct pci_dev *pdev) + + if (i >= len) { + dev_err(&pdev->dev, "oprom parse error\n"); +- devm_kfree(&pdev->dev, rom); + rom = NULL; + } + pci_unmap_biosrom(oprom); +diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c +index caa0525..101b28e 100644 +--- a/drivers/scsi/libsas/sas_expander.c ++++ b/drivers/scsi/libsas/sas_expander.c +@@ -868,7 +868,7 @@ static struct domain_device *sas_ex_discover_end_dev( + } + + /* 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; +@@ -884,11 +884,11 @@ static int sas_ex_join_wide_port(struct domain_device *parent, int phy_id) + 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( +@@ -1030,8 +1030,7 @@ static int sas_ex_discover_dev(struct domain_device *dev, int phy_id) + 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; +@@ -1077,8 +1076,7 @@ static int sas_ex_discover_dev(struct domain_device *dev, int phy_id) + 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)); + +@@ -1943,32 +1941,20 @@ static int sas_discover_new(struct domain_device *dev, int phy_id) + { + 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)) { +@@ -1978,7 +1964,6 @@ static int sas_discover_new(struct domain_device *dev, int phy_id) + break; + } + } +-out: + return res; + } + +@@ -2109,9 +2094,7 @@ int sas_ex_revalidate_domain(struct domain_device *port_dev) + 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; + +@@ -2123,8 +2106,10 @@ int sas_ex_revalidate_domain(struct domain_device *port_dev) + 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 --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile +index fe5d396..e2516ba 100644 +--- a/drivers/scsi/lpfc/Makefile ++++ b/drivers/scsi/lpfc/Makefile +@@ -22,7 +22,9 @@ + ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage + ccflags-$(GCOV) += -O0 + ++ifdef WARNINGS_BECOME_ERRORS + ccflags-y += -Werror ++endif + + obj-$(CONFIG_SCSI_LPFC) := lpfc.o + +diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c +index dc27598..ed38454 100644 +--- a/drivers/scsi/megaraid/megaraid_sas_base.c ++++ b/drivers/scsi/megaraid/megaraid_sas_base.c +@@ -4066,7 +4066,6 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) + spin_lock_init(&instance->cmd_pool_lock); + spin_lock_init(&instance->hba_lock); + spin_lock_init(&instance->completion_lock); +- spin_lock_init(&poll_aen_lock); + + mutex_init(&instance->aen_mutex); + mutex_init(&instance->reset_mutex); +@@ -5392,6 +5391,8 @@ static int __init megasas_init(void) + printk(KERN_INFO "megasas: %s %s\n", MEGASAS_VERSION, + MEGASAS_EXT_VERSION); + ++ spin_lock_init(&poll_aen_lock); ++ + support_poll_for_event = 2; + support_device_change = 1; + +diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c b/drivers/scsi/mpt2sas/mpt2sas_base.c +index 9d46fcb..9d5a56c 100644 +--- a/drivers/scsi/mpt2sas/mpt2sas_base.c ++++ b/drivers/scsi/mpt2sas/mpt2sas_base.c +@@ -1209,6 +1209,13 @@ _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc) + u16 message_control; + + ++ /* Check whether controller SAS2008 B0 controller, ++ if it is SAS2008 B0 controller use IO-APIC instead of MSIX */ ++ if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 && ++ ioc->pdev->revision == 0x01) { ++ return -EINVAL; ++ } ++ + base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX); + if (!base) { + dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not " +@@ -2424,10 +2431,13 @@ _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) + } + + /* command line tunables for max controller queue depth */ +- if (max_queue_depth != -1) +- max_request_credit = (max_queue_depth < facts->RequestCredit) +- ? max_queue_depth : facts->RequestCredit; +- else ++ if (max_queue_depth != -1 && max_queue_depth != 0) { ++ max_request_credit = min_t(u16, max_queue_depth + ++ ioc->hi_priority_depth + ioc->internal_depth, ++ facts->RequestCredit); ++ if (max_request_credit > MAX_HBA_QUEUE_DEPTH) ++ max_request_credit = MAX_HBA_QUEUE_DEPTH; ++ } else + max_request_credit = min_t(u16, facts->RequestCredit, + MAX_HBA_QUEUE_DEPTH); + +@@ -2502,7 +2512,7 @@ _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) + /* set the scsi host can_queue depth + * with some internal commands that could be outstanding + */ +- ioc->shost->can_queue = ioc->scsiio_depth - (2); ++ ioc->shost->can_queue = ioc->scsiio_depth; + dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: " + "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue)); + +diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c +index d0f71e5..f21f0ee 100644 +--- a/drivers/scsi/scsi_error.c ++++ b/drivers/scsi/scsi_error.c +@@ -42,6 +42,8 @@ + + #include + ++static void scsi_eh_done(struct scsi_cmnd *scmd); ++ + #define SENSE_TIMEOUT (10*HZ) + + /* +@@ -241,6 +243,14 @@ static int scsi_check_sense(struct scsi_cmnd *scmd) + if (! scsi_command_normalize_sense(scmd, &sshdr)) + return FAILED; /* no valid sense data */ + ++ if (scmd->cmnd[0] == TEST_UNIT_READY && scmd->scsi_done != scsi_eh_done) ++ /* ++ * nasty: for mid-layer issued TURs, we need to return the ++ * actual sense data without any recovery attempt. For eh ++ * issued ones, we need to try to recover and interpret ++ */ ++ return SUCCESS; ++ + if (scsi_sense_is_deferred(&sshdr)) + return NEEDS_RETRY; + +@@ -1687,6 +1697,20 @@ static void scsi_restart_operations(struct Scsi_Host *shost) + * 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 --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c +index 6dfb978..dae3873 100644 +--- a/drivers/scsi/scsi_lib.c ++++ b/drivers/scsi/scsi_lib.c +@@ -406,10 +406,6 @@ static void scsi_run_queue(struct request_queue *q) + LIST_HEAD(starved_list); + unsigned long flags; + +- /* if the device is dead, sdev will be NULL, so no queue to run */ +- if (!sdev) +- return; +- + shost = sdev->host; + if (scsi_target(sdev)->single_lun) + scsi_single_lun_run(sdev); +@@ -483,15 +479,26 @@ void scsi_requeue_run_queue(struct work_struct *work) + */ + 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) +@@ -753,7 +760,6 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) + } + + if (req->cmd_type == REQ_TYPE_BLOCK_PC) { /* SG_IO ioctl from block level */ +- req->errors = result; + if (result) { + if (sense_valid && req->sense) { + /* +@@ -769,6 +775,10 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) + if (!sense_deferred) + error = __scsi_error_from_host_byte(cmd, result); + } ++ /* ++ * __scsi_error_from_host_byte may have reset the host_byte ++ */ ++ req->errors = cmd->result; + + req->resid_len = scsi_get_resid(cmd); + +@@ -1370,16 +1380,16 @@ static inline int scsi_host_queue_ready(struct request_queue *q, + * may be changed after request stacking drivers call the function, + * regardless of taking lock or not. + * +- * When scsi can't dispatch I/Os anymore and needs to kill I/Os +- * (e.g. !sdev), scsi needs to return 'not busy'. +- * Otherwise, request stacking drivers may hold requests forever. ++ * When scsi can't dispatch I/Os anymore and needs to kill I/Os scsi ++ * needs to return 'not busy'. Otherwise, request stacking drivers ++ * may hold requests forever. + */ + static int scsi_lld_busy(struct request_queue *q) + { + struct scsi_device *sdev = q->queuedata; + struct Scsi_Host *shost; + +- if (!sdev) ++ if (blk_queue_dead(q)) + return 0; + + shost = sdev->host; +@@ -1490,12 +1500,6 @@ static void scsi_request_fn(struct request_queue *q) + struct scsi_cmnd *cmd; + struct request *req; + +- if (!sdev) { +- while ((req = blk_peek_request(q)) != NULL) +- scsi_kill_request(req, q); +- return; +- } +- + if(!get_device(&sdev->sdev_gendev)) + /* We must be tearing the block queue down already */ + return; +@@ -1697,20 +1701,6 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev) + return q; + } + +-void scsi_free_queue(struct request_queue *q) +-{ +- unsigned long flags; +- +- WARN_ON(q->queuedata); +- +- /* cause scsi_request_fn() to kill all non-finished requests */ +- spin_lock_irqsave(q->queue_lock, flags); +- q->request_fn(q); +- spin_unlock_irqrestore(q->queue_lock, flags); +- +- blk_cleanup_queue(q); +-} +- + /* + * Function: scsi_block_requests() + * +diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h +index 07ce3f5..2b8d8b5 100644 +--- a/drivers/scsi/scsi_priv.h ++++ b/drivers/scsi/scsi_priv.h +@@ -84,7 +84,6 @@ extern void scsi_next_command(struct scsi_cmnd *cmd); + extern void scsi_io_completion(struct scsi_cmnd *, unsigned int); + extern void scsi_run_host_queues(struct Scsi_Host *shost); + extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev); +-extern void scsi_free_queue(struct request_queue *q); + extern int scsi_init_queue(void); + extern void scsi_exit_queue(void); + struct request_queue; +diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c +index 2e5fe58..61def02 100644 +--- a/drivers/scsi/scsi_scan.c ++++ b/drivers/scsi/scsi_scan.c +@@ -779,6 +779,16 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result, + sdev->model = (char *) (sdev->inquiry + 16); + sdev->rev = (char *) (sdev->inquiry + 32); + ++ if (strncmp(sdev->vendor, "ATA ", 8) == 0) { ++ /* ++ * sata emulation layer device. This is a hack to work around ++ * the SATL power management specifications which state that ++ * when the SATL detects the device has gone into standby ++ * mode, it shall respond with NOT READY. ++ */ ++ sdev->allow_restart = 1; ++ } ++ + if (*bflags & BLIST_ISROM) { + sdev->type = TYPE_ROM; + sdev->removable = 1; +@@ -1717,6 +1727,9 @@ static void scsi_sysfs_add_devices(struct Scsi_Host *shost) + { + 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 --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c +index 04c2a27..08d48a3 100644 +--- a/drivers/scsi/scsi_sysfs.c ++++ b/drivers/scsi/scsi_sysfs.c +@@ -971,11 +971,8 @@ void __scsi_remove_device(struct scsi_device *sdev) + sdev->host->hostt->slave_destroy(sdev); + transport_destroy_device(dev); + +- /* cause the request function to reject all I/O requests */ +- sdev->request_queue->queuedata = NULL; +- + /* Freeing the queue signals to block that we're done */ +- scsi_free_queue(sdev->request_queue); ++ blk_cleanup_queue(sdev->request_queue); + put_device(dev); + } + +@@ -1000,7 +997,6 @@ static void __scsi_remove_target(struct scsi_target *starget) + 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 || +@@ -1014,14 +1010,6 @@ static void __scsi_remove_target(struct scsi_target *starget) + 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; + } + + /** +@@ -1034,14 +1022,32 @@ static int __remove_child (struct device * dev, void * data) + */ + 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, *last = NULL; ++ unsigned long flags; ++ ++ /* remove targets being careful to lookup next entry before ++ * deleting the last ++ */ ++ 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) { ++ /* assuming new targets arrive at the end */ ++ starget->reap_ref++; ++ spin_unlock_irqrestore(shost->host_lock, flags); ++ if (last) ++ scsi_target_reap(last); ++ last = starget; ++ __scsi_remove_target(starget); ++ spin_lock_irqsave(shost->host_lock, flags); ++ } + } ++ spin_unlock_irqrestore(shost->host_lock, flags); + +- get_device(dev); +- device_for_each_child(dev, NULL, __remove_child); +- put_device(dev); ++ if (last) ++ scsi_target_reap(last); + } + EXPORT_SYMBOL(scsi_remove_target); + +diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c +index 1b38431..6661610 100644 +--- a/drivers/scsi/virtio_scsi.c ++++ b/drivers/scsi/virtio_scsi.c +@@ -198,7 +198,7 @@ static void virtscsi_map_sgl(struct scatterlist *sg, unsigned int *p_idx, + int i; + + for_each_sg(table->sgl, sg_elem, table->nents, i) +- sg_set_buf(&sg[idx++], sg_virt(sg_elem), sg_elem->length); ++ sg[idx++] = *sg_elem; + + *p_idx = idx; + } +diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c +index 400ae21..469eb28 100644 +--- a/drivers/spi/spi-pl022.c ++++ b/drivers/spi/spi-pl022.c +@@ -489,6 +489,11 @@ static void giveback(struct pl022 *pl022) + pl022->cur_transfer = NULL; + pl022->cur_chip = NULL; + spi_finalize_current_message(pl022->master); ++ ++ /* disable the SPI/SSP operation */ ++ writew((readw(SSP_CR1(pl022->virtbase)) & ++ (~SSP_CR1_MASK_SSE)), SSP_CR1(pl022->virtbase)); ++ + } + + /** +diff --git a/drivers/staging/android/android_alarm.h b/drivers/staging/android/android_alarm.h +index d0cafd6..f2ffd96 100644 +--- a/drivers/staging/android/android_alarm.h ++++ b/drivers/staging/android/android_alarm.h +@@ -51,10 +51,12 @@ enum android_alarm_return_flags { + #define ANDROID_ALARM_WAIT _IO('a', 1) + + #define ALARM_IOW(c, type, size) _IOW('a', (c) | ((type) << 4), size) ++#define ALARM_IOR(c, type, size) _IOR('a', (c) | ((type) << 4), size) ++ + /* Set alarm */ + #define ANDROID_ALARM_SET(type) ALARM_IOW(2, type, struct timespec) + #define ANDROID_ALARM_SET_AND_WAIT(type) ALARM_IOW(3, type, struct timespec) +-#define ANDROID_ALARM_GET_TIME(type) ALARM_IOW(4, type, struct timespec) ++#define ANDROID_ALARM_GET_TIME(type) ALARM_IOR(4, type, struct timespec) + #define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec) + #define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0))) + #define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4) +diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c +index 7677657..d77219a 100644 +--- a/drivers/staging/comedi/comedi_fops.c ++++ b/drivers/staging/comedi/comedi_fops.c +@@ -1132,7 +1132,7 @@ static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn, + ret = -EAGAIN; + break; + } +- ret = s->async->inttrig(dev, s, insn->data[0]); ++ ret = s->async->inttrig(dev, s, data[0]); + if (ret >= 0) + ret = 1; + break; +@@ -1377,7 +1377,6 @@ static int do_cmd_ioctl(struct comedi_device *dev, + goto cleanup; + } + +- kfree(async->cmd.chanlist); + async->cmd = user_cmd; + async->cmd.data = NULL; + /* load channel/gain list */ +@@ -2122,6 +2121,8 @@ void do_become_nonbusy(struct comedi_device *dev, struct comedi_subdevice *s) + if (async) { + comedi_reset_async_buf(async); + async->inttrig = NULL; ++ kfree(async->cmd.chanlist); ++ async->cmd.chanlist = NULL; + } else { + printk(KERN_ERR + "BUG: (?) do_become_nonbusy called with async=0\n"); +diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c +index aeac1ca..327c0ce 100644 +--- a/drivers/staging/comedi/drivers.c ++++ b/drivers/staging/comedi/drivers.c +@@ -144,7 +144,7 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) + dev->board_ptr = comedi_recognize(driv, it->board_name); + if (dev->board_ptr) + break; +- } else if (strcmp(driv->driver_name, it->board_name)) ++ } else if (strcmp(driv->driver_name, it->board_name) == 0) + break; + module_put(driv->module); + } +diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c +index fbf19ca..0def1be 100644 +--- a/drivers/staging/comedi/drivers/amplc_pci224.c ++++ b/drivers/staging/comedi/drivers/amplc_pci224.c +@@ -1519,6 +1519,13 @@ pci224_attach_pci(struct comedi_device *dev, struct pci_dev *pci_dev) + dev->minor, DRIVER_NAME); + return -EINVAL; + } ++ /* ++ * Need to 'get' the PCI device to match the 'put' in pci224_detach(). ++ * TODO: Remove the pci_dev_get() and matching pci_dev_put() once ++ * support for manual attachment of PCI devices via pci224_attach() ++ * has been removed. ++ */ ++ pci_dev_get(pci_dev); + return pci224_attach_common(dev, pci_dev, NULL); + } + +diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c +index 1f31943..83dae6e 100644 +--- a/drivers/staging/comedi/drivers/das08.c ++++ b/drivers/staging/comedi/drivers/das08.c +@@ -403,7 +403,7 @@ static const struct das08_board_struct das08_boards[] = { + .ai = das08_ai_rinsn, + .ai_nbits = 16, + .ai_pg = das08_pg_none, +- .ai_encoding = das08_encode12, ++ .ai_encoding = das08_encode16, + .ao = das08jr_ao_winsn, + .ao_nbits = 16, + .di = das08jr_di_rbits, +@@ -678,7 +678,7 @@ static int das08jr_ao_winsn(struct comedi_device *dev, + int chan; + + lsb = data[0] & 0xff; +- msb = (data[0] >> 8) & 0xf; ++ msb = (data[0] >> 8) & 0xff; + + chan = CR_CHAN(insn->chanspec); + +diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c +index d536a11..cf523e5 100644 +--- a/drivers/staging/comedi/drivers/jr3_pci.c ++++ b/drivers/staging/comedi/drivers/jr3_pci.c +@@ -883,7 +883,7 @@ static int jr3_pci_attach(struct comedi_device *dev, + } + + /* Reset DSP card */ +- devpriv->iobase->channel[0].reset = 0; ++ writel(0, &devpriv->iobase->channel[0].reset); + + result = comedi_load_firmware(dev, "jr3pci.idm", jr3_download_firmware); + dev_dbg(dev->hw_dev, "Firmare load %d\n", result); +diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c +index 7beb8f6..e68e474 100644 +--- a/drivers/staging/comedi/drivers/s626.c ++++ b/drivers/staging/comedi/drivers/s626.c +@@ -2311,7 +2311,7 @@ static int s626_enc_insn_config(struct comedi_device *dev, + /* (data==NULL) ? (Preloadvalue=0) : (Preloadvalue=data[0]); */ + + k->SetMode(dev, k, Setup, TRUE); +- Preload(dev, k, *(insn->data)); ++ Preload(dev, k, data[0]); + k->PulseIndex(dev, k); + SetLatchSource(dev, k, valueSrclatch); + k->SetEnable(dev, k, (uint16_t) (enab != 0)); +diff --git a/drivers/staging/media/lirc/lirc_sir.c b/drivers/staging/media/lirc/lirc_sir.c +index 945d962..4afc3b4 100644 +--- a/drivers/staging/media/lirc/lirc_sir.c ++++ b/drivers/staging/media/lirc/lirc_sir.c +@@ -52,6 +52,7 @@ + #include + #include + #include ++#include + #ifdef LIRC_ON_SA1100 + #include + #ifdef CONFIG_SA1100_COLLIE +@@ -487,9 +488,11 @@ static struct lirc_driver driver = { + .owner = THIS_MODULE, + }; + ++static struct platform_device *lirc_sir_dev; + + static int init_chrdev(void) + { ++ driver.dev = &lirc_sir_dev->dev; + driver.minor = lirc_register_driver(&driver); + if (driver.minor < 0) { + printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n"); +@@ -1215,20 +1218,71 @@ static int init_lirc_sir(void) + return 0; + } + ++static int __devinit lirc_sir_probe(struct platform_device *dev) ++{ ++ return 0; ++} ++ ++static int __devexit lirc_sir_remove(struct platform_device *dev) ++{ ++ return 0; ++} ++ ++static struct platform_driver lirc_sir_driver = { ++ .probe = lirc_sir_probe, ++ .remove = __devexit_p(lirc_sir_remove), ++ .driver = { ++ .name = "lirc_sir", ++ .owner = THIS_MODULE, ++ }, ++}; + + static int __init lirc_sir_init(void) + { + int retval; + ++ retval = platform_driver_register(&lirc_sir_driver); ++ if (retval) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ": Platform driver register " ++ "failed!\n"); ++ return -ENODEV; ++ } ++ ++ lirc_sir_dev = platform_device_alloc("lirc_dev", 0); ++ if (!lirc_sir_dev) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ": Platform device alloc " ++ "failed!\n"); ++ retval = -ENOMEM; ++ goto pdev_alloc_fail; ++ } ++ ++ retval = platform_device_add(lirc_sir_dev); ++ if (retval) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ": Platform device add " ++ "failed!\n"); ++ retval = -ENODEV; ++ goto pdev_add_fail; ++ } ++ + retval = init_chrdev(); + if (retval < 0) +- return retval; ++ goto fail; ++ + retval = init_lirc_sir(); + if (retval) { + drop_chrdev(); +- return retval; ++ goto fail; + } ++ + return 0; ++ ++fail: ++ platform_device_del(lirc_sir_dev); ++pdev_add_fail: ++ platform_device_put(lirc_sir_dev); ++pdev_alloc_fail: ++ platform_driver_unregister(&lirc_sir_driver); ++ return retval; + } + + static void __exit lirc_sir_exit(void) +@@ -1236,6 +1290,8 @@ static void __exit lirc_sir_exit(void) + drop_hardware(); + drop_chrdev(); + drop_port(); ++ platform_device_unregister(lirc_sir_dev); ++ platform_driver_unregister(&lirc_sir_driver); + printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n"); + } + +diff --git a/drivers/staging/rtl8712/recv_linux.c b/drivers/staging/rtl8712/recv_linux.c +index 0e26d5f..495ee12 100644 +--- a/drivers/staging/rtl8712/recv_linux.c ++++ b/drivers/staging/rtl8712/recv_linux.c +@@ -117,13 +117,8 @@ void r8712_recv_indicatepkt(struct _adapter *padapter, + if (skb == NULL) + goto _recv_indicatepkt_drop; + skb->data = precv_frame->u.hdr.rx_data; +-#ifdef NET_SKBUFF_DATA_USES_OFFSET +- skb->tail = (sk_buff_data_t)(precv_frame->u.hdr.rx_tail - +- precv_frame->u.hdr.rx_head); +-#else +- skb->tail = (sk_buff_data_t)precv_frame->u.hdr.rx_tail; +-#endif + skb->len = precv_frame->u.hdr.len; ++ skb_set_tail_pointer(skb, skb->len); + if ((pattrib->tcpchk_valid == 1) && (pattrib->tcp_chkrpt == 1)) + skb->ip_summed = CHECKSUM_UNNECESSARY; + else +diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c +index 8e82ce2..88e3ca6 100644 +--- a/drivers/staging/rtl8712/rtl8712_recv.c ++++ b/drivers/staging/rtl8712/rtl8712_recv.c +@@ -1127,6 +1127,9 @@ static void recv_tasklet(void *priv) + recvbuf2recvframe(padapter, pskb); + skb_reset_tail_pointer(pskb); + pskb->len = 0; +- skb_queue_tail(&precvpriv->free_recv_skb_queue, pskb); ++ if (!skb_cloned(pskb)) ++ skb_queue_tail(&precvpriv->free_recv_skb_queue, pskb); ++ else ++ consume_skb(pskb); + } + } +diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c +index 92b34e2..40e2488 100644 +--- a/drivers/staging/speakup/main.c ++++ b/drivers/staging/speakup/main.c +@@ -1854,7 +1854,7 @@ static void speakup_bits(struct vc_data *vc) + + static int handle_goto(struct vc_data *vc, u_char type, u_char ch, u_short key) + { +- static u_char *goto_buf = "\0\0\0\0\0\0"; ++ static u_char goto_buf[8]; + static int num; + int maxlen, go_pos; + char *cp; +diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c +index 42cdafe..b5130c8 100644 +--- a/drivers/staging/speakup/speakup_soft.c ++++ b/drivers/staging/speakup/speakup_soft.c +@@ -40,7 +40,7 @@ static int softsynth_is_alive(struct spk_synth *synth); + static unsigned char get_index(void); + + static struct miscdevice synth_device; +-static int initialized; ++static int init_pos; + static int misc_registered; + + static struct var_t vars[] = { +@@ -194,7 +194,7 @@ static int softsynth_close(struct inode *inode, struct file *fp) + unsigned long flags; + spk_lock(flags); + synth_soft.alive = 0; +- initialized = 0; ++ init_pos = 0; + spk_unlock(flags); + /* Make sure we let applications go before leaving */ + speakup_start_ttys(); +@@ -239,13 +239,8 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count, + ch = '\x18'; + } else if (synth_buffer_empty()) { + break; +- } else if (!initialized) { +- if (*init) { +- ch = *init; +- init++; +- } else { +- initialized = 1; +- } ++ } else if (init[init_pos]) { ++ ch = init[init_pos++]; + } else { + ch = synth_buffer_getc(); + } +diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c +index e4bdf2a..3aa895e 100644 +--- a/drivers/staging/vt6656/dpc.c ++++ b/drivers/staging/vt6656/dpc.c +@@ -200,7 +200,7 @@ s_vProcessRxMACHeader ( + } else if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) { + cbHeaderSize += 6; + pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize); +- if ((*pwType == cpu_to_le16(ETH_P_IPX)) || ++ if ((*pwType == cpu_to_be16(ETH_P_IPX)) || + (*pwType == cpu_to_le16(0xF380))) { + cbHeaderSize -= 8; + pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize); +diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c +index ee5261a..b318806 100644 +--- a/drivers/staging/vt6656/main_usb.c ++++ b/drivers/staging/vt6656/main_usb.c +@@ -222,7 +222,7 @@ DEVICE_PARAM(b80211hEnable, "802.11h mode"); + // Static vars definitions + // + +-static struct usb_device_id vt6656_table[] __devinitdata = { ++static struct usb_device_id vt6656_table[] = { + {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)}, + {} + }; +diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c +index 9b64b10..fe21868 100644 +--- a/drivers/staging/vt6656/rxtx.c ++++ b/drivers/staging/vt6656/rxtx.c +@@ -1701,7 +1701,7 @@ s_bPacketToWirelessUsb( + // 802.1H + if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) { + if (pDevice->dwDiagRefCount == 0) { +- if ((psEthHeader->wType == cpu_to_le16(ETH_P_IPX)) || ++ if ((psEthHeader->wType == cpu_to_be16(ETH_P_IPX)) || + (psEthHeader->wType == cpu_to_le16(0xF380))) { + memcpy((PBYTE) (pbyPayloadHead), + abySNAP_Bridgetunnel, 6); +@@ -2840,10 +2840,10 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb) + Packet_Type = skb->data[ETH_HLEN+1]; + Descriptor_type = skb->data[ETH_HLEN+1+1+2]; + Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]); +- if (pDevice->sTxEthHeader.wType == cpu_to_le16(ETH_P_PAE)) { +- /* 802.1x OR eapol-key challenge frame transfer */ +- if (((Protocol_Version == 1) || (Protocol_Version == 2)) && +- (Packet_Type == 3)) { ++ if (pDevice->sTxEthHeader.wType == cpu_to_be16(ETH_P_PAE)) { ++ /* 802.1x OR eapol-key challenge frame transfer */ ++ if (((Protocol_Version == 1) || (Protocol_Version == 2)) && ++ (Packet_Type == 3)) { + bTxeapol_key = TRUE; + if(!(Key_info & BIT3) && //WPA or RSN group-key challenge + (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key +@@ -2989,19 +2989,19 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb) + } + } + +- if (pDevice->sTxEthHeader.wType == cpu_to_le16(ETH_P_PAE)) { +- if (pDevice->byBBType != BB_TYPE_11A) { +- pDevice->wCurrentRate = RATE_1M; +- pDevice->byACKRate = RATE_1M; +- pDevice->byTopCCKBasicRate = RATE_1M; +- pDevice->byTopOFDMBasicRate = RATE_6M; +- } else { +- pDevice->wCurrentRate = RATE_6M; +- pDevice->byACKRate = RATE_6M; +- pDevice->byTopCCKBasicRate = RATE_1M; +- pDevice->byTopOFDMBasicRate = RATE_6M; +- } +- } ++ if (pDevice->sTxEthHeader.wType == cpu_to_be16(ETH_P_PAE)) { ++ if (pDevice->byBBType != BB_TYPE_11A) { ++ pDevice->wCurrentRate = RATE_1M; ++ pDevice->byACKRate = RATE_1M; ++ pDevice->byTopCCKBasicRate = RATE_1M; ++ pDevice->byTopOFDMBasicRate = RATE_6M; ++ } else { ++ pDevice->wCurrentRate = RATE_6M; ++ pDevice->byACKRate = RATE_6M; ++ pDevice->byTopCCKBasicRate = RATE_1M; ++ pDevice->byTopOFDMBasicRate = RATE_6M; ++ } ++ } + + DBG_PRT(MSG_LEVEL_DEBUG, + KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n", +@@ -3017,7 +3017,7 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb) + + if (bNeedEncryption == TRUE) { + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType)); +- if ((pDevice->sTxEthHeader.wType) == cpu_to_le16(ETH_P_PAE)) { ++ if ((pDevice->sTxEthHeader.wType) == cpu_to_be16(ETH_P_PAE)) { + bNeedEncryption = FALSE; + DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType)); + if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { +diff --git a/drivers/staging/winbond/wbusb.c b/drivers/staging/winbond/wbusb.c +index c3751a7..9160049 100644 +--- a/drivers/staging/winbond/wbusb.c ++++ b/drivers/staging/winbond/wbusb.c +@@ -25,7 +25,7 @@ MODULE_DESCRIPTION("IS89C35 802.11bg WLAN USB Driver"); + MODULE_LICENSE("GPL"); + MODULE_VERSION("0.1"); + +-static const struct usb_device_id wb35_table[] __devinitconst = { ++static const struct usb_device_id wb35_table[] = { + { USB_DEVICE(0x0416, 0x0035) }, + { USB_DEVICE(0x18E8, 0x6201) }, + { USB_DEVICE(0x18E8, 0x6206) }, +diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c +index 784c796..8d30f5c 100644 +--- a/drivers/staging/zcache/zcache-main.c ++++ b/drivers/staging/zcache/zcache-main.c +@@ -1259,13 +1259,12 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *bufsize, bool raw, + void *pampd, struct tmem_pool *pool, + struct tmem_oid *oid, uint32_t index) + { +- int ret = 0; +- + BUG_ON(!is_ephemeral(pool)); +- zbud_decompress((struct page *)(data), pampd); ++ if (zbud_decompress((struct page *)(data), pampd) < 0) ++ return -EINVAL; + zbud_free_and_delist((struct zbud_hdr *)pampd); + atomic_dec(&zcache_curr_eph_pampd_count); +- return ret; ++ return 0; + } + + /* +diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c +index 4496737..8ded9a0 100644 +--- a/drivers/staging/zsmalloc/zsmalloc-main.c ++++ b/drivers/staging/zsmalloc/zsmalloc-main.c +@@ -425,12 +425,6 @@ static struct page *find_get_zspage(struct size_class *class) + } + + +-/* +- * If this becomes a separate module, register zs_init() with +- * module_init(), zs_exit with module_exit(), and remove zs_initialized +-*/ +-static int zs_initialized; +- + static int zs_cpu_notifier(struct notifier_block *nb, unsigned long action, + void *pcpu) + { +@@ -489,7 +483,7 @@ fail: + + struct zs_pool *zs_create_pool(const char *name, gfp_t flags) + { +- int i, error, ovhd_size; ++ int i, ovhd_size; + struct zs_pool *pool; + + if (!name) +@@ -516,28 +510,9 @@ struct zs_pool *zs_create_pool(const char *name, gfp_t flags) + + } + +- /* +- * If this becomes a separate module, register zs_init with +- * module_init, and remove this block +- */ +- if (!zs_initialized) { +- error = zs_init(); +- if (error) +- goto cleanup; +- zs_initialized = 1; +- } +- + pool->flags = flags; + pool->name = name; + +- error = 0; /* Success */ +- +-cleanup: +- if (error) { +- zs_destroy_pool(pool); +- pool = NULL; +- } +- + return pool; + } + EXPORT_SYMBOL_GPL(zs_create_pool); +@@ -753,3 +728,9 @@ u64 zs_get_total_size_bytes(struct zs_pool *pool) + return npages << PAGE_SHIFT; + } + EXPORT_SYMBOL_GPL(zs_get_total_size_bytes); ++ ++module_init(zs_init); ++module_exit(zs_exit); ++ ++MODULE_LICENSE("Dual BSD/GPL"); ++MODULE_AUTHOR("Nitin Gupta "); +diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c +index d57d10c..d7dcd67 100644 +--- a/drivers/target/iscsi/iscsi_target.c ++++ b/drivers/target/iscsi/iscsi_target.c +@@ -429,19 +429,8 @@ int iscsit_reset_np_thread( + + int iscsit_del_np_comm(struct iscsi_np *np) + { +- if (!np->np_socket) +- return 0; +- +- /* +- * Some network transports allocate their own struct sock->file, +- * see if we need to free any additional allocated resources. +- */ +- if (np->np_flags & NPF_SCTP_STRUCT_FILE) { +- kfree(np->np_socket->file); +- np->np_socket->file = NULL; +- } +- +- sock_release(np->np_socket); ++ if (np->np_socket) ++ sock_release(np->np_socket); + return 0; + } + +@@ -4077,13 +4066,8 @@ int iscsit_close_connection( + kfree(conn->conn_ops); + conn->conn_ops = NULL; + +- if (conn->sock) { +- if (conn->conn_flags & CONNFLAG_SCTP_STRUCT_FILE) { +- kfree(conn->sock->file); +- conn->sock->file = NULL; +- } ++ if (conn->sock) + sock_release(conn->sock); +- } + conn->thread_set = NULL; + + pr_debug("Moving to TARG_CONN_STATE_FREE.\n"); +diff --git a/drivers/target/iscsi/iscsi_target_core.h b/drivers/target/iscsi/iscsi_target_core.h +index 1c70144..1dd5716 100644 +--- a/drivers/target/iscsi/iscsi_target_core.h ++++ b/drivers/target/iscsi/iscsi_target_core.h +@@ -224,7 +224,6 @@ enum iscsi_timer_flags_table { + /* Used for struct iscsi_np->np_flags */ + enum np_flags_table { + NPF_IP_NETWORK = 0x00, +- NPF_SCTP_STRUCT_FILE = 0x01 /* Bugfix */ + }; + + /* Used for struct iscsi_np->np_thread_state */ +@@ -503,7 +502,6 @@ struct iscsi_conn { + u16 local_port; + int net_size; + u32 auth_id; +-#define CONNFLAG_SCTP_STRUCT_FILE 0x01 + u32 conn_flags; + /* Used for iscsi_tx_login_rsp() */ + u32 login_itt; +diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c +index a3656c9..ae30424 100644 +--- a/drivers/target/iscsi/iscsi_target_login.c ++++ b/drivers/target/iscsi/iscsi_target_login.c +@@ -795,22 +795,6 @@ int iscsi_target_setup_login_socket( + } + np->np_socket = sock; + /* +- * The SCTP stack needs struct socket->file. +- */ +- if ((np->np_network_transport == ISCSI_SCTP_TCP) || +- (np->np_network_transport == ISCSI_SCTP_UDP)) { +- if (!sock->file) { +- sock->file = kzalloc(sizeof(struct file), GFP_KERNEL); +- if (!sock->file) { +- pr_err("Unable to allocate struct" +- " file for SCTP\n"); +- ret = -ENOMEM; +- goto fail; +- } +- np->np_flags |= NPF_SCTP_STRUCT_FILE; +- } +- } +- /* + * Setup the np->np_sockaddr from the passed sockaddr setup + * in iscsi_target_configfs.c code.. + */ +@@ -869,21 +853,15 @@ int iscsi_target_setup_login_socket( + + fail: + np->np_socket = NULL; +- if (sock) { +- if (np->np_flags & NPF_SCTP_STRUCT_FILE) { +- kfree(sock->file); +- sock->file = NULL; +- } +- ++ if (sock) + sock_release(sock); +- } + return ret; + } + + static int __iscsi_target_login_thread(struct iscsi_np *np) + { + u8 buffer[ISCSI_HDR_LEN], iscsi_opcode, zero_tsih = 0; +- int err, ret = 0, set_sctp_conn_flag, stop; ++ int err, ret = 0, stop; + struct iscsi_conn *conn = NULL; + struct iscsi_login *login; + struct iscsi_portal_group *tpg = NULL; +@@ -894,7 +872,6 @@ static int __iscsi_target_login_thread(struct iscsi_np *np) + struct sockaddr_in6 sock_in6; + + flush_signals(current); +- set_sctp_conn_flag = 0; + sock = np->np_socket; + + spin_lock_bh(&np->np_thread_lock); +@@ -917,35 +894,12 @@ static int __iscsi_target_login_thread(struct iscsi_np *np) + spin_unlock_bh(&np->np_thread_lock); + goto out; + } +- /* +- * The SCTP stack needs struct socket->file. +- */ +- if ((np->np_network_transport == ISCSI_SCTP_TCP) || +- (np->np_network_transport == ISCSI_SCTP_UDP)) { +- if (!new_sock->file) { +- new_sock->file = kzalloc( +- sizeof(struct file), GFP_KERNEL); +- if (!new_sock->file) { +- pr_err("Unable to allocate struct" +- " file for SCTP\n"); +- sock_release(new_sock); +- /* Get another socket */ +- return 1; +- } +- set_sctp_conn_flag = 1; +- } +- } +- + iscsi_start_login_thread_timer(np); + + conn = kzalloc(sizeof(struct iscsi_conn), GFP_KERNEL); + if (!conn) { + pr_err("Could not allocate memory for" + " new connection\n"); +- if (set_sctp_conn_flag) { +- kfree(new_sock->file); +- new_sock->file = NULL; +- } + sock_release(new_sock); + /* Get another socket */ + return 1; +@@ -955,9 +909,6 @@ static int __iscsi_target_login_thread(struct iscsi_np *np) + conn->conn_state = TARG_CONN_STATE_FREE; + conn->sock = new_sock; + +- if (set_sctp_conn_flag) +- conn->conn_flags |= CONNFLAG_SCTP_STRUCT_FILE; +- + pr_debug("Moving to TARG_CONN_STATE_XPT_UP.\n"); + conn->conn_state = TARG_CONN_STATE_XPT_UP; + +@@ -1205,13 +1156,8 @@ old_sess_out: + iscsi_release_param_list(conn->param_list); + conn->param_list = NULL; + } +- if (conn->sock) { +- if (conn->conn_flags & CONNFLAG_SCTP_STRUCT_FILE) { +- kfree(conn->sock->file); +- conn->sock->file = NULL; +- } ++ if (conn->sock) + sock_release(conn->sock); +- } + kfree(conn); + + if (tpg) { +diff --git a/drivers/target/target_core_cdb.c b/drivers/target/target_core_cdb.c +index 664f6e7..bf7d38a 100644 +--- a/drivers/target/target_core_cdb.c ++++ b/drivers/target/target_core_cdb.c +@@ -1013,11 +1013,11 @@ int target_emulate_unmap(struct se_cmd *cmd) + { + struct se_device *dev = cmd->se_dev; + unsigned char *buf, *ptr = NULL; +- unsigned char *cdb = &cmd->t_task_cdb[0]; + sector_t lba; +- unsigned int size = cmd->data_length, range; +- int ret = 0, offset; +- unsigned short dl, bd_dl; ++ int size = cmd->data_length; ++ u32 range; ++ int ret = 0; ++ int dl, bd_dl; + + if (!dev->transport->do_discard) { + pr_err("UNMAP emulation not supported for: %s\n", +@@ -1026,24 +1026,41 @@ int target_emulate_unmap(struct se_cmd *cmd) + return -ENOSYS; + } + +- /* First UNMAP block descriptor starts at 8 byte offset */ +- offset = 8; +- size -= 8; +- dl = get_unaligned_be16(&cdb[0]); +- bd_dl = get_unaligned_be16(&cdb[2]); +- + buf = transport_kmap_data_sg(cmd); + +- ptr = &buf[offset]; +- pr_debug("UNMAP: Sub: %s Using dl: %hu bd_dl: %hu size: %hu" ++ dl = get_unaligned_be16(&buf[0]); ++ bd_dl = get_unaligned_be16(&buf[2]); ++ ++ size = min(size - 8, bd_dl); ++ if (size / 16 > dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count) { ++ cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST; ++ ret = -EINVAL; ++ goto err; ++ } ++ ++ /* First UNMAP block descriptor starts at 8 byte offset */ ++ ptr = &buf[8]; ++ pr_debug("UNMAP: Sub: %s Using dl: %u bd_dl: %u size: %u" + " ptr: %p\n", dev->transport->name, dl, bd_dl, size, ptr); + +- while (size) { ++ while (size >= 16) { + lba = get_unaligned_be64(&ptr[0]); + range = get_unaligned_be32(&ptr[8]); + pr_debug("UNMAP: Using lba: %llu and range: %u\n", + (unsigned long long)lba, range); + ++ if (range > dev->se_sub_dev->se_dev_attrib.max_unmap_lba_count) { ++ cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST; ++ ret = -EINVAL; ++ goto err; ++ } ++ ++ if (lba + range > dev->transport->get_blocks(dev) + 1) { ++ cmd->scsi_sense_reason = TCM_ADDRESS_OUT_OF_RANGE; ++ ret = -EINVAL; ++ goto err; ++ } ++ + ret = dev->transport->do_discard(dev, lba, range); + if (ret < 0) { + pr_err("blkdev_issue_discard() failed: %d\n", +diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c +index 634d0f3..0981707 100644 +--- a/drivers/target/target_core_transport.c ++++ b/drivers/target/target_core_transport.c +@@ -1797,6 +1797,7 @@ void transport_generic_request_failure(struct se_cmd *cmd) + case TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE: + case TCM_UNKNOWN_MODE_PAGE: + case TCM_WRITE_PROTECTED: ++ case TCM_ADDRESS_OUT_OF_RANGE: + case TCM_CHECK_CONDITION_ABORT_CMD: + case TCM_CHECK_CONDITION_UNIT_ATTENTION: + case TCM_CHECK_CONDITION_NOT_READY: +@@ -2260,7 +2261,7 @@ out: + /* + * Used to obtain Sense Data from underlying Linux/SCSI struct scsi_cmnd + */ +-static int transport_get_sense_data(struct se_cmd *cmd) ++static void transport_get_sense_data(struct se_cmd *cmd) + { + unsigned char *buffer = cmd->sense_buffer, *sense_buffer = NULL; + struct se_device *dev = cmd->se_dev; +@@ -2270,30 +2271,15 @@ static int transport_get_sense_data(struct se_cmd *cmd) + WARN_ON(!cmd->se_lun); + + if (!dev) +- return 0; ++ return; + + spin_lock_irqsave(&cmd->t_state_lock, flags); + if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) { + spin_unlock_irqrestore(&cmd->t_state_lock, flags); +- return 0; +- } +- +- if (!(cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE)) +- goto out; +- +- if (!dev->transport->get_sense_buffer) { +- pr_err("dev->transport->get_sense_buffer is NULL\n"); +- goto out; ++ return; + } + + sense_buffer = dev->transport->get_sense_buffer(cmd); +- if (!sense_buffer) { +- pr_err("ITT 0x%08x cmd %p: Unable to locate" +- " sense buffer for task with sense\n", +- cmd->se_tfo->get_task_tag(cmd), cmd); +- goto out; +- } +- + spin_unlock_irqrestore(&cmd->t_state_lock, flags); + + offset = cmd->se_tfo->set_fabric_sense_len(cmd, TRANSPORT_SENSE_BUFFER); +@@ -2305,11 +2291,6 @@ static int transport_get_sense_data(struct se_cmd *cmd) + + pr_debug("HBA_[%u]_PLUG[%s]: Set SAM STATUS: 0x%02x and sense\n", + dev->se_hba->hba_id, dev->transport->name, cmd->scsi_status); +- return 0; +- +-out: +- spin_unlock_irqrestore(&cmd->t_state_lock, flags); +- return -1; + } + + static inline long long transport_dev_end_lba(struct se_device *dev) +@@ -2999,15 +2980,20 @@ static int transport_generic_cmd_sequencer( + /* Returns CHECK_CONDITION + INVALID_CDB_FIELD */ + goto out_invalid_cdb_field; + } +- ++ /* ++ * For the overflow case keep the existing fabric provided ++ * ->data_length. Otherwise for the underflow case, reset ++ * ->data_length to the smaller SCSI expected data transfer ++ * length. ++ */ + if (size > cmd->data_length) { + cmd->se_cmd_flags |= SCF_OVERFLOW_BIT; + cmd->residual_count = (size - cmd->data_length); + } else { + cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT; + cmd->residual_count = (cmd->data_length - size); ++ cmd->data_length = size; + } +- cmd->data_length = size; + } + + if (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB) { +@@ -3165,7 +3151,7 @@ static void transport_handle_queue_full( + static void target_complete_ok_work(struct work_struct *work) + { + struct se_cmd *cmd = container_of(work, struct se_cmd, work); +- int reason = 0, ret; ++ int ret; + + /* + * Check if we need to move delayed/dormant tasks from cmds on the +@@ -3186,19 +3172,16 @@ static void target_complete_ok_work(struct work_struct *work) + * the struct se_cmd in question. + */ + if (cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) { +- if (transport_get_sense_data(cmd) < 0) +- reason = TCM_NON_EXISTENT_LUN; +- +- if (cmd->scsi_status) { +- ret = transport_send_check_condition_and_sense( +- cmd, reason, 1); +- if (ret == -EAGAIN || ret == -ENOMEM) +- goto queue_full; ++ WARN_ON(!cmd->scsi_status); ++ transport_get_sense_data(cmd); ++ ret = transport_send_check_condition_and_sense( ++ cmd, 0, 1); ++ if (ret == -EAGAIN || ret == -ENOMEM) ++ goto queue_full; + +- transport_lun_remove_cmd(cmd); +- transport_cmd_check_stop_to_fabric(cmd); +- return; +- } ++ transport_lun_remove_cmd(cmd); ++ transport_cmd_check_stop_to_fabric(cmd); ++ return; + } + /* + * Check for a callback, used by amongst other things +@@ -3476,9 +3459,9 @@ transport_generic_get_mem(struct se_cmd *cmd) + return 0; + + out: +- while (i >= 0) { +- __free_page(sg_page(&cmd->t_data_sg[i])); ++ while (i > 0) { + i--; ++ __free_page(sg_page(&cmd->t_data_sg[i])); + } + kfree(cmd->t_data_sg); + cmd->t_data_sg = NULL; +@@ -4212,6 +4195,15 @@ int transport_send_check_condition_and_sense( + /* WRITE PROTECTED */ + buffer[offset+SPC_ASC_KEY_OFFSET] = 0x27; + break; ++ case TCM_ADDRESS_OUT_OF_RANGE: ++ /* CURRENT ERROR */ ++ buffer[offset] = 0x70; ++ buffer[offset+SPC_ADD_SENSE_LEN_OFFSET] = 10; ++ /* ILLEGAL REQUEST */ ++ buffer[offset+SPC_SENSE_KEY_OFFSET] = ILLEGAL_REQUEST; ++ /* LOGICAL BLOCK ADDRESS OUT OF RANGE */ ++ buffer[offset+SPC_ASC_KEY_OFFSET] = 0x21; ++ break; + case TCM_CHECK_CONDITION_UNIT_ATTENTION: + /* CURRENT ERROR */ + buffer[offset] = 0x70; +diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c +index c43b683..90dff82 100644 +--- a/drivers/tty/n_gsm.c ++++ b/drivers/tty/n_gsm.c +@@ -875,7 +875,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm, + + /* dlci->skb is locked by tx_lock */ + if (dlci->skb == NULL) { +- dlci->skb = skb_dequeue(&dlci->skb_list); ++ dlci->skb = skb_dequeue_tail(&dlci->skb_list); + if (dlci->skb == NULL) + return 0; + first = 1; +@@ -899,8 +899,11 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm, + + /* FIXME: need a timer or something to kick this so it can't + get stuck with no work outstanding and no buffer free */ +- if (msg == NULL) ++ if (msg == NULL) { ++ skb_queue_tail(&dlci->skb_list, dlci->skb); ++ dlci->skb = NULL; + return -ENOMEM; ++ } + dp = msg->data; + + if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ +@@ -971,16 +974,19 @@ static void gsm_dlci_data_sweep(struct gsm_mux *gsm) + static void gsm_dlci_data_kick(struct gsm_dlci *dlci) + { + unsigned long flags; ++ int sweep; + + spin_lock_irqsave(&dlci->gsm->tx_lock, flags); + /* If we have nothing running then we need to fire up */ ++ sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); + if (dlci->gsm->tx_bytes == 0) { + if (dlci->net) + gsm_dlci_data_output_framed(dlci->gsm, dlci); + else + gsm_dlci_data_output(dlci->gsm, dlci); +- } else if (dlci->gsm->tx_bytes < TX_THRESH_LO) +- gsm_dlci_data_sweep(dlci->gsm); ++ } ++ if (sweep) ++ gsm_dlci_data_sweep(dlci->gsm); + spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); + } + +@@ -1190,6 +1196,8 @@ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command, + u8 *data, int clen) + { + u8 buf[1]; ++ unsigned long flags; ++ + switch (command) { + case CMD_CLD: { + struct gsm_dlci *dlci = gsm->dlci[0]; +@@ -1215,7 +1223,9 @@ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command, + gsm->constipated = 0; + gsm_control_reply(gsm, CMD_FCOFF, NULL, 0); + /* Kick the link in case it is idling */ ++ spin_lock_irqsave(&gsm->tx_lock, flags); + gsm_data_kick(gsm); ++ spin_unlock_irqrestore(&gsm->tx_lock, flags); + break; + case CMD_MSC: + /* Out of band modem line change indicator for a DLCI */ +@@ -2377,12 +2387,12 @@ static void gsmld_write_wakeup(struct tty_struct *tty) + + /* Queue poll */ + clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); ++ spin_lock_irqsave(&gsm->tx_lock, flags); + gsm_data_kick(gsm); + if (gsm->tx_bytes < TX_THRESH_LO) { +- spin_lock_irqsave(&gsm->tx_lock, flags); + gsm_dlci_data_sweep(gsm); +- spin_unlock_irqrestore(&gsm->tx_lock, flags); + } ++ spin_unlock_irqrestore(&gsm->tx_lock, flags); + } + + /** +@@ -2889,6 +2899,10 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp) + gsm = gsm_mux[mux]; + if (gsm->dead) + return -EL2HLT; ++ /* If DLCI 0 is not yet fully open return an error. This is ok from a locking ++ perspective as we don't have to worry about this if DLCI0 is lost */ ++ if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) ++ return -EL2NSYNC; + dlci = gsm->dlci[line]; + if (dlci == NULL) + dlci = gsm_dlci_alloc(gsm, line); +diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c +index ee1c268..26f0d0e 100644 +--- a/drivers/tty/n_tty.c ++++ b/drivers/tty/n_tty.c +@@ -1728,7 +1728,8 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, + + do_it_again: + +- BUG_ON(!tty->read_buf); ++ if (WARN_ON(!tty->read_buf)) ++ return -EAGAIN; + + c = job_control(tty, file); + if (c < 0) +diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c +index 28e7c7c..6b8fcb4 100644 +--- a/drivers/tty/serial/8250/8250_pci.c ++++ b/drivers/tty/serial/8250/8250_pci.c +@@ -1164,6 +1164,8 @@ pci_xr17c154_setup(struct serial_private *priv, + #define PCI_SUBDEVICE_ID_OCTPRO422 0x0208 + #define PCI_SUBDEVICE_ID_POCTAL232 0x0308 + #define PCI_SUBDEVICE_ID_POCTAL422 0x0408 ++#define PCI_SUBDEVICE_ID_SIIG_DUAL_00 0x2500 ++#define PCI_SUBDEVICE_ID_SIIG_DUAL_30 0x2530 + #define PCI_VENDOR_ID_ADVANTECH 0x13fe + #define PCI_DEVICE_ID_INTEL_CE4100_UART 0x2e66 + #define PCI_DEVICE_ID_ADVANTECH_PCI3620 0x3620 +@@ -3232,8 +3234,11 @@ static struct pci_device_id serial_pci_tbl[] = { + * For now just used the hex ID 0x950a. + */ + { PCI_VENDOR_ID_OXSEMI, 0x950a, +- PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_DUAL_SERIAL, 0, 0, +- pbn_b0_2_115200 }, ++ PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_DUAL_00, ++ 0, 0, pbn_b0_2_115200 }, ++ { PCI_VENDOR_ID_OXSEMI, 0x950a, ++ PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_DUAL_30, ++ 0, 0, pbn_b0_2_115200 }, + { PCI_VENDOR_ID_OXSEMI, 0x950a, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, + pbn_b0_2_1130000 }, +diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c +index c17923e..da8a37f 100644 +--- a/drivers/tty/serial/amba-pl011.c ++++ b/drivers/tty/serial/amba-pl011.c +@@ -1603,13 +1603,26 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios, + old_cr &= ~ST_UART011_CR_OVSFACT; + } + ++ /* ++ * Workaround for the ST Micro oversampling variants to ++ * increase the bitrate slightly, by lowering the divisor, ++ * to avoid delayed sampling of start bit at high speeds, ++ * else we see data corruption. ++ */ ++ if (uap->vendor->oversampling) { ++ if ((baud >= 3000000) && (baud < 3250000) && (quot > 1)) ++ quot -= 1; ++ else if ((baud > 3250000) && (quot > 2)) ++ quot -= 2; ++ } + /* Set baud rate */ + writew(quot & 0x3f, port->membase + UART011_FBRD); + writew(quot >> 6, port->membase + UART011_IBRD); + + /* + * ----------v----------v----------v----------v----- +- * NOTE: MUST BE WRITTEN AFTER UARTLCR_M & UARTLCR_L ++ * NOTE: lcrh_tx and lcrh_rx MUST BE WRITTEN AFTER ++ * UART011_FBRD & UART011_IBRD. + * ----------^----------^----------^----------^----- + */ + writew(lcr_h, port->membase + uap->lcrh_rx); +diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c +index 4ef7473..e983331 100644 +--- a/drivers/tty/serial/imx.c ++++ b/drivers/tty/serial/imx.c +@@ -132,6 +132,7 @@ + #define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */ + #define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ + #define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ ++#define UFCR_DCEDTE (1<<6) /* DCE/DTE mode select */ + #define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ + #define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7) + #define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ +@@ -668,22 +669,11 @@ static void imx_break_ctl(struct uart_port *port, int break_state) + static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode) + { + unsigned int val; +- unsigned int ufcr_rfdiv; +- +- /* set receiver / transmitter trigger level. +- * RFDIV is set such way to satisfy requested uartclk value +- */ +- val = TXTL << 10 | RXTL; +- ufcr_rfdiv = (clk_get_rate(sport->clk_per) + sport->port.uartclk / 2) +- / sport->port.uartclk; +- +- if(!ufcr_rfdiv) +- ufcr_rfdiv = 1; +- +- val |= UFCR_RFDIV_REG(ufcr_rfdiv); + ++ /* set receiver / transmitter trigger level */ ++ val = readl(sport->port.membase + UFCR) & (UFCR_RFDIV | UFCR_DCEDTE); ++ val |= TXTL << UFCR_TXTL_SHF | RXTL; + writel(val, sport->port.membase + UFCR); +- + return 0; + } + +@@ -758,6 +748,7 @@ static int imx_startup(struct uart_port *port) + } + } + ++ spin_lock_irqsave(&sport->port.lock, flags); + /* + * Finally, clear and enable interrupts + */ +@@ -811,7 +802,6 @@ static int imx_startup(struct uart_port *port) + /* + * Enable modem status interrupts + */ +- spin_lock_irqsave(&sport->port.lock,flags); + imx_enable_ms(&sport->port); + spin_unlock_irqrestore(&sport->port.lock,flags); + +@@ -841,10 +831,13 @@ static void imx_shutdown(struct uart_port *port) + { + struct imx_port *sport = (struct imx_port *)port; + unsigned long temp; ++ unsigned long flags; + ++ spin_lock_irqsave(&sport->port.lock, flags); + temp = readl(sport->port.membase + UCR2); + temp &= ~(UCR2_TXEN); + writel(temp, sport->port.membase + UCR2); ++ spin_unlock_irqrestore(&sport->port.lock, flags); + + if (USE_IRDA(sport)) { + struct imxuart_platform_data *pdata; +@@ -873,12 +866,14 @@ static void imx_shutdown(struct uart_port *port) + * Disable all interrupts, port and break condition. + */ + ++ spin_lock_irqsave(&sport->port.lock, flags); + temp = readl(sport->port.membase + UCR1); + temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); + if (USE_IRDA(sport)) + temp &= ~(UCR1_IREN); + + writel(temp, sport->port.membase + UCR1); ++ spin_unlock_irqrestore(&sport->port.lock, flags); + } + + static void +@@ -1221,6 +1216,9 @@ imx_console_write(struct console *co, const char *s, unsigned int count) + struct imx_port *sport = imx_ports[co->index]; + struct imx_port_ucrs old_ucr; + unsigned int ucr1; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&sport->port.lock, flags); + + /* + * First, save UCR1/2/3 and then disable interrupts +@@ -1246,6 +1244,8 @@ imx_console_write(struct console *co, const char *s, unsigned int count) + while (!(readl(sport->port.membase + USR2) & USR2_TXDC)); + + imx_port_ucrs_restore(&sport->port, &old_ucr); ++ ++ spin_unlock_irqrestore(&sport->port.lock, flags); + } + + /* +diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c +index d3cda0c..22992cd 100644 +--- a/drivers/tty/serial/omap-serial.c ++++ b/drivers/tty/serial/omap-serial.c +@@ -667,19 +667,19 @@ serial_omap_configure_xonxoff + + /* + * IXON Flag: +- * Enable XON/XOFF flow control on output. +- * Transmit XON1, XOFF1 ++ * Flow control for OMAP.TX ++ * OMAP.RX should listen for XON/XOFF + */ + if (termios->c_iflag & IXON) +- up->efr |= OMAP_UART_SW_TX; ++ up->efr |= OMAP_UART_SW_RX; + + /* + * IXOFF Flag: +- * Enable XON/XOFF flow control on input. +- * Receiver compares XON1, XOFF1. ++ * Flow control for OMAP.RX ++ * OMAP.TX should send XON/XOFF + */ + if (termios->c_iflag & IXOFF) +- up->efr |= OMAP_UART_SW_RX; ++ up->efr |= OMAP_UART_SW_TX; + + serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); +diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c +index 4fdec6a..558ce85 100644 +--- a/drivers/tty/serial/pch_uart.c ++++ b/drivers/tty/serial/pch_uart.c +@@ -253,6 +253,9 @@ struct eg20t_port { + dma_addr_t rx_buf_dma; + + struct dentry *debugfs; ++ ++ /* protect the eg20t_port private structure and io access to membase */ ++ spinlock_t lock; + }; + + /** +@@ -754,7 +757,8 @@ static void pch_dma_rx_complete(void *arg) + tty_flip_buffer_push(tty); + tty_kref_put(tty); + async_tx_ack(priv->desc_rx); +- pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT); ++ pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT | ++ PCH_UART_HAL_RX_ERR_INT); + } + + static void pch_dma_tx_complete(void *arg) +@@ -809,7 +813,8 @@ static int handle_rx_to(struct eg20t_port *priv) + int rx_size; + int ret; + if (!priv->start_rx) { +- pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT); ++ pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT | ++ PCH_UART_HAL_RX_ERR_INT); + return 0; + } + buf = &priv->rxbuf; +@@ -1058,7 +1063,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) + int next = 1; + u8 msr; + +- spin_lock_irqsave(&priv->port.lock, flags); ++ spin_lock_irqsave(&priv->lock, flags); + handled = 0; + while (next) { + iid = pch_uart_hal_get_iid(priv); +@@ -1078,11 +1083,13 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) + case PCH_UART_IID_RDR: /* Received Data Ready */ + if (priv->use_dma) { + pch_uart_hal_disable_interrupt(priv, +- PCH_UART_HAL_RX_INT); ++ PCH_UART_HAL_RX_INT | ++ PCH_UART_HAL_RX_ERR_INT); + ret = dma_handle_rx(priv); + if (!ret) + pch_uart_hal_enable_interrupt(priv, +- PCH_UART_HAL_RX_INT); ++ PCH_UART_HAL_RX_INT | ++ PCH_UART_HAL_RX_ERR_INT); + } else { + ret = handle_rx(priv); + } +@@ -1116,7 +1123,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) + handled |= (unsigned int)ret; + } + +- spin_unlock_irqrestore(&priv->port.lock, flags); ++ spin_unlock_irqrestore(&priv->lock, flags); + return IRQ_RETVAL(handled); + } + +@@ -1208,7 +1215,8 @@ static void pch_uart_stop_rx(struct uart_port *port) + struct eg20t_port *priv; + priv = container_of(port, struct eg20t_port, port); + priv->start_rx = 0; +- pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT); ++ pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT | ++ PCH_UART_HAL_RX_ERR_INT); + } + + /* Enable the modem status interrupts. */ +@@ -1226,9 +1234,9 @@ static void pch_uart_break_ctl(struct uart_port *port, int ctl) + unsigned long flags; + + priv = container_of(port, struct eg20t_port, port); +- spin_lock_irqsave(&port->lock, flags); ++ spin_lock_irqsave(&priv->lock, flags); + pch_uart_hal_set_break(priv, ctl); +- spin_unlock_irqrestore(&port->lock, flags); ++ spin_unlock_irqrestore(&priv->lock, flags); + } + + /* Grab any interrupt resources and initialise any low level driver state. */ +@@ -1263,6 +1271,7 @@ static int pch_uart_startup(struct uart_port *port) + break; + case 16: + fifo_size = PCH_UART_HAL_FIFO16; ++ break; + case 1: + default: + fifo_size = PCH_UART_HAL_FIFO_DIS; +@@ -1300,7 +1309,8 @@ static int pch_uart_startup(struct uart_port *port) + pch_request_dma(port); + + priv->start_rx = 1; +- pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT); ++ pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT | ++ PCH_UART_HAL_RX_ERR_INT); + uart_update_timeout(port, CS8, default_baud); + + return 0; +@@ -1358,7 +1368,7 @@ static void pch_uart_set_termios(struct uart_port *port, + stb = PCH_UART_HAL_STB1; + + if (termios->c_cflag & PARENB) { +- if (!(termios->c_cflag & PARODD)) ++ if (termios->c_cflag & PARODD) + parity = PCH_UART_HAL_PARITY_ODD; + else + parity = PCH_UART_HAL_PARITY_EVEN; +@@ -1376,7 +1386,8 @@ static void pch_uart_set_termios(struct uart_port *port, + + baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); + +- spin_lock_irqsave(&port->lock, flags); ++ spin_lock_irqsave(&priv->lock, flags); ++ spin_lock(&port->lock); + + uart_update_timeout(port, termios->c_cflag, baud); + rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb); +@@ -1389,7 +1400,8 @@ static void pch_uart_set_termios(struct uart_port *port, + tty_termios_encode_baud_rate(termios, baud, baud); + + out: +- spin_unlock_irqrestore(&port->lock, flags); ++ spin_unlock(&port->lock); ++ spin_unlock_irqrestore(&priv->lock, flags); + } + + static const char *pch_uart_type(struct uart_port *port) +@@ -1538,8 +1550,9 @@ pch_console_write(struct console *co, const char *s, unsigned int count) + { + struct eg20t_port *priv; + unsigned long flags; ++ int priv_locked = 1; ++ int port_locked = 1; + u8 ier; +- int locked = 1; + + priv = pch_uart_ports[co->index]; + +@@ -1547,12 +1560,16 @@ pch_console_write(struct console *co, const char *s, unsigned int count) + + local_irq_save(flags); + if (priv->port.sysrq) { +- /* serial8250_handle_port() already took the lock */ +- locked = 0; ++ spin_lock(&priv->lock); ++ /* serial8250_handle_port() already took the port lock */ ++ port_locked = 0; + } else if (oops_in_progress) { +- locked = spin_trylock(&priv->port.lock); +- } else ++ priv_locked = spin_trylock(&priv->lock); ++ port_locked = spin_trylock(&priv->port.lock); ++ } else { ++ spin_lock(&priv->lock); + spin_lock(&priv->port.lock); ++ } + + /* + * First save the IER then disable the interrupts +@@ -1570,8 +1587,10 @@ pch_console_write(struct console *co, const char *s, unsigned int count) + wait_for_xmitr(priv, BOTH_EMPTY); + iowrite8(ier, priv->membase + UART_IER); + +- if (locked) ++ if (port_locked) + spin_unlock(&priv->port.lock); ++ if (priv_locked) ++ spin_unlock(&priv->lock); + local_irq_restore(flags); + } + +@@ -1669,6 +1688,8 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev, + pci_enable_msi(pdev); + pci_set_master(pdev); + ++ spin_lock_init(&priv->lock); ++ + iobase = pci_resource_start(pdev, 0); + mapbase = pci_resource_start(pdev, 1); + priv->mapbase = mapbase; +diff --git a/drivers/tty/serial/pmac_zilog.c b/drivers/tty/serial/pmac_zilog.c +index 654755a..333c8d0 100644 +--- a/drivers/tty/serial/pmac_zilog.c ++++ b/drivers/tty/serial/pmac_zilog.c +@@ -1348,10 +1348,16 @@ static int pmz_verify_port(struct uart_port *port, struct serial_struct *ser) + static int pmz_poll_get_char(struct uart_port *port) + { + struct uart_pmac_port *uap = (struct uart_pmac_port *)port; ++ int tries = 2; + +- while ((read_zsreg(uap, R0) & Rx_CH_AV) == 0) +- udelay(5); +- return read_zsdata(uap); ++ while (tries) { ++ if ((read_zsreg(uap, R0) & Rx_CH_AV) != 0) ++ return read_zsdata(uap); ++ if (tries--) ++ udelay(5); ++ } ++ ++ return NO_POLL_CHAR; + } + + static void pmz_poll_put_char(struct uart_port *port, unsigned char c) +diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c +index 48cc6f2..770a854 100644 +--- a/drivers/tty/vt/keyboard.c ++++ b/drivers/tty/vt/keyboard.c +@@ -1049,13 +1049,10 @@ static int kbd_update_leds_helper(struct input_handle *handle, void *data) + */ + int vt_get_leds(int console, int flag) + { +- unsigned long flags; + struct kbd_struct * kbd = kbd_table + console; + int ret; + +- spin_lock_irqsave(&kbd_event_lock, flags); + ret = vc_kbd_led(kbd, flag); +- spin_unlock_irqrestore(&kbd_event_lock, flags); + + return ret; + } +diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c +index 51f9694..ea271d7 100644 +--- a/drivers/usb/chipidea/udc.c ++++ b/drivers/usb/chipidea/udc.c +@@ -77,8 +77,7 @@ static inline int ep_to_bit(struct ci13xxx *udc, int n) + } + + /** +- * hw_device_state: enables/disables interrupts & starts/stops device (execute +- * without interruption) ++ * hw_device_state: enables/disables interrupts (execute without interruption) + * @dma: 0 => disable, !0 => enable and set dma engine + * + * This function returns an error code +@@ -92,7 +91,6 @@ static int hw_device_state(struct ci13xxx *udc, u32 dma) + USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); + hw_write(udc, OP_USBCMD, USBCMD_RS, USBCMD_RS); + } else { +- hw_write(udc, OP_USBCMD, USBCMD_RS, 0); + hw_write(udc, OP_USBINTR, ~0, 0); + } + return 0; +@@ -773,10 +771,7 @@ __acquires(mEp->lock) + { + struct ci13xxx_req *mReq, *mReqTemp; + struct ci13xxx_ep *mEpTemp = mEp; +- int uninitialized_var(retval); +- +- if (list_empty(&mEp->qh.queue)) +- return -EINVAL; ++ int retval = 0; + + list_for_each_entry_safe(mReq, mReqTemp, &mEp->qh.queue, + queue) { +@@ -1419,6 +1414,21 @@ static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA) + return -ENOTSUPP; + } + ++/* Change Data+ pullup status ++ * this func is used by usb_gadget_connect/disconnet ++ */ ++static int ci13xxx_pullup(struct usb_gadget *_gadget, int is_on) ++{ ++ struct ci13xxx *ci = container_of(_gadget, struct ci13xxx, gadget); ++ ++ if (is_on) ++ hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); ++ else ++ hw_write(ci, OP_USBCMD, USBCMD_RS, 0); ++ ++ return 0; ++} ++ + static int ci13xxx_start(struct usb_gadget *gadget, + struct usb_gadget_driver *driver); + static int ci13xxx_stop(struct usb_gadget *gadget, +@@ -1431,6 +1441,7 @@ static int ci13xxx_stop(struct usb_gadget *gadget, + static const struct usb_gadget_ops usb_gadget_ops = { + .vbus_session = ci13xxx_vbus_session, + .wakeup = ci13xxx_wakeup, ++ .pullup = ci13xxx_pullup, + .vbus_draw = ci13xxx_vbus_draw, + .udc_start = ci13xxx_start, + .udc_stop = ci13xxx_stop, +@@ -1454,7 +1465,12 @@ static int init_eps(struct ci13xxx *udc) + + mEp->ep.name = mEp->name; + mEp->ep.ops = &usb_ep_ops; +- mEp->ep.maxpacket = CTRL_PAYLOAD_MAX; ++ /* ++ * for ep0: maxP defined in desc, for other ++ * eps, maxP is set by epautoconfig() called ++ * by gadget layer ++ */ ++ mEp->ep.maxpacket = (unsigned short)~0; + + INIT_LIST_HEAD(&mEp->qh.queue); + mEp->qh.ptr = dma_pool_alloc(udc->qh_pool, GFP_KERNEL, +@@ -1474,6 +1490,7 @@ static int init_eps(struct ci13xxx *udc) + else + udc->ep0in = mEp; + ++ mEp->ep.maxpacket = CTRL_PAYLOAD_MAX; + continue; + } + +@@ -1483,6 +1500,17 @@ static int init_eps(struct ci13xxx *udc) + return retval; + } + ++static void destroy_eps(struct ci13xxx *udc) ++{ ++ int i; ++ ++ for (i = 0; i < udc->hw_ep_max; i++) { ++ struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; ++ ++ dma_pool_free(udc->qh_pool, mEp->qh.ptr, mEp->qh.dma); ++ } ++} ++ + /** + * ci13xxx_start: register a gadget driver + * @gadget: our gadget +@@ -1692,7 +1720,7 @@ static int udc_start(struct ci13xxx *udc) + if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) { + if (udc->transceiver == NULL) { + retval = -ENODEV; +- goto free_pools; ++ goto destroy_eps; + } + } + +@@ -1730,7 +1758,7 @@ static int udc_start(struct ci13xxx *udc) + + remove_trans: + if (udc->transceiver) { +- otg_set_peripheral(udc->transceiver->otg, &udc->gadget); ++ otg_set_peripheral(udc->transceiver->otg, NULL); + usb_put_transceiver(udc->transceiver); + } + +@@ -1742,6 +1770,8 @@ unreg_device: + put_transceiver: + if (udc->transceiver) + usb_put_transceiver(udc->transceiver); ++destroy_eps: ++ destroy_eps(udc); + free_pools: + dma_pool_destroy(udc->td_pool); + free_qh_pool: +@@ -1756,18 +1786,12 @@ free_qh_pool: + */ + static void udc_stop(struct ci13xxx *udc) + { +- int i; +- + if (udc == NULL) + return; + + usb_del_gadget_udc(&udc->gadget); + +- for (i = 0; i < udc->hw_ep_max; i++) { +- struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; +- +- dma_pool_free(udc->qh_pool, mEp->qh.ptr, mEp->qh.dma); +- } ++ destroy_eps(udc); + + dma_pool_destroy(udc->td_pool); + dma_pool_destroy(udc->qh_pool); +diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c +index 36a2a0b..2e29044 100644 +--- a/drivers/usb/class/cdc-acm.c ++++ b/drivers/usb/class/cdc-acm.c +@@ -1104,7 +1104,8 @@ skip_normal_probe: + } + + +- if (data_interface->cur_altsetting->desc.bNumEndpoints < 2) ++ if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 || ++ control_interface->cur_altsetting->desc.bNumEndpoints == 0) + return -EINVAL; + + epctrl = &control_interface->cur_altsetting->endpoint[0].desc; +diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c +index ee46927..3cc771e 100644 +--- a/drivers/usb/class/cdc-wdm.c ++++ b/drivers/usb/class/cdc-wdm.c +@@ -134,12 +134,14 @@ static struct usb_driver wdm_driver; + /* return intfdata if we own the interface, else look up intf in the list */ + static struct wdm_device *wdm_find_device(struct usb_interface *intf) + { +- struct wdm_device *desc = NULL; ++ struct wdm_device *desc; + + spin_lock(&wdm_device_list_lock); + list_for_each_entry(desc, &wdm_device_list, device_list) + if (desc->intf == intf) +- break; ++ goto found; ++ desc = NULL; ++found: + spin_unlock(&wdm_device_list_lock); + + return desc; +@@ -147,12 +149,14 @@ static struct wdm_device *wdm_find_device(struct usb_interface *intf) + + static struct wdm_device *wdm_find_device_by_minor(int minor) + { +- struct wdm_device *desc = NULL; ++ struct wdm_device *desc; + + spin_lock(&wdm_device_list_lock); + list_for_each_entry(desc, &wdm_device_list, device_list) + if (desc->intf->minor == minor) +- break; ++ goto found; ++ desc = NULL; ++found: + spin_unlock(&wdm_device_list_lock); + + return desc; +diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c +index d956965..3440812 100644 +--- a/drivers/usb/core/devices.c ++++ b/drivers/usb/core/devices.c +@@ -624,7 +624,7 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, + /* print devices for all busses */ + list_for_each_entry(bus, &usb_bus_list, bus_list) { + /* recurse through all children of the root hub */ +- if (!bus->root_hub) ++ if (!bus_to_hcd(bus)->rh_registered) + continue; + usb_lock_device(bus->root_hub); + ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, +diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c +index e0f1079..62679bc 100644 +--- a/drivers/usb/core/devio.c ++++ b/drivers/usb/core/devio.c +@@ -1604,10 +1604,14 @@ static int processcompl_compat(struct async *as, void __user * __user *arg) + 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 --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c +index 190b1ec7..6b6891fc 100644 +--- a/drivers/usb/core/hcd.c ++++ b/drivers/usb/core/hcd.c +@@ -1011,10 +1011,7 @@ static int register_root_hub(struct usb_hcd *hcd) + if (retval) { + dev_err (parent_dev, "can't register root hub for %s, %d\n", + dev_name(&usb_dev->dev), retval); +- } +- mutex_unlock(&usb_bus_list_lock); +- +- if (retval == 0) { ++ } else { + spin_lock_irq (&hcd_root_hub_lock); + hcd->rh_registered = 1; + spin_unlock_irq (&hcd_root_hub_lock); +@@ -1023,6 +1020,7 @@ static int register_root_hub(struct usb_hcd *hcd) + if (HCD_DEAD(hcd)) + usb_hc_died (hcd); /* This time clean up */ + } ++ mutex_unlock(&usb_bus_list_lock); + + return retval; + } +diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c +index dc36678..924cac0 100644 +--- a/drivers/usb/core/hub.c ++++ b/drivers/usb/core/hub.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -2184,6 +2185,14 @@ int usb_new_device(struct usb_device *udev) + /* Tell the world! */ + announce_device(udev); + ++ if (udev->serial) ++ add_device_randomness(udev->serial, strlen(udev->serial)); ++ if (udev->product) ++ add_device_randomness(udev->product, strlen(udev->product)); ++ if (udev->manufacturer) ++ add_device_randomness(udev->manufacturer, ++ strlen(udev->manufacturer)); ++ + device_enable_async_suspend(&udev->dev); + + /* +@@ -4683,6 +4692,16 @@ static int usb_reset_and_verify_device(struct usb_device *udev) + } + parent_hub = hdev_to_hub(parent_hdev); + ++ /* Disable LPM while we reset the device and reinstall the alt settings. ++ * Device-initiated LPM settings, and system exit latency settings are ++ * cleared when the device is reset, so we have to set them up again. ++ */ ++ ret = usb_unlocked_disable_lpm(udev); ++ if (ret) { ++ dev_err(&udev->dev, "%s Failed to disable LPM\n.", __func__); ++ goto re_enumerate; ++ } ++ + set_bit(port1, parent_hub->busy_bits); + for (i = 0; i < SET_CONFIG_TRIES; ++i) { + +@@ -4710,22 +4729,11 @@ static int usb_reset_and_verify_device(struct usb_device *udev) + goto done; + + mutex_lock(hcd->bandwidth_mutex); +- /* Disable LPM while we reset the device and reinstall the alt settings. +- * Device-initiated LPM settings, and system exit latency settings are +- * cleared when the device is reset, so we have to set them up again. +- */ +- ret = usb_disable_lpm(udev); +- if (ret) { +- dev_err(&udev->dev, "%s Failed to disable LPM\n.", __func__); +- mutex_unlock(hcd->bandwidth_mutex); +- goto done; +- } + ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); + if (ret < 0) { + dev_warn(&udev->dev, + "Busted HC? Not enough HCD resources for " + "old configuration.\n"); +- usb_enable_lpm(udev); + mutex_unlock(hcd->bandwidth_mutex); + goto re_enumerate; + } +@@ -4737,7 +4745,6 @@ static int usb_reset_and_verify_device(struct usb_device *udev) + dev_err(&udev->dev, + "can't restore configuration #%d (error=%d)\n", + udev->actconfig->desc.bConfigurationValue, ret); +- usb_enable_lpm(udev); + mutex_unlock(hcd->bandwidth_mutex); + goto re_enumerate; + } +@@ -4776,17 +4783,17 @@ static int usb_reset_and_verify_device(struct usb_device *udev) + desc->bInterfaceNumber, + desc->bAlternateSetting, + ret); +- usb_unlocked_enable_lpm(udev); + goto re_enumerate; + } + } + ++done: + /* Now that the alt settings are re-installed, enable LPM. */ + usb_unlocked_enable_lpm(udev); +-done: + return 0; + + re_enumerate: ++ /* LPM state doesn't matter when we're about to destroy the device. */ + hub_port_logical_disconnect(parent_hub, port1); + return -ENODEV; + } +diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c +index bdd1c67..11cc49d 100644 +--- a/drivers/usb/core/message.c ++++ b/drivers/usb/core/message.c +@@ -1174,6 +1174,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) + put_device(&dev->actconfig->interface[i]->dev); + dev->actconfig->interface[i] = NULL; + } ++ usb_unlocked_disable_lpm(dev); + dev->actconfig = NULL; + if (dev->state == USB_STATE_CONFIGURED) + usb_set_device_state(dev, USB_STATE_ADDRESS); +@@ -1791,14 +1792,15 @@ free_interfaces: + * installed, so that the xHCI driver can recalculate the U1/U2 + * timeouts. + */ +- if (usb_disable_lpm(dev)) { ++ if (dev->actconfig && usb_disable_lpm(dev)) { + dev_err(&dev->dev, "%s Failed to disable LPM\n.", __func__); + mutex_unlock(hcd->bandwidth_mutex); + return -ENOMEM; + } + ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); + if (ret < 0) { +- usb_enable_lpm(dev); ++ if (dev->actconfig) ++ usb_enable_lpm(dev); + mutex_unlock(hcd->bandwidth_mutex); + usb_autosuspend_device(dev); + goto free_interfaces; +@@ -1818,7 +1820,7 @@ free_interfaces: + if (!cp) { + usb_set_device_state(dev, USB_STATE_ADDRESS); + usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); +- usb_enable_lpm(dev); ++ /* Leave LPM disabled while the device is unconfigured. */ + mutex_unlock(hcd->bandwidth_mutex); + usb_autosuspend_device(dev); + goto free_interfaces; +diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c +index 32d3adc..8b2a9d8 100644 +--- a/drivers/usb/core/quirks.c ++++ b/drivers/usb/core/quirks.c +@@ -96,6 +96,10 @@ static const struct usb_device_id usb_quirk_list[] = { + { USB_DEVICE(0x04b4, 0x0526), .driver_info = + USB_QUIRK_CONFIG_INTF_STRINGS }, + ++ /* Microchip Joss Optical infrared touchboard device */ ++ { USB_DEVICE(0x04d8, 0x000c), .driver_info = ++ USB_QUIRK_CONFIG_INTF_STRINGS }, ++ + /* Samsung Android phone modem - ID conflict with SPH-I500 */ + { USB_DEVICE(0x04e8, 0x6601), .driver_info = + USB_QUIRK_CONFIG_INTF_STRINGS }, +diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c +index 25d0c61..cd8fb44 100644 +--- a/drivers/usb/core/usb.c ++++ b/drivers/usb/core/usb.c +@@ -396,6 +396,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, + dev->dev.dma_mask = bus->controller->dma_mask; + set_dev_node(&dev->dev, dev_to_node(bus->controller)); + dev->state = USB_STATE_ATTACHED; ++ dev->lpm_disable_count = 1; + atomic_set(&dev->urbnum, 0); + + INIT_LIST_HEAD(&dev->ep0.urb_list); +diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c +index 1040bdb..6dc9d2f 100644 +--- a/drivers/usb/dwc3/core.c ++++ b/drivers/usb/dwc3/core.c +@@ -429,16 +429,21 @@ static int __devinit dwc3_probe(struct platform_device *pdev) + dev_err(dev, "missing IRQ\n"); + return -ENODEV; + } +- dwc->xhci_resources[1] = *res; ++ dwc->xhci_resources[1].start = res->start; ++ dwc->xhci_resources[1].end = res->end; ++ dwc->xhci_resources[1].flags = res->flags; ++ dwc->xhci_resources[1].name = res->name; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(dev, "missing memory resource\n"); + return -ENODEV; + } +- dwc->xhci_resources[0] = *res; ++ dwc->xhci_resources[0].start = res->start; + dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + + DWC3_XHCI_REGS_END; ++ dwc->xhci_resources[0].flags = res->flags; ++ dwc->xhci_resources[0].name = res->name; + + /* + * Request memory region but exclude xHCI regs, +diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c +index 9e8a3dc..127551c 100644 +--- a/drivers/usb/dwc3/ep0.c ++++ b/drivers/usb/dwc3/ep0.c +@@ -702,7 +702,6 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, + transferred = min_t(u32, ur->length, + transfer_size - length); + memcpy(ur->buf, dwc->ep0_bounce, transferred); +- dwc->ep0_bounced = false; + } else { + transferred = ur->length - length; + } +diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c +index ec70df7..0b24d9d 100644 +--- a/drivers/usb/dwc3/gadget.c ++++ b/drivers/usb/dwc3/gadget.c +@@ -238,8 +238,11 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, + if (req->request.status == -EINPROGRESS) + req->request.status = status; + +- usb_gadget_unmap_request(&dwc->gadget, &req->request, +- req->direction); ++ if (dwc->ep0_bounced && dep->number == 0) ++ dwc->ep0_bounced = false; ++ else ++ usb_gadget_unmap_request(&dwc->gadget, &req->request, ++ req->direction); + + dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", + req, dep->name, req->request.actual, +diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c +index 1fc8f12..347bb05 100644 +--- a/drivers/usb/early/ehci-dbgp.c ++++ b/drivers/usb/early/ehci-dbgp.c +@@ -450,7 +450,7 @@ static int dbgp_ehci_startup(void) + 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 --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c +index 1a4430f..22865dd 100644 +--- a/drivers/usb/gadget/at91_udc.c ++++ b/drivers/usb/gadget/at91_udc.c +@@ -475,8 +475,7 @@ static int at91_ep_enable(struct usb_ep *_ep, + unsigned long flags; + + if (!_ep || !ep +- || !desc || ep->ep.desc +- || _ep->name == ep0name ++ || !desc || _ep->name == ep0name + || desc->bDescriptorType != USB_DT_ENDPOINT + || (maxpacket = usb_endpoint_maxp(desc)) == 0 + || maxpacket > ep->maxpacket) { +@@ -530,7 +529,6 @@ ok: + tmp |= AT91_UDP_EPEDS; + __raw_writel(tmp, ep->creg); + +- ep->ep.desc = desc; + ep->ep.maxpacket = maxpacket; + + /* +@@ -1634,7 +1632,6 @@ static int at91_start(struct usb_gadget *gadget, + udc = container_of(gadget, struct at91_udc, gadget); + udc->driver = driver; + udc->gadget.dev.driver = &driver->driver; +- dev_set_drvdata(&udc->gadget.dev, &driver->driver); + udc->enabled = 1; + udc->selfpowered = 1; + +@@ -1655,7 +1652,6 @@ static int at91_stop(struct usb_gadget *gadget, + spin_unlock_irqrestore(&udc->lock, flags); + + udc->gadget.dev.driver = NULL; +- dev_set_drvdata(&udc->gadget.dev, NULL); + udc->driver = NULL; + + DBG("unbound from %s\n", driver->driver.name); +diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c +index b799106..afdbb1c 100644 +--- a/drivers/usb/gadget/dummy_hcd.c ++++ b/drivers/usb/gadget/dummy_hcd.c +@@ -1916,6 +1916,27 @@ done: + return retval; + } + ++/* usb 3.0 root hub device descriptor */ ++struct { ++ struct usb_bos_descriptor bos; ++ struct usb_ss_cap_descriptor ss_cap; ++} __packed usb3_bos_desc = { ++ ++ .bos = { ++ .bLength = USB_DT_BOS_SIZE, ++ .bDescriptorType = USB_DT_BOS, ++ .wTotalLength = cpu_to_le16(sizeof(usb3_bos_desc)), ++ .bNumDeviceCaps = 1, ++ }, ++ .ss_cap = { ++ .bLength = USB_DT_USB_SS_CAP_SIZE, ++ .bDescriptorType = USB_DT_DEVICE_CAPABILITY, ++ .bDevCapabilityType = USB_SS_CAP_TYPE, ++ .wSpeedSupported = cpu_to_le16(USB_5GBPS_OPERATION), ++ .bFunctionalitySupport = ilog2(USB_5GBPS_OPERATION), ++ }, ++}; ++ + static inline void + ss_hub_descriptor(struct usb_hub_descriptor *desc) + { +@@ -2006,6 +2027,18 @@ static int dummy_hub_control( + else + hub_descriptor((struct usb_hub_descriptor *) buf); + break; ++ ++ case DeviceRequest | USB_REQ_GET_DESCRIPTOR: ++ if (hcd->speed != HCD_USB3) ++ goto error; ++ ++ if ((wValue >> 8) != USB_DT_BOS) ++ goto error; ++ ++ memcpy(buf, &usb3_bos_desc, sizeof(usb3_bos_desc)); ++ retval = sizeof(usb3_bos_desc); ++ break; ++ + case GetHubStatus: + *(__le32 *) buf = cpu_to_le32(0); + break; +@@ -2503,10 +2536,8 @@ static int dummy_hcd_probe(struct platform_device *pdev) + hs_hcd->has_tt = 1; + + retval = usb_add_hcd(hs_hcd, 0, 0); +- if (retval != 0) { +- usb_put_hcd(hs_hcd); +- return retval; +- } ++ if (retval) ++ goto put_usb2_hcd; + + if (mod_data.is_super_speed) { + ss_hcd = usb_create_shared_hcd(&dummy_hcd, &pdev->dev, +@@ -2525,6 +2556,8 @@ static int dummy_hcd_probe(struct platform_device *pdev) + put_usb3_hcd: + usb_put_hcd(ss_hcd); + dealloc_usb2_hcd: ++ usb_remove_hcd(hs_hcd); ++put_usb2_hcd: + usb_put_hcd(hs_hcd); + the_controller.hs_hcd = the_controller.ss_hcd = NULL; + return retval; +diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c +index f1f9290..7587615 100644 +--- a/drivers/usb/gadget/printer.c ++++ b/drivers/usb/gadget/printer.c +@@ -141,18 +141,14 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR); + * descriptors are built on demand. + */ + +-#define STRING_MANUFACTURER 1 +-#define STRING_PRODUCT 2 +-#define STRING_SERIALNUM 3 ++#define STRING_MANUFACTURER 0 ++#define STRING_PRODUCT 1 ++#define STRING_SERIALNUM 2 + + /* holds our biggest descriptor */ + #define USB_DESC_BUFSIZE 256 + #define USB_BUFSIZE 8192 + +-/* This device advertises one configuration. */ +-#define DEV_CONFIG_VALUE 1 +-#define PRINTER_INTERFACE 0 +- + static struct usb_device_descriptor device_desc = { + .bLength = sizeof device_desc, + .bDescriptorType = USB_DT_DEVICE, +@@ -162,16 +158,12 @@ static struct usb_device_descriptor device_desc = { + .bDeviceProtocol = 0, + .idVendor = cpu_to_le16(PRINTER_VENDOR_NUM), + .idProduct = cpu_to_le16(PRINTER_PRODUCT_NUM), +- .iManufacturer = STRING_MANUFACTURER, +- .iProduct = STRING_PRODUCT, +- .iSerialNumber = STRING_SERIALNUM, + .bNumConfigurations = 1 + }; + + static struct usb_interface_descriptor intf_desc = { + .bLength = sizeof intf_desc, + .bDescriptorType = USB_DT_INTERFACE, +- .bInterfaceNumber = PRINTER_INTERFACE, + .bNumEndpoints = 2, + .bInterfaceClass = USB_CLASS_PRINTER, + .bInterfaceSubClass = 1, /* Printer Sub-Class */ +@@ -260,9 +252,9 @@ static char pnp_string [1024] = + + /* static strings, in UTF-8 */ + static struct usb_string strings [] = { +- { STRING_MANUFACTURER, manufacturer, }, +- { STRING_PRODUCT, product_desc, }, +- { STRING_SERIALNUM, serial_num, }, ++ [STRING_MANUFACTURER].s = manufacturer, ++ [STRING_PRODUCT].s = product_desc, ++ [STRING_SERIALNUM].s = serial_num, + { } /* end of list */ + }; + +@@ -871,25 +863,13 @@ static int set_interface(struct printer_dev *dev, unsigned number) + int result = 0; + + /* Free the current interface */ +- switch (dev->interface) { +- case PRINTER_INTERFACE: +- printer_reset_interface(dev); +- break; +- } ++ printer_reset_interface(dev); + +- switch (number) { +- case PRINTER_INTERFACE: +- result = set_printer_interface(dev); +- if (result) { +- printer_reset_interface(dev); +- } else { +- dev->interface = PRINTER_INTERFACE; +- } +- break; +- default: +- result = -EINVAL; +- /* FALL THROUGH */ +- } ++ result = set_printer_interface(dev); ++ if (result) ++ printer_reset_interface(dev); ++ else ++ dev->interface = number; + + if (!result) + INFO(dev, "Using interface %x\n", number); +@@ -972,7 +952,7 @@ static int printer_func_setup(struct usb_function *f, + switch (ctrl->bRequest) { + case 0: /* Get the IEEE-1284 PNP String */ + /* Only one printer interface is supported. */ +- if ((wIndex>>8) != PRINTER_INTERFACE) ++ if ((wIndex>>8) != dev->interface) + break; + + value = (pnp_string[0]<<8)|pnp_string[1]; +@@ -983,7 +963,7 @@ static int printer_func_setup(struct usb_function *f, + + case 1: /* Get Port Status */ + /* Only one printer interface is supported. */ +- if (wIndex != PRINTER_INTERFACE) ++ if (wIndex != dev->interface) + break; + + *(u8 *)req->buf = dev->printer_status; +@@ -992,7 +972,7 @@ static int printer_func_setup(struct usb_function *f, + + case 2: /* Soft Reset */ + /* Only one printer interface is supported. */ +- if (wIndex != PRINTER_INTERFACE) ++ if (wIndex != dev->interface) + break; + + printer_soft_reset(dev); +@@ -1020,6 +1000,37 @@ unknown: + static int __init printer_func_bind(struct usb_configuration *c, + struct usb_function *f) + { ++ struct printer_dev *dev = container_of(f, struct printer_dev, function); ++ struct usb_composite_dev *cdev = c->cdev; ++ struct usb_ep *in_ep, *out_ep; ++ int id; ++ ++ id = usb_interface_id(c, f); ++ if (id < 0) ++ return id; ++ intf_desc.bInterfaceNumber = id; ++ ++ /* all we really need is bulk IN/OUT */ ++ in_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_in_desc); ++ if (!in_ep) { ++autoconf_fail: ++ dev_err(&cdev->gadget->dev, "can't autoconfigure on %s\n", ++ cdev->gadget->name); ++ return -ENODEV; ++ } ++ in_ep->driver_data = in_ep; /* claim */ ++ ++ out_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_out_desc); ++ if (!out_ep) ++ goto autoconf_fail; ++ out_ep->driver_data = out_ep; /* claim */ ++ ++ /* assumes that all endpoints are dual-speed */ ++ hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; ++ hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; ++ ++ dev->in_ep = in_ep; ++ dev->out_ep = out_ep; + return 0; + } + +@@ -1035,7 +1046,8 @@ static int printer_func_set_alt(struct usb_function *f, + int ret = -ENOTSUPP; + + if (!alt) +- ret = set_interface(dev, PRINTER_INTERFACE); ++ ret = set_interface(dev, intf); ++ + return ret; + } + +@@ -1107,13 +1119,14 @@ static int __init printer_bind_config(struct usb_configuration *c) + { + struct usb_gadget *gadget = c->cdev->gadget; + struct printer_dev *dev; +- struct usb_ep *in_ep, *out_ep; + int status = -ENOMEM; + int gcnum; + size_t len; + u32 i; + struct usb_request *req; + ++ usb_ep_autoconfig_reset(gadget); ++ + dev = &usb_printer_gadget; + + dev->function.name = shortname; +@@ -1125,6 +1138,10 @@ static int __init printer_bind_config(struct usb_configuration *c) + dev->function.set_alt = printer_func_set_alt; + dev->function.disable = printer_func_disable; + ++ status = usb_add_function(c, &dev->function); ++ if (status) ++ return status; ++ + /* Setup the sysfs files for the printer gadget. */ + dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, + NULL, "g_printer"); +@@ -1169,26 +1186,6 @@ static int __init printer_bind_config(struct usb_configuration *c) + pnp_string[0] = (len >> 8) & 0xFF; + pnp_string[1] = len & 0xFF; + +- /* all we really need is bulk IN/OUT */ +- usb_ep_autoconfig_reset(gadget); +- in_ep = usb_ep_autoconfig(gadget, &fs_ep_in_desc); +- if (!in_ep) { +-autoconf_fail: +- dev_err(&gadget->dev, "can't autoconfigure on %s\n", +- gadget->name); +- return -ENODEV; +- } +- in_ep->driver_data = in_ep; /* claim */ +- +- out_ep = usb_ep_autoconfig(gadget, &fs_ep_out_desc); +- if (!out_ep) +- goto autoconf_fail; +- out_ep->driver_data = out_ep; /* claim */ +- +- /* assumes that all endpoints are dual-speed */ +- hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; +- hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; +- + usb_gadget_set_selfpowered(gadget); + + if (gadget->is_otg) { +@@ -1215,9 +1212,6 @@ autoconf_fail: + dev->current_rx_bytes = 0; + dev->current_rx_buf = NULL; + +- dev->in_ep = in_ep; +- dev->out_ep = out_ep; +- + for (i = 0; i < QLEN; i++) { + req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); + if (!req) { +@@ -1250,8 +1244,6 @@ autoconf_fail: + dev->gadget = gadget; + + INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); +- INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, out_ep->name, +- in_ep->name); + return 0; + + fail: +@@ -1266,7 +1258,17 @@ static int printer_unbind(struct usb_composite_dev *cdev) + + static int __init printer_bind(struct usb_composite_dev *cdev) + { +- return usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); ++ int ret; ++ ++ ret = usb_string_ids_tab(cdev, strings); ++ if (ret < 0) ++ return ret; ++ device_desc.iManufacturer = strings[STRING_MANUFACTURER].id; ++ device_desc.iProduct = strings[STRING_PRODUCT].id; ++ device_desc.iSerialNumber = strings[STRING_SERIALNUM].id; ++ ++ ret = usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); ++ return ret; + } + + static struct usb_composite_driver printer_driver = { +diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c +index c46439c..cdfbac7 100644 +--- a/drivers/usb/gadget/tcm_usb_gadget.c ++++ b/drivers/usb/gadget/tcm_usb_gadget.c +@@ -1983,7 +1983,6 @@ static struct usb_interface_descriptor bot_intf_desc = { + .bInterfaceClass = USB_CLASS_MASS_STORAGE, + .bInterfaceSubClass = USB_SC_SCSI, + .bInterfaceProtocol = USB_PR_BULK, +- .iInterface = USB_G_STR_INT_UAS, + }; + + static struct usb_interface_descriptor uasp_intf_desc = { +@@ -1994,7 +1993,6 @@ static struct usb_interface_descriptor uasp_intf_desc = { + .bInterfaceClass = USB_CLASS_MASS_STORAGE, + .bInterfaceSubClass = USB_SC_SCSI, + .bInterfaceProtocol = USB_PR_UAS, +- .iInterface = USB_G_STR_INT_BBB, + }; + + static struct usb_endpoint_descriptor uasp_bi_desc = { +@@ -2215,20 +2213,16 @@ static struct usb_device_descriptor usbg_device_desc = { + .bDeviceClass = USB_CLASS_PER_INTERFACE, + .idVendor = cpu_to_le16(UAS_VENDOR_ID), + .idProduct = cpu_to_le16(UAS_PRODUCT_ID), +- .iManufacturer = USB_G_STR_MANUFACTOR, +- .iProduct = USB_G_STR_PRODUCT, +- .iSerialNumber = USB_G_STR_SERIAL, +- + .bNumConfigurations = 1, + }; + + static struct usb_string usbg_us_strings[] = { +- { USB_G_STR_MANUFACTOR, "Target Manufactor"}, +- { USB_G_STR_PRODUCT, "Target Product"}, +- { USB_G_STR_SERIAL, "000000000001"}, +- { USB_G_STR_CONFIG, "default config"}, +- { USB_G_STR_INT_UAS, "USB Attached SCSI"}, +- { USB_G_STR_INT_BBB, "Bulk Only Transport"}, ++ [USB_G_STR_MANUFACTOR].s = "Target Manufactor", ++ [USB_G_STR_PRODUCT].s = "Target Product", ++ [USB_G_STR_SERIAL].s = "000000000001", ++ [USB_G_STR_CONFIG].s = "default config", ++ [USB_G_STR_INT_UAS].s = "USB Attached SCSI", ++ [USB_G_STR_INT_BBB].s = "Bulk Only Transport", + { }, + }; + +@@ -2250,7 +2244,6 @@ static int guas_unbind(struct usb_composite_dev *cdev) + static struct usb_configuration usbg_config_driver = { + .label = "Linux Target", + .bConfigurationValue = 1, +- .iConfiguration = USB_G_STR_CONFIG, + .bmAttributes = USB_CONFIG_ATT_SELFPOWER, + }; + +@@ -2423,6 +2416,9 @@ static int usbg_cfg_bind(struct usb_configuration *c) + fu->function.disable = usbg_disable; + fu->tpg = the_only_tpg_I_currently_have; + ++ bot_intf_desc.iInterface = usbg_us_strings[USB_G_STR_INT_BBB].id; ++ uasp_intf_desc.iInterface = usbg_us_strings[USB_G_STR_INT_UAS].id; ++ + ret = usb_add_function(c, &fu->function); + if (ret) + goto err; +@@ -2437,6 +2433,17 @@ static int usb_target_bind(struct usb_composite_dev *cdev) + { + int ret; + ++ ret = usb_string_ids_tab(cdev, usbg_us_strings); ++ if (ret) ++ return ret; ++ ++ usbg_device_desc.iManufacturer = ++ usbg_us_strings[USB_G_STR_MANUFACTOR].id; ++ usbg_device_desc.iProduct = usbg_us_strings[USB_G_STR_PRODUCT].id; ++ usbg_device_desc.iSerialNumber = usbg_us_strings[USB_G_STR_SERIAL].id; ++ usbg_config_driver.iConfiguration = ++ usbg_us_strings[USB_G_STR_CONFIG].id; ++ + ret = usb_add_config(cdev, &usbg_config_driver, + usbg_cfg_bind); + return 0; +diff --git a/drivers/usb/gadget/tcm_usb_gadget.h b/drivers/usb/gadget/tcm_usb_gadget.h +index bb18999..9d32ec3 100644 +--- a/drivers/usb/gadget/tcm_usb_gadget.h ++++ b/drivers/usb/gadget/tcm_usb_gadget.h +@@ -16,12 +16,14 @@ + #define UASP_SS_EP_COMP_LOG_STREAMS 4 + #define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS) + +-#define USB_G_STR_MANUFACTOR 1 +-#define USB_G_STR_PRODUCT 2 +-#define USB_G_STR_SERIAL 3 +-#define USB_G_STR_CONFIG 4 +-#define USB_G_STR_INT_UAS 5 +-#define USB_G_STR_INT_BBB 6 ++enum { ++ USB_G_STR_MANUFACTOR, ++ USB_G_STR_PRODUCT, ++ USB_G_STR_SERIAL, ++ USB_G_STR_CONFIG, ++ USB_G_STR_INT_UAS, ++ USB_G_STR_INT_BBB, ++}; + + #define USB_G_ALT_INT_BBB 0 + #define USB_G_ALT_INT_UAS 1 +diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c +index 47cf48b..5617467 100644 +--- a/drivers/usb/gadget/u_ether.c ++++ b/drivers/usb/gadget/u_ether.c +@@ -669,6 +669,8 @@ static int eth_stop(struct net_device *net) + spin_lock_irqsave(&dev->lock, flags); + if (dev->port_usb) { + struct gether *link = dev->port_usb; ++ const struct usb_endpoint_descriptor *in; ++ const struct usb_endpoint_descriptor *out; + + if (link->close) + link->close(link); +@@ -682,10 +684,14 @@ static int eth_stop(struct net_device *net) + * their own pace; the network stack can handle old packets. + * For the moment we leave this here, since it works. + */ ++ in = link->in_ep->desc; ++ out = link->out_ep->desc; + usb_ep_disable(link->in_ep); + usb_ep_disable(link->out_ep); + if (netif_carrier_ok(net)) { + DBG(dev, "host still using in/out endpoints\n"); ++ link->in_ep->desc = in; ++ link->out_ep->desc = out; + usb_ep_enable(link->in_ep); + usb_ep_enable(link->out_ep); + } +@@ -798,12 +804,6 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], + + 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); +@@ -817,6 +817,12 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], + 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 --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c +index c304354..4a54418d 100644 +--- a/drivers/usb/host/ehci-omap.c ++++ b/drivers/usb/host/ehci-omap.c +@@ -56,15 +56,6 @@ + #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8 + #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0 + +-/* Errata i693 */ +-static struct clk *utmi_p1_fck; +-static struct clk *utmi_p2_fck; +-static struct clk *xclk60mhsp1_ck; +-static struct clk *xclk60mhsp2_ck; +-static struct clk *usbhost_p1_fck; +-static struct clk *usbhost_p2_fck; +-static struct clk *init_60m_fclk; +- + /*-------------------------------------------------------------------------*/ + + static const struct hc_driver ehci_omap_hc_driver; +@@ -80,40 +71,6 @@ static inline u32 ehci_read(void __iomem *base, u32 reg) + return __raw_readl(base + reg); + } + +-/* Erratum i693 workaround sequence */ +-static void omap_ehci_erratum_i693(struct ehci_hcd *ehci) +-{ +- int ret = 0; +- +- /* Switch to the internal 60 MHz clock */ +- ret = clk_set_parent(utmi_p1_fck, init_60m_fclk); +- if (ret != 0) +- ehci_err(ehci, "init_60m_fclk set parent" +- "failed error:%d\n", ret); +- +- ret = clk_set_parent(utmi_p2_fck, init_60m_fclk); +- if (ret != 0) +- ehci_err(ehci, "init_60m_fclk set parent" +- "failed error:%d\n", ret); +- +- clk_enable(usbhost_p1_fck); +- clk_enable(usbhost_p2_fck); +- +- /* Wait 1ms and switch back to the external clock */ +- mdelay(1); +- ret = clk_set_parent(utmi_p1_fck, xclk60mhsp1_ck); +- if (ret != 0) +- ehci_err(ehci, "xclk60mhsp1_ck set parent" +- "failed error:%d\n", ret); +- +- ret = clk_set_parent(utmi_p2_fck, xclk60mhsp2_ck); +- if (ret != 0) +- ehci_err(ehci, "xclk60mhsp2_ck set parent" +- "failed error:%d\n", ret); +- +- clk_disable(usbhost_p1_fck); +- clk_disable(usbhost_p2_fck); +-} + + static void omap_ehci_soft_phy_reset(struct platform_device *pdev, u8 port) + { +@@ -145,50 +102,6 @@ static void omap_ehci_soft_phy_reset(struct platform_device *pdev, u8 port) + } + } + +-static int omap_ehci_hub_control( +- struct usb_hcd *hcd, +- u16 typeReq, +- u16 wValue, +- u16 wIndex, +- char *buf, +- u16 wLength +-) +-{ +- struct ehci_hcd *ehci = hcd_to_ehci(hcd); +- u32 __iomem *status_reg = &ehci->regs->port_status[ +- (wIndex & 0xff) - 1]; +- u32 temp; +- unsigned long flags; +- int retval = 0; +- +- spin_lock_irqsave(&ehci->lock, flags); +- +- if (typeReq == SetPortFeature && wValue == USB_PORT_FEAT_SUSPEND) { +- temp = ehci_readl(ehci, status_reg); +- if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) != 0) { +- retval = -EPIPE; +- goto done; +- } +- +- temp &= ~PORT_WKCONN_E; +- temp |= PORT_WKDISC_E | PORT_WKOC_E; +- ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); +- +- omap_ehci_erratum_i693(ehci); +- +- set_bit((wIndex & 0xff) - 1, &ehci->suspended_ports); +- goto done; +- } +- +- spin_unlock_irqrestore(&ehci->lock, flags); +- +- /* Handle the hub control events here */ +- return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); +-done: +- spin_unlock_irqrestore(&ehci->lock, flags); +- return retval; +-} +- + static void disable_put_regulator( + struct ehci_hcd_omap_platform_data *pdata) + { +@@ -351,76 +264,9 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev) + /* root ports should always stay powered */ + ehci_port_power(omap_ehci, 1); + +- /* get clocks */ +- utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk"); +- if (IS_ERR(utmi_p1_fck)) { +- ret = PTR_ERR(utmi_p1_fck); +- dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret); +- goto err_add_hcd; +- } +- +- xclk60mhsp1_ck = clk_get(dev, "xclk60mhsp1_ck"); +- if (IS_ERR(xclk60mhsp1_ck)) { +- ret = PTR_ERR(xclk60mhsp1_ck); +- dev_err(dev, "xclk60mhsp1_ck failed error:%d\n", ret); +- goto err_utmi_p1_fck; +- } +- +- utmi_p2_fck = clk_get(dev, "utmi_p2_gfclk"); +- if (IS_ERR(utmi_p2_fck)) { +- ret = PTR_ERR(utmi_p2_fck); +- dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret); +- goto err_xclk60mhsp1_ck; +- } +- +- xclk60mhsp2_ck = clk_get(dev, "xclk60mhsp2_ck"); +- if (IS_ERR(xclk60mhsp2_ck)) { +- ret = PTR_ERR(xclk60mhsp2_ck); +- dev_err(dev, "xclk60mhsp2_ck failed error:%d\n", ret); +- goto err_utmi_p2_fck; +- } +- +- usbhost_p1_fck = clk_get(dev, "usb_host_hs_utmi_p1_clk"); +- if (IS_ERR(usbhost_p1_fck)) { +- ret = PTR_ERR(usbhost_p1_fck); +- dev_err(dev, "usbhost_p1_fck failed error:%d\n", ret); +- goto err_xclk60mhsp2_ck; +- } +- +- usbhost_p2_fck = clk_get(dev, "usb_host_hs_utmi_p2_clk"); +- if (IS_ERR(usbhost_p2_fck)) { +- ret = PTR_ERR(usbhost_p2_fck); +- dev_err(dev, "usbhost_p2_fck failed error:%d\n", ret); +- goto err_usbhost_p1_fck; +- } +- +- init_60m_fclk = clk_get(dev, "init_60m_fclk"); +- if (IS_ERR(init_60m_fclk)) { +- ret = PTR_ERR(init_60m_fclk); +- dev_err(dev, "init_60m_fclk failed error:%d\n", ret); +- goto err_usbhost_p2_fck; +- } + + return 0; + +-err_usbhost_p2_fck: +- clk_put(usbhost_p2_fck); +- +-err_usbhost_p1_fck: +- clk_put(usbhost_p1_fck); +- +-err_xclk60mhsp2_ck: +- clk_put(xclk60mhsp2_ck); +- +-err_utmi_p2_fck: +- clk_put(utmi_p2_fck); +- +-err_xclk60mhsp1_ck: +- clk_put(xclk60mhsp1_ck); +- +-err_utmi_p1_fck: +- clk_put(utmi_p1_fck); +- + err_add_hcd: + disable_put_regulator(pdata); + pm_runtime_put_sync(dev); +@@ -450,14 +296,6 @@ static int ehci_hcd_omap_remove(struct platform_device *pdev) + iounmap(hcd->regs); + usb_put_hcd(hcd); + +- clk_put(utmi_p1_fck); +- clk_put(utmi_p2_fck); +- clk_put(xclk60mhsp1_ck); +- clk_put(xclk60mhsp2_ck); +- clk_put(usbhost_p1_fck); +- clk_put(usbhost_p2_fck); +- clk_put(init_60m_fclk); +- + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); + +@@ -528,7 +366,7 @@ static const struct hc_driver ehci_omap_hc_driver = { + * root hub support + */ + .hub_status_data = ehci_hub_status_data, +- .hub_control = omap_ehci_hub_control, ++ .hub_control = ehci_hub_control, + .bus_suspend = ehci_bus_suspend, + .bus_resume = ehci_bus_resume, + +diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c +index 4378bf7..d2b0957 100644 +--- a/drivers/usb/host/ehci-q.c ++++ b/drivers/usb/host/ehci-q.c +@@ -128,9 +128,17 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh) + else { + qtd = list_entry (qh->qtd_list.next, + struct ehci_qtd, qtd_list); +- /* first qtd may already be partially processed */ +- if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current) ++ /* ++ * first qtd may already be partially processed. ++ * If we come here during unlink, the QH overlay region ++ * might have reference to the just unlinked qtd. The ++ * qtd is updated in qh_completions(). Update the QH ++ * overlay here. ++ */ ++ if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current) { ++ qh->hw->hw_qtd_next = qtd->hw_next; + qtd = NULL; ++ } + } + + if (qtd) +diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c +index a665b3e..0bf72f9 100644 +--- a/drivers/usb/host/ohci-at91.c ++++ b/drivers/usb/host/ohci-at91.c +@@ -467,7 +467,8 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) + /* From the GPIO notifying the over-current situation, find + * out the corresponding port */ + at91_for_each_port(port) { +- if (gpio_to_irq(pdata->overcurrent_pin[port]) == irq) { ++ if (gpio_is_valid(pdata->overcurrent_pin[port]) && ++ gpio_to_irq(pdata->overcurrent_pin[port]) == irq) { + gpio = pdata->overcurrent_pin[port]; + break; + } +@@ -570,6 +571,16 @@ static int __devinit ohci_hcd_at91_drv_probe(struct platform_device *pdev) + + if (pdata) { + at91_for_each_port(i) { ++ /* ++ * do not configure PIO if not in relation with ++ * real USB port on board ++ */ ++ if (i >= pdata->ports) { ++ pdata->vbus_pin[i] = -EINVAL; ++ pdata->overcurrent_pin[i] = -EINVAL; ++ break; ++ } ++ + if (!gpio_is_valid(pdata->vbus_pin[i])) + continue; + gpio = pdata->vbus_pin[i]; +diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c +index df0828c..966d148 100644 +--- a/drivers/usb/host/pci-quirks.c ++++ b/drivers/usb/host/pci-quirks.c +@@ -75,7 +75,9 @@ + #define NB_PIF0_PWRDOWN_1 0x01100013 + + #define USB_INTEL_XUSB2PR 0xD0 ++#define USB_INTEL_USB2PRM 0xD4 + #define USB_INTEL_USB3_PSSEN 0xD8 ++#define USB_INTEL_USB3PRM 0xDC + + static struct amd_chipset_info { + struct pci_dev *nb_dev; +@@ -772,10 +774,18 @@ void usb_enable_xhci_ports(struct pci_dev *xhci_pdev) + return; + } + +- ports_available = 0xffffffff; ++ /* Read USB3PRM, the USB 3.0 Port Routing Mask Register ++ * Indicate the ports that can be changed from OS. ++ */ ++ pci_read_config_dword(xhci_pdev, USB_INTEL_USB3PRM, ++ &ports_available); ++ ++ dev_dbg(&xhci_pdev->dev, "Configurable ports to enable SuperSpeed: 0x%x\n", ++ ports_available); ++ + /* Write USB3_PSSEN, the USB 3.0 Port SuperSpeed Enable +- * Register, to turn on SuperSpeed terminations for all +- * available ports. ++ * Register, to turn on SuperSpeed terminations for the ++ * switchable ports. + */ + pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN, + cpu_to_le32(ports_available)); +@@ -785,7 +795,16 @@ void usb_enable_xhci_ports(struct pci_dev *xhci_pdev) + dev_dbg(&xhci_pdev->dev, "USB 3.0 ports that are now enabled " + "under xHCI: 0x%x\n", ports_available); + +- ports_available = 0xffffffff; ++ /* Read XUSB2PRM, xHCI USB 2.0 Port Routing Mask Register ++ * Indicate the USB 2.0 ports to be controlled by the xHCI host. ++ */ ++ ++ pci_read_config_dword(xhci_pdev, USB_INTEL_USB2PRM, ++ &ports_available); ++ ++ dev_dbg(&xhci_pdev->dev, "Configurable USB 2.0 ports to hand over to xCHI: 0x%x\n", ++ ports_available); ++ + /* Write XUSB2PR, the xHC USB 2.0 Port Routing Register, to + * switch the USB 2.0 power and data lines over to the xHCI + * host. +@@ -800,6 +819,13 @@ void usb_enable_xhci_ports(struct pci_dev *xhci_pdev) + } + EXPORT_SYMBOL_GPL(usb_enable_xhci_ports); + ++void usb_disable_xhci_ports(struct pci_dev *xhci_pdev) ++{ ++ pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN, 0x0); ++ pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, 0x0); ++} ++EXPORT_SYMBOL_GPL(usb_disable_xhci_ports); ++ + /** + * PCI Quirks for xHCI. + * +@@ -815,12 +841,12 @@ static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev) + void __iomem *op_reg_base; + u32 val; + int timeout; ++ int len = pci_resource_len(pdev, 0); + + if (!mmio_resource_enabled(pdev, 0)) + return; + +- base = ioremap_nocache(pci_resource_start(pdev, 0), +- pci_resource_len(pdev, 0)); ++ base = ioremap_nocache(pci_resource_start(pdev, 0), len); + if (base == NULL) + return; + +@@ -830,9 +856,17 @@ static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev) + */ + ext_cap_offset = xhci_find_next_cap_offset(base, XHCI_HCC_PARAMS_OFFSET); + do { ++ if ((ext_cap_offset + sizeof(val)) > len) { ++ /* We're reading garbage from the controller */ ++ dev_warn(&pdev->dev, ++ "xHCI controller failing to respond"); ++ return; ++ } ++ + if (!ext_cap_offset) + /* We've reached the end of the extended capabilities */ + goto hc_init; ++ + val = readl(base + ext_cap_offset); + if (XHCI_EXT_CAPS_ID(val) == XHCI_EXT_CAPS_LEGACY) + break; +@@ -863,9 +897,10 @@ static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev) + /* Disable any BIOS SMIs and clear all SMI events*/ + writel(val, base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET); + ++hc_init: + if (usb_is_intel_switchable_xhci(pdev)) + usb_enable_xhci_ports(pdev); +-hc_init: ++ + op_reg_base = base + XHCI_HC_LENGTH(readl(base)); + + /* Wait for the host controller to be ready before writing any +diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h +index b1002a8..7f69a39 100644 +--- a/drivers/usb/host/pci-quirks.h ++++ b/drivers/usb/host/pci-quirks.h +@@ -10,10 +10,12 @@ void usb_amd_quirk_pll_disable(void); + void usb_amd_quirk_pll_enable(void); + bool usb_is_intel_switchable_xhci(struct pci_dev *pdev); + void usb_enable_xhci_ports(struct pci_dev *xhci_pdev); ++void usb_disable_xhci_ports(struct pci_dev *xhci_pdev); + #else + static inline void usb_amd_quirk_pll_disable(void) {} + static inline void usb_amd_quirk_pll_enable(void) {} + static inline void usb_amd_dev_put(void) {} ++static inline void usb_disable_xhci_ports(struct pci_dev *xhci_pdev) {} + #endif /* CONFIG_PCI */ + + #endif /* __LINUX_USB_PCI_QUIRKS_H */ +diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c +index 7b01094..32ca289 100644 +--- a/drivers/usb/host/xhci-hub.c ++++ b/drivers/usb/host/xhci-hub.c +@@ -493,11 +493,48 @@ static void xhci_hub_report_link_state(u32 *status, u32 status_reg) + * when this bit is set. + */ + pls |= USB_PORT_STAT_CONNECTION; ++ } else { ++ /* ++ * If CAS bit isn't set but the Port is already at ++ * Compliance Mode, fake a connection so the USB core ++ * notices the Compliance state and resets the port. ++ * This resolves an issue generated by the SN65LVPE502CP ++ * in which sometimes the port enters compliance mode ++ * caused by a delay on the host-device negotiation. ++ */ ++ if (pls == USB_SS_PORT_LS_COMP_MOD) ++ pls |= USB_PORT_STAT_CONNECTION; + } ++ + /* update status field */ + *status |= pls; + } + ++/* ++ * Function for Compliance Mode Quirk. ++ * ++ * This Function verifies if all xhc USB3 ports have entered U0, if so, ++ * the compliance mode timer is deleted. A port won't enter ++ * compliance mode if it has previously entered U0. ++ */ ++void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status, u16 wIndex) ++{ ++ u32 all_ports_seen_u0 = ((1 << xhci->num_usb3_ports)-1); ++ bool port_in_u0 = ((status & PORT_PLS_MASK) == XDEV_U0); ++ ++ if (!(xhci->quirks & XHCI_COMP_MODE_QUIRK)) ++ return; ++ ++ if ((xhci->port_status_u0 != all_ports_seen_u0) && port_in_u0) { ++ xhci->port_status_u0 |= 1 << wIndex; ++ if (xhci->port_status_u0 == all_ports_seen_u0) { ++ del_timer_sync(&xhci->comp_mode_recovery_timer); ++ xhci_dbg(xhci, "All USB3 ports have entered U0 already!\n"); ++ xhci_dbg(xhci, "Compliance Mode Recovery Timer Deleted.\n"); ++ } ++ } ++} ++ + int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, + u16 wIndex, char *buf, u16 wLength) + { +@@ -645,6 +682,11 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, + /* Update Port Link State for super speed ports*/ + if (hcd->speed == HCD_USB3) { + xhci_hub_report_link_state(&status, temp); ++ /* ++ * Verify if all USB3 Ports Have entered U0 already. ++ * Delete Compliance Mode Timer if so. ++ */ ++ xhci_del_comp_mod_timer(xhci, temp, wIndex); + } + if (bus_state->port_c_suspend & (1 << wIndex)) + status |= 1 << USB_PORT_FEAT_C_SUSPEND; +diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c +index 77689bd..487bc08 100644 +--- a/drivers/usb/host/xhci-mem.c ++++ b/drivers/usb/host/xhci-mem.c +@@ -1772,6 +1772,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) + { + struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); + struct dev_info *dev_info, *next; ++ struct xhci_cd *cur_cd, *next_cd; + unsigned long flags; + int size; + int i, j, num_ports; +@@ -1795,6 +1796,11 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) + xhci_ring_free(xhci, xhci->cmd_ring); + xhci->cmd_ring = NULL; + xhci_dbg(xhci, "Freed command ring\n"); ++ list_for_each_entry_safe(cur_cd, next_cd, ++ &xhci->cancel_cmd_list, cancel_cmd_list) { ++ list_del(&cur_cd->cancel_cmd_list); ++ kfree(cur_cd); ++ } + + for (i = 1; i < MAX_HC_SLOTS; ++i) + xhci_free_virt_device(xhci, i); +@@ -2340,6 +2346,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) + xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, flags); + if (!xhci->cmd_ring) + goto fail; ++ INIT_LIST_HEAD(&xhci->cancel_cmd_list); + xhci_dbg(xhci, "Allocated command ring at %p\n", xhci->cmd_ring); + xhci_dbg(xhci, "First segment DMA is 0x%llx\n", + (unsigned long long)xhci->cmd_ring->first_seg->dma); +diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c +index 18b231b..8345d7c 100644 +--- a/drivers/usb/host/xhci-pci.c ++++ b/drivers/usb/host/xhci-pci.c +@@ -94,11 +94,22 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) + xhci->quirks |= XHCI_EP_LIMIT_QUIRK; + xhci->limit_active_eps = 64; + xhci->quirks |= XHCI_SW_BW_CHECKING; ++ /* ++ * PPT desktop boards DH77EB and DH77DF will power back on after ++ * a few seconds of being shutdown. The fix for this is to ++ * switch the ports from xHCI to EHCI on shutdown. We can't use ++ * DMI information to find those particular boards (since each ++ * vendor will change the board name), so we have to key off all ++ * PPT chipsets. ++ */ ++ xhci->quirks |= XHCI_SPURIOUS_REBOOT; ++ xhci->quirks |= XHCI_AVOID_BEI; + } + if (pdev->vendor == PCI_VENDOR_ID_ETRON && + pdev->device == PCI_DEVICE_ID_ASROCK_P67) { + xhci->quirks |= XHCI_RESET_ON_RESUME; + xhci_dbg(xhci, "QUIRK: Resetting on resume\n"); ++ xhci->quirks |= XHCI_TRUST_TX_LENGTH; + } + if (pdev->vendor == PCI_VENDOR_ID_VIA) + xhci->quirks |= XHCI_RESET_ON_RESUME; +diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c +index 689bc18..df90fe5 100644 +--- a/drivers/usb/host/xhci-plat.c ++++ b/drivers/usb/host/xhci-plat.c +@@ -118,7 +118,7 @@ static int xhci_plat_probe(struct platform_device *pdev) + goto put_hcd; + } + +- hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); ++ hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); + if (!hcd->regs) { + dev_dbg(&pdev->dev, "error mapping memory\n"); + ret = -EFAULT; +diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c +index 8275645..47b6bb6 100644 +--- a/drivers/usb/host/xhci-ring.c ++++ b/drivers/usb/host/xhci-ring.c +@@ -145,29 +145,37 @@ static void next_trb(struct xhci_hcd *xhci, + */ + static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) + { +- union xhci_trb *next; + unsigned long long addr; + + ring->deq_updates++; + +- /* If this is not event ring, there is one more usable TRB */ ++ /* ++ * If this is not event ring, and the dequeue pointer ++ * is not on a link TRB, there is one more usable TRB ++ */ + if (ring->type != TYPE_EVENT && + !last_trb(xhci, ring, ring->deq_seg, ring->dequeue)) + ring->num_trbs_free++; +- next = ++(ring->dequeue); + +- /* Update the dequeue pointer further if that was a link TRB or we're at +- * the end of an event ring segment (which doesn't have link TRBS) +- */ +- while (last_trb(xhci, ring, ring->deq_seg, next)) { +- if (ring->type == TYPE_EVENT && last_trb_on_last_seg(xhci, +- ring, ring->deq_seg, next)) { +- ring->cycle_state = (ring->cycle_state ? 0 : 1); ++ do { ++ /* ++ * Update the dequeue pointer further if that was a link TRB or ++ * we're at the end of an event ring segment (which doesn't have ++ * link TRBS) ++ */ ++ if (last_trb(xhci, ring, ring->deq_seg, ring->dequeue)) { ++ if (ring->type == TYPE_EVENT && ++ last_trb_on_last_seg(xhci, ring, ++ ring->deq_seg, ring->dequeue)) { ++ ring->cycle_state = (ring->cycle_state ? 0 : 1); ++ } ++ ring->deq_seg = ring->deq_seg->next; ++ ring->dequeue = ring->deq_seg->trbs; ++ } else { ++ ring->dequeue++; + } +- ring->deq_seg = ring->deq_seg->next; +- ring->dequeue = ring->deq_seg->trbs; +- next = ring->dequeue; +- } ++ } while (last_trb(xhci, ring, ring->deq_seg, ring->dequeue)); ++ + addr = (unsigned long long) xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue); + } + +@@ -272,12 +280,123 @@ static inline int room_on_ring(struct xhci_hcd *xhci, struct xhci_ring *ring, + /* Ring the host controller doorbell after placing a command on the ring */ + void xhci_ring_cmd_db(struct xhci_hcd *xhci) + { ++ if (!(xhci->cmd_ring_state & CMD_RING_STATE_RUNNING)) ++ return; ++ + xhci_dbg(xhci, "// Ding dong!\n"); + xhci_writel(xhci, DB_VALUE_HOST, &xhci->dba->doorbell[0]); + /* Flush PCI posted writes */ + xhci_readl(xhci, &xhci->dba->doorbell[0]); + } + ++static int xhci_abort_cmd_ring(struct xhci_hcd *xhci) ++{ ++ u64 temp_64; ++ int ret; ++ ++ xhci_dbg(xhci, "Abort command ring\n"); ++ ++ if (!(xhci->cmd_ring_state & CMD_RING_STATE_RUNNING)) { ++ xhci_dbg(xhci, "The command ring isn't running, " ++ "Have the command ring been stopped?\n"); ++ return 0; ++ } ++ ++ temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); ++ if (!(temp_64 & CMD_RING_RUNNING)) { ++ xhci_dbg(xhci, "Command ring had been stopped\n"); ++ return 0; ++ } ++ xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; ++ xhci_write_64(xhci, temp_64 | CMD_RING_ABORT, ++ &xhci->op_regs->cmd_ring); ++ ++ /* Section 4.6.1.2 of xHCI 1.0 spec says software should ++ * time the completion od all xHCI commands, including ++ * the Command Abort operation. If software doesn't see ++ * CRR negated in a timely manner (e.g. longer than 5 ++ * seconds), then it should assume that the there are ++ * larger problems with the xHC and assert HCRST. ++ */ ++ ret = handshake(xhci, &xhci->op_regs->cmd_ring, ++ CMD_RING_RUNNING, 0, 5 * 1000 * 1000); ++ if (ret < 0) { ++ xhci_err(xhci, "Stopped the command ring failed, " ++ "maybe the host is dead\n"); ++ xhci->xhc_state |= XHCI_STATE_DYING; ++ xhci_quiesce(xhci); ++ xhci_halt(xhci); ++ return -ESHUTDOWN; ++ } ++ ++ return 0; ++} ++ ++static int xhci_queue_cd(struct xhci_hcd *xhci, ++ struct xhci_command *command, ++ union xhci_trb *cmd_trb) ++{ ++ struct xhci_cd *cd; ++ cd = kzalloc(sizeof(struct xhci_cd), GFP_ATOMIC); ++ if (!cd) ++ return -ENOMEM; ++ INIT_LIST_HEAD(&cd->cancel_cmd_list); ++ ++ cd->command = command; ++ cd->cmd_trb = cmd_trb; ++ list_add_tail(&cd->cancel_cmd_list, &xhci->cancel_cmd_list); ++ ++ return 0; ++} ++ ++/* ++ * Cancel the command which has issue. ++ * ++ * Some commands may hang due to waiting for acknowledgement from ++ * usb device. It is outside of the xHC's ability to control and ++ * will cause the command ring is blocked. When it occurs software ++ * should intervene to recover the command ring. ++ * See Section 4.6.1.1 and 4.6.1.2 ++ */ ++int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command, ++ union xhci_trb *cmd_trb) ++{ ++ int retval = 0; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&xhci->lock, flags); ++ ++ if (xhci->xhc_state & XHCI_STATE_DYING) { ++ xhci_warn(xhci, "Abort the command ring," ++ " but the xHCI is dead.\n"); ++ retval = -ESHUTDOWN; ++ goto fail; ++ } ++ ++ /* queue the cmd desriptor to cancel_cmd_list */ ++ retval = xhci_queue_cd(xhci, command, cmd_trb); ++ if (retval) { ++ xhci_warn(xhci, "Queuing command descriptor failed.\n"); ++ goto fail; ++ } ++ ++ /* abort command ring */ ++ retval = xhci_abort_cmd_ring(xhci); ++ if (retval) { ++ xhci_err(xhci, "Abort command ring failed\n"); ++ if (unlikely(retval == -ESHUTDOWN)) { ++ spin_unlock_irqrestore(&xhci->lock, flags); ++ usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); ++ xhci_dbg(xhci, "xHCI host controller is dead.\n"); ++ return retval; ++ } ++ } ++ ++fail: ++ spin_unlock_irqrestore(&xhci->lock, flags); ++ return retval; ++} ++ + void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, + unsigned int slot_id, + unsigned int ep_index, +@@ -1051,6 +1170,20 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci, + } + } + ++/* Complete the command and detele it from the devcie's command queue. ++ */ ++static void xhci_complete_cmd_in_cmd_wait_list(struct xhci_hcd *xhci, ++ struct xhci_command *command, u32 status) ++{ ++ command->status = status; ++ list_del(&command->cmd_list); ++ if (command->completion) ++ complete(command->completion); ++ else ++ xhci_free_command(xhci, command); ++} ++ ++ + /* Check to see if a command in the device's command queue matches this one. + * Signal the completion or free the command, and return 1. Return 0 if the + * completed command isn't at the head of the command list. +@@ -1069,15 +1202,144 @@ static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci, + if (xhci->cmd_ring->dequeue != command->command_trb) + return 0; + +- command->status = GET_COMP_CODE(le32_to_cpu(event->status)); +- list_del(&command->cmd_list); +- if (command->completion) +- complete(command->completion); +- else +- xhci_free_command(xhci, command); ++ xhci_complete_cmd_in_cmd_wait_list(xhci, command, ++ GET_COMP_CODE(le32_to_cpu(event->status))); + return 1; + } + ++/* ++ * Finding the command trb need to be cancelled and modifying it to ++ * NO OP command. And if the command is in device's command wait ++ * list, finishing and freeing it. ++ * ++ * If we can't find the command trb, we think it had already been ++ * executed. ++ */ ++static void xhci_cmd_to_noop(struct xhci_hcd *xhci, struct xhci_cd *cur_cd) ++{ ++ struct xhci_segment *cur_seg; ++ union xhci_trb *cmd_trb; ++ u32 cycle_state; ++ ++ if (xhci->cmd_ring->dequeue == xhci->cmd_ring->enqueue) ++ return; ++ ++ /* find the current segment of command ring */ ++ cur_seg = find_trb_seg(xhci->cmd_ring->first_seg, ++ xhci->cmd_ring->dequeue, &cycle_state); ++ ++ /* find the command trb matched by cd from command ring */ ++ for (cmd_trb = xhci->cmd_ring->dequeue; ++ cmd_trb != xhci->cmd_ring->enqueue; ++ next_trb(xhci, xhci->cmd_ring, &cur_seg, &cmd_trb)) { ++ /* If the trb is link trb, continue */ ++ if (TRB_TYPE_LINK_LE32(cmd_trb->generic.field[3])) ++ continue; ++ ++ if (cur_cd->cmd_trb == cmd_trb) { ++ ++ /* If the command in device's command list, we should ++ * finish it and free the command structure. ++ */ ++ if (cur_cd->command) ++ xhci_complete_cmd_in_cmd_wait_list(xhci, ++ cur_cd->command, COMP_CMD_STOP); ++ ++ /* get cycle state from the origin command trb */ ++ cycle_state = le32_to_cpu(cmd_trb->generic.field[3]) ++ & TRB_CYCLE; ++ ++ /* modify the command trb to NO OP command */ ++ cmd_trb->generic.field[0] = 0; ++ cmd_trb->generic.field[1] = 0; ++ cmd_trb->generic.field[2] = 0; ++ cmd_trb->generic.field[3] = cpu_to_le32( ++ TRB_TYPE(TRB_CMD_NOOP) | cycle_state); ++ break; ++ } ++ } ++} ++ ++static void xhci_cancel_cmd_in_cd_list(struct xhci_hcd *xhci) ++{ ++ struct xhci_cd *cur_cd, *next_cd; ++ ++ if (list_empty(&xhci->cancel_cmd_list)) ++ return; ++ ++ list_for_each_entry_safe(cur_cd, next_cd, ++ &xhci->cancel_cmd_list, cancel_cmd_list) { ++ xhci_cmd_to_noop(xhci, cur_cd); ++ list_del(&cur_cd->cancel_cmd_list); ++ kfree(cur_cd); ++ } ++} ++ ++/* ++ * traversing the cancel_cmd_list. If the command descriptor according ++ * to cmd_trb is found, the function free it and return 1, otherwise ++ * return 0. ++ */ ++static int xhci_search_cmd_trb_in_cd_list(struct xhci_hcd *xhci, ++ union xhci_trb *cmd_trb) ++{ ++ struct xhci_cd *cur_cd, *next_cd; ++ ++ if (list_empty(&xhci->cancel_cmd_list)) ++ return 0; ++ ++ list_for_each_entry_safe(cur_cd, next_cd, ++ &xhci->cancel_cmd_list, cancel_cmd_list) { ++ if (cur_cd->cmd_trb == cmd_trb) { ++ if (cur_cd->command) ++ xhci_complete_cmd_in_cmd_wait_list(xhci, ++ cur_cd->command, COMP_CMD_STOP); ++ list_del(&cur_cd->cancel_cmd_list); ++ kfree(cur_cd); ++ return 1; ++ } ++ } ++ ++ return 0; ++} ++ ++/* ++ * If the cmd_trb_comp_code is COMP_CMD_ABORT, we just check whether the ++ * trb pointed by the command ring dequeue pointer is the trb we want to ++ * cancel or not. And if the cmd_trb_comp_code is COMP_CMD_STOP, we will ++ * traverse the cancel_cmd_list to trun the all of the commands according ++ * to command descriptor to NO-OP trb. ++ */ ++static int handle_stopped_cmd_ring(struct xhci_hcd *xhci, ++ int cmd_trb_comp_code) ++{ ++ int cur_trb_is_good = 0; ++ ++ /* Searching the cmd trb pointed by the command ring dequeue ++ * pointer in command descriptor list. If it is found, free it. ++ */ ++ cur_trb_is_good = xhci_search_cmd_trb_in_cd_list(xhci, ++ xhci->cmd_ring->dequeue); ++ ++ if (cmd_trb_comp_code == COMP_CMD_ABORT) ++ xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; ++ else if (cmd_trb_comp_code == COMP_CMD_STOP) { ++ /* traversing the cancel_cmd_list and canceling ++ * the command according to command descriptor ++ */ ++ xhci_cancel_cmd_in_cd_list(xhci); ++ ++ xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; ++ /* ++ * ring command ring doorbell again to restart the ++ * command ring ++ */ ++ if (xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) ++ xhci_ring_cmd_db(xhci); ++ } ++ return cur_trb_is_good; ++} ++ + static void handle_cmd_completion(struct xhci_hcd *xhci, + struct xhci_event_cmd *event) + { +@@ -1103,6 +1365,22 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, + xhci->error_bitmask |= 1 << 5; + return; + } ++ ++ if ((GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_ABORT) || ++ (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_STOP)) { ++ /* If the return value is 0, we think the trb pointed by ++ * command ring dequeue pointer is a good trb. The good ++ * trb means we don't want to cancel the trb, but it have ++ * been stopped by host. So we should handle it normally. ++ * Otherwise, driver should invoke inc_deq() and return. ++ */ ++ if (handle_stopped_cmd_ring(xhci, ++ GET_COMP_CODE(le32_to_cpu(event->status)))) { ++ inc_deq(xhci, xhci->cmd_ring); ++ return; ++ } ++ } ++ + switch (le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3]) + & TRB_TYPE_BITMASK) { + case TRB_TYPE(TRB_ENABLE_SLOT): +@@ -3392,7 +3670,9 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, + } else { + td->last_trb = ep_ring->enqueue; + field |= TRB_IOC; +- if (xhci->hci_version == 0x100) { ++ if (xhci->hci_version == 0x100 && ++ !(xhci->quirks & ++ XHCI_AVOID_BEI)) { + /* Set BEI bit except for the last td */ + if (i < num_tds - 1) + field |= TRB_BEI; +diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c +index a979cd0..db4a2fa 100644 +--- a/drivers/usb/host/xhci.c ++++ b/drivers/usb/host/xhci.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + #include "xhci.h" + +@@ -51,7 +52,7 @@ MODULE_PARM_DESC(link_quirk, "Don't clear the chain bit on a link TRB"); + * handshake done). There are two failure modes: "usec" have passed (major + * hardware flakeout), or the register reads as all-ones (hardware removed). + */ +-static int handshake(struct xhci_hcd *xhci, void __iomem *ptr, ++int handshake(struct xhci_hcd *xhci, void __iomem *ptr, + u32 mask, u32 done, int usec) + { + u32 result; +@@ -104,9 +105,10 @@ int xhci_halt(struct xhci_hcd *xhci) + + ret = handshake(xhci, &xhci->op_regs->status, + STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); +- if (!ret) ++ if (!ret) { + xhci->xhc_state |= XHCI_STATE_HALTED; +- else ++ xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; ++ } else + xhci_warn(xhci, "Host not halted after %u microseconds.\n", + XHCI_MAX_HALT_USEC); + return ret; +@@ -166,7 +168,7 @@ int xhci_reset(struct xhci_hcd *xhci) + xhci_writel(xhci, command, &xhci->op_regs->command); + + ret = handshake(xhci, &xhci->op_regs->command, +- CMD_RESET, 0, 250 * 1000); ++ CMD_RESET, 0, 10 * 1000 * 1000); + if (ret) + return ret; + +@@ -175,7 +177,8 @@ int xhci_reset(struct xhci_hcd *xhci) + * xHCI cannot write to any doorbells or operational registers other + * than status until the "Controller Not Ready" flag is cleared. + */ +- ret = handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000); ++ ret = handshake(xhci, &xhci->op_regs->status, ++ STS_CNR, 0, 10 * 1000 * 1000); + + for (i = 0; i < 2; ++i) { + xhci->bus_state[i].port_c_suspend = 0; +@@ -397,6 +400,97 @@ static void xhci_msix_sync_irqs(struct xhci_hcd *xhci) + + #endif + ++static void compliance_mode_recovery(unsigned long arg) ++{ ++ struct xhci_hcd *xhci; ++ struct usb_hcd *hcd; ++ u32 temp; ++ int i; ++ ++ xhci = (struct xhci_hcd *)arg; ++ ++ for (i = 0; i < xhci->num_usb3_ports; i++) { ++ temp = xhci_readl(xhci, xhci->usb3_ports[i]); ++ if ((temp & PORT_PLS_MASK) == USB_SS_PORT_LS_COMP_MOD) { ++ /* ++ * Compliance Mode Detected. Letting USB Core ++ * handle the Warm Reset ++ */ ++ xhci_dbg(xhci, "Compliance Mode Detected->Port %d!\n", ++ i + 1); ++ xhci_dbg(xhci, "Attempting Recovery routine!\n"); ++ hcd = xhci->shared_hcd; ++ ++ if (hcd->state == HC_STATE_SUSPENDED) ++ usb_hcd_resume_root_hub(hcd); ++ ++ usb_hcd_poll_rh_status(hcd); ++ } ++ } ++ ++ if (xhci->port_status_u0 != ((1 << xhci->num_usb3_ports)-1)) ++ mod_timer(&xhci->comp_mode_recovery_timer, ++ jiffies + msecs_to_jiffies(COMP_MODE_RCVRY_MSECS)); ++} ++ ++/* ++ * Quirk to work around issue generated by the SN65LVPE502CP USB3.0 re-driver ++ * that causes ports behind that hardware to enter compliance mode sometimes. ++ * The quirk creates a timer that polls every 2 seconds the link state of ++ * each host controller's port and recovers it by issuing a Warm reset ++ * if Compliance mode is detected, otherwise the port will become "dead" (no ++ * device connections or disconnections will be detected anymore). Becasue no ++ * status event is generated when entering compliance mode (per xhci spec), ++ * this quirk is needed on systems that have the failing hardware installed. ++ */ ++static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci) ++{ ++ xhci->port_status_u0 = 0; ++ init_timer(&xhci->comp_mode_recovery_timer); ++ ++ xhci->comp_mode_recovery_timer.data = (unsigned long) xhci; ++ xhci->comp_mode_recovery_timer.function = compliance_mode_recovery; ++ xhci->comp_mode_recovery_timer.expires = jiffies + ++ msecs_to_jiffies(COMP_MODE_RCVRY_MSECS); ++ ++ set_timer_slack(&xhci->comp_mode_recovery_timer, ++ msecs_to_jiffies(COMP_MODE_RCVRY_MSECS)); ++ add_timer(&xhci->comp_mode_recovery_timer); ++ xhci_dbg(xhci, "Compliance Mode Recovery Timer Initialized.\n"); ++} ++ ++/* ++ * This function identifies the systems that have installed the SN65LVPE502CP ++ * USB3.0 re-driver and that need the Compliance Mode Quirk. ++ * Systems: ++ * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820 ++ */ ++static bool compliance_mode_recovery_timer_quirk_check(void) ++{ ++ const char *dmi_product_name, *dmi_sys_vendor; ++ ++ dmi_product_name = dmi_get_system_info(DMI_PRODUCT_NAME); ++ dmi_sys_vendor = dmi_get_system_info(DMI_SYS_VENDOR); ++ if (!dmi_product_name || !dmi_sys_vendor) ++ return false; ++ ++ if (!(strstr(dmi_sys_vendor, "Hewlett-Packard"))) ++ return false; ++ ++ if (strstr(dmi_product_name, "Z420") || ++ strstr(dmi_product_name, "Z620") || ++ strstr(dmi_product_name, "Z820")) ++ return true; ++ ++ return false; ++} ++ ++static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci) ++{ ++ return (xhci->port_status_u0 == ((1 << xhci->num_usb3_ports)-1)); ++} ++ ++ + /* + * Initialize memory for HCD and xHC (one-time init). + * +@@ -420,6 +514,12 @@ int xhci_init(struct usb_hcd *hcd) + retval = xhci_mem_init(xhci, GFP_KERNEL); + xhci_dbg(xhci, "Finished xhci_init\n"); + ++ /* Initializing Compliance Mode Recovery Data If Needed */ ++ if (compliance_mode_recovery_timer_quirk_check()) { ++ xhci->quirks |= XHCI_COMP_MODE_QUIRK; ++ compliance_mode_recovery_timer_init(xhci); ++ } ++ + return retval; + } + +@@ -484,6 +584,7 @@ static int xhci_run_finished(struct xhci_hcd *xhci) + return -ENODEV; + } + xhci->shared_hcd->state = HC_STATE_RUNNING; ++ xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; + + if (xhci->quirks & XHCI_NEC_HOST) + xhci_ring_cmd_db(xhci); +@@ -628,6 +729,11 @@ void xhci_stop(struct usb_hcd *hcd) + del_timer_sync(&xhci->event_ring_timer); + #endif + ++ /* Deleting Compliance Mode Recovery Timer */ ++ if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && ++ (!(xhci_all_ports_seen_u0(xhci)))) ++ del_timer_sync(&xhci->comp_mode_recovery_timer); ++ + if (xhci->quirks & XHCI_AMD_PLL_FIX) + usb_amd_dev_put(); + +@@ -658,6 +764,9 @@ void xhci_shutdown(struct usb_hcd *hcd) + { + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + ++ if (xhci->quirks & XHCI_SPURIOUS_REBOOT) ++ usb_disable_xhci_ports(to_pci_dev(hcd->self.controller)); ++ + spin_lock_irq(&xhci->lock); + xhci_halt(xhci); + spin_unlock_irq(&xhci->lock); +@@ -781,7 +890,7 @@ int xhci_suspend(struct xhci_hcd *xhci) + command &= ~CMD_RUN; + xhci_writel(xhci, command, &xhci->op_regs->command); + if (handshake(xhci, &xhci->op_regs->status, +- STS_HALT, STS_HALT, 100*100)) { ++ STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC)) { + xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n"); + spin_unlock_irq(&xhci->lock); + return -ETIMEDOUT; +@@ -802,6 +911,16 @@ int xhci_suspend(struct xhci_hcd *xhci) + } + spin_unlock_irq(&xhci->lock); + ++ /* ++ * Deleting Compliance Mode Recovery Timer because the xHCI Host ++ * is about to be suspended. ++ */ ++ if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && ++ (!(xhci_all_ports_seen_u0(xhci)))) { ++ del_timer_sync(&xhci->comp_mode_recovery_timer); ++ xhci_dbg(xhci, "Compliance Mode Recovery Timer Deleted!\n"); ++ } ++ + /* step 5: remove core well power */ + /* synchronize irq when using MSI-X */ + xhci_msix_sync_irqs(xhci); +@@ -934,6 +1053,16 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) + usb_hcd_resume_root_hub(hcd); + usb_hcd_resume_root_hub(xhci->shared_hcd); + } ++ ++ /* ++ * If system is subject to the Quirk, Compliance Mode Timer needs to ++ * be re-initialized Always after a system resume. Ports are subject ++ * to suffer the Compliance Mode issue again. It doesn't matter if ++ * ports have entered previously to U0 before system's suspension. ++ */ ++ if (xhci->quirks & XHCI_COMP_MODE_QUIRK) ++ compliance_mode_recovery_timer_init(xhci); ++ + return retval; + } + #endif /* CONFIG_PM */ +@@ -2396,6 +2525,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, + struct completion *cmd_completion; + u32 *cmd_status; + struct xhci_virt_device *virt_dev; ++ union xhci_trb *cmd_trb; + + spin_lock_irqsave(&xhci->lock, flags); + virt_dev = xhci->devs[udev->slot_id]; +@@ -2441,6 +2571,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, + } + init_completion(cmd_completion); + ++ cmd_trb = xhci->cmd_ring->dequeue; + if (!ctx_change) + ret = xhci_queue_configure_endpoint(xhci, in_ctx->dma, + udev->slot_id, must_succeed); +@@ -2462,14 +2593,17 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, + /* Wait for the configure endpoint command to complete */ + timeleft = wait_for_completion_interruptible_timeout( + cmd_completion, +- USB_CTRL_SET_TIMEOUT); ++ XHCI_CMD_DEFAULT_TIMEOUT); + if (timeleft <= 0) { + xhci_warn(xhci, "%s while waiting for %s command\n", + timeleft == 0 ? "Timeout" : "Signal", + ctx_change == 0 ? + "configure endpoint" : + "evaluate context"); +- /* FIXME cancel the configure endpoint command */ ++ /* cancel the configure endpoint command */ ++ ret = xhci_cancel_cmd(xhci, command, cmd_trb); ++ if (ret < 0) ++ return ret; + return -ETIME; + } + +@@ -3418,8 +3552,10 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) + unsigned long flags; + int timeleft; + int ret; ++ union xhci_trb *cmd_trb; + + spin_lock_irqsave(&xhci->lock, flags); ++ cmd_trb = xhci->cmd_ring->dequeue; + ret = xhci_queue_slot_control(xhci, TRB_ENABLE_SLOT, 0); + if (ret) { + spin_unlock_irqrestore(&xhci->lock, flags); +@@ -3431,12 +3567,12 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) + + /* XXX: how much time for xHC slot assignment? */ + timeleft = wait_for_completion_interruptible_timeout(&xhci->addr_dev, +- USB_CTRL_SET_TIMEOUT); ++ XHCI_CMD_DEFAULT_TIMEOUT); + if (timeleft <= 0) { + xhci_warn(xhci, "%s while waiting for a slot\n", + timeleft == 0 ? "Timeout" : "Signal"); +- /* FIXME cancel the enable slot request */ +- return 0; ++ /* cancel the enable slot request */ ++ return xhci_cancel_cmd(xhci, NULL, cmd_trb); + } + + if (!xhci->slot_id) { +@@ -3497,6 +3633,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) + struct xhci_slot_ctx *slot_ctx; + struct xhci_input_control_ctx *ctrl_ctx; + u64 temp_64; ++ union xhci_trb *cmd_trb; + + if (!udev->slot_id) { + xhci_dbg(xhci, "Bad Slot ID %d\n", udev->slot_id); +@@ -3535,6 +3672,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) + xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); + + spin_lock_irqsave(&xhci->lock, flags); ++ cmd_trb = xhci->cmd_ring->dequeue; + ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma, + udev->slot_id); + if (ret) { +@@ -3547,7 +3685,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) + + /* ctrl tx can take up to 5 sec; XXX: need more time for xHC? */ + timeleft = wait_for_completion_interruptible_timeout(&xhci->addr_dev, +- USB_CTRL_SET_TIMEOUT); ++ XHCI_CMD_DEFAULT_TIMEOUT); + /* FIXME: From section 4.3.4: "Software shall be responsible for timing + * the SetAddress() "recovery interval" required by USB and aborting the + * command on a timeout. +@@ -3555,7 +3693,10 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) + if (timeleft <= 0) { + xhci_warn(xhci, "%s while waiting for address device command\n", + timeleft == 0 ? "Timeout" : "Signal"); +- /* FIXME cancel the address device command */ ++ /* cancel the address device command */ ++ ret = xhci_cancel_cmd(xhci, NULL, cmd_trb); ++ if (ret < 0) ++ return ret; + return -ETIME; + } + +diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h +index 55c0785..b2a5527 100644 +--- a/drivers/usb/host/xhci.h ++++ b/drivers/usb/host/xhci.h +@@ -1256,6 +1256,16 @@ struct xhci_td { + union xhci_trb *last_trb; + }; + ++/* xHCI command default timeout value */ ++#define XHCI_CMD_DEFAULT_TIMEOUT (5 * HZ) ++ ++/* command descriptor */ ++struct xhci_cd { ++ struct list_head cancel_cmd_list; ++ struct xhci_command *command; ++ union xhci_trb *cmd_trb; ++}; ++ + struct xhci_dequeue_state { + struct xhci_segment *new_deq_seg; + union xhci_trb *new_deq_ptr; +@@ -1421,6 +1431,11 @@ struct xhci_hcd { + /* data structures */ + struct xhci_device_context_array *dcbaa; + struct xhci_ring *cmd_ring; ++ unsigned int cmd_ring_state; ++#define CMD_RING_STATE_RUNNING (1 << 0) ++#define CMD_RING_STATE_ABORTED (1 << 1) ++#define CMD_RING_STATE_STOPPED (1 << 2) ++ struct list_head cancel_cmd_list; + unsigned int cmd_ring_reserved_trbs; + struct xhci_ring *event_ring; + struct xhci_erst erst; +@@ -1494,6 +1509,9 @@ struct xhci_hcd { + #define XHCI_TRUST_TX_LENGTH (1 << 10) + #define XHCI_LPM_SUPPORT (1 << 11) + #define XHCI_INTEL_HOST (1 << 12) ++#define XHCI_SPURIOUS_REBOOT (1 << 13) ++#define XHCI_COMP_MODE_QUIRK (1 << 14) ++#define XHCI_AVOID_BEI (1 << 15) + unsigned int num_active_eps; + unsigned int limit_active_eps; + /* There are two roothubs to keep track of bus suspend info for */ +@@ -1510,6 +1528,11 @@ struct xhci_hcd { + unsigned sw_lpm_support:1; + /* support xHCI 1.0 spec USB2 hardware LPM */ + unsigned hw_lpm_support:1; ++ /* Compliance Mode Recovery Data */ ++ struct timer_list comp_mode_recovery_timer; ++ u32 port_status_u0; ++/* Compliance Mode Timer Triggered every 2 seconds */ ++#define COMP_MODE_RCVRY_MSECS 2000 + }; + + /* convert between an HCD pointer and the corresponding EHCI_HCD */ +@@ -1695,6 +1718,8 @@ static inline void xhci_unregister_plat(void) + + /* xHCI host controller glue */ + typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *); ++int handshake(struct xhci_hcd *xhci, void __iomem *ptr, ++ u32 mask, u32 done, int usec); + void xhci_quiesce(struct xhci_hcd *xhci); + int xhci_halt(struct xhci_hcd *xhci); + int xhci_reset(struct xhci_hcd *xhci); +@@ -1785,6 +1810,8 @@ void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci, + unsigned int slot_id, unsigned int ep_index, + struct xhci_dequeue_state *deq_state); + void xhci_stop_endpoint_command_watchdog(unsigned long arg); ++int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command, ++ union xhci_trb *cmd_trb); + void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, + unsigned int ep_index, unsigned int stream_id); + +diff --git a/drivers/usb/misc/emi62.c b/drivers/usb/misc/emi62.c +index ff08015..ae794b9 100644 +--- a/drivers/usb/misc/emi62.c ++++ b/drivers/usb/misc/emi62.c +@@ -232,7 +232,7 @@ wraperr: + return err; + } + +-static const struct usb_device_id id_table[] __devinitconst = { ++static const struct usb_device_id id_table[] = { + { USB_DEVICE(EMI62_VENDOR_ID, EMI62_PRODUCT_ID) }, + { } /* Terminating entry */ + }; +diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c +index bc912e5..b71ee32 100644 +--- a/drivers/usb/serial/ftdi_sio.c ++++ b/drivers/usb/serial/ftdi_sio.c +@@ -584,6 +584,8 @@ static struct usb_device_id id_table_combined [] = { + { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_TAVIR_STK500_PID) }, ++ { USB_DEVICE(FTDI_VID, FTDI_TIAO_UMPA_PID), ++ .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, + /* + * ELV devices: + */ +@@ -704,6 +706,7 @@ static struct usb_device_id id_table_combined [] = { + { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_RRCIRKITS_LOCOBUFFER_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ASK_RDR400_PID) }, ++ { USB_DEVICE(FTDI_VID, FTDI_NZR_SEM_USB_PID) }, + { USB_DEVICE(ICOM_VID, ICOM_ID_1_PID) }, + { USB_DEVICE(ICOM_VID, ICOM_OPC_U_UC_PID) }, + { USB_DEVICE(ICOM_VID, ICOM_ID_RP2C1_PID) }, +@@ -804,13 +807,33 @@ static struct usb_device_id id_table_combined [] = { + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, + { USB_DEVICE(ADI_VID, ADI_GNICEPLUS_PID), + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, +- { USB_DEVICE(MICROCHIP_VID, MICROCHIP_USB_BOARD_PID) }, ++ { USB_DEVICE_AND_INTERFACE_INFO(MICROCHIP_VID, MICROCHIP_USB_BOARD_PID, ++ USB_CLASS_VENDOR_SPEC, ++ USB_SUBCLASS_VENDOR_SPEC, 0x00) }, + { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) }, + { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID), + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, + { USB_DEVICE(LARSENBRUSGAARD_VID, LB_ALTITRACK_PID) }, + { USB_DEVICE(GN_OTOMETRICS_VID, AURICAL_USB_PID) }, ++ { USB_DEVICE(FTDI_VID, PI_C865_PID) }, ++ { USB_DEVICE(FTDI_VID, PI_C857_PID) }, ++ { USB_DEVICE(PI_VID, PI_C866_PID) }, ++ { USB_DEVICE(PI_VID, PI_C663_PID) }, ++ { USB_DEVICE(PI_VID, PI_C725_PID) }, ++ { USB_DEVICE(PI_VID, PI_E517_PID) }, ++ { USB_DEVICE(PI_VID, PI_C863_PID) }, + { USB_DEVICE(PI_VID, PI_E861_PID) }, ++ { USB_DEVICE(PI_VID, PI_C867_PID) }, ++ { USB_DEVICE(PI_VID, PI_E609_PID) }, ++ { USB_DEVICE(PI_VID, PI_E709_PID) }, ++ { USB_DEVICE(PI_VID, PI_100F_PID) }, ++ { USB_DEVICE(PI_VID, PI_1011_PID) }, ++ { USB_DEVICE(PI_VID, PI_1012_PID) }, ++ { USB_DEVICE(PI_VID, PI_1013_PID) }, ++ { USB_DEVICE(PI_VID, PI_1014_PID) }, ++ { USB_DEVICE(PI_VID, PI_1015_PID) }, ++ { USB_DEVICE(PI_VID, PI_1016_PID) }, ++ { USB_DEVICE(KONDO_VID, KONDO_USB_SERIAL_PID) }, + { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) }, + { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID), + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, +diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h +index 5661c7e..57c12ef 100644 +--- a/drivers/usb/serial/ftdi_sio_ids.h ++++ b/drivers/usb/serial/ftdi_sio_ids.h +@@ -75,6 +75,9 @@ + #define FTDI_OPENDCC_GATEWAY_PID 0xBFDB + #define FTDI_OPENDCC_GBM_PID 0xBFDC + ++/* NZR SEM 16+ USB (http://www.nzr.de) */ ++#define FTDI_NZR_SEM_USB_PID 0xC1E0 /* NZR SEM-LOG16+ */ ++ + /* + * RR-CirKits LocoBuffer USB (http://www.rr-cirkits.com) + */ +@@ -514,6 +517,11 @@ + */ + #define FTDI_TAVIR_STK500_PID 0xFA33 /* STK500 AVR programmer */ + ++/* ++ * TIAO product ids (FTDI_VID) ++ * http://www.tiaowiki.com/w/Main_Page ++ */ ++#define FTDI_TIAO_UMPA_PID 0x8a98 /* TIAO/DIYGADGET USB Multi-Protocol Adapter */ + + + /********************************/ +@@ -539,7 +547,10 @@ + /* + * Microchip Technology, Inc. + * +- * MICROCHIP_VID (0x04D8) and MICROCHIP_USB_BOARD_PID (0x000A) are also used by: ++ * MICROCHIP_VID (0x04D8) and MICROCHIP_USB_BOARD_PID (0x000A) are ++ * used by single function CDC ACM class based firmware demo ++ * applications. The VID/PID has also been used in firmware ++ * emulating FTDI serial chips by: + * Hornby Elite - Digital Command Control Console + * http://www.hornby.com/hornby-dcc/controllers/ + */ +@@ -791,8 +802,34 @@ + * Physik Instrumente + * http://www.physikinstrumente.com/en/products/ + */ ++/* These two devices use the VID of FTDI */ ++#define PI_C865_PID 0xe0a0 /* PI C-865 Piezomotor Controller */ ++#define PI_C857_PID 0xe0a1 /* PI Encoder Trigger Box */ ++ + #define PI_VID 0x1a72 /* Vendor ID */ +-#define PI_E861_PID 0x1008 /* E-861 piezo controller USB connection */ ++#define PI_C866_PID 0x1000 /* PI C-866 Piezomotor Controller */ ++#define PI_C663_PID 0x1001 /* PI C-663 Mercury-Step */ ++#define PI_C725_PID 0x1002 /* PI C-725 Piezomotor Controller */ ++#define PI_E517_PID 0x1005 /* PI E-517 Digital Piezo Controller Operation Module */ ++#define PI_C863_PID 0x1007 /* PI C-863 */ ++#define PI_E861_PID 0x1008 /* PI E-861 Piezomotor Controller */ ++#define PI_C867_PID 0x1009 /* PI C-867 Piezomotor Controller */ ++#define PI_E609_PID 0x100D /* PI E-609 Digital Piezo Controller */ ++#define PI_E709_PID 0x100E /* PI E-709 Digital Piezo Controller */ ++#define PI_100F_PID 0x100F /* PI Digital Piezo Controller */ ++#define PI_1011_PID 0x1011 /* PI Digital Piezo Controller */ ++#define PI_1012_PID 0x1012 /* PI Motion Controller */ ++#define PI_1013_PID 0x1013 /* PI Motion Controller */ ++#define PI_1014_PID 0x1014 /* PI Device */ ++#define PI_1015_PID 0x1015 /* PI Device */ ++#define PI_1016_PID 0x1016 /* PI Digital Servo Module */ ++ ++/* ++ * Kondo Kagaku Co.Ltd. ++ * http://www.kondo-robot.com/EN ++ */ ++#define KONDO_VID 0x165c ++#define KONDO_USB_SERIAL_PID 0x0002 + + /* + * Bayer Ascensia Contour blood glucose meter USB-converter cable. +diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c +index 57eca24..009c1d9 100644 +--- a/drivers/usb/serial/mos7840.c ++++ b/drivers/usb/serial/mos7840.c +@@ -1232,9 +1232,12 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty) + return 0; + + spin_lock_irqsave(&mos7840_port->pool_lock, flags); +- for (i = 0; i < NUM_URBS; ++i) +- if (mos7840_port->busy[i]) +- chars += URB_TRANSFER_BUFFER_SIZE; ++ for (i = 0; i < NUM_URBS; ++i) { ++ if (mos7840_port->busy[i]) { ++ struct urb *urb = mos7840_port->write_urb_pool[i]; ++ chars += urb->transfer_buffer_length; ++ } ++ } + spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); + dbg("%s - returns %d", __func__, chars); + return chars; +diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c +index 417ab1b..d581ed3 100644 +--- a/drivers/usb/serial/option.c ++++ b/drivers/usb/serial/option.c +@@ -80,85 +80,9 @@ static void option_instat_callback(struct urb *urb); + #define OPTION_PRODUCT_GTM380_MODEM 0x7201 + + #define HUAWEI_VENDOR_ID 0x12D1 +-#define HUAWEI_PRODUCT_E600 0x1001 +-#define HUAWEI_PRODUCT_E220 0x1003 +-#define HUAWEI_PRODUCT_E220BIS 0x1004 +-#define HUAWEI_PRODUCT_E1401 0x1401 +-#define HUAWEI_PRODUCT_E1402 0x1402 +-#define HUAWEI_PRODUCT_E1403 0x1403 +-#define HUAWEI_PRODUCT_E1404 0x1404 +-#define HUAWEI_PRODUCT_E1405 0x1405 +-#define HUAWEI_PRODUCT_E1406 0x1406 +-#define HUAWEI_PRODUCT_E1407 0x1407 +-#define HUAWEI_PRODUCT_E1408 0x1408 +-#define HUAWEI_PRODUCT_E1409 0x1409 +-#define HUAWEI_PRODUCT_E140A 0x140A +-#define HUAWEI_PRODUCT_E140B 0x140B +-#define HUAWEI_PRODUCT_E140C 0x140C +-#define HUAWEI_PRODUCT_E140D 0x140D +-#define HUAWEI_PRODUCT_E140E 0x140E +-#define HUAWEI_PRODUCT_E140F 0x140F +-#define HUAWEI_PRODUCT_E1410 0x1410 +-#define HUAWEI_PRODUCT_E1411 0x1411 +-#define HUAWEI_PRODUCT_E1412 0x1412 +-#define HUAWEI_PRODUCT_E1413 0x1413 +-#define HUAWEI_PRODUCT_E1414 0x1414 +-#define HUAWEI_PRODUCT_E1415 0x1415 +-#define HUAWEI_PRODUCT_E1416 0x1416 +-#define HUAWEI_PRODUCT_E1417 0x1417 +-#define HUAWEI_PRODUCT_E1418 0x1418 +-#define HUAWEI_PRODUCT_E1419 0x1419 +-#define HUAWEI_PRODUCT_E141A 0x141A +-#define HUAWEI_PRODUCT_E141B 0x141B +-#define HUAWEI_PRODUCT_E141C 0x141C +-#define HUAWEI_PRODUCT_E141D 0x141D +-#define HUAWEI_PRODUCT_E141E 0x141E +-#define HUAWEI_PRODUCT_E141F 0x141F +-#define HUAWEI_PRODUCT_E1420 0x1420 +-#define HUAWEI_PRODUCT_E1421 0x1421 +-#define HUAWEI_PRODUCT_E1422 0x1422 +-#define HUAWEI_PRODUCT_E1423 0x1423 +-#define HUAWEI_PRODUCT_E1424 0x1424 +-#define HUAWEI_PRODUCT_E1425 0x1425 +-#define HUAWEI_PRODUCT_E1426 0x1426 +-#define HUAWEI_PRODUCT_E1427 0x1427 +-#define HUAWEI_PRODUCT_E1428 0x1428 +-#define HUAWEI_PRODUCT_E1429 0x1429 +-#define HUAWEI_PRODUCT_E142A 0x142A +-#define HUAWEI_PRODUCT_E142B 0x142B +-#define HUAWEI_PRODUCT_E142C 0x142C +-#define HUAWEI_PRODUCT_E142D 0x142D +-#define HUAWEI_PRODUCT_E142E 0x142E +-#define HUAWEI_PRODUCT_E142F 0x142F +-#define HUAWEI_PRODUCT_E1430 0x1430 +-#define HUAWEI_PRODUCT_E1431 0x1431 +-#define HUAWEI_PRODUCT_E1432 0x1432 +-#define HUAWEI_PRODUCT_E1433 0x1433 +-#define HUAWEI_PRODUCT_E1434 0x1434 +-#define HUAWEI_PRODUCT_E1435 0x1435 +-#define HUAWEI_PRODUCT_E1436 0x1436 +-#define HUAWEI_PRODUCT_E1437 0x1437 +-#define HUAWEI_PRODUCT_E1438 0x1438 +-#define HUAWEI_PRODUCT_E1439 0x1439 +-#define HUAWEI_PRODUCT_E143A 0x143A +-#define HUAWEI_PRODUCT_E143B 0x143B +-#define HUAWEI_PRODUCT_E143C 0x143C +-#define HUAWEI_PRODUCT_E143D 0x143D +-#define HUAWEI_PRODUCT_E143E 0x143E +-#define HUAWEI_PRODUCT_E143F 0x143F + #define HUAWEI_PRODUCT_K4505 0x1464 + #define HUAWEI_PRODUCT_K3765 0x1465 +-#define HUAWEI_PRODUCT_E14AC 0x14AC +-#define HUAWEI_PRODUCT_K3806 0x14AE + #define HUAWEI_PRODUCT_K4605 0x14C6 +-#define HUAWEI_PRODUCT_K5005 0x14C8 +-#define HUAWEI_PRODUCT_K3770 0x14C9 +-#define HUAWEI_PRODUCT_K3771 0x14CA +-#define HUAWEI_PRODUCT_K4510 0x14CB +-#define HUAWEI_PRODUCT_K4511 0x14CC +-#define HUAWEI_PRODUCT_ETS1220 0x1803 +-#define HUAWEI_PRODUCT_E353 0x1506 +-#define HUAWEI_PRODUCT_E173S 0x1C05 + + #define QUANTA_VENDOR_ID 0x0408 + #define QUANTA_PRODUCT_Q101 0xEA02 +@@ -615,104 +539,123 @@ static const struct usb_device_id option_ids[] = { + { USB_DEVICE(QUANTA_VENDOR_ID, QUANTA_PRODUCT_GLX) }, + { USB_DEVICE(QUANTA_VENDOR_ID, QUANTA_PRODUCT_GKE) }, + { USB_DEVICE(QUANTA_VENDOR_ID, QUANTA_PRODUCT_GLE) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220BIS, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1401, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1402, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1403, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1404, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1405, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1406, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1407, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1408, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1409, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E140A, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E140B, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E140C, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E140D, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E140E, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E140F, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1410, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1411, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1412, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1413, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1414, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1415, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1416, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1417, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1418, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1419, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E141A, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E141B, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E141C, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E141D, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E141E, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E141F, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1420, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1421, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1422, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1423, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1424, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1425, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1426, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1427, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1428, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1429, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E142A, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E142B, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E142C, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E142D, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E142E, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E142F, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1430, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1431, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1432, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1433, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1434, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1435, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1436, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1437, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1438, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1439, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143A, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143B, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143C, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143D, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143E, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143F, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E173S, 0xff, 0xff, 0xff) }, + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff), + .driver_info = (kernel_ulong_t) &huawei_cdc12_blacklist }, + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff), + .driver_info = (kernel_ulong_t) &huawei_cdc12_blacklist }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ETS1220, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3806, 0xff, 0xff, 0xff) }, + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4605, 0xff, 0xff, 0xff), + .driver_info = (kernel_ulong_t) &huawei_cdc12_blacklist }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4605, 0xff, 0x01, 0x31) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4605, 0xff, 0x01, 0x32) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K5005, 0xff, 0x01, 0x31) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K5005, 0xff, 0x01, 0x32) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K5005, 0xff, 0x01, 0x33) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3770, 0xff, 0x02, 0x31) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3770, 0xff, 0x02, 0x32) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3771, 0xff, 0x02, 0x31) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3771, 0xff, 0x02, 0x32) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4510, 0xff, 0x01, 0x31) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4510, 0xff, 0x01, 0x32) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x31) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x32) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x01) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x02) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x03) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x10) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x12) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x13) }, +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x02, 0x01) }, /* E398 3G Modem */ +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x02, 0x02) }, /* E398 3G PC UI Interface */ +- { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x02, 0x03) }, /* E398 3G Application Interface */ ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0xff, 0xff) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x01) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x02) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x03) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x04) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x05) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x06) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x0A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x0B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x0D) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x0E) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x0F) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x10) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x12) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x13) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x14) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x15) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x17) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x18) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x19) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x1A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x1B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x1C) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x31) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x32) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x33) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x34) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x35) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x36) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x3A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x3B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x3D) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x3E) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x3F) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x48) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x49) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x4A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x4B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x4C) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x61) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x62) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x63) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x64) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x65) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x66) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x6A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x6B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x6D) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x6E) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x6F) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x78) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x79) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x7A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x7B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x7C) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x01) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x02) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x03) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x04) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x05) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x06) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x0A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x0B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x0D) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x0E) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x0F) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x10) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x12) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x13) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x14) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x15) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x17) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x18) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x19) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x1A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x1B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x1C) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x31) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x32) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x33) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x34) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x35) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x36) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x3A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x3B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x3D) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x3E) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x3F) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x48) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x49) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x4A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x4B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x4C) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x61) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x62) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x63) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x64) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x65) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x66) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x6A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x6B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x6D) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x6E) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x6F) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x78) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x79) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7A) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7B) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7C) }, ++ ++ + { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, + { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) }, + { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) }, +@@ -927,7 +870,8 @@ static const struct usb_device_id option_ids[] = { + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0153, 0xff, 0xff, 0xff) }, + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0155, 0xff, 0xff, 0xff) }, + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0156, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0157, 0xff, 0xff, 0xff) }, ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0157, 0xff, 0xff, 0xff), ++ .driver_info = (kernel_ulong_t)&net_intf5_blacklist }, + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0158, 0xff, 0xff, 0xff) }, + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0159, 0xff, 0xff, 0xff) }, + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0161, 0xff, 0xff, 0xff) }, +@@ -936,6 +880,8 @@ static const struct usb_device_id option_ids[] = { + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0165, 0xff, 0xff, 0xff) }, + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0167, 0xff, 0xff, 0xff), + .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, ++ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0326, 0xff, 0xff, 0xff), ++ .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1008, 0xff, 0xff, 0xff), + .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1010, 0xff, 0xff, 0xff), +@@ -1145,6 +1091,10 @@ static const struct usb_device_id option_ids[] = { + .driver_info = (kernel_ulong_t)&zte_ad3812_z_blacklist }, + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MC2716, 0xff, 0xff, 0xff), + .driver_info = (kernel_ulong_t)&zte_mc2716_z_blacklist }, ++ { USB_VENDOR_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff, 0x02, 0x01) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff, 0x02, 0x05) }, ++ { USB_VENDOR_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff, 0x86, 0x10) }, ++ + { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) }, + { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) }, + { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5) }, /* Yes, ALINK_VENDOR_ID */ +diff --git a/drivers/usb/serial/qcaux.c b/drivers/usb/serial/qcaux.c +index a4edc7e..9b1b96f 100644 +--- a/drivers/usb/serial/qcaux.c ++++ b/drivers/usb/serial/qcaux.c +@@ -36,8 +36,6 @@ + #define UTSTARCOM_PRODUCT_UM175_V1 0x3712 + #define UTSTARCOM_PRODUCT_UM175_V2 0x3714 + #define UTSTARCOM_PRODUCT_UM175_ALLTEL 0x3715 +-#define PANTECH_PRODUCT_UML190_VZW 0x3716 +-#define PANTECH_PRODUCT_UML290_VZW 0x3718 + + /* CMOTECH devices */ + #define CMOTECH_VENDOR_ID 0x16d8 +@@ -68,11 +66,9 @@ static struct usb_device_id id_table[] = { + { USB_DEVICE_AND_INTERFACE_INFO(LG_VENDOR_ID, LG_PRODUCT_VX4400_6000, 0xff, 0xff, 0x00) }, + { USB_DEVICE_AND_INTERFACE_INFO(SANYO_VENDOR_ID, SANYO_PRODUCT_KATANA_LX, 0xff, 0xff, 0x00) }, + { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_U520, 0xff, 0x00, 0x00) }, +- { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, PANTECH_PRODUCT_UML190_VZW, 0xff, 0xff, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, PANTECH_PRODUCT_UML190_VZW, 0xff, 0xfe, 0xff) }, +- { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, PANTECH_PRODUCT_UML290_VZW, 0xff, 0xfd, 0xff) }, /* NMEA */ +- { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, PANTECH_PRODUCT_UML290_VZW, 0xff, 0xfe, 0xff) }, /* WMC */ +- { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, PANTECH_PRODUCT_UML290_VZW, 0xff, 0xff, 0xff) }, /* DIAG */ ++ { USB_VENDOR_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, 0xff, 0xfd, 0xff) }, /* NMEA */ ++ { USB_VENDOR_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, 0xff, 0xfe, 0xff) }, /* WMC */ ++ { USB_VENDOR_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, 0xff, 0xff, 0xff) }, /* DIAG */ + { }, + }; + MODULE_DEVICE_TABLE(usb, id_table); +diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c +index 27483f9..667c39c 100644 +--- a/drivers/usb/serial/usb-serial.c ++++ b/drivers/usb/serial/usb-serial.c +@@ -1426,9 +1426,10 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] + + /* we only set the reset_resume field if the serial_driver has one */ + for (sd = serial_drivers; *sd; ++sd) { +- if ((*sd)->reset_resume) ++ if ((*sd)->reset_resume) { + udriver->reset_resume = usb_serial_reset_resume; + break; ++ } + } + + rc = usb_register(udriver); +diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c +index 8ec8a6e..f98ba40 100644 +--- a/drivers/usb/storage/uas.c ++++ b/drivers/usb/storage/uas.c +@@ -58,9 +58,6 @@ enum { + SUBMIT_DATA_OUT_URB = (1 << 5), + ALLOC_CMD_URB = (1 << 6), + SUBMIT_CMD_URB = (1 << 7), +- COMPLETED_DATA_IN = (1 << 8), +- COMPLETED_DATA_OUT = (1 << 9), +- DATA_COMPLETES_CMD = (1 << 10), + }; + + /* Overrides scsi_pointer */ +@@ -114,7 +111,6 @@ static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd) + { + struct sense_iu *sense_iu = urb->transfer_buffer; + struct scsi_device *sdev = cmnd->device; +- struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; + + if (urb->actual_length > 16) { + unsigned len = be16_to_cpup(&sense_iu->len); +@@ -132,15 +128,13 @@ static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd) + } + + cmnd->result = sense_iu->status; +- if (!(cmdinfo->state & DATA_COMPLETES_CMD)) +- cmnd->scsi_done(cmnd); ++ cmnd->scsi_done(cmnd); + } + + static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd) + { + struct sense_iu_old *sense_iu = urb->transfer_buffer; + struct scsi_device *sdev = cmnd->device; +- struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; + + if (urb->actual_length > 8) { + unsigned len = be16_to_cpup(&sense_iu->len) - 2; +@@ -158,8 +152,7 @@ static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd) + } + + cmnd->result = sense_iu->status; +- if (!(cmdinfo->state & DATA_COMPLETES_CMD)) +- cmnd->scsi_done(cmnd); ++ cmnd->scsi_done(cmnd); + } + + static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd, +@@ -184,7 +177,6 @@ static void uas_stat_cmplt(struct urb *urb) + struct Scsi_Host *shost = urb->context; + struct uas_dev_info *devinfo = (void *)shost->hostdata[0]; + struct scsi_cmnd *cmnd; +- struct uas_cmd_info *cmdinfo; + u16 tag; + int ret; + +@@ -210,32 +202,12 @@ static void uas_stat_cmplt(struct urb *urb) + dev_err(&urb->dev->dev, "failed submit status urb\n"); + return; + } +- cmdinfo = (void *)&cmnd->SCp; + + switch (iu->iu_id) { + case IU_ID_STATUS: + if (devinfo->cmnd == cmnd) + devinfo->cmnd = NULL; + +- if (!(cmdinfo->state & COMPLETED_DATA_IN) && +- cmdinfo->data_in_urb) { +- if (devinfo->use_streams) { +- cmdinfo->state |= DATA_COMPLETES_CMD; +- usb_unlink_urb(cmdinfo->data_in_urb); +- } else { +- usb_free_urb(cmdinfo->data_in_urb); +- } +- } +- if (!(cmdinfo->state & COMPLETED_DATA_OUT) && +- cmdinfo->data_out_urb) { +- if (devinfo->use_streams) { +- cmdinfo->state |= DATA_COMPLETES_CMD; +- usb_unlink_urb(cmdinfo->data_in_urb); +- } else { +- usb_free_urb(cmdinfo->data_out_urb); +- } +- } +- + if (urb->actual_length < 16) + devinfo->uas_sense_old = 1; + if (devinfo->uas_sense_old) +@@ -264,59 +236,27 @@ static void uas_stat_cmplt(struct urb *urb) + dev_err(&urb->dev->dev, "failed submit status urb\n"); + } + +-static void uas_data_out_cmplt(struct urb *urb) +-{ +- struct scsi_cmnd *cmnd = urb->context; +- struct scsi_data_buffer *sdb = scsi_out(cmnd); +- struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; +- +- cmdinfo->state |= COMPLETED_DATA_OUT; +- +- sdb->resid = sdb->length - urb->actual_length; +- usb_free_urb(urb); +- +- if (cmdinfo->state & DATA_COMPLETES_CMD) +- cmnd->scsi_done(cmnd); +-} +- +-static void uas_data_in_cmplt(struct urb *urb) ++static void uas_data_cmplt(struct urb *urb) + { +- struct scsi_cmnd *cmnd = urb->context; +- struct scsi_data_buffer *sdb = scsi_in(cmnd); +- struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; +- +- cmdinfo->state |= COMPLETED_DATA_IN; +- ++ struct scsi_data_buffer *sdb = urb->context; + sdb->resid = sdb->length - urb->actual_length; + usb_free_urb(urb); +- +- if (cmdinfo->state & DATA_COMPLETES_CMD) +- cmnd->scsi_done(cmnd); + } + + static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp, +- unsigned int pipe, struct scsi_cmnd *cmnd, +- enum dma_data_direction dir) ++ unsigned int pipe, u16 stream_id, ++ struct scsi_data_buffer *sdb, ++ enum dma_data_direction dir) + { +- struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; + struct usb_device *udev = devinfo->udev; + struct urb *urb = usb_alloc_urb(0, gfp); +- struct scsi_data_buffer *sdb; +- usb_complete_t complete_fn; +- u16 stream_id = cmdinfo->stream; + + if (!urb) + goto out; +- if (dir == DMA_FROM_DEVICE) { +- sdb = scsi_in(cmnd); +- complete_fn = uas_data_in_cmplt; +- } else { +- sdb = scsi_out(cmnd); +- complete_fn = uas_data_out_cmplt; +- } +- usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length, +- complete_fn, cmnd); +- urb->stream_id = stream_id; ++ usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length, uas_data_cmplt, ++ sdb); ++ if (devinfo->use_streams) ++ urb->stream_id = stream_id; + urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0; + urb->sg = sdb->table.sgl; + out: +@@ -418,8 +358,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, + + if (cmdinfo->state & ALLOC_DATA_IN_URB) { + cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp, +- devinfo->data_in_pipe, cmnd, +- DMA_FROM_DEVICE); ++ devinfo->data_in_pipe, cmdinfo->stream, ++ scsi_in(cmnd), DMA_FROM_DEVICE); + if (!cmdinfo->data_in_urb) + return SCSI_MLQUEUE_DEVICE_BUSY; + cmdinfo->state &= ~ALLOC_DATA_IN_URB; +@@ -436,8 +376,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, + + if (cmdinfo->state & ALLOC_DATA_OUT_URB) { + cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp, +- devinfo->data_out_pipe, cmnd, +- DMA_TO_DEVICE); ++ devinfo->data_out_pipe, cmdinfo->stream, ++ scsi_out(cmnd), DMA_TO_DEVICE); + if (!cmdinfo->data_out_urb) + return SCSI_MLQUEUE_DEVICE_BUSY; + cmdinfo->state &= ~ALLOC_DATA_OUT_URB; +diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c +index 2e471c2..88e9204 100644 +--- a/drivers/video/console/fbcon.c ++++ b/drivers/video/console/fbcon.c +@@ -372,8 +372,15 @@ static void fb_flashcursor(struct work_struct *work) + struct vc_data *vc = NULL; + int c; + int mode; ++ int ret; ++ ++ /* FIXME: we should sort out the unbind locking instead */ ++ /* instead we just fail to flash the cursor if we can't get ++ * the lock instead of blocking fbcon deinit */ ++ ret = console_trylock(); ++ if (ret == 0) ++ return; + +- console_lock(); + if (ops && ops->currcon != -1) + vc = vc_cons[ops->currcon].d; + +diff --git a/drivers/video/omap2/omapfb/omapfb-main.c b/drivers/video/omap2/omapfb/omapfb-main.c +index 3450ea0..30f9c32 100644 +--- a/drivers/video/omap2/omapfb/omapfb-main.c ++++ b/drivers/video/omap2/omapfb/omapfb-main.c +@@ -1188,7 +1188,7 @@ static int _setcolreg(struct fb_info *fbi, u_int regno, u_int red, u_int green, + break; + + if (regno < 16) { +- u16 pal; ++ u32 pal; + pal = ((red >> (16 - var->red.length)) << + var->red.offset) | + ((green >> (16 - var->green.length)) << +diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c +index af3ef27..f39e069 100644 +--- a/drivers/video/smscufx.c ++++ b/drivers/video/smscufx.c +@@ -904,7 +904,7 @@ static ssize_t ufx_ops_write(struct fb_info *info, const char __user *buf, + result = fb_sys_write(info, buf, count, ppos); + + if (result > 0) { +- int start = max((int)(offset / info->fix.line_length) - 1, 0); ++ int start = max((int)(offset / info->fix.line_length), 0); + int lines = min((u32)((result / info->fix.line_length) + 1), + (u32)info->var.yres); + +diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c +index 1eff743..ae60406 100644 +--- a/drivers/watchdog/hpwdt.c ++++ b/drivers/watchdog/hpwdt.c +@@ -814,6 +814,9 @@ static int __devinit hpwdt_init_one(struct pci_dev *dev, + hpwdt_timer_reg = pci_mem_addr + 0x70; + hpwdt_timer_con = pci_mem_addr + 0x72; + ++ /* Make sure that timer is disabled until /dev/watchdog is opened */ ++ hpwdt_stop(); ++ + /* Make sure that we have a valid soft_margin */ + if (hpwdt_change_timer(soft_margin)) + hpwdt_change_timer(DEFAULT_MARGIN); +diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c +index 1ffd03b..7f12416 100644 +--- a/drivers/xen/gntdev.c ++++ b/drivers/xen/gntdev.c +@@ -314,8 +314,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages) + } + } + +- err = gnttab_unmap_refs(map->unmap_ops + offset, map->pages + offset, +- pages, true); ++ err = gnttab_unmap_refs(map->unmap_ops + offset, ++ use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset, ++ pages); + if (err) + return err; + +diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c +index 0bfc1ef..0067266 100644 +--- a/drivers/xen/grant-table.c ++++ b/drivers/xen/grant-table.c +@@ -870,7 +870,8 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, + EXPORT_SYMBOL_GPL(gnttab_map_refs); + + int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, +- struct page **pages, unsigned int count, bool clear_pte) ++ struct gnttab_map_grant_ref *kmap_ops, ++ struct page **pages, unsigned int count) + { + int i, ret; + bool lazy = false; +@@ -888,7 +889,8 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, + } + + for (i = 0; i < count; i++) { +- ret = m2p_remove_override(pages[i], clear_pte); ++ ret = m2p_remove_override(pages[i], kmap_ops ? ++ &kmap_ops[i] : NULL); + if (ret) + return ret; + } +diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c +index 1afb4fb..4d51948 100644 +--- a/drivers/xen/swiotlb-xen.c ++++ b/drivers/xen/swiotlb-xen.c +@@ -232,7 +232,7 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, + return ret; + + if (hwdev && hwdev->coherent_dma_mask) +- dma_mask = hwdev->coherent_dma_mask; ++ dma_mask = dma_alloc_coherent_mask(hwdev, flags); + + phys = virt_to_phys(ret); + dev_addr = xen_phys_to_bus(phys); +diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c +index 097e536..77c9f76 100644 +--- a/drivers/xen/xen-pciback/pci_stub.c ++++ b/drivers/xen/xen-pciback/pci_stub.c +@@ -353,16 +353,17 @@ static int __devinit pcistub_init_device(struct pci_dev *dev) + if (err) + goto config_release; + +- dev_dbg(&dev->dev, "reseting (FLR, D3, etc) the device\n"); +- __pci_reset_function_locked(dev); +- + /* We need the device active to save the state. */ + dev_dbg(&dev->dev, "save state of device\n"); + pci_save_state(dev); + dev_data->pci_saved_state = pci_store_saved_state(dev); + if (!dev_data->pci_saved_state) + dev_err(&dev->dev, "Could not store PCI conf saved state!\n"); +- ++ else { ++ dev_dbg(&dev->dev, "reseting (FLR, D3, etc) the device\n"); ++ __pci_reset_function_locked(dev); ++ pci_restore_state(dev); ++ } + /* Now disable the device (this also ensures some private device + * data is setup before we export) + */ +diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c +index 1b52956..0225fdd 100644 +--- a/fs/binfmt_elf.c ++++ b/fs/binfmt_elf.c +@@ -1696,30 +1696,19 @@ static int elf_note_info_init(struct elf_note_info *info) + return 0; + info->psinfo = kmalloc(sizeof(*info->psinfo), GFP_KERNEL); + if (!info->psinfo) +- goto notes_free; ++ return 0; + info->prstatus = kmalloc(sizeof(*info->prstatus), GFP_KERNEL); + if (!info->prstatus) +- goto psinfo_free; ++ return 0; + info->fpu = kmalloc(sizeof(*info->fpu), GFP_KERNEL); + if (!info->fpu) +- goto prstatus_free; ++ return 0; + #ifdef ELF_CORE_COPY_XFPREGS + info->xfpu = kmalloc(sizeof(*info->xfpu), GFP_KERNEL); + if (!info->xfpu) +- goto fpu_free; ++ return 0; + #endif + return 1; +-#ifdef ELF_CORE_COPY_XFPREGS +- fpu_free: +- kfree(info->fpu); +-#endif +- prstatus_free: +- kfree(info->prstatus); +- psinfo_free: +- kfree(info->psinfo); +- notes_free: +- kfree(info->notes); +- return 0; + } + + static int fill_note_info(struct elfhdr *elf, int phdrs, +diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c +index 4270414..58b7d14 100644 +--- a/fs/btrfs/async-thread.c ++++ b/fs/btrfs/async-thread.c +@@ -206,10 +206,17 @@ static noinline void run_ordered_completions(struct btrfs_workers *workers, + + 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 --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c +index 01c21b6..b89ba9f 100644 +--- a/fs/btrfs/extent_io.c ++++ b/fs/btrfs/extent_io.c +@@ -2329,23 +2329,10 @@ static void end_bio_extent_readpage(struct bio *bio, int err) + if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { + ret = tree->ops->readpage_end_io_hook(page, start, end, + state, mirror); +- if (ret) { +- /* no IO indicated but software detected errors +- * in the block, either checksum errors or +- * issues with the contents */ +- struct btrfs_root *root = +- BTRFS_I(page->mapping->host)->root; +- struct btrfs_device *device; +- ++ if (ret) + uptodate = 0; +- device = btrfs_find_device_for_logical( +- root, start, mirror); +- if (device) +- btrfs_dev_stat_inc_and_print(device, +- BTRFS_DEV_STAT_CORRUPTION_ERRS); +- } else { ++ else + clean_io_failure(start, page); +- } + } + + if (!uptodate && tree->ops && tree->ops->readpage_io_failed_hook) { +diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c +index ecaad40..037e0bb 100644 +--- a/fs/btrfs/volumes.c ++++ b/fs/btrfs/volumes.c +@@ -4602,28 +4602,6 @@ int btrfs_read_sys_array(struct btrfs_root *root) + return ret; + } + +-struct btrfs_device *btrfs_find_device_for_logical(struct btrfs_root *root, +- u64 logical, int mirror_num) +-{ +- struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree; +- int ret; +- u64 map_length = 0; +- struct btrfs_bio *bbio = NULL; +- struct btrfs_device *device; +- +- BUG_ON(mirror_num == 0); +- ret = btrfs_map_block(map_tree, WRITE, logical, &map_length, &bbio, +- mirror_num); +- if (ret) { +- BUG_ON(bbio != NULL); +- return NULL; +- } +- BUG_ON(mirror_num != bbio->mirror_num); +- device = bbio->stripes[mirror_num - 1].dev; +- kfree(bbio); +- return device; +-} +- + int btrfs_read_chunk_tree(struct btrfs_root *root) + { + struct btrfs_path *path; +diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h +index 95f6637..8297cc8 100644 +--- a/fs/btrfs/volumes.h ++++ b/fs/btrfs/volumes.h +@@ -288,8 +288,6 @@ int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); + int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); + int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, + u64 *start, u64 *max_avail); +-struct btrfs_device *btrfs_find_device_for_logical(struct btrfs_root *root, +- u64 logical, int mirror_num); + void btrfs_dev_stat_print_on_error(struct btrfs_device *device); + void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index); + int btrfs_get_dev_stats(struct btrfs_root *root, +diff --git a/fs/buffer.c b/fs/buffer.c +index c7062c8..2c78739 100644 +--- a/fs/buffer.c ++++ b/fs/buffer.c +@@ -914,7 +914,7 @@ link_dev_buffers(struct page *page, struct buffer_head *head) + /* + * Initialise the state of a blockdev page's buffers. + */ +-static void ++static sector_t + init_page_buffers(struct page *page, struct block_device *bdev, + sector_t block, int size) + { +@@ -936,33 +936,41 @@ init_page_buffers(struct page *page, struct block_device *bdev, + block++; + bh = bh->b_this_page; + } while (bh != head); ++ ++ /* ++ * Caller needs to validate requested block against end of device. ++ */ ++ return end_block; + } + + /* + * Create the page-cache page that contains the requested block. + * +- * This is user purely for blockdev mappings. ++ * This is used purely for blockdev mappings. + */ +-static struct page * ++static int + grow_dev_page(struct block_device *bdev, sector_t block, +- pgoff_t index, int size) ++ pgoff_t index, int size, int sizebits) + { + struct inode *inode = bdev->bd_inode; + struct page *page; + struct buffer_head *bh; ++ sector_t end_block; ++ int ret = 0; /* Will call free_more_memory() */ + + page = find_or_create_page(inode->i_mapping, index, + (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS)|__GFP_MOVABLE); + if (!page) +- return NULL; ++ return ret; + + BUG_ON(!PageLocked(page)); + + if (page_has_buffers(page)) { + bh = page_buffers(page); + if (bh->b_size == size) { +- init_page_buffers(page, bdev, block, size); +- return page; ++ end_block = init_page_buffers(page, bdev, ++ index << sizebits, size); ++ goto done; + } + if (!try_to_free_buffers(page)) + goto failed; +@@ -982,14 +990,14 @@ grow_dev_page(struct block_device *bdev, sector_t block, + */ + spin_lock(&inode->i_mapping->private_lock); + link_dev_buffers(page, bh); +- init_page_buffers(page, bdev, block, size); ++ end_block = init_page_buffers(page, bdev, index << sizebits, size); + spin_unlock(&inode->i_mapping->private_lock); +- return page; +- ++done: ++ ret = (block < end_block) ? 1 : -ENXIO; + failed: + unlock_page(page); + page_cache_release(page); +- return NULL; ++ return ret; + } + + /* +@@ -999,7 +1007,6 @@ failed: + static int + grow_buffers(struct block_device *bdev, sector_t block, int size) + { +- struct page *page; + pgoff_t index; + int sizebits; + +@@ -1023,22 +1030,14 @@ grow_buffers(struct block_device *bdev, sector_t block, int size) + bdevname(bdev, b)); + return -EIO; + } +- block = index << sizebits; ++ + /* Create a page with the proper size buffers.. */ +- page = grow_dev_page(bdev, block, index, size); +- if (!page) +- return 0; +- unlock_page(page); +- page_cache_release(page); +- return 1; ++ return grow_dev_page(bdev, block, index, size, sizebits); + } + + static struct buffer_head * + __getblk_slow(struct block_device *bdev, sector_t block, int size) + { +- int ret; +- struct buffer_head *bh; +- + /* Size must be multiple of hard sectorsize */ + if (unlikely(size & (bdev_logical_block_size(bdev)-1) || + (size < 512 || size > PAGE_SIZE))) { +@@ -1051,21 +1050,20 @@ __getblk_slow(struct block_device *bdev, sector_t block, int size) + return NULL; + } + +-retry: +- bh = __find_get_block(bdev, block, size); +- if (bh) +- return bh; ++ for (;;) { ++ struct buffer_head *bh; ++ int ret; + +- ret = grow_buffers(bdev, block, size); +- if (ret == 0) { +- free_more_memory(); +- goto retry; +- } else if (ret > 0) { + bh = __find_get_block(bdev, block, size); + if (bh) + return bh; ++ ++ ret = grow_buffers(bdev, block, size); ++ if (ret < 0) ++ return NULL; ++ if (ret == 0) ++ free_more_memory(); + } +- return NULL; + } + + /* +@@ -1321,10 +1319,6 @@ EXPORT_SYMBOL(__find_get_block); + * which corresponds to the passed block_device, block and size. The + * returned buffer has its reference count incremented. + * +- * __getblk() cannot fail - it just keeps trying. If you pass it an +- * illegal block number, __getblk() will happily return a buffer_head +- * which represents the non-existent block. Very weird. +- * + * __getblk() will lock up the machine if grow_dev_page's try_to_free_buffers() + * attempt is failing. FIXME, perhaps? + */ +diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c +index fbb9da9..6a8568c 100644 +--- a/fs/cifs/cifs_unicode.c ++++ b/fs/cifs/cifs_unicode.c +@@ -203,6 +203,27 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len, + int i; + wchar_t wchar_to; /* needed to quiet sparse */ + ++ /* special case for utf8 to handle no plane0 chars */ ++ if (!strcmp(codepage->charset, "utf8")) { ++ /* ++ * convert utf8 -> utf16, we assume we have enough space ++ * as caller should have assumed conversion does not overflow ++ * in destination len is length in wchar_t units (16bits) ++ */ ++ i = utf8s_to_utf16s(from, len, UTF16_LITTLE_ENDIAN, ++ (wchar_t *) to, len); ++ ++ /* if success terminate and exit */ ++ if (i >= 0) ++ goto success; ++ /* ++ * if fails fall back to UCS encoding as this ++ * function should not return negative values ++ * currently can fail only if source contains ++ * invalid encoded characters ++ */ ++ } ++ + for (i = 0; len && *from; i++, from += charlen, len -= charlen) { + charlen = codepage->char2uni(from, len, &wchar_to); + if (charlen < 1) { +@@ -215,6 +236,7 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len, + put_unaligned_le16(wchar_to, &to[i]); + } + ++success: + put_unaligned_le16(0, &to[i]); + return i; + } +@@ -328,6 +350,6 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen, + } + + ctoUTF16_out: +- return i; ++ return j; + } + +diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h +index 6df0cbe..d86ba9f 100644 +--- a/fs/cifs/cifsglob.h ++++ b/fs/cifs/cifsglob.h +@@ -657,13 +657,13 @@ struct cifs_io_parms { + * Take a reference on the file private data. Must be called with + * cifs_file_list_lock held. + */ +-static inline +-struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file) ++static inline void ++cifsFileInfo_get_locked(struct cifsFileInfo *cifs_file) + { + ++cifs_file->count; +- return cifs_file; + } + ++struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file); + void cifsFileInfo_put(struct cifsFileInfo *cifs_file); + + /* +diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c +index 94b7788..f027c2b 100644 +--- a/fs/cifs/connect.c ++++ b/fs/cifs/connect.c +@@ -70,6 +70,7 @@ enum { + /* Mount options that take no arguments */ + Opt_user_xattr, Opt_nouser_xattr, + Opt_forceuid, Opt_noforceuid, ++ Opt_forcegid, Opt_noforcegid, + Opt_noblocksend, Opt_noautotune, + Opt_hard, Opt_soft, Opt_perm, Opt_noperm, + Opt_mapchars, Opt_nomapchars, Opt_sfu, +@@ -121,6 +122,8 @@ static const match_table_t cifs_mount_option_tokens = { + { Opt_nouser_xattr, "nouser_xattr" }, + { Opt_forceuid, "forceuid" }, + { Opt_noforceuid, "noforceuid" }, ++ { Opt_forcegid, "forcegid" }, ++ { Opt_noforcegid, "noforcegid" }, + { Opt_noblocksend, "noblocksend" }, + { Opt_noautotune, "noautotune" }, + { Opt_hard, "hard" }, +@@ -238,8 +241,8 @@ static const match_table_t cifs_mount_option_tokens = { + enum { + Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, + Opt_sec_ntlmsspi, Opt_sec_ntlmssp, +- Opt_ntlm, Opt_sec_ntlmi, Opt_sec_ntlmv2i, +- Opt_sec_nontlm, Opt_sec_lanman, ++ Opt_ntlm, Opt_sec_ntlmi, Opt_sec_ntlmv2, ++ Opt_sec_ntlmv2i, Opt_sec_lanman, + Opt_sec_none, + + Opt_sec_err +@@ -253,8 +256,9 @@ static const match_table_t cifs_secflavor_tokens = { + { Opt_sec_ntlmssp, "ntlmssp" }, + { Opt_ntlm, "ntlm" }, + { Opt_sec_ntlmi, "ntlmi" }, ++ { Opt_sec_ntlmv2, "nontlm" }, ++ { Opt_sec_ntlmv2, "ntlmv2" }, + { Opt_sec_ntlmv2i, "ntlmv2i" }, +- { Opt_sec_nontlm, "nontlm" }, + { Opt_sec_lanman, "lanman" }, + { Opt_sec_none, "none" }, + +@@ -1167,7 +1171,7 @@ static int cifs_parse_security_flavors(char *value, + case Opt_sec_ntlmi: + vol->secFlg |= CIFSSEC_MAY_NTLM | CIFSSEC_MUST_SIGN; + break; +- case Opt_sec_nontlm: ++ case Opt_sec_ntlmv2: + vol->secFlg |= CIFSSEC_MAY_NTLMV2; + break; + case Opt_sec_ntlmv2i: +@@ -1344,6 +1348,12 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, + case Opt_noforceuid: + override_uid = 0; + break; ++ case Opt_forcegid: ++ override_gid = 1; ++ break; ++ case Opt_noforcegid: ++ override_gid = 0; ++ break; + case Opt_noblocksend: + vol->noblocksnd = 1; + break; +diff --git a/fs/cifs/file.c b/fs/cifs/file.c +index 513adbc..2cbda4e 100644 +--- a/fs/cifs/file.c ++++ b/fs/cifs/file.c +@@ -284,6 +284,15 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file, + + static void cifs_del_lock_waiters(struct cifsLockInfo *lock); + ++struct cifsFileInfo * ++cifsFileInfo_get(struct cifsFileInfo *cifs_file) ++{ ++ spin_lock(&cifs_file_list_lock); ++ cifsFileInfo_get_locked(cifs_file); ++ spin_unlock(&cifs_file_list_lock); ++ return cifs_file; ++} ++ + /* + * Release a reference on the file private data. This may involve closing + * the filehandle out on the server. Must be called without holding +@@ -1563,7 +1572,7 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode, + if (!open_file->invalidHandle) { + /* found a good file */ + /* lock it so it will not be closed on us */ +- cifsFileInfo_get(open_file); ++ cifsFileInfo_get_locked(open_file); + spin_unlock(&cifs_file_list_lock); + return open_file; + } /* else might as well continue, and look for +@@ -1615,7 +1624,7 @@ refind_writable: + if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { + if (!open_file->invalidHandle) { + /* found a good writable file */ +- cifsFileInfo_get(open_file); ++ cifsFileInfo_get_locked(open_file); + spin_unlock(&cifs_file_list_lock); + return open_file; + } else { +@@ -1632,7 +1641,7 @@ refind_writable: + + if (inv_file) { + any_available = false; +- cifsFileInfo_get(inv_file); ++ cifsFileInfo_get_locked(inv_file); + } + + spin_unlock(&cifs_file_list_lock); +@@ -3082,8 +3091,6 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, + break; + } + +- spin_lock(&cifs_file_list_lock); +- spin_unlock(&cifs_file_list_lock); + rdata->cfile = cifsFileInfo_get(open_file); + rdata->mapping = mapping; + rdata->offset = offset; +diff --git a/fs/compat.c b/fs/compat.c +index 6161255..1bdb350 100644 +--- a/fs/compat.c ++++ b/fs/compat.c +@@ -1155,11 +1155,14 @@ compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec, + struct file *file; + int fput_needed; + ssize_t ret; ++ loff_t pos; + + file = fget_light(fd, &fput_needed); + if (!file) + return -EBADF; +- ret = compat_readv(file, vec, vlen, &file->f_pos); ++ pos = file->f_pos; ++ ret = compat_readv(file, vec, vlen, &pos); ++ file->f_pos = pos; + fput_light(file, fput_needed); + return ret; + } +@@ -1221,11 +1224,14 @@ compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec, + struct file *file; + int fput_needed; + ssize_t ret; ++ loff_t pos; + + file = fget_light(fd, &fput_needed); + if (!file) + return -EBADF; +- ret = compat_writev(file, vec, vlen, &file->f_pos); ++ pos = file->f_pos; ++ ret = compat_writev(file, vec, vlen, &pos); ++ file->f_pos = pos; + fput_light(file, fput_needed); + return ret; + } +diff --git a/fs/dcache.c b/fs/dcache.c +index 4046904..9560257 100644 +--- a/fs/dcache.c ++++ b/fs/dcache.c +@@ -389,7 +389,7 @@ static struct dentry *d_kill(struct dentry *dentry, struct dentry *parent) + * Inform try_to_ascend() that we are no longer attached to the + * dentry tree + */ +- dentry->d_flags |= DCACHE_DISCONNECTED; ++ dentry->d_flags |= DCACHE_DENTRY_KILLED; + if (parent) + spin_unlock(&parent->d_lock); + dentry_iput(dentry); +@@ -1046,7 +1046,7 @@ static struct dentry *try_to_ascend(struct dentry *old, int locked, unsigned seq + * or deletion + */ + if (new != old->d_parent || +- (old->d_flags & DCACHE_DISCONNECTED) || ++ (old->d_flags & DCACHE_DENTRY_KILLED) || + (!locked && read_seqretry(&rename_lock, seq))) { + spin_unlock(&new->d_lock); + new = NULL; +@@ -1132,6 +1132,8 @@ positive: + return 1; + + rename_retry: ++ if (locked) ++ goto again; + locked = 1; + write_seqlock(&rename_lock); + goto again; +@@ -1234,6 +1236,8 @@ out: + rename_retry: + if (found) + return found; ++ if (locked) ++ goto again; + locked = 1; + write_seqlock(&rename_lock); + goto again; +@@ -3031,6 +3035,8 @@ resume: + return; + + rename_retry: ++ if (locked) ++ goto again; + locked = 1; + write_seqlock(&rename_lock); + goto again; +diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c +index a07441a..02e2fec 100644 +--- a/fs/ecryptfs/inode.c ++++ b/fs/ecryptfs/inode.c +@@ -621,6 +621,7 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, + struct dentry *lower_old_dir_dentry; + struct dentry *lower_new_dir_dentry; + struct dentry *trap = NULL; ++ struct inode *target_inode; + + lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); + lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); +@@ -628,6 +629,7 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, + dget(lower_new_dentry); + lower_old_dir_dentry = dget_parent(lower_old_dentry); + lower_new_dir_dentry = dget_parent(lower_new_dentry); ++ target_inode = new_dentry->d_inode; + trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); + /* source should not be ancestor of target */ + if (trap == lower_old_dentry) { +@@ -643,6 +645,9 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, + lower_new_dir_dentry->d_inode, lower_new_dentry); + if (rc) + goto out_lock; ++ if (target_inode) ++ fsstack_copy_attr_all(target_inode, ++ ecryptfs_inode_to_lower(target_inode)); + fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode); + if (new_dir != old_dir) + fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); +diff --git a/fs/exec.c b/fs/exec.c +index da27b91..e95aeed 100644 +--- a/fs/exec.c ++++ b/fs/exec.c +@@ -1020,7 +1020,7 @@ static void flush_old_files(struct files_struct * files) + unsigned long set, i; + + j++; +- i = j * __NFDBITS; ++ i = j * BITS_PER_LONG; + fdt = files_fdtable(files); + if (i >= fdt->max_fds) + break; +diff --git a/fs/exofs/ore.c b/fs/exofs/ore.c +index 24a49d4..1585db1 100644 +--- a/fs/exofs/ore.c ++++ b/fs/exofs/ore.c +@@ -837,11 +837,11 @@ static int _write_mirror(struct ore_io_state *ios, int cur_comp) + bio->bi_rw |= REQ_WRITE; + } + +- osd_req_write(or, _ios_obj(ios, dev), per_dev->offset, +- bio, per_dev->length); ++ osd_req_write(or, _ios_obj(ios, cur_comp), ++ per_dev->offset, bio, per_dev->length); + ORE_DBGMSG("write(0x%llx) offset=0x%llx " + "length=0x%llx dev=%d\n", +- _LLU(_ios_obj(ios, dev)->id), ++ _LLU(_ios_obj(ios, cur_comp)->id), + _LLU(per_dev->offset), + _LLU(per_dev->length), dev); + } else if (ios->kern_buff) { +@@ -853,20 +853,20 @@ static int _write_mirror(struct ore_io_state *ios, int cur_comp) + (ios->si.unit_off + ios->length > + ios->layout->stripe_unit)); + +- ret = osd_req_write_kern(or, _ios_obj(ios, per_dev->dev), ++ ret = osd_req_write_kern(or, _ios_obj(ios, cur_comp), + per_dev->offset, + ios->kern_buff, ios->length); + if (unlikely(ret)) + goto out; + ORE_DBGMSG2("write_kern(0x%llx) offset=0x%llx " + "length=0x%llx dev=%d\n", +- _LLU(_ios_obj(ios, dev)->id), ++ _LLU(_ios_obj(ios, cur_comp)->id), + _LLU(per_dev->offset), + _LLU(ios->length), per_dev->dev); + } else { +- osd_req_set_attributes(or, _ios_obj(ios, dev)); ++ osd_req_set_attributes(or, _ios_obj(ios, cur_comp)); + ORE_DBGMSG2("obj(0x%llx) set_attributes=%d dev=%d\n", +- _LLU(_ios_obj(ios, dev)->id), ++ _LLU(_ios_obj(ios, cur_comp)->id), + ios->out_attr_len, dev); + } + +diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c +index 9a4a5c4..4a84e75 100644 +--- a/fs/ext3/inode.c ++++ b/fs/ext3/inode.c +@@ -3072,6 +3072,8 @@ static int ext3_do_update_inode(handle_t *handle, + struct ext3_inode_info *ei = EXT3_I(inode); + struct buffer_head *bh = iloc->bh; + int err = 0, rc, block; ++ int need_datasync = 0; ++ __le32 disksize; + uid_t i_uid; + gid_t i_gid; + +@@ -3113,7 +3115,11 @@ again: + raw_inode->i_gid_high = 0; + } + raw_inode->i_links_count = cpu_to_le16(inode->i_nlink); +- raw_inode->i_size = cpu_to_le32(ei->i_disksize); ++ disksize = cpu_to_le32(ei->i_disksize); ++ if (disksize != raw_inode->i_size) { ++ need_datasync = 1; ++ raw_inode->i_size = disksize; ++ } + raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec); + raw_inode->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec); + raw_inode->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec); +@@ -3129,8 +3135,11 @@ again: + if (!S_ISREG(inode->i_mode)) { + raw_inode->i_dir_acl = cpu_to_le32(ei->i_dir_acl); + } else { +- raw_inode->i_size_high = +- cpu_to_le32(ei->i_disksize >> 32); ++ disksize = cpu_to_le32(ei->i_disksize >> 32); ++ if (disksize != raw_inode->i_size_high) { ++ raw_inode->i_size_high = disksize; ++ need_datasync = 1; ++ } + if (ei->i_disksize > 0x7fffffffULL) { + struct super_block *sb = inode->i_sb; + if (!EXT3_HAS_RO_COMPAT_FEATURE(sb, +@@ -3183,6 +3192,8 @@ again: + ext3_clear_inode_state(inode, EXT3_STATE_NEW); + + atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid); ++ if (need_datasync) ++ atomic_set(&ei->i_datasync_tid, handle->h_transaction->t_tid); + out_brelse: + brelse (bh); + ext3_std_error(inode->i_sb, err); +diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c +index cee7812..1b50890 100644 +--- a/fs/ext4/balloc.c ++++ b/fs/ext4/balloc.c +@@ -280,14 +280,18 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block *sb, + return desc; + } + +-static int ext4_valid_block_bitmap(struct super_block *sb, +- struct ext4_group_desc *desc, +- unsigned int block_group, +- struct buffer_head *bh) ++/* ++ * Return the block number which was discovered to be invalid, or 0 if ++ * the block bitmap is valid. ++ */ ++static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb, ++ struct ext4_group_desc *desc, ++ unsigned int block_group, ++ struct buffer_head *bh) + { + ext4_grpblk_t offset; + ext4_grpblk_t next_zero_bit; +- ext4_fsblk_t bitmap_blk; ++ ext4_fsblk_t blk; + ext4_fsblk_t group_first_block; + + if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) { +@@ -297,37 +301,33 @@ static int ext4_valid_block_bitmap(struct super_block *sb, + * or it has to also read the block group where the bitmaps + * are located to verify they are set. + */ +- return 1; ++ return 0; + } + group_first_block = ext4_group_first_block_no(sb, block_group); + + /* check whether block bitmap block number is set */ +- bitmap_blk = ext4_block_bitmap(sb, desc); +- offset = bitmap_blk - group_first_block; ++ blk = ext4_block_bitmap(sb, desc); ++ offset = blk - group_first_block; + if (!ext4_test_bit(offset, bh->b_data)) + /* bad block bitmap */ +- goto err_out; ++ return blk; + + /* check whether the inode bitmap block number is set */ +- bitmap_blk = ext4_inode_bitmap(sb, desc); +- offset = bitmap_blk - group_first_block; ++ blk = ext4_inode_bitmap(sb, desc); ++ offset = blk - group_first_block; + if (!ext4_test_bit(offset, bh->b_data)) + /* bad block bitmap */ +- goto err_out; ++ return blk; + + /* check whether the inode table block number is set */ +- bitmap_blk = ext4_inode_table(sb, desc); +- offset = bitmap_blk - group_first_block; ++ blk = ext4_inode_table(sb, desc); ++ offset = blk - group_first_block; + next_zero_bit = ext4_find_next_zero_bit(bh->b_data, + offset + EXT4_SB(sb)->s_itb_per_group, + offset); +- if (next_zero_bit >= offset + EXT4_SB(sb)->s_itb_per_group) +- /* good bitmap for inode tables */ +- return 1; +- +-err_out: +- ext4_error(sb, "Invalid block bitmap - block_group = %d, block = %llu", +- block_group, bitmap_blk); ++ if (next_zero_bit < offset + EXT4_SB(sb)->s_itb_per_group) ++ /* bad bitmap for inode tables */ ++ return blk; + return 0; + } + +@@ -336,14 +336,26 @@ void ext4_validate_block_bitmap(struct super_block *sb, + unsigned int block_group, + struct buffer_head *bh) + { ++ ext4_fsblk_t blk; ++ + if (buffer_verified(bh)) + return; + + ext4_lock_group(sb, block_group); +- if (ext4_valid_block_bitmap(sb, desc, block_group, bh) && +- ext4_block_bitmap_csum_verify(sb, block_group, desc, bh, +- EXT4_BLOCKS_PER_GROUP(sb) / 8)) +- set_buffer_verified(bh); ++ blk = ext4_valid_block_bitmap(sb, desc, block_group, bh); ++ if (unlikely(blk != 0)) { ++ ext4_unlock_group(sb, block_group); ++ ext4_error(sb, "bg %u: block %llu: invalid block bitmap", ++ block_group, blk); ++ return; ++ } ++ if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group, ++ desc, bh, EXT4_BLOCKS_PER_GROUP(sb) / 8))) { ++ ext4_unlock_group(sb, block_group); ++ ext4_error(sb, "bg %u: bad block bitmap checksum", block_group); ++ return; ++ } ++ set_buffer_verified(bh); + ext4_unlock_group(sb, block_group); + } + +@@ -609,7 +621,8 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb) + 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_group_clusters(sb, gdp), x); + bitmap_count += x; +diff --git a/fs/ext4/bitmap.c b/fs/ext4/bitmap.c +index b319721..ad9d96e 100644 +--- a/fs/ext4/bitmap.c ++++ b/fs/ext4/bitmap.c +@@ -11,24 +11,18 @@ + #include + #include "ext4.h" + +-#ifdef EXT4FS_DEBUG +- + 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; + } + +-#endif /* EXT4FS_DEBUG */ +- + int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group, + struct ext4_group_desc *gdp, + struct buffer_head *bh, int sz) +@@ -92,7 +86,6 @@ int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group, + if (provided == calculated) + return 1; + +- ext4_error(sb, "Bad block bitmap checksum: block_group = %u", group); + return 0; + } + +diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h +index cfc4e01..01434f2 100644 +--- a/fs/ext4/ext4.h ++++ b/fs/ext4/ext4.h +@@ -1161,8 +1161,7 @@ struct ext4_sb_info { + unsigned long s_desc_per_block; /* Number of group descriptors per block */ + ext4_group_t s_groups_count; /* Number of groups in the fs */ + ext4_group_t s_blockfile_groups;/* Groups acceptable for non-extent files */ +- unsigned long s_overhead_last; /* Last calculated overhead */ +- unsigned long s_blocks_last; /* Last seen block count */ ++ unsigned long s_overhead; /* # of fs overhead clusters */ + unsigned int s_cluster_ratio; /* Number of blocks per cluster */ + unsigned int s_cluster_bits; /* log2 of s_cluster_ratio */ + loff_t s_bitmap_maxbytes; /* max bytes for bitmap files */ +@@ -1852,7 +1851,7 @@ struct mmpd_data { + # 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); + void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group, + struct ext4_group_desc *gdp, + struct buffer_head *bh, int sz); +@@ -2037,6 +2036,7 @@ extern int ext4_group_extend(struct super_block *sb, + extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count); + + /* super.c */ ++extern int ext4_calculate_overhead(struct super_block *sb); + extern int ext4_superblock_csum_verify(struct super_block *sb, + struct ext4_super_block *es); + extern void ext4_superblock_csum_set(struct super_block *sb, +diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c +index 91341ec..9752106 100644 +--- a/fs/ext4/extents.c ++++ b/fs/ext4/extents.c +@@ -2570,10 +2570,10 @@ static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, + { + struct super_block *sb = inode->i_sb; + int depth = ext_depth(inode); +- struct ext4_ext_path *path; ++ struct ext4_ext_path *path = NULL; + ext4_fsblk_t partial_cluster = 0; + handle_t *handle; +- int i, err; ++ int i = 0, err; + + ext_debug("truncate since %u to %u\n", start, end); + +@@ -2606,8 +2606,12 @@ again: + } + depth = ext_depth(inode); + ex = path[depth].p_ext; +- if (!ex) ++ if (!ex) { ++ ext4_ext_drop_refs(path); ++ kfree(path); ++ path = NULL; + goto cont; ++ } + + ee_block = le32_to_cpu(ex->ee_block); + +@@ -2637,8 +2641,6 @@ again: + if (err < 0) + goto out; + } +- ext4_ext_drop_refs(path); +- kfree(path); + } + cont: + +@@ -2647,19 +2649,28 @@ cont: + * after i_size and walking into the tree depth-wise. + */ + depth = ext_depth(inode); +- path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 1), GFP_NOFS); +- if (path == NULL) { +- ext4_journal_stop(handle); +- return -ENOMEM; +- } +- path[0].p_depth = depth; +- path[0].p_hdr = ext_inode_hdr(inode); ++ if (path) { ++ int k = i = depth; ++ while (--k > 0) ++ path[k].p_block = ++ le16_to_cpu(path[k].p_hdr->eh_entries)+1; ++ } else { ++ path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 1), ++ GFP_NOFS); ++ if (path == NULL) { ++ ext4_journal_stop(handle); ++ return -ENOMEM; ++ } ++ path[0].p_depth = depth; ++ path[0].p_hdr = ext_inode_hdr(inode); ++ i = 0; + +- if (ext4_ext_check(inode, path[0].p_hdr, depth)) { +- err = -EIO; +- goto out; ++ if (ext4_ext_check(inode, path[0].p_hdr, depth)) { ++ err = -EIO; ++ goto out; ++ } + } +- i = err = 0; ++ err = 0; + + while (i >= 0 && err == 0) { + if (i == depth) { +@@ -2773,8 +2784,10 @@ cont: + out: + ext4_ext_drop_refs(path); + kfree(path); +- if (err == -EAGAIN) ++ if (err == -EAGAIN) { ++ path = NULL; + goto again; ++ } + ext4_journal_stop(handle); + + return err; +diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c +index d48e8b1..6866bc2 100644 +--- a/fs/ext4/ialloc.c ++++ b/fs/ext4/ialloc.c +@@ -1054,7 +1054,8 @@ unsigned long ext4_count_free_inodes(struct super_block *sb) + 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 --git a/fs/ext4/inode.c b/fs/ext4/inode.c +index 02bc8cb..9e9aed3 100644 +--- a/fs/ext4/inode.c ++++ b/fs/ext4/inode.c +@@ -346,6 +346,15 @@ void ext4_da_update_reserve_space(struct inode *inode, + 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; +@@ -1171,6 +1180,17 @@ static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock) + struct ext4_inode_info *ei = EXT4_I(inode); + unsigned int md_needed; + int ret; ++ ext4_lblk_t save_last_lblock; ++ int save_len; ++ ++ /* ++ * We will charge metadata quota at writeout time; this saves ++ * us from metadata over-estimation, though we may go over by ++ * a small amount in the end. Here we just reserve for data. ++ */ ++ ret = dquot_reserve_block(inode, EXT4_C2B(sbi, 1)); ++ if (ret) ++ return ret; + + /* + * recalculate the amount of metadata blocks to reserve +@@ -1179,32 +1199,31 @@ static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock) + */ + repeat: + spin_lock(&ei->i_block_reservation_lock); ++ /* ++ * ext4_calc_metadata_amount() has side effects, which we have ++ * to be prepared undo if we fail to claim space. ++ */ ++ save_len = ei->i_da_metadata_calc_len; ++ save_last_lblock = ei->i_da_metadata_calc_last_lblock; + md_needed = EXT4_NUM_B2C(sbi, + ext4_calc_metadata_amount(inode, lblock)); + trace_ext4_da_reserve_space(inode, md_needed); +- spin_unlock(&ei->i_block_reservation_lock); + + /* +- * We will charge metadata quota at writeout time; this saves +- * us from metadata over-estimation, though we may go over by +- * a small amount in the end. Here we just reserve for data. +- */ +- ret = dquot_reserve_block(inode, EXT4_C2B(sbi, 1)); +- if (ret) +- return ret; +- /* + * We do still charge estimated metadata to the sb though; + * we cannot afford to run out of free blocks. + */ + if (ext4_claim_free_clusters(sbi, md_needed + 1, 0)) { +- dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1)); ++ ei->i_da_metadata_calc_len = save_len; ++ ei->i_da_metadata_calc_last_lblock = save_last_lblock; ++ spin_unlock(&ei->i_block_reservation_lock); + if (ext4_should_retry_alloc(inode->i_sb, &retries)) { + yield(); + goto repeat; + } ++ dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1)); + return -ENOSPC; + } +- spin_lock(&ei->i_block_reservation_lock); + ei->i_reserved_data_blocks++; + ei->i_reserved_meta_blocks += md_needed; + spin_unlock(&ei->i_block_reservation_lock); +@@ -2434,6 +2453,16 @@ static int ext4_nonda_switch(struct super_block *sb) + free_blocks = EXT4_C2B(sbi, + percpu_counter_read_positive(&sbi->s_freeclusters_counter)); + dirty_blocks = percpu_counter_read_positive(&sbi->s_dirtyclusters_counter); ++ /* ++ * Start pushing delalloc when 1/2 of free blocks are dirty. ++ */ ++ if (dirty_blocks && (free_blocks < 2 * dirty_blocks) && ++ !writeback_in_progress(sb->s_bdi) && ++ down_read_trylock(&sb->s_umount)) { ++ writeback_inodes_sb(sb, WB_REASON_FS_FREE_SPACE); ++ up_read(&sb->s_umount); ++ } ++ + if (2 * free_blocks < 3 * dirty_blocks || + free_blocks < (dirty_blocks + EXT4_FREECLUSTERS_WATERMARK)) { + /* +@@ -2442,13 +2471,6 @@ static int ext4_nonda_switch(struct super_block *sb) + */ + return 1; + } +- /* +- * Even if we don't switch but are nearing capacity, +- * start pushing delalloc when 1/2 of free blocks are dirty. +- */ +- if (free_blocks < 2 * dirty_blocks) +- writeback_inodes_sb_if_idle(sb, WB_REASON_FS_FREE_SPACE); +- + return 0; + } + +@@ -3966,6 +3988,7 @@ static int ext4_do_update_inode(handle_t *handle, + struct ext4_inode_info *ei = EXT4_I(inode); + struct buffer_head *bh = iloc->bh; + int err = 0, rc, block; ++ int need_datasync = 0; + uid_t i_uid; + gid_t i_gid; + +@@ -4016,7 +4039,10 @@ static int ext4_do_update_inode(handle_t *handle, + raw_inode->i_file_acl_high = + cpu_to_le16(ei->i_file_acl >> 32); + raw_inode->i_file_acl_lo = cpu_to_le32(ei->i_file_acl); +- ext4_isize_set(raw_inode, ei->i_disksize); ++ if (ei->i_disksize != ext4_isize(raw_inode)) { ++ ext4_isize_set(raw_inode, ei->i_disksize); ++ need_datasync = 1; ++ } + if (ei->i_disksize > 0x7fffffffULL) { + struct super_block *sb = inode->i_sb; + if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, +@@ -4069,7 +4095,7 @@ static int ext4_do_update_inode(handle_t *handle, + err = rc; + ext4_clear_inode_state(inode, EXT4_STATE_NEW); + +- ext4_update_inode_fsync_trans(handle, inode, 0); ++ ext4_update_inode_fsync_trans(handle, inode, need_datasync); + out_brelse: + brelse(bh); + ext4_std_error(inode->i_sb, err); +diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c +index c5826c6..e2016f3 100644 +--- a/fs/ext4/move_extent.c ++++ b/fs/ext4/move_extent.c +@@ -141,55 +141,21 @@ mext_next_extent(struct inode *inode, struct ext4_ext_path *path, + } + + /** +- * mext_check_null_inode - NULL check for two inodes +- * +- * If inode1 or inode2 is NULL, return -EIO. Otherwise, return 0. +- */ +-static int +-mext_check_null_inode(struct inode *inode1, struct inode *inode2, +- const char *function, unsigned int line) +-{ +- int ret = 0; +- +- if (inode1 == NULL) { +- __ext4_error(inode2->i_sb, function, line, +- "Both inodes should not be NULL: " +- "inode1 NULL inode2 %lu", inode2->i_ino); +- ret = -EIO; +- } else if (inode2 == NULL) { +- __ext4_error(inode1->i_sb, function, line, +- "Both inodes should not be NULL: " +- "inode1 %lu inode2 NULL", inode1->i_ino); +- ret = -EIO; +- } +- return ret; +-} +- +-/** + * double_down_write_data_sem - Acquire two inodes' write lock of i_data_sem + * +- * @orig_inode: original inode structure +- * @donor_inode: donor inode structure +- * Acquire write lock of i_data_sem of the two inodes (orig and donor) by +- * i_ino order. ++ * Acquire write lock of i_data_sem of the two inodes + */ + static void +-double_down_write_data_sem(struct inode *orig_inode, struct inode *donor_inode) ++double_down_write_data_sem(struct inode *first, struct inode *second) + { +- struct inode *first = orig_inode, *second = donor_inode; ++ if (first < second) { ++ down_write(&EXT4_I(first)->i_data_sem); ++ down_write_nested(&EXT4_I(second)->i_data_sem, SINGLE_DEPTH_NESTING); ++ } else { ++ down_write(&EXT4_I(second)->i_data_sem); ++ down_write_nested(&EXT4_I(first)->i_data_sem, SINGLE_DEPTH_NESTING); + +- /* +- * Use the inode number to provide the stable locking order instead +- * of its address, because the C language doesn't guarantee you can +- * compare pointers that don't come from the same array. +- */ +- if (donor_inode->i_ino < orig_inode->i_ino) { +- first = donor_inode; +- second = orig_inode; + } +- +- down_write(&EXT4_I(first)->i_data_sem); +- down_write_nested(&EXT4_I(second)->i_data_sem, SINGLE_DEPTH_NESTING); + } + + /** +@@ -969,14 +935,6 @@ mext_check_arguments(struct inode *orig_inode, + return -EINVAL; + } + +- /* Files should be in the same ext4 FS */ +- if (orig_inode->i_sb != donor_inode->i_sb) { +- ext4_debug("ext4 move extent: The argument files " +- "should be in same FS [ino:orig %lu, donor %lu]\n", +- orig_inode->i_ino, donor_inode->i_ino); +- return -EINVAL; +- } +- + /* Ext4 move extent supports only extent based file */ + if (!(ext4_test_inode_flag(orig_inode, EXT4_INODE_EXTENTS))) { + ext4_debug("ext4 move extent: orig file is not extents " +@@ -1072,35 +1030,19 @@ mext_check_arguments(struct inode *orig_inode, + * @inode1: the inode structure + * @inode2: the inode structure + * +- * Lock two inodes' i_mutex by i_ino order. +- * If inode1 or inode2 is NULL, return -EIO. Otherwise, return 0. ++ * Lock two inodes' i_mutex + */ +-static int ++static void + mext_inode_double_lock(struct inode *inode1, struct inode *inode2) + { +- int ret = 0; +- +- BUG_ON(inode1 == NULL && inode2 == NULL); +- +- ret = mext_check_null_inode(inode1, inode2, __func__, __LINE__); +- if (ret < 0) +- goto out; +- +- if (inode1 == inode2) { +- mutex_lock(&inode1->i_mutex); +- goto out; +- } +- +- if (inode1->i_ino < inode2->i_ino) { ++ BUG_ON(inode1 == inode2); ++ if (inode1 < inode2) { + mutex_lock_nested(&inode1->i_mutex, I_MUTEX_PARENT); + mutex_lock_nested(&inode2->i_mutex, I_MUTEX_CHILD); + } else { + mutex_lock_nested(&inode2->i_mutex, I_MUTEX_PARENT); + mutex_lock_nested(&inode1->i_mutex, I_MUTEX_CHILD); + } +- +-out: +- return ret; + } + + /** +@@ -1109,28 +1051,13 @@ out: + * @inode1: the inode that is released first + * @inode2: the inode that is released second + * +- * If inode1 or inode2 is NULL, return -EIO. Otherwise, return 0. + */ + +-static int ++static void + mext_inode_double_unlock(struct inode *inode1, struct inode *inode2) + { +- int ret = 0; +- +- BUG_ON(inode1 == NULL && inode2 == NULL); +- +- ret = mext_check_null_inode(inode1, inode2, __func__, __LINE__); +- if (ret < 0) +- goto out; +- +- if (inode1) +- mutex_unlock(&inode1->i_mutex); +- +- if (inode2 && inode2 != inode1) +- mutex_unlock(&inode2->i_mutex); +- +-out: +- return ret; ++ mutex_unlock(&inode1->i_mutex); ++ mutex_unlock(&inode2->i_mutex); + } + + /** +@@ -1187,16 +1114,23 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, + ext4_lblk_t block_end, seq_start, add_blocks, file_end, seq_blocks = 0; + ext4_lblk_t rest_blocks; + pgoff_t orig_page_offset = 0, seq_end_page; +- int ret1, ret2, depth, last_extent = 0; ++ int ret, depth, last_extent = 0; + int blocks_per_page = PAGE_CACHE_SIZE >> orig_inode->i_blkbits; + int data_offset_in_page; + int block_len_in_page; + int uninit; + +- /* orig and donor should be different file */ +- if (orig_inode->i_ino == donor_inode->i_ino) { ++ if (orig_inode->i_sb != donor_inode->i_sb) { ++ ext4_debug("ext4 move extent: The argument files " ++ "should be in same FS [ino:orig %lu, donor %lu]\n", ++ orig_inode->i_ino, donor_inode->i_ino); ++ return -EINVAL; ++ } ++ ++ /* orig and donor should be different inodes */ ++ if (orig_inode == donor_inode) { + ext4_debug("ext4 move extent: The argument files should not " +- "be same file [ino:orig %lu, donor %lu]\n", ++ "be same inode [ino:orig %lu, donor %lu]\n", + orig_inode->i_ino, donor_inode->i_ino); + return -EINVAL; + } +@@ -1208,18 +1142,21 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, + orig_inode->i_ino, donor_inode->i_ino); + return -EINVAL; + } +- ++ /* TODO: This is non obvious task to swap blocks for inodes with full ++ jornaling enabled */ ++ if (ext4_should_journal_data(orig_inode) || ++ ext4_should_journal_data(donor_inode)) { ++ return -EINVAL; ++ } + /* Protect orig and donor inodes against a truncate */ +- ret1 = mext_inode_double_lock(orig_inode, donor_inode); +- if (ret1 < 0) +- return ret1; ++ mext_inode_double_lock(orig_inode, donor_inode); + + /* Protect extent tree against block allocations via delalloc */ + double_down_write_data_sem(orig_inode, donor_inode); + /* Check the filesystem environment whether move_extent can be done */ +- ret1 = mext_check_arguments(orig_inode, donor_inode, orig_start, ++ ret = mext_check_arguments(orig_inode, donor_inode, orig_start, + donor_start, &len); +- if (ret1) ++ if (ret) + goto out; + + file_end = (i_size_read(orig_inode) - 1) >> orig_inode->i_blkbits; +@@ -1227,13 +1164,13 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, + if (file_end < block_end) + len -= block_end - file_end; + +- ret1 = get_ext_path(orig_inode, block_start, &orig_path); +- if (ret1) ++ ret = get_ext_path(orig_inode, block_start, &orig_path); ++ if (ret) + goto out; + + /* Get path structure to check the hole */ +- ret1 = get_ext_path(orig_inode, block_start, &holecheck_path); +- if (ret1) ++ ret = get_ext_path(orig_inode, block_start, &holecheck_path); ++ if (ret) + goto out; + + depth = ext_depth(orig_inode); +@@ -1252,13 +1189,13 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, + last_extent = mext_next_extent(orig_inode, + holecheck_path, &ext_cur); + if (last_extent < 0) { +- ret1 = last_extent; ++ ret = last_extent; + goto out; + } + last_extent = mext_next_extent(orig_inode, orig_path, + &ext_dummy); + if (last_extent < 0) { +- ret1 = last_extent; ++ ret = last_extent; + goto out; + } + seq_start = le32_to_cpu(ext_cur->ee_block); +@@ -1272,7 +1209,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, + if (le32_to_cpu(ext_cur->ee_block) > block_end) { + ext4_debug("ext4 move extent: The specified range of file " + "may be the hole\n"); +- ret1 = -EINVAL; ++ ret = -EINVAL; + goto out; + } + +@@ -1292,7 +1229,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, + last_extent = mext_next_extent(orig_inode, holecheck_path, + &ext_cur); + if (last_extent < 0) { +- ret1 = last_extent; ++ ret = last_extent; + break; + } + add_blocks = ext4_ext_get_actual_len(ext_cur); +@@ -1349,18 +1286,18 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, + orig_page_offset, + data_offset_in_page, + block_len_in_page, uninit, +- &ret1); ++ &ret); + + /* Count how many blocks we have exchanged */ + *moved_len += block_len_in_page; +- if (ret1 < 0) ++ if (ret < 0) + break; + if (*moved_len > len) { + EXT4_ERROR_INODE(orig_inode, + "We replaced blocks too much! " + "sum of replaced: %llu requested: %llu", + *moved_len, len); +- ret1 = -EIO; ++ ret = -EIO; + break; + } + +@@ -1374,22 +1311,22 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, + } + + double_down_write_data_sem(orig_inode, donor_inode); +- if (ret1 < 0) ++ if (ret < 0) + break; + + /* Decrease buffer counter */ + if (holecheck_path) + ext4_ext_drop_refs(holecheck_path); +- ret1 = get_ext_path(orig_inode, seq_start, &holecheck_path); +- if (ret1) ++ ret = get_ext_path(orig_inode, seq_start, &holecheck_path); ++ if (ret) + break; + depth = holecheck_path->p_depth; + + /* Decrease buffer counter */ + if (orig_path) + ext4_ext_drop_refs(orig_path); +- ret1 = get_ext_path(orig_inode, seq_start, &orig_path); +- if (ret1) ++ ret = get_ext_path(orig_inode, seq_start, &orig_path); ++ if (ret) + break; + + ext_cur = holecheck_path[depth].p_ext; +@@ -1412,12 +1349,7 @@ out: + kfree(holecheck_path); + } + double_up_write_data_sem(orig_inode, donor_inode); +- ret2 = mext_inode_double_unlock(orig_inode, donor_inode); +- +- if (ret1) +- return ret1; +- else if (ret2) +- return ret2; ++ mext_inode_double_unlock(orig_inode, donor_inode); + +- return 0; ++ return ret; + } +diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c +index 5845cd9..ad6767e 100644 +--- a/fs/ext4/namei.c ++++ b/fs/ext4/namei.c +@@ -2149,9 +2149,7 @@ retry: + err = PTR_ERR(inode); + if (!IS_ERR(inode)) { + init_special_inode(inode, inode->i_mode, rdev); +-#ifdef CONFIG_EXT4_FS_XATTR + inode->i_op = &ext4_special_inode_operations; +-#endif + err = ext4_add_nondir(handle, dentry, inode); + } + ext4_journal_stop(handle); +@@ -2918,8 +2916,15 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, + PARENT_INO(dir_bh->b_data, new_dir->i_sb->s_blocksize) = + cpu_to_le32(new_dir->i_ino); + BUFFER_TRACE(dir_bh, "call ext4_handle_dirty_metadata"); +- retval = ext4_handle_dirty_dirent_node(handle, old_inode, +- dir_bh); ++ if (is_dx(old_inode)) { ++ retval = ext4_handle_dirty_dx_node(handle, ++ old_inode, ++ dir_bh); ++ } else { ++ retval = ext4_handle_dirty_dirent_node(handle, ++ old_inode, ++ dir_bh); ++ } + if (retval) { + ext4_std_error(old_dir->i_sb, retval); + goto end_rename; +diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c +index 7ea6cbb..b0bdd10 100644 +--- a/fs/ext4/resize.c ++++ b/fs/ext4/resize.c +@@ -200,8 +200,11 @@ static void free_flex_gd(struct ext4_new_flex_group_data *flex_gd) + * be a partial of a flex group. + * + * @sb: super block of fs to which the groups belongs ++ * ++ * Returns 0 on a successful allocation of the metadata blocks in the ++ * block group. + */ +-static void ext4_alloc_group_tables(struct super_block *sb, ++static int ext4_alloc_group_tables(struct super_block *sb, + struct ext4_new_flex_group_data *flex_gd, + int flexbg_size) + { +@@ -226,6 +229,8 @@ static void ext4_alloc_group_tables(struct super_block *sb, + (last_group & ~(flexbg_size - 1)))); + next_group: + group = group_data[0].group; ++ if (src_group >= group_data[0].group + flex_gd->count) ++ return -ENOSPC; + start_blk = ext4_group_first_block_no(sb, src_group); + last_blk = start_blk + group_data[src_group - group].blocks_count; + +@@ -235,7 +240,6 @@ next_group: + + start_blk += overhead; + +- BUG_ON(src_group >= group_data[0].group + flex_gd->count); + /* We collect contiguous blocks as much as possible. */ + src_group++; + for (; src_group <= last_group; src_group++) +@@ -300,6 +304,7 @@ next_group: + group_data[i].free_blocks_count); + } + } ++ return 0; + } + + static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, +@@ -451,6 +456,9 @@ static int setup_new_flex_group_blocks(struct super_block *sb, + gdblocks = ext4_bg_num_gdb(sb, group); + start = ext4_group_first_block_no(sb, group); + ++ if (!ext4_bg_has_super(sb, group)) ++ goto handle_itb; ++ + /* Copy all of the GDT blocks into the backup in this group */ + for (j = 0, block = start + 1; j < gdblocks; j++, block++) { + struct buffer_head *gdb; +@@ -493,6 +501,7 @@ static int setup_new_flex_group_blocks(struct super_block *sb, + goto out; + } + ++handle_itb: + /* Initialize group tables of the grop @group */ + if (!(bg_flags[i] & EXT4_BG_INODE_ZEROED)) + goto handle_bb; +@@ -1197,7 +1206,7 @@ static void ext4_update_super(struct super_block *sb, + struct ext4_new_group_data *group_data = flex_gd->groups; + struct ext4_sb_info *sbi = EXT4_SB(sb); + struct ext4_super_block *es = sbi->s_es; +- int i; ++ int i, ret; + + BUG_ON(flex_gd->count == 0 || group_data == NULL); + /* +@@ -1272,6 +1281,11 @@ static void ext4_update_super(struct super_block *sb, + &sbi->s_flex_groups[flex_group].free_inodes); + } + ++ /* ++ * Update the fs overhead information ++ */ ++ ext4_calculate_overhead(sb); ++ + if (test_opt(sb, DEBUG)) + printk(KERN_DEBUG "EXT4-fs: added group %u:" + "%llu blocks(%llu free %llu reserved)\n", flex_gd->count, +@@ -1344,13 +1358,15 @@ exit_journal: + err = err2; + + if (!err) { +- int i; ++ int gdb_num = group / EXT4_DESC_PER_BLOCK(sb); ++ int gdb_num_end = ((group + flex_gd->count - 1) / ++ EXT4_DESC_PER_BLOCK(sb)); ++ + update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es, + sizeof(struct ext4_super_block)); +- for (i = 0; i < flex_gd->count; i++, group++) { ++ for (; gdb_num <= gdb_num_end; gdb_num++) { + struct buffer_head *gdb_bh; +- int gdb_num; +- gdb_num = group / EXT4_BLOCKS_PER_GROUP(sb); ++ + gdb_bh = sbi->s_group_desc[gdb_num]; + update_backups(sb, gdb_bh->b_blocknr, gdb_bh->b_data, + gdb_bh->b_size); +@@ -1724,7 +1740,8 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count) + */ + while (ext4_setup_next_flex_gd(sb, flex_gd, n_blocks_count, + flexbg_size)) { +- ext4_alloc_group_tables(sb, flex_gd, flexbg_size); ++ if (ext4_alloc_group_tables(sb, flex_gd, flexbg_size) != 0) ++ break; + err = ext4_flex_group_add(sb, resize_inode, flex_gd); + if (unlikely(err)) + break; +diff --git a/fs/ext4/super.c b/fs/ext4/super.c +index eb7aa3e..975405c 100644 +--- a/fs/ext4/super.c ++++ b/fs/ext4/super.c +@@ -976,6 +976,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) + ei->i_reserved_meta_blocks = 0; + ei->i_allocated_meta_blocks = 0; + ei->i_da_metadata_calc_len = 0; ++ ei->i_da_metadata_calc_last_lblock = 0; + spin_lock_init(&(ei->i_block_reservation_lock)); + #ifdef CONFIG_QUOTA + ei->i_reserved_quota = 0; +@@ -1747,7 +1748,7 @@ static inline void ext4_show_quota_options(struct seq_file *seq, + + static const char *token2str(int token) + { +- static const struct match_token *t; ++ const struct match_token *t; + + for (t = tokens; t->token != Opt_err; t++) + if (t->token == token && !strchr(t->pattern, '=')) +@@ -3085,6 +3086,118 @@ static int set_journal_csum_feature_set(struct super_block *sb) + return ret; + } + ++/* ++ * Note: calculating the overhead so we can be compatible with ++ * historical BSD practice is quite difficult in the face of ++ * clusters/bigalloc. This is because multiple metadata blocks from ++ * different block group can end up in the same allocation cluster. ++ * Calculating the exact overhead in the face of clustered allocation ++ * requires either O(all block bitmaps) in memory or O(number of block ++ * groups**2) in time. We will still calculate the superblock for ++ * older file systems --- and if we come across with a bigalloc file ++ * system with zero in s_overhead_clusters the estimate will be close to ++ * correct especially for very large cluster sizes --- but for newer ++ * file systems, it's better to calculate this figure once at mkfs ++ * time, and store it in the superblock. If the superblock value is ++ * present (even for non-bigalloc file systems), we will use it. ++ */ ++static int count_overhead(struct super_block *sb, ext4_group_t grp, ++ char *buf) ++{ ++ struct ext4_sb_info *sbi = EXT4_SB(sb); ++ struct ext4_group_desc *gdp; ++ ext4_fsblk_t first_block, last_block, b; ++ ext4_group_t i, ngroups = ext4_get_groups_count(sb); ++ int s, j, count = 0; ++ ++ if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_BIGALLOC)) ++ return (ext4_bg_has_super(sb, grp) + ext4_bg_num_gdb(sb, grp) + ++ sbi->s_itb_per_group + 2); ++ ++ first_block = le32_to_cpu(sbi->s_es->s_first_data_block) + ++ (grp * EXT4_BLOCKS_PER_GROUP(sb)); ++ last_block = first_block + EXT4_BLOCKS_PER_GROUP(sb) - 1; ++ for (i = 0; i < ngroups; i++) { ++ gdp = ext4_get_group_desc(sb, i, NULL); ++ b = ext4_block_bitmap(sb, gdp); ++ if (b >= first_block && b <= last_block) { ++ ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf); ++ count++; ++ } ++ b = ext4_inode_bitmap(sb, gdp); ++ if (b >= first_block && b <= last_block) { ++ ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf); ++ count++; ++ } ++ b = ext4_inode_table(sb, gdp); ++ if (b >= first_block && b + sbi->s_itb_per_group <= last_block) ++ for (j = 0; j < sbi->s_itb_per_group; j++, b++) { ++ int c = EXT4_B2C(sbi, b - first_block); ++ ext4_set_bit(c, buf); ++ count++; ++ } ++ if (i != grp) ++ continue; ++ s = 0; ++ if (ext4_bg_has_super(sb, grp)) { ++ ext4_set_bit(s++, buf); ++ count++; ++ } ++ for (j = ext4_bg_num_gdb(sb, grp); j > 0; j--) { ++ ext4_set_bit(EXT4_B2C(sbi, s++), buf); ++ count++; ++ } ++ } ++ if (!count) ++ return 0; ++ return EXT4_CLUSTERS_PER_GROUP(sb) - ++ ext4_count_free(buf, EXT4_CLUSTERS_PER_GROUP(sb) / 8); ++} ++ ++/* ++ * Compute the overhead and stash it in sbi->s_overhead ++ */ ++int ext4_calculate_overhead(struct super_block *sb) ++{ ++ struct ext4_sb_info *sbi = EXT4_SB(sb); ++ struct ext4_super_block *es = sbi->s_es; ++ ext4_group_t i, ngroups = ext4_get_groups_count(sb); ++ ext4_fsblk_t overhead = 0; ++ char *buf = (char *) get_zeroed_page(GFP_KERNEL); ++ ++ memset(buf, 0, PAGE_SIZE); ++ if (!buf) ++ return -ENOMEM; ++ ++ /* ++ * Compute the overhead (FS structures). This is constant ++ * for a given filesystem unless the number of block groups ++ * changes so we cache the previous value until it does. ++ */ ++ ++ /* ++ * All of the blocks before first_data_block are overhead ++ */ ++ overhead = EXT4_B2C(sbi, le32_to_cpu(es->s_first_data_block)); ++ ++ /* ++ * Add the overhead found in each block group ++ */ ++ for (i = 0; i < ngroups; i++) { ++ int blks; ++ ++ blks = count_overhead(sb, i, buf); ++ overhead += blks; ++ if (blks) ++ memset(buf, 0, PAGE_SIZE); ++ cond_resched(); ++ } ++ sbi->s_overhead = overhead; ++ smp_wmb(); ++ free_page((unsigned long) buf); ++ return 0; ++} ++ + static int ext4_fill_super(struct super_block *sb, void *data, int silent) + { + char *orig_data = kstrdup(data, GFP_KERNEL); +@@ -3735,6 +3848,18 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) + + no_journal: + /* ++ * Get the # of file system overhead blocks from the ++ * superblock if present. ++ */ ++ if (es->s_overhead_clusters) ++ sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters); ++ else { ++ ret = ext4_calculate_overhead(sb); ++ if (ret) ++ goto failed_mount_wq; ++ } ++ ++ /* + * The maximum number of concurrent works can be high and + * concurrency isn't really necessary. Limit it to 1. + */ +@@ -4286,6 +4411,7 @@ static void ext4_clear_journal_err(struct super_block *sb, + ext4_commit_super(sb, 1); + + jbd2_journal_clear_err(journal); ++ jbd2_journal_update_sb_errno(journal); + } + } + +@@ -4600,67 +4726,21 @@ restore_opts: + return err; + } + +-/* +- * Note: calculating the overhead so we can be compatible with +- * historical BSD practice is quite difficult in the face of +- * clusters/bigalloc. This is because multiple metadata blocks from +- * different block group can end up in the same allocation cluster. +- * Calculating the exact overhead in the face of clustered allocation +- * requires either O(all block bitmaps) in memory or O(number of block +- * groups**2) in time. We will still calculate the superblock for +- * older file systems --- and if we come across with a bigalloc file +- * system with zero in s_overhead_clusters the estimate will be close to +- * correct especially for very large cluster sizes --- but for newer +- * file systems, it's better to calculate this figure once at mkfs +- * time, and store it in the superblock. If the superblock value is +- * present (even for non-bigalloc file systems), we will use it. +- */ + static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf) + { + struct super_block *sb = dentry->d_sb; + struct ext4_sb_info *sbi = EXT4_SB(sb); + struct ext4_super_block *es = sbi->s_es; +- struct ext4_group_desc *gdp; ++ ext4_fsblk_t overhead = 0; + u64 fsid; + s64 bfree; + +- if (test_opt(sb, MINIX_DF)) { +- sbi->s_overhead_last = 0; +- } else if (es->s_overhead_clusters) { +- sbi->s_overhead_last = le32_to_cpu(es->s_overhead_clusters); +- } else if (sbi->s_blocks_last != ext4_blocks_count(es)) { +- ext4_group_t i, ngroups = ext4_get_groups_count(sb); +- ext4_fsblk_t overhead = 0; +- +- /* +- * Compute the overhead (FS structures). This is constant +- * for a given filesystem unless the number of block groups +- * changes so we cache the previous value until it does. +- */ +- +- /* +- * All of the blocks before first_data_block are +- * overhead +- */ +- overhead = EXT4_B2C(sbi, le32_to_cpu(es->s_first_data_block)); +- +- /* +- * Add the overhead found in each block group +- */ +- for (i = 0; i < ngroups; i++) { +- gdp = ext4_get_group_desc(sb, i, NULL); +- overhead += ext4_num_overhead_clusters(sb, i, gdp); +- cond_resched(); +- } +- sbi->s_overhead_last = overhead; +- smp_wmb(); +- sbi->s_blocks_last = ext4_blocks_count(es); +- } ++ if (!test_opt(sb, MINIX_DF)) ++ overhead = sbi->s_overhead; + + buf->f_type = EXT4_SUPER_MAGIC; + buf->f_bsize = sb->s_blocksize; +- buf->f_blocks = (ext4_blocks_count(es) - +- EXT4_C2B(sbi, sbi->s_overhead_last)); ++ buf->f_blocks = ext4_blocks_count(es) - EXT4_C2B(sbi, sbi->s_overhead); + bfree = percpu_counter_sum_positive(&sbi->s_freeclusters_counter) - + percpu_counter_sum_positive(&sbi->s_dirtyclusters_counter); + /* prevent underflow in case that few free space is available */ +diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c +index e56c9ed..2cdb98d 100644 +--- a/fs/ext4/xattr.c ++++ b/fs/ext4/xattr.c +@@ -127,19 +127,16 @@ static __le32 ext4_xattr_block_csum(struct inode *inode, + struct ext4_xattr_header *hdr) + { + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); +- struct ext4_inode_info *ei = EXT4_I(inode); + __u32 csum, old; + + old = hdr->h_checksum; + hdr->h_checksum = 0; +- if (le32_to_cpu(hdr->h_refcount) != 1) { +- block_nr = cpu_to_le64(block_nr); +- csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&block_nr, +- sizeof(block_nr)); +- } else +- csum = ei->i_csum_seed; ++ block_nr = cpu_to_le64(block_nr); ++ csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&block_nr, ++ sizeof(block_nr)); + csum = ext4_chksum(sbi, csum, (__u8 *)hdr, + EXT4_BLOCK_SIZE(inode->i_sb)); ++ + hdr->h_checksum = old; + return cpu_to_le32(csum); + } +diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c +index 41a3ccf..e2901ab 100644 +--- a/fs/fs-writeback.c ++++ b/fs/fs-writeback.c +@@ -68,6 +68,7 @@ int writeback_in_progress(struct backing_dev_info *bdi) + { + return test_bit(BDI_writeback_running, &bdi->state); + } ++EXPORT_SYMBOL(writeback_in_progress); + + static inline struct backing_dev_info *inode_to_bdi(struct inode *inode) + { +diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c +index 7df2b5e..f4246cf 100644 +--- a/fs/fuse/dev.c ++++ b/fs/fuse/dev.c +@@ -1576,6 +1576,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct inode *inode, + req->pages[req->num_pages] = page; + req->num_pages++; + ++ offset = 0; + num -= this_num; + total_len += this_num; + index++; +diff --git a/fs/fuse/file.c b/fs/fuse/file.c +index b321a68..514f12a 100644 +--- a/fs/fuse/file.c ++++ b/fs/fuse/file.c +@@ -1700,7 +1700,7 @@ static int fuse_verify_ioctl_iov(struct iovec *iov, size_t count) + size_t n; + u32 max = FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT; + +- for (n = 0; n < count; n++) { ++ for (n = 0; n < count; n++, iov++) { + if (iov->iov_len > (size_t) max) + return -ENOMEM; + max -= iov->iov_len; +diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c +index 425c2f2..4101422 100644 +--- a/fs/jbd/journal.c ++++ b/fs/jbd/journal.c +@@ -1113,6 +1113,11 @@ static void mark_journal_empty(journal_t *journal) + + BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); + spin_lock(&journal->j_state_lock); ++ /* Is it already empty? */ ++ if (sb->s_start == 0) { ++ spin_unlock(&journal->j_state_lock); ++ return; ++ } + jbd_debug(1, "JBD: Marking journal as empty (seq %d)\n", + journal->j_tail_sequence); + +diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c +index e9a3c4c..0f16edd 100644 +--- a/fs/jbd2/journal.c ++++ b/fs/jbd2/journal.c +@@ -1354,6 +1354,11 @@ static void jbd2_mark_journal_empty(journal_t *journal) + + BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); + read_lock(&journal->j_state_lock); ++ /* Is it already empty? */ ++ if (sb->s_start == 0) { ++ read_unlock(&journal->j_state_lock); ++ return; ++ } + jbd_debug(1, "JBD2: Marking journal as empty (seq %d)\n", + journal->j_tail_sequence); + +@@ -1377,7 +1382,7 @@ static void jbd2_mark_journal_empty(journal_t *journal) + * Update a journal's errno. Write updated superblock to disk waiting for IO + * to complete. + */ +-static void jbd2_journal_update_sb_errno(journal_t *journal) ++void jbd2_journal_update_sb_errno(journal_t *journal) + { + journal_superblock_t *sb = journal->j_superblock; + +@@ -1390,6 +1395,7 @@ static void jbd2_journal_update_sb_errno(journal_t *journal) + + jbd2_write_superblock(journal, WRITE_SYNC); + } ++EXPORT_SYMBOL(jbd2_journal_update_sb_errno); + + /* + * Read the superblock for a given journal, performing initial +diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c +index 61ea413..1224d6b 100644 +--- a/fs/jffs2/super.c ++++ b/fs/jffs2/super.c +@@ -100,6 +100,10 @@ static int jffs2_sync_fs(struct super_block *sb, int wait) + { + struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); + ++#ifdef CONFIG_JFFS2_FS_WRITEBUFFER ++ cancel_delayed_work_sync(&c->wbuf_dwork); ++#endif ++ + mutex_lock(&c->alloc_sem); + jffs2_flush_wbuf_pad(c); + mutex_unlock(&c->alloc_sem); +diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c +index 6f4529d..a6597d6 100644 +--- a/fs/jffs2/wbuf.c ++++ b/fs/jffs2/wbuf.c +@@ -1044,10 +1044,10 @@ int jffs2_check_oob_empty(struct jffs2_sb_info *c, + ops.datbuf = NULL; + + ret = mtd_read_oob(c->mtd, jeb->offset, &ops); +- if (ret || ops.oobretlen != ops.ooblen) { ++ if ((ret && !mtd_is_bitflip(ret)) || ops.oobretlen != ops.ooblen) { + pr_err("cannot read OOB for EB at %08x, requested %zd bytes, read %zd bytes, error %d\n", + jeb->offset, ops.ooblen, ops.oobretlen, ret); +- if (!ret) ++ if (!ret || mtd_is_bitflip(ret)) + ret = -EIO; + return ret; + } +@@ -1086,10 +1086,10 @@ int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, + ops.datbuf = NULL; + + ret = mtd_read_oob(c->mtd, jeb->offset, &ops); +- if (ret || ops.oobretlen != ops.ooblen) { ++ if ((ret && !mtd_is_bitflip(ret)) || ops.oobretlen != ops.ooblen) { + pr_err("cannot read OOB for EB at %08x, requested %zd bytes, read %zd bytes, error %d\n", + jeb->offset, ops.ooblen, ops.oobretlen, ret); +- if (!ret) ++ if (!ret || mtd_is_bitflip(ret)) + ret = -EIO; + return ret; + } +diff --git a/fs/locks.c b/fs/locks.c +index fce6238..82c3533 100644 +--- a/fs/locks.c ++++ b/fs/locks.c +@@ -308,7 +308,7 @@ static int flock_make_lock(struct file *filp, struct file_lock **lock, + 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: +@@ -445,7 +445,7 @@ static const struct lock_manager_operations lease_manager_ops = { + /* + * 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; +@@ -463,7 +463,7 @@ static int lease_init(struct file *filp, int type, struct file_lock *fl) + } + + /* 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 --git a/fs/nfs/dir.c b/fs/nfs/dir.c +index f430057..b1f3675 100644 +--- a/fs/nfs/dir.c ++++ b/fs/nfs/dir.c +@@ -1123,7 +1123,7 @@ static int nfs_lookup_revalidate(struct dentry *dentry, struct nameidata *nd) + struct nfs_fattr *fattr = NULL; + int error; + +- if (nd->flags & LOOKUP_RCU) ++ if (nd && (nd->flags & LOOKUP_RCU)) + return -ECHILD; + + parent = dget_parent(dentry); +@@ -1526,7 +1526,7 @@ static int nfs4_lookup_revalidate(struct dentry *dentry, struct nameidata *nd) + struct inode *dir; + int openflags, ret = 0; + +- if (nd->flags & LOOKUP_RCU) ++ if (nd && (nd->flags & LOOKUP_RCU)) + return -ECHILD; + + inode = dentry->d_inode; +diff --git a/fs/nfs/file.c b/fs/nfs/file.c +index a6708e6b..9075769 100644 +--- a/fs/nfs/file.c ++++ b/fs/nfs/file.c +@@ -459,8 +459,11 @@ static int nfs_release_page(struct page *page, gfp_t gfp) + + 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 --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c +index 864c51e..a0972e9 100644 +--- a/fs/nfs/idmap.c ++++ b/fs/nfs/idmap.c +@@ -63,6 +63,12 @@ struct idmap { + struct mutex idmap_mutex; + }; + ++struct idmap_legacy_upcalldata { ++ struct rpc_pipe_msg pipe_msg; ++ struct idmap_msg idmap_msg; ++ struct idmap *idmap; ++}; ++ + /** + * nfs_fattr_init_names - initialise the nfs_fattr owner_name/group_name fields + * @fattr: fully initialised struct nfs_fattr +@@ -205,12 +211,18 @@ static int nfs_idmap_init_keyring(void) + if (ret < 0) + goto failed_put_key; + ++ ret = register_key_type(&key_type_id_resolver_legacy); ++ if (ret < 0) ++ goto failed_reg_legacy; ++ + set_bit(KEY_FLAG_ROOT_CAN_CLEAR, &keyring->flags); + cred->thread_keyring = keyring; + cred->jit_keyring = KEY_REQKEY_DEFL_THREAD_KEYRING; + id_resolver_cache = cred; + return 0; + ++failed_reg_legacy: ++ unregister_key_type(&key_type_id_resolver); + failed_put_key: + key_put(keyring); + failed_put_cred: +@@ -222,6 +234,7 @@ static void nfs_idmap_quit_keyring(void) + { + key_revoke(id_resolver_cache->thread_keyring); + unregister_key_type(&key_type_id_resolver); ++ unregister_key_type(&key_type_id_resolver_legacy); + put_cred(id_resolver_cache); + } + +@@ -319,6 +332,7 @@ static ssize_t nfs_idmap_get_key(const char *name, size_t namelen, + ret = nfs_idmap_request_key(&key_type_id_resolver_legacy, + name, namelen, type, data, + data_size, idmap); ++ idmap->idmap_key_cons = NULL; + mutex_unlock(&idmap->idmap_mutex); + } + return ret; +@@ -376,16 +390,18 @@ static const match_table_t nfs_idmap_tokens = { + static int nfs_idmap_legacy_upcall(struct key_construction *, const char *, void *); + static ssize_t idmap_pipe_downcall(struct file *, const char __user *, + size_t); ++static void idmap_release_pipe(struct inode *); + static void idmap_pipe_destroy_msg(struct rpc_pipe_msg *); + + static const struct rpc_pipe_ops idmap_upcall_ops = { + .upcall = rpc_pipe_generic_upcall, + .downcall = idmap_pipe_downcall, ++ .release_pipe = idmap_release_pipe, + .destroy_msg = idmap_pipe_destroy_msg, + }; + + static struct key_type key_type_id_resolver_legacy = { +- .name = "id_resolver", ++ .name = "id_legacy", + .instantiate = user_instantiate, + .match = user_match, + .revoke = user_revoke, +@@ -612,7 +628,8 @@ void nfs_idmap_quit(void) + nfs_idmap_quit_keyring(); + } + +-static int nfs_idmap_prepare_message(char *desc, struct idmap_msg *im, ++static int nfs_idmap_prepare_message(char *desc, struct idmap *idmap, ++ struct idmap_msg *im, + struct rpc_pipe_msg *msg) + { + substring_t substr; +@@ -655,6 +672,7 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons, + const char *op, + void *aux) + { ++ struct idmap_legacy_upcalldata *data; + struct rpc_pipe_msg *msg; + struct idmap_msg *im; + struct idmap *idmap = (struct idmap *)aux; +@@ -662,33 +680,33 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons, + int ret = -ENOMEM; + + /* msg and im are freed in idmap_pipe_destroy_msg */ +- msg = kmalloc(sizeof(*msg), GFP_KERNEL); +- if (!msg) +- goto out0; +- +- im = kmalloc(sizeof(*im), GFP_KERNEL); +- if (!im) ++ data = kmalloc(sizeof(*data), GFP_KERNEL); ++ if (!data) + goto out1; + +- ret = nfs_idmap_prepare_message(key->description, im, msg); ++ msg = &data->pipe_msg; ++ im = &data->idmap_msg; ++ data->idmap = idmap; ++ ++ ret = nfs_idmap_prepare_message(key->description, idmap, im, msg); + if (ret < 0) + goto out2; + ++ BUG_ON(idmap->idmap_key_cons != NULL); + idmap->idmap_key_cons = cons; + + ret = rpc_queue_upcall(idmap->idmap_pipe, msg); + if (ret < 0) +- goto out2; ++ goto out3; + + return ret; + ++out3: ++ idmap->idmap_key_cons = NULL; + out2: +- kfree(im); ++ kfree(data); + out1: +- kfree(msg); +-out0: +- key_revoke(cons->key); +- key_revoke(cons->authkey); ++ complete_request_key(cons, ret); + return ret; + } + +@@ -722,11 +740,18 @@ idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) + { + struct rpc_inode *rpci = RPC_I(filp->f_path.dentry->d_inode); + struct idmap *idmap = (struct idmap *)rpci->private; +- struct key_construction *cons = idmap->idmap_key_cons; ++ struct key_construction *cons; + struct idmap_msg im; + size_t namelen_in; + int ret; + ++ /* If instantiation is successful, anyone waiting for key construction ++ * will have been woken up and someone else may now have used ++ * idmap_key_cons - so after this point we may no longer touch it. ++ */ ++ cons = ACCESS_ONCE(idmap->idmap_key_cons); ++ idmap->idmap_key_cons = NULL; ++ + if (mlen != sizeof(im)) { + ret = -ENOSPC; + goto out; +@@ -738,9 +763,8 @@ idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) + } + + if (!(im.im_status & IDMAP_STATUS_SUCCESS)) { +- ret = mlen; +- complete_request_key(idmap->idmap_key_cons, -ENOKEY); +- goto out_incomplete; ++ ret = -ENOKEY; ++ goto out; + } + + namelen_in = strnlen(im.im_name, IDMAP_NAMESZ); +@@ -756,17 +780,33 @@ idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) + } + + out: +- complete_request_key(idmap->idmap_key_cons, ret); +-out_incomplete: ++ complete_request_key(cons, ret); + return ret; + } + + static void + idmap_pipe_destroy_msg(struct rpc_pipe_msg *msg) + { ++ struct idmap_legacy_upcalldata *data = container_of(msg, ++ struct idmap_legacy_upcalldata, ++ pipe_msg); ++ struct idmap *idmap = data->idmap; ++ struct key_construction *cons; ++ if (msg->errno) { ++ cons = ACCESS_ONCE(idmap->idmap_key_cons); ++ idmap->idmap_key_cons = NULL; ++ complete_request_key(cons, msg->errno); ++ } + /* Free memory allocated in nfs_idmap_legacy_upcall() */ +- kfree(msg->data); +- kfree(msg); ++ kfree(data); ++} ++ ++static void ++idmap_release_pipe(struct inode *inode) ++{ ++ struct rpc_inode *rpci = RPC_I(inode); ++ struct idmap *idmap = (struct idmap *)rpci->private; ++ idmap->idmap_key_cons = NULL; + } + + int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) +diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c +index f729698..30bd45a 100644 +--- a/fs/nfs/inode.c ++++ b/fs/nfs/inode.c +@@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode) + nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); + nfsi->attrtimeo_timestamp = jiffies; + +- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode))); ++ memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf)); + if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) + nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE; + else +diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c +index 2292a0f..fda63e9 100644 +--- a/fs/nfs/nfs3proc.c ++++ b/fs/nfs/nfs3proc.c +@@ -69,7 +69,7 @@ do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle, + nfs_fattr_init(info->fattr); + status = rpc_call_sync(client, &msg, 0); + dprintk("%s: reply fsinfo: %d\n", __func__, status); +- if (!(info->fattr->valid & NFS_ATTR_FATTR)) { ++ if (status == 0 && !(info->fattr->valid & NFS_ATTR_FATTR)) { + msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; + msg.rpc_resp = info->fattr; + status = rpc_call_sync(client, &msg, 0); +@@ -643,7 +643,7 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, + u64 cookie, struct page **pages, unsigned int count, int plus) + { + struct inode *dir = dentry->d_inode; +- __be32 *verf = NFS_COOKIEVERF(dir); ++ __be32 *verf = NFS_I(dir)->cookieverf; + struct nfs3_readdirargs arg = { + .fh = NFS_FH(dir), + .cookie = cookie, +diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c +index 15fc7e4..dd372e2 100644 +--- a/fs/nfs/nfs4proc.c ++++ b/fs/nfs/nfs4proc.c +@@ -3189,11 +3189,11 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, + dentry->d_parent->d_name.name, + dentry->d_name.name, + (unsigned long long)cookie); +- nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); ++ nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); + res.pgbase = args.pgbase; + status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); + if (status >= 0) { +- memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); ++ memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); + status += args.pgbase; + } + +@@ -6164,11 +6164,58 @@ static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) + dprintk("<-- %s\n", __func__); + } + ++static size_t max_response_pages(struct nfs_server *server) ++{ ++ u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; ++ return nfs_page_array_len(0, max_resp_sz); ++} ++ ++static void nfs4_free_pages(struct page **pages, size_t size) ++{ ++ int i; ++ ++ if (!pages) ++ return; ++ ++ for (i = 0; i < size; i++) { ++ if (!pages[i]) ++ break; ++ __free_page(pages[i]); ++ } ++ kfree(pages); ++} ++ ++static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) ++{ ++ struct page **pages; ++ int i; ++ ++ pages = kcalloc(size, sizeof(struct page *), gfp_flags); ++ if (!pages) { ++ dprintk("%s: can't alloc array of %zu pages\n", __func__, size); ++ return NULL; ++ } ++ ++ for (i = 0; i < size; i++) { ++ pages[i] = alloc_page(gfp_flags); ++ if (!pages[i]) { ++ dprintk("%s: failed to allocate page\n", __func__); ++ nfs4_free_pages(pages, size); ++ return NULL; ++ } ++ } ++ ++ return pages; ++} ++ + static void nfs4_layoutget_release(void *calldata) + { + struct nfs4_layoutget *lgp = calldata; ++ struct nfs_server *server = NFS_SERVER(lgp->args.inode); ++ size_t max_pages = max_response_pages(server); + + dprintk("--> %s\n", __func__); ++ nfs4_free_pages(lgp->args.layout.pages, max_pages); + put_nfs_open_context(lgp->args.ctx); + kfree(calldata); + dprintk("<-- %s\n", __func__); +@@ -6180,9 +6227,10 @@ static const struct rpc_call_ops nfs4_layoutget_call_ops = { + .rpc_release = nfs4_layoutget_release, + }; + +-int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) ++int nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) + { + struct nfs_server *server = NFS_SERVER(lgp->args.inode); ++ size_t max_pages = max_response_pages(server); + struct rpc_task *task; + struct rpc_message msg = { + .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], +@@ -6200,6 +6248,13 @@ int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) + + dprintk("--> %s\n", __func__); + ++ lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); ++ if (!lgp->args.layout.pages) { ++ nfs4_layoutget_release(lgp); ++ return -ENOMEM; ++ } ++ lgp->args.layout.pglen = max_pages * PAGE_SIZE; ++ + lgp->res.layoutp = &lgp->args.layout; + lgp->res.seq_res.sr_slot = NULL; + nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); +@@ -6245,12 +6300,8 @@ static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) + return; + } + spin_lock(&lo->plh_inode->i_lock); +- if (task->tk_status == 0) { +- if (lrp->res.lrs_present) { +- pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); +- } else +- BUG_ON(!list_empty(&lo->plh_segs)); +- } ++ if (task->tk_status == 0 && lrp->res.lrs_present) ++ pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); + lo->plh_block_lgets--; + spin_unlock(&lo->plh_inode->i_lock); + dprintk("<-- %s\n", __func__); +diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c +index 18fae29..cfce99b 100644 +--- a/fs/nfs/nfs4xdr.c ++++ b/fs/nfs/nfs4xdr.c +@@ -6262,7 +6262,8 @@ static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, + status = decode_open(xdr, res); + if (status) + goto out; +- if (decode_getfh(xdr, &res->fh) != 0) ++ status = decode_getfh(xdr, &res->fh); ++ if (status) + goto out; + decode_getfattr(xdr, res->f_attr, res->server); + out: +diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c +index bbc49ca..8229a0e 100644 +--- a/fs/nfs/pnfs.c ++++ b/fs/nfs/pnfs.c +@@ -583,9 +583,6 @@ send_layoutget(struct pnfs_layout_hdr *lo, + struct nfs_server *server = NFS_SERVER(ino); + struct nfs4_layoutget *lgp; + struct pnfs_layout_segment *lseg = NULL; +- struct page **pages = NULL; +- int i; +- u32 max_resp_sz, max_pages; + + dprintk("--> %s\n", __func__); + +@@ -594,20 +591,6 @@ send_layoutget(struct pnfs_layout_hdr *lo, + if (lgp == NULL) + return NULL; + +- /* allocate pages for xdr post processing */ +- max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; +- max_pages = nfs_page_array_len(0, max_resp_sz); +- +- pages = kcalloc(max_pages, sizeof(struct page *), gfp_flags); +- if (!pages) +- goto out_err_free; +- +- for (i = 0; i < max_pages; i++) { +- pages[i] = alloc_page(gfp_flags); +- if (!pages[i]) +- goto out_err_free; +- } +- + lgp->args.minlength = PAGE_CACHE_SIZE; + if (lgp->args.minlength > range->length) + lgp->args.minlength = range->length; +@@ -616,39 +599,19 @@ send_layoutget(struct pnfs_layout_hdr *lo, + lgp->args.type = server->pnfs_curr_ld->id; + lgp->args.inode = ino; + lgp->args.ctx = get_nfs_open_context(ctx); +- lgp->args.layout.pages = pages; +- lgp->args.layout.pglen = max_pages * PAGE_SIZE; + lgp->lsegpp = &lseg; + lgp->gfp_flags = gfp_flags; + + /* Synchronously retrieve layout information from server and + * store in lseg. + */ +- nfs4_proc_layoutget(lgp); ++ nfs4_proc_layoutget(lgp, gfp_flags); + if (!lseg) { + /* remember that LAYOUTGET failed and suspend trying */ + set_bit(lo_fail_bit(range->iomode), &lo->plh_flags); + } + +- /* free xdr pages */ +- for (i = 0; i < max_pages; i++) +- __free_page(pages[i]); +- kfree(pages); +- + return lseg; +- +-out_err_free: +- /* free any allocated xdr pages, lgp as it's not used */ +- if (pages) { +- for (i = 0; i < max_pages; i++) { +- if (!pages[i]) +- break; +- __free_page(pages[i]); +- } +- kfree(pages); +- } +- kfree(lgp); +- return NULL; + } + + /* Initiates a LAYOUTRETURN(FILE) */ +diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h +index 64f90d8..9a31ff3 100644 +--- a/fs/nfs/pnfs.h ++++ b/fs/nfs/pnfs.h +@@ -171,7 +171,7 @@ extern int nfs4_proc_getdevicelist(struct nfs_server *server, + struct pnfs_devicelist *devlist); + extern int nfs4_proc_getdeviceinfo(struct nfs_server *server, + struct pnfs_device *dev); +-extern int nfs4_proc_layoutget(struct nfs4_layoutget *lgp); ++extern int nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags); + extern int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp); + + /* pnfs.c */ +diff --git a/fs/nfs/super.c b/fs/nfs/super.c +index 0622819..cdbaae2 100644 +--- a/fs/nfs/super.c ++++ b/fs/nfs/super.c +@@ -1918,6 +1918,7 @@ static int nfs23_validate_mount_data(void *options, + + memcpy(sap, &data->addr, sizeof(data->addr)); + args->nfs_server.addrlen = sizeof(data->addr); ++ args->nfs_server.port = ntohs(data->addr.sin_port); + if (!nfs_verify_server_address(sap)) + goto out_no_address; + +@@ -2651,6 +2652,7 @@ static int nfs4_validate_mount_data(void *options, + return -EFAULT; + if (!nfs_verify_server_address(sap)) + goto out_no_address; ++ args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port); + + if (data->auth_flavourlen) { + if (data->auth_flavourlen > 1) +@@ -2961,4 +2963,6 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type, + return res; + } + ++MODULE_ALIAS("nfs4"); ++ + #endif /* CONFIG_NFS_V4 */ +diff --git a/fs/nfs/write.c b/fs/nfs/write.c +index 4d6861c..c11d7cf 100644 +--- a/fs/nfs/write.c ++++ b/fs/nfs/write.c +@@ -1806,19 +1806,19 @@ int __init nfs_init_writepagecache(void) + nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE, + nfs_wdata_cachep); + if (nfs_wdata_mempool == NULL) +- return -ENOMEM; ++ goto out_destroy_write_cache; + + nfs_cdata_cachep = kmem_cache_create("nfs_commit_data", + sizeof(struct nfs_commit_data), + 0, SLAB_HWCACHE_ALIGN, + NULL); + if (nfs_cdata_cachep == NULL) +- return -ENOMEM; ++ goto out_destroy_write_mempool; + + nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT, + nfs_wdata_cachep); + if (nfs_commit_mempool == NULL) +- return -ENOMEM; ++ goto out_destroy_commit_cache; + + /* + * NFS congestion size, scale with available memory. +@@ -1841,11 +1841,20 @@ int __init nfs_init_writepagecache(void) + nfs_congestion_kb = 256*1024; + + return 0; ++ ++out_destroy_commit_cache: ++ kmem_cache_destroy(nfs_cdata_cachep); ++out_destroy_write_mempool: ++ mempool_destroy(nfs_wdata_mempool); ++out_destroy_write_cache: ++ kmem_cache_destroy(nfs_wdata_cachep); ++ return -ENOMEM; + } + + void nfs_destroy_writepagecache(void) + { + mempool_destroy(nfs_commit_mempool); ++ kmem_cache_destroy(nfs_cdata_cachep); + mempool_destroy(nfs_wdata_mempool); + kmem_cache_destroy(nfs_wdata_cachep); + } +diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c +index a5fd6b9..f19145b 100644 +--- a/fs/nfsd/nfs4callback.c ++++ b/fs/nfsd/nfs4callback.c +@@ -651,12 +651,12 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *c + + if (clp->cl_minorversion == 0) { + if (!clp->cl_cred.cr_principal && +- (clp->cl_flavor >= RPC_AUTH_GSS_KRB5)) ++ (clp->cl_cred.cr_flavor >= RPC_AUTH_GSS_KRB5)) + return -EINVAL; + args.client_name = clp->cl_cred.cr_principal; + args.prognumber = conn->cb_prog, + args.protocol = XPRT_TRANSPORT_TCP; +- args.authflavor = clp->cl_flavor; ++ args.authflavor = clp->cl_cred.cr_flavor; + clp->cl_cb_ident = conn->cb_ident; + } else { + if (!conn->cb_xprt) +diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c +index 94effd5..e8ead04 100644 +--- a/fs/nfsd/nfs4state.c ++++ b/fs/nfsd/nfs4state.c +@@ -1215,7 +1215,7 @@ static bool groups_equal(struct group_info *g1, struct group_info *g2) + return true; + } + +-static int ++static bool + same_creds(struct svc_cred *cr1, struct svc_cred *cr2) + { + if ((cr1->cr_flavor != cr2->cr_flavor) +@@ -1227,7 +1227,7 @@ same_creds(struct svc_cred *cr1, struct svc_cred *cr2) + return true; + if (!cr1->cr_principal || !cr2->cr_principal) + return false; +- return 0 == strcmp(cr1->cr_principal, cr1->cr_principal); ++ return 0 == strcmp(cr1->cr_principal, cr2->cr_principal); + } + + static void gen_clid(struct nfs4_client *clp) +diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c +index 4949667..6322df3 100644 +--- a/fs/nfsd/nfs4xdr.c ++++ b/fs/nfsd/nfs4xdr.c +@@ -2259,7 +2259,7 @@ out_acl: + 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 --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c +index c55298e..fa49cff 100644 +--- a/fs/nfsd/nfsctl.c ++++ b/fs/nfsd/nfsctl.c +@@ -673,9 +673,7 @@ static ssize_t __write_ports_addfd(char *buf) + + err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT); + if (err < 0) { +- if (nfsd_serv->sv_nrthreads == 1) +- svc_shutdown_net(nfsd_serv, net); +- svc_destroy(nfsd_serv); ++ nfsd_destroy(net); + return err; + } + +@@ -744,9 +742,7 @@ out_close: + svc_xprt_put(xprt); + } + out_err: +- if (nfsd_serv->sv_nrthreads == 1) +- svc_shutdown_net(nfsd_serv, net); +- svc_destroy(nfsd_serv); ++ nfsd_destroy(net); + return err; + } + +diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h +index 1671429..1336a65 100644 +--- a/fs/nfsd/nfsd.h ++++ b/fs/nfsd/nfsd.h +@@ -73,6 +73,17 @@ int nfsd_nrpools(void); + int nfsd_get_nrthreads(int n, int *); + int nfsd_set_nrthreads(int n, int *); + ++static inline void nfsd_destroy(struct net *net) ++{ ++ int destroy = (nfsd_serv->sv_nrthreads == 1); ++ ++ if (destroy) ++ svc_shutdown_net(nfsd_serv, net); ++ svc_destroy(nfsd_serv); ++ if (destroy) ++ nfsd_serv = NULL; ++} ++ + #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) + #ifdef CONFIG_NFSD_V2_ACL + extern struct svc_version nfsd_acl_version2; +diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c +index ee709fc..240473c 100644 +--- a/fs/nfsd/nfssvc.c ++++ b/fs/nfsd/nfssvc.c +@@ -254,8 +254,6 @@ static void nfsd_shutdown(void) + + static void nfsd_last_thread(struct svc_serv *serv, struct net *net) + { +- /* When last nfsd thread exits we need to do some clean-up */ +- nfsd_serv = NULL; + nfsd_shutdown(); + + svc_rpcb_cleanup(serv, net); +@@ -332,6 +330,7 @@ static int nfsd_get_default_max_blksize(void) + int nfsd_create_serv(void) + { + int error; ++ struct net *net = current->nsproxy->net_ns; + + WARN_ON(!mutex_is_locked(&nfsd_mutex)); + if (nfsd_serv) { +@@ -346,7 +345,7 @@ int nfsd_create_serv(void) + if (nfsd_serv == NULL) + return -ENOMEM; + +- error = svc_bind(nfsd_serv, current->nsproxy->net_ns); ++ error = svc_bind(nfsd_serv, net); + if (error < 0) { + svc_destroy(nfsd_serv); + return error; +@@ -427,11 +426,7 @@ int nfsd_set_nrthreads(int n, int *nthreads) + if (err) + break; + } +- +- if (nfsd_serv->sv_nrthreads == 1) +- svc_shutdown_net(nfsd_serv, net); +- svc_destroy(nfsd_serv); +- ++ nfsd_destroy(net); + return err; + } + +@@ -478,9 +473,7 @@ out_shutdown: + if (error < 0 && !nfsd_up_before) + nfsd_shutdown(); + out_destroy: +- if (nfsd_serv->sv_nrthreads == 1) +- svc_shutdown_net(nfsd_serv, net); +- svc_destroy(nfsd_serv); /* Release server */ ++ nfsd_destroy(net); /* Release server */ + out: + mutex_unlock(&nfsd_mutex); + return error; +@@ -563,12 +556,13 @@ nfsd(void *vrqstp) + nfsdstats.th_cnt --; + + out: +- if (rqstp->rq_server->sv_nrthreads == 1) +- svc_shutdown_net(rqstp->rq_server, &init_net); ++ rqstp->rq_server = NULL; + + /* Release the thread */ + svc_exit_thread(rqstp); + ++ nfsd_destroy(&init_net); ++ + /* Release module */ + mutex_unlock(&nfsd_mutex); + module_put_and_exit(0); +@@ -682,9 +676,7 @@ int nfsd_pool_stats_release(struct inode *inode, struct file *file) + + mutex_lock(&nfsd_mutex); + /* this function really, really should have been called svc_put() */ +- if (nfsd_serv->sv_nrthreads == 1) +- svc_shutdown_net(nfsd_serv, net); +- svc_destroy(nfsd_serv); ++ nfsd_destroy(net); + mutex_unlock(&nfsd_mutex); + return ret; + } +diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h +index 849091e..0e220b8 100644 +--- a/fs/nfsd/state.h ++++ b/fs/nfsd/state.h +@@ -231,7 +231,6 @@ struct nfs4_client { + nfs4_verifier cl_verifier; /* generated by client */ + time_t cl_time; /* time of last lease renewal */ + struct sockaddr_storage cl_addr; /* client ipaddress */ +- u32 cl_flavor; /* setclientid pseudoflavor */ + struct svc_cred cl_cred; /* setclientid principal */ + clientid_t cl_clientid; /* generated by server */ + nfs4_verifier cl_confirm; /* generated by server */ +diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c +index 06658ca..0b6387c 100644 +--- a/fs/nilfs2/ioctl.c ++++ b/fs/nilfs2/ioctl.c +@@ -182,7 +182,7 @@ static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp, + if (copy_from_user(&cpmode, argp, sizeof(cpmode))) + goto out; + +- down_read(&inode->i_sb->s_umount); ++ mutex_lock(&nilfs->ns_snapshot_mount_mutex); + + nilfs_transaction_begin(inode->i_sb, &ti, 0); + ret = nilfs_cpfile_change_cpmode( +@@ -192,7 +192,7 @@ static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp, + else + nilfs_transaction_commit(inode->i_sb); /* never fails */ + +- up_read(&inode->i_sb->s_umount); ++ mutex_unlock(&nilfs->ns_snapshot_mount_mutex); + out: + mnt_drop_write_file(filp); + return ret; +diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c +index 1099a76..496904b 100644 +--- a/fs/nilfs2/super.c ++++ b/fs/nilfs2/super.c +@@ -948,6 +948,8 @@ static int nilfs_attach_snapshot(struct super_block *s, __u64 cno, + struct nilfs_root *root; + int ret; + ++ mutex_lock(&nilfs->ns_snapshot_mount_mutex); ++ + down_read(&nilfs->ns_segctor_sem); + ret = nilfs_cpfile_is_snapshot(nilfs->ns_cpfile, cno); + up_read(&nilfs->ns_segctor_sem); +@@ -972,6 +974,7 @@ static int nilfs_attach_snapshot(struct super_block *s, __u64 cno, + ret = nilfs_get_root_dentry(s, root, root_dentry); + nilfs_put_root(root); + out: ++ mutex_unlock(&nilfs->ns_snapshot_mount_mutex); + return ret; + } + +diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c +index 501b7f8..41e6a04 100644 +--- a/fs/nilfs2/the_nilfs.c ++++ b/fs/nilfs2/the_nilfs.c +@@ -76,6 +76,7 @@ struct the_nilfs *alloc_nilfs(struct block_device *bdev) + nilfs->ns_bdev = bdev; + atomic_set(&nilfs->ns_ndirtyblks, 0); + init_rwsem(&nilfs->ns_sem); ++ mutex_init(&nilfs->ns_snapshot_mount_mutex); + INIT_LIST_HEAD(&nilfs->ns_dirty_files); + INIT_LIST_HEAD(&nilfs->ns_gc_inodes); + spin_lock_init(&nilfs->ns_inode_lock); +diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h +index 9992b11..de7435f 100644 +--- a/fs/nilfs2/the_nilfs.h ++++ b/fs/nilfs2/the_nilfs.h +@@ -47,6 +47,7 @@ enum { + * @ns_flags: flags + * @ns_bdev: block device + * @ns_sem: semaphore for shared states ++ * @ns_snapshot_mount_mutex: mutex to protect snapshot mounts + * @ns_sbh: buffer heads of on-disk super blocks + * @ns_sbp: pointers to super block data + * @ns_sbwtime: previous write time of super block +@@ -99,6 +100,7 @@ struct the_nilfs { + + struct block_device *ns_bdev; + struct rw_semaphore ns_sem; ++ struct mutex ns_snapshot_mount_mutex; + + /* + * used for +diff --git a/fs/open.c b/fs/open.c +index 1540632..5d9c71b 100644 +--- a/fs/open.c ++++ b/fs/open.c +@@ -930,9 +930,10 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o + int lookup_flags = 0; + int acc_mode; + +- if (!(flags & O_CREAT)) +- mode = 0; +- op->mode = mode; ++ if (flags & O_CREAT) ++ op->mode = (mode & S_IALLUGO) | S_IFREG; ++ else ++ op->mode = 0; + + /* Must never be set by userspace */ + flags &= ~FMODE_NONOTIFY; +diff --git a/fs/proc/page.c b/fs/proc/page.c +index 7fcd0d6..b8730d9 100644 +--- a/fs/proc/page.c ++++ b/fs/proc/page.c +@@ -115,7 +115,13 @@ u64 stable_page_flags(struct page *page) + u |= 1 << KPF_COMPOUND_TAIL; + if (PageHuge(page)) + u |= 1 << KPF_HUGE; +- else if (PageTransCompound(page)) ++ /* ++ * PageTransCompound can be true for non-huge compound pages (slab ++ * pages or pages allocated by drivers with __GFP_COMP) because it ++ * just checks PG_head/PG_tail, so we need to check PageLRU to make ++ * sure a given page is a thp, not a non-huge compound page. ++ */ ++ else if (PageTransCompound(page) && PageLRU(compound_trans_head(page))) + u |= 1 << KPF_THP; + + /* +diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c +index 3476bca..5d00eb8 100644 +--- a/fs/proc/proc_sysctl.c ++++ b/fs/proc/proc_sysctl.c +@@ -462,9 +462,6 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, + + err = ERR_PTR(-ENOMEM); + inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p); +- if (h) +- sysctl_head_finish(h); +- + if (!inode) + goto out; + +@@ -473,6 +470,8 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, + d_add(dentry, inode); + + out: ++ if (h) ++ sysctl_head_finish(h); + sysctl_head_finish(head); + return err; + } +diff --git a/fs/select.c b/fs/select.c +index bae3215..db14c78 100644 +--- a/fs/select.c ++++ b/fs/select.c +@@ -345,8 +345,8 @@ static int max_select_fd(unsigned long n, fd_set_bits *fds) + struct fdtable *fdt; + + /* handle last in-complete long-word first */ +- set = ~(~0UL << (n & (__NFDBITS-1))); +- n /= __NFDBITS; ++ set = ~(~0UL << (n & (BITS_PER_LONG-1))); ++ n /= BITS_PER_LONG; + fdt = files_fdtable(current->files); + open_fds = fdt->open_fds + n; + max = 0; +@@ -373,7 +373,7 @@ get_max: + max++; + set >>= 1; + } while (set); +- max += n * __NFDBITS; ++ max += n * BITS_PER_LONG; + } + + return max; +@@ -435,11 +435,11 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time) + in = *inp++; out = *outp++; ex = *exp++; + all_bits = in | out | ex; + if (all_bits == 0) { +- i += __NFDBITS; ++ i += BITS_PER_LONG; + continue; + } + +- for (j = 0; j < __NFDBITS; ++j, ++i, bit <<= 1) { ++ for (j = 0; j < BITS_PER_LONG; ++j, ++i, bit <<= 1) { + int fput_needed; + if (i >= n) + break; +diff --git a/fs/stat.c b/fs/stat.c +index b6ff118..4078022 100644 +--- a/fs/stat.c ++++ b/fs/stat.c +@@ -58,7 +58,7 @@ EXPORT_SYMBOL(vfs_getattr); + int vfs_fstat(unsigned int fd, struct kstat *stat) + { + int fput_needed; +- struct file *f = fget_light(fd, &fput_needed); ++ struct file *f = fget_raw_light(fd, &fput_needed); + int error = -EBADF; + + if (f) { +diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h +index 486a8e0..a850909 100644 +--- a/fs/ubifs/debug.h ++++ b/fs/ubifs/debug.h +@@ -162,7 +162,7 @@ struct ubifs_global_debug_info { + #define ubifs_dbg_msg(type, fmt, ...) \ + pr_debug("UBIFS DBG " type ": " fmt "\n", ##__VA_ARGS__) + +-#define DBG_KEY_BUF_LEN 32 ++#define DBG_KEY_BUF_LEN 48 + #define ubifs_dbg_msg_key(type, key, fmt, ...) do { \ + char __tmp_key_buf[DBG_KEY_BUF_LEN]; \ + pr_debug("UBIFS DBG " type ": " fmt "%s\n", ##__VA_ARGS__, \ +diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c +index ce33b2b..8640920 100644 +--- a/fs/ubifs/lpt.c ++++ b/fs/ubifs/lpt.c +@@ -1749,7 +1749,10 @@ int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr) + return 0; + + out_err: +- ubifs_lpt_free(c, 0); ++ if (wr) ++ ubifs_lpt_free(c, 1); ++ if (rd) ++ ubifs_lpt_free(c, 0); + return err; + } + +diff --git a/fs/udf/file.c b/fs/udf/file.c +index 7f3f7ba..d1c6093 100644 +--- a/fs/udf/file.c ++++ b/fs/udf/file.c +@@ -39,20 +39,24 @@ + #include "udf_i.h" + #include "udf_sb.h" + +-static int udf_adinicb_readpage(struct file *file, struct page *page) ++static void __udf_adinicb_readpage(struct page *page) + { + struct inode *inode = page->mapping->host; + char *kaddr; + struct udf_inode_info *iinfo = UDF_I(inode); + +- BUG_ON(!PageLocked(page)); +- + kaddr = kmap(page); +- memset(kaddr, 0, PAGE_CACHE_SIZE); + memcpy(kaddr, iinfo->i_ext.i_data + iinfo->i_lenEAttr, inode->i_size); ++ memset(kaddr + inode->i_size, 0, PAGE_CACHE_SIZE - inode->i_size); + flush_dcache_page(page); + SetPageUptodate(page); + kunmap(page); ++} ++ ++static int udf_adinicb_readpage(struct file *file, struct page *page) ++{ ++ BUG_ON(!PageLocked(page)); ++ __udf_adinicb_readpage(page); + unlock_page(page); + + return 0; +@@ -77,6 +81,25 @@ static int udf_adinicb_writepage(struct page *page, + return 0; + } + ++static int udf_adinicb_write_begin(struct file *file, ++ struct address_space *mapping, loff_t pos, ++ unsigned len, unsigned flags, struct page **pagep, ++ void **fsdata) ++{ ++ struct page *page; ++ ++ if (WARN_ON_ONCE(pos >= PAGE_CACHE_SIZE)) ++ return -EIO; ++ page = grab_cache_page_write_begin(mapping, 0, flags); ++ if (!page) ++ return -ENOMEM; ++ *pagep = page; ++ ++ if (!PageUptodate(page) && len != PAGE_CACHE_SIZE) ++ __udf_adinicb_readpage(page); ++ return 0; ++} ++ + static int udf_adinicb_write_end(struct file *file, + struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, +@@ -98,8 +121,8 @@ static int udf_adinicb_write_end(struct file *file, + const struct address_space_operations udf_adinicb_aops = { + .readpage = udf_adinicb_readpage, + .writepage = udf_adinicb_writepage, +- .write_begin = simple_write_begin, +- .write_end = udf_adinicb_write_end, ++ .write_begin = udf_adinicb_write_begin, ++ .write_end = udf_adinicb_write_end, + }; + + static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, +diff --git a/fs/udf/super.c b/fs/udf/super.c +index 8d86a87..e660ffd 100644 +--- a/fs/udf/super.c ++++ b/fs/udf/super.c +@@ -1283,7 +1283,7 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block, + BUG_ON(ident != TAG_IDENT_LVD); + lvd = (struct logicalVolDesc *)bh->b_data; + table_len = le32_to_cpu(lvd->mapTableLength); +- if (sizeof(*lvd) + table_len > sb->s_blocksize) { ++ if (table_len > sb->s_blocksize - sizeof(*lvd)) { + udf_err(sb, "error loading logical volume descriptor: " + "Partition table too long (%u > %lu)\n", table_len, + sb->s_blocksize - sizeof(*lvd)); +diff --git a/include/asm-generic/mutex-xchg.h b/include/asm-generic/mutex-xchg.h +index 580a6d3..c04e0db 100644 +--- a/include/asm-generic/mutex-xchg.h ++++ b/include/asm-generic/mutex-xchg.h +@@ -26,7 +26,13 @@ static inline void + __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *)) + { + if (unlikely(atomic_xchg(count, 0) != 1)) +- fail_fn(count); ++ /* ++ * We failed to acquire the lock, so mark it contended ++ * to ensure that any waiting tasks are woken up by the ++ * unlock slow path. ++ */ ++ if (likely(atomic_xchg(count, -1) != 1)) ++ fail_fn(count); + } + + /** +@@ -43,7 +49,8 @@ static inline int + __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) + { + if (unlikely(atomic_xchg(count, 0) != 1)) +- return fail_fn(count); ++ if (likely(atomic_xchg(count, -1) != 1)) ++ return fail_fn(count); + return 0; + } + +diff --git a/include/drm/drm_mode.h b/include/drm/drm_mode.h +index 5581980..3d6301b 100644 +--- a/include/drm/drm_mode.h ++++ b/include/drm/drm_mode.h +@@ -359,8 +359,9 @@ struct drm_mode_mode_cmd { + struct drm_mode_modeinfo mode; + }; + +-#define DRM_MODE_CURSOR_BO (1<<0) +-#define DRM_MODE_CURSOR_MOVE (1<<1) ++#define DRM_MODE_CURSOR_BO 0x01 ++#define DRM_MODE_CURSOR_MOVE 0x02 ++#define DRM_MODE_CURSOR_FLAGS 0x03 + + /* + * depending on the value in flags different members are used. +diff --git a/include/drm/drm_pciids.h b/include/drm/drm_pciids.h +index a7aec39..bae1d11 100644 +--- a/include/drm/drm_pciids.h ++++ b/include/drm/drm_pciids.h +@@ -213,9 +213,12 @@ + {0x1002, 0x6800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x6801, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x6802, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x6806, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x6808, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x6809, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x6810, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x6816, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x6817, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x6818, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x6819, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x6820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ +diff --git a/include/linux/cpu.h b/include/linux/cpu.h +index 2e9b9eb..ce7a074 100644 +--- a/include/linux/cpu.h ++++ b/include/linux/cpu.h +@@ -73,8 +73,9 @@ enum { + /* 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, + }; + + #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */ +diff --git a/include/linux/dcache.h b/include/linux/dcache.h +index 094789f..525ab12 100644 +--- a/include/linux/dcache.h ++++ b/include/linux/dcache.h +@@ -206,6 +206,8 @@ struct dentry_operations { + #define DCACHE_MANAGED_DENTRY \ + (DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT) + ++#define DCACHE_DENTRY_KILLED 0x100000 ++ + extern seqlock_t rename_lock; + + static inline int dname_external(struct dentry *dentry) +diff --git a/include/linux/init_task.h b/include/linux/init_task.h +index 9e65eff..b806b82 100644 +--- a/include/linux/init_task.h ++++ b/include/linux/init_task.h +@@ -123,8 +123,17 @@ extern struct group_info init_groups; + + extern struct cred init_cred; + ++extern struct task_group root_task_group; ++ ++#ifdef CONFIG_CGROUP_SCHED ++# define INIT_CGROUP_SCHED(tsk) \ ++ .sched_task_group = &root_task_group, ++#else ++# define INIT_CGROUP_SCHED(tsk) ++#endif ++ + #ifdef CONFIG_PERF_EVENTS +-# define INIT_PERF_EVENTS(tsk) \ ++# define INIT_PERF_EVENTS(tsk) \ + .perf_event_mutex = \ + __MUTEX_INITIALIZER(tsk.perf_event_mutex), \ + .perf_event_list = LIST_HEAD_INIT(tsk.perf_event_list), +@@ -161,6 +170,7 @@ extern struct cred init_cred; + }, \ + .tasks = LIST_HEAD_INIT(tsk.tasks), \ + INIT_PUSHABLE_TASKS(tsk) \ ++ INIT_CGROUP_SCHED(tsk) \ + .ptraced = LIST_HEAD_INIT(tsk.ptraced), \ + .ptrace_entry = LIST_HEAD_INIT(tsk.ptrace_entry), \ + .real_parent = &tsk, \ +diff --git a/include/linux/input/eeti_ts.h b/include/linux/input/eeti_ts.h +index f875b31..16625d7 100644 +--- a/include/linux/input/eeti_ts.h ++++ b/include/linux/input/eeti_ts.h +@@ -2,6 +2,7 @@ + #define LINUX_INPUT_EETI_TS_H + + struct eeti_ts_platform_data { ++ int irq_gpio; + unsigned int irq_active_high; + }; + +diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h +index f1e2527..9a323d1 100644 +--- a/include/linux/irqdesc.h ++++ b/include/linux/irqdesc.h +@@ -39,7 +39,6 @@ struct module; + */ + struct irq_desc { + struct irq_data irq_data; +- struct timer_rand_state *timer_rand_state; + unsigned int __percpu *kstat_irqs; + irq_flow_handler_t handle_irq; + #ifdef CONFIG_IRQ_PREFLOW_FASTEOI +diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h +index f334c7f..3efc43f 100644 +--- a/include/linux/jbd2.h ++++ b/include/linux/jbd2.h +@@ -1125,6 +1125,7 @@ extern int jbd2_journal_destroy (journal_t *); + extern int jbd2_journal_recover (journal_t *journal); + extern int jbd2_journal_wipe (journal_t *, int); + extern int jbd2_journal_skip_recovery (journal_t *); ++extern void jbd2_journal_update_sb_errno(journal_t *); + extern void jbd2_journal_update_sb_log_tail (journal_t *, tid_t, + unsigned long, int); + extern void __jbd2_journal_abort_hard (journal_t *); +diff --git a/include/linux/kobject.h b/include/linux/kobject.h +index fc615a9..1e57449 100644 +--- a/include/linux/kobject.h ++++ b/include/linux/kobject.h +@@ -224,7 +224,7 @@ static inline int kobject_uevent_env(struct kobject *kobj, + + static inline __printf(2, 3) + int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) +-{ return 0; } ++{ return -ENOMEM; } + + static inline int kobject_action_type(const char *buf, size_t count, + enum kobject_action *type) +diff --git a/include/linux/kthread.h b/include/linux/kthread.h +index 0714b24..22ccf9d 100644 +--- a/include/linux/kthread.h ++++ b/include/linux/kthread.h +@@ -49,8 +49,6 @@ extern int tsk_fork_get_node(struct task_struct *tsk); + * can be queued and flushed using queue/flush_kthread_work() + * respectively. Queued kthread_works are processed by a kthread + * running kthread_worker_fn(). +- * +- * A kthread_work can't be freed while it is executing. + */ + struct kthread_work; + typedef void (*kthread_work_func_t)(struct kthread_work *work); +@@ -59,15 +57,14 @@ struct kthread_worker { + spinlock_t lock; + struct list_head work_list; + struct task_struct *task; ++ struct kthread_work *current_work; + }; + + struct kthread_work { + struct list_head node; + kthread_work_func_t func; + wait_queue_head_t done; +- atomic_t flushing; +- int queue_seq; +- int done_seq; ++ struct kthread_worker *worker; + }; + + #define KTHREAD_WORKER_INIT(worker) { \ +@@ -79,7 +76,6 @@ struct kthread_work { + .node = LIST_HEAD_INIT((work).node), \ + .func = (fn), \ + .done = __WAIT_QUEUE_HEAD_INITIALIZER((work).done), \ +- .flushing = ATOMIC_INIT(0), \ + } + + #define DEFINE_KTHREAD_WORKER(worker) \ +diff --git a/include/linux/ktime.h b/include/linux/ktime.h +index 603bec2..06177ba10 100644 +--- a/include/linux/ktime.h ++++ b/include/linux/ktime.h +@@ -58,13 +58,6 @@ union ktime { + + typedef union ktime ktime_t; /* Kill this */ + +-#define KTIME_MAX ((s64)~((u64)1 << 63)) +-#if (BITS_PER_LONG == 64) +-# define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) +-#else +-# define KTIME_SEC_MAX LONG_MAX +-#endif +- + /* + * ktime_t definitions when using the 64-bit scalar representation: + */ +diff --git a/include/linux/mISDNhw.h b/include/linux/mISDNhw.h +index d0752ec..9d96d5d 100644 +--- a/include/linux/mISDNhw.h ++++ b/include/linux/mISDNhw.h +@@ -183,7 +183,7 @@ extern int mISDN_initbchannel(struct bchannel *, unsigned short, + unsigned short); + extern int mISDN_freedchannel(struct dchannel *); + extern void mISDN_clear_bchannel(struct bchannel *); +-extern int mISDN_freebchannel(struct bchannel *); ++extern void mISDN_freebchannel(struct bchannel *); + extern int mISDN_ctrl_bchannel(struct bchannel *, struct mISDN_ctrl_req *); + extern void queue_ch_frame(struct mISDNchannel *, u_int, + int, struct sk_buff *); +diff --git a/include/linux/memory.h b/include/linux/memory.h +index 1ac7f6e..ff9a9f8 100644 +--- a/include/linux/memory.h ++++ b/include/linux/memory.h +@@ -19,7 +19,7 @@ + #include + #include + +-#define MIN_MEMORY_BLOCK_SIZE (1 << SECTION_SIZE_BITS) ++#define MIN_MEMORY_BLOCK_SIZE (1UL << SECTION_SIZE_BITS) + + struct memory_block { + unsigned long start_section_nr; +diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h +index 4aa4273..c252970 100644 +--- a/include/linux/mempolicy.h ++++ b/include/linux/mempolicy.h +@@ -188,7 +188,7 @@ struct sp_node { + + struct shared_policy { + struct rb_root root; +- spinlock_t lock; ++ struct mutex mutex; + }; + + void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol); +diff --git a/include/linux/mfd/ezx-pcap.h b/include/linux/mfd/ezx-pcap.h +index 40c37216..32a1b5c 100644 +--- a/include/linux/mfd/ezx-pcap.h ++++ b/include/linux/mfd/ezx-pcap.h +@@ -16,6 +16,7 @@ struct pcap_subdev { + struct pcap_platform_data { + unsigned int irq_base; + unsigned int config; ++ int gpio; + void (*init) (void *); /* board specific init */ + int num_subdevs; + struct pcap_subdev *subdevs; +diff --git a/include/linux/mm.h b/include/linux/mm.h +index b36d08c..f9f279c 100644 +--- a/include/linux/mm.h ++++ b/include/linux/mm.h +@@ -1591,6 +1591,7 @@ void vmemmap_populate_print_last(void); + enum mf_flags { + MF_COUNT_INCREASED = 1 << 0, + MF_ACTION_REQUIRED = 1 << 1, ++ MF_MUST_KILL = 1 << 2, + }; + extern int memory_failure(unsigned long pfn, int trapno, int flags); + extern void memory_failure_queue(unsigned long pfn, int trapno, int flags); +diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h +index d76513b..2bd1769 100644 +--- a/include/linux/mmc/card.h ++++ b/include/linux/mmc/card.h +@@ -238,6 +238,7 @@ struct mmc_card { + #define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */ + #define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8) /* Avoid sending 512 bytes in */ + #define MMC_QUIRK_LONG_READ_TIME (1<<9) /* Data read time > CSD says */ ++#define MMC_QUIRK_SEC_ERASE_TRIM_BROKEN (1<<10) /* Skip secure for erase/trim */ + /* byte mode */ + unsigned int poweroff_notify_state; /* eMMC4.5 notify feature */ + #define MMC_NO_POWER_NOTIFICATION 0 +diff --git a/include/linux/net.h b/include/linux/net.h +index e9ac2df..dc95700 100644 +--- a/include/linux/net.h ++++ b/include/linux/net.h +@@ -72,6 +72,7 @@ struct net; + #define SOCK_NOSPACE 2 + #define SOCK_PASSCRED 3 + #define SOCK_PASSSEC 4 ++#define SOCK_EXTERNALLY_ALLOCATED 5 + + #ifndef ARCH_HAS_SOCKET_TYPES + /** +diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h +index d94cb14..b52070a 100644 +--- a/include/linux/netdevice.h ++++ b/include/linux/netdevice.h +@@ -1301,6 +1301,8 @@ struct net_device { + /* for setting kernel sock attribute on TCP connection setup */ + #define GSO_MAX_SIZE 65536 + unsigned int gso_max_size; ++#define GSO_MAX_SEGS 65535 ++ u16 gso_max_segs; + + #ifdef CONFIG_DCB + /* Data Center Bridging netlink ops */ +@@ -1518,6 +1520,8 @@ struct packet_type { + struct sk_buff **(*gro_receive)(struct sk_buff **head, + struct sk_buff *skb); + int (*gro_complete)(struct sk_buff *skb); ++ bool (*id_match)(struct packet_type *ptype, ++ struct sock *sk); + void *af_packet_priv; + struct list_head list; + }; +diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h +index b23cfc1..4841108 100644 +--- a/include/linux/nfs_fs.h ++++ b/include/linux/nfs_fs.h +@@ -265,11 +265,6 @@ static inline const struct nfs_rpc_ops *NFS_PROTO(const struct inode *inode) + return NFS_SERVER(inode)->nfs_client->rpc_ops; + } + +-static inline __be32 *NFS_COOKIEVERF(const struct inode *inode) +-{ +- return NFS_I(inode)->cookieverf; +-} +- + static inline unsigned NFS_MINATTRTIMEO(const struct inode *inode) + { + struct nfs_server *nfss = NFS_SERVER(inode); +diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h +index ab741b0..c71eea2 100644 +--- a/include/linux/pci_ids.h ++++ b/include/linux/pci_ids.h +@@ -1846,7 +1846,6 @@ + #define PCI_DEVICE_ID_SIIG_8S_20x_650 0x2081 + #define PCI_DEVICE_ID_SIIG_8S_20x_850 0x2082 + #define PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL 0x2050 +-#define PCI_SUBDEVICE_ID_SIIG_DUAL_SERIAL 0x2530 + + #define PCI_VENDOR_ID_RADISYS 0x1331 + +@@ -2148,7 +2147,7 @@ + #define PCI_DEVICE_ID_TIGON3_5704S 0x16a8 + #define PCI_DEVICE_ID_NX2_57800_VF 0x16a9 + #define PCI_DEVICE_ID_NX2_5706S 0x16aa +-#define PCI_DEVICE_ID_NX2_57840_MF 0x16ab ++#define PCI_DEVICE_ID_NX2_57840_MF 0x16a4 + #define PCI_DEVICE_ID_NX2_5708S 0x16ac + #define PCI_DEVICE_ID_NX2_57840_VF 0x16ad + #define PCI_DEVICE_ID_NX2_57810_MF 0x16ae +diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h +index 45db49f..c3c98a6 100644 +--- a/include/linux/perf_event.h ++++ b/include/linux/perf_event.h +@@ -274,6 +274,8 @@ struct perf_event_attr { + __u64 branch_sample_type; /* enum branch_sample_type */ + }; + ++#define perf_flags(attr) (*(&(attr)->read_format + 1)) ++ + /* + * Ioctls that can be done on a perf event fd: + */ +@@ -925,7 +927,7 @@ struct perf_event { + struct hw_perf_event hw; + + struct perf_event_context *ctx; +- struct file *filp; ++ atomic_long_t refcount; + + /* + * These accumulate total time (in nanoseconds) that children +diff --git a/include/linux/posix_types.h b/include/linux/posix_types.h +index f04c98c..988f76e 100644 +--- a/include/linux/posix_types.h ++++ b/include/linux/posix_types.h +@@ -15,26 +15,14 @@ + */ + + /* +- * Those macros may have been defined in . But we always +- * use the ones here. ++ * This macro may have been defined in . But we always ++ * use the one here. + */ +-#undef __NFDBITS +-#define __NFDBITS (8 * sizeof(unsigned long)) +- + #undef __FD_SETSIZE + #define __FD_SETSIZE 1024 + +-#undef __FDSET_LONGS +-#define __FDSET_LONGS (__FD_SETSIZE/__NFDBITS) +- +-#undef __FDELT +-#define __FDELT(d) ((d) / __NFDBITS) +- +-#undef __FDMASK +-#define __FDMASK(d) (1UL << ((d) % __NFDBITS)) +- + typedef struct { +- unsigned long fds_bits [__FDSET_LONGS]; ++ unsigned long fds_bits[__FD_SETSIZE / (8 * sizeof(long))]; + } __kernel_fd_set; + + /* Type of a signal handler. */ +diff --git a/include/linux/random.h b/include/linux/random.h +index 8f74538..ac621ce 100644 +--- a/include/linux/random.h ++++ b/include/linux/random.h +@@ -48,13 +48,13 @@ struct rnd_state { + + #ifdef __KERNEL__ + +-extern void rand_initialize_irq(int irq); +- ++extern void add_device_randomness(const void *, unsigned int); + extern void add_input_randomness(unsigned int type, unsigned int code, + unsigned int value); +-extern void add_interrupt_randomness(int irq); ++extern void add_interrupt_randomness(int irq, int irq_flags); + + extern void get_random_bytes(void *buf, int nbytes); ++extern void get_random_bytes_arch(void *buf, int nbytes); + void generate_random_uuid(unsigned char uuid_out[16]); + + #ifndef MODULE +diff --git a/include/linux/sched.h b/include/linux/sched.h +index 4a1f493..e63650f 100644 +--- a/include/linux/sched.h ++++ b/include/linux/sched.h +@@ -1244,6 +1244,9 @@ struct task_struct { + const struct sched_class *sched_class; + struct sched_entity se; + struct sched_rt_entity rt; ++#ifdef CONFIG_CGROUP_SCHED ++ struct task_group *sched_task_group; ++#endif + + #ifdef CONFIG_PREEMPT_NOTIFIERS + /* list of struct preempt_notifier: */ +@@ -2723,7 +2726,7 @@ extern int sched_group_set_rt_period(struct task_group *tg, + extern long sched_group_rt_period(struct task_group *tg); + extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk); + #endif +-#endif ++#endif /* CONFIG_CGROUP_SCHED */ + + extern int task_can_switch_user(struct user_struct *up, + struct task_struct *tsk); +diff --git a/include/linux/security.h b/include/linux/security.h +index 4e5a73c..d143b8e 100644 +--- a/include/linux/security.h ++++ b/include/linux/security.h +@@ -118,6 +118,7 @@ void reset_security_ops(void); + extern unsigned long mmap_min_addr; + extern unsigned long dac_mmap_min_addr; + #else ++#define mmap_min_addr 0UL + #define dac_mmap_min_addr 0UL + #endif + +@@ -1242,8 +1243,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) + * Check that the @parent process has sufficient permission to trace the + * current process before allowing the current process to present itself + * to the @parent process for tracing. +- * The parent process will still have to undergo the ptrace_access_check +- * checks before it is allowed to trace this one. + * @parent contains the task_struct structure for debugger process. + * Return 0 if permission is granted. + * @capget: +diff --git a/include/linux/time.h b/include/linux/time.h +index 179f4d67..b51e664 100644 +--- a/include/linux/time.h ++++ b/include/linux/time.h +@@ -107,11 +107,36 @@ static inline struct timespec timespec_sub(struct timespec lhs, + return ts_delta; + } + ++#define KTIME_MAX ((s64)~((u64)1 << 63)) ++#if (BITS_PER_LONG == 64) ++# define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) ++#else ++# define KTIME_SEC_MAX LONG_MAX ++#endif ++ + /* + * Returns true if the timespec is norm, false if denorm: + */ +-#define timespec_valid(ts) \ +- (((ts)->tv_sec >= 0) && (((unsigned long) (ts)->tv_nsec) < NSEC_PER_SEC)) ++static inline bool timespec_valid(const struct timespec *ts) ++{ ++ /* Dates before 1970 are bogus */ ++ if (ts->tv_sec < 0) ++ return false; ++ /* Can't have more nanoseconds then a second */ ++ if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) ++ return false; ++ return true; ++} ++ ++static inline bool timespec_valid_strict(const struct timespec *ts) ++{ ++ if (!timespec_valid(ts)) ++ return false; ++ /* Disallow values that could overflow ktime_t */ ++ if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) ++ return false; ++ return true; ++} + + extern void read_persistent_clock(struct timespec *ts); + extern void read_boot_clock(struct timespec *ts); +@@ -257,14 +282,6 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns) + + #endif /* __KERNEL__ */ + +-#define NFDBITS __NFDBITS +- +-#define FD_SETSIZE __FD_SETSIZE +-#define FD_SET(fd,fdsetp) __FD_SET(fd,fdsetp) +-#define FD_CLR(fd,fdsetp) __FD_CLR(fd,fdsetp) +-#define FD_ISSET(fd,fdsetp) __FD_ISSET(fd,fdsetp) +-#define FD_ZERO(fdsetp) __FD_ZERO(fdsetp) +- + /* + * Names of the interval timers, and structure + * defining a timer setting: +diff --git a/include/linux/usb.h b/include/linux/usb.h +index dea39dc..3049707 100644 +--- a/include/linux/usb.h ++++ b/include/linux/usb.h +@@ -556,7 +556,6 @@ struct usb_device { + struct usb3_lpm_parameters u1_params; + struct usb3_lpm_parameters u2_params; + unsigned lpm_disable_count; +- unsigned hub_initiated_lpm_disable_count; + }; + #define to_usb_device(d) container_of(d, struct usb_device, dev) + +@@ -829,6 +828,27 @@ static inline int usb_make_path(struct usb_device *dev, char *buf, size_t size) + .bInterfaceSubClass = (sc), \ + .bInterfaceProtocol = (pr) + ++/** ++ * USB_VENDOR_AND_INTERFACE_INFO - describe a specific usb vendor with a class of usb interfaces ++ * @vend: the 16 bit USB Vendor ID ++ * @cl: bInterfaceClass value ++ * @sc: bInterfaceSubClass value ++ * @pr: bInterfaceProtocol value ++ * ++ * This macro is used to create a struct usb_device_id that matches a ++ * specific vendor with a specific class of interfaces. ++ * ++ * This is especially useful when explicitly matching devices that have ++ * vendor specific bDeviceClass values, but standards-compliant interfaces. ++ */ ++#define USB_VENDOR_AND_INTERFACE_INFO(vend, cl, sc, pr) \ ++ .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \ ++ | USB_DEVICE_ID_MATCH_VENDOR, \ ++ .idVendor = (vend), \ ++ .bInterfaceClass = (cl), \ ++ .bInterfaceSubClass = (sc), \ ++ .bInterfaceProtocol = (pr) ++ + /* ----------------------------------------------------------------------- */ + + /* Stuff for dynamic usb ids */ +diff --git a/include/linux/xfrm.h b/include/linux/xfrm.h +index 22e61fd..28e493b 100644 +--- a/include/linux/xfrm.h ++++ b/include/linux/xfrm.h +@@ -84,6 +84,8 @@ struct xfrm_replay_state { + __u32 bitmap; + }; + ++#define XFRMA_REPLAY_ESN_MAX 4096 ++ + struct xfrm_replay_state_esn { + unsigned int bmp_len; + __u32 oseq; +diff --git a/include/net/bluetooth/smp.h b/include/net/bluetooth/smp.h +index ca356a7..8b27927 100644 +--- a/include/net/bluetooth/smp.h ++++ b/include/net/bluetooth/smp.h +@@ -136,7 +136,7 @@ struct smp_chan { + }; + + /* SMP Commands */ +-int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level); ++int smp_conn_security(struct hci_conn *hcon, __u8 sec_level); + int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb); + int smp_distribute_keys(struct l2cap_conn *conn, __u8 force); + int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, __le32 passkey); +diff --git a/include/net/codel.h b/include/net/codel.h +index 550debf..389cf62 100644 +--- a/include/net/codel.h ++++ b/include/net/codel.h +@@ -305,6 +305,8 @@ static struct sk_buff *codel_dequeue(struct Qdisc *sch, + } + } + } else if (drop) { ++ u32 delta; ++ + if (params->ecn && INET_ECN_set_ce(skb)) { + stats->ecn_mark++; + } else { +@@ -320,9 +322,11 @@ static struct sk_buff *codel_dequeue(struct Qdisc *sch, + * assume that the drop rate that controlled the queue on the + * last cycle is a good starting point to control it now. + */ +- if (codel_time_before(now - vars->drop_next, ++ delta = vars->count - vars->lastcount; ++ if (delta > 1 && ++ codel_time_before(now - vars->drop_next, + 16 * params->interval)) { +- vars->count = (vars->count - vars->lastcount) | 1; ++ vars->count = delta; + /* we dont care if rec_inv_sqrt approximation + * is not very precise : + * Next Newton steps will correct it quadratically. +diff --git a/include/net/scm.h b/include/net/scm.h +index d456f4c..0c0017c 100644 +--- a/include/net/scm.h ++++ b/include/net/scm.h +@@ -71,9 +71,11 @@ static __inline__ void scm_destroy(struct scm_cookie *scm) + } + + static __inline__ int scm_send(struct socket *sock, struct msghdr *msg, +- struct scm_cookie *scm) ++ struct scm_cookie *scm, bool forcecreds) + { + memset(scm, 0, sizeof(*scm)); ++ if (forcecreds) ++ scm_set_cred(scm, task_tgid(current), current_cred()); + unix_get_peersec_dgram(sock, scm); + if (msg->msg_controllen <= 0) + return 0; +diff --git a/include/net/sock.h b/include/net/sock.h +index 4a45216..5de6557 100644 +--- a/include/net/sock.h ++++ b/include/net/sock.h +@@ -217,6 +217,7 @@ struct cg_proto; + * @sk_route_nocaps: forbidden route capabilities (e.g NETIF_F_GSO_MASK) + * @sk_gso_type: GSO type (e.g. %SKB_GSO_TCPV4) + * @sk_gso_max_size: Maximum GSO segment size to build ++ * @sk_gso_max_segs: Maximum number of GSO segments + * @sk_lingertime: %SO_LINGER l_linger setting + * @sk_backlog: always used with the per-socket spinlock held + * @sk_callback_lock: used with the callbacks in the end of this struct +@@ -336,6 +337,7 @@ struct sock { + netdev_features_t sk_route_nocaps; + int sk_gso_type; + unsigned int sk_gso_max_size; ++ u16 sk_gso_max_segs; + int sk_rcvlowat; + unsigned long sk_lingertime; + struct sk_buff_head sk_error_queue; +diff --git a/include/net/xfrm.h b/include/net/xfrm.h +index e0a55df..887a232 100644 +--- a/include/net/xfrm.h ++++ b/include/net/xfrm.h +@@ -269,6 +269,9 @@ struct xfrm_replay { + int (*check)(struct xfrm_state *x, + struct sk_buff *skb, + __be32 net_seq); ++ int (*recheck)(struct xfrm_state *x, ++ struct sk_buff *skb, ++ __be32 net_seq); + void (*notify)(struct xfrm_state *x, int event); + int (*overflow)(struct xfrm_state *x, struct sk_buff *skb); + }; +diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h +index dc35d86..362e0d9 100644 +--- a/include/target/target_core_base.h ++++ b/include/target/target_core_base.h +@@ -220,6 +220,7 @@ enum tcm_sense_reason_table { + TCM_CHECK_CONDITION_UNIT_ATTENTION = 0x0e, + TCM_CHECK_CONDITION_NOT_READY = 0x0f, + TCM_RESERVATION_CONFLICT = 0x10, ++ TCM_ADDRESS_OUT_OF_RANGE = 0x11, + }; + + enum target_sc_flags_table { +diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h +index 5f889f1..08fa272 100644 +--- a/include/trace/events/kmem.h ++++ b/include/trace/events/kmem.h +@@ -214,7 +214,7 @@ TRACE_EVENT(mm_page_alloc, + + TP_printk("page=%p pfn=%lu order=%d migratetype=%d gfp_flags=%s", + __entry->page, +- page_to_pfn(__entry->page), ++ __entry->page ? page_to_pfn(__entry->page) : 0, + __entry->order, + __entry->migratetype, + show_gfp_flags(__entry->gfp_flags)) +@@ -240,7 +240,7 @@ DECLARE_EVENT_CLASS(mm_page, + + TP_printk("page=%p pfn=%lu order=%u migratetype=%d percpu_refill=%d", + __entry->page, +- page_to_pfn(__entry->page), ++ __entry->page ? page_to_pfn(__entry->page) : 0, + __entry->order, + __entry->migratetype, + __entry->order == 0) +diff --git a/include/trace/events/random.h b/include/trace/events/random.h +new file mode 100644 +index 0000000..422df19 +--- /dev/null ++++ b/include/trace/events/random.h +@@ -0,0 +1,134 @@ ++#undef TRACE_SYSTEM ++#define TRACE_SYSTEM random ++ ++#if !defined(_TRACE_RANDOM_H) || defined(TRACE_HEADER_MULTI_READ) ++#define _TRACE_RANDOM_H ++ ++#include ++#include ++ ++DECLARE_EVENT_CLASS(random__mix_pool_bytes, ++ TP_PROTO(const char *pool_name, int bytes, unsigned long IP), ++ ++ TP_ARGS(pool_name, bytes, IP), ++ ++ TP_STRUCT__entry( ++ __field( const char *, pool_name ) ++ __field( int, bytes ) ++ __field(unsigned long, IP ) ++ ), ++ ++ TP_fast_assign( ++ __entry->pool_name = pool_name; ++ __entry->bytes = bytes; ++ __entry->IP = IP; ++ ), ++ ++ TP_printk("%s pool: bytes %d caller %pF", ++ __entry->pool_name, __entry->bytes, (void *)__entry->IP) ++); ++ ++DEFINE_EVENT(random__mix_pool_bytes, mix_pool_bytes, ++ TP_PROTO(const char *pool_name, int bytes, unsigned long IP), ++ ++ TP_ARGS(pool_name, bytes, IP) ++); ++ ++DEFINE_EVENT(random__mix_pool_bytes, mix_pool_bytes_nolock, ++ TP_PROTO(const char *pool_name, int bytes, unsigned long IP), ++ ++ TP_ARGS(pool_name, bytes, IP) ++); ++ ++TRACE_EVENT(credit_entropy_bits, ++ TP_PROTO(const char *pool_name, int bits, int entropy_count, ++ int entropy_total, unsigned long IP), ++ ++ TP_ARGS(pool_name, bits, entropy_count, entropy_total, IP), ++ ++ TP_STRUCT__entry( ++ __field( const char *, pool_name ) ++ __field( int, bits ) ++ __field( int, entropy_count ) ++ __field( int, entropy_total ) ++ __field(unsigned long, IP ) ++ ), ++ ++ TP_fast_assign( ++ __entry->pool_name = pool_name; ++ __entry->bits = bits; ++ __entry->entropy_count = entropy_count; ++ __entry->entropy_total = entropy_total; ++ __entry->IP = IP; ++ ), ++ ++ TP_printk("%s pool: bits %d entropy_count %d entropy_total %d " ++ "caller %pF", __entry->pool_name, __entry->bits, ++ __entry->entropy_count, __entry->entropy_total, ++ (void *)__entry->IP) ++); ++ ++TRACE_EVENT(get_random_bytes, ++ TP_PROTO(int nbytes, unsigned long IP), ++ ++ TP_ARGS(nbytes, IP), ++ ++ TP_STRUCT__entry( ++ __field( int, nbytes ) ++ __field(unsigned long, IP ) ++ ), ++ ++ TP_fast_assign( ++ __entry->nbytes = nbytes; ++ __entry->IP = IP; ++ ), ++ ++ TP_printk("nbytes %d caller %pF", __entry->nbytes, (void *)__entry->IP) ++); ++ ++DECLARE_EVENT_CLASS(random__extract_entropy, ++ TP_PROTO(const char *pool_name, int nbytes, int entropy_count, ++ unsigned long IP), ++ ++ TP_ARGS(pool_name, nbytes, entropy_count, IP), ++ ++ TP_STRUCT__entry( ++ __field( const char *, pool_name ) ++ __field( int, nbytes ) ++ __field( int, entropy_count ) ++ __field(unsigned long, IP ) ++ ), ++ ++ TP_fast_assign( ++ __entry->pool_name = pool_name; ++ __entry->nbytes = nbytes; ++ __entry->entropy_count = entropy_count; ++ __entry->IP = IP; ++ ), ++ ++ TP_printk("%s pool: nbytes %d entropy_count %d caller %pF", ++ __entry->pool_name, __entry->nbytes, __entry->entropy_count, ++ (void *)__entry->IP) ++); ++ ++ ++DEFINE_EVENT(random__extract_entropy, extract_entropy, ++ TP_PROTO(const char *pool_name, int nbytes, int entropy_count, ++ unsigned long IP), ++ ++ TP_ARGS(pool_name, nbytes, entropy_count, IP) ++); ++ ++DEFINE_EVENT(random__extract_entropy, extract_entropy_user, ++ TP_PROTO(const char *pool_name, int nbytes, int entropy_count, ++ unsigned long IP), ++ ++ TP_ARGS(pool_name, nbytes, entropy_count, IP) ++); ++ ++ ++ ++#endif /* _TRACE_RANDOM_H */ ++ ++/* This part must be outside protection */ ++#include +diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h +index 11e27c3..f19fff8 100644 +--- a/include/xen/grant_table.h ++++ b/include/xen/grant_table.h +@@ -187,6 +187,7 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, + struct gnttab_map_grant_ref *kmap_ops, + struct page **pages, unsigned int count); + int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, +- struct page **pages, unsigned int count, bool clear_pte); ++ struct gnttab_map_grant_ref *kunmap_ops, ++ struct page **pages, unsigned int count); + + #endif /* __ASM_GNTTAB_H__ */ +diff --git a/kernel/async.c b/kernel/async.c +index bd0c168..32d8dc9 100644 +--- a/kernel/async.c ++++ b/kernel/async.c +@@ -86,6 +86,13 @@ static async_cookie_t __lowest_in_progress(struct list_head *running) + { + struct async_entry *entry; + ++ if (!running) { /* just check the entry count */ ++ if (atomic_read(&entry_count)) ++ return 0; /* smaller than any cookie */ ++ else ++ return next_cookie; ++ } ++ + if (!list_empty(running)) { + entry = list_first_entry(running, + struct async_entry, list); +@@ -236,9 +243,7 @@ EXPORT_SYMBOL_GPL(async_schedule_domain); + */ + void async_synchronize_full(void) + { +- do { +- async_synchronize_cookie(next_cookie); +- } while (!list_empty(&async_running) || !list_empty(&async_pending)); ++ async_synchronize_cookie_domain(next_cookie, NULL); + } + EXPORT_SYMBOL_GPL(async_synchronize_full); + +@@ -258,7 +263,7 @@ EXPORT_SYMBOL_GPL(async_synchronize_full_domain); + /** + * async_synchronize_cookie_domain - synchronize asynchronous function calls within a certain domain with cookie checkpointing + * @cookie: async_cookie_t to use as checkpoint +- * @running: running list to synchronize on ++ * @running: running list to synchronize on, NULL indicates all lists + * + * This function waits until all asynchronous function calls for the + * synchronization domain specified by the running list @list submitted +diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c +index 5bf0790..31fdc48 100644 +--- a/kernel/audit_tree.c ++++ b/kernel/audit_tree.c +@@ -250,7 +250,6 @@ static void untag_chunk(struct node *p) + spin_unlock(&hash_lock); + spin_unlock(&entry->lock); + fsnotify_destroy_mark(entry); +- fsnotify_put_mark(entry); + goto out; + } + +@@ -259,7 +258,7 @@ static void untag_chunk(struct node *p) + + fsnotify_duplicate_mark(&new->mark, entry); + if (fsnotify_add_mark(&new->mark, new->mark.group, new->mark.i.inode, NULL, 1)) { +- free_chunk(new); ++ fsnotify_put_mark(&new->mark); + goto Fallback; + } + +@@ -293,7 +292,6 @@ static void untag_chunk(struct node *p) + spin_unlock(&hash_lock); + spin_unlock(&entry->lock); + fsnotify_destroy_mark(entry); +- fsnotify_put_mark(entry); + goto out; + + Fallback: +@@ -322,7 +320,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree) + + entry = &chunk->mark; + if (fsnotify_add_mark(entry, audit_tree_group, inode, NULL, 0)) { +- free_chunk(chunk); ++ fsnotify_put_mark(entry); + return -ENOSPC; + } + +@@ -332,6 +330,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree) + spin_unlock(&hash_lock); + chunk->dead = 1; + spin_unlock(&entry->lock); ++ fsnotify_get_mark(entry); + fsnotify_destroy_mark(entry); + fsnotify_put_mark(entry); + return 0; +@@ -396,7 +395,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) + fsnotify_duplicate_mark(chunk_entry, old_entry); + if (fsnotify_add_mark(chunk_entry, chunk_entry->group, chunk_entry->i.inode, NULL, 1)) { + spin_unlock(&old_entry->lock); +- free_chunk(chunk); ++ fsnotify_put_mark(chunk_entry); + fsnotify_put_mark(old_entry); + return -ENOSPC; + } +@@ -412,6 +411,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) + spin_unlock(&chunk_entry->lock); + spin_unlock(&old_entry->lock); + ++ fsnotify_get_mark(chunk_entry); + fsnotify_destroy_mark(chunk_entry); + + fsnotify_put_mark(chunk_entry); +@@ -445,7 +445,6 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) + spin_unlock(&old_entry->lock); + fsnotify_destroy_mark(old_entry); + fsnotify_put_mark(old_entry); /* pair to fsnotify_find mark_entry */ +- fsnotify_put_mark(old_entry); /* and kill it */ + return 0; + } + +diff --git a/kernel/cgroup.c b/kernel/cgroup.c +index b303dfc..15462a0 100644 +--- a/kernel/cgroup.c ++++ b/kernel/cgroup.c +@@ -954,7 +954,7 @@ static int cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft) + + dget(d); + d_delete(d); +- simple_unlink(d->d_inode, d); ++ simple_unlink(cgrp->dentry->d_inode, d); + list_del_init(&cfe->node); + dput(d); + +diff --git a/kernel/cpuset.c b/kernel/cpuset.c +index 8c8bd65..746d1ee 100644 +--- a/kernel/cpuset.c ++++ b/kernel/cpuset.c +@@ -2054,6 +2054,9 @@ static void scan_for_empty_cpusets(struct cpuset *root) + * (of no affect) on systems that are actively using CPU hotplug + * but making no active use of cpusets. + * ++ * The only exception to this is suspend/resume, where we don't ++ * modify cpusets at all. ++ * + * This routine ensures that top_cpuset.cpus_allowed tracks + * cpu_active_mask on each CPU hotplug (cpuhp) event. + * +diff --git a/kernel/events/core.c b/kernel/events/core.c +index d7d71d6..11409af 100644 +--- a/kernel/events/core.c ++++ b/kernel/events/core.c +@@ -2933,12 +2933,12 @@ EXPORT_SYMBOL_GPL(perf_event_release_kernel); + /* + * Called when the last reference to the file is gone. + */ +-static int perf_release(struct inode *inode, struct file *file) ++static void put_event(struct perf_event *event) + { +- struct perf_event *event = file->private_data; + struct task_struct *owner; + +- file->private_data = NULL; ++ if (!atomic_long_dec_and_test(&event->refcount)) ++ return; + + rcu_read_lock(); + owner = ACCESS_ONCE(event->owner); +@@ -2973,7 +2973,13 @@ static int perf_release(struct inode *inode, struct file *file) + put_task_struct(owner); + } + +- return perf_event_release_kernel(event); ++ perf_event_release_kernel(event); ++} ++ ++static int perf_release(struct inode *inode, struct file *file) ++{ ++ put_event(file->private_data); ++ return 0; + } + + u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running) +@@ -3225,7 +3231,7 @@ unlock: + + static const struct file_operations perf_fops; + +-static struct perf_event *perf_fget_light(int fd, int *fput_needed) ++static struct file *perf_fget_light(int fd, int *fput_needed) + { + struct file *file; + +@@ -3239,7 +3245,7 @@ static struct perf_event *perf_fget_light(int fd, int *fput_needed) + return ERR_PTR(-EBADF); + } + +- return file->private_data; ++ return file; + } + + static int perf_event_set_output(struct perf_event *event, +@@ -3271,19 +3277,21 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg) + + case PERF_EVENT_IOC_SET_OUTPUT: + { ++ struct file *output_file = NULL; + struct perf_event *output_event = NULL; + int fput_needed = 0; + int ret; + + if (arg != -1) { +- output_event = perf_fget_light(arg, &fput_needed); +- if (IS_ERR(output_event)) +- return PTR_ERR(output_event); ++ output_file = perf_fget_light(arg, &fput_needed); ++ if (IS_ERR(output_file)) ++ return PTR_ERR(output_file); ++ output_event = output_file->private_data; + } + + ret = perf_event_set_output(event, output_event); + if (output_event) +- fput_light(output_event->filp, fput_needed); ++ fput_light(output_file, fput_needed); + + return ret; + } +@@ -5922,6 +5930,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, + + mutex_init(&event->mmap_mutex); + ++ atomic_long_set(&event->refcount, 1); + event->cpu = cpu; + event->attr = *attr; + event->group_leader = group_leader; +@@ -6232,12 +6241,12 @@ SYSCALL_DEFINE5(perf_event_open, + return event_fd; + + if (group_fd != -1) { +- group_leader = perf_fget_light(group_fd, &fput_needed); +- if (IS_ERR(group_leader)) { +- err = PTR_ERR(group_leader); ++ group_file = perf_fget_light(group_fd, &fput_needed); ++ if (IS_ERR(group_file)) { ++ err = PTR_ERR(group_file); + goto err_fd; + } +- group_file = group_leader->filp; ++ group_leader = group_file->private_data; + if (flags & PERF_FLAG_FD_OUTPUT) + output_event = group_leader; + if (flags & PERF_FLAG_FD_NO_GROUP) +@@ -6372,7 +6381,6 @@ SYSCALL_DEFINE5(perf_event_open, + put_ctx(gctx); + } + +- event->filp = event_file; + WARN_ON_ONCE(ctx->parent_ctx); + mutex_lock(&ctx->mutex); + +@@ -6462,7 +6470,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, + goto err_free; + } + +- event->filp = NULL; + WARN_ON_ONCE(ctx->parent_ctx); + mutex_lock(&ctx->mutex); + perf_install_in_context(ctx, event, cpu); +@@ -6511,7 +6518,7 @@ static void sync_child_event(struct perf_event *child_event, + * Release the parent event, if this was the last + * reference to it. + */ +- fput(parent_event->filp); ++ put_event(parent_event); + } + + static void +@@ -6587,9 +6594,8 @@ static void perf_event_exit_task_context(struct task_struct *child, int ctxn) + * + * __perf_event_exit_task() + * sync_child_event() +- * fput(parent_event->filp) +- * perf_release() +- * mutex_lock(&ctx->mutex) ++ * put_event() ++ * mutex_lock(&ctx->mutex) + * + * But since its the parent context it won't be the same instance. + */ +@@ -6657,7 +6663,7 @@ static void perf_free_event(struct perf_event *event, + list_del_init(&event->child_list); + mutex_unlock(&parent->child_mutex); + +- fput(parent->filp); ++ put_event(parent); + + perf_group_detach(event); + list_del_event(event, ctx); +@@ -6737,6 +6743,12 @@ inherit_event(struct perf_event *parent_event, + NULL, NULL); + if (IS_ERR(child_event)) + return child_event; ++ ++ if (!atomic_long_inc_not_zero(&parent_event->refcount)) { ++ free_event(child_event); ++ return NULL; ++ } ++ + get_ctx(child_ctx); + + /* +@@ -6778,14 +6790,6 @@ inherit_event(struct perf_event *parent_event, + raw_spin_unlock_irqrestore(&child_ctx->lock, flags); + + /* +- * Get a reference to the parent filp - we will fput it +- * when the child event exits. This is safe to do because +- * we are in the parent and we know that the filp still +- * exists and has a nonzero count: +- */ +- atomic_long_inc(&parent_event->filp->f_count); +- +- /* + * Link this into the parent event's child list + */ + WARN_ON_ONCE(parent_event->ctx->parent_ctx); +diff --git a/kernel/exit.c b/kernel/exit.c +index 2f59cc3..46ce8da 100644 +--- a/kernel/exit.c ++++ b/kernel/exit.c +@@ -483,7 +483,7 @@ static void close_files(struct files_struct * files) + rcu_read_unlock(); + for (;;) { + unsigned long set; +- i = j * __NFDBITS; ++ i = j * BITS_PER_LONG; + if (i >= fdt->max_fds) + break; + set = fdt->open_fds[j++]; +diff --git a/kernel/fork.c b/kernel/fork.c +index f00e319..f9d0499 100644 +--- a/kernel/fork.c ++++ b/kernel/fork.c +@@ -459,8 +459,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) + if (retval) + goto out; + +- if (file && uprobe_mmap(tmp)) +- goto out; ++ if (file) ++ uprobe_mmap(tmp); + } + /* a new mm has just been created */ + arch_dup_mmap(oldmm, mm); +diff --git a/kernel/futex.c b/kernel/futex.c +index e2b0fb9..3717e7b 100644 +--- a/kernel/futex.c ++++ b/kernel/futex.c +@@ -2231,11 +2231,11 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb, + * @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 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, + struct futex_q q = futex_q_init; + int res, ret; + ++ if (uaddr == uaddr2) ++ return -EINVAL; ++ + if (!bitset) + return -EINVAL; + +@@ -2343,7 +2346,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, + * 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 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, + * 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 --git a/kernel/irq/handle.c b/kernel/irq/handle.c +index bdb1803..131ca17 100644 +--- a/kernel/irq/handle.c ++++ b/kernel/irq/handle.c +@@ -133,7 +133,7 @@ irqreturn_t + handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action) + { + irqreturn_t retval = IRQ_NONE; +- unsigned int random = 0, irq = desc->irq_data.irq; ++ unsigned int flags = 0, irq = desc->irq_data.irq; + + do { + irqreturn_t res; +@@ -161,7 +161,7 @@ handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action) + + /* Fall through to add to randomness */ + case IRQ_HANDLED: +- random |= action->flags; ++ flags |= action->flags; + break; + + default: +@@ -172,8 +172,7 @@ handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action) + action = action->next; + } while (action); + +- if (random & IRQF_SAMPLE_RANDOM) +- add_interrupt_randomness(irq); ++ add_interrupt_randomness(irq, flags); + + if (!noirqdebug) + note_interrupt(irq, desc, retval); +diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c +index 8c54823..5e42eb1 100644 +--- a/kernel/irq/manage.c ++++ b/kernel/irq/manage.c +@@ -893,22 +893,6 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) + return -ENOSYS; + if (!try_module_get(desc->owner)) + return -ENODEV; +- /* +- * Some drivers like serial.c use request_irq() heavily, +- * so we have to be careful not to interfere with a +- * running system. +- */ +- if (new->flags & IRQF_SAMPLE_RANDOM) { +- /* +- * This function might sleep, we want to call it first, +- * outside of the atomic block. +- * Yes, this might clear the entropy pool if the wrong +- * driver is attempted to be loaded, without actually +- * installing a new handler, but is this really a problem, +- * only the sysadmin is able to do this. +- */ +- rand_initialize_irq(irq); +- } + + /* + * Check whether the interrupt nests into another interrupt +@@ -1354,7 +1338,6 @@ EXPORT_SYMBOL(free_irq); + * Flags: + * + * IRQF_SHARED Interrupt is shared +- * IRQF_SAMPLE_RANDOM The interrupt can be used for entropy + * IRQF_TRIGGER_* Specify active edge(s) or level + * + */ +diff --git a/kernel/kthread.c b/kernel/kthread.c +index 3d3de63..b579af5 100644 +--- a/kernel/kthread.c ++++ b/kernel/kthread.c +@@ -360,16 +360,12 @@ repeat: + struct kthread_work, node); + list_del_init(&work->node); + } ++ worker->current_work = work; + spin_unlock_irq(&worker->lock); + + if (work) { + __set_current_state(TASK_RUNNING); + work->func(work); +- smp_wmb(); /* wmb worker-b0 paired with flush-b1 */ +- work->done_seq = work->queue_seq; +- smp_mb(); /* mb worker-b1 paired with flush-b0 */ +- if (atomic_read(&work->flushing)) +- wake_up_all(&work->done); + } else if (!freezing(current)) + schedule(); + +@@ -378,6 +374,19 @@ repeat: + } + EXPORT_SYMBOL_GPL(kthread_worker_fn); + ++/* insert @work before @pos in @worker */ ++static void insert_kthread_work(struct kthread_worker *worker, ++ struct kthread_work *work, ++ struct list_head *pos) ++{ ++ lockdep_assert_held(&worker->lock); ++ ++ list_add_tail(&work->node, pos); ++ work->worker = worker; ++ if (likely(worker->task)) ++ wake_up_process(worker->task); ++} ++ + /** + * queue_kthread_work - queue a kthread_work + * @worker: target kthread_worker +@@ -395,10 +404,7 @@ bool queue_kthread_work(struct kthread_worker *worker, + + spin_lock_irqsave(&worker->lock, flags); + if (list_empty(&work->node)) { +- list_add_tail(&work->node, &worker->work_list); +- work->queue_seq++; +- if (likely(worker->task)) +- wake_up_process(worker->task); ++ insert_kthread_work(worker, work, &worker->work_list); + ret = true; + } + spin_unlock_irqrestore(&worker->lock, flags); +@@ -406,6 +412,18 @@ bool queue_kthread_work(struct kthread_worker *worker, + } + EXPORT_SYMBOL_GPL(queue_kthread_work); + ++struct kthread_flush_work { ++ struct kthread_work work; ++ struct completion done; ++}; ++ ++static void kthread_flush_work_fn(struct kthread_work *work) ++{ ++ struct kthread_flush_work *fwork = ++ container_of(work, struct kthread_flush_work, work); ++ complete(&fwork->done); ++} ++ + /** + * flush_kthread_work - flush a kthread_work + * @work: work to flush +@@ -414,39 +432,37 @@ EXPORT_SYMBOL_GPL(queue_kthread_work); + */ + void flush_kthread_work(struct kthread_work *work) + { +- int seq = work->queue_seq; +- +- atomic_inc(&work->flushing); ++ struct kthread_flush_work fwork = { ++ KTHREAD_WORK_INIT(fwork.work, kthread_flush_work_fn), ++ COMPLETION_INITIALIZER_ONSTACK(fwork.done), ++ }; ++ struct kthread_worker *worker; ++ bool noop = false; + +- /* +- * mb flush-b0 paired with worker-b1, to make sure either +- * worker sees the above increment or we see done_seq update. +- */ +- smp_mb__after_atomic_inc(); ++retry: ++ worker = work->worker; ++ if (!worker) ++ return; + +- /* A - B <= 0 tests whether B is in front of A regardless of overflow */ +- wait_event(work->done, seq - work->done_seq <= 0); +- atomic_dec(&work->flushing); ++ spin_lock_irq(&worker->lock); ++ if (work->worker != worker) { ++ spin_unlock_irq(&worker->lock); ++ goto retry; ++ } + +- /* +- * rmb flush-b1 paired with worker-b0, to make sure our caller +- * sees every change made by work->func(). +- */ +- smp_mb__after_atomic_dec(); +-} +-EXPORT_SYMBOL_GPL(flush_kthread_work); ++ if (!list_empty(&work->node)) ++ insert_kthread_work(worker, &fwork.work, work->node.next); ++ else if (worker->current_work == work) ++ insert_kthread_work(worker, &fwork.work, worker->work_list.next); ++ else ++ noop = true; + +-struct kthread_flush_work { +- struct kthread_work work; +- struct completion done; +-}; ++ spin_unlock_irq(&worker->lock); + +-static void kthread_flush_work_fn(struct kthread_work *work) +-{ +- struct kthread_flush_work *fwork = +- container_of(work, struct kthread_flush_work, work); +- complete(&fwork->done); ++ if (!noop) ++ wait_for_completion(&fwork.done); + } ++EXPORT_SYMBOL_GPL(flush_kthread_work); + + /** + * flush_kthread_worker - flush all current works on a kthread_worker +diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c +index 238025f..4d46daf 100644 +--- a/kernel/power/hibernate.c ++++ b/kernel/power/hibernate.c +@@ -353,6 +353,7 @@ int hibernation_snapshot(int platform_mode) + } + + suspend_console(); ++ ftrace_stop(); + pm_restrict_gfp_mask(); + + error = dpm_suspend(PMSG_FREEZE); +@@ -378,6 +379,7 @@ int hibernation_snapshot(int platform_mode) + if (error || !in_suspend) + pm_restore_gfp_mask(); + ++ ftrace_start(); + resume_console(); + dpm_complete(msg); + +@@ -480,6 +482,7 @@ int hibernation_restore(int platform_mode) + + pm_prepare_console(); + suspend_console(); ++ ftrace_stop(); + pm_restrict_gfp_mask(); + error = dpm_suspend_start(PMSG_QUIESCE); + if (!error) { +@@ -487,6 +490,7 @@ int hibernation_restore(int platform_mode) + dpm_resume_end(PMSG_RECOVER); + } + pm_restore_gfp_mask(); ++ ftrace_start(); + resume_console(); + pm_restore_console(); + return error; +@@ -513,6 +517,7 @@ int hibernation_platform_enter(void) + + entering_platform_hibernation = true; + suspend_console(); ++ ftrace_stop(); + error = dpm_suspend_start(PMSG_HIBERNATE); + if (error) { + if (hibernation_ops->recover) +@@ -556,6 +561,7 @@ int hibernation_platform_enter(void) + Resume_devices: + entering_platform_hibernation = false; + dpm_resume_end(PMSG_RESTORE); ++ ftrace_start(); + resume_console(); + + Close: +diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c +index 396d262..c8b7446 100644 +--- a/kernel/power/suspend.c ++++ b/kernel/power/suspend.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + + #include "power.h" +@@ -212,6 +213,7 @@ int suspend_devices_and_enter(suspend_state_t state) + goto Close; + } + suspend_console(); ++ ftrace_stop(); + suspend_test_start(); + error = dpm_suspend_start(PMSG_SUSPEND); + if (error) { +@@ -231,6 +233,7 @@ int suspend_devices_and_enter(suspend_state_t state) + suspend_test_start(); + dpm_resume_end(PMSG_RESUME); + suspend_test_finish("resume devices"); ++ ftrace_start(); + resume_console(); + Close: + if (suspend_ops->end) +diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c +index c8fba33..8f50de3 100644 +--- a/kernel/power/wakelock.c ++++ b/kernel/power/wakelock.c +@@ -9,6 +9,7 @@ + * manipulate wakelocks on Android. + */ + ++#include + #include + #include + #include +@@ -188,6 +189,9 @@ int pm_wake_lock(const char *buf) + size_t len; + int ret = 0; + ++ if (!capable(CAP_BLOCK_SUSPEND)) ++ return -EPERM; ++ + while (*str && !isspace(*str)) + str++; + +@@ -231,6 +235,9 @@ int pm_wake_unlock(const char *buf) + size_t len; + int ret = 0; + ++ if (!capable(CAP_BLOCK_SUSPEND)) ++ return -EPERM; ++ + len = strlen(buf); + if (!len) + return -EINVAL; +diff --git a/kernel/printk.c b/kernel/printk.c +index ac4bc9e..146827f 100644 +--- a/kernel/printk.c ++++ b/kernel/printk.c +@@ -235,7 +235,8 @@ static u32 log_next_idx; + static u64 clear_seq; + static u32 clear_idx; + +-#define LOG_LINE_MAX 1024 ++#define PREFIX_MAX 32 ++#define LOG_LINE_MAX 1024 - PREFIX_MAX + + /* record buffer */ + #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) +@@ -876,7 +877,7 @@ static size_t msg_print_text(const struct log *msg, enum log_flags prev, + + if (buf) { + if (print_prefix(msg, syslog, NULL) + +- text_len + 1>= size - len) ++ text_len + 1 >= size - len) + break; + + if (prefix) +@@ -907,7 +908,7 @@ static int syslog_print(char __user *buf, int size) + struct log *msg; + int len = 0; + +- text = kmalloc(LOG_LINE_MAX, GFP_KERNEL); ++ text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL); + if (!text) + return -ENOMEM; + +@@ -930,7 +931,8 @@ static int syslog_print(char __user *buf, int size) + + skip = syslog_partial; + msg = log_from_idx(syslog_idx); +- n = msg_print_text(msg, syslog_prev, true, text, LOG_LINE_MAX); ++ n = msg_print_text(msg, syslog_prev, true, text, ++ LOG_LINE_MAX + PREFIX_MAX); + if (n - syslog_partial <= size) { + /* message fits into buffer, move forward */ + syslog_idx = log_next(syslog_idx); +@@ -969,7 +971,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear) + char *text; + int len = 0; + +- text = kmalloc(LOG_LINE_MAX, GFP_KERNEL); ++ text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL); + if (!text) + return -ENOMEM; + +@@ -997,6 +999,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear) + struct log *msg = log_from_idx(idx); + + len += msg_print_text(msg, prev, true, NULL, 0); ++ prev = msg->flags; + idx = log_next(idx); + seq++; + } +@@ -1009,6 +1012,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear) + struct log *msg = log_from_idx(idx); + + len -= msg_print_text(msg, prev, true, NULL, 0); ++ prev = msg->flags; + idx = log_next(idx); + seq++; + } +@@ -1022,7 +1026,8 @@ static int syslog_print_all(char __user *buf, int size, bool clear) + struct log *msg = log_from_idx(idx); + int textlen; + +- textlen = msg_print_text(msg, prev, true, text, LOG_LINE_MAX); ++ textlen = msg_print_text(msg, prev, true, text, ++ LOG_LINE_MAX + PREFIX_MAX); + if (textlen < 0) { + len = textlen; + break; +@@ -1352,15 +1357,15 @@ static struct cont { + bool flushed:1; /* buffer sealed and committed */ + } cont; + +-static void cont_flush(void) ++static void cont_flush(enum log_flags flags) + { + if (cont.flushed) + return; + if (cont.len == 0) + return; + +- log_store(cont.facility, cont.level, LOG_NOCONS, cont.ts_nsec, +- NULL, 0, cont.buf, cont.len); ++ log_store(cont.facility, cont.level, LOG_NOCONS | flags, ++ cont.ts_nsec, NULL, 0, cont.buf, cont.len); + + cont.flushed = true; + } +@@ -1371,7 +1376,8 @@ static bool cont_add(int facility, int level, const char *text, size_t len) + return false; + + if (cont.len + len > sizeof(cont.buf)) { +- cont_flush(); ++ /* the line gets too long, split it up in separate records */ ++ cont_flush(LOG_CONT); + return false; + } + +@@ -1507,7 +1513,7 @@ asmlinkage int vprintk_emit(int facility, int level, + * or another task also prints continuation lines. + */ + if (cont.len && (lflags & LOG_PREFIX || cont.owner != current)) +- cont_flush(); ++ cont_flush(0); + + /* buffer line if possible, otherwise store it right away */ + if (!cont_add(facility, level, text, text_len)) +@@ -1525,7 +1531,7 @@ asmlinkage int vprintk_emit(int facility, int level, + if (cont.len && cont.owner == current) { + if (!(lflags & LOG_PREFIX)) + stored = cont_add(facility, level, text, text_len); +- cont_flush(); ++ cont_flush(0); + } + + if (!stored) +@@ -1618,7 +1624,8 @@ EXPORT_SYMBOL(printk); + + #else + +-#define LOG_LINE_MAX 0 ++#define LOG_LINE_MAX 0 ++#define PREFIX_MAX 0 + static struct cont { + size_t len; + size_t cons; +@@ -1923,7 +1930,7 @@ static enum log_flags console_prev; + */ + void console_unlock(void) + { +- static char text[LOG_LINE_MAX]; ++ static char text[LOG_LINE_MAX + PREFIX_MAX]; + static u64 seen_seq; + unsigned long flags; + bool wake_klogd = false; +diff --git a/kernel/rcutree.c b/kernel/rcutree.c +index 4b97bba..dd55ba1 100644 +--- a/kernel/rcutree.c ++++ b/kernel/rcutree.c +@@ -304,7 +304,9 @@ cpu_has_callbacks_ready_to_invoke(struct rcu_data *rdp) + static int + cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp) + { +- return *rdp->nxttail[RCU_DONE_TAIL] && !rcu_gp_in_progress(rsp); ++ return *rdp->nxttail[RCU_DONE_TAIL + ++ ACCESS_ONCE(rsp->completed) != rdp->completed] && ++ !rcu_gp_in_progress(rsp); + } + + /* +diff --git a/kernel/sched/core.c b/kernel/sched/core.c +index 468bdd4..9f81a3a 100644 +--- a/kernel/sched/core.c ++++ b/kernel/sched/core.c +@@ -1096,7 +1096,7 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu) + * a task's CPU. ->pi_lock for waking tasks, rq->lock for runnable tasks. + * + * sched_move_task() holds both and thus holding either pins the cgroup, +- * see set_task_rq(). ++ * see task_group(). + * + * Furthermore, all task_rq users should acquire both locks, see + * task_rq_lock(). +@@ -3142,6 +3142,20 @@ void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st) + # define nsecs_to_cputime(__nsecs) nsecs_to_jiffies(__nsecs) + #endif + ++static cputime_t scale_utime(cputime_t utime, cputime_t rtime, cputime_t total) ++{ ++ u64 temp = (__force u64) rtime; ++ ++ temp *= (__force u64) utime; ++ ++ if (sizeof(cputime_t) == 4) ++ temp = div_u64(temp, (__force u32) total); ++ else ++ temp = div64_u64(temp, (__force u64) total); ++ ++ return (__force cputime_t) temp; ++} ++ + void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st) + { + cputime_t rtime, utime = p->utime, total = utime + p->stime; +@@ -3151,13 +3165,9 @@ void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st) + */ + rtime = nsecs_to_cputime(p->se.sum_exec_runtime); + +- if (total) { +- u64 temp = (__force u64) rtime; +- +- temp *= (__force u64) utime; +- do_div(temp, (__force u32) total); +- utime = (__force cputime_t) temp; +- } else ++ if (total) ++ utime = scale_utime(utime, rtime, total); ++ else + utime = rtime; + + /* +@@ -3184,13 +3194,9 @@ void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st) + total = cputime.utime + cputime.stime; + rtime = nsecs_to_cputime(cputime.sum_exec_runtime); + +- if (total) { +- u64 temp = (__force u64) rtime; +- +- temp *= (__force u64) cputime.utime; +- do_div(temp, (__force u32) total); +- utime = (__force cputime_t) temp; +- } else ++ if (total) ++ utime = scale_utime(cputime.utime, rtime, total); ++ else + utime = rtime; + + sig->prev_utime = max(sig->prev_utime, utime); +@@ -7097,34 +7103,66 @@ match2: + mutex_unlock(&sched_domains_mutex); + } + ++static int num_cpus_frozen; /* used to mark begin/end of suspend/resume */ ++ + /* + * Update cpusets according to cpu_active mask. If cpusets are + * disabled, cpuset_update_active_cpus() becomes a simple wrapper + * around partition_sched_domains(). ++ * ++ * If we come here as part of a suspend/resume, don't touch cpusets because we ++ * want to restore it back to its original state upon resume anyway. + */ + static int cpuset_cpu_active(struct notifier_block *nfb, unsigned long action, + void *hcpu) + { +- switch (action & ~CPU_TASKS_FROZEN) { ++ switch (action) { ++ case CPU_ONLINE_FROZEN: ++ case CPU_DOWN_FAILED_FROZEN: ++ ++ /* ++ * num_cpus_frozen tracks how many CPUs are involved in suspend ++ * resume sequence. As long as this is not the last online ++ * operation in the resume sequence, just build a single sched ++ * domain, ignoring cpusets. ++ */ ++ num_cpus_frozen--; ++ if (likely(num_cpus_frozen)) { ++ partition_sched_domains(1, NULL, NULL); ++ break; ++ } ++ ++ /* ++ * This is the last CPU online operation. So fall through and ++ * restore the original sched domains by considering the ++ * cpuset configurations. ++ */ ++ + case CPU_ONLINE: + case CPU_DOWN_FAILED: + cpuset_update_active_cpus(); +- return NOTIFY_OK; ++ break; + default: + return NOTIFY_DONE; + } ++ return NOTIFY_OK; + } + + static int cpuset_cpu_inactive(struct notifier_block *nfb, unsigned long action, + void *hcpu) + { +- switch (action & ~CPU_TASKS_FROZEN) { ++ switch (action) { + case CPU_DOWN_PREPARE: + cpuset_update_active_cpus(); +- return NOTIFY_OK; ++ break; ++ case CPU_DOWN_PREPARE_FROZEN: ++ num_cpus_frozen++; ++ partition_sched_domains(1, NULL, NULL); ++ break; + default: + return NOTIFY_DONE; + } ++ return NOTIFY_OK; + } + + void __init sched_init_smp(void) +@@ -7179,6 +7217,7 @@ int in_sched_functions(unsigned long addr) + + #ifdef CONFIG_CGROUP_SCHED + struct task_group root_task_group; ++LIST_HEAD(task_groups); + #endif + + DECLARE_PER_CPU(cpumask_var_t, load_balance_tmpmask); +@@ -7589,6 +7628,7 @@ void sched_destroy_group(struct task_group *tg) + */ + void sched_move_task(struct task_struct *tsk) + { ++ struct task_group *tg; + int on_rq, running; + unsigned long flags; + struct rq *rq; +@@ -7603,6 +7643,12 @@ void sched_move_task(struct task_struct *tsk) + if (unlikely(running)) + tsk->sched_class->put_prev_task(rq, tsk); + ++ tg = container_of(task_subsys_state_check(tsk, cpu_cgroup_subsys_id, ++ lockdep_is_held(&tsk->sighand->siglock)), ++ struct task_group, css); ++ tg = autogroup_task_group(tsk, tg); ++ tsk->sched_task_group = tg; ++ + #ifdef CONFIG_FAIR_GROUP_SCHED + if (tsk->sched_class->task_move_group) + tsk->sched_class->task_move_group(tsk, on_rq); +diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h +index 55844f2..749f712 100644 +--- a/kernel/sched/sched.h ++++ b/kernel/sched/sched.h +@@ -80,7 +80,7 @@ extern struct mutex sched_domains_mutex; + struct cfs_rq; + struct rt_rq; + +-static LIST_HEAD(task_groups); ++extern struct list_head task_groups; + + struct cfs_bandwidth { + #ifdef CONFIG_CFS_BANDWIDTH +@@ -538,22 +538,19 @@ extern int group_balance_cpu(struct sched_group *sg); + /* + * Return the group to which this tasks belongs. + * +- * We use task_subsys_state_check() and extend the RCU verification with +- * pi->lock and rq->lock because cpu_cgroup_attach() holds those locks for each +- * task it moves into the cgroup. Therefore by holding either of those locks, +- * we pin the task to the current cgroup. ++ * We cannot use task_subsys_state() and friends because the cgroup ++ * subsystem changes that value before the cgroup_subsys::attach() method ++ * is called, therefore we cannot pin it and might observe the wrong value. ++ * ++ * The same is true for autogroup's p->signal->autogroup->tg, the autogroup ++ * core changes this before calling sched_move_task(). ++ * ++ * Instead we use a 'copy' which is updated from sched_move_task() while ++ * holding both task_struct::pi_lock and rq::lock. + */ + static inline struct task_group *task_group(struct task_struct *p) + { +- struct task_group *tg; +- struct cgroup_subsys_state *css; +- +- css = task_subsys_state_check(p, cpu_cgroup_subsys_id, +- lockdep_is_held(&p->pi_lock) || +- lockdep_is_held(&task_rq(p)->lock)); +- tg = container_of(css, struct task_group, css); +- +- return autogroup_task_group(p, tg); ++ return p->sched_task_group; + } + + /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */ +diff --git a/kernel/sys.c b/kernel/sys.c +index 2d39a84..0349bde 100644 +--- a/kernel/sys.c ++++ b/kernel/sys.c +@@ -368,6 +368,7 @@ EXPORT_SYMBOL(unregister_reboot_notifier); + void kernel_restart(char *cmd) + { + kernel_restart_prepare(cmd); ++ disable_nonboot_cpus(); + if (!cmd) + printk(KERN_EMERG "Restarting system.\n"); + else +diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c +index 4a08472..a057ed4 100644 +--- a/kernel/time/tick-sched.c ++++ b/kernel/time/tick-sched.c +@@ -145,6 +145,7 @@ static void tick_nohz_update_jiffies(ktime_t now) + tick_do_update_jiffies64(now); + local_irq_restore(flags); + ++ calc_load_exit_idle(); + touch_softlockup_watchdog(); + } + +diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c +index 3447cfa..63c88c1 100644 +--- a/kernel/time/timekeeping.c ++++ b/kernel/time/timekeeping.c +@@ -384,7 +384,7 @@ int do_settimeofday(const struct timespec *tv) + struct timespec ts_delta; + unsigned long flags; + +- if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC) ++ if (!timespec_valid_strict(tv)) + return -EINVAL; + + write_seqlock_irqsave(&timekeeper.lock, flags); +@@ -418,6 +418,8 @@ EXPORT_SYMBOL(do_settimeofday); + int timekeeping_inject_offset(struct timespec *ts) + { + unsigned long flags; ++ struct timespec tmp; ++ int ret = 0; + + if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) + return -EINVAL; +@@ -426,10 +428,17 @@ int timekeeping_inject_offset(struct timespec *ts) + + timekeeping_forward_now(); + ++ tmp = timespec_add(timekeeper.xtime, *ts); ++ if (!timespec_valid_strict(&tmp)) { ++ ret = -EINVAL; ++ goto error; ++ } ++ + timekeeper.xtime = timespec_add(timekeeper.xtime, *ts); + timekeeper.wall_to_monotonic = + timespec_sub(timekeeper.wall_to_monotonic, *ts); + ++error: /* even if we error out, we forwarded the time, so call update */ + timekeeping_update(true); + + write_sequnlock_irqrestore(&timekeeper.lock, flags); +@@ -437,7 +446,7 @@ int timekeeping_inject_offset(struct timespec *ts) + /* signal hrtimers about time change */ + clock_was_set(); + +- return 0; ++ return ret; + } + EXPORT_SYMBOL(timekeeping_inject_offset); + +@@ -597,7 +606,20 @@ void __init timekeeping_init(void) + struct timespec now, boot; + + read_persistent_clock(&now); ++ if (!timespec_valid_strict(&now)) { ++ pr_warn("WARNING: Persistent clock returned invalid value!\n" ++ " Check your CMOS/BIOS settings.\n"); ++ now.tv_sec = 0; ++ now.tv_nsec = 0; ++ } ++ + read_boot_clock(&boot); ++ if (!timespec_valid_strict(&boot)) { ++ pr_warn("WARNING: Boot clock returned invalid value!\n" ++ " Check your CMOS/BIOS settings.\n"); ++ boot.tv_sec = 0; ++ boot.tv_nsec = 0; ++ } + + seqlock_init(&timekeeper.lock); + +@@ -643,7 +665,7 @@ static void update_sleep_time(struct timespec t) + */ + static void __timekeeping_inject_sleeptime(struct timespec *delta) + { +- if (!timespec_valid(delta)) { ++ if (!timespec_valid_strict(delta)) { + printk(KERN_WARNING "__timekeeping_inject_sleeptime: Invalid " + "sleep delta value!\n"); + return; +@@ -1033,6 +1055,10 @@ static void update_wall_time(void) + #else + offset = (clock->read(clock) - clock->cycle_last) & clock->mask; + #endif ++ /* Check if there's really nothing to do */ ++ if (offset < timekeeper.cycle_interval) ++ goto out; ++ + timekeeper.xtime_nsec = (s64)timekeeper.xtime.tv_nsec << + timekeeper.shift; + +diff --git a/kernel/workqueue.c b/kernel/workqueue.c +index 9a3128d..478f2ab 100644 +--- a/kernel/workqueue.c ++++ b/kernel/workqueue.c +@@ -1869,7 +1869,9 @@ __acquires(&gcwq->lock) + + spin_unlock_irq(&gcwq->lock); + ++ smp_wmb(); /* paired with test_and_set_bit(PENDING) */ + work_clear_pending(work); ++ + lock_map_acquire_read(&cwq->wq->lockdep_map); + lock_map_acquire(&lockdep_map); + trace_workqueue_execute_start(work); +@@ -3441,14 +3443,17 @@ static int __cpuinit trustee_thread(void *__gcwq) + + for_each_busy_worker(worker, i, pos, gcwq) { + struct work_struct *rebind_work = &worker->rebind_work; ++ unsigned long worker_flags = worker->flags; + + /* + * Rebind_work may race with future cpu hotplug + * operations. Use a separate flag to mark that +- * rebinding is scheduled. ++ * rebinding is scheduled. The morphing should ++ * be atomic. + */ +- worker->flags |= WORKER_REBIND; +- worker->flags &= ~WORKER_ROGUE; ++ worker_flags |= WORKER_REBIND; ++ worker_flags &= ~WORKER_ROGUE; ++ ACCESS_ONCE(worker->flags) = worker_flags; + + /* queue rebind_work, wq doesn't matter, use the default one */ + if (test_and_set_bit(WORK_STRUCT_PENDING_BIT, +@@ -3590,21 +3595,55 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, + 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 { +- struct completion completion; ++ struct work_struct work; + long (*fn)(void *); + void *arg; + long ret; + }; + +-static int do_work_for_cpu(void *_wfc) ++static void work_for_cpu_fn(struct work_struct *work) + { +- struct work_for_cpu *wfc = _wfc; ++ struct work_for_cpu *wfc = container_of(work, struct work_for_cpu, work); ++ + wfc->ret = wfc->fn(wfc->arg); +- complete(&wfc->completion); +- return 0; + } + + /** +@@ -3619,19 +3658,11 @@ static int do_work_for_cpu(void *_wfc) + */ + long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg) + { +- struct task_struct *sub_thread; +- struct work_for_cpu wfc = { +- .completion = COMPLETION_INITIALIZER_ONSTACK(wfc.completion), +- .fn = fn, +- .arg = arg, +- }; ++ struct work_for_cpu wfc = { .fn = fn, .arg = arg }; + +- sub_thread = kthread_create(do_work_for_cpu, &wfc, "work_for_cpu"); +- if (IS_ERR(sub_thread)) +- return PTR_ERR(sub_thread); +- kthread_bind(sub_thread, cpu); +- wake_up_process(sub_thread); +- wait_for_completion(&wfc.completion); ++ INIT_WORK_ONSTACK(&wfc.work, work_for_cpu_fn); ++ schedule_work_on(cpu, &wfc.work); ++ flush_work(&wfc.work); + return wfc.ret; + } + EXPORT_SYMBOL_GPL(work_on_cpu); +@@ -3783,7 +3814,8 @@ static int __init init_workqueues(void) + 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 --git a/lib/digsig.c b/lib/digsig.c +index 286d558..8c0e629 100644 +--- a/lib/digsig.c ++++ b/lib/digsig.c +@@ -163,9 +163,11 @@ static int digsig_verify_rsa(struct key *key, + memcpy(out1 + head, p, l); + + err = pkcs_1_v1_5_decode_emsa(out1, len, mblen, out2, &len); ++ if (err) ++ goto err; + +- if (!err && len == hlen) +- err = memcmp(out2, h, hlen); ++ if (len != hlen || memcmp(out2, h, hlen)) ++ err = -EINVAL; + + err: + mpi_free(in); +diff --git a/lib/gcd.c b/lib/gcd.c +index cce4f3c..3657f12 100644 +--- a/lib/gcd.c ++++ b/lib/gcd.c +@@ -9,6 +9,9 @@ unsigned long gcd(unsigned long a, unsigned long b) + + if (a < b) + swap(a, b); ++ ++ if (!b) ++ return a; + while ((r = a % b) != 0) { + a = b; + b = r; +diff --git a/lib/vsprintf.c b/lib/vsprintf.c +index c3f36d41..598a73e 100644 +--- a/lib/vsprintf.c ++++ b/lib/vsprintf.c +@@ -1030,7 +1030,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, + * %pK cannot be used in IRQ context because its test + * for CAP_SYSLOG would be meaningless. + */ +- if (in_irq() || in_serving_softirq() || in_nmi()) { ++ if (kptr_restrict && (in_irq() || in_serving_softirq() || ++ in_nmi())) { + if (spec.field_width == -1) + spec.field_width = default_width; + return string(buf, end, "pK-error", spec); +diff --git a/mm/hugetlb.c b/mm/hugetlb.c +index e198831..9c34eb5 100644 +--- a/mm/hugetlb.c ++++ b/mm/hugetlb.c +@@ -2393,6 +2393,22 @@ void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start, + { + mutex_lock(&vma->vm_file->f_mapping->i_mmap_mutex); + __unmap_hugepage_range(vma, start, end, ref_page); ++ /* ++ * Clear this flag so that x86's huge_pmd_share page_table_shareable ++ * test will fail on a vma being torn down, and not grab a page table ++ * on its way out. We're lucky that the flag has such an appropriate ++ * name, and can in fact be safely cleared here. We could clear it ++ * before the __unmap_hugepage_range above, but all that's necessary ++ * is to clear it before releasing the i_mmap_mutex below. ++ * ++ * This works because in the contexts this is called, the VMA is ++ * going to be destroyed. It is not vunerable to madvise(DONTNEED) ++ * because madvise is not supported on hugetlbfs. The same applies ++ * for direct IO. unmap_hugepage_range() is only being called just ++ * before free_pgtables() so clearing VM_MAYSHARE will not cause ++ * surprises later. ++ */ ++ vma->vm_flags &= ~VM_MAYSHARE; + mutex_unlock(&vma->vm_file->f_mapping->i_mmap_mutex); + } + +@@ -2416,7 +2432,8 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma, + * from page cache lookup which is in HPAGE_SIZE units. + */ + address = address & huge_page_mask(h); +- pgoff = vma_hugecache_offset(h, vma, address); ++ pgoff = ((address - vma->vm_start) >> PAGE_SHIFT) + ++ vma->vm_pgoff; + mapping = vma->vm_file->f_dentry->d_inode->i_mapping; + + /* +@@ -2959,9 +2976,14 @@ void hugetlb_change_protection(struct vm_area_struct *vma, + } + } + spin_unlock(&mm->page_table_lock); +- mutex_unlock(&vma->vm_file->f_mapping->i_mmap_mutex); +- ++ /* ++ * Must flush TLB before releasing i_mmap_mutex: x86's huge_pmd_unshare ++ * may have cleared our pud entry and done put_page on the page table: ++ * once we release i_mmap_mutex, another task can do the final put_page ++ * and that page table be reused and filled with junk. ++ */ + flush_tlb_range(vma, start, end); ++ mutex_unlock(&vma->vm_file->f_mapping->i_mmap_mutex); + } + + int hugetlb_reserve_pages(struct inode *inode, +diff --git a/mm/internal.h b/mm/internal.h +index 2ba87fb..8052379 100644 +--- a/mm/internal.h ++++ b/mm/internal.h +@@ -347,3 +347,5 @@ extern u32 hwpoison_filter_enable; + extern unsigned long vm_mmap_pgoff(struct file *, unsigned long, + unsigned long, unsigned long, + unsigned long, unsigned long); ++ ++extern void set_pageblock_order(void); +diff --git a/mm/memory-failure.c b/mm/memory-failure.c +index ab1e714..6de0d61 100644 +--- a/mm/memory-failure.c ++++ b/mm/memory-failure.c +@@ -345,14 +345,14 @@ static void add_to_kill(struct task_struct *tsk, struct page *p, + * Also when FAIL is set do a force kill because something went + * wrong earlier. + */ +-static void kill_procs(struct list_head *to_kill, int doit, int trapno, ++static void kill_procs(struct list_head *to_kill, int forcekill, int trapno, + int fail, struct page *page, unsigned long pfn, + int flags) + { + struct to_kill *tk, *next; + + list_for_each_entry_safe (tk, next, to_kill, nd) { +- if (doit) { ++ if (forcekill) { + /* + * In case something went wrong with munmapping + * make sure the process doesn't catch the +@@ -858,7 +858,7 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn, + struct address_space *mapping; + LIST_HEAD(tokill); + int ret; +- int kill = 1; ++ int kill = 1, forcekill; + struct page *hpage = compound_head(p); + struct page *ppage; + +@@ -888,7 +888,7 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn, + * be called inside page lock (it's recommended but not enforced). + */ + mapping = page_mapping(hpage); +- if (!PageDirty(hpage) && mapping && ++ if (!(flags & MF_MUST_KILL) && !PageDirty(hpage) && mapping && + mapping_cap_writeback_dirty(mapping)) { + if (page_mkclean(hpage)) { + SetPageDirty(hpage); +@@ -965,12 +965,14 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn, + * Now that the dirty bit has been propagated to the + * struct page and all unmaps done we can decide if + * killing is needed or not. Only kill when the page +- * was dirty, otherwise the tokill list is merely ++ * was dirty or the process is not restartable, ++ * otherwise the tokill list is merely + * freed. When there was a problem unmapping earlier + * use a more force-full uncatchable kill to prevent + * any accesses to the poisoned memory. + */ +- kill_procs(&tokill, !!PageDirty(ppage), trapno, ++ forcekill = PageDirty(ppage) || (flags & MF_MUST_KILL); ++ kill_procs(&tokill, forcekill, trapno, + ret != SWAP_SUCCESS, p, pfn, flags); + + return ret; +@@ -1431,8 +1433,8 @@ static int soft_offline_huge_page(struct page *page, int flags) + /* Keep page count to indicate a given hugepage is isolated. */ + + list_add(&hpage->lru, &pagelist); +- ret = migrate_huge_pages(&pagelist, new_page, MPOL_MF_MOVE_ALL, 0, +- true); ++ ret = migrate_huge_pages(&pagelist, new_page, MPOL_MF_MOVE_ALL, false, ++ MIGRATE_SYNC); + if (ret) { + struct page *page1, *page2; + list_for_each_entry_safe(page1, page2, &pagelist, lru) +@@ -1561,7 +1563,7 @@ int soft_offline_page(struct page *page, int flags) + page_is_file_cache(page)); + list_add(&page->lru, &pagelist); + ret = migrate_pages(&pagelist, new_page, MPOL_MF_MOVE_ALL, +- 0, MIGRATE_SYNC); ++ false, MIGRATE_SYNC); + if (ret) { + putback_lru_pages(&pagelist); + pr_info("soft offline: %#lx: migration failed %d, type %lx\n", +diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c +index 427bb29..0086ac9 100644 +--- a/mm/memory_hotplug.c ++++ b/mm/memory_hotplug.c +@@ -126,9 +126,6 @@ static void register_page_bootmem_info_section(unsigned long start_pfn) + struct mem_section *ms; + struct page *page, *memmap; + +- if (!pfn_valid(start_pfn)) +- return; +- + section_nr = pfn_to_section_nr(start_pfn); + ms = __nr_to_section(section_nr); + +@@ -187,9 +184,16 @@ void register_page_bootmem_info_node(struct pglist_data *pgdat) + end_pfn = pfn + pgdat->node_spanned_pages; + + /* register_section info */ +- for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) +- register_page_bootmem_info_section(pfn); +- ++ for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) { ++ /* ++ * Some platforms can assign the same pfn to multiple nodes - on ++ * node0 as well as nodeN. To avoid registering a pfn against ++ * multiple nodes we check that this pfn does not already ++ * reside in some other node. ++ */ ++ if (pfn_valid(pfn) && (pfn_to_nid(pfn) == node)) ++ register_page_bootmem_info_section(pfn); ++ } + } + #endif /* !CONFIG_SPARSEMEM_VMEMMAP */ + +diff --git a/mm/mempolicy.c b/mm/mempolicy.c +index 1d771e4..cee020c 100644 +--- a/mm/mempolicy.c ++++ b/mm/mempolicy.c +@@ -607,6 +607,42 @@ check_range(struct mm_struct *mm, unsigned long start, unsigned long end, + return first; + } + ++/* ++ * Apply policy to a single VMA ++ * This must be called with the mmap_sem held for writing. ++ */ ++static int vma_replace_policy(struct vm_area_struct *vma, ++ struct mempolicy *pol) ++{ ++ int err; ++ struct mempolicy *old; ++ struct mempolicy *new; ++ ++ pr_debug("vma %lx-%lx/%lx vm_ops %p vm_file %p set_policy %p\n", ++ vma->vm_start, vma->vm_end, vma->vm_pgoff, ++ vma->vm_ops, vma->vm_file, ++ vma->vm_ops ? vma->vm_ops->set_policy : NULL); ++ ++ new = mpol_dup(pol); ++ if (IS_ERR(new)) ++ return PTR_ERR(new); ++ ++ if (vma->vm_ops && vma->vm_ops->set_policy) { ++ err = vma->vm_ops->set_policy(vma, new); ++ if (err) ++ goto err_out; ++ } ++ ++ old = vma->vm_policy; ++ vma->vm_policy = new; /* protected by mmap_sem */ ++ mpol_put(old); ++ ++ return 0; ++ err_out: ++ mpol_put(new); ++ return err; ++} ++ + /* Step 2: apply policy to a range and do splits. */ + static int mbind_range(struct mm_struct *mm, unsigned long start, + unsigned long end, struct mempolicy *new_pol) +@@ -655,23 +691,9 @@ static int mbind_range(struct mm_struct *mm, unsigned long start, + if (err) + goto out; + } +- +- /* +- * Apply policy to a single VMA. The reference counting of +- * policy for vma_policy linkages has already been handled by +- * vma_merge and split_vma as necessary. If this is a shared +- * policy then ->set_policy will increment the reference count +- * for an sp node. +- */ +- pr_debug("vma %lx-%lx/%lx vm_ops %p vm_file %p set_policy %p\n", +- vma->vm_start, vma->vm_end, vma->vm_pgoff, +- vma->vm_ops, vma->vm_file, +- vma->vm_ops ? vma->vm_ops->set_policy : NULL); +- if (vma->vm_ops && vma->vm_ops->set_policy) { +- err = vma->vm_ops->set_policy(vma, new_pol); +- if (err) +- goto out; +- } ++ err = vma_replace_policy(vma, new_pol); ++ if (err) ++ goto out; + } + + out: +@@ -1530,8 +1552,18 @@ struct mempolicy *get_vma_policy(struct task_struct *task, + addr); + if (vpol) + pol = vpol; +- } else if (vma->vm_policy) ++ } else if (vma->vm_policy) { + pol = vma->vm_policy; ++ ++ /* ++ * shmem_alloc_page() passes MPOL_F_SHARED policy with ++ * a pseudo vma whose vma->vm_ops=NULL. Take a reference ++ * count on these policies which will be dropped by ++ * mpol_cond_put() later ++ */ ++ if (mpol_needs_cond_ref(pol)) ++ mpol_get(pol); ++ } + } + if (!pol) + pol = &default_policy; +@@ -2055,7 +2087,7 @@ bool __mpol_equal(struct mempolicy *a, struct mempolicy *b) + */ + + /* lookup first element intersecting start-end */ +-/* Caller holds sp->lock */ ++/* Caller holds sp->mutex */ + static struct sp_node * + sp_lookup(struct shared_policy *sp, unsigned long start, unsigned long end) + { +@@ -2119,36 +2151,50 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx) + + if (!sp->root.rb_node) + return NULL; +- spin_lock(&sp->lock); ++ mutex_lock(&sp->mutex); + sn = sp_lookup(sp, idx, idx+1); + if (sn) { + mpol_get(sn->policy); + pol = sn->policy; + } +- spin_unlock(&sp->lock); ++ mutex_unlock(&sp->mutex); + return pol; + } + ++static void sp_free(struct sp_node *n) ++{ ++ mpol_put(n->policy); ++ kmem_cache_free(sn_cache, n); ++} ++ + static void sp_delete(struct shared_policy *sp, struct sp_node *n) + { + pr_debug("deleting %lx-l%lx\n", n->start, n->end); + rb_erase(&n->nd, &sp->root); +- mpol_put(n->policy); +- kmem_cache_free(sn_cache, n); ++ sp_free(n); + } + + static struct sp_node *sp_alloc(unsigned long start, unsigned long end, + struct mempolicy *pol) + { +- struct sp_node *n = kmem_cache_alloc(sn_cache, GFP_KERNEL); ++ struct sp_node *n; ++ struct mempolicy *newpol; + ++ n = kmem_cache_alloc(sn_cache, GFP_KERNEL); + if (!n) + return NULL; ++ ++ newpol = mpol_dup(pol); ++ if (IS_ERR(newpol)) { ++ kmem_cache_free(sn_cache, n); ++ return NULL; ++ } ++ newpol->flags |= MPOL_F_SHARED; ++ + n->start = start; + n->end = end; +- mpol_get(pol); +- pol->flags |= MPOL_F_SHARED; /* for unref */ +- n->policy = pol; ++ n->policy = newpol; ++ + return n; + } + +@@ -2156,10 +2202,10 @@ static struct sp_node *sp_alloc(unsigned long start, unsigned long end, + static int shared_policy_replace(struct shared_policy *sp, unsigned long start, + unsigned long end, struct sp_node *new) + { +- struct sp_node *n, *new2 = NULL; ++ struct sp_node *n; ++ int ret = 0; + +-restart: +- spin_lock(&sp->lock); ++ mutex_lock(&sp->mutex); + n = sp_lookup(sp, start, end); + /* Take care of old policies in the same range. */ + while (n && n->start < end) { +@@ -2172,16 +2218,14 @@ restart: + } else { + /* Old policy spanning whole new range. */ + if (n->end > end) { ++ struct sp_node *new2; ++ new2 = sp_alloc(end, n->end, n->policy); + if (!new2) { +- spin_unlock(&sp->lock); +- new2 = sp_alloc(end, n->end, n->policy); +- if (!new2) +- return -ENOMEM; +- goto restart; ++ ret = -ENOMEM; ++ goto out; + } + n->end = start; + sp_insert(sp, new2); +- new2 = NULL; + break; + } else + n->end = start; +@@ -2192,12 +2236,9 @@ restart: + } + if (new) + sp_insert(sp, new); +- spin_unlock(&sp->lock); +- if (new2) { +- mpol_put(new2->policy); +- kmem_cache_free(sn_cache, new2); +- } +- return 0; ++out: ++ mutex_unlock(&sp->mutex); ++ return ret; + } + + /** +@@ -2215,7 +2256,7 @@ void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol) + int ret; + + sp->root = RB_ROOT; /* empty tree == default mempolicy */ +- spin_lock_init(&sp->lock); ++ mutex_init(&sp->mutex); + + if (mpol) { + struct vm_area_struct pvma; +@@ -2269,7 +2310,7 @@ int mpol_set_shared_policy(struct shared_policy *info, + } + err = shared_policy_replace(info, vma->vm_pgoff, vma->vm_pgoff+sz, new); + if (err && new) +- kmem_cache_free(sn_cache, new); ++ sp_free(new); + return err; + } + +@@ -2281,16 +2322,14 @@ void mpol_free_shared_policy(struct shared_policy *p) + + if (!p->root.rb_node) + return; +- spin_lock(&p->lock); ++ mutex_lock(&p->mutex); + next = rb_first(&p->root); + while (next) { + n = rb_entry(next, struct sp_node, nd); + next = rb_next(&n->nd); +- rb_erase(&n->nd, &p->root); +- mpol_put(n->policy); +- kmem_cache_free(sn_cache, n); ++ sp_delete(p, n); + } +- spin_unlock(&p->lock); ++ mutex_unlock(&p->mutex); + } + + /* assumes fs == KERNEL_DS */ +@@ -2556,7 +2595,7 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context) + break; + + default: +- BUG(); ++ return -EINVAL; + } + + l = strlen(policy_modes[mode]); +diff --git a/mm/mmap.c b/mm/mmap.c +index ab1b066..5c2cbfd 100644 +--- a/mm/mmap.c ++++ b/mm/mmap.c +@@ -1355,9 +1355,8 @@ out: + } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK)) + make_pages_present(addr, addr + len); + +- if (file && uprobe_mmap(vma)) +- /* matching probes but cannot insert */ +- goto unmap_and_free_vma; ++ if (file) ++ uprobe_mmap(vma); + + return addr; + +diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c +index 9a611d3..862b608 100644 +--- a/mm/mmu_notifier.c ++++ b/mm/mmu_notifier.c +@@ -33,6 +33,24 @@ + void __mmu_notifier_release(struct mm_struct *mm) + { + struct mmu_notifier *mn; ++ struct hlist_node *n; ++ ++ /* ++ * RCU here will block mmu_notifier_unregister until ++ * ->release returns. ++ */ ++ rcu_read_lock(); ++ hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list, hlist) ++ /* ++ * if ->release runs before mmu_notifier_unregister it ++ * must be handled as it's the only way for the driver ++ * to flush all existing sptes and stop the driver ++ * from establishing any more sptes before all the ++ * pages in the mm are freed. ++ */ ++ if (mn->ops->release) ++ mn->ops->release(mn, mm); ++ rcu_read_unlock(); + + spin_lock(&mm->mmu_notifier_mm->lock); + while (unlikely(!hlist_empty(&mm->mmu_notifier_mm->list))) { +@@ -46,23 +64,6 @@ void __mmu_notifier_release(struct mm_struct *mm) + * mmu_notifier_unregister to return. + */ + hlist_del_init_rcu(&mn->hlist); +- /* +- * RCU here will block mmu_notifier_unregister until +- * ->release returns. +- */ +- rcu_read_lock(); +- spin_unlock(&mm->mmu_notifier_mm->lock); +- /* +- * if ->release runs before mmu_notifier_unregister it +- * must be handled as it's the only way for the driver +- * to flush all existing sptes and stop the driver +- * from establishing any more sptes before all the +- * pages in the mm are freed. +- */ +- if (mn->ops->release) +- mn->ops->release(mn, mm); +- rcu_read_unlock(); +- spin_lock(&mm->mmu_notifier_mm->lock); + } + spin_unlock(&mm->mmu_notifier_mm->lock); + +@@ -284,16 +285,13 @@ void mmu_notifier_unregister(struct mmu_notifier *mn, struct mm_struct *mm) + { + BUG_ON(atomic_read(&mm->mm_count) <= 0); + +- spin_lock(&mm->mmu_notifier_mm->lock); + if (!hlist_unhashed(&mn->hlist)) { +- hlist_del_rcu(&mn->hlist); +- + /* + * RCU here will force exit_mmap to wait ->release to finish + * before freeing the pages. + */ + rcu_read_lock(); +- spin_unlock(&mm->mmu_notifier_mm->lock); ++ + /* + * exit_mmap will block in mmu_notifier_release to + * guarantee ->release is called before freeing the +@@ -302,8 +300,11 @@ void mmu_notifier_unregister(struct mmu_notifier *mn, struct mm_struct *mm) + if (mn->ops->release) + mn->ops->release(mn, mm); + rcu_read_unlock(); +- } else ++ ++ spin_lock(&mm->mmu_notifier_mm->lock); ++ hlist_del_rcu(&mn->hlist); + spin_unlock(&mm->mmu_notifier_mm->lock); ++ } + + /* + * Wait any running method to finish, of course including +diff --git a/mm/page_alloc.c b/mm/page_alloc.c +index 4a4f921..34d879e 100644 +--- a/mm/page_alloc.c ++++ b/mm/page_alloc.c +@@ -580,7 +580,7 @@ static inline void __free_one_page(struct page *page, + combined_idx = buddy_idx & page_idx; + higher_page = page + (combined_idx - page_idx); + buddy_idx = __find_buddy_index(combined_idx, order + 1); +- higher_buddy = page + (buddy_idx - combined_idx); ++ higher_buddy = higher_page + (buddy_idx - combined_idx); + if (page_is_buddy(higher_page, higher_buddy, order + 1)) { + list_add_tail(&page->lru, + &zone->free_area[order].free_list[migratetype]); +@@ -4301,7 +4301,7 @@ static inline void setup_usemap(struct pglist_data *pgdat, + #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE + + /* Initialise the number of pages represented by NR_PAGEBLOCK_BITS */ +-static inline void __init set_pageblock_order(void) ++void __init set_pageblock_order(void) + { + unsigned int order; + +@@ -4329,7 +4329,7 @@ static inline void __init set_pageblock_order(void) + * include/linux/pageblock-flags.h for the values of pageblock_order based on + * the kernel config + */ +-static inline void set_pageblock_order(void) ++void __init set_pageblock_order(void) + { + } + +diff --git a/mm/slab.c b/mm/slab.c +index e901a36..da2bb68 100644 +--- a/mm/slab.c ++++ b/mm/slab.c +@@ -1685,9 +1685,6 @@ void __init kmem_cache_init_late(void) + + g_cpucache_up = LATE; + +- /* Annotate slab for lockdep -- annotate the malloc caches */ +- init_lock_keys(); +- + /* 6) resize the head arrays to their final sizes */ + mutex_lock(&cache_chain_mutex); + list_for_each_entry(cachep, &cache_chain, next) +@@ -1695,6 +1692,9 @@ void __init kmem_cache_init_late(void) + BUG(); + mutex_unlock(&cache_chain_mutex); + ++ /* Annotate slab for lockdep -- annotate the malloc caches */ ++ init_lock_keys(); ++ + /* Done! */ + g_cpucache_up = FULL; + +diff --git a/mm/sparse.c b/mm/sparse.c +index c7bb952..950981f 100644 +--- a/mm/sparse.c ++++ b/mm/sparse.c +@@ -493,6 +493,9 @@ void __init sparse_init(void) + struct page **map_map; + #endif + ++ /* Setup pageblock_order for HUGETLB_PAGE_SIZE_VARIABLE */ ++ set_pageblock_order(); ++ + /* + * map is using big page (aka 2M in x86 64 bit) + * usemap is less one page (aka 24 bytes) +diff --git a/mm/truncate.c b/mm/truncate.c +index 75801ac..f38055c 100644 +--- a/mm/truncate.c ++++ b/mm/truncate.c +@@ -394,11 +394,12 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page) + if (page_has_private(page) && !try_to_release_page(page, GFP_KERNEL)) + return 0; + ++ clear_page_mlock(page); ++ + spin_lock_irq(&mapping->tree_lock); + if (PageDirty(page)) + goto failed; + +- clear_page_mlock(page); + BUG_ON(page_has_private(page)); + __delete_from_page_cache(page); + spin_unlock_irq(&mapping->tree_lock); +diff --git a/mm/vmscan.c b/mm/vmscan.c +index 66e4310..f0f8ebb 100644 +--- a/mm/vmscan.c ++++ b/mm/vmscan.c +@@ -720,9 +720,41 @@ static unsigned long shrink_page_list(struct list_head *page_list, + (PageSwapCache(page) && (sc->gfp_mask & __GFP_IO)); + + if (PageWriteback(page)) { +- nr_writeback++; +- unlock_page(page); +- goto keep; ++ /* ++ * memcg doesn't have any dirty pages throttling so we ++ * could easily OOM just because too many pages are in ++ * writeback and there is nothing else to reclaim. ++ * ++ * Check __GFP_IO, certainly because a loop driver ++ * thread might enter reclaim, and deadlock if it waits ++ * on a page for which it is needed to do the write ++ * (loop masks off __GFP_IO|__GFP_FS for this reason); ++ * but more thought would probably show more reasons. ++ * ++ * Don't require __GFP_FS, since we're not going into ++ * the FS, just waiting on its writeback completion. ++ * Worryingly, ext4 gfs2 and xfs allocate pages with ++ * grab_cache_page_write_begin(,,AOP_FLAG_NOFS), so ++ * testing may_enter_fs here is liable to OOM on them. ++ */ ++ if (global_reclaim(sc) || ++ !PageReclaim(page) || !(sc->gfp_mask & __GFP_IO)) { ++ /* ++ * This is slightly racy - end_page_writeback() ++ * might have just cleared PageReclaim, then ++ * setting PageReclaim here end up interpreted ++ * as PageReadahead - but that does not matter ++ * enough to care. What we do want is for this ++ * page to have PageReclaim set next time memcg ++ * reclaim reaches the tests above, so it will ++ * then wait_on_page_writeback() to avoid OOM; ++ * and it's also appropriate in global reclaim. ++ */ ++ SetPageReclaim(page); ++ nr_writeback++; ++ goto keep_locked; ++ } ++ wait_on_page_writeback(page); + } + + references = page_check_references(page, sc); +diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c +index 8ca533c..830059d 100644 +--- a/net/8021q/vlan_core.c ++++ b/net/8021q/vlan_core.c +@@ -105,7 +105,6 @@ static struct sk_buff *vlan_reorder_header(struct sk_buff *skb) + return NULL; + memmove(skb->data - ETH_HLEN, skb->data - VLAN_ETH_HLEN, 2 * ETH_ALEN); + skb->mac_header += VLAN_HLEN; +- skb_reset_mac_len(skb); + return skb; + } + +@@ -139,6 +138,8 @@ struct sk_buff *vlan_untag(struct sk_buff *skb) + + skb_reset_network_header(skb); + skb_reset_transport_header(skb); ++ skb_reset_mac_len(skb); ++ + return skb; + + err_free: +diff --git a/net/atm/common.c b/net/atm/common.c +index b4b44db..0c0ad93 100644 +--- a/net/atm/common.c ++++ b/net/atm/common.c +@@ -812,6 +812,7 @@ int vcc_getsockopt(struct socket *sock, int level, int optname, + + if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags)) + return -ENOTCONN; ++ memset(&pvc, 0, sizeof(pvc)); + pvc.sap_family = AF_ATMPVC; + pvc.sap_addr.itf = vcc->dev->number; + pvc.sap_addr.vpi = vcc->vpi; +diff --git a/net/atm/pvc.c b/net/atm/pvc.c +index 3a73491..ae03240 100644 +--- a/net/atm/pvc.c ++++ b/net/atm/pvc.c +@@ -95,6 +95,7 @@ static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr, + return -ENOTCONN; + *sockaddr_len = sizeof(struct sockaddr_atmpvc); + addr = (struct sockaddr_atmpvc *)sockaddr; ++ memset(addr, 0, sizeof(*addr)); + addr->sap_family = AF_ATMPVC; + addr->sap_addr.itf = vcc->dev->number; + addr->sap_addr.vpi = vcc->vpi; +diff --git a/net/batman-adv/bitarray.h b/net/batman-adv/bitarray.h +index 1835c15..7d1840b 100644 +--- a/net/batman-adv/bitarray.h ++++ b/net/batman-adv/bitarray.h +@@ -22,8 +22,9 @@ + #ifndef _NET_BATMAN_ADV_BITARRAY_H_ + #define _NET_BATMAN_ADV_BITARRAY_H_ + +-/* returns true if the corresponding bit in the given seq_bits indicates true +- * and curr_seqno is within range of last_seqno */ ++/* Returns 1 if the corresponding bit in the given seq_bits indicates true ++ * and curr_seqno is within range of last_seqno. Otherwise returns 0. ++ */ + static inline int bat_test_bit(const unsigned long *seq_bits, + uint32_t last_seqno, uint32_t curr_seqno) + { +@@ -33,7 +34,7 @@ static inline int bat_test_bit(const unsigned long *seq_bits, + if (diff < 0 || diff >= TQ_LOCAL_WINDOW_SIZE) + return 0; + else +- return test_bit(diff, seq_bits); ++ return test_bit(diff, seq_bits) != 0; + } + + /* turn corresponding bit on, so we can remember that we got the packet */ +diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c +index 3f18a6e..d74947d 100644 +--- a/net/bluetooth/hci_conn.c ++++ b/net/bluetooth/hci_conn.c +@@ -42,6 +42,7 @@ + + #include + #include ++#include + + static void hci_le_connect(struct hci_conn *conn) + { +@@ -627,6 +628,9 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) + { + BT_DBG("conn %p", conn); + ++ if (conn->type == LE_LINK) ++ return smp_conn_security(conn, sec_level); ++ + /* For sdp we don't need the link key. */ + if (sec_level == BT_SECURITY_SDP) + return 1; +diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c +index 411ace8..730ff46 100644 +--- a/net/bluetooth/hci_core.c ++++ b/net/bluetooth/hci_core.c +@@ -753,6 +753,8 @@ static int hci_dev_do_close(struct hci_dev *hdev) + + cancel_work_sync(&hdev->le_scan); + ++ cancel_delayed_work(&hdev->power_off); ++ + hci_req_cancel(hdev, ENODEV); + hci_req_lock(hdev); + +diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c +index 94ad124..ad9cae0 100644 +--- a/net/bluetooth/hci_event.c ++++ b/net/bluetooth/hci_event.c +@@ -1375,6 +1375,9 @@ static bool hci_resolve_next_name(struct hci_dev *hdev) + return false; + + e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); ++ if (!e) ++ return false; ++ + if (hci_resolve_name(hdev, e) == 0) { + e->name_state = NAME_PENDING; + return true; +@@ -1403,12 +1406,20 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn, + return; + + e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING); +- if (e) { ++ /* If the device was not found in a list of found devices names of which ++ * are pending. there is no need to continue resolving a next name as it ++ * will be done upon receiving another Remote Name Request Complete ++ * Event */ ++ if (!e) ++ return; ++ ++ list_del(&e->list); ++ if (name) { + e->name_state = NAME_KNOWN; +- list_del(&e->list); +- if (name) +- mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, +- e->data.rssi, name, name_len); ++ mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, ++ e->data.rssi, name, name_len); ++ } else { ++ e->name_state = NAME_NOT_KNOWN; + } + + if (hci_resolve_next_name(hdev)) +@@ -1772,7 +1783,12 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s + if (conn->type == ACL_LINK) { + conn->state = BT_CONFIG; + hci_conn_hold(conn); +- conn->disc_timeout = HCI_DISCONN_TIMEOUT; ++ ++ if (!conn->out && !hci_conn_ssp_enabled(conn) && ++ !hci_find_link_key(hdev, &ev->bdaddr)) ++ conn->disc_timeout = HCI_PAIRING_TIMEOUT; ++ else ++ conn->disc_timeout = HCI_DISCONN_TIMEOUT; + } else + conn->state = BT_CONNECTED; + +diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c +index 5914623..bedc768 100644 +--- a/net/bluetooth/hci_sock.c ++++ b/net/bluetooth/hci_sock.c +@@ -706,6 +706,7 @@ static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, int *add + *addr_len = sizeof(*haddr); + haddr->hci_family = AF_BLUETOOTH; + haddr->hci_dev = hdev->id; ++ haddr->hci_channel= 0; + + release_sock(sk); + return 0; +@@ -1016,6 +1017,7 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname, char + { + struct hci_filter *f = &hci_pi(sk)->filter; + ++ memset(&uf, 0, sizeof(uf)); + uf.type_mask = f->type_mask; + uf.opcode = f->opcode; + uf.event_mask[0] = *((u32 *) f->event_mask + 0); +diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c +index 4554e80..6204170 100644 +--- a/net/bluetooth/l2cap_core.c ++++ b/net/bluetooth/l2cap_core.c +@@ -1163,6 +1163,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn) + sk = chan->sk; + + hci_conn_hold(conn->hcon); ++ conn->hcon->disc_timeout = HCI_DISCONN_TIMEOUT; + + bacpy(&bt_sk(sk)->src, conn->src); + bacpy(&bt_sk(sk)->dst, conn->dst); +@@ -1183,14 +1184,15 @@ clean: + static void l2cap_conn_ready(struct l2cap_conn *conn) + { + struct l2cap_chan *chan; ++ struct hci_conn *hcon = conn->hcon; + + BT_DBG("conn %p", conn); + +- if (!conn->hcon->out && conn->hcon->type == LE_LINK) ++ if (!hcon->out && hcon->type == LE_LINK) + l2cap_le_conn_ready(conn); + +- if (conn->hcon->out && conn->hcon->type == LE_LINK) +- smp_conn_security(conn, conn->hcon->pending_sec_level); ++ if (hcon->out && hcon->type == LE_LINK) ++ smp_conn_security(hcon, hcon->pending_sec_level); + + mutex_lock(&conn->chan_lock); + +@@ -1198,8 +1200,8 @@ static void l2cap_conn_ready(struct l2cap_conn *conn) + + l2cap_chan_lock(chan); + +- if (conn->hcon->type == LE_LINK) { +- if (smp_conn_security(conn, chan->sec_level)) ++ if (hcon->type == LE_LINK) { ++ if (smp_conn_security(hcon, chan->sec_level)) + l2cap_chan_ready(chan); + + } else if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { +diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c +index 3bb1611..9c94d44 100644 +--- a/net/bluetooth/l2cap_sock.c ++++ b/net/bluetooth/l2cap_sock.c +@@ -246,6 +246,7 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *l + + BT_DBG("sock %p, sk %p", sock, sk); + ++ memset(la, 0, sizeof(struct sockaddr_l2)); + addr->sa_family = AF_BLUETOOTH; + *len = sizeof(struct sockaddr_l2); + +@@ -595,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch + break; + } + +- if (smp_conn_security(conn, sec.level)) ++ if (smp_conn_security(conn->hcon, sec.level)) + break; + sk->sk_state = BT_CONFIG; + chan->state = BT_CONFIG; +diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c +index 3e5e336..3571450 100644 +--- a/net/bluetooth/mgmt.c ++++ b/net/bluetooth/mgmt.c +@@ -2879,6 +2879,22 @@ int mgmt_powered(struct hci_dev *hdev, u8 powered) + if (scan) + hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); + ++ if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) { ++ u8 ssp = 1; ++ ++ hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, 1, &ssp); ++ } ++ ++ if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) { ++ struct hci_cp_write_le_host_supported cp; ++ ++ cp.le = 1; ++ cp.simul = !!(hdev->features[6] & LMP_SIMUL_LE_BR); ++ ++ hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, ++ sizeof(cp), &cp); ++ } ++ + update_class(hdev); + update_name(hdev, hdev->dev_name); + update_eir(hdev); +diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c +index e8707de..2df6956 100644 +--- a/net/bluetooth/rfcomm/sock.c ++++ b/net/bluetooth/rfcomm/sock.c +@@ -547,6 +547,7 @@ static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int * + + BT_DBG("sock %p, sk %p", sock, sk); + ++ memset(sa, 0, sizeof(*sa)); + sa->rc_family = AF_BLUETOOTH; + sa->rc_channel = rfcomm_pi(sk)->channel; + if (peer) +@@ -841,6 +842,7 @@ static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, c + } + + sec.level = rfcomm_pi(sk)->sec_level; ++ sec.key_size = 0; + + len = min_t(unsigned int, len, sizeof(sec)); + if (copy_to_user(optval, (char *) &sec, len)) +diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c +index d1820ff..6435296 100644 +--- a/net/bluetooth/rfcomm/tty.c ++++ b/net/bluetooth/rfcomm/tty.c +@@ -461,7 +461,7 @@ static int rfcomm_get_dev_list(void __user *arg) + + size = sizeof(*dl) + dev_num * sizeof(*di); + +- dl = kmalloc(size, GFP_KERNEL); ++ dl = kzalloc(size, GFP_KERNEL); + if (!dl) + return -ENOMEM; + +diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c +index 37df4e9..926043c 100644 +--- a/net/bluetooth/smp.c ++++ b/net/bluetooth/smp.c +@@ -266,10 +266,10 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send) + mgmt_auth_failed(conn->hcon->hdev, conn->dst, hcon->type, + hcon->dst_type, reason); + +- if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) { +- cancel_delayed_work_sync(&conn->security_timer); ++ cancel_delayed_work_sync(&conn->security_timer); ++ ++ if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) + smp_chan_destroy(conn); +- } + } + + #define JUST_WORKS 0x00 +@@ -756,9 +756,9 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) + return 0; + } + +-int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) ++int smp_conn_security(struct hci_conn *hcon, __u8 sec_level) + { +- struct hci_conn *hcon = conn->hcon; ++ struct l2cap_conn *conn = hcon->l2cap_data; + struct smp_chan *smp = conn->smp_chan; + __u8 authreq; + +diff --git a/net/compat.c b/net/compat.c +index 1b96281..74ed1d7 100644 +--- a/net/compat.c ++++ b/net/compat.c +@@ -221,6 +221,8 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat + { + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control; + struct compat_cmsghdr cmhdr; ++ struct compat_timeval ctv; ++ struct compat_timespec cts[3]; + int cmlen; + + if (cm == NULL || kmsg->msg_controllen < sizeof(*cm)) { +@@ -229,8 +231,6 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat + } + + if (!COMPAT_USE_64BIT_TIME) { +- struct compat_timeval ctv; +- struct compat_timespec cts[3]; + if (level == SOL_SOCKET && type == SCM_TIMESTAMP) { + struct timeval *tv = (struct timeval *)data; + ctv.tv_sec = tv->tv_sec; +diff --git a/net/core/dev.c b/net/core/dev.c +index 1cb0d8a..8b3dee5 100644 +--- a/net/core/dev.c ++++ b/net/core/dev.c +@@ -1055,6 +1055,8 @@ rollback: + */ + int dev_set_alias(struct net_device *dev, const char *alias, size_t len) + { ++ char *new_ifalias; ++ + ASSERT_RTNL(); + + if (len >= IFALIASZ) +@@ -1068,9 +1070,10 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len) + return 0; + } + +- dev->ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL); +- if (!dev->ifalias) ++ new_ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL); ++ if (!new_ifalias) + return -ENOMEM; ++ dev->ifalias = new_ifalias; + + strlcpy(dev->ifalias, alias, len+1); + return len; +@@ -1172,6 +1175,7 @@ static int __dev_open(struct net_device *dev) + net_dmaengine_get(); + dev_set_rx_mode(dev); + dev_activate(dev); ++ add_device_randomness(dev->dev_addr, dev->addr_len); + } + + return ret; +@@ -1636,6 +1640,19 @@ static inline int deliver_skb(struct sk_buff *skb, + return pt_prev->func(skb, skb->dev, pt_prev, orig_dev); + } + ++static inline bool skb_loop_sk(struct packet_type *ptype, struct sk_buff *skb) ++{ ++ if (ptype->af_packet_priv == NULL) ++ return false; ++ ++ if (ptype->id_match) ++ return ptype->id_match(ptype, skb->sk); ++ else if ((struct sock *)ptype->af_packet_priv == skb->sk) ++ return true; ++ ++ return false; ++} ++ + /* + * Support routine. Sends outgoing frames to any network + * taps currently in use. +@@ -1653,8 +1670,7 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) + * they originated from - MvS (miquels@drinkel.ow.org) + */ + if ((ptype->dev == dev || !ptype->dev) && +- (ptype->af_packet_priv == NULL || +- (struct sock *)ptype->af_packet_priv != skb->sk)) { ++ (!skb_loop_sk(ptype, skb))) { + if (pt_prev) { + deliver_skb(skb2, pt_prev, skb->dev); + pt_prev = ptype; +@@ -2103,7 +2119,8 @@ static bool can_checksum_protocol(netdev_features_t features, __be16 protocol) + static netdev_features_t harmonize_features(struct sk_buff *skb, + __be16 protocol, netdev_features_t features) + { +- if (!can_checksum_protocol(features, protocol)) { ++ if (skb->ip_summed != CHECKSUM_NONE && ++ !can_checksum_protocol(features, protocol)) { + features &= ~NETIF_F_ALL_CSUM; + features &= ~NETIF_F_SG; + } else if (illegal_highdma(skb->dev, skb)) { +@@ -2118,6 +2135,9 @@ netdev_features_t netif_skb_features(struct sk_buff *skb) + __be16 protocol = skb->protocol; + netdev_features_t features = skb->dev->features; + ++ if (skb_shinfo(skb)->gso_segs > skb->dev->gso_max_segs) ++ features &= ~NETIF_F_GSO_MASK; ++ + if (protocol == htons(ETH_P_8021Q)) { + struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; + protocol = veh->h_vlan_encapsulated_proto; +@@ -2596,15 +2616,16 @@ void __skb_get_rxhash(struct sk_buff *skb) + if (!skb_flow_dissect(skb, &keys)) + return; + +- if (keys.ports) { +- if ((__force u16)keys.port16[1] < (__force u16)keys.port16[0]) +- swap(keys.port16[0], keys.port16[1]); ++ if (keys.ports) + skb->l4_rxhash = 1; +- } + + /* get a consistent hash (same value on both flow directions) */ +- if ((__force u32)keys.dst < (__force u32)keys.src) ++ if (((__force u32)keys.dst < (__force u32)keys.src) || ++ (((__force u32)keys.dst == (__force u32)keys.src) && ++ ((__force u16)keys.port16[1] < (__force u16)keys.port16[0]))) { + swap(keys.dst, keys.src); ++ swap(keys.port16[0], keys.port16[1]); ++ } + + hash = jhash_3words((__force u32)keys.dst, + (__force u32)keys.src, +@@ -4767,6 +4788,7 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa) + err = ops->ndo_set_mac_address(dev, sa); + if (!err) + call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); ++ add_device_randomness(dev->dev_addr, dev->addr_len); + return err; + } + EXPORT_SYMBOL(dev_set_mac_address); +@@ -5545,6 +5567,7 @@ int register_netdevice(struct net_device *dev) + dev_init_scheduler(dev); + dev_hold(dev); + list_netdevice(dev); ++ add_device_randomness(dev->dev_addr, dev->addr_len); + + /* Notify protocols, that a new device appeared. */ + ret = call_netdevice_notifiers(NETDEV_REGISTER, dev); +@@ -5908,6 +5931,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, + dev_net_set(dev, &init_net); + + dev->gso_max_size = GSO_MAX_SIZE; ++ dev->gso_max_segs = GSO_MAX_SEGS; + + INIT_LIST_HEAD(&dev->napi_list); + INIT_LIST_HEAD(&dev->unreg_list); +diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c +index 21318d1..6c50ac0 100644 +--- a/net/core/rtnetlink.c ++++ b/net/core/rtnetlink.c +@@ -674,6 +674,12 @@ static void set_operstate(struct net_device *dev, unsigned char transition) + } + } + ++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) + { +@@ -682,7 +688,7 @@ static unsigned int rtnl_dev_combine_flags(const struct net_device *dev, + /* 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; + } +@@ -1378,6 +1384,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm, + goto errout; + send_addr_notify = 1; + modified = 1; ++ add_device_randomness(dev->dev_addr, dev->addr_len); + } + + if (tb[IFLA_MTU]) { +diff --git a/net/core/sock.c b/net/core/sock.c +index 9e5b71f..c5f765c 100644 +--- a/net/core/sock.c ++++ b/net/core/sock.c +@@ -636,7 +636,8 @@ set_rcvbuf: + + case SO_KEEPALIVE: + #ifdef CONFIG_INET +- if (sk->sk_protocol == IPPROTO_TCP) ++ if (sk->sk_protocol == IPPROTO_TCP && ++ sk->sk_type == SOCK_STREAM) + tcp_set_keepalive(sk, valbool); + #endif + sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool); +@@ -1403,6 +1404,7 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst) + } else { + sk->sk_route_caps |= NETIF_F_SG | NETIF_F_HW_CSUM; + sk->sk_gso_max_size = dst->dev->gso_max_size; ++ sk->sk_gso_max_segs = dst->dev->gso_max_segs; + } + } + } +diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h +index 75c3582..fb85d37 100644 +--- a/net/dccp/ccid.h ++++ b/net/dccp/ccid.h +@@ -246,7 +246,7 @@ static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk, + u32 __user *optval, int __user *optlen) + { + int rc = -ENOPROTOOPT; +- if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL) ++ if (ccid != NULL && ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL) + rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len, + optval, optlen); + return rc; +@@ -257,7 +257,7 @@ static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk, + u32 __user *optval, int __user *optlen) + { + int rc = -ENOPROTOOPT; +- if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL) ++ if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL) + rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len, + optval, optlen); + return rc; +diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c +index 8c67bed..ce0d140 100644 +--- a/net/dccp/ccids/ccid3.c ++++ b/net/dccp/ccids/ccid3.c +@@ -531,6 +531,7 @@ static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len, + case DCCP_SOCKOPT_CCID_TX_INFO: + if (len < sizeof(tfrc)) + return -EINVAL; ++ memset(&tfrc, 0, sizeof(tfrc)); + tfrc.tfrctx_x = hc->tx_x; + tfrc.tfrctx_x_recv = hc->tx_x_recv; + tfrc.tfrctx_x_calc = hc->tx_x_calc; +diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c +index c94bbc6..9be3d17 100644 +--- a/net/ipv4/ipmr.c ++++ b/net/ipv4/ipmr.c +@@ -124,6 +124,8 @@ static DEFINE_SPINLOCK(mfc_unres_lock); + static struct kmem_cache *mrt_cachep __read_mostly; + + static struct mr_table *ipmr_new_table(struct net *net, u32 id); ++static void ipmr_free_table(struct mr_table *mrt); ++ + static int ip_mr_forward(struct net *net, struct mr_table *mrt, + struct sk_buff *skb, struct mfc_cache *cache, + int local); +@@ -131,6 +133,7 @@ static int ipmr_cache_report(struct mr_table *mrt, + struct sk_buff *pkt, vifi_t vifi, int assert); + static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, + struct mfc_cache *c, struct rtmsg *rtm); ++static void mroute_clean_tables(struct mr_table *mrt); + static void ipmr_expire_process(unsigned long arg); + + #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES +@@ -271,7 +274,7 @@ static void __net_exit ipmr_rules_exit(struct net *net) + + list_for_each_entry_safe(mrt, next, &net->ipv4.mr_tables, list) { + list_del(&mrt->list); +- kfree(mrt); ++ ipmr_free_table(mrt); + } + fib_rules_unregister(net->ipv4.mr_rules_ops); + } +@@ -299,7 +302,7 @@ static int __net_init ipmr_rules_init(struct net *net) + + static void __net_exit ipmr_rules_exit(struct net *net) + { +- kfree(net->ipv4.mrt); ++ ipmr_free_table(net->ipv4.mrt); + } + #endif + +@@ -336,6 +339,13 @@ static struct mr_table *ipmr_new_table(struct net *net, u32 id) + return mrt; + } + ++static void ipmr_free_table(struct mr_table *mrt) ++{ ++ del_timer_sync(&mrt->ipmr_expire_timer); ++ mroute_clean_tables(mrt); ++ kfree(mrt); ++} ++ + /* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */ + + static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v) +diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c +index 4032b81..d53aa77 100644 +--- a/net/ipv4/raw.c ++++ b/net/ipv4/raw.c +@@ -131,18 +131,20 @@ found: + * 0 - deliver + * 1 - block + */ +-static __inline__ int icmp_filter(struct sock *sk, struct sk_buff *skb) ++static int icmp_filter(const struct sock *sk, const struct sk_buff *skb) + { +- int type; ++ struct icmphdr _hdr; ++ const struct icmphdr *hdr; + +- if (!pskb_may_pull(skb, sizeof(struct icmphdr))) ++ hdr = skb_header_pointer(skb, skb_transport_offset(skb), ++ sizeof(_hdr), &_hdr); ++ if (!hdr) + return 1; + +- type = icmp_hdr(skb)->type; +- if (type < 32) { ++ if (hdr->type < 32) { + __u32 data = raw_sk(sk)->filter.data; + +- return ((1 << type) & data) != 0; ++ return ((1U << hdr->type) & data) != 0; + } + + /* Do not block unknown ICMP types */ +diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c +index 3ba605f..56e9fa7 100644 +--- a/net/ipv4/tcp.c ++++ b/net/ipv4/tcp.c +@@ -805,7 +805,9 @@ static unsigned int tcp_xmit_size_goal(struct sock *sk, u32 mss_now, + old_size_goal + mss_now > xmit_size_goal)) { + xmit_size_goal = old_size_goal; + } else { +- tp->xmit_size_goal_segs = xmit_size_goal / mss_now; ++ tp->xmit_size_goal_segs = ++ min_t(u16, xmit_size_goal / mss_now, ++ sk->sk_gso_max_segs); + xmit_size_goal = tp->xmit_size_goal_segs * mss_now; + } + } +@@ -1704,8 +1706,14 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, + } + + #ifdef CONFIG_NET_DMA +- if (tp->ucopy.dma_chan) +- dma_async_memcpy_issue_pending(tp->ucopy.dma_chan); ++ if (tp->ucopy.dma_chan) { ++ if (tp->rcv_wnd == 0 && ++ !skb_queue_empty(&sk->sk_async_wait_queue)) { ++ tcp_service_net_dma(sk, true); ++ tcp_cleanup_rbuf(sk, copied); ++ } else ++ dma_async_memcpy_issue_pending(tp->ucopy.dma_chan); ++ } + #endif + if (copied >= target) { + /* Do not sleep, just process backlog. */ +@@ -2625,7 +2633,10 @@ static int do_tcp_setsockopt(struct sock *sk, int level, + /* 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 --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c +index 04dbd7a..41ef65d 100644 +--- a/net/ipv4/tcp_cong.c ++++ b/net/ipv4/tcp_cong.c +@@ -291,7 +291,8 @@ bool tcp_is_cwnd_limited(const struct sock *sk, u32 in_flight) + left = tp->snd_cwnd - in_flight; + if (sk_can_gso(sk) && + left * sysctl_tcp_tso_win_divisor < tp->snd_cwnd && +- left * tp->mss_cache < sk->sk_gso_max_size) ++ left * tp->mss_cache < sk->sk_gso_max_size && ++ left < sk->sk_gso_max_segs) + return true; + return left <= tcp_max_tso_deferred_mss(tp); + } +diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c +index b224eb8..ab30c96 100644 +--- a/net/ipv4/tcp_input.c ++++ b/net/ipv4/tcp_input.c +@@ -3107,13 +3107,14 @@ static void tcp_enter_recovery(struct sock *sk, bool ece_ack) + * tcp_xmit_retransmit_queue(). + */ + static void tcp_fastretrans_alert(struct sock *sk, int pkts_acked, +- int newly_acked_sacked, bool is_dupack, ++ int prior_sacked, bool is_dupack, + int flag) + { + struct inet_connection_sock *icsk = inet_csk(sk); + struct tcp_sock *tp = tcp_sk(sk); + int do_lost = is_dupack || ((flag & FLAG_DATA_SACKED) && + (tcp_fackets_out(tp) > tp->reordering)); ++ int newly_acked_sacked = 0; + int fast_rexmit = 0; + + if (WARN_ON(!tp->packets_out && tp->sacked_out)) +@@ -3173,6 +3174,7 @@ static void tcp_fastretrans_alert(struct sock *sk, int pkts_acked, + tcp_add_reno_sack(sk); + } else + do_lost = tcp_try_undo_partial(sk, pkts_acked); ++ newly_acked_sacked = pkts_acked + tp->sacked_out - prior_sacked; + break; + case TCP_CA_Loss: + if (flag & FLAG_DATA_ACKED) +@@ -3194,6 +3196,7 @@ static void tcp_fastretrans_alert(struct sock *sk, int pkts_acked, + if (is_dupack) + tcp_add_reno_sack(sk); + } ++ newly_acked_sacked = pkts_acked + tp->sacked_out - prior_sacked; + + if (icsk->icsk_ca_state <= TCP_CA_Disorder) + tcp_try_undo_dsack(sk); +@@ -3771,7 +3774,6 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) + int prior_packets; + int prior_sacked = tp->sacked_out; + int pkts_acked = 0; +- int newly_acked_sacked = 0; + bool frto_cwnd = false; + + /* If the ack is older than previous acks +@@ -3847,8 +3849,6 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) + flag |= tcp_clean_rtx_queue(sk, prior_fackets, prior_snd_una); + + pkts_acked = prior_packets - tp->packets_out; +- newly_acked_sacked = (prior_packets - prior_sacked) - +- (tp->packets_out - tp->sacked_out); + + if (tp->frto_counter) + frto_cwnd = tcp_process_frto(sk, flag); +@@ -3862,7 +3862,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) + tcp_may_raise_cwnd(sk, flag)) + tcp_cong_avoid(sk, ack, prior_in_flight); + is_dupack = !(flag & (FLAG_SND_UNA_ADVANCED | FLAG_NOT_DUP)); +- tcp_fastretrans_alert(sk, pkts_acked, newly_acked_sacked, ++ tcp_fastretrans_alert(sk, pkts_acked, prior_sacked, + is_dupack, flag); + } else { + if ((flag & FLAG_DATA_ACKED) && !frto_cwnd) +@@ -3877,7 +3877,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) + no_queue: + /* If data was DSACKed, see if we can undo a cwnd reduction. */ + if (flag & FLAG_DSACKING_ACK) +- tcp_fastretrans_alert(sk, pkts_acked, newly_acked_sacked, ++ tcp_fastretrans_alert(sk, pkts_acked, prior_sacked, + is_dupack, flag); + /* If this ack opens up a zero window, clear backoff. It was + * being used to time the probes, and is probably far higher than +@@ -3897,8 +3897,7 @@ old_ack: + */ + if (TCP_SKB_CB(skb)->sacked) { + flag |= tcp_sacktag_write_queue(sk, skb, prior_snd_una); +- newly_acked_sacked = tp->sacked_out - prior_sacked; +- tcp_fastretrans_alert(sk, pkts_acked, newly_acked_sacked, ++ tcp_fastretrans_alert(sk, pkts_acked, prior_sacked, + is_dupack, flag); + } + +@@ -4819,7 +4818,7 @@ queue_and_out: + + if (eaten > 0) + kfree_skb_partial(skb, fragstolen); +- else if (!sock_flag(sk, SOCK_DEAD)) ++ if (!sock_flag(sk, SOCK_DEAD)) + sk->sk_data_ready(sk, 0); + return; + } +@@ -5602,7 +5601,9 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb, + 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; + } +@@ -5679,8 +5680,7 @@ no_ack: + #endif + if (eaten) + kfree_skb_partial(skb, fragstolen); +- else +- sk->sk_data_ready(sk, 0); ++ sk->sk_data_ready(sk, 0); + return 0; + } + } +diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c +index 803cbfe..90b10d0 100644 +--- a/net/ipv4/tcp_output.c ++++ b/net/ipv4/tcp_output.c +@@ -1334,21 +1334,21 @@ static void tcp_cwnd_validate(struct sock *sk) + * when we would be allowed to send the split-due-to-Nagle skb fully. + */ + static unsigned int tcp_mss_split_point(const struct sock *sk, const struct sk_buff *skb, +- unsigned int mss_now, unsigned int cwnd) ++ unsigned int mss_now, unsigned int max_segs) + { + const struct tcp_sock *tp = tcp_sk(sk); +- u32 needed, window, cwnd_len; ++ u32 needed, window, max_len; + + window = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq; +- cwnd_len = mss_now * cwnd; ++ max_len = mss_now * max_segs; + +- if (likely(cwnd_len <= window && skb != tcp_write_queue_tail(sk))) +- return cwnd_len; ++ if (likely(max_len <= window && skb != tcp_write_queue_tail(sk))) ++ return max_len; + + needed = min(skb->len, window); + +- if (cwnd_len <= needed) +- return cwnd_len; ++ if (max_len <= needed) ++ return max_len; + + return needed - needed % mss_now; + } +@@ -1577,7 +1577,8 @@ static bool tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb) + limit = min(send_win, cong_win); + + /* If a full-sized TSO skb can be sent, do it. */ +- if (limit >= sk->sk_gso_max_size) ++ if (limit >= min_t(unsigned int, sk->sk_gso_max_size, ++ sk->sk_gso_max_segs * tp->mss_cache)) + goto send_now; + + /* Middle in queue won't get any more data, full sendable already? */ +@@ -1803,7 +1804,9 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle, + limit = mss_now; + if (tso_segs > 1 && !tcp_urg_mode(tp)) + limit = tcp_mss_split_point(sk, skb, mss_now, +- cwnd_quota); ++ min_t(unsigned int, ++ cwnd_quota, ++ sk->sk_gso_max_segs)); + + if (skb->len > limit && + unlikely(tso_fragment(sk, skb, limit, mss_now, gfp))) +diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c +index 8f6411c..0344f8e 100644 +--- a/net/ipv6/addrconf.c ++++ b/net/ipv6/addrconf.c +@@ -493,8 +493,7 @@ static void addrconf_forward_change(struct net *net, __s32 newf) + struct net_device *dev; + struct inet6_dev *idev; + +- rcu_read_lock(); +- for_each_netdev_rcu(net, dev) { ++ for_each_netdev(net, dev) { + idev = __in6_dev_get(dev); + if (idev) { + int changed = (!idev->cnf.forwarding) ^ (!newf); +@@ -503,7 +502,6 @@ static void addrconf_forward_change(struct net *net, __s32 newf) + dev_forward_change(idev); + } + } +- rcu_read_unlock(); + } + + static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int newf) +@@ -795,10 +793,16 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp) + struct in6_addr prefix; + struct rt6_info *rt; + struct net *net = dev_net(ifp->idev->dev); ++ struct flowi6 fl6 = {}; ++ + ipv6_addr_prefix(&prefix, &ifp->addr, ifp->prefix_len); +- rt = rt6_lookup(net, &prefix, NULL, ifp->idev->dev->ifindex, 1); ++ fl6.flowi6_oif = ifp->idev->dev->ifindex; ++ fl6.daddr = prefix; ++ rt = (struct rt6_info *)ip6_route_lookup(net, &fl6, ++ RT6_LOOKUP_F_IFACE); + +- if (rt && addrconf_is_prefix_route(rt)) { ++ if (rt != net->ipv6.ip6_null_entry && ++ addrconf_is_prefix_route(rt)) { + if (onlink == 0) { + ip6_del_rt(rt); + rt = NULL; +diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c +index 6083276..0907191 100644 +--- a/net/ipv6/ip6_fib.c ++++ b/net/ipv6/ip6_fib.c +@@ -818,6 +818,10 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info) + offsetof(struct rt6_info, rt6i_src), + allow_create, replace_required); + ++ if (IS_ERR(sn)) { ++ err = PTR_ERR(sn); ++ sn = NULL; ++ } + if (!sn) { + /* If it is failed, discard just allocated + root, and then (in st_failure) stale node +diff --git a/net/ipv6/mip6.c b/net/ipv6/mip6.c +index 5b087c3..0f9bdc5 100644 +--- a/net/ipv6/mip6.c ++++ b/net/ipv6/mip6.c +@@ -86,28 +86,30 @@ static int mip6_mh_len(int type) + + static int mip6_mh_filter(struct sock *sk, struct sk_buff *skb) + { +- struct ip6_mh *mh; ++ struct ip6_mh _hdr; ++ const struct ip6_mh *mh; + +- if (!pskb_may_pull(skb, (skb_transport_offset(skb)) + 8) || +- !pskb_may_pull(skb, (skb_transport_offset(skb) + +- ((skb_transport_header(skb)[1] + 1) << 3)))) ++ mh = skb_header_pointer(skb, skb_transport_offset(skb), ++ sizeof(_hdr), &_hdr); ++ if (!mh) + return -1; + +- mh = (struct ip6_mh *)skb_transport_header(skb); ++ if (((mh->ip6mh_hdrlen + 1) << 3) > skb->len) ++ return -1; + + if (mh->ip6mh_hdrlen < mip6_mh_len(mh->ip6mh_type)) { + LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH message too short: %d vs >=%d\n", + mh->ip6mh_hdrlen, mip6_mh_len(mh->ip6mh_type)); +- mip6_param_prob(skb, 0, ((&mh->ip6mh_hdrlen) - +- skb_network_header(skb))); ++ mip6_param_prob(skb, 0, offsetof(struct ip6_mh, ip6mh_hdrlen) + ++ skb_network_header_len(skb)); + return -1; + } + + if (mh->ip6mh_proto != IPPROTO_NONE) { + LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH invalid payload proto = %d\n", + mh->ip6mh_proto); +- mip6_param_prob(skb, 0, ((&mh->ip6mh_proto) - +- skb_network_header(skb))); ++ mip6_param_prob(skb, 0, offsetof(struct ip6_mh, ip6mh_proto) + ++ skb_network_header_len(skb)); + return -1; + } + +diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c +index 93d6983..9dca4a8 100644 +--- a/net/ipv6/raw.c ++++ b/net/ipv6/raw.c +@@ -107,21 +107,20 @@ found: + * 0 - deliver + * 1 - block + */ +-static __inline__ int icmpv6_filter(struct sock *sk, struct sk_buff *skb) ++static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb) + { +- struct icmp6hdr *icmph; +- struct raw6_sock *rp = raw6_sk(sk); +- +- if (pskb_may_pull(skb, sizeof(struct icmp6hdr))) { +- __u32 *data = &rp->filter.data[0]; +- int bit_nr; ++ struct icmp6hdr *_hdr; ++ const struct icmp6hdr *hdr; + +- icmph = (struct icmp6hdr *) skb->data; +- bit_nr = icmph->icmp6_type; ++ hdr = skb_header_pointer(skb, skb_transport_offset(skb), ++ sizeof(_hdr), &_hdr); ++ if (hdr) { ++ const __u32 *data = &raw6_sk(sk)->filter.data[0]; ++ unsigned int type = hdr->icmp6_type; + +- return (data[bit_nr >> 5] & (1 << (bit_nr & 31))) != 0; ++ return (data[type >> 5] & (1U << (type & 31))) != 0; + } +- return 0; ++ return 1; + } + + #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE) +diff --git a/net/ipv6/route.c b/net/ipv6/route.c +index becb048..a3ef2ad 100644 +--- a/net/ipv6/route.c ++++ b/net/ipv6/route.c +@@ -1485,17 +1485,18 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info) + struct fib6_table *table; + struct net *net = dev_net(rt->dst.dev); + +- if (rt == net->ipv6.ip6_null_entry) +- return -ENOENT; ++ if (rt == net->ipv6.ip6_null_entry) { ++ err = -ENOENT; ++ goto out; ++ } + + table = rt->rt6i_table; + write_lock_bh(&table->tb6_lock); +- + err = fib6_del(rt, info); +- dst_release(&rt->dst); +- + write_unlock_bh(&table->tb6_lock); + ++out: ++ dst_release(&rt->dst); + return err; + } + +diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c +index 32b2155..cb6584f7 100644 +--- a/net/l2tp/l2tp_core.c ++++ b/net/l2tp/l2tp_core.c +@@ -1346,11 +1346,10 @@ static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel) + /* Remove from tunnel list */ + spin_lock_bh(&pn->l2tp_tunnel_list_lock); + list_del_rcu(&tunnel->list); ++ kfree_rcu(tunnel, rcu); + spin_unlock_bh(&pn->l2tp_tunnel_list_lock); +- synchronize_rcu(); + + atomic_dec(&l2tp_tunnel_count); +- kfree(tunnel); + } + + /* Create a socket for the tunnel, if one isn't set up by +diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h +index a38ec6c..56d583e 100644 +--- a/net/l2tp/l2tp_core.h ++++ b/net/l2tp/l2tp_core.h +@@ -163,6 +163,7 @@ struct l2tp_tunnel_cfg { + + struct l2tp_tunnel { + int magic; /* Should be L2TP_TUNNEL_MAGIC */ ++ struct rcu_head rcu; + rwlock_t hlist_lock; /* protect session_hlist */ + struct hlist_head session_hlist[L2TP_HASH_SIZE]; + /* hashed list of sessions, +diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c +index 47b259f..94840d8 100644 +--- a/net/l2tp/l2tp_eth.c ++++ b/net/l2tp/l2tp_eth.c +@@ -148,7 +148,7 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb, + print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, skb->data, length); + } + +- if (!pskb_may_pull(skb, sizeof(ETH_HLEN))) ++ if (!pskb_may_pull(skb, ETH_HLEN)) + goto error; + + secpath_reset(skb); +diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c +index 35e1e4b..9275471 100644 +--- a/net/l2tp/l2tp_ip6.c ++++ b/net/l2tp/l2tp_ip6.c +@@ -410,6 +410,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr, + lsa->l2tp_family = AF_INET6; + lsa->l2tp_flowinfo = 0; + lsa->l2tp_scope_id = 0; ++ lsa->l2tp_unused = 0; + if (peer) { + if (!lsk->peer_conn_id) + return -ENOTCONN; +diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c +index fe5453c..a13c3e2 100644 +--- a/net/llc/af_llc.c ++++ b/net/llc/af_llc.c +@@ -969,14 +969,13 @@ static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr, + struct sockaddr_llc sllc; + struct sock *sk = sock->sk; + struct llc_sock *llc = llc_sk(sk); +- int rc = 0; ++ int rc = -EBADF; + + memset(&sllc, 0, sizeof(sllc)); + lock_sock(sk); + if (sock_flag(sk, SOCK_ZAPPED)) + goto out; + *uaddrlen = sizeof(sllc); +- memset(uaddr, 0, *uaddrlen); + if (peer) { + rc = -ENOTCONN; + if (sk->sk_state != TCP_ESTABLISHED) +diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c +index 2913113..e9494bc 100644 +--- a/net/mac80211/mesh.c ++++ b/net/mac80211/mesh.c +@@ -621,6 +621,7 @@ void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) + + del_timer_sync(&sdata->u.mesh.housekeeping_timer); + del_timer_sync(&sdata->u.mesh.mesh_path_root_timer); ++ del_timer_sync(&sdata->u.mesh.mesh_path_timer); + /* + * If the timer fired while we waited for it, it will have + * requeued the work. Now the work will be running again +diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c +index 0db5d34..92028de 100644 +--- a/net/mac80211/mlme.c ++++ b/net/mac80211/mlme.c +@@ -1805,7 +1805,8 @@ ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, + if (status_code != WLAN_STATUS_SUCCESS) { + printk(KERN_DEBUG "%s: %pM denied authentication (status %d)\n", + sdata->name, mgmt->sa, status_code); +- goto out; ++ ieee80211_destroy_auth_data(sdata, false); ++ return RX_MGMT_CFG80211_RX_AUTH; + } + + switch (ifmgd->auth_data->algorithm) { +@@ -1827,7 +1828,6 @@ ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, + } + + printk(KERN_DEBUG "%s: authenticated\n", sdata->name); +- out: + ifmgd->auth_data->done = true; + ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; + run_again(ifmgd, ifmgd->auth_data->timeout); +@@ -3270,6 +3270,8 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, + goto out_unlock; + + err_clear: ++ memset(ifmgd->bssid, 0, ETH_ALEN); ++ ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); + ifmgd->auth_data = NULL; + err_free: + kfree(auth_data); +@@ -3449,6 +3451,8 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, + err = 0; + goto out; + err_clear: ++ memset(ifmgd->bssid, 0, ETH_ALEN); ++ ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); + ifmgd->assoc_data = NULL; + err_free: + kfree(assoc_data); +diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c +index e453212..85cf32d 100644 +--- a/net/mac80211/tx.c ++++ b/net/mac80211/tx.c +@@ -2733,7 +2733,7 @@ EXPORT_SYMBOL(ieee80211_get_buffered_bc); + void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata, + struct sk_buff *skb, int tid) + { +- int ac = ieee802_1d_to_ac[tid]; ++ int ac = ieee802_1d_to_ac[tid & 7]; + + skb_set_mac_header(skb, 0); + skb_set_network_header(skb, 0); +diff --git a/net/mac80211/util.c b/net/mac80211/util.c +index 8dd4712..f564b5e 100644 +--- a/net/mac80211/util.c ++++ b/net/mac80211/util.c +@@ -268,6 +268,10 @@ EXPORT_SYMBOL(ieee80211_ctstoself_duration); + void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue) + { + struct ieee80211_sub_if_data *sdata; ++ int n_acs = IEEE80211_NUM_ACS; ++ ++ if (local->hw.queues < IEEE80211_NUM_ACS) ++ n_acs = 1; + + list_for_each_entry_rcu(sdata, &local->interfaces, list) { + int ac; +@@ -279,7 +283,7 @@ void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue) + local->queue_stop_reasons[sdata->vif.cab_queue] != 0) + continue; + +- for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { ++ for (ac = 0; ac < n_acs; ac++) { + int ac_queue = sdata->vif.hw_queue[ac]; + + if (ac_queue == queue || +@@ -341,6 +345,7 @@ static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, + { + struct ieee80211_local *local = hw_to_local(hw); + struct ieee80211_sub_if_data *sdata; ++ int n_acs = IEEE80211_NUM_ACS; + + trace_stop_queue(local, queue, reason); + +@@ -352,11 +357,14 @@ static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, + + __set_bit(reason, &local->queue_stop_reasons[queue]); + ++ if (local->hw.queues < IEEE80211_NUM_ACS) ++ n_acs = 1; ++ + rcu_read_lock(); + list_for_each_entry_rcu(sdata, &local->interfaces, list) { + int ac; + +- for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { ++ for (ac = 0; ac < n_acs; ac++) { + if (sdata->vif.hw_queue[ac] == queue || + sdata->vif.cab_queue == queue) + netif_stop_subqueue(sdata->dev, ac); +diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c +index 84444dd..72bf32a 100644 +--- a/net/netfilter/ipvs/ip_vs_ctl.c ++++ b/net/netfilter/ipvs/ip_vs_ctl.c +@@ -2759,6 +2759,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) + { + struct ip_vs_timeout_user t; + ++ memset(&t, 0, sizeof(t)); + __ip_vs_get_timeouts(net, &t); + if (copy_to_user(user, &t, sizeof(t)) != 0) + ret = -EFAULT; +diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c +index b3025a6..20b32fd 100644 +--- a/net/netlink/af_netlink.c ++++ b/net/netlink/af_netlink.c +@@ -1344,7 +1344,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock, + if (NULL == siocb->scm) + siocb->scm = &scm; + +- err = scm_send(sock, msg, siocb->scm); ++ err = scm_send(sock, msg, siocb->scm, true); + if (err < 0) + return err; + +@@ -1355,7 +1355,8 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock, + dst_pid = addr->nl_pid; + dst_group = ffs(addr->nl_groups); + err = -EPERM; +- if (dst_group && !netlink_capable(sock, NL_NONROOT_SEND)) ++ if ((dst_group || dst_pid) && ++ !netlink_capable(sock, NL_NONROOT_SEND)) + goto out; + } else { + dst_pid = nlk->dst_pid; +@@ -2124,6 +2125,7 @@ static void __init netlink_add_usersock_entry(void) + rcu_assign_pointer(nl_table[NETLINK_USERSOCK].listeners, listeners); + nl_table[NETLINK_USERSOCK].module = THIS_MODULE; + nl_table[NETLINK_USERSOCK].registered = 1; ++ nl_table[NETLINK_USERSOCK].nl_nonroot = NL_NONROOT_SEND; + + netlink_table_ungrab(); + } +diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c +index 06592d8..1b9024e 100644 +--- a/net/netrom/af_netrom.c ++++ b/net/netrom/af_netrom.c +@@ -1169,7 +1169,12 @@ static int nr_recvmsg(struct kiocb *iocb, struct socket *sock, + msg->msg_flags |= MSG_TRUNC; + } + +- skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); ++ er = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); ++ if (er < 0) { ++ skb_free_datagram(sk, skb); ++ release_sock(sk); ++ return er; ++ } + + if (sax != NULL) { + sax->sax25_family = AF_NETROM; +diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c +index b6b1d7d..ce5348f 100644 +--- a/net/openvswitch/vport-internal_dev.c ++++ b/net/openvswitch/vport-internal_dev.c +@@ -24,6 +24,9 @@ + #include + #include + ++#include ++#include ++ + #include "datapath.h" + #include "vport-internal_dev.h" + #include "vport-netdev.h" +@@ -209,6 +212,11 @@ static int internal_dev_recv(struct vport *vport, struct sk_buff *skb) + int len; + + len = skb->len; ++ ++ skb_dst_drop(skb); ++ nf_reset(skb); ++ secpath_reset(skb); ++ + skb->dev = netdev; + skb->pkt_type = PACKET_HOST; + skb->protocol = eth_type_trans(skb, netdev); +diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c +index 0f66174..901cffd 100644 +--- a/net/packet/af_packet.c ++++ b/net/packet/af_packet.c +@@ -1280,6 +1280,14 @@ static void __fanout_unlink(struct sock *sk, struct packet_sock *po) + spin_unlock(&f->lock); + } + ++bool match_fanout_group(struct packet_type *ptype, struct sock * sk) ++{ ++ if (ptype->af_packet_priv == (void*)((struct packet_sock *)sk)->fanout) ++ return true; ++ ++ return false; ++} ++ + static int fanout_add(struct sock *sk, u16 id, u16 type_flags) + { + struct packet_sock *po = pkt_sk(sk); +@@ -1332,6 +1340,7 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags) + match->prot_hook.dev = po->prot_hook.dev; + match->prot_hook.func = packet_rcv_fanout; + match->prot_hook.af_packet_priv = match; ++ match->prot_hook.id_match = match_fanout_group; + dev_add_pack(&match->prot_hook); + list_add(&match->list, &fanout_list); + } +@@ -1943,7 +1952,6 @@ static void tpacket_destruct_skb(struct sk_buff *skb) + + if (likely(po->tx_ring.pg_vec)) { + ph = skb_shinfo(skb)->destructor_arg; +- BUG_ON(__packet_get_status(po, ph) != TP_STATUS_SENDING); + BUG_ON(atomic_read(&po->tx_ring.pending) == 0); + atomic_dec(&po->tx_ring.pending); + __packet_set_status(po, ph, TP_STATUS_AVAILABLE); +diff --git a/net/rds/recv.c b/net/rds/recv.c +index 5c6e9f1..9f0f17c 100644 +--- a/net/rds/recv.c ++++ b/net/rds/recv.c +@@ -410,6 +410,8 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, + + rdsdebug("size %zu flags 0x%x timeo %ld\n", size, msg_flags, timeo); + ++ msg->msg_namelen = 0; ++ + if (msg_flags & MSG_OOB) + goto out; + +@@ -485,6 +487,7 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, + sin->sin_port = inc->i_hdr.h_sport; + sin->sin_addr.s_addr = inc->i_saddr; + memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); ++ msg->msg_namelen = sizeof(*sin); + } + break; + } +diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c +index f10fb82..05d60859 100644 +--- a/net/sched/act_gact.c ++++ b/net/sched/act_gact.c +@@ -67,6 +67,9 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est, + struct tcf_common *pc; + int ret = 0; + int err; ++#ifdef CONFIG_GACT_PROB ++ struct tc_gact_p *p_parm = NULL; ++#endif + + if (nla == NULL) + return -EINVAL; +@@ -82,6 +85,12 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est, + #ifndef CONFIG_GACT_PROB + if (tb[TCA_GACT_PROB] != NULL) + return -EOPNOTSUPP; ++#else ++ if (tb[TCA_GACT_PROB]) { ++ p_parm = nla_data(tb[TCA_GACT_PROB]); ++ if (p_parm->ptype >= MAX_RAND) ++ return -EINVAL; ++ } + #endif + + pc = tcf_hash_check(parm->index, a, bind, &gact_hash_info); +@@ -103,8 +112,7 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est, + spin_lock_bh(&gact->tcf_lock); + gact->tcf_action = parm->action; + #ifdef CONFIG_GACT_PROB +- if (tb[TCA_GACT_PROB] != NULL) { +- struct tc_gact_p *p_parm = nla_data(tb[TCA_GACT_PROB]); ++ if (p_parm) { + gact->tcfg_paction = p_parm->paction; + gact->tcfg_pval = p_parm->pval; + gact->tcfg_ptype = p_parm->ptype; +@@ -133,7 +141,7 @@ static int tcf_gact(struct sk_buff *skb, const struct tc_action *a, + + spin_lock(&gact->tcf_lock); + #ifdef CONFIG_GACT_PROB +- if (gact->tcfg_ptype && gact_rand[gact->tcfg_ptype] != NULL) ++ if (gact->tcfg_ptype) + action = gact_rand[gact->tcfg_ptype](gact); + else + action = gact->tcf_action; +diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c +index 6aabd77..564b9fc 100644 +--- a/net/sched/sch_cbq.c ++++ b/net/sched/sch_cbq.c +@@ -250,10 +250,11 @@ cbq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) + else if ((cl = defmap[res.classid & TC_PRIO_MAX]) == NULL) + cl = defmap[TC_PRIO_BESTEFFORT]; + +- if (cl == NULL || cl->level >= head->level) ++ if (cl == NULL) + goto fallback; + } +- ++ if (cl->level >= head->level) ++ goto fallback; + #ifdef CONFIG_NET_CLS_ACT + switch (result) { + case TC_ACT_QUEUED: +diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c +index 9af01f3..d92f169 100644 +--- a/net/sched/sch_qfq.c ++++ b/net/sched/sch_qfq.c +@@ -831,7 +831,10 @@ static void qfq_update_start(struct qfq_sched *q, struct qfq_class *cl) + if (mask) { + struct qfq_group *next = qfq_ffs(q, mask); + if (qfq_gt(roundedF, next->F)) { +- cl->S = next->F; ++ if (qfq_gt(limit, next->F)) ++ cl->S = next->F; ++ else /* preserve timestamp correctness */ ++ cl->S = limit; + return; + } + } +diff --git a/net/sctp/output.c b/net/sctp/output.c +index 6ae47ac..83dddb9 100644 +--- a/net/sctp/output.c ++++ b/net/sctp/output.c +@@ -339,6 +339,25 @@ finish: + return retval; + } + ++static void sctp_packet_release_owner(struct sk_buff *skb) ++{ ++ sk_free(skb->sk); ++} ++ ++static void sctp_packet_set_owner_w(struct sk_buff *skb, struct sock *sk) ++{ ++ skb_orphan(skb); ++ skb->sk = sk; ++ skb->destructor = sctp_packet_release_owner; ++ ++ /* ++ * The data chunks have already been accounted for in sctp_sendmsg(), ++ * therefore only reserve a single byte to keep socket around until ++ * the packet has been transmitted. ++ */ ++ atomic_inc(&sk->sk_wmem_alloc); ++} ++ + /* All packets are sent to the network through this function from + * sctp_outq_tail(). + * +@@ -380,7 +399,7 @@ int sctp_packet_transmit(struct sctp_packet *packet) + /* Set the owning socket so that we know where to get the + * destination IP address. + */ +- skb_set_owner_w(nskb, sk); ++ sctp_packet_set_owner_w(nskb, sk); + + if (!sctp_transport_dst_check(tp)) { + sctp_transport_route(tp, NULL, sctp_sk(sk)); +diff --git a/net/socket.c b/net/socket.c +index 6e0ccc0..bce45cc 100644 +--- a/net/socket.c ++++ b/net/socket.c +@@ -522,6 +522,9 @@ void sock_release(struct socket *sock) + if (rcu_dereference_protected(sock->wq, 1)->fasync_list) + printk(KERN_ERR "sock_release: fasync list not empty!\n"); + ++ if (test_bit(SOCK_EXTERNALLY_ALLOCATED, &sock->flags)) ++ return; ++ + this_cpu_sub(sockets_in_use, 1); + if (!sock->file) { + iput(SOCK_INODE(sock)); +@@ -2602,7 +2605,7 @@ static int do_siocgstamp(struct net *net, struct socket *sock, + err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv); + set_fs(old_fs); + if (!err) +- err = compat_put_timeval(up, &ktv); ++ err = compat_put_timeval(&ktv, up); + + return err; + } +@@ -2618,7 +2621,7 @@ static int do_siocgstampns(struct net *net, struct socket *sock, + err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts); + set_fs(old_fs); + if (!err) +- err = compat_put_timespec(up, &kts); ++ err = compat_put_timespec(&kts, up); + + return err; + } +@@ -2655,6 +2658,7 @@ static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32) + if (copy_from_user(&ifc32, uifc32, sizeof(struct compat_ifconf))) + return -EFAULT; + ++ memset(&ifc, 0, sizeof(ifc)); + if (ifc32.ifcbuf == 0) { + ifc32.ifc_len = 0; + ifc.ifc_len = 0; +diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c +index f56f045..aaf70aa 100644 +--- a/net/sunrpc/clnt.c ++++ b/net/sunrpc/clnt.c +@@ -1844,12 +1844,13 @@ call_timeout(struct rpc_task *task) + return; + } + if (RPC_IS_SOFT(task)) { +- if (clnt->cl_chatty) ++ if (clnt->cl_chatty) { + rcu_read_lock(); + printk(KERN_NOTICE "%s: server %s not responding, timed out\n", + clnt->cl_protname, + rcu_dereference(clnt->cl_xprt)->servername); + rcu_read_unlock(); ++ } + if (task->tk_flags & RPC_TASK_TIMEOUT) + rpc_exit(task, -ETIMEDOUT); + else +diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c +index 92509ff..a70acae 100644 +--- a/net/sunrpc/rpcb_clnt.c ++++ b/net/sunrpc/rpcb_clnt.c +@@ -251,7 +251,7 @@ static int rpcb_create_local_unix(struct net *net) + if (IS_ERR(clnt)) { + dprintk("RPC: failed to create AF_LOCAL rpcbind " + "client (errno %ld).\n", PTR_ERR(clnt)); +- result = -PTR_ERR(clnt); ++ result = PTR_ERR(clnt); + goto out; + } + +@@ -298,7 +298,7 @@ static int rpcb_create_local_net(struct net *net) + if (IS_ERR(clnt)) { + dprintk("RPC: failed to create local rpcbind " + "client (errno %ld).\n", PTR_ERR(clnt)); +- result = -PTR_ERR(clnt); ++ result = PTR_ERR(clnt); + goto out; + } + +diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c +index 994cfea..eda32ae 100644 +--- a/net/sunrpc/sched.c ++++ b/net/sunrpc/sched.c +@@ -790,7 +790,9 @@ void rpc_execute(struct rpc_task *task) + + 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 --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c +index 88f2bf6..bac973a 100644 +--- a/net/sunrpc/svc_xprt.c ++++ b/net/sunrpc/svc_xprt.c +@@ -316,7 +316,6 @@ static bool svc_xprt_has_something_to_do(struct svc_xprt *xprt) + */ + void svc_xprt_enqueue(struct svc_xprt *xprt) + { +- struct svc_serv *serv = xprt->xpt_server; + struct svc_pool *pool; + struct svc_rqst *rqstp; + int cpu; +@@ -362,8 +361,6 @@ void svc_xprt_enqueue(struct svc_xprt *xprt) + rqstp, rqstp->rq_xprt); + rqstp->rq_xprt = xprt; + svc_xprt_get(xprt); +- rqstp->rq_reserved = serv->sv_max_mesg; +- atomic_add(rqstp->rq_reserved, &xprt->xpt_reserved); + pool->sp_stats.threads_woken++; + wake_up(&rqstp->rq_wait); + } else { +@@ -640,8 +637,6 @@ int svc_recv(struct svc_rqst *rqstp, long timeout) + if (xprt) { + rqstp->rq_xprt = xprt; + svc_xprt_get(xprt); +- rqstp->rq_reserved = serv->sv_max_mesg; +- atomic_add(rqstp->rq_reserved, &xprt->xpt_reserved); + + /* As there is a shortage of threads and this request + * had to be queued, don't allow the thread to wait so +@@ -738,6 +733,8 @@ int svc_recv(struct svc_rqst *rqstp, long timeout) + else + len = xprt->xpt_ops->xpo_recvfrom(rqstp); + dprintk("svc: got len=%d\n", len); ++ rqstp->rq_reserved = serv->sv_max_mesg; ++ atomic_add(rqstp->rq_reserved, &xprt->xpt_reserved); + } + svc_xprt_received(xprt); + +@@ -794,7 +791,8 @@ int svc_send(struct svc_rqst *rqstp) + + /* Grab mutex to serialize outgoing data. */ + mutex_lock(&xprt->xpt_mutex); +- if (test_bit(XPT_DEAD, &xprt->xpt_flags)) ++ if (test_bit(XPT_DEAD, &xprt->xpt_flags) ++ || test_bit(XPT_CLOSE, &xprt->xpt_flags)) + len = -ENOTCONN; + else + len = xprt->xpt_ops->xpo_sendto(rqstp); +diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c +index a6de09d..0a63175 100644 +--- a/net/sunrpc/svcsock.c ++++ b/net/sunrpc/svcsock.c +@@ -1129,9 +1129,9 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp) + if (len >= 0) + svsk->sk_tcplen += len; + if (len != want) { ++ svc_tcp_save_pages(svsk, rqstp); + if (len < 0 && len != -EAGAIN) + goto err_other; +- svc_tcp_save_pages(svsk, rqstp); + dprintk("svc: incomplete TCP record (%d of %d)\n", + svsk->sk_tcplen, svsk->sk_reclen); + goto err_noclose; +diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c +index b446e10..06cdbff 100644 +--- a/net/sunrpc/xprtrdma/transport.c ++++ b/net/sunrpc/xprtrdma/transport.c +@@ -200,6 +200,7 @@ xprt_rdma_connect_worker(struct work_struct *work) + int rc = 0; + + if (!xprt->shutdown) { ++ current->flags |= PF_FSTRANS; + xprt_clear_connected(xprt); + + dprintk("RPC: %s: %sconnect\n", __func__, +@@ -212,10 +213,10 @@ xprt_rdma_connect_worker(struct work_struct *work) + + out: + xprt_wake_pending_tasks(xprt, rc); +- + out_clear: + dprintk("RPC: %s: exit\n", __func__); + xprt_clear_connecting(xprt); ++ current->flags &= ~PF_FSTRANS; + } + + /* +diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c +index 890b03f..b88c6bf 100644 +--- a/net/sunrpc/xprtsock.c ++++ b/net/sunrpc/xprtsock.c +@@ -1895,6 +1895,8 @@ static void xs_local_setup_socket(struct work_struct *work) + 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); +@@ -1928,6 +1930,7 @@ static void xs_local_setup_socket(struct work_struct *work) + 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) +@@ -1970,6 +1973,8 @@ static void xs_udp_setup_socket(struct work_struct *work) + 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, +@@ -1988,6 +1993,7 @@ static void xs_udp_setup_socket(struct work_struct *work) + out: + xprt_clear_connecting(xprt); + xprt_wake_pending_tasks(xprt, status); ++ current->flags &= ~PF_FSTRANS; + } + + /* +@@ -2113,6 +2119,8 @@ static void xs_tcp_setup_socket(struct work_struct *work) + if (xprt->shutdown) + goto out; + ++ current->flags |= PF_FSTRANS; ++ + if (!sock) { + clear_bit(XPRT_CONNECTION_ABORT, &xprt->state); + sock = xs_create_sock(xprt, transport, +@@ -2162,6 +2170,7 @@ static void xs_tcp_setup_socket(struct work_struct *work) + case -EINPROGRESS: + case -EALREADY: + xprt_clear_connecting(xprt); ++ current->flags &= ~PF_FSTRANS; + return; + case -EINVAL: + /* Happens, for instance, if the user specified a link +@@ -2174,6 +2183,7 @@ out_eagain: + out: + xprt_clear_connecting(xprt); + xprt_wake_pending_tasks(xprt, status); ++ current->flags &= ~PF_FSTRANS; + } + + /** +diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c +index 641f2e4..9aa708c 100644 +--- a/net/unix/af_unix.c ++++ b/net/unix/af_unix.c +@@ -1448,7 +1448,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock, + if (NULL == siocb->scm) + siocb->scm = &tmp_scm; + wait_for_unix_gc(); +- err = scm_send(sock, msg, siocb->scm); ++ err = scm_send(sock, msg, siocb->scm, false); + if (err < 0) + return err; + +@@ -1617,7 +1617,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock, + if (NULL == siocb->scm) + siocb->scm = &tmp_scm; + wait_for_unix_gc(); +- err = scm_send(sock, msg, siocb->scm); ++ err = scm_send(sock, msg, siocb->scm, false); + if (err < 0) + return err; + +diff --git a/net/wanrouter/wanmain.c b/net/wanrouter/wanmain.c +index 788a12c..2ab7850 100644 +--- a/net/wanrouter/wanmain.c ++++ b/net/wanrouter/wanmain.c +@@ -602,36 +602,31 @@ static int wanrouter_device_new_if(struct wan_device *wandev, + * 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 + +- #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; +- +- lock_adapter_irq(&wandev->lock, &smp_flags); +- +- 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; ++ err = register_netdev(dev); ++ if (!err) { ++ struct net_device *slave = NULL; ++ unsigned long smp_flags=0; ++ ++ lock_adapter_irq(&wandev->lock, &smp_flags); ++ ++ 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 --git a/net/wireless/core.c b/net/wireless/core.c +index a87d435..e98ab2f 100644 +--- a/net/wireless/core.c ++++ b/net/wireless/core.c +@@ -974,6 +974,11 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb, + */ + synchronize_rcu(); + INIT_LIST_HEAD(&wdev->list); ++ /* ++ * Ensure that all events have been processed and ++ * freed. ++ */ ++ cfg80211_process_wdev_events(wdev); + break; + case NETDEV_PRE_UP: + if (!(wdev->wiphy->interface_modes & BIT(wdev->iftype))) +diff --git a/net/wireless/core.h b/net/wireless/core.h +index 8523f38..bc686ef 100644 +--- a/net/wireless/core.h ++++ b/net/wireless/core.h +@@ -426,6 +426,7 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev, + struct net_device *dev, enum nl80211_iftype ntype, + u32 *flags, struct vif_params *params); + void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev); ++void cfg80211_process_wdev_events(struct wireless_dev *wdev); + + int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, +diff --git a/net/wireless/reg.c b/net/wireless/reg.c +index baf5704..b01449f 100644 +--- a/net/wireless/reg.c ++++ b/net/wireless/reg.c +@@ -340,6 +340,9 @@ static void reg_regdb_search(struct work_struct *work) + struct reg_regdb_search_request *request; + const struct ieee80211_regdomain *curdom, *regdom; + int i, r; ++ bool set_reg = false; ++ ++ mutex_lock(&cfg80211_mutex); + + mutex_lock(®_regdb_search_mutex); + while (!list_empty(®_regdb_search_list)) { +@@ -355,9 +358,7 @@ static void reg_regdb_search(struct work_struct *work) + r = reg_copy_regd(®dom, curdom); + if (r) + break; +- mutex_lock(&cfg80211_mutex); +- set_regdom(regdom); +- mutex_unlock(&cfg80211_mutex); ++ set_reg = true; + break; + } + } +@@ -365,6 +366,11 @@ static void reg_regdb_search(struct work_struct *work) + kfree(request); + } + mutex_unlock(®_regdb_search_mutex); ++ ++ if (set_reg) ++ set_regdom(regdom); ++ ++ mutex_unlock(&cfg80211_mutex); + } + + static DECLARE_WORK(reg_regdb_work, reg_regdb_search); +@@ -891,7 +897,21 @@ static void handle_channel(struct wiphy *wiphy, + chan->max_antenna_gain = min(chan->orig_mag, + (int) MBI_TO_DBI(power_rule->max_antenna_gain)); + chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp); +- chan->max_power = min(chan->max_power, chan->max_reg_power); ++ if (chan->orig_mpwr) { ++ /* ++ * Devices that have their own custom regulatory domain ++ * but also use WIPHY_FLAG_STRICT_REGULATORY will follow the ++ * passed country IE power settings. ++ */ ++ if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && ++ wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY && ++ wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) ++ chan->max_power = chan->max_reg_power; ++ else ++ chan->max_power = min(chan->orig_mpwr, ++ chan->max_reg_power); ++ } else ++ chan->max_power = chan->max_reg_power; + } + + static void handle_band(struct wiphy *wiphy, +diff --git a/net/wireless/util.c b/net/wireless/util.c +index 316cfd0..6f13299 100644 +--- a/net/wireless/util.c ++++ b/net/wireless/util.c +@@ -716,7 +716,7 @@ void cfg80211_upload_connect_keys(struct wireless_dev *wdev) + wdev->connect_keys = NULL; + } + +-static void cfg80211_process_wdev_events(struct wireless_dev *wdev) ++void cfg80211_process_wdev_events(struct wireless_dev *wdev) + { + struct cfg80211_event *ev; + unsigned long flags; +diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c +index 54a0dc2..ab2bb42 100644 +--- a/net/xfrm/xfrm_input.c ++++ b/net/xfrm/xfrm_input.c +@@ -212,7 +212,7 @@ resume: + /* only the first xfrm gets the encap type */ + encap_type = 0; + +- if (async && x->repl->check(x, skb, seq)) { ++ if (async && x->repl->recheck(x, skb, seq)) { + XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR); + goto drop_unlock; + } +diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c +index ccfbd32..ce19467 100644 +--- a/net/xfrm/xfrm_policy.c ++++ b/net/xfrm/xfrm_policy.c +@@ -1763,7 +1763,7 @@ static struct dst_entry *make_blackhole(struct net *net, u16 family, + + if (!afinfo) { + dst_release(dst_orig); +- ret = ERR_PTR(-EINVAL); ++ return ERR_PTR(-EINVAL); + } else { + ret = afinfo->blackhole_route(net, dst_orig); + } +diff --git a/net/xfrm/xfrm_replay.c b/net/xfrm/xfrm_replay.c +index 2f6d11d..3efb07d 100644 +--- a/net/xfrm/xfrm_replay.c ++++ b/net/xfrm/xfrm_replay.c +@@ -420,6 +420,18 @@ err: + return -EINVAL; + } + ++static int xfrm_replay_recheck_esn(struct xfrm_state *x, ++ struct sk_buff *skb, __be32 net_seq) ++{ ++ if (unlikely(XFRM_SKB_CB(skb)->seq.input.hi != ++ htonl(xfrm_replay_seqhi(x, net_seq)))) { ++ x->stats.replay_window++; ++ return -EINVAL; ++ } ++ ++ return xfrm_replay_check_esn(x, skb, net_seq); ++} ++ + static void xfrm_replay_advance_esn(struct xfrm_state *x, __be32 net_seq) + { + unsigned int bitnr, nr, i; +@@ -479,6 +491,7 @@ static void xfrm_replay_advance_esn(struct xfrm_state *x, __be32 net_seq) + static struct xfrm_replay xfrm_replay_legacy = { + .advance = xfrm_replay_advance, + .check = xfrm_replay_check, ++ .recheck = xfrm_replay_check, + .notify = xfrm_replay_notify, + .overflow = xfrm_replay_overflow, + }; +@@ -486,6 +499,7 @@ static struct xfrm_replay xfrm_replay_legacy = { + static struct xfrm_replay xfrm_replay_bmp = { + .advance = xfrm_replay_advance_bmp, + .check = xfrm_replay_check_bmp, ++ .recheck = xfrm_replay_check_bmp, + .notify = xfrm_replay_notify_bmp, + .overflow = xfrm_replay_overflow_bmp, + }; +@@ -493,6 +507,7 @@ static struct xfrm_replay xfrm_replay_bmp = { + static struct xfrm_replay xfrm_replay_esn = { + .advance = xfrm_replay_advance_esn, + .check = xfrm_replay_check_esn, ++ .recheck = xfrm_replay_recheck_esn, + .notify = xfrm_replay_notify_bmp, + .overflow = xfrm_replay_overflow_esn, + }; +diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c +index 44293b3..5b054d8 100644 +--- a/net/xfrm/xfrm_user.c ++++ b/net/xfrm/xfrm_user.c +@@ -123,9 +123,21 @@ static inline int verify_replay(struct xfrm_usersa_info *p, + struct nlattr **attrs) + { + struct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL]; ++ struct xfrm_replay_state_esn *rs; + +- if ((p->flags & XFRM_STATE_ESN) && !rt) +- return -EINVAL; ++ if (p->flags & XFRM_STATE_ESN) { ++ if (!rt) ++ return -EINVAL; ++ ++ rs = nla_data(rt); ++ ++ if (rs->bmp_len > XFRMA_REPLAY_ESN_MAX / sizeof(rs->bmp[0]) / 8) ++ return -EINVAL; ++ ++ if (nla_len(rt) < xfrm_replay_state_esn_len(rs) && ++ nla_len(rt) != sizeof(*rs)) ++ return -EINVAL; ++ } + + if (!rt) + return 0; +@@ -370,14 +382,15 @@ static inline int xfrm_replay_verify_len(struct xfrm_replay_state_esn *replay_es + struct nlattr *rp) + { + struct xfrm_replay_state_esn *up; ++ int ulen; + + if (!replay_esn || !rp) + return 0; + + up = nla_data(rp); ++ ulen = xfrm_replay_state_esn_len(up); + +- if (xfrm_replay_state_esn_len(replay_esn) != +- xfrm_replay_state_esn_len(up)) ++ if (nla_len(rp) < ulen || xfrm_replay_state_esn_len(replay_esn) != ulen) + return -EINVAL; + + return 0; +@@ -388,22 +401,28 @@ static int xfrm_alloc_replay_state_esn(struct xfrm_replay_state_esn **replay_esn + struct nlattr *rta) + { + struct xfrm_replay_state_esn *p, *pp, *up; ++ int klen, ulen; + + if (!rta) + return 0; + + up = nla_data(rta); ++ klen = xfrm_replay_state_esn_len(up); ++ ulen = nla_len(rta) >= klen ? klen : sizeof(*up); + +- p = kmemdup(up, xfrm_replay_state_esn_len(up), GFP_KERNEL); ++ p = kzalloc(klen, GFP_KERNEL); + if (!p) + return -ENOMEM; + +- pp = kmemdup(up, xfrm_replay_state_esn_len(up), GFP_KERNEL); ++ pp = kzalloc(klen, GFP_KERNEL); + if (!pp) { + kfree(p); + return -ENOMEM; + } + ++ memcpy(p, up, ulen); ++ memcpy(pp, up, ulen); ++ + *replay_esn = p; + *preplay_esn = pp; + +@@ -442,10 +461,11 @@ static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info * + * somehow made shareable and move it to xfrm_state.c - JHS + * + */ +-static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs) ++static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs, ++ int update_esn) + { + struct nlattr *rp = attrs[XFRMA_REPLAY_VAL]; +- struct nlattr *re = attrs[XFRMA_REPLAY_ESN_VAL]; ++ struct nlattr *re = update_esn ? attrs[XFRMA_REPLAY_ESN_VAL] : NULL; + struct nlattr *lt = attrs[XFRMA_LTIME_VAL]; + struct nlattr *et = attrs[XFRMA_ETIMER_THRESH]; + struct nlattr *rt = attrs[XFRMA_REPLAY_THRESH]; +@@ -555,7 +575,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, + goto error; + + /* override default values from above */ +- xfrm_update_ae_params(x, attrs); ++ xfrm_update_ae_params(x, attrs, 0); + + return x; + +@@ -689,6 +709,7 @@ out: + + static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p) + { ++ memset(p, 0, sizeof(*p)); + memcpy(&p->id, &x->id, sizeof(p->id)); + memcpy(&p->sel, &x->sel, sizeof(p->sel)); + memcpy(&p->lft, &x->lft, sizeof(p->lft)); +@@ -742,7 +763,7 @@ static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb) + return -EMSGSIZE; + + algo = nla_data(nla); +- strcpy(algo->alg_name, auth->alg_name); ++ strncpy(algo->alg_name, auth->alg_name, sizeof(algo->alg_name)); + memcpy(algo->alg_key, auth->alg_key, (auth->alg_key_len + 7) / 8); + algo->alg_key_len = auth->alg_key_len; + +@@ -872,6 +893,7 @@ static struct sk_buff *xfrm_state_netlink(struct sk_buff *in_skb, + { + struct xfrm_dump_info info; + struct sk_buff *skb; ++ int err; + + skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!skb) +@@ -882,9 +904,10 @@ static struct sk_buff *xfrm_state_netlink(struct sk_buff *in_skb, + info.nlmsg_seq = seq; + info.nlmsg_flags = 0; + +- if (dump_one_state(x, 0, &info)) { ++ err = dump_one_state(x, 0, &info); ++ if (err) { + kfree_skb(skb); +- return NULL; ++ return ERR_PTR(err); + } + + return skb; +@@ -1309,6 +1332,7 @@ static void copy_from_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy + + static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_info *p, int dir) + { ++ memset(p, 0, sizeof(*p)); + memcpy(&p->sel, &xp->selector, sizeof(p->sel)); + memcpy(&p->lft, &xp->lft, sizeof(p->lft)); + memcpy(&p->curlft, &xp->curlft, sizeof(p->curlft)); +@@ -1413,6 +1437,7 @@ static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb) + struct xfrm_user_tmpl *up = &vec[i]; + struct xfrm_tmpl *kp = &xp->xfrm_vec[i]; + ++ memset(up, 0, sizeof(*up)); + memcpy(&up->id, &kp->id, sizeof(up->id)); + up->family = kp->encap_family; + memcpy(&up->saddr, &kp->saddr, sizeof(up->saddr)); +@@ -1541,6 +1566,7 @@ static struct sk_buff *xfrm_policy_netlink(struct sk_buff *in_skb, + { + struct xfrm_dump_info info; + struct sk_buff *skb; ++ int err; + + skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) +@@ -1551,9 +1577,10 @@ static struct sk_buff *xfrm_policy_netlink(struct sk_buff *in_skb, + info.nlmsg_seq = seq; + info.nlmsg_flags = 0; + +- if (dump_one_policy(xp, dir, 0, &info) < 0) { ++ err = dump_one_policy(xp, dir, 0, &info); ++ if (err) { + kfree_skb(skb); +- return NULL; ++ return ERR_PTR(err); + } + + return skb; +@@ -1812,7 +1839,7 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, + goto out; + + spin_lock_bh(&x->lock); +- xfrm_update_ae_params(x, attrs); ++ xfrm_update_ae_params(x, attrs, 1); + spin_unlock_bh(&x->lock); + + c.event = nlh->nlmsg_type; +diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include +index 6a3ee98..978416d 100644 +--- a/scripts/Kbuild.include ++++ b/scripts/Kbuild.include +@@ -98,24 +98,24 @@ try-run = $(shell set -e; \ + # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) + + as-option = $(call try-run,\ +- $(CC) $(KBUILD_CFLAGS) $(1) -c -xassembler /dev/null -o "$$TMP",$(1),$(2)) ++ $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) + + # as-instr + # Usage: cflags-y += $(call as-instr,instr,option1,option2) + + as-instr = $(call try-run,\ +- printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3)) ++ printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) + + # cc-option + # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) + + cc-option = $(call try-run,\ +- $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2)) ++ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) + + # cc-option-yn + # Usage: flag := $(call cc-option-yn,-march=winchip-c6) + cc-option-yn = $(call try-run,\ +- $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",y,n) ++ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) + + # cc-option-align + # Prefix align with either -falign or -malign +@@ -125,7 +125,7 @@ cc-option-align = $(subst -functions=0,,\ + # cc-disable-warning + # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) + cc-disable-warning = $(call try-run,\ +- $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -xc /dev/null -o "$$TMP",-Wno-$(strip $(1))) ++ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) + + # cc-version + # Usage gcc-ver := $(call cc-version) +@@ -143,7 +143,7 @@ cc-ifversion = $(shell [ $(call cc-version, $(CC)) $(1) $(2) ] && echo $(3)) + # cc-ldoption + # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) + cc-ldoption = $(call try-run,\ +- $(CC) $(1) -nostdlib -xc /dev/null -o "$$TMP",$(1),$(2)) ++ $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) + + # ld-option + # Usage: LDFLAGS += $(call ld-option, -X) +@@ -209,7 +209,7 @@ endif + # >$< substitution to preserve $ when reloading .cmd file + # note: when using inline perl scripts [perl -e '...$$t=1;...'] + # in $(cmd_xxx) double $$ your perl vars +-make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))) ++make-cmd = $(subst \\,\\\\,$(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1)))))) + + # Find any prerequisites that is newer than target or that does not exist. + # PHONY targets skipped in both cases. +diff --git a/scripts/gcc-version.sh b/scripts/gcc-version.sh +index debecb5..7f2126d 100644 +--- a/scripts/gcc-version.sh ++++ b/scripts/gcc-version.sh +@@ -22,10 +22,10 @@ if [ ${#compiler} -eq 0 ]; then + exit 1 + fi + +-MAJOR=$(echo __GNUC__ | $compiler -E -xc - | tail -n 1) +-MINOR=$(echo __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1) ++MAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1) ++MINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1) + if [ "x$with_patchlevel" != "x" ] ; then +- PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -xc - | tail -n 1) ++ PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1) + printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL + else + printf "%02d%02d\\n" $MAJOR $MINOR +diff --git a/scripts/gcc-x86_32-has-stack-protector.sh b/scripts/gcc-x86_32-has-stack-protector.sh +index 29493dc..12dbd0b 100644 +--- a/scripts/gcc-x86_32-has-stack-protector.sh ++++ b/scripts/gcc-x86_32-has-stack-protector.sh +@@ -1,6 +1,6 @@ + #!/bin/sh + +-echo "int foo(void) { char X[200]; return 3; }" | $* -S -xc -c -O0 -fstack-protector - -o - 2> /dev/null | grep -q "%gs" ++echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -O0 -fstack-protector - -o - 2> /dev/null | grep -q "%gs" + if [ "$?" -eq "0" ] ; then + echo y + else +diff --git a/scripts/gcc-x86_64-has-stack-protector.sh b/scripts/gcc-x86_64-has-stack-protector.sh +index afaec61..973e8c1 100644 +--- a/scripts/gcc-x86_64-has-stack-protector.sh ++++ b/scripts/gcc-x86_64-has-stack-protector.sh +@@ -1,6 +1,6 @@ + #!/bin/sh + +-echo "int foo(void) { char X[200]; return 3; }" | $* -S -xc -c -O0 -mcmodel=kernel -fstack-protector - -o - 2> /dev/null | grep -q "%gs" ++echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -O0 -mcmodel=kernel -fstack-protector - -o - 2> /dev/null | grep -q "%gs" + if [ "$?" -eq "0" ] ; then + echo y + else +diff --git a/scripts/kconfig/check.sh b/scripts/kconfig/check.sh +index fa59cbf..854d9c7 100755 +--- a/scripts/kconfig/check.sh ++++ b/scripts/kconfig/check.sh +@@ -1,6 +1,6 @@ + #!/bin/sh + # Needed for systems without gettext +-$* -xc -o /dev/null - > /dev/null 2>&1 << EOF ++$* -x c -o /dev/null - > /dev/null 2>&1 << EOF + #include + int main() + { +diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh +index 82cc3a8..50df490 100644 +--- a/scripts/kconfig/lxdialog/check-lxdialog.sh ++++ b/scripts/kconfig/lxdialog/check-lxdialog.sh +@@ -38,7 +38,7 @@ trap "rm -f $tmp" 0 1 2 3 15 + + # Check if we can link to ncurses + check() { +- $cc -xc - -o $tmp 2>/dev/null <<'EOF' ++ $cc -x c - -o $tmp 2>/dev/null <<'EOF' + #include CURSES_LOC + main() {} + EOF +diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl +index bccf07dd..3346f42 100644 +--- a/scripts/kconfig/streamline_config.pl ++++ b/scripts/kconfig/streamline_config.pl +@@ -463,6 +463,8 @@ while() { + if (defined($configs{$1})) { + if ($localyesconfig) { + $setconfigs{$1} = 'y'; ++ print "$1=y\n"; ++ next; + } else { + $setconfigs{$1} = $2; + } +diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c +index ffd8900..db10db2 100644 +--- a/security/selinux/hooks.c ++++ b/security/selinux/hooks.c +@@ -2129,7 +2129,7 @@ static inline void flush_unauthorized_files(const struct cred *cred, + int fd; + + j++; +- i = j * __NFDBITS; ++ i = j * BITS_PER_LONG; + fdt = files_fdtable(files); + if (i >= fdt->max_fds) + break; +@@ -2792,11 +2792,16 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name, + + /* We strip a nul only if it is at the end, otherwise the + * context contains a nul and we should audit that */ +- str = value; +- if (str[size - 1] == '\0') +- audit_size = size - 1; +- else +- audit_size = size; ++ if (value) { ++ str = value; ++ if (str[size - 1] == '\0') ++ audit_size = size - 1; ++ else ++ audit_size = size; ++ } else { ++ str = ""; ++ audit_size = 0; ++ } + ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR); + audit_log_format(ab, "op=setxattr invalid_context="); + audit_log_n_untrustedstring(ab, value, audit_size); +diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c +index 1810c9a..cb6d904 100644 +--- a/security/smack/smackfs.c ++++ b/security/smack/smackfs.c +@@ -325,11 +325,11 @@ static int smk_parse_long_rule(const char *data, struct smack_rule *rule, + int datalen; + int rc = -1; + +- /* +- * This is probably inefficient, but safe. +- */ ++ /* This is inefficient */ + datalen = strlen(data); +- subject = kzalloc(datalen, GFP_KERNEL); ++ ++ /* Our first element can be 64 + \0 with no spaces */ ++ subject = kzalloc(datalen + 1, GFP_KERNEL); + if (subject == NULL) + return -1; + object = kzalloc(datalen, GFP_KERNEL); +diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c +index 83554ee..dcd6178 100644 +--- a/security/yama/yama_lsm.c ++++ b/security/yama/yama_lsm.c +@@ -143,7 +143,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3, + if (arg2 == 0) { + yama_ptracer_del(NULL, myself); + rc = 0; +- } else if (arg2 == PR_SET_PTRACER_ANY) { ++ } else if (arg2 == PR_SET_PTRACER_ANY || (int)arg2 == -1) { + rc = yama_ptracer_add(NULL, myself); + } else { + struct task_struct *tracer; +@@ -279,12 +279,46 @@ static int yama_ptrace_access_check(struct task_struct *child, + } + + if (rc) { +- char name[sizeof(current->comm)]; + printk_ratelimited(KERN_NOTICE + "ptrace of pid %d was attempted by: %s (pid %d)\n", +- child->pid, +- get_task_comm(name, current), +- current->pid); ++ child->pid, current->comm, current->pid); ++ } ++ ++ return rc; ++} ++ ++/** ++ * yama_ptrace_traceme - validate PTRACE_TRACEME calls ++ * @parent: task that will become the ptracer of the current task ++ * ++ * Returns 0 if following the ptrace is allowed, -ve on error. ++ */ ++static int yama_ptrace_traceme(struct task_struct *parent) ++{ ++ int rc; ++ ++ /* If standard caps disallows it, so does Yama. We should ++ * only tighten restrictions further. ++ */ ++ rc = cap_ptrace_traceme(parent); ++ if (rc) ++ return rc; ++ ++ /* Only disallow PTRACE_TRACEME on more aggressive settings. */ ++ switch (ptrace_scope) { ++ case YAMA_SCOPE_CAPABILITY: ++ if (!ns_capable(task_user_ns(parent), CAP_SYS_PTRACE)) ++ rc = -EPERM; ++ break; ++ case YAMA_SCOPE_NO_ATTACH: ++ rc = -EPERM; ++ break; ++ } ++ ++ if (rc) { ++ printk_ratelimited(KERN_NOTICE ++ "ptraceme of pid %d was attempted by: %s (pid %d)\n", ++ current->pid, parent->comm, parent->pid); + } + + return rc; +@@ -294,6 +328,7 @@ static struct security_operations yama_ops = { + .name = "yama", + + .ptrace_access_check = yama_ptrace_access_check, ++ .ptrace_traceme = yama_ptrace_traceme, + .task_prctl = yama_task_prctl, + .task_free = yama_task_free, + }; +diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c +index 270790d..4cedc69 100644 +--- a/sound/aoa/codecs/onyx.c ++++ b/sound/aoa/codecs/onyx.c +@@ -997,45 +997,10 @@ static void onyx_exit_codec(struct aoa_codec *codec) + onyx->codec.soundbus_dev->detach_codec(onyx->codec.soundbus_dev, onyx); + } + +-static int onyx_create(struct i2c_adapter *adapter, +- struct device_node *node, +- int addr) +-{ +- struct i2c_board_info info; +- struct i2c_client *client; +- +- memset(&info, 0, sizeof(struct i2c_board_info)); +- strlcpy(info.type, "aoa_codec_onyx", I2C_NAME_SIZE); +- info.addr = addr; +- info.platform_data = node; +- client = i2c_new_device(adapter, &info); +- if (!client) +- return -ENODEV; +- +- /* +- * We know the driver is already loaded, so the device should be +- * already bound. If not it means binding failed, which suggests +- * the device doesn't really exist and should be deleted. +- * Ideally this would be replaced by better checks _before_ +- * instantiating the device. +- */ +- if (!client->driver) { +- i2c_unregister_device(client); +- return -ENODEV; +- } +- +- /* +- * Let i2c-core delete that device on driver removal. +- * This is safe because i2c-core holds the core_lock mutex for us. +- */ +- list_add_tail(&client->detected, &client->driver->clients); +- return 0; +-} +- + static int onyx_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) + { +- struct device_node *node = client->dev.platform_data; ++ struct device_node *node = client->dev.of_node; + struct onyx *onyx; + u8 dummy; + +@@ -1071,40 +1036,6 @@ static int onyx_i2c_probe(struct i2c_client *client, + return -ENODEV; + } + +-static int onyx_i2c_attach(struct i2c_adapter *adapter) +-{ +- struct device_node *busnode, *dev = NULL; +- struct pmac_i2c_bus *bus; +- +- bus = pmac_i2c_adapter_to_bus(adapter); +- if (bus == NULL) +- return -ENODEV; +- busnode = pmac_i2c_get_bus_node(bus); +- +- while ((dev = of_get_next_child(busnode, dev)) != NULL) { +- if (of_device_is_compatible(dev, "pcm3052")) { +- const u32 *addr; +- printk(KERN_DEBUG PFX "found pcm3052\n"); +- addr = of_get_property(dev, "reg", NULL); +- if (!addr) +- return -ENODEV; +- return onyx_create(adapter, dev, (*addr)>>1); +- } +- } +- +- /* if that didn't work, try desperate mode for older +- * machines that have stuff missing from the device tree */ +- +- if (!of_device_is_compatible(busnode, "k2-i2c")) +- return -ENODEV; +- +- printk(KERN_DEBUG PFX "found k2-i2c, checking if onyx chip is on it\n"); +- /* probe both possible addresses for the onyx chip */ +- if (onyx_create(adapter, NULL, 0x46) == 0) +- return 0; +- return onyx_create(adapter, NULL, 0x47); +-} +- + static int onyx_i2c_remove(struct i2c_client *client) + { + struct onyx *onyx = i2c_get_clientdata(client); +@@ -1117,16 +1048,16 @@ static int onyx_i2c_remove(struct i2c_client *client) + } + + static const struct i2c_device_id onyx_i2c_id[] = { +- { "aoa_codec_onyx", 0 }, ++ { "MAC,pcm3052", 0 }, + { } + }; ++MODULE_DEVICE_TABLE(i2c,onyx_i2c_id); + + static struct i2c_driver onyx_driver = { + .driver = { + .name = "aoa_codec_onyx", + .owner = THIS_MODULE, + }, +- .attach_adapter = onyx_i2c_attach, + .probe = onyx_i2c_probe, + .remove = onyx_i2c_remove, + .id_table = onyx_i2c_id, +diff --git a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c +index 8e63d1f..c491ae0 100644 +--- a/sound/aoa/codecs/tas.c ++++ b/sound/aoa/codecs/tas.c +@@ -883,43 +883,10 @@ static void tas_exit_codec(struct aoa_codec *codec) + } + + +-static int tas_create(struct i2c_adapter *adapter, +- struct device_node *node, +- int addr) +-{ +- struct i2c_board_info info; +- struct i2c_client *client; +- +- memset(&info, 0, sizeof(struct i2c_board_info)); +- strlcpy(info.type, "aoa_codec_tas", I2C_NAME_SIZE); +- info.addr = addr; +- info.platform_data = node; +- +- client = i2c_new_device(adapter, &info); +- if (!client) +- return -ENODEV; +- /* +- * We know the driver is already loaded, so the device should be +- * already bound. If not it means binding failed, and then there +- * is no point in keeping the device instantiated. +- */ +- if (!client->driver) { +- i2c_unregister_device(client); +- return -ENODEV; +- } +- +- /* +- * Let i2c-core delete that device on driver removal. +- * This is safe because i2c-core holds the core_lock mutex for us. +- */ +- list_add_tail(&client->detected, &client->driver->clients); +- return 0; +-} +- + static int tas_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) + { +- struct device_node *node = client->dev.platform_data; ++ struct device_node *node = client->dev.of_node; + struct tas *tas; + + tas = kzalloc(sizeof(struct tas), GFP_KERNEL); +@@ -953,47 +920,6 @@ static int tas_i2c_probe(struct i2c_client *client, + return -EINVAL; + } + +-static int tas_i2c_attach(struct i2c_adapter *adapter) +-{ +- struct device_node *busnode, *dev = NULL; +- struct pmac_i2c_bus *bus; +- +- bus = pmac_i2c_adapter_to_bus(adapter); +- if (bus == NULL) +- return -ENODEV; +- busnode = pmac_i2c_get_bus_node(bus); +- +- while ((dev = of_get_next_child(busnode, dev)) != NULL) { +- if (of_device_is_compatible(dev, "tas3004")) { +- const u32 *addr; +- printk(KERN_DEBUG PFX "found tas3004\n"); +- addr = of_get_property(dev, "reg", NULL); +- if (!addr) +- continue; +- return tas_create(adapter, dev, ((*addr) >> 1) & 0x7f); +- } +- /* older machines have no 'codec' node with a 'compatible' +- * property that says 'tas3004', they just have a 'deq' +- * node without any such property... */ +- if (strcmp(dev->name, "deq") == 0) { +- const u32 *_addr; +- u32 addr; +- printk(KERN_DEBUG PFX "found 'deq' node\n"); +- _addr = of_get_property(dev, "i2c-address", NULL); +- if (!_addr) +- continue; +- addr = ((*_addr) >> 1) & 0x7f; +- /* now, if the address doesn't match any of the two +- * that a tas3004 can have, we cannot handle this. +- * I doubt it ever happens but hey. */ +- if (addr != 0x34 && addr != 0x35) +- continue; +- return tas_create(adapter, dev, addr); +- } +- } +- return -ENODEV; +-} +- + static int tas_i2c_remove(struct i2c_client *client) + { + struct tas *tas = i2c_get_clientdata(client); +@@ -1011,16 +937,16 @@ static int tas_i2c_remove(struct i2c_client *client) + } + + static const struct i2c_device_id tas_i2c_id[] = { +- { "aoa_codec_tas", 0 }, ++ { "MAC,tas3004", 0 }, + { } + }; ++MODULE_DEVICE_TABLE(i2c,tas_i2c_id); + + static struct i2c_driver tas_driver = { + .driver = { + .name = "aoa_codec_tas", + .owner = THIS_MODULE, + }, +- .attach_adapter = tas_i2c_attach, + .probe = tas_i2c_probe, + .remove = tas_i2c_remove, + .id_table = tas_i2c_id, +diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c +index 8b5c36f..c5d463c 100644 +--- a/sound/drivers/aloop.c ++++ b/sound/drivers/aloop.c +@@ -120,6 +120,7 @@ struct loopback_pcm { + unsigned int last_drift; + unsigned long last_jiffies; + struct timer_list timer; ++ spinlock_t timer_lock; + }; + + static struct platform_device *devices[SNDRV_CARDS]; +@@ -170,6 +171,7 @@ static void loopback_timer_start(struct loopback_pcm *dpcm) + unsigned long tick; + unsigned int rate_shift = get_rate_shift(dpcm); + ++ spin_lock(&dpcm->timer_lock); + if (rate_shift != dpcm->pcm_rate_shift) { + dpcm->pcm_rate_shift = rate_shift; + dpcm->period_size_frac = frac_pos(dpcm, dpcm->pcm_period_size); +@@ -182,12 +184,15 @@ static void loopback_timer_start(struct loopback_pcm *dpcm) + tick = (tick + dpcm->pcm_bps - 1) / dpcm->pcm_bps; + dpcm->timer.expires = jiffies + tick; + add_timer(&dpcm->timer); ++ spin_unlock(&dpcm->timer_lock); + } + + static inline void loopback_timer_stop(struct loopback_pcm *dpcm) + { ++ spin_lock(&dpcm->timer_lock); + del_timer(&dpcm->timer); + dpcm->timer.expires = 0; ++ spin_unlock(&dpcm->timer_lock); + } + + #define CABLE_VALID_PLAYBACK (1 << SNDRV_PCM_STREAM_PLAYBACK) +@@ -667,6 +672,7 @@ static int loopback_open(struct snd_pcm_substream *substream) + dpcm->substream = substream; + setup_timer(&dpcm->timer, loopback_timer_function, + (unsigned long)dpcm); ++ spin_lock_init(&dpcm->timer_lock); + + cable = loopback->cables[substream->number][dev]; + if (!cable) { +diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c +index 1cff331..4608c2c 100644 +--- a/sound/drivers/mpu401/mpu401_uart.c ++++ b/sound/drivers/mpu401/mpu401_uart.c +@@ -554,6 +554,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device, + 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 --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c +index 51cb2a2..f1c6164 100644 +--- a/sound/pci/hda/hda_codec.c ++++ b/sound/pci/hda/hda_codec.c +@@ -2325,6 +2325,7 @@ int snd_hda_codec_reset(struct hda_codec *codec) + } + if (codec->patch_ops.free) + codec->patch_ops.free(codec); ++ memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); + snd_hda_jack_tbl_clear(codec); + codec->proc_widget_hook = NULL; + codec->spec = NULL; +@@ -2340,7 +2341,6 @@ int snd_hda_codec_reset(struct hda_codec *codec) + codec->num_pcms = 0; + codec->pcm_info = NULL; + codec->preset = NULL; +- memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); + codec->slave_dig_outs = NULL; + codec->spdif_status_reset = 0; + module_put(codec->owner); +@@ -4418,6 +4418,15 @@ static void __snd_hda_power_up(struct hda_codec *codec, bool wait_power_down) + cancel_delayed_work_sync(&codec->power_work); + + spin_lock(&codec->power_lock); ++ /* If the power down delayed work was cancelled above before starting, ++ * then there is no need to go through power up here. ++ */ ++ if (codec->power_on) { ++ if (codec->power_transition < 0) ++ codec->power_transition = 0; ++ spin_unlock(&codec->power_lock); ++ return; ++ } + trace_hda_power_up(codec); + snd_hda_update_power_acct(codec); + codec->power_on = 1; +diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c +index e59e2f0..0074aee 100644 +--- a/sound/pci/hda/hda_proc.c ++++ b/sound/pci/hda/hda_proc.c +@@ -412,7 +412,7 @@ static void print_digital_conv(struct snd_info_buffer *buffer, + if (digi1 & AC_DIG1_EMPHASIS) + snd_iprintf(buffer, " Preemphasis"); + if (digi1 & AC_DIG1_COPYRIGHT) +- snd_iprintf(buffer, " Copyright"); ++ snd_iprintf(buffer, " Non-Copyright"); + if (digi1 & AC_DIG1_NONAUDIO) + snd_iprintf(buffer, " Non-Audio"); + if (digi1 & AC_DIG1_PROFESSIONAL) +diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c +index d0d3540..cf70dab 100644 +--- a/sound/pci/hda/patch_ca0132.c ++++ b/sound/pci/hda/patch_ca0132.c +@@ -275,6 +275,10 @@ static int _add_switch(struct hda_codec *codec, hda_nid_t nid, const char *pfx, + int type = dir ? HDA_INPUT : HDA_OUTPUT; + struct snd_kcontrol_new knew = + HDA_CODEC_MUTE_MONO(namestr, nid, chan, 0, type); ++ if ((query_amp_caps(codec, nid, type) & AC_AMPCAP_MUTE) == 0) { ++ snd_printdd("Skipping '%s %s Switch' (no mute on node 0x%x)\n", pfx, dirstr[dir], nid); ++ return 0; ++ } + sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]); + return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); + } +@@ -286,6 +290,10 @@ static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx, + int type = dir ? HDA_INPUT : HDA_OUTPUT; + struct snd_kcontrol_new knew = + HDA_CODEC_VOLUME_MONO(namestr, nid, chan, 0, type); ++ if ((query_amp_caps(codec, nid, type) & AC_AMPCAP_NUM_STEPS) == 0) { ++ snd_printdd("Skipping '%s %s Volume' (no amp on node 0x%x)\n", pfx, dirstr[dir], nid); ++ return 0; ++ } + sprintf(namestr, "%s %s Volume", pfx, dirstr[dir]); + return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); + } +diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c +index 2bf99fc..afa5b4d 100644 +--- a/sound/pci/hda/patch_conexant.c ++++ b/sound/pci/hda/patch_conexant.c +@@ -2972,7 +2972,6 @@ static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { + SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), + SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), + SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), +- SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), + SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), + SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), + SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), +@@ -4468,6 +4467,7 @@ static const struct snd_pci_quirk cxt5066_fixups[] = { + SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), + SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), + SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), ++ SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC), + SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC), + {} + }; +diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c +index ad319d4d..5d52332 100644 +--- a/sound/pci/hda/patch_hdmi.c ++++ b/sound/pci/hda/patch_hdmi.c +@@ -876,7 +876,6 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, + struct hdmi_spec_per_pin *per_pin; + struct hdmi_eld *eld; + struct hdmi_spec_per_cvt *per_cvt = NULL; +- int pinctl; + + /* Validate hinfo */ + pin_idx = hinfo_to_pin_index(spec, hinfo); +@@ -912,11 +911,6 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, + snd_hda_codec_write(codec, per_pin->pin_nid, 0, + AC_VERB_SET_CONNECT_SEL, + mux_idx); +- pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0, +- AC_VERB_GET_PIN_WIDGET_CONTROL, 0); +- snd_hda_codec_write(codec, per_pin->pin_nid, 0, +- AC_VERB_SET_PIN_WIDGET_CONTROL, +- pinctl | PIN_OUT); + snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid); + + /* Initially set the converter's capabilities */ +@@ -1153,11 +1147,17 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, + struct hdmi_spec *spec = codec->spec; + int pin_idx = hinfo_to_pin_index(spec, hinfo); + hda_nid_t pin_nid = spec->pins[pin_idx].pin_nid; ++ int pinctl; + + hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels); + + hdmi_setup_audio_infoframe(codec, pin_idx, substream); + ++ pinctl = snd_hda_codec_read(codec, pin_nid, 0, ++ AC_VERB_GET_PIN_WIDGET_CONTROL, 0); ++ snd_hda_codec_write(codec, pin_nid, 0, ++ AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl | PIN_OUT); ++ + return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format); + } + +diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c +index aa4c25e..95b9090 100644 +--- a/sound/pci/hda/patch_realtek.c ++++ b/sound/pci/hda/patch_realtek.c +@@ -201,6 +201,7 @@ struct alc_spec { + unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */ + unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ + unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ ++ unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */ + + /* auto-mute control */ + int automute_mode; +@@ -4182,7 +4183,8 @@ static int alc_parse_auto_config(struct hda_codec *codec, + return 0; /* can't find valid BIOS pin config */ + } + +- if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && ++ if (!spec->no_primary_hp && ++ cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && + cfg->line_outs <= cfg->hp_outs) { + /* use HP as primary out */ + cfg->speaker_outs = cfg->line_outs; +@@ -4909,6 +4911,7 @@ enum { + ALC889_FIXUP_DAC_ROUTE, + ALC889_FIXUP_MBP_VREF, + ALC889_FIXUP_IMAC91_VREF, ++ ALC882_FIXUP_NO_PRIMARY_HP, + }; + + static void alc889_fixup_coef(struct hda_codec *codec, +@@ -5030,6 +5033,17 @@ static void alc889_fixup_imac91_vref(struct hda_codec *codec, + spec->keep_vref_in_automute = 1; + } + ++/* Don't take HP output as primary ++ * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05 ++ */ ++static void alc882_fixup_no_primary_hp(struct hda_codec *codec, ++ const struct alc_fixup *fix, int action) ++{ ++ struct alc_spec *spec = codec->spec; ++ if (action == ALC_FIXUP_ACT_PRE_PROBE) ++ spec->no_primary_hp = 1; ++} ++ + static const struct alc_fixup alc882_fixups[] = { + [ALC882_FIXUP_ABIT_AW9D_MAX] = { + .type = ALC_FIXUP_PINS, +@@ -5212,6 +5226,10 @@ static const struct alc_fixup alc882_fixups[] = { + .chained = true, + .chain_id = ALC882_FIXUP_GPIO1, + }, ++ [ALC882_FIXUP_NO_PRIMARY_HP] = { ++ .type = ALC_FIXUP_FUNC, ++ .v.func = alc882_fixup_no_primary_hp, ++ }, + }; + + static const struct snd_pci_quirk alc882_fixup_tbl[] = { +@@ -5246,6 +5264,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = { + SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC), + SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601), + SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT), ++ SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP), + + /* All Apple entries are in codec SSIDs */ + SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF), +@@ -5286,6 +5305,7 @@ static const struct alc_model_fixup alc882_fixup_models[] = { + {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"}, + {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"}, + {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"}, ++ {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"}, + {} + }; + +@@ -5704,6 +5724,15 @@ static int alc269_resume(struct hda_codec *codec) + } + #endif /* CONFIG_PM */ + ++static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec, ++ const struct alc_fixup *fix, int action) ++{ ++ struct alc_spec *spec = codec->spec; ++ ++ if (action == ALC_FIXUP_ACT_PRE_PROBE) ++ spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; ++} ++ + static void alc269_fixup_hweq(struct hda_codec *codec, + const struct alc_fixup *fix, int action) + { +@@ -5828,6 +5857,8 @@ enum { + ALC269VB_FIXUP_AMIC, + ALC269VB_FIXUP_DMIC, + ALC269_FIXUP_MIC2_MUTE_LED, ++ ALC269_FIXUP_LENOVO_DOCK, ++ ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT, + }; + + static const struct alc_fixup alc269_fixups[] = { +@@ -5889,6 +5920,8 @@ static const struct alc_fixup alc269_fixups[] = { + [ALC269_FIXUP_PCM_44K] = { + .type = ALC_FIXUP_FUNC, + .v.func = alc269_fixup_pcm_44k, ++ .chained = true, ++ .chain_id = ALC269_FIXUP_QUANTA_MUTE + }, + [ALC269_FIXUP_STEREO_DMIC] = { + .type = ALC_FIXUP_FUNC, +@@ -5952,6 +5985,20 @@ static const struct alc_fixup alc269_fixups[] = { + .type = ALC_FIXUP_FUNC, + .v.func = alc269_fixup_mic2_mute, + }, ++ [ALC269_FIXUP_LENOVO_DOCK] = { ++ .type = ALC_FIXUP_PINS, ++ .v.pins = (const struct alc_pincfg[]) { ++ { 0x19, 0x23a11040 }, /* dock mic */ ++ { 0x1b, 0x2121103f }, /* dock headphone */ ++ { } ++ }, ++ .chained = true, ++ .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT ++ }, ++ [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = { ++ .type = ALC_FIXUP_FUNC, ++ .v.func = alc269_fixup_pincfg_no_hp_to_lineout, ++ }, + }; + + static const struct snd_pci_quirk alc269_fixup_tbl[] = { +@@ -5975,8 +6022,11 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = { + SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), + SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), + SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), +- SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE), +- SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K), ++ SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK), ++ SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK), ++ SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK), ++ SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK), ++ SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K), + SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), + + #if 0 +@@ -6033,6 +6083,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = { + static const struct alc_model_fixup alc269_fixup_models[] = { + {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, + {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, ++ {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"}, + {} + }; + +@@ -6094,6 +6145,12 @@ static int patch_alc269(struct hda_codec *codec) + + spec = codec->spec; + ++ alc_pick_fixup(codec, alc269_fixup_models, ++ alc269_fixup_tbl, alc269_fixups); ++ alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); ++ ++ alc_auto_parse_customize_define(codec); ++ + if (codec->vendor_id == 0x10ec0269) { + spec->codec_variant = ALC269_TYPE_ALC269VA; + switch (alc_get_coef0(codec) & 0x00f0) { +@@ -6121,12 +6178,6 @@ static int patch_alc269(struct hda_codec *codec) + alc269_fill_coef(codec); + } + +- alc_pick_fixup(codec, alc269_fixup_models, +- alc269_fixup_tbl, alc269_fixups); +- alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); +- +- alc_auto_parse_customize_define(codec); +- + /* automatic parse from the BIOS config */ + err = alc269_parse_auto_config(codec); + if (err < 0) +@@ -6831,6 +6882,7 @@ static const struct hda_codec_preset snd_hda_preset_realtek[] = { + { .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 --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c +index 0767528..b98aded 100644 +--- a/sound/pci/hda/patch_sigmatel.c ++++ b/sound/pci/hda/patch_sigmatel.c +@@ -101,6 +101,8 @@ enum { + STAC_92HD83XXX_HP_cNB11_INTQUAD, + STAC_HP_DV7_4000, + STAC_HP_ZEPHYR, ++ STAC_92HD83XXX_HP_LED, ++ STAC_92HD83XXX_HP_INV_LED, + STAC_92HD83XXX_MODELS + }; + +@@ -1073,7 +1075,7 @@ static struct snd_kcontrol_new stac_smux_mixer = { + + static const char * const slave_pfxs[] = { + "Front", "Surround", "Center", "LFE", "Side", +- "Headphone", "Speaker", "IEC958", ++ "Headphone", "Speaker", "IEC958", "PCM", + NULL + }; + +@@ -1675,6 +1677,8 @@ static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = { + [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad", + [STAC_HP_DV7_4000] = "hp-dv7-4000", + [STAC_HP_ZEPHYR] = "hp-zephyr", ++ [STAC_92HD83XXX_HP_LED] = "hp-led", ++ [STAC_92HD83XXX_HP_INV_LED] = "hp-inv-led", + }; + + static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = { +@@ -1729,6 +1733,8 @@ static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = { + "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD), + SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561, + "HP", STAC_HP_ZEPHYR), ++ SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3660, ++ "HP Mini", STAC_92HD83XXX_HP_LED), + {} /* terminator */ + }; + +@@ -4414,7 +4420,12 @@ static int stac92xx_init(struct hda_codec *codec) + snd_hda_jack_report_sync(codec); + + /* sync mute LED */ +- snd_hda_sync_vmaster_hook(&spec->vmaster_mute); ++ if (spec->gpio_led) { ++ if (spec->vmaster_mute.hook) ++ snd_hda_sync_vmaster_hook(&spec->vmaster_mute); ++ else /* the very first init call doesn't have vmaster yet */ ++ stac92xx_update_led_status(codec, false); ++ } + + /* sync the power-map */ + if (spec->num_pwrs) +@@ -5507,6 +5518,7 @@ static void stac92hd8x_fill_auto_spec(struct hda_codec *codec) + static int patch_stac92hd83xxx(struct hda_codec *codec) + { + struct sigmatel_spec *spec; ++ int default_polarity = -1; /* no default cfg */ + int err; + + spec = kzalloc(sizeof(*spec), GFP_KERNEL); +@@ -5555,9 +5567,15 @@ again: + case STAC_HP_ZEPHYR: + spec->init = stac92hd83xxx_hp_zephyr_init; + break; ++ case STAC_92HD83XXX_HP_LED: ++ default_polarity = 0; ++ break; ++ case STAC_92HD83XXX_HP_INV_LED: ++ default_polarity = 1; ++ break; + } + +- if (find_mute_led_cfg(codec, -1/*no default cfg*/)) ++ if (find_mute_led_cfg(codec, default_polarity)) + snd_printd("mute LED gpio %d polarity %d\n", + spec->gpio_led, + spec->gpio_led_polarity); +diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c +index 82b3680..9c35043 100644 +--- a/sound/pci/hda/patch_via.c ++++ b/sound/pci/hda/patch_via.c +@@ -3226,7 +3226,7 @@ static void set_widgets_power_state_vt1718S(struct hda_codec *codec) + { + struct via_spec *spec = codec->spec; + int imux_is_smixer; +- unsigned int parm; ++ unsigned int parm, parm2; + /* MUX6 (1eh) = stereo mixer */ + imux_is_smixer = + snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; +@@ -3249,7 +3249,7 @@ static void set_widgets_power_state_vt1718S(struct hda_codec *codec) + parm = AC_PWRST_D3; + set_pin_power_state(codec, 0x27, &parm); + update_power_state(codec, 0x1a, parm); +- update_power_state(codec, 0xb, parm); ++ parm2 = parm; /* for pin 0x0b */ + + /* PW2 (26h), AOW2 (ah) */ + parm = AC_PWRST_D3; +@@ -3264,6 +3264,9 @@ static void set_widgets_power_state_vt1718S(struct hda_codec *codec) + if (!spec->hp_independent_mode) /* check for redirected HP */ + set_pin_power_state(codec, 0x28, &parm); + update_power_state(codec, 0x8, parm); ++ if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3) ++ parm = parm2; ++ update_power_state(codec, 0xb, parm); + /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ + update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm); + +@@ -3658,6 +3661,32 @@ static void set_widgets_power_state_vt2002P(struct hda_codec *codec) + update_power_state(codec, 0x21, AC_PWRST_D3); + } + ++/* ++ * pin fix-up ++ */ ++enum { ++ VIA_FIXUP_INTMIC_BOOST, ++}; ++ ++static void via_fixup_intmic_boost(struct hda_codec *codec, ++ const struct hda_fixup *fix, int action) ++{ ++ if (action == HDA_FIXUP_ACT_PRE_PROBE) ++ override_mic_boost(codec, 0x30, 0, 2, 40); ++} ++ ++static const struct hda_fixup via_fixups[] = { ++ [VIA_FIXUP_INTMIC_BOOST] = { ++ .type = HDA_FIXUP_FUNC, ++ .v.func = via_fixup_intmic_boost, ++ }, ++}; ++ ++static const struct snd_pci_quirk vt2002p_fixups[] = { ++ SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST), ++ {} ++}; ++ + /* patch for vt2002P */ + static int patch_vt2002P(struct hda_codec *codec) + { +@@ -3674,6 +3703,9 @@ static int patch_vt2002P(struct hda_codec *codec) + override_mic_boost(codec, 0x29, 0, 3, 40); + add_secret_dac_path(codec); + ++ snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups); ++ snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); ++ + /* automatic parse from the BIOS config */ + err = via_parse_auto_config(codec); + if (err < 0) { +diff --git a/sound/pci/ice1712/prodigy_hifi.c b/sound/pci/ice1712/prodigy_hifi.c +index 764cc93..075d5aa 100644 +--- a/sound/pci/ice1712/prodigy_hifi.c ++++ b/sound/pci/ice1712/prodigy_hifi.c +@@ -297,6 +297,7 @@ static int ak4396_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem + } + + static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -12700, 100, 1); ++static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); + + static struct snd_kcontrol_new prodigy_hd2_controls[] __devinitdata = { + { +@@ -307,7 +308,7 @@ static struct snd_kcontrol_new prodigy_hd2_controls[] __devinitdata = { + .info = ak4396_dac_vol_info, + .get = ak4396_dac_vol_get, + .put = ak4396_dac_vol_put, +- .tlv = { .p = db_scale_wm_dac }, ++ .tlv = { .p = ak4396_db_scale }, + }, + }; + +diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c +index 0418fa1..45f2faf 100644 +--- a/sound/soc/codecs/wm2000.c ++++ b/sound/soc/codecs/wm2000.c +@@ -675,7 +675,7 @@ static int wm2000_resume(struct snd_soc_codec *codec) + #endif + + static const struct regmap_config wm2000_regmap = { +- .reg_bits = 8, ++ .reg_bits = 16, + .val_bits = 8, + }; + +diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c +index 0cfce99..dab6256 100644 +--- a/sound/soc/codecs/wm8962.c ++++ b/sound/soc/codecs/wm8962.c +@@ -2501,6 +2501,9 @@ static int wm8962_set_bias_level(struct snd_soc_codec *codec, + /* 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: +@@ -3722,6 +3725,9 @@ static int wm8962_runtime_resume(struct device *dev) + } + + regcache_cache_only(wm8962->regmap, false); ++ ++ wm8962_reset(wm8962); ++ + regcache_sync(wm8962->regmap); + + regmap_update_bits(wm8962->regmap, WM8962_ANTI_POP, +diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c +index 1436b6c..fc9afc8 100644 +--- a/sound/soc/codecs/wm8994.c ++++ b/sound/soc/codecs/wm8994.c +@@ -2649,7 +2649,7 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream, + 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 --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c +index a154141..d924a59 100644 +--- a/sound/soc/codecs/wm9712.c ++++ b/sound/soc/codecs/wm9712.c +@@ -146,7 +146,7 @@ SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0), + SOC_SINGLE("Bass Volume", AC97_MASTER_TONE, 8, 15, 1), + SOC_SINGLE("Treble Volume", AC97_MASTER_TONE, 0, 15, 1), + +-SOC_SINGLE("Capture ADC Switch", AC97_REC_GAIN, 15, 1, 1), ++SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1), + SOC_ENUM("Capture Volume Steps", wm9712_enum[6]), + SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1), + SOC_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0), +@@ -272,7 +272,7 @@ SOC_DAPM_ENUM("Route", wm9712_enum[9]); + + /* Mic select */ + static const struct snd_kcontrol_new wm9712_mic_src_controls = +-SOC_DAPM_ENUM("Route", wm9712_enum[7]); ++SOC_DAPM_ENUM("Mic Source Select", wm9712_enum[7]); + + /* diff select */ + static const struct snd_kcontrol_new wm9712_diff_sel_controls = +@@ -291,7 +291,9 @@ SND_SOC_DAPM_MUX("Left Capture Select", SND_SOC_NOPM, 0, 0, + &wm9712_capture_selectl_controls), + SND_SOC_DAPM_MUX("Right Capture Select", SND_SOC_NOPM, 0, 0, + &wm9712_capture_selectr_controls), +-SND_SOC_DAPM_MUX("Mic Select Source", SND_SOC_NOPM, 0, 0, ++SND_SOC_DAPM_MUX("Left Mic Select Source", SND_SOC_NOPM, 0, 0, ++ &wm9712_mic_src_controls), ++SND_SOC_DAPM_MUX("Right Mic Select Source", SND_SOC_NOPM, 0, 0, + &wm9712_mic_src_controls), + SND_SOC_DAPM_MUX("Differential Source", SND_SOC_NOPM, 0, 0, + &wm9712_diff_sel_controls), +@@ -319,6 +321,7 @@ SND_SOC_DAPM_PGA("Out 3 PGA", AC97_INT_PAGING, 5, 1, NULL, 0), + SND_SOC_DAPM_PGA("Line PGA", AC97_INT_PAGING, 2, 1, NULL, 0), + SND_SOC_DAPM_PGA("Phone PGA", AC97_INT_PAGING, 1, 1, NULL, 0), + SND_SOC_DAPM_PGA("Mic PGA", AC97_INT_PAGING, 0, 1, NULL, 0), ++SND_SOC_DAPM_PGA("Differential Mic", SND_SOC_NOPM, 0, 0, NULL, 0), + SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_INT_PAGING, 10, 1), + SND_SOC_DAPM_OUTPUT("MONOOUT"), + SND_SOC_DAPM_OUTPUT("HPOUTL"), +@@ -379,6 +382,18 @@ static const struct snd_soc_dapm_route wm9712_audio_map[] = { + {"Mic PGA", NULL, "MIC1"}, + {"Mic PGA", NULL, "MIC2"}, + ++ /* microphones */ ++ {"Differential Mic", NULL, "MIC1"}, ++ {"Differential Mic", NULL, "MIC2"}, ++ {"Left Mic Select Source", "Mic 1", "MIC1"}, ++ {"Left Mic Select Source", "Mic 2", "MIC2"}, ++ {"Left Mic Select Source", "Stereo", "MIC1"}, ++ {"Left Mic Select Source", "Differential", "Differential Mic"}, ++ {"Right Mic Select Source", "Mic 1", "MIC1"}, ++ {"Right Mic Select Source", "Mic 2", "MIC2"}, ++ {"Right Mic Select Source", "Stereo", "MIC2"}, ++ {"Right Mic Select Source", "Differential", "Differential Mic"}, ++ + /* left capture selector */ + {"Left Capture Select", "Mic", "MIC1"}, + {"Left Capture Select", "Speaker Mixer", "Speaker Mixer"}, +diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c +index dfe957a..932a535 100644 +--- a/sound/soc/codecs/wm_hubs.c ++++ b/sound/soc/codecs/wm_hubs.c +@@ -634,6 +634,11 @@ void wm_hubs_update_class_w(struct snd_soc_codec *codec) + + snd_soc_update_bits(codec, WM8993_CLASS_W_0, + WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ, enable); ++ ++ snd_soc_write(codec, WM8993_LEFT_OUTPUT_VOLUME, ++ snd_soc_read(codec, WM8993_LEFT_OUTPUT_VOLUME)); ++ snd_soc_write(codec, WM8993_RIGHT_OUTPUT_VOLUME, ++ snd_soc_read(codec, WM8993_RIGHT_OUTPUT_VOLUME)); + } + EXPORT_SYMBOL_GPL(wm_hubs_update_class_w); + +diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c +index 34835e8..d33c48b 100644 +--- a/sound/soc/omap/mcbsp.c ++++ b/sound/soc/omap/mcbsp.c +@@ -745,7 +745,7 @@ int omap_mcbsp_6pin_src_mux(struct omap_mcbsp *mcbsp, u8 mux) + { + const char *signal, *src; + +- if (mcbsp->pdata->mux_signal) ++ if (!mcbsp->pdata->mux_signal) + return -EINVAL; + + switch (mux) { +diff --git a/sound/soc/samsung/dma.c b/sound/soc/samsung/dma.c +index ddc6cde..2526eca 100644 +--- a/sound/soc/samsung/dma.c ++++ b/sound/soc/samsung/dma.c +@@ -34,9 +34,7 @@ static const struct snd_pcm_hardware dma_hardware = { + .info = SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_BLOCK_TRANSFER | + SNDRV_PCM_INFO_MMAP | +- SNDRV_PCM_INFO_MMAP_VALID | +- SNDRV_PCM_INFO_PAUSE | +- SNDRV_PCM_INFO_RESUME, ++ SNDRV_PCM_INFO_MMAP_VALID, + .formats = SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_U16_LE | + SNDRV_PCM_FMTBIT_U8 | +@@ -246,15 +244,11 @@ static int dma_trigger(struct snd_pcm_substream *substream, int cmd) + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: +- case SNDRV_PCM_TRIGGER_RESUME: +- case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + prtd->state |= ST_RUNNING; + prtd->params->ops->trigger(prtd->params->ch); + break; + + case SNDRV_PCM_TRIGGER_STOP: +- case SNDRV_PCM_TRIGGER_SUSPEND: +- case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + prtd->state &= ~ST_RUNNING; + prtd->params->ops->stop(prtd->params->ch); + break; +diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c +index 89eae93..5b32b15 100644 +--- a/sound/soc/soc-dapm.c ++++ b/sound/soc/soc-dapm.c +@@ -1570,7 +1570,15 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) + } + + list_for_each_entry(w, &card->widgets, list) { +- list_del_init(&w->dirty); ++ switch (w->id) { ++ case snd_soc_dapm_pre: ++ case snd_soc_dapm_post: ++ /* These widgets always need to be powered */ ++ break; ++ default: ++ list_del_init(&w->dirty); ++ break; ++ } + + if (w->power) { + d = w->dapm; +@@ -3538,10 +3546,13 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_free); + + static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) + { ++ struct snd_soc_card *card = dapm->card; + struct snd_soc_dapm_widget *w; + LIST_HEAD(down_list); + int powerdown = 0; + ++ mutex_lock(&card->dapm_mutex); ++ + list_for_each_entry(w, &dapm->card->widgets, list) { + if (w->dapm != dapm) + continue; +@@ -3564,6 +3575,8 @@ static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) + snd_soc_dapm_set_bias_level(dapm, + SND_SOC_BIAS_STANDBY); + } ++ ++ mutex_unlock(&card->dapm_mutex); + } + + /* +diff --git a/sound/soc/tegra/tegra_alc5632.c b/sound/soc/tegra/tegra_alc5632.c +index 32de700..2f272c5 100644 +--- a/sound/soc/tegra/tegra_alc5632.c ++++ b/sound/soc/tegra/tegra_alc5632.c +@@ -92,7 +92,6 @@ static struct snd_soc_jack_gpio tegra_alc5632_hp_jack_gpio = { + .name = "Headset detection", + .report = SND_JACK_HEADSET, + .debounce_time = 150, +- .invert = 1, + }; + + static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = { +diff --git a/sound/usb/card.c b/sound/usb/card.c +index d5b5c338..4a469f0 100644 +--- a/sound/usb/card.c ++++ b/sound/usb/card.c +@@ -553,7 +553,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, + struct snd_usb_audio *chip) + { + struct snd_card *card; +- struct list_head *p; ++ struct list_head *p, *n; + + if (chip == (void *)-1L) + return; +@@ -570,7 +570,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, + snd_usb_stream_disconnect(p); + } + /* release the endpoint resources */ +- list_for_each(p, &chip->ep_list) { ++ list_for_each_safe(p, n, &chip->ep_list) { + snd_usb_endpoint_free(p); + } + /* release the midi resources */ +diff --git a/sound/usb/clock.c b/sound/usb/clock.c +index 379baad..5e634a2 100644 +--- a/sound/usb/clock.c ++++ b/sound/usb/clock.c +@@ -111,7 +111,8 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id) + 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, +diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c +index 0f647d2..060dccb 100644 +--- a/sound/usb/endpoint.c ++++ b/sound/usb/endpoint.c +@@ -141,7 +141,7 @@ int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep) + * + * For implicit feedback, next_packet_size() is unused. + */ +-static int next_packet_size(struct snd_usb_endpoint *ep) ++int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep) + { + unsigned long flags; + int ret; +@@ -177,15 +177,6 @@ static void retire_inbound_urb(struct snd_usb_endpoint *ep, + ep->retire_data_urb(ep->data_subs, urb); + } + +-static void prepare_outbound_urb_sizes(struct snd_usb_endpoint *ep, +- struct snd_urb_ctx *ctx) +-{ +- int i; +- +- for (i = 0; i < ctx->packets; ++i) +- ctx->packet_size[i] = next_packet_size(ep); +-} +- + /* + * Prepare a PLAYBACK urb for submission to the bus. + */ +@@ -206,7 +197,13 @@ static void prepare_outbound_urb(struct snd_usb_endpoint *ep, + /* no data provider, so send silence */ + unsigned int offs = 0; + for (i = 0; i < ctx->packets; ++i) { +- int counts = ctx->packet_size[i]; ++ int counts; ++ ++ if (ctx->packet_size[i]) ++ counts = ctx->packet_size[i]; ++ else ++ counts = snd_usb_endpoint_next_packet_size(ep); ++ + urb->iso_frame_desc[i].offset = offs * ep->stride; + urb->iso_frame_desc[i].length = counts * ep->stride; + offs += counts; +@@ -370,7 +367,6 @@ static void snd_complete_urb(struct urb *urb) + goto exit_clear; + } + +- prepare_outbound_urb_sizes(ep, ctx); + prepare_outbound_urb(ep, ctx); + } else { + retire_inbound_urb(ep, ctx); +@@ -799,7 +795,9 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, + /** + * snd_usb_endpoint_start: start an snd_usb_endpoint + * +- * @ep: the endpoint to start ++ * @ep: the endpoint to start ++ * @can_sleep: flag indicating whether the operation is executed in ++ * non-atomic context + * + * A call to this function will increment the use count of the endpoint. + * In case it is not already running, the URBs for this endpoint will be +@@ -809,7 +807,7 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, + * + * Returns an error if the URB submission failed, 0 in all other cases. + */ +-int snd_usb_endpoint_start(struct snd_usb_endpoint *ep) ++int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, int can_sleep) + { + int err; + unsigned int i; +@@ -822,8 +820,9 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep) + return 0; + + /* just to be sure */ +- deactivate_urbs(ep, 0, 1); +- wait_clear_urbs(ep); ++ deactivate_urbs(ep, 0, can_sleep); ++ if (can_sleep) ++ wait_clear_urbs(ep); + + ep->active_mask = 0; + ep->unlink_mask = 0; +@@ -854,7 +853,6 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep) + goto __error; + + if (usb_pipeout(ep->pipe)) { +- prepare_outbound_urb_sizes(ep, urb->context); + prepare_outbound_urb(ep, urb->context); + } else { + prepare_inbound_urb(ep, urb->context); +diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h +index ee2723f..cbbbdf2 100644 +--- a/sound/usb/endpoint.h ++++ b/sound/usb/endpoint.h +@@ -13,7 +13,7 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, + struct audioformat *fmt, + struct snd_usb_endpoint *sync_ep); + +-int snd_usb_endpoint_start(struct snd_usb_endpoint *ep); ++int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, int can_sleep); + void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep, + int force, int can_sleep, int wait); + int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep); +@@ -21,6 +21,7 @@ int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep); + void snd_usb_endpoint_free(struct list_head *head); + + int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep); ++int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep); + + void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep, + struct snd_usb_endpoint *sender, +diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c +index 4f40ba8..fe56c9d 100644 +--- a/sound/usb/mixer.c ++++ b/sound/usb/mixer.c +@@ -1267,6 +1267,13 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void + /* disable non-functional volume control */ + master_bits &= ~UAC_CONTROL_BIT(UAC_FU_VOLUME); + break; ++ case USB_ID(0x1130, 0xf211): ++ snd_printk(KERN_INFO ++ "usbmixer: volume control quirk for Tenx TP6911 Audio Headset\n"); ++ /* disable non-functional volume control */ ++ channels = 0; ++ break; ++ + } + if (channels > 0) + first_ch_bits = snd_usb_combine_bytes(bmaControls + csize, csize); +diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c +index a1298f3..f782ce1 100644 +--- a/sound/usb/pcm.c ++++ b/sound/usb/pcm.c +@@ -212,7 +212,7 @@ int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface, + } + } + +-static int start_endpoints(struct snd_usb_substream *subs) ++static int start_endpoints(struct snd_usb_substream *subs, int can_sleep) + { + int err; + +@@ -225,7 +225,7 @@ static int start_endpoints(struct snd_usb_substream *subs) + snd_printdd(KERN_DEBUG "Starting data EP @%p\n", ep); + + ep->data_subs = subs; +- err = snd_usb_endpoint_start(ep); ++ err = snd_usb_endpoint_start(ep, can_sleep); + if (err < 0) { + clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags); + return err; +@@ -236,10 +236,25 @@ static int start_endpoints(struct snd_usb_substream *subs) + !test_and_set_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) { + struct snd_usb_endpoint *ep = subs->sync_endpoint; + ++ if (subs->data_endpoint->iface != subs->sync_endpoint->iface || ++ subs->data_endpoint->alt_idx != subs->sync_endpoint->alt_idx) { ++ err = usb_set_interface(subs->dev, ++ subs->sync_endpoint->iface, ++ subs->sync_endpoint->alt_idx); ++ if (err < 0) { ++ snd_printk(KERN_ERR ++ "%d:%d:%d: cannot set interface (%d)\n", ++ subs->dev->devnum, ++ subs->sync_endpoint->iface, ++ subs->sync_endpoint->alt_idx, err); ++ return -EIO; ++ } ++ } ++ + snd_printdd(KERN_DEBUG "Starting sync EP @%p\n", ep); + + ep->sync_slave = subs->data_endpoint; +- err = snd_usb_endpoint_start(ep); ++ err = snd_usb_endpoint_start(ep, can_sleep); + if (err < 0) { + clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags); + return err; +@@ -547,7 +562,7 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) + /* for playback, submit the URBs now; otherwise, the first hwptr_done + * updates for all URBs would happen at the same time when starting */ + if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) +- return start_endpoints(subs); ++ return start_endpoints(subs, 1); + + return 0; + } +@@ -1029,6 +1044,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs, + struct urb *urb) + { + struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; ++ struct snd_usb_endpoint *ep = subs->data_endpoint; + struct snd_urb_ctx *ctx = urb->context; + unsigned int counts, frames, bytes; + int i, stride, period_elapsed = 0; +@@ -1040,7 +1056,11 @@ static void prepare_playback_urb(struct snd_usb_substream *subs, + urb->number_of_packets = 0; + spin_lock_irqsave(&subs->lock, flags); + for (i = 0; i < ctx->packets; i++) { +- counts = ctx->packet_size[i]; ++ if (ctx->packet_size[i]) ++ counts = ctx->packet_size[i]; ++ else ++ counts = snd_usb_endpoint_next_packet_size(ep); ++ + /* set up descriptor */ + urb->iso_frame_desc[i].offset = frames * stride; + urb->iso_frame_desc[i].length = counts * stride; +@@ -1091,7 +1111,16 @@ static void prepare_playback_urb(struct snd_usb_substream *subs, + subs->hwptr_done += bytes; + if (subs->hwptr_done >= runtime->buffer_size * stride) + subs->hwptr_done -= runtime->buffer_size * stride; ++ ++ /* update delay with exact number of samples queued */ ++ runtime->delay = subs->last_delay; + runtime->delay += frames; ++ subs->last_delay = runtime->delay; ++ ++ /* realign last_frame_number */ ++ subs->last_frame_number = usb_get_current_frame_number(subs->dev); ++ subs->last_frame_number &= 0xFF; /* keep 8 LSBs */ ++ + spin_unlock_irqrestore(&subs->lock, flags); + urb->transfer_buffer_length = bytes; + if (period_elapsed) +@@ -1109,12 +1138,32 @@ static void retire_playback_urb(struct snd_usb_substream *subs, + struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; + int stride = runtime->frame_bits >> 3; + int processed = urb->transfer_buffer_length / stride; ++ int est_delay; ++ ++ /* ignore the delay accounting when procssed=0 is given, i.e. ++ * silent payloads are procssed before handling the actual data ++ */ ++ if (!processed) ++ return; + + spin_lock_irqsave(&subs->lock, flags); +- if (processed > runtime->delay) +- runtime->delay = 0; ++ est_delay = snd_usb_pcm_delay(subs, runtime->rate); ++ /* update delay with exact number of samples played */ ++ if (processed > subs->last_delay) ++ subs->last_delay = 0; + else +- runtime->delay -= processed; ++ subs->last_delay -= processed; ++ runtime->delay = subs->last_delay; ++ ++ /* ++ * Report when delay estimate is off by more than 2ms. ++ * The error should be lower than 2ms since the estimate relies ++ * on two reads of a counter updated every ms. ++ */ ++ if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2) ++ snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n", ++ est_delay, subs->last_delay); ++ + spin_unlock_irqrestore(&subs->lock, flags); + } + +@@ -1172,7 +1221,7 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: +- err = start_endpoints(subs); ++ err = start_endpoints(subs, 0); + if (err < 0) + return err; + +diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h +index 79780fa..d73ac9b 100644 +--- a/sound/usb/quirks-table.h ++++ b/sound/usb/quirks-table.h +@@ -2781,6 +2781,59 @@ YAMAHA_DEVICE(0x7010, "UB99"), + } + }, + ++/* Microsoft XboxLive Headset/Xbox Communicator */ ++{ ++ USB_DEVICE(0x045e, 0x0283), ++ .bInterfaceClass = USB_CLASS_PER_INTERFACE, ++ .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { ++ .vendor_name = "Microsoft", ++ .product_name = "XboxLive Headset/Xbox Communicator", ++ .ifnum = QUIRK_ANY_INTERFACE, ++ .type = QUIRK_COMPOSITE, ++ .data = &(const struct snd_usb_audio_quirk[]) { ++ { ++ /* playback */ ++ .ifnum = 0, ++ .type = QUIRK_AUDIO_FIXED_ENDPOINT, ++ .data = &(const struct audioformat) { ++ .formats = SNDRV_PCM_FMTBIT_S16_LE, ++ .channels = 1, ++ .iface = 0, ++ .altsetting = 0, ++ .altset_idx = 0, ++ .attributes = 0, ++ .endpoint = 0x04, ++ .ep_attr = 0x05, ++ .rates = SNDRV_PCM_RATE_CONTINUOUS, ++ .rate_min = 22050, ++ .rate_max = 22050 ++ } ++ }, ++ { ++ /* capture */ ++ .ifnum = 1, ++ .type = QUIRK_AUDIO_FIXED_ENDPOINT, ++ .data = &(const struct audioformat) { ++ .formats = SNDRV_PCM_FMTBIT_S16_LE, ++ .channels = 1, ++ .iface = 1, ++ .altsetting = 0, ++ .altset_idx = 0, ++ .attributes = 0, ++ .endpoint = 0x85, ++ .ep_attr = 0x05, ++ .rates = SNDRV_PCM_RATE_CONTINUOUS, ++ .rate_min = 16000, ++ .rate_max = 16000 ++ } ++ }, ++ { ++ .ifnum = -1 ++ } ++ } ++ } ++}, ++ + { + /* + * Some USB MIDI devices don't have an audio control interface, +diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c +index d9834b3..2984ffb 100644 +--- a/tools/hv/hv_kvp_daemon.c ++++ b/tools/hv/hv_kvp_daemon.c +@@ -106,7 +106,7 @@ static void kvp_acquire_lock(int pool) + + if (fcntl(kvp_file_info[pool].fd, F_SETLKW, &fl) == -1) { + syslog(LOG_ERR, "Failed to acquire the lock pool: %d", pool); +- exit(-1); ++ exit(EXIT_FAILURE); + } + } + +@@ -118,7 +118,7 @@ static void kvp_release_lock(int pool) + if (fcntl(kvp_file_info[pool].fd, F_SETLK, &fl) == -1) { + perror("fcntl"); + syslog(LOG_ERR, "Failed to release the lock pool: %d", pool); +- exit(-1); ++ exit(EXIT_FAILURE); + } + } + +@@ -137,14 +137,19 @@ static void kvp_update_file(int pool) + if (!filep) { + kvp_release_lock(pool); + syslog(LOG_ERR, "Failed to open file, pool: %d", pool); +- exit(-1); ++ exit(EXIT_FAILURE); + } + + bytes_written = fwrite(kvp_file_info[pool].records, + sizeof(struct kvp_record), + kvp_file_info[pool].num_records, filep); + +- fflush(filep); ++ if (ferror(filep) || fclose(filep)) { ++ kvp_release_lock(pool); ++ syslog(LOG_ERR, "Failed to write file, pool: %d", pool); ++ exit(EXIT_FAILURE); ++ } ++ + kvp_release_lock(pool); + } + +@@ -163,14 +168,19 @@ static void kvp_update_mem_state(int pool) + if (!filep) { + kvp_release_lock(pool); + syslog(LOG_ERR, "Failed to open file, pool: %d", pool); +- exit(-1); ++ exit(EXIT_FAILURE); + } +- while (!feof(filep)) { ++ for (;;) { + readp = &record[records_read]; + records_read += fread(readp, sizeof(struct kvp_record), + ENTRIES_PER_BLOCK * num_blocks, + filep); + ++ if (ferror(filep)) { ++ syslog(LOG_ERR, "Failed to read file, pool: %d", pool); ++ exit(EXIT_FAILURE); ++ } ++ + if (!feof(filep)) { + /* + * We have more data to read. +@@ -180,7 +190,7 @@ static void kvp_update_mem_state(int pool) + + if (record == NULL) { + syslog(LOG_ERR, "malloc failed"); +- exit(-1); ++ exit(EXIT_FAILURE); + } + continue; + } +@@ -191,6 +201,7 @@ static void kvp_update_mem_state(int pool) + kvp_file_info[pool].records = record; + kvp_file_info[pool].num_records = records_read; + ++ fclose(filep); + kvp_release_lock(pool); + } + static int kvp_file_init(void) +@@ -208,7 +219,7 @@ static int kvp_file_init(void) + if (access("/var/opt/hyperv", F_OK)) { + if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) { + syslog(LOG_ERR, " Failed to create /var/opt/hyperv"); +- exit(-1); ++ exit(EXIT_FAILURE); + } + } + +@@ -232,12 +243,18 @@ static int kvp_file_init(void) + fclose(filep); + return 1; + } +- while (!feof(filep)) { ++ for (;;) { + readp = &record[records_read]; + records_read += fread(readp, sizeof(struct kvp_record), + ENTRIES_PER_BLOCK, + filep); + ++ if (ferror(filep)) { ++ syslog(LOG_ERR, "Failed to read file, pool: %d", ++ i); ++ exit(EXIT_FAILURE); ++ } ++ + if (!feof(filep)) { + /* + * We have more data to read. +@@ -657,13 +674,13 @@ int main(void) + + if (kvp_file_init()) { + syslog(LOG_ERR, "Failed to initialize the pools"); +- exit(-1); ++ exit(EXIT_FAILURE); + } + + fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); + if (fd < 0) { + syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd); +- exit(-1); ++ exit(EXIT_FAILURE); + } + addr.nl_family = AF_NETLINK; + addr.nl_pad = 0; +@@ -675,7 +692,7 @@ int main(void) + if (error < 0) { + syslog(LOG_ERR, "bind failed; error:%d", error); + close(fd); +- exit(-1); ++ exit(EXIT_FAILURE); + } + sock_opt = addr.nl_groups; + setsockopt(fd, 270, 1, &sock_opt, sizeof(sock_opt)); +@@ -695,7 +712,7 @@ int main(void) + if (len < 0) { + syslog(LOG_ERR, "netlink_send failed; error:%d", len); + close(fd); +- exit(-1); ++ exit(EXIT_FAILURE); + } + + pfd.fd = fd; +@@ -863,7 +880,7 @@ kvp_done: + len = netlink_send(fd, incoming_cn_msg); + if (len < 0) { + syslog(LOG_ERR, "net_link send failed; error:%d", len); +- exit(-1); ++ exit(EXIT_FAILURE); + } + } + +diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c +index f759f4f..fd2f9221 100644 +--- a/tools/lguest/lguest.c ++++ b/tools/lguest/lguest.c +@@ -1299,6 +1299,7 @@ static struct device *new_device(const char *name, u16 type) + dev->feature_len = 0; + dev->num_vq = 0; + dev->running = false; ++ dev->next = NULL; + + /* + * Append to device list. Prepending to a single-linked list is +diff --git a/tools/perf/Makefile b/tools/perf/Makefile +index 0eee64c..e21f414 100644 +--- a/tools/perf/Makefile ++++ b/tools/perf/Makefile +@@ -62,7 +62,7 @@ ifeq ($(ARCH),x86_64) + ARCH := x86 + IS_X86_64 := 0 + ifeq (, $(findstring m32,$(EXTRA_CFLAGS))) +- IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -xc - | tail -n 1) ++ IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1) + endif + ifeq (${IS_X86_64}, 1) + RAW_ARCH := x86_64 +diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile +index a93e06c..cf397bd 100644 +--- a/tools/power/cpupower/Makefile ++++ b/tools/power/cpupower/Makefile +@@ -111,7 +111,7 @@ GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo $(OUTPUT)po/$$HLANG.gmo; + export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS + + # check if compiler option is supported +-cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;} ++cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;} + + # use '-Os' optimization if available, else use -O2 + OPTIMIZATION := $(call cc-supports,-Os,-O2) -- 1.8.5.2