Magellan Linux

Annotation of /trunk/kernel-alx/patches-3.10/0112-3.10.13-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2340 - (hide annotations) (download)
Mon Dec 16 10:04:05 2013 UTC (10 years, 5 months ago) by niro
File size: 127780 byte(s)
-linux-3.10.13
1 niro 2340 diff --git a/Documentation/DocBook/media_api.tmpl b/Documentation/DocBook/media_api.tmpl
2     index 6a8b7158..9c92bb87 100644
3     --- a/Documentation/DocBook/media_api.tmpl
4     +++ b/Documentation/DocBook/media_api.tmpl
5     @@ -1,6 +1,6 @@
6     <?xml version="1.0"?>
7     -<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
8     - "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
9     +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
10     + "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
11     <!ENTITY % media-entities SYSTEM "./media-entities.tmpl"> %media-entities;
12     <!ENTITY media-indices SYSTEM "./media-indices.tmpl">
13    
14     diff --git a/Makefile b/Makefile
15     index afe001e3..25d38b79 100644
16     --- a/Makefile
17     +++ b/Makefile
18     @@ -1,6 +1,6 @@
19     VERSION = 3
20     PATCHLEVEL = 10
21     -SUBLEVEL = 12
22     +SUBLEVEL = 13
23     EXTRAVERSION =
24     NAME = TOSSUG Baby Fish
25    
26     diff --git a/arch/arm/boot/dts/at91rm9200.dtsi b/arch/arm/boot/dts/at91rm9200.dtsi
27     index 5d3ed5aa..0af879a4 100644
28     --- a/arch/arm/boot/dts/at91rm9200.dtsi
29     +++ b/arch/arm/boot/dts/at91rm9200.dtsi
30     @@ -35,8 +35,12 @@
31     ssc2 = &ssc2;
32     };
33     cpus {
34     - cpu@0 {
35     + #address-cells = <0>;
36     + #size-cells = <0>;
37     +
38     + cpu {
39     compatible = "arm,arm920t";
40     + device_type = "cpu";
41     };
42     };
43    
44     diff --git a/arch/arm/boot/dts/at91sam9260.dtsi b/arch/arm/boot/dts/at91sam9260.dtsi
45     index 43a18f74..0dbdb846 100644
46     --- a/arch/arm/boot/dts/at91sam9260.dtsi
47     +++ b/arch/arm/boot/dts/at91sam9260.dtsi
48     @@ -32,8 +32,12 @@
49     ssc0 = &ssc0;
50     };
51     cpus {
52     - cpu@0 {
53     - compatible = "arm,arm926ejs";
54     + #address-cells = <0>;
55     + #size-cells = <0>;
56     +
57     + cpu {
58     + compatible = "arm,arm926ej-s";
59     + device_type = "cpu";
60     };
61     };
62    
63     diff --git a/arch/arm/boot/dts/at91sam9263.dtsi b/arch/arm/boot/dts/at91sam9263.dtsi
64     index 94b58ab2..fcd38f89 100644
65     --- a/arch/arm/boot/dts/at91sam9263.dtsi
66     +++ b/arch/arm/boot/dts/at91sam9263.dtsi
67     @@ -29,8 +29,12 @@
68     ssc1 = &ssc1;
69     };
70     cpus {
71     - cpu@0 {
72     - compatible = "arm,arm926ejs";
73     + #address-cells = <0>;
74     + #size-cells = <0>;
75     +
76     + cpu {
77     + compatible = "arm,arm926ej-s";
78     + device_type = "cpu";
79     };
80     };
81    
82     diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi b/arch/arm/boot/dts/at91sam9g45.dtsi
83     index bf18a735..479a0622 100644
84     --- a/arch/arm/boot/dts/at91sam9g45.dtsi
85     +++ b/arch/arm/boot/dts/at91sam9g45.dtsi
86     @@ -35,8 +35,12 @@
87     ssc1 = &ssc1;
88     };
89     cpus {
90     - cpu@0 {
91     - compatible = "arm,arm926ejs";
92     + #address-cells = <0>;
93     + #size-cells = <0>;
94     +
95     + cpu {
96     + compatible = "arm,arm926ej-s";
97     + device_type = "cpu";
98     };
99     };
100    
101     diff --git a/arch/arm/boot/dts/at91sam9n12.dtsi b/arch/arm/boot/dts/at91sam9n12.dtsi
102     index 8d25f889..a92ec783 100644
103     --- a/arch/arm/boot/dts/at91sam9n12.dtsi
104     +++ b/arch/arm/boot/dts/at91sam9n12.dtsi
105     @@ -31,8 +31,12 @@
106     ssc0 = &ssc0;
107     };
108     cpus {
109     - cpu@0 {
110     - compatible = "arm,arm926ejs";
111     + #address-cells = <0>;
112     + #size-cells = <0>;
113     +
114     + cpu {
115     + compatible = "arm,arm926ej-s";
116     + device_type = "cpu";
117     };
118     };
119    
120     diff --git a/arch/arm/boot/dts/at91sam9x5.dtsi b/arch/arm/boot/dts/at91sam9x5.dtsi
121     index b5833d1f..2b2b6923 100644
122     --- a/arch/arm/boot/dts/at91sam9x5.dtsi
123     +++ b/arch/arm/boot/dts/at91sam9x5.dtsi
124     @@ -33,8 +33,12 @@
125     ssc0 = &ssc0;
126     };
127     cpus {
128     - cpu@0 {
129     - compatible = "arm,arm926ejs";
130     + #address-cells = <0>;
131     + #size-cells = <0>;
132     +
133     + cpu {
134     + compatible = "arm,arm926ej-s";
135     + device_type = "cpu";
136     };
137     };
138    
139     diff --git a/arch/arm/boot/dts/sama5d3.dtsi b/arch/arm/boot/dts/sama5d3.dtsi
140     index 5000e0d4..642775d7 100644
141     --- a/arch/arm/boot/dts/sama5d3.dtsi
142     +++ b/arch/arm/boot/dts/sama5d3.dtsi
143     @@ -35,8 +35,12 @@
144     ssc1 = &ssc1;
145     };
146     cpus {
147     + #address-cells = <1>;
148     + #size-cells = <0>;
149     cpu@0 {
150     + device_type = "cpu";
151     compatible = "arm,cortex-a5";
152     + reg = <0x0>;
153     };
154     };
155    
156     diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
157     index e7ef619a..06ef8b62 100644
158     --- a/arch/arm/boot/dts/sun4i-a10.dtsi
159     +++ b/arch/arm/boot/dts/sun4i-a10.dtsi
160     @@ -16,8 +16,12 @@
161     interrupt-parent = <&intc>;
162    
163     cpus {
164     + #address-cells = <1>;
165     + #size-cells = <0>;
166     cpu@0 {
167     + device_type = "cpu";
168     compatible = "arm,cortex-a8";
169     + reg = <0x0>;
170     };
171     };
172    
173     diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi
174     index 31fa38f8..d2852547 100644
175     --- a/arch/arm/boot/dts/sun5i-a13.dtsi
176     +++ b/arch/arm/boot/dts/sun5i-a13.dtsi
177     @@ -17,8 +17,12 @@
178     interrupt-parent = <&intc>;
179    
180     cpus {
181     + #address-cells = <1>;
182     + #size-cells = <0>;
183     cpu@0 {
184     + device_type = "cpu";
185     compatible = "arm,cortex-a8";
186     + reg = <0x0>;
187     };
188     };
189    
190     diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
191     index 4a519907..db9cf692 100644
192     --- a/arch/arm/kvm/coproc.c
193     +++ b/arch/arm/kvm/coproc.c
194     @@ -146,7 +146,11 @@ static bool pm_fake(struct kvm_vcpu *vcpu,
195     #define access_pmintenclr pm_fake
196    
197     /* Architected CP15 registers.
198     - * Important: Must be sorted ascending by CRn, CRM, Op1, Op2
199     + * CRn denotes the primary register number, but is copied to the CRm in the
200     + * user space API for 64-bit register access in line with the terminology used
201     + * in the ARM ARM.
202     + * Important: Must be sorted ascending by CRn, CRM, Op1, Op2 and with 64-bit
203     + * registers preceding 32-bit ones.
204     */
205     static const struct coproc_reg cp15_regs[] = {
206     /* CSSELR: swapped by interrupt.S. */
207     @@ -154,8 +158,8 @@ static const struct coproc_reg cp15_regs[] = {
208     NULL, reset_unknown, c0_CSSELR },
209    
210     /* TTBR0/TTBR1: swapped by interrupt.S. */
211     - { CRm( 2), Op1( 0), is64, NULL, reset_unknown64, c2_TTBR0 },
212     - { CRm( 2), Op1( 1), is64, NULL, reset_unknown64, c2_TTBR1 },
213     + { CRm64( 2), Op1( 0), is64, NULL, reset_unknown64, c2_TTBR0 },
214     + { CRm64( 2), Op1( 1), is64, NULL, reset_unknown64, c2_TTBR1 },
215    
216     /* TTBCR: swapped by interrupt.S. */
217     { CRn( 2), CRm( 0), Op1( 0), Op2( 2), is32,
218     @@ -182,7 +186,7 @@ static const struct coproc_reg cp15_regs[] = {
219     NULL, reset_unknown, c6_IFAR },
220    
221     /* PAR swapped by interrupt.S */
222     - { CRn( 7), Op1( 0), is64, NULL, reset_unknown64, c7_PAR },
223     + { CRm64( 7), Op1( 0), is64, NULL, reset_unknown64, c7_PAR },
224    
225     /*
226     * DC{C,I,CI}SW operations:
227     @@ -399,12 +403,13 @@ static bool index_to_params(u64 id, struct coproc_params *params)
228     | KVM_REG_ARM_OPC1_MASK))
229     return false;
230     params->is_64bit = true;
231     - params->CRm = ((id & KVM_REG_ARM_CRM_MASK)
232     + /* CRm to CRn: see cp15_to_index for details */
233     + params->CRn = ((id & KVM_REG_ARM_CRM_MASK)
234     >> KVM_REG_ARM_CRM_SHIFT);
235     params->Op1 = ((id & KVM_REG_ARM_OPC1_MASK)
236     >> KVM_REG_ARM_OPC1_SHIFT);
237     params->Op2 = 0;
238     - params->CRn = 0;
239     + params->CRm = 0;
240     return true;
241     default:
242     return false;
243     @@ -898,7 +903,14 @@ static u64 cp15_to_index(const struct coproc_reg *reg)
244     if (reg->is_64) {
245     val |= KVM_REG_SIZE_U64;
246     val |= (reg->Op1 << KVM_REG_ARM_OPC1_SHIFT);
247     - val |= (reg->CRm << KVM_REG_ARM_CRM_SHIFT);
248     + /*
249     + * CRn always denotes the primary coproc. reg. nr. for the
250     + * in-kernel representation, but the user space API uses the
251     + * CRm for the encoding, because it is modelled after the
252     + * MRRC/MCRR instructions: see the ARM ARM rev. c page
253     + * B3-1445
254     + */
255     + val |= (reg->CRn << KVM_REG_ARM_CRM_SHIFT);
256     } else {
257     val |= KVM_REG_SIZE_U32;
258     val |= (reg->Op1 << KVM_REG_ARM_OPC1_SHIFT);
259     diff --git a/arch/arm/kvm/coproc.h b/arch/arm/kvm/coproc.h
260     index b7301d3e..0461d5c8 100644
261     --- a/arch/arm/kvm/coproc.h
262     +++ b/arch/arm/kvm/coproc.h
263     @@ -135,6 +135,8 @@ static inline int cmp_reg(const struct coproc_reg *i1,
264     return -1;
265     if (i1->CRn != i2->CRn)
266     return i1->CRn - i2->CRn;
267     + if (i1->is_64 != i2->is_64)
268     + return i2->is_64 - i1->is_64;
269     if (i1->CRm != i2->CRm)
270     return i1->CRm - i2->CRm;
271     if (i1->Op1 != i2->Op1)
272     @@ -145,6 +147,7 @@ static inline int cmp_reg(const struct coproc_reg *i1,
273    
274     #define CRn(_x) .CRn = _x
275     #define CRm(_x) .CRm = _x
276     +#define CRm64(_x) .CRn = _x, .CRm = 0
277     #define Op1(_x) .Op1 = _x
278     #define Op2(_x) .Op2 = _x
279     #define is64 .is_64 = true
280     diff --git a/arch/arm/kvm/coproc_a15.c b/arch/arm/kvm/coproc_a15.c
281     index 685063a6..cf93472b 100644
282     --- a/arch/arm/kvm/coproc_a15.c
283     +++ b/arch/arm/kvm/coproc_a15.c
284     @@ -114,7 +114,11 @@ static bool access_l2ectlr(struct kvm_vcpu *vcpu,
285    
286     /*
287     * A15-specific CP15 registers.
288     - * Important: Must be sorted ascending by CRn, CRM, Op1, Op2
289     + * CRn denotes the primary register number, but is copied to the CRm in the
290     + * user space API for 64-bit register access in line with the terminology used
291     + * in the ARM ARM.
292     + * Important: Must be sorted ascending by CRn, CRM, Op1, Op2 and with 64-bit
293     + * registers preceding 32-bit ones.
294     */
295     static const struct coproc_reg a15_regs[] = {
296     /* MPIDR: we use VMPIDR for guest access. */
297     diff --git a/arch/arm/mach-versatile/include/mach/platform.h b/arch/arm/mach-versatile/include/mach/platform.h
298     index ec087407..6f938ccb 100644
299     --- a/arch/arm/mach-versatile/include/mach/platform.h
300     +++ b/arch/arm/mach-versatile/include/mach/platform.h
301     @@ -231,12 +231,14 @@
302     /* PCI space */
303     #define VERSATILE_PCI_BASE 0x41000000 /* PCI Interface */
304     #define VERSATILE_PCI_CFG_BASE 0x42000000
305     +#define VERSATILE_PCI_IO_BASE 0x43000000
306     #define VERSATILE_PCI_MEM_BASE0 0x44000000
307     #define VERSATILE_PCI_MEM_BASE1 0x50000000
308     #define VERSATILE_PCI_MEM_BASE2 0x60000000
309     /* Sizes of above maps */
310     #define VERSATILE_PCI_BASE_SIZE 0x01000000
311     #define VERSATILE_PCI_CFG_BASE_SIZE 0x02000000
312     +#define VERSATILE_PCI_IO_BASE_SIZE 0x01000000
313     #define VERSATILE_PCI_MEM_BASE0_SIZE 0x0c000000 /* 32Mb */
314     #define VERSATILE_PCI_MEM_BASE1_SIZE 0x10000000 /* 256Mb */
315     #define VERSATILE_PCI_MEM_BASE2_SIZE 0x10000000 /* 256Mb */
316     diff --git a/arch/arm/mach-versatile/pci.c b/arch/arm/mach-versatile/pci.c
317     index e92e5e07..c97be4ea 100644
318     --- a/arch/arm/mach-versatile/pci.c
319     +++ b/arch/arm/mach-versatile/pci.c
320     @@ -43,9 +43,9 @@
321     #define PCI_IMAP0 __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0x0)
322     #define PCI_IMAP1 __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0x4)
323     #define PCI_IMAP2 __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0x8)
324     -#define PCI_SMAP0 __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0x10)
325     -#define PCI_SMAP1 __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0x14)
326     -#define PCI_SMAP2 __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0x18)
327     +#define PCI_SMAP0 __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0x14)
328     +#define PCI_SMAP1 __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0x18)
329     +#define PCI_SMAP2 __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0x1c)
330     #define PCI_SELFID __IO_ADDRESS(VERSATILE_PCI_CORE_BASE+0xc)
331    
332     #define DEVICE_ID_OFFSET 0x00
333     @@ -170,8 +170,8 @@ static struct pci_ops pci_versatile_ops = {
334     .write = versatile_write_config,
335     };
336    
337     -static struct resource io_mem = {
338     - .name = "PCI I/O space",
339     +static struct resource unused_mem = {
340     + .name = "PCI unused",
341     .start = VERSATILE_PCI_MEM_BASE0,
342     .end = VERSATILE_PCI_MEM_BASE0+VERSATILE_PCI_MEM_BASE0_SIZE-1,
343     .flags = IORESOURCE_MEM,
344     @@ -195,9 +195,9 @@ static int __init pci_versatile_setup_resources(struct pci_sys_data *sys)
345     {
346     int ret = 0;
347    
348     - ret = request_resource(&iomem_resource, &io_mem);
349     + ret = request_resource(&iomem_resource, &unused_mem);
350     if (ret) {
351     - printk(KERN_ERR "PCI: unable to allocate I/O "
352     + printk(KERN_ERR "PCI: unable to allocate unused "
353     "memory region (%d)\n", ret);
354     goto out;
355     }
356     @@ -205,7 +205,7 @@ static int __init pci_versatile_setup_resources(struct pci_sys_data *sys)
357     if (ret) {
358     printk(KERN_ERR "PCI: unable to allocate non-prefetchable "
359     "memory region (%d)\n", ret);
360     - goto release_io_mem;
361     + goto release_unused_mem;
362     }
363     ret = request_resource(&iomem_resource, &pre_mem);
364     if (ret) {
365     @@ -225,8 +225,8 @@ static int __init pci_versatile_setup_resources(struct pci_sys_data *sys)
366    
367     release_non_mem:
368     release_resource(&non_mem);
369     - release_io_mem:
370     - release_resource(&io_mem);
371     + release_unused_mem:
372     + release_resource(&unused_mem);
373     out:
374     return ret;
375     }
376     @@ -246,7 +246,7 @@ int __init pci_versatile_setup(int nr, struct pci_sys_data *sys)
377     goto out;
378     }
379    
380     - ret = pci_ioremap_io(0, VERSATILE_PCI_MEM_BASE0);
381     + ret = pci_ioremap_io(0, VERSATILE_PCI_IO_BASE);
382     if (ret)
383     goto out;
384    
385     @@ -295,6 +295,19 @@ int __init pci_versatile_setup(int nr, struct pci_sys_data *sys)
386     __raw_writel(PHYS_OFFSET, local_pci_cfg_base + PCI_BASE_ADDRESS_2);
387    
388     /*
389     + * For many years the kernel and QEMU were symbiotically buggy
390     + * in that they both assumed the same broken IRQ mapping.
391     + * QEMU therefore attempts to auto-detect old broken kernels
392     + * so that they still work on newer QEMU as they did on old
393     + * QEMU. Since we now use the correct (ie matching-hardware)
394     + * IRQ mapping we write a definitely different value to a
395     + * PCI_INTERRUPT_LINE register to tell QEMU that we expect
396     + * real hardware behaviour and it need not be backwards
397     + * compatible for us. This write is harmless on real hardware.
398     + */
399     + __raw_writel(0, VERSATILE_PCI_VIRT_BASE+PCI_INTERRUPT_LINE);
400     +
401     + /*
402     * Do not to map Versatile FPGA PCI device into memory space
403     */
404     pci_slot_ignore |= (1 << myslot);
405     @@ -327,13 +340,13 @@ static int __init versatile_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
406     {
407     int irq;
408    
409     - /* slot, pin, irq
410     - * 24 1 IRQ_SIC_PCI0
411     - * 25 1 IRQ_SIC_PCI1
412     - * 26 1 IRQ_SIC_PCI2
413     - * 27 1 IRQ_SIC_PCI3
414     + /*
415     + * Slot INTA INTB INTC INTD
416     + * 31 PCI1 PCI2 PCI3 PCI0
417     + * 30 PCI0 PCI1 PCI2 PCI3
418     + * 29 PCI3 PCI0 PCI1 PCI2
419     */
420     - irq = IRQ_SIC_PCI0 + ((slot - 24 + pin - 1) & 3);
421     + irq = IRQ_SIC_PCI0 + ((slot + 2 + pin - 1) & 3);
422    
423     return irq;
424     }
425     diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
426     index 05db95d0..81edd31b 100644
427     --- a/arch/arm/xen/enlighten.c
428     +++ b/arch/arm/xen/enlighten.c
429     @@ -273,12 +273,15 @@ core_initcall(xen_guest_init);
430    
431     static int __init xen_pm_init(void)
432     {
433     + if (!xen_domain())
434     + return -ENODEV;
435     +
436     pm_power_off = xen_power_off;
437     arm_pm_restart = xen_restart;
438    
439     return 0;
440     }
441     -subsys_initcall(xen_pm_init);
442     +late_initcall(xen_pm_init);
443    
444     static irqreturn_t xen_arm_callback(int irq, void *arg)
445     {
446     diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
447     index 12e6ccb8..cea1594f 100644
448     --- a/arch/arm64/kernel/perf_event.c
449     +++ b/arch/arm64/kernel/perf_event.c
450     @@ -325,7 +325,10 @@ validate_event(struct pmu_hw_events *hw_events,
451     if (is_software_event(event))
452     return 1;
453    
454     - if (event->pmu != leader_pmu || event->state <= PERF_EVENT_STATE_OFF)
455     + if (event->pmu != leader_pmu || event->state < PERF_EVENT_STATE_OFF)
456     + return 1;
457     +
458     + if (event->state == PERF_EVENT_STATE_OFF && !event->attr.enable_on_exec)
459     return 1;
460    
461     return armpmu->get_event_idx(hw_events, &fake_event) >= 0;
462     @@ -781,7 +784,7 @@ static const unsigned armv8_pmuv3_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
463     /*
464     * PMXEVTYPER: Event selection reg
465     */
466     -#define ARMV8_EVTYPE_MASK 0xc00000ff /* Mask for writable bits */
467     +#define ARMV8_EVTYPE_MASK 0xc80000ff /* Mask for writable bits */
468     #define ARMV8_EVTYPE_EVENT 0xff /* Mask for EVENT bits */
469    
470     /*
471     diff --git a/arch/mips/ath79/clock.c b/arch/mips/ath79/clock.c
472     index 765ef30e..733017b3 100644
473     --- a/arch/mips/ath79/clock.c
474     +++ b/arch/mips/ath79/clock.c
475     @@ -164,7 +164,7 @@ static void __init ar933x_clocks_init(void)
476     ath79_ahb_clk.rate = freq / t;
477     }
478    
479     - ath79_wdt_clk.rate = ath79_ref_clk.rate;
480     + ath79_wdt_clk.rate = ath79_ahb_clk.rate;
481     ath79_uart_clk.rate = ath79_ref_clk.rate;
482     }
483    
484     diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
485     index ee5b690a..52e5758e 100644
486     --- a/arch/powerpc/kernel/align.c
487     +++ b/arch/powerpc/kernel/align.c
488     @@ -764,6 +764,16 @@ int fix_alignment(struct pt_regs *regs)
489     nb = aligninfo[instr].len;
490     flags = aligninfo[instr].flags;
491    
492     + /* ldbrx/stdbrx overlap lfs/stfs in the DSISR unfortunately */
493     + if (IS_XFORM(instruction) && ((instruction >> 1) & 0x3ff) == 532) {
494     + nb = 8;
495     + flags = LD+SW;
496     + } else if (IS_XFORM(instruction) &&
497     + ((instruction >> 1) & 0x3ff) == 660) {
498     + nb = 8;
499     + flags = ST+SW;
500     + }
501     +
502     /* Byteswap little endian loads and stores */
503     swiz = 0;
504     if (regs->msr & MSR_LE) {
505     diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
506     index 94c1dd46..a3a5cb8e 100644
507     --- a/arch/powerpc/kvm/book3s_xics.c
508     +++ b/arch/powerpc/kvm/book3s_xics.c
509     @@ -19,6 +19,7 @@
510     #include <asm/hvcall.h>
511     #include <asm/xics.h>
512     #include <asm/debug.h>
513     +#include <asm/time.h>
514    
515     #include <linux/debugfs.h>
516     #include <linux/seq_file.h>
517     diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
518     index c11c8238..54b998f2 100644
519     --- a/arch/powerpc/platforms/pseries/setup.c
520     +++ b/arch/powerpc/platforms/pseries/setup.c
521     @@ -354,7 +354,7 @@ static int alloc_dispatch_log_kmem_cache(void)
522     }
523     early_initcall(alloc_dispatch_log_kmem_cache);
524    
525     -static void pSeries_idle(void)
526     +static void pseries_lpar_idle(void)
527     {
528     /* This would call on the cpuidle framework, and the back-end pseries
529     * driver to go to idle states
530     @@ -362,10 +362,22 @@ static void pSeries_idle(void)
531     if (cpuidle_idle_call()) {
532     /* On error, execute default handler
533     * to go into low thread priority and possibly
534     - * low power mode.
535     + * low power mode by cedeing processor to hypervisor
536     */
537     - HMT_low();
538     - HMT_very_low();
539     +
540     + /* Indicate to hypervisor that we are idle. */
541     + get_lppaca()->idle = 1;
542     +
543     + /*
544     + * Yield the processor to the hypervisor. We return if
545     + * an external interrupt occurs (which are driven prior
546     + * to returning here) or if a prod occurs from another
547     + * processor. When returning here, external interrupts
548     + * are enabled.
549     + */
550     + cede_processor();
551     +
552     + get_lppaca()->idle = 0;
553     }
554     }
555    
556     @@ -456,15 +468,14 @@ static void __init pSeries_setup_arch(void)
557    
558     pSeries_nvram_init();
559    
560     - if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
561     + if (firmware_has_feature(FW_FEATURE_LPAR)) {
562     vpa_init(boot_cpuid);
563     - ppc_md.power_save = pSeries_idle;
564     - }
565     -
566     - if (firmware_has_feature(FW_FEATURE_LPAR))
567     + ppc_md.power_save = pseries_lpar_idle;
568     ppc_md.enable_pmcs = pseries_lpar_enable_pmcs;
569     - else
570     + } else {
571     + /* No special idle routine */
572     ppc_md.enable_pmcs = power4_enable_pmcs;
573     + }
574    
575     ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
576    
577     diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
578     index 95feaa47..c70a234a 100644
579     --- a/arch/um/include/shared/os.h
580     +++ b/arch/um/include/shared/os.h
581     @@ -200,6 +200,7 @@ extern int os_unmap_memory(void *addr, int len);
582     extern int os_drop_memory(void *addr, int length);
583     extern int can_drop_memory(void);
584     extern void os_flush_stdout(void);
585     +extern int os_mincore(void *addr, unsigned long len);
586    
587     /* execvp.c */
588     extern int execvp_noalloc(char *buf, const char *file, char *const argv[]);
589     diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile
590     index babe2182..d8b78a03 100644
591     --- a/arch/um/kernel/Makefile
592     +++ b/arch/um/kernel/Makefile
593     @@ -13,7 +13,7 @@ clean-files :=
594     obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \
595     physmem.o process.o ptrace.o reboot.o sigio.o \
596     signal.o smp.o syscall.o sysrq.o time.o tlb.o trap.o \
597     - um_arch.o umid.o skas/
598     + um_arch.o umid.o maccess.o skas/
599    
600     obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
601     obj-$(CONFIG_GPROF) += gprof_syms.o
602     diff --git a/arch/um/kernel/maccess.c b/arch/um/kernel/maccess.c
603     new file mode 100644
604     index 00000000..1f3d5c49
605     --- /dev/null
606     +++ b/arch/um/kernel/maccess.c
607     @@ -0,0 +1,24 @@
608     +/*
609     + * Copyright (C) 2013 Richard Weinberger <richrd@nod.at>
610     + *
611     + * This program is free software; you can redistribute it and/or modify
612     + * it under the terms of the GNU General Public License version 2 as
613     + * published by the Free Software Foundation.
614     + */
615     +
616     +#include <linux/uaccess.h>
617     +#include <linux/kernel.h>
618     +#include <os.h>
619     +
620     +long probe_kernel_read(void *dst, const void *src, size_t size)
621     +{
622     + void *psrc = (void *)rounddown((unsigned long)src, PAGE_SIZE);
623     +
624     + if ((unsigned long)src < PAGE_SIZE || size <= 0)
625     + return -EFAULT;
626     +
627     + if (os_mincore(psrc, size + src - psrc) <= 0)
628     + return -EFAULT;
629     +
630     + return __probe_kernel_read(dst, src, size);
631     +}
632     diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c
633     index b8f34c9e..67b9c8f5 100644
634     --- a/arch/um/os-Linux/process.c
635     +++ b/arch/um/os-Linux/process.c
636     @@ -4,6 +4,7 @@
637     */
638    
639     #include <stdio.h>
640     +#include <stdlib.h>
641     #include <unistd.h>
642     #include <errno.h>
643     #include <signal.h>
644     @@ -232,6 +233,57 @@ out:
645     return ok;
646     }
647    
648     +static int os_page_mincore(void *addr)
649     +{
650     + char vec[2];
651     + int ret;
652     +
653     + ret = mincore(addr, UM_KERN_PAGE_SIZE, vec);
654     + if (ret < 0) {
655     + if (errno == ENOMEM || errno == EINVAL)
656     + return 0;
657     + else
658     + return -errno;
659     + }
660     +
661     + return vec[0] & 1;
662     +}
663     +
664     +int os_mincore(void *addr, unsigned long len)
665     +{
666     + char *vec;
667     + int ret, i;
668     +
669     + if (len <= UM_KERN_PAGE_SIZE)
670     + return os_page_mincore(addr);
671     +
672     + vec = calloc(1, (len + UM_KERN_PAGE_SIZE - 1) / UM_KERN_PAGE_SIZE);
673     + if (!vec)
674     + return -ENOMEM;
675     +
676     + ret = mincore(addr, UM_KERN_PAGE_SIZE, vec);
677     + if (ret < 0) {
678     + if (errno == ENOMEM || errno == EINVAL)
679     + ret = 0;
680     + else
681     + ret = -errno;
682     +
683     + goto out;
684     + }
685     +
686     + for (i = 0; i < ((len + UM_KERN_PAGE_SIZE - 1) / UM_KERN_PAGE_SIZE); i++) {
687     + if (!(vec[i] & 1)) {
688     + ret = 0;
689     + goto out;
690     + }
691     + }
692     +
693     + ret = 1;
694     +out:
695     + free(vec);
696     + return ret;
697     +}
698     +
699     void init_new_thread_signals(void)
700     {
701     set_handler(SIGSEGV);
702     diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
703     index cf1a471a..10adb41f 100644
704     --- a/arch/x86/ia32/ia32_signal.c
705     +++ b/arch/x86/ia32/ia32_signal.c
706     @@ -459,7 +459,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
707     else
708     put_user_ex(0, &frame->uc.uc_flags);
709     put_user_ex(0, &frame->uc.uc_link);
710     - err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
711     + compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
712    
713     if (ksig->ka.sa.sa_flags & SA_RESTORER)
714     restorer = ksig->ka.sa.sa_restorer;
715     diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
716     index 46fc474f..f50de695 100644
717     --- a/arch/x86/include/asm/checksum_32.h
718     +++ b/arch/x86/include/asm/checksum_32.h
719     @@ -49,9 +49,15 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
720     int len, __wsum sum,
721     int *err_ptr)
722     {
723     + __wsum ret;
724     +
725     might_sleep();
726     - return csum_partial_copy_generic((__force void *)src, dst,
727     - len, sum, err_ptr, NULL);
728     + stac();
729     + ret = csum_partial_copy_generic((__force void *)src, dst,
730     + len, sum, err_ptr, NULL);
731     + clac();
732     +
733     + return ret;
734     }
735    
736     /*
737     @@ -176,10 +182,16 @@ static inline __wsum csum_and_copy_to_user(const void *src,
738     int len, __wsum sum,
739     int *err_ptr)
740     {
741     + __wsum ret;
742     +
743     might_sleep();
744     - if (access_ok(VERIFY_WRITE, dst, len))
745     - return csum_partial_copy_generic(src, (__force void *)dst,
746     - len, sum, NULL, err_ptr);
747     + if (access_ok(VERIFY_WRITE, dst, len)) {
748     + stac();
749     + ret = csum_partial_copy_generic(src, (__force void *)dst,
750     + len, sum, NULL, err_ptr);
751     + clac();
752     + return ret;
753     + }
754    
755     if (len)
756     *err_ptr = -EFAULT;
757     diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h
758     index fa5f71e0..e6833c65 100644
759     --- a/arch/x86/include/asm/mce.h
760     +++ b/arch/x86/include/asm/mce.h
761     @@ -32,11 +32,20 @@
762     #define MCI_STATUS_PCC (1ULL<<57) /* processor context corrupt */
763     #define MCI_STATUS_S (1ULL<<56) /* Signaled machine check */
764     #define MCI_STATUS_AR (1ULL<<55) /* Action required */
765     -#define MCACOD 0xffff /* MCA Error Code */
766     +
767     +/*
768     + * Note that the full MCACOD field of IA32_MCi_STATUS MSR is
769     + * bits 15:0. But bit 12 is the 'F' bit, defined for corrected
770     + * errors to indicate that errors are being filtered by hardware.
771     + * We should mask out bit 12 when looking for specific signatures
772     + * of uncorrected errors - so the F bit is deliberately skipped
773     + * in this #define.
774     + */
775     +#define MCACOD 0xefff /* MCA Error Code */
776    
777     /* Architecturally defined codes from SDM Vol. 3B Chapter 15 */
778     #define MCACOD_SCRUB 0x00C0 /* 0xC0-0xCF Memory Scrubbing */
779     -#define MCACOD_SCRUBMSK 0xfff0
780     +#define MCACOD_SCRUBMSK 0xeff0 /* Skip bit 12 ('F' bit) */
781     #define MCACOD_L3WB 0x017A /* L3 Explicit Writeback */
782     #define MCACOD_DATA 0x0134 /* Data Load */
783     #define MCACOD_INSTR 0x0150 /* Instruction Fetch */
784     diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
785     index cdbf3677..be12c534 100644
786     --- a/arch/x86/include/asm/mmu_context.h
787     +++ b/arch/x86/include/asm/mmu_context.h
788     @@ -45,22 +45,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
789     /* Re-load page tables */
790     load_cr3(next->pgd);
791    
792     - /* stop flush ipis for the previous mm */
793     + /* Stop flush ipis for the previous mm */
794     cpumask_clear_cpu(cpu, mm_cpumask(prev));
795    
796     - /*
797     - * load the LDT, if the LDT is different:
798     - */
799     + /* Load the LDT, if the LDT is different: */
800     if (unlikely(prev->context.ldt != next->context.ldt))
801     load_LDT_nolock(&next->context);
802     }
803     #ifdef CONFIG_SMP
804     - else {
805     + else {
806     this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
807     BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
808    
809     - if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next))) {
810     - /* We were in lazy tlb mode and leave_mm disabled
811     + if (!cpumask_test_cpu(cpu, mm_cpumask(next))) {
812     + /*
813     + * On established mms, the mm_cpumask is only changed
814     + * from irq context, from ptep_clear_flush() while in
815     + * lazy tlb mode, and here. Irqs are blocked during
816     + * schedule, protecting us from simultaneous changes.
817     + */
818     + cpumask_set_cpu(cpu, mm_cpumask(next));
819     + /*
820     + * We were in lazy tlb mode and leave_mm disabled
821     * tlb flush IPI delivery. We must reload CR3
822     * to make sure to use no freed page tables.
823     */
824     diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
825     index 3048ded1..59554dca 100644
826     --- a/arch/x86/kernel/amd_nb.c
827     +++ b/arch/x86/kernel/amd_nb.c
828     @@ -20,6 +20,7 @@ const struct pci_device_id amd_nb_misc_ids[] = {
829     { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) },
830     { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) },
831     { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M10H_F3) },
832     + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F3) },
833     { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) },
834     {}
835     };
836     @@ -27,6 +28,7 @@ EXPORT_SYMBOL(amd_nb_misc_ids);
837    
838     static const struct pci_device_id amd_nb_link_ids[] = {
839     { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) },
840     + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F4) },
841     { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) },
842     {}
843     };
844     @@ -81,13 +83,20 @@ int amd_cache_northbridges(void)
845     next_northbridge(misc, amd_nb_misc_ids);
846     node_to_amd_nb(i)->link = link =
847     next_northbridge(link, amd_nb_link_ids);
848     - }
849     + }
850    
851     + /* GART present only on Fam15h upto model 0fh */
852     if (boot_cpu_data.x86 == 0xf || boot_cpu_data.x86 == 0x10 ||
853     - boot_cpu_data.x86 == 0x15)
854     + (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model < 0x10))
855     amd_northbridges.flags |= AMD_NB_GART;
856    
857     /*
858     + * Check for L3 cache presence.
859     + */
860     + if (!cpuid_edx(0x80000006))
861     + return 0;
862     +
863     + /*
864     * Some CPU families support L3 Cache Index Disable. There are some
865     * limitations because of E382 and E388 on family 0x10.
866     */
867     diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
868     index 69562992..087ab2af 100644
869     --- a/arch/x86/kernel/signal.c
870     +++ b/arch/x86/kernel/signal.c
871     @@ -364,7 +364,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
872     else
873     put_user_ex(0, &frame->uc.uc_flags);
874     put_user_ex(0, &frame->uc.uc_link);
875     - err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
876     + save_altstack_ex(&frame->uc.uc_stack, regs->sp);
877    
878     /* Set up to return from userspace. */
879     restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
880     @@ -429,7 +429,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
881     else
882     put_user_ex(0, &frame->uc.uc_flags);
883     put_user_ex(0, &frame->uc.uc_link);
884     - err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
885     + save_altstack_ex(&frame->uc.uc_stack, regs->sp);
886    
887     /* Set up to return from userspace. If provided, use a stub
888     already in userspace. */
889     @@ -496,7 +496,7 @@ static int x32_setup_rt_frame(struct ksignal *ksig,
890     else
891     put_user_ex(0, &frame->uc.uc_flags);
892     put_user_ex(0, &frame->uc.uc_link);
893     - err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
894     + compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
895     put_user_ex(0, &frame->uc.uc__pad0);
896    
897     if (ksig->ka.sa.sa_flags & SA_RESTORER) {
898     diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
899     index 25b7ae8d..7609e0e4 100644
900     --- a/arch/x86/lib/csum-wrappers_64.c
901     +++ b/arch/x86/lib/csum-wrappers_64.c
902     @@ -6,6 +6,7 @@
903     */
904     #include <asm/checksum.h>
905     #include <linux/module.h>
906     +#include <asm/smap.h>
907    
908     /**
909     * csum_partial_copy_from_user - Copy and checksum from user space.
910     @@ -52,8 +53,10 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
911     len -= 2;
912     }
913     }
914     + stac();
915     isum = csum_partial_copy_generic((__force const void *)src,
916     dst, len, isum, errp, NULL);
917     + clac();
918     if (unlikely(*errp))
919     goto out_err;
920    
921     @@ -82,6 +85,8 @@ __wsum
922     csum_partial_copy_to_user(const void *src, void __user *dst,
923     int len, __wsum isum, int *errp)
924     {
925     + __wsum ret;
926     +
927     might_sleep();
928    
929     if (unlikely(!access_ok(VERIFY_WRITE, dst, len))) {
930     @@ -105,8 +110,11 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
931     }
932    
933     *errp = 0;
934     - return csum_partial_copy_generic(src, (void __force *)dst,
935     - len, isum, NULL, errp);
936     + stac();
937     + ret = csum_partial_copy_generic(src, (void __force *)dst,
938     + len, isum, NULL, errp);
939     + clac();
940     + return ret;
941     }
942     EXPORT_SYMBOL(csum_partial_copy_to_user);
943    
944     diff --git a/crypto/api.c b/crypto/api.c
945     index 3b618033..37c4c721 100644
946     --- a/crypto/api.c
947     +++ b/crypto/api.c
948     @@ -34,6 +34,8 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
949     BLOCKING_NOTIFIER_HEAD(crypto_chain);
950     EXPORT_SYMBOL_GPL(crypto_chain);
951    
952     +static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
953     +
954     struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
955     {
956     return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;
957     @@ -144,8 +146,11 @@ static struct crypto_alg *crypto_larval_add(const char *name, u32 type,
958     }
959     up_write(&crypto_alg_sem);
960    
961     - if (alg != &larval->alg)
962     + if (alg != &larval->alg) {
963     kfree(larval);
964     + if (crypto_is_larval(alg))
965     + alg = crypto_larval_wait(alg);
966     + }
967    
968     return alg;
969     }
970     diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
971     index cab13f2f..7c451cb2 100644
972     --- a/drivers/acpi/acpi_lpss.c
973     +++ b/drivers/acpi/acpi_lpss.c
974     @@ -155,12 +155,13 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
975     pdata->mmio_size = resource_size(&rentry->res);
976     pdata->mmio_base = ioremap(rentry->res.start,
977     pdata->mmio_size);
978     - pdata->dev_desc = dev_desc;
979     break;
980     }
981    
982     acpi_dev_free_resource_list(&resource_list);
983    
984     + pdata->dev_desc = dev_desc;
985     +
986     if (dev_desc->clk_required) {
987     ret = register_device_clock(adev, pdata);
988     if (ret) {
989     diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
990     index aff789d6..8c7421af 100644
991     --- a/drivers/block/rbd.c
992     +++ b/drivers/block/rbd.c
993     @@ -1565,11 +1565,12 @@ rbd_img_obj_request_read_callback(struct rbd_obj_request *obj_request)
994     obj_request, obj_request->img_request, obj_request->result,
995     xferred, length);
996     /*
997     - * ENOENT means a hole in the image. We zero-fill the
998     - * entire length of the request. A short read also implies
999     - * zero-fill to the end of the request. Either way we
1000     - * update the xferred count to indicate the whole request
1001     - * was satisfied.
1002     + * ENOENT means a hole in the image. We zero-fill the entire
1003     + * length of the request. A short read also implies zero-fill
1004     + * to the end of the request. An error requires the whole
1005     + * length of the request to be reported finished with an error
1006     + * to the block layer. In each case we update the xferred
1007     + * count to indicate the whole request was satisfied.
1008     */
1009     rbd_assert(obj_request->type != OBJ_REQUEST_NODATA);
1010     if (obj_request->result == -ENOENT) {
1011     @@ -1578,14 +1579,13 @@ rbd_img_obj_request_read_callback(struct rbd_obj_request *obj_request)
1012     else
1013     zero_pages(obj_request->pages, 0, length);
1014     obj_request->result = 0;
1015     - obj_request->xferred = length;
1016     } else if (xferred < length && !obj_request->result) {
1017     if (obj_request->type == OBJ_REQUEST_BIO)
1018     zero_bio_chain(obj_request->bio_list, xferred);
1019     else
1020     zero_pages(obj_request->pages, xferred, length);
1021     - obj_request->xferred = length;
1022     }
1023     + obj_request->xferred = length;
1024     obj_request_done_set(obj_request);
1025     }
1026    
1027     diff --git a/drivers/clk/clk-wm831x.c b/drivers/clk/clk-wm831x.c
1028     index 16ed0680..917a3ab4 100644
1029     --- a/drivers/clk/clk-wm831x.c
1030     +++ b/drivers/clk/clk-wm831x.c
1031     @@ -360,6 +360,8 @@ static int wm831x_clk_probe(struct platform_device *pdev)
1032     if (!clkdata)
1033     return -ENOMEM;
1034    
1035     + clkdata->wm831x = wm831x;
1036     +
1037     /* XTAL_ENA can only be set via OTP/InstantConfig so just read once */
1038     ret = wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_2);
1039     if (ret < 0) {
1040     diff --git a/drivers/cpuidle/coupled.c b/drivers/cpuidle/coupled.c
1041     index 2a297f86..fe853903 100644
1042     --- a/drivers/cpuidle/coupled.c
1043     +++ b/drivers/cpuidle/coupled.c
1044     @@ -106,6 +106,7 @@ struct cpuidle_coupled {
1045     cpumask_t coupled_cpus;
1046     int requested_state[NR_CPUS];
1047     atomic_t ready_waiting_counts;
1048     + atomic_t abort_barrier;
1049     int online_count;
1050     int refcnt;
1051     int prevent;
1052     @@ -122,12 +123,19 @@ static DEFINE_MUTEX(cpuidle_coupled_lock);
1053     static DEFINE_PER_CPU(struct call_single_data, cpuidle_coupled_poke_cb);
1054    
1055     /*
1056     - * The cpuidle_coupled_poked_mask mask is used to avoid calling
1057     + * The cpuidle_coupled_poke_pending mask is used to avoid calling
1058     * __smp_call_function_single with the per cpu call_single_data struct already
1059     * in use. This prevents a deadlock where two cpus are waiting for each others
1060     * call_single_data struct to be available
1061     */
1062     -static cpumask_t cpuidle_coupled_poked_mask;
1063     +static cpumask_t cpuidle_coupled_poke_pending;
1064     +
1065     +/*
1066     + * The cpuidle_coupled_poked mask is used to ensure that each cpu has been poked
1067     + * once to minimize entering the ready loop with a poke pending, which would
1068     + * require aborting and retrying.
1069     + */
1070     +static cpumask_t cpuidle_coupled_poked;
1071    
1072     /**
1073     * cpuidle_coupled_parallel_barrier - synchronize all online coupled cpus
1074     @@ -291,10 +299,11 @@ static inline int cpuidle_coupled_get_state(struct cpuidle_device *dev,
1075     return state;
1076     }
1077    
1078     -static void cpuidle_coupled_poked(void *info)
1079     +static void cpuidle_coupled_handle_poke(void *info)
1080     {
1081     int cpu = (unsigned long)info;
1082     - cpumask_clear_cpu(cpu, &cpuidle_coupled_poked_mask);
1083     + cpumask_set_cpu(cpu, &cpuidle_coupled_poked);
1084     + cpumask_clear_cpu(cpu, &cpuidle_coupled_poke_pending);
1085     }
1086    
1087     /**
1088     @@ -313,7 +322,7 @@ static void cpuidle_coupled_poke(int cpu)
1089     {
1090     struct call_single_data *csd = &per_cpu(cpuidle_coupled_poke_cb, cpu);
1091    
1092     - if (!cpumask_test_and_set_cpu(cpu, &cpuidle_coupled_poked_mask))
1093     + if (!cpumask_test_and_set_cpu(cpu, &cpuidle_coupled_poke_pending))
1094     __smp_call_function_single(cpu, csd, 0);
1095     }
1096    
1097     @@ -340,30 +349,19 @@ static void cpuidle_coupled_poke_others(int this_cpu,
1098     * @coupled: the struct coupled that contains the current cpu
1099     * @next_state: the index in drv->states of the requested state for this cpu
1100     *
1101     - * Updates the requested idle state for the specified cpuidle device,
1102     - * poking all coupled cpus out of idle if necessary to let them see the new
1103     - * state.
1104     + * Updates the requested idle state for the specified cpuidle device.
1105     + * Returns the number of waiting cpus.
1106     */
1107     -static void cpuidle_coupled_set_waiting(int cpu,
1108     +static int cpuidle_coupled_set_waiting(int cpu,
1109     struct cpuidle_coupled *coupled, int next_state)
1110     {
1111     - int w;
1112     -
1113     coupled->requested_state[cpu] = next_state;
1114    
1115     /*
1116     - * If this is the last cpu to enter the waiting state, poke
1117     - * all the other cpus out of their waiting state so they can
1118     - * enter a deeper state. This can race with one of the cpus
1119     - * exiting the waiting state due to an interrupt and
1120     - * decrementing waiting_count, see comment below.
1121     - *
1122     * The atomic_inc_return provides a write barrier to order the write
1123     * to requested_state with the later write that increments ready_count.
1124     */
1125     - w = atomic_inc_return(&coupled->ready_waiting_counts) & WAITING_MASK;
1126     - if (w == coupled->online_count)
1127     - cpuidle_coupled_poke_others(cpu, coupled);
1128     + return atomic_inc_return(&coupled->ready_waiting_counts) & WAITING_MASK;
1129     }
1130    
1131     /**
1132     @@ -410,19 +408,33 @@ static void cpuidle_coupled_set_done(int cpu, struct cpuidle_coupled *coupled)
1133     * been processed and the poke bit has been cleared.
1134     *
1135     * Other interrupts may also be processed while interrupts are enabled, so
1136     - * need_resched() must be tested after turning interrupts off again to make sure
1137     + * need_resched() must be tested after this function returns to make sure
1138     * the interrupt didn't schedule work that should take the cpu out of idle.
1139     *
1140     - * Returns 0 if need_resched was false, -EINTR if need_resched was true.
1141     + * Returns 0 if no poke was pending, 1 if a poke was cleared.
1142     */
1143     static int cpuidle_coupled_clear_pokes(int cpu)
1144     {
1145     + if (!cpumask_test_cpu(cpu, &cpuidle_coupled_poke_pending))
1146     + return 0;
1147     +
1148     local_irq_enable();
1149     - while (cpumask_test_cpu(cpu, &cpuidle_coupled_poked_mask))
1150     + while (cpumask_test_cpu(cpu, &cpuidle_coupled_poke_pending))
1151     cpu_relax();
1152     local_irq_disable();
1153    
1154     - return need_resched() ? -EINTR : 0;
1155     + return 1;
1156     +}
1157     +
1158     +static bool cpuidle_coupled_any_pokes_pending(struct cpuidle_coupled *coupled)
1159     +{
1160     + cpumask_t cpus;
1161     + int ret;
1162     +
1163     + cpumask_and(&cpus, cpu_online_mask, &coupled->coupled_cpus);
1164     + ret = cpumask_and(&cpus, &cpuidle_coupled_poke_pending, &cpus);
1165     +
1166     + return ret;
1167     }
1168    
1169     /**
1170     @@ -449,12 +461,14 @@ int cpuidle_enter_state_coupled(struct cpuidle_device *dev,
1171     {
1172     int entered_state = -1;
1173     struct cpuidle_coupled *coupled = dev->coupled;
1174     + int w;
1175    
1176     if (!coupled)
1177     return -EINVAL;
1178    
1179     while (coupled->prevent) {
1180     - if (cpuidle_coupled_clear_pokes(dev->cpu)) {
1181     + cpuidle_coupled_clear_pokes(dev->cpu);
1182     + if (need_resched()) {
1183     local_irq_enable();
1184     return entered_state;
1185     }
1186     @@ -465,15 +479,37 @@ int cpuidle_enter_state_coupled(struct cpuidle_device *dev,
1187     /* Read barrier ensures online_count is read after prevent is cleared */
1188     smp_rmb();
1189    
1190     - cpuidle_coupled_set_waiting(dev->cpu, coupled, next_state);
1191     +reset:
1192     + cpumask_clear_cpu(dev->cpu, &cpuidle_coupled_poked);
1193     +
1194     + w = cpuidle_coupled_set_waiting(dev->cpu, coupled, next_state);
1195     + /*
1196     + * If this is the last cpu to enter the waiting state, poke
1197     + * all the other cpus out of their waiting state so they can
1198     + * enter a deeper state. This can race with one of the cpus
1199     + * exiting the waiting state due to an interrupt and
1200     + * decrementing waiting_count, see comment below.
1201     + */
1202     + if (w == coupled->online_count) {
1203     + cpumask_set_cpu(dev->cpu, &cpuidle_coupled_poked);
1204     + cpuidle_coupled_poke_others(dev->cpu, coupled);
1205     + }
1206    
1207     retry:
1208     /*
1209     * Wait for all coupled cpus to be idle, using the deepest state
1210     - * allowed for a single cpu.
1211     + * allowed for a single cpu. If this was not the poking cpu, wait
1212     + * for at least one poke before leaving to avoid a race where
1213     + * two cpus could arrive at the waiting loop at the same time,
1214     + * but the first of the two to arrive could skip the loop without
1215     + * processing the pokes from the last to arrive.
1216     */
1217     - while (!cpuidle_coupled_cpus_waiting(coupled)) {
1218     - if (cpuidle_coupled_clear_pokes(dev->cpu)) {
1219     + while (!cpuidle_coupled_cpus_waiting(coupled) ||
1220     + !cpumask_test_cpu(dev->cpu, &cpuidle_coupled_poked)) {
1221     + if (cpuidle_coupled_clear_pokes(dev->cpu))
1222     + continue;
1223     +
1224     + if (need_resched()) {
1225     cpuidle_coupled_set_not_waiting(dev->cpu, coupled);
1226     goto out;
1227     }
1228     @@ -487,12 +523,19 @@ retry:
1229     dev->safe_state_index);
1230     }
1231    
1232     - if (cpuidle_coupled_clear_pokes(dev->cpu)) {
1233     + cpuidle_coupled_clear_pokes(dev->cpu);
1234     + if (need_resched()) {
1235     cpuidle_coupled_set_not_waiting(dev->cpu, coupled);
1236     goto out;
1237     }
1238    
1239     /*
1240     + * Make sure final poke status for this cpu is visible before setting
1241     + * cpu as ready.
1242     + */
1243     + smp_wmb();
1244     +
1245     + /*
1246     * All coupled cpus are probably idle. There is a small chance that
1247     * one of the other cpus just became active. Increment the ready count,
1248     * and spin until all coupled cpus have incremented the counter. Once a
1249     @@ -511,6 +554,28 @@ retry:
1250     cpu_relax();
1251     }
1252    
1253     + /*
1254     + * Make sure read of all cpus ready is done before reading pending pokes
1255     + */
1256     + smp_rmb();
1257     +
1258     + /*
1259     + * There is a small chance that a cpu left and reentered idle after this
1260     + * cpu saw that all cpus were waiting. The cpu that reentered idle will
1261     + * have sent this cpu a poke, which will still be pending after the
1262     + * ready loop. The pending interrupt may be lost by the interrupt
1263     + * controller when entering the deep idle state. It's not possible to
1264     + * clear a pending interrupt without turning interrupts on and handling
1265     + * it, and it's too late to turn on interrupts here, so reset the
1266     + * coupled idle state of all cpus and retry.
1267     + */
1268     + if (cpuidle_coupled_any_pokes_pending(coupled)) {
1269     + cpuidle_coupled_set_done(dev->cpu, coupled);
1270     + /* Wait for all cpus to see the pending pokes */
1271     + cpuidle_coupled_parallel_barrier(dev, &coupled->abort_barrier);
1272     + goto reset;
1273     + }
1274     +
1275     /* all cpus have acked the coupled state */
1276     next_state = cpuidle_coupled_get_state(dev, coupled);
1277    
1278     @@ -596,7 +661,7 @@ have_coupled:
1279     coupled->refcnt++;
1280    
1281     csd = &per_cpu(cpuidle_coupled_poke_cb, dev->cpu);
1282     - csd->func = cpuidle_coupled_poked;
1283     + csd->func = cpuidle_coupled_handle_poke;
1284     csd->info = (void *)(unsigned long)dev->cpu;
1285    
1286     return 0;
1287     diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
1288     index 8b6a0343..8b3d9014 100644
1289     --- a/drivers/edac/amd64_edac.c
1290     +++ b/drivers/edac/amd64_edac.c
1291     @@ -2470,8 +2470,15 @@ static int amd64_init_one_instance(struct pci_dev *F2)
1292     layers[0].size = pvt->csels[0].b_cnt;
1293     layers[0].is_virt_csrow = true;
1294     layers[1].type = EDAC_MC_LAYER_CHANNEL;
1295     - layers[1].size = pvt->channel_count;
1296     +
1297     + /*
1298     + * Always allocate two channels since we can have setups with DIMMs on
1299     + * only one channel. Also, this simplifies handling later for the price
1300     + * of a couple of KBs tops.
1301     + */
1302     + layers[1].size = 2;
1303     layers[1].is_virt_csrow = false;
1304     +
1305     mci = edac_mc_alloc(nid, ARRAY_SIZE(layers), layers, 0);
1306     if (!mci)
1307     goto err_siblings;
1308     diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
1309     index 9e62bbed..0cb9b5d8 100644
1310     --- a/drivers/gpu/drm/drm_edid.c
1311     +++ b/drivers/gpu/drm/drm_edid.c
1312     @@ -125,6 +125,9 @@ static struct edid_quirk {
1313    
1314     /* ViewSonic VA2026w */
1315     { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
1316     +
1317     + /* Medion MD 30217 PG */
1318     + { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
1319     };
1320    
1321     /*
1322     diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
1323     index 402f4868..ed626e01 100644
1324     --- a/drivers/hid/hid-core.c
1325     +++ b/drivers/hid/hid-core.c
1326     @@ -63,6 +63,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,
1327     struct hid_report_enum *report_enum = device->report_enum + type;
1328     struct hid_report *report;
1329    
1330     + if (id >= HID_MAX_IDS)
1331     + return NULL;
1332     if (report_enum->report_id_hash[id])
1333     return report_enum->report_id_hash[id];
1334    
1335     @@ -404,8 +406,10 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
1336    
1337     case HID_GLOBAL_ITEM_TAG_REPORT_ID:
1338     parser->global.report_id = item_udata(item);
1339     - if (parser->global.report_id == 0) {
1340     - hid_err(parser->device, "report_id 0 is invalid\n");
1341     + if (parser->global.report_id == 0 ||
1342     + parser->global.report_id >= HID_MAX_IDS) {
1343     + hid_err(parser->device, "report_id %u is invalid\n",
1344     + parser->global.report_id);
1345     return -1;
1346     }
1347     return 0;
1348     @@ -575,7 +579,7 @@ static void hid_close_report(struct hid_device *device)
1349     for (i = 0; i < HID_REPORT_TYPES; i++) {
1350     struct hid_report_enum *report_enum = device->report_enum + i;
1351    
1352     - for (j = 0; j < 256; j++) {
1353     + for (j = 0; j < HID_MAX_IDS; j++) {
1354     struct hid_report *report = report_enum->report_id_hash[j];
1355     if (report)
1356     hid_free_report(report);
1357     @@ -1152,7 +1156,12 @@ EXPORT_SYMBOL_GPL(hid_output_report);
1358    
1359     int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1360     {
1361     - unsigned size = field->report_size;
1362     + unsigned size;
1363     +
1364     + if (!field)
1365     + return -1;
1366     +
1367     + size = field->report_size;
1368    
1369     hid_dump_input(field->report->device, field->usage + offset, value);
1370    
1371     diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
1372     index 21688853..ca0219f9 100644
1373     --- a/drivers/hid/hid-ids.h
1374     +++ b/drivers/hid/hid-ids.h
1375     @@ -135,9 +135,9 @@
1376     #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
1377     #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI 0x0255
1378     #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256
1379     -#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0291
1380     -#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0292
1381     -#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0293
1382     +#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290
1383     +#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291
1384     +#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292
1385     #define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
1386     #define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
1387     #define USB_DEVICE_ID_APPLE_IRCONTROL 0x8240
1388     @@ -646,6 +646,7 @@
1389     #define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16 0x0012
1390     #define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17 0x0013
1391     #define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18 0x0014
1392     +#define USB_DEVICE_ID_NTRIG_DUOSENSE 0x1500
1393    
1394     #define USB_VENDOR_ID_ONTRAK 0x0a07
1395     #define USB_DEVICE_ID_ONTRAK_ADU100 0x0064
1396     diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
1397     index 945b8158..ac5e9352 100644
1398     --- a/drivers/hid/hid-input.c
1399     +++ b/drivers/hid/hid-input.c
1400     @@ -340,7 +340,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,
1401     {
1402     struct hid_device *dev = container_of(psy, struct hid_device, battery);
1403     int ret = 0;
1404     - __u8 buf[2] = {};
1405     + __u8 *buf;
1406    
1407     switch (prop) {
1408     case POWER_SUPPLY_PROP_PRESENT:
1409     @@ -349,13 +349,20 @@ static int hidinput_get_battery_property(struct power_supply *psy,
1410     break;
1411    
1412     case POWER_SUPPLY_PROP_CAPACITY:
1413     +
1414     + buf = kmalloc(2 * sizeof(__u8), GFP_KERNEL);
1415     + if (!buf) {
1416     + ret = -ENOMEM;
1417     + break;
1418     + }
1419     ret = dev->hid_get_raw_report(dev, dev->battery_report_id,
1420     - buf, sizeof(buf),
1421     + buf, 2,
1422     dev->battery_report_type);
1423    
1424     if (ret != 2) {
1425     if (ret >= 0)
1426     ret = -EINVAL;
1427     + kfree(buf);
1428     break;
1429     }
1430    
1431     @@ -364,6 +371,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,
1432     buf[1] <= dev->battery_max)
1433     val->intval = (100 * (buf[1] - dev->battery_min)) /
1434     (dev->battery_max - dev->battery_min);
1435     + kfree(buf);
1436     break;
1437    
1438     case POWER_SUPPLY_PROP_MODEL_NAME:
1439     diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
1440     index ef951025..5482156a 100644
1441     --- a/drivers/hid/hid-ntrig.c
1442     +++ b/drivers/hid/hid-ntrig.c
1443     @@ -115,7 +115,8 @@ static inline int ntrig_get_mode(struct hid_device *hdev)
1444     struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
1445     report_id_hash[0x0d];
1446    
1447     - if (!report)
1448     + if (!report || report->maxfield < 1 ||
1449     + report->field[0]->report_count < 1)
1450     return -EINVAL;
1451    
1452     hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
1453     diff --git a/drivers/hid/hid-picolcd_cir.c b/drivers/hid/hid-picolcd_cir.c
1454     index e346038f..59d5eb1e 100644
1455     --- a/drivers/hid/hid-picolcd_cir.c
1456     +++ b/drivers/hid/hid-picolcd_cir.c
1457     @@ -145,6 +145,7 @@ void picolcd_exit_cir(struct picolcd_data *data)
1458     struct rc_dev *rdev = data->rc_dev;
1459    
1460     data->rc_dev = NULL;
1461     - rc_unregister_device(rdev);
1462     + if (rdev)
1463     + rc_unregister_device(rdev);
1464     }
1465    
1466     diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
1467     index b48092d0..acbb0210 100644
1468     --- a/drivers/hid/hid-picolcd_core.c
1469     +++ b/drivers/hid/hid-picolcd_core.c
1470     @@ -290,7 +290,7 @@ static ssize_t picolcd_operation_mode_store(struct device *dev,
1471     buf += 10;
1472     cnt -= 10;
1473     }
1474     - if (!report)
1475     + if (!report || report->maxfield != 1)
1476     return -EINVAL;
1477    
1478     while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
1479     diff --git a/drivers/hid/hid-picolcd_fb.c b/drivers/hid/hid-picolcd_fb.c
1480     index 591f6b22..c930ab85 100644
1481     --- a/drivers/hid/hid-picolcd_fb.c
1482     +++ b/drivers/hid/hid-picolcd_fb.c
1483     @@ -593,10 +593,14 @@ err_nomem:
1484     void picolcd_exit_framebuffer(struct picolcd_data *data)
1485     {
1486     struct fb_info *info = data->fb_info;
1487     - struct picolcd_fb_data *fbdata = info->par;
1488     + struct picolcd_fb_data *fbdata;
1489     unsigned long flags;
1490    
1491     + if (!info)
1492     + return;
1493     +
1494     device_remove_file(&data->hdev->dev, &dev_attr_fb_update_rate);
1495     + fbdata = info->par;
1496    
1497     /* disconnect framebuffer from HID dev */
1498     spin_lock_irqsave(&fbdata->lock, flags);
1499     diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
1500     index d29112fa..2dcd7d98 100644
1501     --- a/drivers/hid/hid-pl.c
1502     +++ b/drivers/hid/hid-pl.c
1503     @@ -132,8 +132,14 @@ static int plff_init(struct hid_device *hid)
1504     strong = &report->field[0]->value[2];
1505     weak = &report->field[0]->value[3];
1506     debug("detected single-field device");
1507     - } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 &&
1508     - report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) {
1509     + } else if (report->field[0]->maxusage == 1 &&
1510     + report->field[0]->usage[0].hid ==
1511     + (HID_UP_LED | 0x43) &&
1512     + report->maxfield >= 4 &&
1513     + report->field[0]->report_count >= 1 &&
1514     + report->field[1]->report_count >= 1 &&
1515     + report->field[2]->report_count >= 1 &&
1516     + report->field[3]->report_count >= 1) {
1517     report->field[0]->value[0] = 0x00;
1518     report->field[1]->value[0] = 0x00;
1519     strong = &report->field[2]->value[0];
1520     diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
1521     index ca749810..aa34755c 100644
1522     --- a/drivers/hid/hid-sensor-hub.c
1523     +++ b/drivers/hid/hid-sensor-hub.c
1524     @@ -221,7 +221,8 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
1525    
1526     mutex_lock(&data->mutex);
1527     report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
1528     - if (!report || (field_index >= report->maxfield)) {
1529     + if (!report || (field_index >= report->maxfield) ||
1530     + report->field[field_index]->report_count < 1) {
1531     ret = -EINVAL;
1532     goto done_proc;
1533     }
1534     diff --git a/drivers/hid/hid-speedlink.c b/drivers/hid/hid-speedlink.c
1535     index a2f587d0..7112f3e8 100644
1536     --- a/drivers/hid/hid-speedlink.c
1537     +++ b/drivers/hid/hid-speedlink.c
1538     @@ -3,7 +3,7 @@
1539     * Fixes "jumpy" cursor and removes nonexistent keyboard LEDS from
1540     * the HID descriptor.
1541     *
1542     - * Copyright (c) 2011 Stefan Kriwanek <mail@stefankriwanek.de>
1543     + * Copyright (c) 2011, 2013 Stefan Kriwanek <dev@stefankriwanek.de>
1544     */
1545    
1546     /*
1547     @@ -46,8 +46,13 @@ static int speedlink_event(struct hid_device *hdev, struct hid_field *field,
1548     struct hid_usage *usage, __s32 value)
1549     {
1550     /* No other conditions due to usage_table. */
1551     - /* Fix "jumpy" cursor (invalid events sent by device). */
1552     - if (value == 256)
1553     +
1554     + /* This fixes the "jumpy" cursor occuring due to invalid events sent
1555     + * by the device. Some devices only send them with value==+256, others
1556     + * don't. However, catching abs(value)>=256 is restrictive enough not
1557     + * to interfere with devices that were bug-free (has been tested).
1558     + */
1559     + if (abs(value) >= 256)
1560     return 1;
1561     /* Drop useless distance 0 events (on button clicks etc.) as well */
1562     if (value == 0)
1563     diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
1564     index a7451632..612a655b 100644
1565     --- a/drivers/hid/hidraw.c
1566     +++ b/drivers/hid/hidraw.c
1567     @@ -113,7 +113,7 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer,
1568     __u8 *buf;
1569     int ret = 0;
1570    
1571     - if (!hidraw_table[minor]) {
1572     + if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
1573     ret = -ENODEV;
1574     goto out;
1575     }
1576     @@ -261,7 +261,7 @@ static int hidraw_open(struct inode *inode, struct file *file)
1577     }
1578    
1579     mutex_lock(&minors_lock);
1580     - if (!hidraw_table[minor]) {
1581     + if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
1582     err = -ENODEV;
1583     goto out_unlock;
1584     }
1585     @@ -302,39 +302,38 @@ static int hidraw_fasync(int fd, struct file *file, int on)
1586     return fasync_helper(fd, file, on, &list->fasync);
1587     }
1588    
1589     +static void drop_ref(struct hidraw *hidraw, int exists_bit)
1590     +{
1591     + if (exists_bit) {
1592     + hid_hw_close(hidraw->hid);
1593     + hidraw->exist = 0;
1594     + if (hidraw->open)
1595     + wake_up_interruptible(&hidraw->wait);
1596     + } else {
1597     + --hidraw->open;
1598     + }
1599     +
1600     + if (!hidraw->open && !hidraw->exist) {
1601     + device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
1602     + hidraw_table[hidraw->minor] = NULL;
1603     + kfree(hidraw);
1604     + }
1605     +}
1606     +
1607     static int hidraw_release(struct inode * inode, struct file * file)
1608     {
1609     unsigned int minor = iminor(inode);
1610     - struct hidraw *dev;
1611     struct hidraw_list *list = file->private_data;
1612     - int ret;
1613     - int i;
1614    
1615     mutex_lock(&minors_lock);
1616     - if (!hidraw_table[minor]) {
1617     - ret = -ENODEV;
1618     - goto unlock;
1619     - }
1620    
1621     list_del(&list->node);
1622     - dev = hidraw_table[minor];
1623     - if (!--dev->open) {
1624     - if (list->hidraw->exist) {
1625     - hid_hw_power(dev->hid, PM_HINT_NORMAL);
1626     - hid_hw_close(dev->hid);
1627     - } else {
1628     - kfree(list->hidraw);
1629     - }
1630     - }
1631     -
1632     - for (i = 0; i < HIDRAW_BUFFER_SIZE; ++i)
1633     - kfree(list->buffer[i].value);
1634     kfree(list);
1635     - ret = 0;
1636     -unlock:
1637     - mutex_unlock(&minors_lock);
1638    
1639     - return ret;
1640     + drop_ref(hidraw_table[minor], 0);
1641     +
1642     + mutex_unlock(&minors_lock);
1643     + return 0;
1644     }
1645    
1646     static long hidraw_ioctl(struct file *file, unsigned int cmd,
1647     @@ -539,18 +538,9 @@ void hidraw_disconnect(struct hid_device *hid)
1648     struct hidraw *hidraw = hid->hidraw;
1649    
1650     mutex_lock(&minors_lock);
1651     - hidraw->exist = 0;
1652     -
1653     - device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
1654    
1655     - hidraw_table[hidraw->minor] = NULL;
1656     + drop_ref(hidraw, 1);
1657    
1658     - if (hidraw->open) {
1659     - hid_hw_close(hid);
1660     - wake_up_interruptible(&hidraw->wait);
1661     - } else {
1662     - kfree(hidraw);
1663     - }
1664     mutex_unlock(&minors_lock);
1665     }
1666     EXPORT_SYMBOL_GPL(hidraw_disconnect);
1667     diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
1668     index 19b8360f..07345521 100644
1669     --- a/drivers/hid/usbhid/hid-quirks.c
1670     +++ b/drivers/hid/usbhid/hid-quirks.c
1671     @@ -109,6 +109,8 @@ static const struct hid_blacklist {
1672     { USB_VENDOR_ID_SIGMA_MICRO, USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD, HID_QUIRK_NO_INIT_REPORTS },
1673     { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT },
1674     { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT },
1675     + { USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS },
1676     +
1677     { 0, 0 }
1678     };
1679    
1680     diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
1681     index 4ef4d5e1..a73f9618 100644
1682     --- a/drivers/input/mouse/bcm5974.c
1683     +++ b/drivers/input/mouse/bcm5974.c
1684     @@ -89,9 +89,9 @@
1685     #define USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO 0x025a
1686     #define USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS 0x025b
1687     /* MacbookAir6,2 (unibody, June 2013) */
1688     -#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0291
1689     -#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0292
1690     -#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0293
1691     +#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290
1692     +#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291
1693     +#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292
1694    
1695     #define BCM5974_DEVICE(prod) { \
1696     .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \
1697     diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
1698     index b4f0e28d..fa004b11 100644
1699     --- a/drivers/iommu/intel-iommu.c
1700     +++ b/drivers/iommu/intel-iommu.c
1701     @@ -890,56 +890,54 @@ static int dma_pte_clear_range(struct dmar_domain *domain,
1702     return order;
1703     }
1704    
1705     +static void dma_pte_free_level(struct dmar_domain *domain, int level,
1706     + struct dma_pte *pte, unsigned long pfn,
1707     + unsigned long start_pfn, unsigned long last_pfn)
1708     +{
1709     + pfn = max(start_pfn, pfn);
1710     + pte = &pte[pfn_level_offset(pfn, level)];
1711     +
1712     + do {
1713     + unsigned long level_pfn;
1714     + struct dma_pte *level_pte;
1715     +
1716     + if (!dma_pte_present(pte) || dma_pte_superpage(pte))
1717     + goto next;
1718     +
1719     + level_pfn = pfn & level_mask(level - 1);
1720     + level_pte = phys_to_virt(dma_pte_addr(pte));
1721     +
1722     + if (level > 2)
1723     + dma_pte_free_level(domain, level - 1, level_pte,
1724     + level_pfn, start_pfn, last_pfn);
1725     +
1726     + /* If range covers entire pagetable, free it */
1727     + if (!(start_pfn > level_pfn ||
1728     + last_pfn < level_pfn + level_size(level))) {
1729     + dma_clear_pte(pte);
1730     + domain_flush_cache(domain, pte, sizeof(*pte));
1731     + free_pgtable_page(level_pte);
1732     + }
1733     +next:
1734     + pfn += level_size(level);
1735     + } while (!first_pte_in_page(++pte) && pfn <= last_pfn);
1736     +}
1737     +
1738     /* free page table pages. last level pte should already be cleared */
1739     static void dma_pte_free_pagetable(struct dmar_domain *domain,
1740     unsigned long start_pfn,
1741     unsigned long last_pfn)
1742     {
1743     int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;
1744     - struct dma_pte *first_pte, *pte;
1745     - int total = agaw_to_level(domain->agaw);
1746     - int level;
1747     - unsigned long tmp;
1748     - int large_page = 2;
1749    
1750     BUG_ON(addr_width < BITS_PER_LONG && start_pfn >> addr_width);
1751     BUG_ON(addr_width < BITS_PER_LONG && last_pfn >> addr_width);
1752     BUG_ON(start_pfn > last_pfn);
1753    
1754     /* We don't need lock here; nobody else touches the iova range */
1755     - level = 2;
1756     - while (level <= total) {
1757     - tmp = align_to_level(start_pfn, level);
1758     -
1759     - /* If we can't even clear one PTE at this level, we're done */
1760     - if (tmp + level_size(level) - 1 > last_pfn)
1761     - return;
1762     -
1763     - do {
1764     - large_page = level;
1765     - first_pte = pte = dma_pfn_level_pte(domain, tmp, level, &large_page);
1766     - if (large_page > level)
1767     - level = large_page + 1;
1768     - if (!pte) {
1769     - tmp = align_to_level(tmp + 1, level + 1);
1770     - continue;
1771     - }
1772     - do {
1773     - if (dma_pte_present(pte)) {
1774     - free_pgtable_page(phys_to_virt(dma_pte_addr(pte)));
1775     - dma_clear_pte(pte);
1776     - }
1777     - pte++;
1778     - tmp += level_size(level);
1779     - } while (!first_pte_in_page(pte) &&
1780     - tmp + level_size(level) - 1 <= last_pfn);
1781     + dma_pte_free_level(domain, agaw_to_level(domain->agaw),
1782     + domain->pgd, 0, start_pfn, last_pfn);
1783    
1784     - domain_flush_cache(domain, first_pte,
1785     - (void *)pte - (void *)first_pte);
1786     -
1787     - } while (tmp && tmp + level_size(level) - 1 <= last_pfn);
1788     - level++;
1789     - }
1790     /* free pgd */
1791     if (start_pfn == 0 && last_pfn == DOMAIN_MAX_PFN(domain->gaw)) {
1792     free_pgtable_page(domain->pgd);
1793     diff --git a/drivers/leds/leds-wm831x-status.c b/drivers/leds/leds-wm831x-status.c
1794     index 6bd5c679..b7d83d68 100644
1795     --- a/drivers/leds/leds-wm831x-status.c
1796     +++ b/drivers/leds/leds-wm831x-status.c
1797     @@ -230,9 +230,9 @@ static int wm831x_status_probe(struct platform_device *pdev)
1798     int id = pdev->id % ARRAY_SIZE(chip_pdata->status);
1799     int ret;
1800    
1801     - res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1802     + res = platform_get_resource(pdev, IORESOURCE_REG, 0);
1803     if (res == NULL) {
1804     - dev_err(&pdev->dev, "No I/O resource\n");
1805     + dev_err(&pdev->dev, "No register resource\n");
1806     ret = -EINVAL;
1807     goto err;
1808     }
1809     diff --git a/drivers/media/common/siano/smsdvb-main.c b/drivers/media/common/siano/smsdvb-main.c
1810     index 297f1b2f..8df1aea5 100644
1811     --- a/drivers/media/common/siano/smsdvb-main.c
1812     +++ b/drivers/media/common/siano/smsdvb-main.c
1813     @@ -275,7 +275,8 @@ static void smsdvb_update_per_slices(struct smsdvb_client_t *client,
1814    
1815     /* Legacy PER/BER */
1816     tmp = p->ets_packets * 65535;
1817     - do_div(tmp, p->ts_packets + p->ets_packets);
1818     + if (p->ts_packets + p->ets_packets)
1819     + do_div(tmp, p->ts_packets + p->ets_packets);
1820     client->legacy_per = tmp;
1821     }
1822    
1823     diff --git a/drivers/media/dvb-frontends/mb86a20s.c b/drivers/media/dvb-frontends/mb86a20s.c
1824     index 856374bd..2c7217fb 100644
1825     --- a/drivers/media/dvb-frontends/mb86a20s.c
1826     +++ b/drivers/media/dvb-frontends/mb86a20s.c
1827     @@ -157,7 +157,6 @@ static struct regdata mb86a20s_init2[] = {
1828     { 0x45, 0x04 }, /* CN symbol 4 */
1829     { 0x48, 0x04 }, /* CN manual mode */
1830    
1831     - { 0x50, 0xd5 }, { 0x51, 0x01 }, /* Serial */
1832     { 0x50, 0xd6 }, { 0x51, 0x1f },
1833     { 0x50, 0xd2 }, { 0x51, 0x03 },
1834     { 0x50, 0xd7 }, { 0x51, 0xbf },
1835     @@ -1860,16 +1859,15 @@ static int mb86a20s_initfe(struct dvb_frontend *fe)
1836     dev_dbg(&state->i2c->dev, "%s: IF=%d, IF reg=0x%06llx\n",
1837     __func__, state->if_freq, (long long)pll);
1838    
1839     - if (!state->config->is_serial) {
1840     + if (!state->config->is_serial)
1841     regD5 &= ~1;
1842    
1843     - rc = mb86a20s_writereg(state, 0x50, 0xd5);
1844     - if (rc < 0)
1845     - goto err;
1846     - rc = mb86a20s_writereg(state, 0x51, regD5);
1847     - if (rc < 0)
1848     - goto err;
1849     - }
1850     + rc = mb86a20s_writereg(state, 0x50, 0xd5);
1851     + if (rc < 0)
1852     + goto err;
1853     + rc = mb86a20s_writereg(state, 0x51, regD5);
1854     + if (rc < 0)
1855     + goto err;
1856    
1857     rc = mb86a20s_writeregdata(state, mb86a20s_init2);
1858     if (rc < 0)
1859     diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
1860     index 9d1481a6..c504f70d 100644
1861     --- a/drivers/media/platform/coda.c
1862     +++ b/drivers/media/platform/coda.c
1863     @@ -1933,7 +1933,7 @@ MODULE_DEVICE_TABLE(platform, coda_platform_ids);
1864    
1865     #ifdef CONFIG_OF
1866     static const struct of_device_id coda_dt_ids[] = {
1867     - { .compatible = "fsl,imx27-vpu", .data = &coda_platform_ids[CODA_IMX27] },
1868     + { .compatible = "fsl,imx27-vpu", .data = &coda_devdata[CODA_IMX27] },
1869     { .compatible = "fsl,imx53-vpu", .data = &coda_devdata[CODA_IMX53] },
1870     { /* sentinel */ }
1871     };
1872     diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
1873     index 33b5ffc8..f45b940d 100644
1874     --- a/drivers/media/platform/exynos-gsc/gsc-core.c
1875     +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
1876     @@ -1122,10 +1122,14 @@ static int gsc_probe(struct platform_device *pdev)
1877     goto err_clk;
1878     }
1879    
1880     - ret = gsc_register_m2m_device(gsc);
1881     + ret = v4l2_device_register(dev, &gsc->v4l2_dev);
1882     if (ret)
1883     goto err_clk;
1884    
1885     + ret = gsc_register_m2m_device(gsc);
1886     + if (ret)
1887     + goto err_v4l2;
1888     +
1889     platform_set_drvdata(pdev, gsc);
1890     pm_runtime_enable(dev);
1891     ret = pm_runtime_get_sync(&pdev->dev);
1892     @@ -1147,6 +1151,8 @@ err_pm:
1893     pm_runtime_put(dev);
1894     err_m2m:
1895     gsc_unregister_m2m_device(gsc);
1896     +err_v4l2:
1897     + v4l2_device_unregister(&gsc->v4l2_dev);
1898     err_clk:
1899     gsc_clk_put(gsc);
1900     return ret;
1901     @@ -1157,6 +1163,7 @@ static int gsc_remove(struct platform_device *pdev)
1902     struct gsc_dev *gsc = platform_get_drvdata(pdev);
1903    
1904     gsc_unregister_m2m_device(gsc);
1905     + v4l2_device_unregister(&gsc->v4l2_dev);
1906    
1907     vb2_dma_contig_cleanup_ctx(gsc->alloc_ctx);
1908     pm_runtime_disable(&pdev->dev);
1909     diff --git a/drivers/media/platform/exynos-gsc/gsc-core.h b/drivers/media/platform/exynos-gsc/gsc-core.h
1910     index cc19bba0..76435d3b 100644
1911     --- a/drivers/media/platform/exynos-gsc/gsc-core.h
1912     +++ b/drivers/media/platform/exynos-gsc/gsc-core.h
1913     @@ -343,6 +343,7 @@ struct gsc_dev {
1914     unsigned long state;
1915     struct vb2_alloc_ctx *alloc_ctx;
1916     struct video_device vdev;
1917     + struct v4l2_device v4l2_dev;
1918     };
1919    
1920     /**
1921     diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
1922     index 40a73f7d..e576ff2d 100644
1923     --- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
1924     +++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
1925     @@ -751,6 +751,7 @@ int gsc_register_m2m_device(struct gsc_dev *gsc)
1926     gsc->vdev.release = video_device_release_empty;
1927     gsc->vdev.lock = &gsc->lock;
1928     gsc->vdev.vfl_dir = VFL_DIR_M2M;
1929     + gsc->vdev.v4l2_dev = &gsc->v4l2_dev;
1930     snprintf(gsc->vdev.name, sizeof(gsc->vdev.name), "%s.%d:m2m",
1931     GSC_MODULE_NAME, gsc->id);
1932    
1933     diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
1934     index 15ef8f28..b5b480be 100644
1935     --- a/drivers/media/platform/exynos4-is/media-dev.c
1936     +++ b/drivers/media/platform/exynos4-is/media-dev.c
1937     @@ -1441,9 +1441,9 @@ static int fimc_md_probe(struct platform_device *pdev)
1938     err_unlock:
1939     mutex_unlock(&fmd->media_dev.graph_mutex);
1940     err_clk:
1941     - media_device_unregister(&fmd->media_dev);
1942     fimc_md_put_clocks(fmd);
1943     fimc_md_unregister_entities(fmd);
1944     + media_device_unregister(&fmd->media_dev);
1945     err_md:
1946     v4l2_device_unregister(&fmd->v4l2_dev);
1947     return ret;
1948     diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
1949     index 553d87e5..fd6289d6 100644
1950     --- a/drivers/media/platform/s5p-g2d/g2d.c
1951     +++ b/drivers/media/platform/s5p-g2d/g2d.c
1952     @@ -784,6 +784,7 @@ static int g2d_probe(struct platform_device *pdev)
1953     }
1954     *vfd = g2d_videodev;
1955     vfd->lock = &dev->mutex;
1956     + vfd->v4l2_dev = &dev->v4l2_dev;
1957     ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
1958     if (ret) {
1959     v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
1960     diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c
1961     index 8247c19d..77d7b7fb 100644
1962     --- a/drivers/media/usb/hdpvr/hdpvr-core.c
1963     +++ b/drivers/media/usb/hdpvr/hdpvr-core.c
1964     @@ -311,6 +311,11 @@ static int hdpvr_probe(struct usb_interface *interface,
1965    
1966     dev->workqueue = 0;
1967    
1968     + /* init video transfer queues first of all */
1969     + /* to prevent oops in hdpvr_delete() on error paths */
1970     + INIT_LIST_HEAD(&dev->free_buff_list);
1971     + INIT_LIST_HEAD(&dev->rec_buff_list);
1972     +
1973     /* register v4l2_device early so it can be used for printks */
1974     if (v4l2_device_register(&interface->dev, &dev->v4l2_dev)) {
1975     dev_err(&interface->dev, "v4l2_device_register failed\n");
1976     @@ -333,10 +338,6 @@ static int hdpvr_probe(struct usb_interface *interface,
1977     if (!dev->workqueue)
1978     goto error;
1979    
1980     - /* init video transfer queues */
1981     - INIT_LIST_HEAD(&dev->free_buff_list);
1982     - INIT_LIST_HEAD(&dev->rec_buff_list);
1983     -
1984     dev->options = hdpvr_default_options;
1985    
1986     if (default_video_input < HDPVR_VIDEO_INPUTS)
1987     @@ -413,7 +414,7 @@ static int hdpvr_probe(struct usb_interface *interface,
1988     video_nr[atomic_inc_return(&dev_nr)]);
1989     if (retval < 0) {
1990     v4l2_err(&dev->v4l2_dev, "registering videodev failed\n");
1991     - goto error;
1992     + goto reg_fail;
1993     }
1994    
1995     /* let the user know what node this device is now attached to */
1996     diff --git a/drivers/mmc/host/tmio_mmc_dma.c b/drivers/mmc/host/tmio_mmc_dma.c
1997     index fff92860..491e9ecc 100644
1998     --- a/drivers/mmc/host/tmio_mmc_dma.c
1999     +++ b/drivers/mmc/host/tmio_mmc_dma.c
2000     @@ -104,6 +104,7 @@ static void tmio_mmc_start_dma_rx(struct tmio_mmc_host *host)
2001     pio:
2002     if (!desc) {
2003     /* DMA failed, fall back to PIO */
2004     + tmio_mmc_enable_dma(host, false);
2005     if (ret >= 0)
2006     ret = -EIO;
2007     host->chan_rx = NULL;
2008     @@ -116,7 +117,6 @@ pio:
2009     }
2010     dev_warn(&host->pdev->dev,
2011     "DMA failed: %d, falling back to PIO\n", ret);
2012     - tmio_mmc_enable_dma(host, false);
2013     }
2014    
2015     dev_dbg(&host->pdev->dev, "%s(): desc %p, cookie %d, sg[%d]\n", __func__,
2016     @@ -185,6 +185,7 @@ static void tmio_mmc_start_dma_tx(struct tmio_mmc_host *host)
2017     pio:
2018     if (!desc) {
2019     /* DMA failed, fall back to PIO */
2020     + tmio_mmc_enable_dma(host, false);
2021     if (ret >= 0)
2022     ret = -EIO;
2023     host->chan_tx = NULL;
2024     @@ -197,7 +198,6 @@ pio:
2025     }
2026     dev_warn(&host->pdev->dev,
2027     "DMA failed: %d, falling back to PIO\n", ret);
2028     - tmio_mmc_enable_dma(host, false);
2029     }
2030    
2031     dev_dbg(&host->pdev->dev, "%s(): desc %p, cookie %d\n", __func__,
2032     diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
2033     index dfcd0a56..fb8c4dea 100644
2034     --- a/drivers/mtd/nand/nand_base.c
2035     +++ b/drivers/mtd/nand/nand_base.c
2036     @@ -2793,7 +2793,9 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
2037    
2038     if (!chip->select_chip)
2039     chip->select_chip = nand_select_chip;
2040     - if (!chip->read_byte)
2041     +
2042     + /* If called twice, pointers that depend on busw may need to be reset */
2043     + if (!chip->read_byte || chip->read_byte == nand_read_byte)
2044     chip->read_byte = busw ? nand_read_byte16 : nand_read_byte;
2045     if (!chip->read_word)
2046     chip->read_word = nand_read_word;
2047     @@ -2801,9 +2803,9 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
2048     chip->block_bad = nand_block_bad;
2049     if (!chip->block_markbad)
2050     chip->block_markbad = nand_default_block_markbad;
2051     - if (!chip->write_buf)
2052     + if (!chip->write_buf || chip->write_buf == nand_write_buf)
2053     chip->write_buf = busw ? nand_write_buf16 : nand_write_buf;
2054     - if (!chip->read_buf)
2055     + if (!chip->read_buf || chip->read_buf == nand_read_buf)
2056     chip->read_buf = busw ? nand_read_buf16 : nand_read_buf;
2057     if (!chip->scan_bbt)
2058     chip->scan_bbt = nand_default_bbt;
2059     diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
2060     index 5df49d3c..c95bfb18 100644
2061     --- a/drivers/mtd/ubi/wl.c
2062     +++ b/drivers/mtd/ubi/wl.c
2063     @@ -1069,6 +1069,9 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
2064     if (!(e2->ec - e1->ec >= UBI_WL_THRESHOLD)) {
2065     dbg_wl("no WL needed: min used EC %d, max free EC %d",
2066     e1->ec, e2->ec);
2067     +
2068     + /* Give the unused PEB back */
2069     + wl_tree_add(e2, &ubi->free);
2070     goto out_cancel;
2071     }
2072     self_check_in_wl_tree(ubi, e1, &ubi->used);
2073     diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
2074     index e1714d7c..3457ca53 100644
2075     --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
2076     +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
2077     @@ -1076,6 +1076,10 @@ static bool ar9003_hw_ani_control(struct ath_hw *ah,
2078     * is_on == 0 means MRC CCK is OFF (more noise imm)
2079     */
2080     bool is_on = param ? 1 : 0;
2081     +
2082     + if (ah->caps.rx_chainmask == 1)
2083     + break;
2084     +
2085     REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
2086     AR_PHY_MRC_CCK_ENABLE, is_on);
2087     REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
2088     diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
2089     index 42b03dc3..4ebd9fd8 100644
2090     --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2091     +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
2092     @@ -79,10 +79,6 @@ struct ath_config {
2093     sizeof(struct ath_buf_state)); \
2094     } while (0)
2095    
2096     -#define ATH_RXBUF_RESET(_bf) do { \
2097     - (_bf)->bf_stale = false; \
2098     - } while (0)
2099     -
2100     /**
2101     * enum buffer_type - Buffer type flags
2102     *
2103     @@ -316,6 +312,7 @@ struct ath_rx {
2104     struct ath_descdma rxdma;
2105     struct ath_rx_edma rx_edma[ATH9K_RX_QUEUE_MAX];
2106    
2107     + struct ath_buf *buf_hold;
2108     struct sk_buff *frag;
2109    
2110     u32 ampdu_ref;
2111     diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
2112     index 8be2b5d8..f53dbd11 100644
2113     --- a/drivers/net/wireless/ath/ath9k/recv.c
2114     +++ b/drivers/net/wireless/ath/ath9k/recv.c
2115     @@ -42,8 +42,6 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
2116     struct ath_desc *ds;
2117     struct sk_buff *skb;
2118    
2119     - ATH_RXBUF_RESET(bf);
2120     -
2121     ds = bf->bf_desc;
2122     ds->ds_link = 0; /* link to null */
2123     ds->ds_data = bf->bf_buf_addr;
2124     @@ -70,6 +68,14 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
2125     sc->rx.rxlink = &ds->ds_link;
2126     }
2127    
2128     +static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_buf *bf)
2129     +{
2130     + if (sc->rx.buf_hold)
2131     + ath_rx_buf_link(sc, sc->rx.buf_hold);
2132     +
2133     + sc->rx.buf_hold = bf;
2134     +}
2135     +
2136     static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
2137     {
2138     /* XXX block beacon interrupts */
2139     @@ -117,7 +123,6 @@ static bool ath_rx_edma_buf_link(struct ath_softc *sc,
2140    
2141     skb = bf->bf_mpdu;
2142    
2143     - ATH_RXBUF_RESET(bf);
2144     memset(skb->data, 0, ah->caps.rx_status_len);
2145     dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
2146     ah->caps.rx_status_len, DMA_TO_DEVICE);
2147     @@ -432,6 +437,7 @@ int ath_startrecv(struct ath_softc *sc)
2148     if (list_empty(&sc->rx.rxbuf))
2149     goto start_recv;
2150    
2151     + sc->rx.buf_hold = NULL;
2152     sc->rx.rxlink = NULL;
2153     list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
2154     ath_rx_buf_link(sc, bf);
2155     @@ -677,6 +683,9 @@ static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
2156     }
2157    
2158     bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
2159     + if (bf == sc->rx.buf_hold)
2160     + return NULL;
2161     +
2162     ds = bf->bf_desc;
2163    
2164     /*
2165     @@ -1378,7 +1387,7 @@ requeue:
2166     if (edma) {
2167     ath_rx_edma_buf_link(sc, qtype);
2168     } else {
2169     - ath_rx_buf_link(sc, bf);
2170     + ath_rx_buf_relink(sc, bf);
2171     ath9k_hw_rxena(ah);
2172     }
2173     } while (1);
2174     diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
2175     index 83ab6be3..e752f5d4 100644
2176     --- a/drivers/net/wireless/ath/ath9k/xmit.c
2177     +++ b/drivers/net/wireless/ath/ath9k/xmit.c
2178     @@ -2387,6 +2387,7 @@ void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2179     for (acno = 0, ac = &an->ac[acno];
2180     acno < IEEE80211_NUM_ACS; acno++, ac++) {
2181     ac->sched = false;
2182     + ac->clear_ps_filter = true;
2183     ac->txq = sc->tx.txq_map[acno];
2184     INIT_LIST_HEAD(&ac->tid_q);
2185     }
2186     diff --git a/drivers/net/wireless/brcm80211/brcmsmac/dma.c b/drivers/net/wireless/brcm80211/brcmsmac/dma.c
2187     index 1860c572..4fb9635d 100644
2188     --- a/drivers/net/wireless/brcm80211/brcmsmac/dma.c
2189     +++ b/drivers/net/wireless/brcm80211/brcmsmac/dma.c
2190     @@ -1015,9 +1015,10 @@ static bool dma64_txidle(struct dma_info *di)
2191    
2192     /*
2193     * post receive buffers
2194     - * return false is refill failed completely and ring is empty this will stall
2195     - * the rx dma and user might want to call rxfill again asap. This unlikely
2196     - * happens on memory-rich NIC, but often on memory-constrained dongle
2197     + * Return false if refill failed completely or dma mapping failed. The ring
2198     + * is empty, which will stall the rx dma and user might want to call rxfill
2199     + * again asap. This is unlikely to happen on a memory-rich NIC, but often on
2200     + * memory-constrained dongle.
2201     */
2202     bool dma_rxfill(struct dma_pub *pub)
2203     {
2204     @@ -1078,6 +1079,8 @@ bool dma_rxfill(struct dma_pub *pub)
2205    
2206     pa = dma_map_single(di->dmadev, p->data, di->rxbufsize,
2207     DMA_FROM_DEVICE);
2208     + if (dma_mapping_error(di->dmadev, pa))
2209     + return false;
2210    
2211     /* save the free packet pointer */
2212     di->rxp[rxout] = p;
2213     @@ -1284,7 +1287,11 @@ static void dma_txenq(struct dma_info *di, struct sk_buff *p)
2214    
2215     /* get physical address of buffer start */
2216     pa = dma_map_single(di->dmadev, data, len, DMA_TO_DEVICE);
2217     -
2218     + /* if mapping failed, free skb */
2219     + if (dma_mapping_error(di->dmadev, pa)) {
2220     + brcmu_pkt_buf_free_skb(p);
2221     + return;
2222     + }
2223     /* With a DMA segment list, Descriptor table is filled
2224     * using the segment list instead of looping over
2225     * buffers in multi-chain DMA. Therefore, EOF for SGLIST
2226     diff --git a/drivers/of/base.c b/drivers/of/base.c
2227     index a6f584a7..1d10b4ec 100644
2228     --- a/drivers/of/base.c
2229     +++ b/drivers/of/base.c
2230     @@ -1629,6 +1629,7 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
2231     ap = dt_alloc(sizeof(*ap) + len + 1, 4);
2232     if (!ap)
2233     continue;
2234     + memset(ap, 0, sizeof(*ap) + len + 1);
2235     ap->alias = start;
2236     of_alias_add(ap, np, id, start, len);
2237     }
2238     diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
2239     index 5d7529ed..314e5e8e 100644
2240     --- a/drivers/pinctrl/pinctrl-at91.c
2241     +++ b/drivers/pinctrl/pinctrl-at91.c
2242     @@ -325,7 +325,7 @@ static void at91_mux_disable_interrupt(void __iomem *pio, unsigned mask)
2243    
2244     static unsigned at91_mux_get_pullup(void __iomem *pio, unsigned pin)
2245     {
2246     - return (readl_relaxed(pio + PIO_PUSR) >> pin) & 0x1;
2247     + return !((readl_relaxed(pio + PIO_PUSR) >> pin) & 0x1);
2248     }
2249    
2250     static void at91_mux_set_pullup(void __iomem *pio, unsigned mask, bool on)
2251     @@ -445,7 +445,7 @@ static void at91_mux_pio3_set_debounce(void __iomem *pio, unsigned mask,
2252    
2253     static bool at91_mux_pio3_get_pulldown(void __iomem *pio, unsigned pin)
2254     {
2255     - return (__raw_readl(pio + PIO_PPDSR) >> pin) & 0x1;
2256     + return !((__raw_readl(pio + PIO_PPDSR) >> pin) & 0x1);
2257     }
2258    
2259     static void at91_mux_pio3_set_pulldown(void __iomem *pio, unsigned mask, bool is_on)
2260     diff --git a/drivers/scsi/mpt3sas/Makefile b/drivers/scsi/mpt3sas/Makefile
2261     index 4c1d2e7a..efb0c4c2 100644
2262     --- a/drivers/scsi/mpt3sas/Makefile
2263     +++ b/drivers/scsi/mpt3sas/Makefile
2264     @@ -1,5 +1,5 @@
2265     # mpt3sas makefile
2266     -obj-m += mpt3sas.o
2267     +obj-$(CONFIG_SCSI_MPT3SAS) += mpt3sas.o
2268     mpt3sas-y += mpt3sas_base.o \
2269     mpt3sas_config.o \
2270     mpt3sas_scsih.o \
2271     diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
2272     index 610417ec..c3986344 100644
2273     --- a/drivers/scsi/sd.c
2274     +++ b/drivers/scsi/sd.c
2275     @@ -2409,14 +2409,9 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
2276     }
2277     }
2278    
2279     - if (modepage == 0x3F) {
2280     - sd_printk(KERN_ERR, sdkp, "No Caching mode page "
2281     - "present\n");
2282     - goto defaults;
2283     - } else if ((buffer[offset] & 0x3f) != modepage) {
2284     - sd_printk(KERN_ERR, sdkp, "Got wrong page\n");
2285     - goto defaults;
2286     - }
2287     + sd_printk(KERN_ERR, sdkp, "No Caching mode page found\n");
2288     + goto defaults;
2289     +
2290     Page_found:
2291     if (modepage == 8) {
2292     sdkp->WCE = ((buffer[offset + 2] & 0x04) != 0);
2293     diff --git a/drivers/staging/comedi/drivers/dt282x.c b/drivers/staging/comedi/drivers/dt282x.c
2294     index 90f2de9b..f4c1e998 100644
2295     --- a/drivers/staging/comedi/drivers/dt282x.c
2296     +++ b/drivers/staging/comedi/drivers/dt282x.c
2297     @@ -269,8 +269,9 @@ struct dt282x_private {
2298     } \
2299     udelay(5); \
2300     } \
2301     - if (_i) \
2302     + if (_i) { \
2303     b \
2304     + } \
2305     } while (0)
2306    
2307     static int prep_ai_dma(struct comedi_device *dev, int chan, int size);
2308     diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
2309     index 163c638e..972a0723 100644
2310     --- a/drivers/staging/iio/adc/mxs-lradc.c
2311     +++ b/drivers/staging/iio/adc/mxs-lradc.c
2312     @@ -234,7 +234,6 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
2313     {
2314     struct mxs_lradc *lradc = iio_priv(iio_dev);
2315     int ret;
2316     - unsigned long mask;
2317    
2318     if (m != IIO_CHAN_INFO_RAW)
2319     return -EINVAL;
2320     @@ -243,12 +242,6 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
2321     if (chan->channel > LRADC_MAX_TOTAL_CHANS)
2322     return -EINVAL;
2323    
2324     - /* Validate the channel if it doesn't intersect with reserved chans. */
2325     - bitmap_set(&mask, chan->channel, 1);
2326     - ret = iio_validate_scan_mask_onehot(iio_dev, &mask);
2327     - if (ret)
2328     - return -EINVAL;
2329     -
2330     /*
2331     * See if there is no buffered operation in progess. If there is, simply
2332     * bail out. This can be improved to support both buffered and raw IO at
2333     @@ -661,12 +654,13 @@ static int mxs_lradc_trigger_init(struct iio_dev *iio)
2334     {
2335     int ret;
2336     struct iio_trigger *trig;
2337     + struct mxs_lradc *lradc = iio_priv(iio);
2338    
2339     trig = iio_trigger_alloc("%s-dev%i", iio->name, iio->id);
2340     if (trig == NULL)
2341     return -ENOMEM;
2342    
2343     - trig->dev.parent = iio->dev.parent;
2344     + trig->dev.parent = lradc->dev;
2345     iio_trigger_set_drvdata(trig, iio);
2346     trig->ops = &mxs_lradc_trigger_ops;
2347    
2348     @@ -676,15 +670,17 @@ static int mxs_lradc_trigger_init(struct iio_dev *iio)
2349     return ret;
2350     }
2351    
2352     - iio->trig = trig;
2353     + lradc->trig = trig;
2354    
2355     return 0;
2356     }
2357    
2358     static void mxs_lradc_trigger_remove(struct iio_dev *iio)
2359     {
2360     - iio_trigger_unregister(iio->trig);
2361     - iio_trigger_free(iio->trig);
2362     + struct mxs_lradc *lradc = iio_priv(iio);
2363     +
2364     + iio_trigger_unregister(lradc->trig);
2365     + iio_trigger_free(lradc->trig);
2366     }
2367    
2368     static int mxs_lradc_buffer_preenable(struct iio_dev *iio)
2369     diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
2370     index cbe48ab4..f608fbc1 100644
2371     --- a/drivers/target/target_core_alua.c
2372     +++ b/drivers/target/target_core_alua.c
2373     @@ -730,7 +730,7 @@ static int core_alua_write_tpg_metadata(
2374     if (ret < 0)
2375     pr_err("Error writing ALUA metadata file: %s\n", path);
2376     fput(file);
2377     - return ret ? -EIO : 0;
2378     + return (ret < 0) ? -EIO : 0;
2379     }
2380    
2381     /*
2382     diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
2383     index 3240f2cc..04a74938 100644
2384     --- a/drivers/target/target_core_pr.c
2385     +++ b/drivers/target/target_core_pr.c
2386     @@ -1987,7 +1987,7 @@ static int __core_scsi3_write_aptpl_to_file(
2387     pr_debug("Error writing APTPL metadata file: %s\n", path);
2388     fput(file);
2389    
2390     - return ret ? -EIO : 0;
2391     + return (ret < 0) ? -EIO : 0;
2392     }
2393    
2394     static int
2395     diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
2396     index 44766821..59d26ef5 100644
2397     --- a/drivers/tty/tty_io.c
2398     +++ b/drivers/tty/tty_io.c
2399     @@ -850,7 +850,8 @@ void disassociate_ctty(int on_exit)
2400     struct pid *tty_pgrp = tty_get_pgrp(tty);
2401     if (tty_pgrp) {
2402     kill_pgrp(tty_pgrp, SIGHUP, on_exit);
2403     - kill_pgrp(tty_pgrp, SIGCONT, on_exit);
2404     + if (!on_exit)
2405     + kill_pgrp(tty_pgrp, SIGCONT, on_exit);
2406     put_pid(tty_pgrp);
2407     }
2408     }
2409     diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
2410     index 8a230f0e..d3318a0d 100644
2411     --- a/drivers/usb/class/cdc-wdm.c
2412     +++ b/drivers/usb/class/cdc-wdm.c
2413     @@ -209,6 +209,7 @@ skip_error:
2414     static void wdm_int_callback(struct urb *urb)
2415     {
2416     int rv = 0;
2417     + int responding;
2418     int status = urb->status;
2419     struct wdm_device *desc;
2420     struct usb_cdc_notification *dr;
2421     @@ -262,8 +263,8 @@ static void wdm_int_callback(struct urb *urb)
2422    
2423     spin_lock(&desc->iuspin);
2424     clear_bit(WDM_READ, &desc->flags);
2425     - set_bit(WDM_RESPONDING, &desc->flags);
2426     - if (!test_bit(WDM_DISCONNECTING, &desc->flags)
2427     + responding = test_and_set_bit(WDM_RESPONDING, &desc->flags);
2428     + if (!responding && !test_bit(WDM_DISCONNECTING, &desc->flags)
2429     && !test_bit(WDM_SUSPENDING, &desc->flags)) {
2430     rv = usb_submit_urb(desc->response, GFP_ATOMIC);
2431     dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d",
2432     @@ -685,16 +686,20 @@ static void wdm_rxwork(struct work_struct *work)
2433     {
2434     struct wdm_device *desc = container_of(work, struct wdm_device, rxwork);
2435     unsigned long flags;
2436     - int rv;
2437     + int rv = 0;
2438     + int responding;
2439    
2440     spin_lock_irqsave(&desc->iuspin, flags);
2441     if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
2442     spin_unlock_irqrestore(&desc->iuspin, flags);
2443     } else {
2444     + responding = test_and_set_bit(WDM_RESPONDING, &desc->flags);
2445     spin_unlock_irqrestore(&desc->iuspin, flags);
2446     - rv = usb_submit_urb(desc->response, GFP_KERNEL);
2447     + if (!responding)
2448     + rv = usb_submit_urb(desc->response, GFP_KERNEL);
2449     if (rv < 0 && rv != -EPERM) {
2450     spin_lock_irqsave(&desc->iuspin, flags);
2451     + clear_bit(WDM_RESPONDING, &desc->flags);
2452     if (!test_bit(WDM_DISCONNECTING, &desc->flags))
2453     schedule_work(&desc->rxwork);
2454     spin_unlock_irqrestore(&desc->iuspin, flags);
2455     diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
2456     index 7199adcc..a6b2cabe 100644
2457     --- a/drivers/usb/core/config.c
2458     +++ b/drivers/usb/core/config.c
2459     @@ -424,7 +424,8 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
2460    
2461     memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE);
2462     if (config->desc.bDescriptorType != USB_DT_CONFIG ||
2463     - config->desc.bLength < USB_DT_CONFIG_SIZE) {
2464     + config->desc.bLength < USB_DT_CONFIG_SIZE ||
2465     + config->desc.bLength > size) {
2466     dev_err(ddev, "invalid descriptor for config index %d: "
2467     "type = 0x%X, length = %d\n", cfgidx,
2468     config->desc.bDescriptorType, config->desc.bLength);
2469     diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
2470     index da2905a1..6cf2ae0a 100644
2471     --- a/drivers/usb/core/hub.c
2472     +++ b/drivers/usb/core/hub.c
2473     @@ -2916,7 +2916,6 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2474     {
2475     struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
2476     struct usb_port *port_dev = hub->ports[udev->portnum - 1];
2477     - enum pm_qos_flags_status pm_qos_stat;
2478     int port1 = udev->portnum;
2479     int status;
2480     bool really_suspend = true;
2481     @@ -2954,7 +2953,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2482     status);
2483     /* bail if autosuspend is requested */
2484     if (PMSG_IS_AUTO(msg))
2485     - return status;
2486     + goto err_wakeup;
2487     }
2488     }
2489    
2490     @@ -2963,14 +2962,16 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2491     usb_set_usb2_hardware_lpm(udev, 0);
2492    
2493     if (usb_disable_ltm(udev)) {
2494     - dev_err(&udev->dev, "%s Failed to disable LTM before suspend\n.",
2495     - __func__);
2496     - return -ENOMEM;
2497     + dev_err(&udev->dev, "Failed to disable LTM before suspend\n.");
2498     + status = -ENOMEM;
2499     + if (PMSG_IS_AUTO(msg))
2500     + goto err_ltm;
2501     }
2502     if (usb_unlocked_disable_lpm(udev)) {
2503     - dev_err(&udev->dev, "%s Failed to disable LPM before suspend\n.",
2504     - __func__);
2505     - return -ENOMEM;
2506     + dev_err(&udev->dev, "Failed to disable LPM before suspend\n.");
2507     + status = -ENOMEM;
2508     + if (PMSG_IS_AUTO(msg))
2509     + goto err_lpm3;
2510     }
2511    
2512     /* see 7.1.7.6 */
2513     @@ -2998,28 +2999,31 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2514     if (status) {
2515     dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n",
2516     port1, status);
2517     - /* paranoia: "should not happen" */
2518     - if (udev->do_remote_wakeup) {
2519     - if (!hub_is_superspeed(hub->hdev)) {
2520     - (void) usb_control_msg(udev,
2521     - usb_sndctrlpipe(udev, 0),
2522     - USB_REQ_CLEAR_FEATURE,
2523     - USB_RECIP_DEVICE,
2524     - USB_DEVICE_REMOTE_WAKEUP, 0,
2525     - NULL, 0,
2526     - USB_CTRL_SET_TIMEOUT);
2527     - } else
2528     - (void) usb_disable_function_remotewakeup(udev);
2529     -
2530     - }
2531    
2532     + /* Try to enable USB3 LPM and LTM again */
2533     + usb_unlocked_enable_lpm(udev);
2534     + err_lpm3:
2535     + usb_enable_ltm(udev);
2536     + err_ltm:
2537     /* Try to enable USB2 hardware LPM again */
2538     if (udev->usb2_hw_lpm_capable == 1)
2539     usb_set_usb2_hardware_lpm(udev, 1);
2540    
2541     - /* Try to enable USB3 LTM and LPM again */
2542     - usb_enable_ltm(udev);
2543     - usb_unlocked_enable_lpm(udev);
2544     + if (udev->do_remote_wakeup) {
2545     + if (udev->speed < USB_SPEED_SUPER)
2546     + usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2547     + USB_REQ_CLEAR_FEATURE,
2548     + USB_RECIP_DEVICE,
2549     + USB_DEVICE_REMOTE_WAKEUP, 0,
2550     + NULL, 0, USB_CTRL_SET_TIMEOUT);
2551     + else
2552     + usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2553     + USB_REQ_CLEAR_FEATURE,
2554     + USB_RECIP_INTERFACE,
2555     + USB_INTRF_FUNC_SUSPEND, 0,
2556     + NULL, 0, USB_CTRL_SET_TIMEOUT);
2557     + }
2558     + err_wakeup:
2559    
2560     /* System sleep transitions should never fail */
2561     if (!PMSG_IS_AUTO(msg))
2562     @@ -3037,16 +3041,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2563     usb_set_device_state(udev, USB_STATE_SUSPENDED);
2564     }
2565    
2566     - /*
2567     - * Check whether current status meets the requirement of
2568     - * usb port power off mechanism
2569     - */
2570     - pm_qos_stat = dev_pm_qos_flags(&port_dev->dev,
2571     - PM_QOS_FLAG_NO_POWER_OFF);
2572     - if (!udev->do_remote_wakeup
2573     - && pm_qos_stat != PM_QOS_FLAGS_ALL
2574     - && udev->persist_enabled
2575     - && !status) {
2576     + if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled) {
2577     pm_runtime_put_sync(&port_dev->dev);
2578     port_dev->did_runtime_put = true;
2579     }
2580     diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
2581     index b8bad294..ef07b359 100644
2582     --- a/drivers/usb/core/port.c
2583     +++ b/drivers/usb/core/port.c
2584     @@ -89,22 +89,19 @@ static int usb_port_runtime_resume(struct device *dev)
2585     retval = usb_hub_set_port_power(hdev, port1, true);
2586     if (port_dev->child && !retval) {
2587     /*
2588     - * Wait for usb hub port to be reconnected in order to make
2589     - * the resume procedure successful.
2590     + * Attempt to wait for usb hub port to be reconnected in order
2591     + * to make the resume procedure successful. The device may have
2592     + * disconnected while the port was powered off, so ignore the
2593     + * return status.
2594     */
2595     retval = hub_port_debounce_be_connected(hub, port1);
2596     - if (retval < 0) {
2597     + if (retval < 0)
2598     dev_dbg(&port_dev->dev, "can't get reconnection after setting port power on, status %d\n",
2599     retval);
2600     - goto out;
2601     - }
2602     usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE);
2603     -
2604     - /* Set return value to 0 if debounce successful */
2605     retval = 0;
2606     }
2607    
2608     -out:
2609     clear_bit(port1, hub->busy_bits);
2610     usb_autopm_put_interface(intf);
2611     return retval;
2612     diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
2613     index f77083fe..14d28d61 100644
2614     --- a/drivers/usb/dwc3/gadget.c
2615     +++ b/drivers/usb/dwc3/gadget.c
2616     @@ -1508,6 +1508,15 @@ static int dwc3_gadget_start(struct usb_gadget *g,
2617     int irq;
2618     u32 reg;
2619    
2620     + irq = platform_get_irq(to_platform_device(dwc->dev), 0);
2621     + ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
2622     + IRQF_SHARED | IRQF_ONESHOT, "dwc3", dwc);
2623     + if (ret) {
2624     + dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
2625     + irq, ret);
2626     + goto err0;
2627     + }
2628     +
2629     spin_lock_irqsave(&dwc->lock, flags);
2630    
2631     if (dwc->gadget_driver) {
2632     @@ -1515,7 +1524,7 @@ static int dwc3_gadget_start(struct usb_gadget *g,
2633     dwc->gadget.name,
2634     dwc->gadget_driver->driver.name);
2635     ret = -EBUSY;
2636     - goto err0;
2637     + goto err1;
2638     }
2639    
2640     dwc->gadget_driver = driver;
2641     @@ -1551,42 +1560,38 @@ static int dwc3_gadget_start(struct usb_gadget *g,
2642     ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false);
2643     if (ret) {
2644     dev_err(dwc->dev, "failed to enable %s\n", dep->name);
2645     - goto err0;
2646     + goto err2;
2647     }
2648    
2649     dep = dwc->eps[1];
2650     ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false);
2651     if (ret) {
2652     dev_err(dwc->dev, "failed to enable %s\n", dep->name);
2653     - goto err1;
2654     + goto err3;
2655     }
2656    
2657     /* begin to receive SETUP packets */
2658     dwc->ep0state = EP0_SETUP_PHASE;
2659     dwc3_ep0_out_start(dwc);
2660    
2661     - irq = platform_get_irq(to_platform_device(dwc->dev), 0);
2662     - ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
2663     - IRQF_SHARED | IRQF_ONESHOT, "dwc3", dwc);
2664     - if (ret) {
2665     - dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
2666     - irq, ret);
2667     - goto err1;
2668     - }
2669     -
2670     dwc3_gadget_enable_irq(dwc);
2671    
2672     spin_unlock_irqrestore(&dwc->lock, flags);
2673    
2674     return 0;
2675    
2676     -err1:
2677     +err3:
2678     __dwc3_gadget_ep_disable(dwc->eps[0]);
2679    
2680     -err0:
2681     +err2:
2682     dwc->gadget_driver = NULL;
2683     +
2684     +err1:
2685     spin_unlock_irqrestore(&dwc->lock, flags);
2686    
2687     + free_irq(irq, dwc);
2688     +
2689     +err0:
2690     return ret;
2691     }
2692    
2693     @@ -1600,9 +1605,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g,
2694     spin_lock_irqsave(&dwc->lock, flags);
2695    
2696     dwc3_gadget_disable_irq(dwc);
2697     - irq = platform_get_irq(to_platform_device(dwc->dev), 0);
2698     - free_irq(irq, dwc);
2699     -
2700     __dwc3_gadget_ep_disable(dwc->eps[0]);
2701     __dwc3_gadget_ep_disable(dwc->eps[1]);
2702    
2703     @@ -1610,6 +1612,9 @@ static int dwc3_gadget_stop(struct usb_gadget *g,
2704    
2705     spin_unlock_irqrestore(&dwc->lock, flags);
2706    
2707     + irq = platform_get_irq(to_platform_device(dwc->dev), 0);
2708     + free_irq(irq, dwc);
2709     +
2710     return 0;
2711     }
2712    
2713     diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c
2714     index 7ce27e35..de456a5a 100644
2715     --- a/drivers/usb/gadget/uvc_queue.c
2716     +++ b/drivers/usb/gadget/uvc_queue.c
2717     @@ -177,12 +177,16 @@ static int uvc_queue_buffer(struct uvc_video_queue *queue,
2718    
2719     mutex_lock(&queue->mutex);
2720     ret = vb2_qbuf(&queue->queue, buf);
2721     + if (ret < 0)
2722     + goto done;
2723     +
2724     spin_lock_irqsave(&queue->irqlock, flags);
2725     ret = (queue->flags & UVC_QUEUE_PAUSED) != 0;
2726     queue->flags &= ~UVC_QUEUE_PAUSED;
2727     spin_unlock_irqrestore(&queue->irqlock, flags);
2728     - mutex_unlock(&queue->mutex);
2729    
2730     +done:
2731     + mutex_unlock(&queue->mutex);
2732     return ret;
2733     }
2734    
2735     diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
2736     index c369767b..ec128bc7 100644
2737     --- a/drivers/usb/host/ehci-mxc.c
2738     +++ b/drivers/usb/host/ehci-mxc.c
2739     @@ -184,7 +184,7 @@ static int ehci_mxc_drv_remove(struct platform_device *pdev)
2740     if (pdata && pdata->exit)
2741     pdata->exit(pdev);
2742    
2743     - if (pdata->otg)
2744     + if (pdata && pdata->otg)
2745     usb_phy_shutdown(pdata->otg);
2746    
2747     clk_disable_unprepare(priv->usbclk);
2748     diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
2749     index 951514ef..ef6782bd 100644
2750     --- a/drivers/usb/host/ohci-pci.c
2751     +++ b/drivers/usb/host/ohci-pci.c
2752     @@ -371,7 +371,7 @@ static struct pci_driver ohci_pci_driver = {
2753     .remove = usb_hcd_pci_remove,
2754     .shutdown = usb_hcd_pci_shutdown,
2755    
2756     -#ifdef CONFIG_PM_SLEEP
2757     +#ifdef CONFIG_PM
2758     .driver = {
2759     .pm = &usb_hcd_pci_pm_ops
2760     },
2761     diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
2762     index 93ad67ec..6e70ce97 100644
2763     --- a/drivers/usb/host/xhci-plat.c
2764     +++ b/drivers/usb/host/xhci-plat.c
2765     @@ -24,7 +24,7 @@ static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
2766     * here that the generic code does not try to make a pci_dev from our
2767     * dev struct in order to setup MSI
2768     */
2769     - xhci->quirks |= XHCI_BROKEN_MSI;
2770     + xhci->quirks |= XHCI_PLAT;
2771     }
2772    
2773     /* called during probe() after chip reset completes */
2774     diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
2775     index 9a550b6a..f4a49c45 100644
2776     --- a/drivers/usb/host/xhci.c
2777     +++ b/drivers/usb/host/xhci.c
2778     @@ -342,9 +342,14 @@ static void xhci_msix_sync_irqs(struct xhci_hcd *xhci)
2779     static int xhci_try_enable_msi(struct usb_hcd *hcd)
2780     {
2781     struct xhci_hcd *xhci = hcd_to_xhci(hcd);
2782     - struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
2783     + struct pci_dev *pdev;
2784     int ret;
2785    
2786     + /* The xhci platform device has set up IRQs through usb_add_hcd. */
2787     + if (xhci->quirks & XHCI_PLAT)
2788     + return 0;
2789     +
2790     + pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
2791     /*
2792     * Some Fresco Logic host controllers advertise MSI, but fail to
2793     * generate interrupts. Don't even try to enable MSI.
2794     @@ -3506,10 +3511,21 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
2795     {
2796     struct xhci_hcd *xhci = hcd_to_xhci(hcd);
2797     struct xhci_virt_device *virt_dev;
2798     + struct device *dev = hcd->self.controller;
2799     unsigned long flags;
2800     u32 state;
2801     int i, ret;
2802    
2803     +#ifndef CONFIG_USB_DEFAULT_PERSIST
2804     + /*
2805     + * We called pm_runtime_get_noresume when the device was attached.
2806     + * Decrement the counter here to allow controller to runtime suspend
2807     + * if no devices remain.
2808     + */
2809     + if (xhci->quirks & XHCI_RESET_ON_RESUME)
2810     + pm_runtime_put_noidle(dev);
2811     +#endif
2812     +
2813     ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__);
2814     /* If the host is halted due to driver unload, we still need to free the
2815     * device.
2816     @@ -3581,6 +3597,7 @@ static int xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci)
2817     int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
2818     {
2819     struct xhci_hcd *xhci = hcd_to_xhci(hcd);
2820     + struct device *dev = hcd->self.controller;
2821     unsigned long flags;
2822     int timeleft;
2823     int ret;
2824     @@ -3633,6 +3650,16 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
2825     goto disable_slot;
2826     }
2827     udev->slot_id = xhci->slot_id;
2828     +
2829     +#ifndef CONFIG_USB_DEFAULT_PERSIST
2830     + /*
2831     + * If resetting upon resume, we can't put the controller into runtime
2832     + * suspend if there is a device attached.
2833     + */
2834     + if (xhci->quirks & XHCI_RESET_ON_RESUME)
2835     + pm_runtime_get_noresume(dev);
2836     +#endif
2837     +
2838     /* Is this a LS or FS device under a HS hub? */
2839     /* Hub or peripherial? */
2840     return 1;
2841     diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
2842     index 77600cef..3638f1d7 100644
2843     --- a/drivers/usb/host/xhci.h
2844     +++ b/drivers/usb/host/xhci.h
2845     @@ -1516,6 +1516,7 @@ struct xhci_hcd {
2846     #define XHCI_SPURIOUS_REBOOT (1 << 13)
2847     #define XHCI_COMP_MODE_QUIRK (1 << 14)
2848     #define XHCI_AVOID_BEI (1 << 15)
2849     +#define XHCI_PLAT (1 << 16)
2850     unsigned int num_active_eps;
2851     unsigned int limit_active_eps;
2852     /* There are two roothubs to keep track of bus suspend info for */
2853     diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
2854     index 5050cc85..0f16bf6e 100644
2855     --- a/drivers/usb/serial/mos7720.c
2856     +++ b/drivers/usb/serial/mos7720.c
2857     @@ -374,7 +374,7 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
2858     kfree(urbtrack);
2859     return -ENOMEM;
2860     }
2861     - urbtrack->setup = kmalloc(sizeof(*urbtrack->setup), GFP_KERNEL);
2862     + urbtrack->setup = kmalloc(sizeof(*urbtrack->setup), GFP_ATOMIC);
2863     if (!urbtrack->setup) {
2864     usb_free_urb(urbtrack->urb);
2865     kfree(urbtrack);
2866     @@ -382,8 +382,8 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
2867     }
2868     urbtrack->setup->bRequestType = (__u8)0x40;
2869     urbtrack->setup->bRequest = (__u8)0x0e;
2870     - urbtrack->setup->wValue = get_reg_value(reg, dummy);
2871     - urbtrack->setup->wIndex = get_reg_index(reg);
2872     + urbtrack->setup->wValue = cpu_to_le16(get_reg_value(reg, dummy));
2873     + urbtrack->setup->wIndex = cpu_to_le16(get_reg_index(reg));
2874     urbtrack->setup->wLength = 0;
2875     usb_fill_control_urb(urbtrack->urb, usbdev,
2876     usb_sndctrlpipe(usbdev, 0),
2877     diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
2878     index 04c1b2d9..d5418c1b 100644
2879     --- a/drivers/xen/grant-table.c
2880     +++ b/drivers/xen/grant-table.c
2881     @@ -729,9 +729,18 @@ void gnttab_request_free_callback(struct gnttab_free_callback *callback,
2882     void (*fn)(void *), void *arg, u16 count)
2883     {
2884     unsigned long flags;
2885     + struct gnttab_free_callback *cb;
2886     +
2887     spin_lock_irqsave(&gnttab_list_lock, flags);
2888     - if (callback->next)
2889     - goto out;
2890     +
2891     + /* Check if the callback is already on the list */
2892     + cb = gnttab_free_callback_list;
2893     + while (cb) {
2894     + if (cb == callback)
2895     + goto out;
2896     + cb = cb->next;
2897     + }
2898     +
2899     callback->fn = fn;
2900     callback->arg = arg;
2901     callback->count = count;
2902     diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
2903     index 0f81d67c..8dedf401 100644
2904     --- a/fs/btrfs/ioctl.c
2905     +++ b/fs/btrfs/ioctl.c
2906     @@ -3299,6 +3299,9 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root *root, void __user *arg)
2907    
2908     switch (p->cmd) {
2909     case BTRFS_IOCTL_DEV_REPLACE_CMD_START:
2910     + if (root->fs_info->sb->s_flags & MS_RDONLY)
2911     + return -EROFS;
2912     +
2913     if (atomic_xchg(
2914     &root->fs_info->mutually_exclusive_operation_running,
2915     1)) {
2916     diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
2917     index e0b4ef31..a5ce62eb 100644
2918     --- a/fs/ceph/ioctl.c
2919     +++ b/fs/ceph/ioctl.c
2920     @@ -196,8 +196,10 @@ static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)
2921     r = ceph_calc_file_object_mapping(&ci->i_layout, dl.file_offset, len,
2922     &dl.object_no, &dl.object_offset,
2923     &olen);
2924     - if (r < 0)
2925     + if (r < 0) {
2926     + up_read(&osdc->map_sem);
2927     return -EIO;
2928     + }
2929     dl.file_offset -= dl.object_offset;
2930     dl.object_size = ceph_file_layout_object_size(ci->i_layout);
2931     dl.block_size = ceph_file_layout_su(ci->i_layout);
2932     diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
2933     index d6a5c5ac..d05a3007 100644
2934     --- a/fs/cifs/connect.c
2935     +++ b/fs/cifs/connect.c
2936     @@ -377,6 +377,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
2937     try_to_freeze();
2938    
2939     /* we should try only the port we connected to before */
2940     + mutex_lock(&server->srv_mutex);
2941     rc = generic_ip_connect(server);
2942     if (rc) {
2943     cifs_dbg(FYI, "reconnect error %d\n", rc);
2944     @@ -388,6 +389,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
2945     server->tcpStatus = CifsNeedNegotiate;
2946     spin_unlock(&GlobalMid_Lock);
2947     }
2948     + mutex_unlock(&server->srv_mutex);
2949     } while (server->tcpStatus == CifsNeedReconnect);
2950    
2951     return rc;
2952     diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
2953     index 10383d8c..4f791e0e 100644
2954     --- a/fs/cifs/smb2misc.c
2955     +++ b/fs/cifs/smb2misc.c
2956     @@ -413,96 +413,108 @@ cifs_ses_oplock_break(struct work_struct *work)
2957     }
2958    
2959     static bool
2960     -smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
2961     +smb2_tcon_has_lease(struct cifs_tcon *tcon, struct smb2_lease_break *rsp,
2962     + struct smb2_lease_break_work *lw)
2963     {
2964     - struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer;
2965     - struct list_head *tmp, *tmp1, *tmp2;
2966     - struct cifs_ses *ses;
2967     - struct cifs_tcon *tcon;
2968     - struct cifsInodeInfo *cinode;
2969     + bool found;
2970     + __u8 lease_state;
2971     + struct list_head *tmp;
2972     struct cifsFileInfo *cfile;
2973     struct cifs_pending_open *open;
2974     - struct smb2_lease_break_work *lw;
2975     - bool found;
2976     + struct cifsInodeInfo *cinode;
2977     int ack_req = le32_to_cpu(rsp->Flags &
2978     SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED);
2979    
2980     - lw = kmalloc(sizeof(struct smb2_lease_break_work), GFP_KERNEL);
2981     - if (!lw)
2982     - return false;
2983     + lease_state = smb2_map_lease_to_oplock(rsp->NewLeaseState);
2984    
2985     - INIT_WORK(&lw->lease_break, cifs_ses_oplock_break);
2986     - lw->lease_state = rsp->NewLeaseState;
2987     + list_for_each(tmp, &tcon->openFileList) {
2988     + cfile = list_entry(tmp, struct cifsFileInfo, tlist);
2989     + cinode = CIFS_I(cfile->dentry->d_inode);
2990    
2991     - cifs_dbg(FYI, "Checking for lease break\n");
2992     + if (memcmp(cinode->lease_key, rsp->LeaseKey,
2993     + SMB2_LEASE_KEY_SIZE))
2994     + continue;
2995    
2996     - /* look up tcon based on tid & uid */
2997     - spin_lock(&cifs_tcp_ses_lock);
2998     - list_for_each(tmp, &server->smb_ses_list) {
2999     - ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
3000     + cifs_dbg(FYI, "found in the open list\n");
3001     + cifs_dbg(FYI, "lease key match, lease break 0x%d\n",
3002     + le32_to_cpu(rsp->NewLeaseState));
3003    
3004     - spin_lock(&cifs_file_list_lock);
3005     - list_for_each(tmp1, &ses->tcon_list) {
3006     - tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
3007     + smb2_set_oplock_level(cinode, lease_state);
3008    
3009     - cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks);
3010     - list_for_each(tmp2, &tcon->openFileList) {
3011     - cfile = list_entry(tmp2, struct cifsFileInfo,
3012     - tlist);
3013     - cinode = CIFS_I(cfile->dentry->d_inode);
3014     + if (ack_req)
3015     + cfile->oplock_break_cancelled = false;
3016     + else
3017     + cfile->oplock_break_cancelled = true;
3018    
3019     - if (memcmp(cinode->lease_key, rsp->LeaseKey,
3020     - SMB2_LEASE_KEY_SIZE))
3021     - continue;
3022     + queue_work(cifsiod_wq, &cfile->oplock_break);
3023     + kfree(lw);
3024     + return true;
3025     + }
3026    
3027     - cifs_dbg(FYI, "found in the open list\n");
3028     - cifs_dbg(FYI, "lease key match, lease break 0x%d\n",
3029     - le32_to_cpu(rsp->NewLeaseState));
3030     + found = false;
3031     + list_for_each_entry(open, &tcon->pending_opens, olist) {
3032     + if (memcmp(open->lease_key, rsp->LeaseKey,
3033     + SMB2_LEASE_KEY_SIZE))
3034     + continue;
3035     +
3036     + if (!found && ack_req) {
3037     + found = true;
3038     + memcpy(lw->lease_key, open->lease_key,
3039     + SMB2_LEASE_KEY_SIZE);
3040     + lw->tlink = cifs_get_tlink(open->tlink);
3041     + queue_work(cifsiod_wq, &lw->lease_break);
3042     + }
3043    
3044     - smb2_set_oplock_level(cinode,
3045     - smb2_map_lease_to_oplock(rsp->NewLeaseState));
3046     + cifs_dbg(FYI, "found in the pending open list\n");
3047     + cifs_dbg(FYI, "lease key match, lease break 0x%d\n",
3048     + le32_to_cpu(rsp->NewLeaseState));
3049    
3050     - if (ack_req)
3051     - cfile->oplock_break_cancelled = false;
3052     - else
3053     - cfile->oplock_break_cancelled = true;
3054     + open->oplock = lease_state;
3055     + }
3056     + return found;
3057     +}
3058    
3059     - queue_work(cifsiod_wq, &cfile->oplock_break);
3060     +static bool
3061     +smb2_is_valid_lease_break(char *buffer)
3062     +{
3063     + struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer;
3064     + struct list_head *tmp, *tmp1, *tmp2;
3065     + struct TCP_Server_Info *server;
3066     + struct cifs_ses *ses;
3067     + struct cifs_tcon *tcon;
3068     + struct smb2_lease_break_work *lw;
3069    
3070     - spin_unlock(&cifs_file_list_lock);
3071     - spin_unlock(&cifs_tcp_ses_lock);
3072     - return true;
3073     - }
3074     + lw = kmalloc(sizeof(struct smb2_lease_break_work), GFP_KERNEL);
3075     + if (!lw)
3076     + return false;
3077    
3078     - found = false;
3079     - list_for_each_entry(open, &tcon->pending_opens, olist) {
3080     - if (memcmp(open->lease_key, rsp->LeaseKey,
3081     - SMB2_LEASE_KEY_SIZE))
3082     - continue;
3083     + INIT_WORK(&lw->lease_break, cifs_ses_oplock_break);
3084     + lw->lease_state = rsp->NewLeaseState;
3085    
3086     - if (!found && ack_req) {
3087     - found = true;
3088     - memcpy(lw->lease_key, open->lease_key,
3089     - SMB2_LEASE_KEY_SIZE);
3090     - lw->tlink = cifs_get_tlink(open->tlink);
3091     - queue_work(cifsiod_wq,
3092     - &lw->lease_break);
3093     - }
3094     + cifs_dbg(FYI, "Checking for lease break\n");
3095     +
3096     + /* look up tcon based on tid & uid */
3097     + spin_lock(&cifs_tcp_ses_lock);
3098     + list_for_each(tmp, &cifs_tcp_ses_list) {
3099     + server = list_entry(tmp, struct TCP_Server_Info, tcp_ses_list);
3100    
3101     - cifs_dbg(FYI, "found in the pending open list\n");
3102     - cifs_dbg(FYI, "lease key match, lease break 0x%d\n",
3103     - le32_to_cpu(rsp->NewLeaseState));
3104     + list_for_each(tmp1, &server->smb_ses_list) {
3105     + ses = list_entry(tmp1, struct cifs_ses, smb_ses_list);
3106    
3107     - open->oplock =
3108     - smb2_map_lease_to_oplock(rsp->NewLeaseState);
3109     - }
3110     - if (found) {
3111     - spin_unlock(&cifs_file_list_lock);
3112     - spin_unlock(&cifs_tcp_ses_lock);
3113     - return true;
3114     + spin_lock(&cifs_file_list_lock);
3115     + list_for_each(tmp2, &ses->tcon_list) {
3116     + tcon = list_entry(tmp2, struct cifs_tcon,
3117     + tcon_list);
3118     + cifs_stats_inc(
3119     + &tcon->stats.cifs_stats.num_oplock_brks);
3120     + if (smb2_tcon_has_lease(tcon, rsp, lw)) {
3121     + spin_unlock(&cifs_file_list_lock);
3122     + spin_unlock(&cifs_tcp_ses_lock);
3123     + return true;
3124     + }
3125     }
3126     + spin_unlock(&cifs_file_list_lock);
3127     }
3128     - spin_unlock(&cifs_file_list_lock);
3129     }
3130     spin_unlock(&cifs_tcp_ses_lock);
3131     kfree(lw);
3132     @@ -528,7 +540,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
3133     if (rsp->StructureSize !=
3134     smb2_rsp_struct_sizes[SMB2_OPLOCK_BREAK_HE]) {
3135     if (le16_to_cpu(rsp->StructureSize) == 44)
3136     - return smb2_is_valid_lease_break(buffer, server);
3137     + return smb2_is_valid_lease_break(buffer);
3138     else
3139     return false;
3140     }
3141     diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
3142     index ccbfbbb1..904ca1a2 100644
3143     --- a/fs/ext4/inode.c
3144     +++ b/fs/ext4/inode.c
3145     @@ -4706,7 +4706,9 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
3146     ext4_journal_stop(handle);
3147     }
3148    
3149     - if (attr->ia_valid & ATTR_SIZE) {
3150     + if (attr->ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) {
3151     + handle_t *handle;
3152     + loff_t oldsize = inode->i_size;
3153    
3154     if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
3155     struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
3156     @@ -4714,73 +4716,60 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
3157     if (attr->ia_size > sbi->s_bitmap_maxbytes)
3158     return -EFBIG;
3159     }
3160     - }
3161     -
3162     - if (S_ISREG(inode->i_mode) &&
3163     - attr->ia_valid & ATTR_SIZE &&
3164     - (attr->ia_size < inode->i_size)) {
3165     - handle_t *handle;
3166     -
3167     - handle = ext4_journal_start(inode, EXT4_HT_INODE, 3);
3168     - if (IS_ERR(handle)) {
3169     - error = PTR_ERR(handle);
3170     - goto err_out;
3171     - }
3172     - if (ext4_handle_valid(handle)) {
3173     - error = ext4_orphan_add(handle, inode);
3174     - orphan = 1;
3175     - }
3176     - EXT4_I(inode)->i_disksize = attr->ia_size;
3177     - rc = ext4_mark_inode_dirty(handle, inode);
3178     - if (!error)
3179     - error = rc;
3180     - ext4_journal_stop(handle);
3181     -
3182     - if (ext4_should_order_data(inode)) {
3183     - error = ext4_begin_ordered_truncate(inode,
3184     + if (S_ISREG(inode->i_mode) &&
3185     + (attr->ia_size < inode->i_size)) {
3186     + if (ext4_should_order_data(inode)) {
3187     + error = ext4_begin_ordered_truncate(inode,
3188     attr->ia_size);
3189     - if (error) {
3190     - /* Do as much error cleanup as possible */
3191     - handle = ext4_journal_start(inode,
3192     - EXT4_HT_INODE, 3);
3193     - if (IS_ERR(handle)) {
3194     - ext4_orphan_del(NULL, inode);
3195     + if (error)
3196     goto err_out;
3197     - }
3198     - ext4_orphan_del(handle, inode);
3199     - orphan = 0;
3200     - ext4_journal_stop(handle);
3201     + }
3202     + handle = ext4_journal_start(inode, EXT4_HT_INODE, 3);
3203     + if (IS_ERR(handle)) {
3204     + error = PTR_ERR(handle);
3205     + goto err_out;
3206     + }
3207     + if (ext4_handle_valid(handle)) {
3208     + error = ext4_orphan_add(handle, inode);
3209     + orphan = 1;
3210     + }
3211     + EXT4_I(inode)->i_disksize = attr->ia_size;
3212     + rc = ext4_mark_inode_dirty(handle, inode);
3213     + if (!error)
3214     + error = rc;
3215     + ext4_journal_stop(handle);
3216     + if (error) {
3217     + ext4_orphan_del(NULL, inode);
3218     goto err_out;
3219     }
3220     }
3221     - }
3222     -
3223     - if (attr->ia_valid & ATTR_SIZE) {
3224     - if (attr->ia_size != inode->i_size) {
3225     - loff_t oldsize = inode->i_size;
3226    
3227     - i_size_write(inode, attr->ia_size);
3228     - /*
3229     - * Blocks are going to be removed from the inode. Wait
3230     - * for dio in flight. Temporarily disable
3231     - * dioread_nolock to prevent livelock.
3232     - */
3233     - if (orphan) {
3234     - if (!ext4_should_journal_data(inode)) {
3235     - ext4_inode_block_unlocked_dio(inode);
3236     - inode_dio_wait(inode);
3237     - ext4_inode_resume_unlocked_dio(inode);
3238     - } else
3239     - ext4_wait_for_tail_page_commit(inode);
3240     - }
3241     - /*
3242     - * Truncate pagecache after we've waited for commit
3243     - * in data=journal mode to make pages freeable.
3244     - */
3245     - truncate_pagecache(inode, oldsize, inode->i_size);
3246     + i_size_write(inode, attr->ia_size);
3247     + /*
3248     + * Blocks are going to be removed from the inode. Wait
3249     + * for dio in flight. Temporarily disable
3250     + * dioread_nolock to prevent livelock.
3251     + */
3252     + if (orphan) {
3253     + if (!ext4_should_journal_data(inode)) {
3254     + ext4_inode_block_unlocked_dio(inode);
3255     + inode_dio_wait(inode);
3256     + ext4_inode_resume_unlocked_dio(inode);
3257     + } else
3258     + ext4_wait_for_tail_page_commit(inode);
3259     }
3260     - ext4_truncate(inode);
3261     + /*
3262     + * Truncate pagecache after we've waited for commit
3263     + * in data=journal mode to make pages freeable.
3264     + */
3265     + truncate_pagecache(inode, oldsize, inode->i_size);
3266     }
3267     + /*
3268     + * We want to call ext4_truncate() even if attr->ia_size ==
3269     + * inode->i_size for cases like truncation of fallocated space
3270     + */
3271     + if (attr->ia_valid & ATTR_SIZE)
3272     + ext4_truncate(inode);
3273    
3274     if (!rc) {
3275     setattr_copy(inode, attr);
3276     diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
3277     index 5b127469..e67b13de 100644
3278     --- a/fs/fuse/dir.c
3279     +++ b/fs/fuse/dir.c
3280     @@ -1175,6 +1175,8 @@ static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
3281     return -EIO;
3282     if (reclen > nbytes)
3283     break;
3284     + if (memchr(dirent->name, '/', dirent->namelen) != NULL)
3285     + return -EIO;
3286    
3287     over = filldir(dstbuf, dirent->name, dirent->namelen,
3288     file->f_pos, dirent->ino, dirent->type);
3289     @@ -1323,6 +1325,8 @@ static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file,
3290     return -EIO;
3291     if (reclen > nbytes)
3292     break;
3293     + if (memchr(dirent->name, '/', dirent->namelen) != NULL)
3294     + return -EIO;
3295    
3296     if (!over) {
3297     /* We fill entries into dstbuf only as much as
3298     @@ -1594,6 +1598,7 @@ int fuse_do_setattr(struct inode *inode, struct iattr *attr,
3299     struct file *file)
3300     {
3301     struct fuse_conn *fc = get_fuse_conn(inode);
3302     + struct fuse_inode *fi = get_fuse_inode(inode);
3303     struct fuse_req *req;
3304     struct fuse_setattr_in inarg;
3305     struct fuse_attr_out outarg;
3306     @@ -1621,8 +1626,10 @@ int fuse_do_setattr(struct inode *inode, struct iattr *attr,
3307     if (IS_ERR(req))
3308     return PTR_ERR(req);
3309    
3310     - if (is_truncate)
3311     + if (is_truncate) {
3312     fuse_set_nowrite(inode);
3313     + set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
3314     + }
3315    
3316     memset(&inarg, 0, sizeof(inarg));
3317     memset(&outarg, 0, sizeof(outarg));
3318     @@ -1684,12 +1691,14 @@ int fuse_do_setattr(struct inode *inode, struct iattr *attr,
3319     invalidate_inode_pages2(inode->i_mapping);
3320     }
3321    
3322     + clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
3323     return 0;
3324    
3325     error:
3326     if (is_truncate)
3327     fuse_release_nowrite(inode);
3328    
3329     + clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
3330     return err;
3331     }
3332    
3333     @@ -1753,6 +1762,8 @@ static int fuse_setxattr(struct dentry *entry, const char *name,
3334     fc->no_setxattr = 1;
3335     err = -EOPNOTSUPP;
3336     }
3337     + if (!err)
3338     + fuse_invalidate_attr(inode);
3339     return err;
3340     }
3341    
3342     @@ -1882,6 +1893,8 @@ static int fuse_removexattr(struct dentry *entry, const char *name)
3343     fc->no_removexattr = 1;
3344     err = -EOPNOTSUPP;
3345     }
3346     + if (!err)
3347     + fuse_invalidate_attr(inode);
3348     return err;
3349     }
3350    
3351     diff --git a/fs/fuse/file.c b/fs/fuse/file.c
3352     index 35f28103..473e8453 100644
3353     --- a/fs/fuse/file.c
3354     +++ b/fs/fuse/file.c
3355     @@ -630,7 +630,8 @@ static void fuse_read_update_size(struct inode *inode, loff_t size,
3356     struct fuse_inode *fi = get_fuse_inode(inode);
3357    
3358     spin_lock(&fc->lock);
3359     - if (attr_ver == fi->attr_version && size < inode->i_size) {
3360     + if (attr_ver == fi->attr_version && size < inode->i_size &&
3361     + !test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) {
3362     fi->attr_version = ++fc->attr_version;
3363     i_size_write(inode, size);
3364     }
3365     @@ -1033,12 +1034,16 @@ static ssize_t fuse_perform_write(struct file *file,
3366     {
3367     struct inode *inode = mapping->host;
3368     struct fuse_conn *fc = get_fuse_conn(inode);
3369     + struct fuse_inode *fi = get_fuse_inode(inode);
3370     int err = 0;
3371     ssize_t res = 0;
3372    
3373     if (is_bad_inode(inode))
3374     return -EIO;
3375    
3376     + if (inode->i_size < pos + iov_iter_count(ii))
3377     + set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
3378     +
3379     do {
3380     struct fuse_req *req;
3381     ssize_t count;
3382     @@ -1074,6 +1079,7 @@ static ssize_t fuse_perform_write(struct file *file,
3383     if (res > 0)
3384     fuse_write_update_size(inode, pos);
3385    
3386     + clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
3387     fuse_invalidate_attr(inode);
3388    
3389     return res > 0 ? res : err;
3390     @@ -1530,7 +1536,6 @@ static int fuse_writepage_locked(struct page *page)
3391    
3392     inc_bdi_stat(mapping->backing_dev_info, BDI_WRITEBACK);
3393     inc_zone_page_state(tmp_page, NR_WRITEBACK_TEMP);
3394     - end_page_writeback(page);
3395    
3396     spin_lock(&fc->lock);
3397     list_add(&req->writepages_entry, &fi->writepages);
3398     @@ -1538,6 +1543,8 @@ static int fuse_writepage_locked(struct page *page)
3399     fuse_flush_writepages(inode);
3400     spin_unlock(&fc->lock);
3401    
3402     + end_page_writeback(page);
3403     +
3404     return 0;
3405    
3406     err_free:
3407     diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
3408     index fde7249a..5ced199b 100644
3409     --- a/fs/fuse/fuse_i.h
3410     +++ b/fs/fuse/fuse_i.h
3411     @@ -115,6 +115,8 @@ struct fuse_inode {
3412     enum {
3413     /** Advise readdirplus */
3414     FUSE_I_ADVISE_RDPLUS,
3415     + /** An operation changing file size is in progress */
3416     + FUSE_I_SIZE_UNSTABLE,
3417     };
3418    
3419     struct fuse_conn;
3420     diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
3421     index 9a0cdde1..b5718516 100644
3422     --- a/fs/fuse/inode.c
3423     +++ b/fs/fuse/inode.c
3424     @@ -201,7 +201,8 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
3425     struct timespec old_mtime;
3426    
3427     spin_lock(&fc->lock);
3428     - if (attr_version != 0 && fi->attr_version > attr_version) {
3429     + if ((attr_version != 0 && fi->attr_version > attr_version) ||
3430     + test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) {
3431     spin_unlock(&fc->lock);
3432     return;
3433     }
3434     diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
3435     index d9b8aebd..d3705490 100644
3436     --- a/fs/isofs/inode.c
3437     +++ b/fs/isofs/inode.c
3438     @@ -125,8 +125,8 @@ static void destroy_inodecache(void)
3439    
3440     static int isofs_remount(struct super_block *sb, int *flags, char *data)
3441     {
3442     - /* we probably want a lot more here */
3443     - *flags |= MS_RDONLY;
3444     + if (!(*flags & MS_RDONLY))
3445     + return -EROFS;
3446     return 0;
3447     }
3448    
3449     @@ -779,15 +779,6 @@ root_found:
3450     */
3451     s->s_maxbytes = 0x80000000000LL;
3452    
3453     - /*
3454     - * The CDROM is read-only, has no nodes (devices) on it, and since
3455     - * all of the files appear to be owned by root, we really do not want
3456     - * to allow suid. (suid or devices will not show up unless we have
3457     - * Rock Ridge extensions)
3458     - */
3459     -
3460     - s->s_flags |= MS_RDONLY /* | MS_NODEV | MS_NOSUID */;
3461     -
3462     /* Set this for reference. Its not currently used except on write
3463     which we don't have .. */
3464    
3465     @@ -1546,6 +1537,9 @@ struct inode *isofs_iget(struct super_block *sb,
3466     static struct dentry *isofs_mount(struct file_system_type *fs_type,
3467     int flags, const char *dev_name, void *data)
3468     {
3469     + /* We don't support read-write mounts */
3470     + if (!(flags & MS_RDONLY))
3471     + return ERR_PTR(-EACCES);
3472     return mount_bdev(fs_type, flags, dev_name, data, isofs_fill_super);
3473     }
3474    
3475     diff --git a/fs/ocfs2/extent_map.c b/fs/ocfs2/extent_map.c
3476     index 2487116d..84606472 100644
3477     --- a/fs/ocfs2/extent_map.c
3478     +++ b/fs/ocfs2/extent_map.c
3479     @@ -781,7 +781,6 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3480     cpos = map_start >> osb->s_clustersize_bits;
3481     mapping_end = ocfs2_clusters_for_bytes(inode->i_sb,
3482     map_start + map_len);
3483     - mapping_end -= cpos;
3484     is_last = 0;
3485     while (cpos < mapping_end && !is_last) {
3486     u32 fe_flags;
3487     diff --git a/fs/proc/root.c b/fs/proc/root.c
3488     index 41a6ea93..04ec276c 100644
3489     --- a/fs/proc/root.c
3490     +++ b/fs/proc/root.c
3491     @@ -110,7 +110,8 @@ static struct dentry *proc_mount(struct file_system_type *fs_type,
3492     ns = task_active_pid_ns(current);
3493     options = data;
3494    
3495     - if (!current_user_ns()->may_mount_proc)
3496     + if (!current_user_ns()->may_mount_proc ||
3497     + !ns_capable(ns->user_ns, CAP_SYS_ADMIN))
3498     return ERR_PTR(-EPERM);
3499     }
3500    
3501     diff --git a/include/linux/compat.h b/include/linux/compat.h
3502     index 7f0c1dd0..ec1aee4a 100644
3503     --- a/include/linux/compat.h
3504     +++ b/include/linux/compat.h
3505     @@ -669,6 +669,13 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
3506    
3507     int compat_restore_altstack(const compat_stack_t __user *uss);
3508     int __compat_save_altstack(compat_stack_t __user *, unsigned long);
3509     +#define compat_save_altstack_ex(uss, sp) do { \
3510     + compat_stack_t __user *__uss = uss; \
3511     + struct task_struct *t = current; \
3512     + put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &__uss->ss_sp); \
3513     + put_user_ex(sas_ss_flags(sp), &__uss->ss_flags); \
3514     + put_user_ex(t->sas_ss_size, &__uss->ss_size); \
3515     +} while (0);
3516    
3517     asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
3518     struct compat_timespec __user *interval);
3519     diff --git a/include/linux/hid.h b/include/linux/hid.h
3520     index 0c48991b..ff545cc3 100644
3521     --- a/include/linux/hid.h
3522     +++ b/include/linux/hid.h
3523     @@ -393,10 +393,12 @@ struct hid_report {
3524     struct hid_device *device; /* associated device */
3525     };
3526    
3527     +#define HID_MAX_IDS 256
3528     +
3529     struct hid_report_enum {
3530     unsigned numbered;
3531     struct list_head report_list;
3532     - struct hid_report *report_id_hash[256];
3533     + struct hid_report *report_id_hash[HID_MAX_IDS];
3534     };
3535    
3536     #define HID_REPORT_TYPES 3
3537     diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
3538     index c1291624..6c7bb35a 100644
3539     --- a/include/linux/pci_ids.h
3540     +++ b/include/linux/pci_ids.h
3541     @@ -518,6 +518,8 @@
3542     #define PCI_DEVICE_ID_AMD_11H_NB_MISC 0x1303
3543     #define PCI_DEVICE_ID_AMD_11H_NB_LINK 0x1304
3544     #define PCI_DEVICE_ID_AMD_15H_M10H_F3 0x1403
3545     +#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F3 0x141d
3546     +#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F4 0x141e
3547     #define PCI_DEVICE_ID_AMD_15H_NB_F0 0x1600
3548     #define PCI_DEVICE_ID_AMD_15H_NB_F1 0x1601
3549     #define PCI_DEVICE_ID_AMD_15H_NB_F2 0x1602
3550     diff --git a/include/linux/rculist.h b/include/linux/rculist.h
3551     index f4b1001a..4106721c 100644
3552     --- a/include/linux/rculist.h
3553     +++ b/include/linux/rculist.h
3554     @@ -267,8 +267,9 @@ static inline void list_splice_init_rcu(struct list_head *list,
3555     */
3556     #define list_first_or_null_rcu(ptr, type, member) \
3557     ({struct list_head *__ptr = (ptr); \
3558     - struct list_head __rcu *__next = list_next_rcu(__ptr); \
3559     - likely(__ptr != __next) ? container_of(__next, type, member) : NULL; \
3560     + struct list_head *__next = ACCESS_ONCE(__ptr->next); \
3561     + likely(__ptr != __next) ? \
3562     + list_entry_rcu(__next, type, member) : NULL; \
3563     })
3564    
3565     /**
3566     diff --git a/include/linux/signal.h b/include/linux/signal.h
3567     index d8974847..2ac423bd 100644
3568     --- a/include/linux/signal.h
3569     +++ b/include/linux/signal.h
3570     @@ -434,6 +434,14 @@ void signals_init(void);
3571     int restore_altstack(const stack_t __user *);
3572     int __save_altstack(stack_t __user *, unsigned long);
3573    
3574     +#define save_altstack_ex(uss, sp) do { \
3575     + stack_t __user *__uss = uss; \
3576     + struct task_struct *t = current; \
3577     + put_user_ex((void __user *)t->sas_ss_sp, &__uss->ss_sp); \
3578     + put_user_ex(sas_ss_flags(sp), &__uss->ss_flags); \
3579     + put_user_ex(t->sas_ss_size, &__uss->ss_size); \
3580     +} while (0);
3581     +
3582     #ifdef CONFIG_PROC_FS
3583     struct seq_file;
3584     extern void render_sigset_t(struct seq_file *, const char *, sigset_t *);
3585     diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
3586     index f5f5c7df..0fdff28d 100644
3587     --- a/include/linux/usb/hcd.h
3588     +++ b/include/linux/usb/hcd.h
3589     @@ -410,7 +410,7 @@ extern int usb_hcd_pci_probe(struct pci_dev *dev,
3590     extern void usb_hcd_pci_remove(struct pci_dev *dev);
3591     extern void usb_hcd_pci_shutdown(struct pci_dev *dev);
3592    
3593     -#ifdef CONFIG_PM_SLEEP
3594     +#ifdef CONFIG_PM
3595     extern const struct dev_pm_ops usb_hcd_pci_pm_ops;
3596     #endif
3597     #endif /* CONFIG_PCI */
3598     diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
3599     index 7343a27f..47ada233 100644
3600     --- a/include/media/v4l2-ctrls.h
3601     +++ b/include/media/v4l2-ctrls.h
3602     @@ -22,6 +22,7 @@
3603     #define _V4L2_CTRLS_H
3604    
3605     #include <linux/list.h>
3606     +#include <linux/mutex.h>
3607     #include <linux/videodev2.h>
3608    
3609     /* forward references */
3610     diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
3611     index f3569747..ad8e1bdc 100644
3612     --- a/kernel/events/uprobes.c
3613     +++ b/kernel/events/uprobes.c
3614     @@ -1682,12 +1682,10 @@ static bool handle_trampoline(struct pt_regs *regs)
3615     tmp = ri;
3616     ri = ri->next;
3617     kfree(tmp);
3618     + utask->depth--;
3619    
3620     if (!chained)
3621     break;
3622     -
3623     - utask->depth--;
3624     -
3625     BUG_ON(!ri);
3626     }
3627    
3628     diff --git a/kernel/fork.c b/kernel/fork.c
3629     index ffbc0904..80d92e98 100644
3630     --- a/kernel/fork.c
3631     +++ b/kernel/fork.c
3632     @@ -1171,10 +1171,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
3633     return ERR_PTR(-EINVAL);
3634    
3635     /*
3636     - * If the new process will be in a different pid namespace
3637     - * don't allow the creation of threads.
3638     + * If the new process will be in a different pid namespace don't
3639     + * allow it to share a thread group or signal handlers with the
3640     + * forking task.
3641     */
3642     - if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) &&
3643     + if ((clone_flags & (CLONE_SIGHAND | CLONE_NEWPID)) &&
3644     (task_active_pid_ns(current) != current->nsproxy->pid_ns))
3645     return ERR_PTR(-EINVAL);
3646    
3647     diff --git a/kernel/pid.c b/kernel/pid.c
3648     index 0db3e791..0eb6d8e8 100644
3649     --- a/kernel/pid.c
3650     +++ b/kernel/pid.c
3651     @@ -264,6 +264,7 @@ void free_pid(struct pid *pid)
3652     struct pid_namespace *ns = upid->ns;
3653     hlist_del_rcu(&upid->pid_chain);
3654     switch(--ns->nr_hashed) {
3655     + case 2:
3656     case 1:
3657     /* When all that is left in the pid namespace
3658     * is the reaper wake up the reaper. The reaper
3659     diff --git a/mm/huge_memory.c b/mm/huge_memory.c
3660     index 362c329b..b92d0ce4 100644
3661     --- a/mm/huge_memory.c
3662     +++ b/mm/huge_memory.c
3663     @@ -2286,6 +2286,8 @@ static void collapse_huge_page(struct mm_struct *mm,
3664     goto out;
3665    
3666     vma = find_vma(mm, address);
3667     + if (!vma)
3668     + goto out;
3669     hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
3670     hend = vma->vm_end & HPAGE_PMD_MASK;
3671     if (address < hstart || address + HPAGE_PMD_SIZE > hend)
3672     diff --git a/mm/memcontrol.c b/mm/memcontrol.c
3673     index 82a187ae..905ce72c 100644
3674     --- a/mm/memcontrol.c
3675     +++ b/mm/memcontrol.c
3676     @@ -5584,7 +5584,13 @@ static int compare_thresholds(const void *a, const void *b)
3677     const struct mem_cgroup_threshold *_a = a;
3678     const struct mem_cgroup_threshold *_b = b;
3679    
3680     - return _a->threshold - _b->threshold;
3681     + if (_a->threshold > _b->threshold)
3682     + return 1;
3683     +
3684     + if (_a->threshold < _b->threshold)
3685     + return -1;
3686     +
3687     + return 0;
3688     }
3689    
3690     static int mem_cgroup_oom_notify_cb(struct mem_cgroup *memcg)
3691     diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
3692     index 3a246a6c..46ec7672 100644
3693     --- a/net/ceph/osd_client.c
3694     +++ b/net/ceph/osd_client.c
3695     @@ -2130,6 +2130,8 @@ int ceph_osdc_start_request(struct ceph_osd_client *osdc,
3696     dout("osdc_start_request failed map, "
3697     " will retry %lld\n", req->r_tid);
3698     rc = 0;
3699     + } else {
3700     + __unregister_request(osdc, req);
3701     }
3702     goto out_unlock;
3703     }
3704     diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
3705     index 603ddd92..dbd9a479 100644
3706     --- a/net/ceph/osdmap.c
3707     +++ b/net/ceph/osdmap.c
3708     @@ -1129,7 +1129,7 @@ static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid,
3709    
3710     /* pg_temp? */
3711     pgid.seed = ceph_stable_mod(pgid.seed, pool->pg_num,
3712     - pool->pgp_num_mask);
3713     + pool->pg_num_mask);
3714     pg = __lookup_pg_mapping(&osdmap->pg_temp, pgid);
3715     if (pg) {
3716     *num = pg->len;
3717     diff --git a/net/core/scm.c b/net/core/scm.c
3718     index 03795d01..b4da80b1 100644
3719     --- a/net/core/scm.c
3720     +++ b/net/core/scm.c
3721     @@ -54,7 +54,7 @@ static __inline__ int scm_check_creds(struct ucred *creds)
3722     return -EINVAL;
3723    
3724     if ((creds->pid == task_tgid_vnr(current) ||
3725     - ns_capable(current->nsproxy->pid_ns->user_ns, CAP_SYS_ADMIN)) &&
3726     + ns_capable(task_active_pid_ns(current)->user_ns, CAP_SYS_ADMIN)) &&
3727     ((uid_eq(uid, cred->uid) || uid_eq(uid, cred->euid) ||
3728     uid_eq(uid, cred->suid)) || nsown_capable(CAP_SETUID)) &&
3729     ((gid_eq(gid, cred->gid) || gid_eq(gid, cred->egid) ||
3730     diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
3731     index de18722c..624e6c04 100644
3732     --- a/sound/pci/hda/hda_intel.c
3733     +++ b/sound/pci/hda/hda_intel.c
3734     @@ -3335,6 +3335,7 @@ static struct snd_pci_quirk msi_black_list[] = {
3735     SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
3736     SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
3737     SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
3738     + SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */
3739     SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
3740     SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
3741     {}
3742     diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
3743     index 5bc41945..b5375ed0 100644
3744     --- a/sound/pci/hda/patch_hdmi.c
3745     +++ b/sound/pci/hda/patch_hdmi.c
3746     @@ -67,6 +67,8 @@ struct hdmi_spec_per_pin {
3747     struct delayed_work work;
3748     struct snd_kcontrol *eld_ctl;
3749     int repoll_count;
3750     + bool setup; /* the stream has been set up by prepare callback */
3751     + int channels; /* current number of channels */
3752     bool non_pcm;
3753     bool chmap_set; /* channel-map override by ALSA API? */
3754     unsigned char chmap[8]; /* ALSA API channel-map */
3755     @@ -551,6 +553,17 @@ static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
3756     }
3757     }
3758    
3759     + if (!ca) {
3760     + /* if there was no match, select the regular ALSA channel
3761     + * allocation with the matching number of channels */
3762     + for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
3763     + if (channels == channel_allocations[i].channels) {
3764     + ca = channel_allocations[i].ca_index;
3765     + break;
3766     + }
3767     + }
3768     + }
3769     +
3770     snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf));
3771     snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
3772     ca, channels, buf);
3773     @@ -868,18 +881,19 @@ static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
3774     return true;
3775     }
3776    
3777     -static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
3778     - bool non_pcm,
3779     - struct snd_pcm_substream *substream)
3780     +static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
3781     + struct hdmi_spec_per_pin *per_pin,
3782     + bool non_pcm)
3783     {
3784     - struct hdmi_spec *spec = codec->spec;
3785     - struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
3786     hda_nid_t pin_nid = per_pin->pin_nid;
3787     - int channels = substream->runtime->channels;
3788     + int channels = per_pin->channels;
3789     struct hdmi_eld *eld;
3790     int ca;
3791     union audio_infoframe ai;
3792    
3793     + if (!channels)
3794     + return;
3795     +
3796     eld = &per_pin->sink_eld;
3797     if (!eld->monitor_present)
3798     return;
3799     @@ -1263,6 +1277,7 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
3800     eld_changed = true;
3801     }
3802     if (update_eld) {
3803     + bool old_eld_valid = pin_eld->eld_valid;
3804     pin_eld->eld_valid = eld->eld_valid;
3805     eld_changed = pin_eld->eld_size != eld->eld_size ||
3806     memcmp(pin_eld->eld_buffer, eld->eld_buffer,
3807     @@ -1272,6 +1287,18 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
3808     eld->eld_size);
3809     pin_eld->eld_size = eld->eld_size;
3810     pin_eld->info = eld->info;
3811     +
3812     + /* Haswell-specific workaround: re-setup when the transcoder is
3813     + * changed during the stream playback
3814     + */
3815     + if (codec->vendor_id == 0x80862807 &&
3816     + eld->eld_valid && !old_eld_valid && per_pin->setup) {
3817     + snd_hda_codec_write(codec, pin_nid, 0,
3818     + AC_VERB_SET_AMP_GAIN_MUTE,
3819     + AMP_OUT_UNMUTE);
3820     + hdmi_setup_audio_infoframe(codec, per_pin,
3821     + per_pin->non_pcm);
3822     + }
3823     }
3824     mutex_unlock(&pin_eld->lock);
3825    
3826     @@ -1444,14 +1471,17 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3827     hda_nid_t cvt_nid = hinfo->nid;
3828     struct hdmi_spec *spec = codec->spec;
3829     int pin_idx = hinfo_to_pin_index(spec, hinfo);
3830     - hda_nid_t pin_nid = get_pin(spec, pin_idx)->pin_nid;
3831     + struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
3832     + hda_nid_t pin_nid = per_pin->pin_nid;
3833     bool non_pcm;
3834    
3835     non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
3836     + per_pin->channels = substream->runtime->channels;
3837     + per_pin->setup = true;
3838    
3839     hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels);
3840    
3841     - hdmi_setup_audio_infoframe(codec, pin_idx, non_pcm, substream);
3842     + hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
3843    
3844     return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
3845     }
3846     @@ -1491,6 +1521,9 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
3847     snd_hda_spdif_ctls_unassign(codec, pin_idx);
3848     per_pin->chmap_set = false;
3849     memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
3850     +
3851     + per_pin->setup = false;
3852     + per_pin->channels = 0;
3853     }
3854    
3855     return 0;
3856     @@ -1626,8 +1659,7 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
3857     per_pin->chmap_set = true;
3858     memcpy(per_pin->chmap, chmap, sizeof(chmap));
3859     if (prepared)
3860     - hdmi_setup_audio_infoframe(codec, pin_idx, per_pin->non_pcm,
3861     - substream);
3862     + hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
3863    
3864     return 0;
3865     }
3866     diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c
3867     index 5402dfbb..8a8d9364 100644
3868     --- a/sound/soc/codecs/mc13783.c
3869     +++ b/sound/soc/codecs/mc13783.c
3870     @@ -126,6 +126,10 @@ static int mc13783_write(struct snd_soc_codec *codec,
3871    
3872     ret = mc13xxx_reg_write(priv->mc13xxx, reg, value);
3873    
3874     + /* include errata fix for spi audio problems */
3875     + if (reg == MC13783_AUDIO_CODEC || reg == MC13783_AUDIO_DAC)
3876     + ret = mc13xxx_reg_write(priv->mc13xxx, reg, value);
3877     +
3878     mc13xxx_unlock(priv->mc13xxx);
3879    
3880     return ret;
3881     diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
3882     index 0a4ffdd1..5e5af898 100644
3883     --- a/sound/soc/codecs/wm8960.c
3884     +++ b/sound/soc/codecs/wm8960.c
3885     @@ -857,9 +857,9 @@ static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
3886     if (pll_div.k) {
3887     reg |= 0x20;
3888    
3889     - snd_soc_write(codec, WM8960_PLL2, (pll_div.k >> 18) & 0x3f);
3890     - snd_soc_write(codec, WM8960_PLL3, (pll_div.k >> 9) & 0x1ff);
3891     - snd_soc_write(codec, WM8960_PLL4, pll_div.k & 0x1ff);
3892     + snd_soc_write(codec, WM8960_PLL2, (pll_div.k >> 16) & 0xff);
3893     + snd_soc_write(codec, WM8960_PLL3, (pll_div.k >> 8) & 0xff);
3894     + snd_soc_write(codec, WM8960_PLL4, pll_div.k & 0xff);
3895     }
3896     snd_soc_write(codec, WM8960_PLL1, reg);
3897