Magellan Linux

Annotation of /trunk/kernel-magellan/patches-3.7/0101-3.7.2-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2038 - (hide annotations) (download)
Mon Jan 28 08:11:12 2013 UTC (11 years, 3 months ago) by niro
File size: 160240 byte(s)
linux-3.7.2
1 niro 2038 diff --git a/arch/arm/kernel/swp_emulate.c b/arch/arm/kernel/swp_emulate.c
2     index df74518..ab1017b 100644
3     --- a/arch/arm/kernel/swp_emulate.c
4     +++ b/arch/arm/kernel/swp_emulate.c
5     @@ -109,10 +109,12 @@ static void set_segfault(struct pt_regs *regs, unsigned long addr)
6     {
7     siginfo_t info;
8    
9     + down_read(&current->mm->mmap_sem);
10     if (find_vma(current->mm, addr) == NULL)
11     info.si_code = SEGV_MAPERR;
12     else
13     info.si_code = SEGV_ACCERR;
14     + up_read(&current->mm->mmap_sem);
15    
16     info.si_signo = SIGSEGV;
17     info.si_errno = 0;
18     diff --git a/arch/arm/mach-realview/include/mach/board-eb.h b/arch/arm/mach-realview/include/mach/board-eb.h
19     index 124bce6..a301e61 100644
20     --- a/arch/arm/mach-realview/include/mach/board-eb.h
21     +++ b/arch/arm/mach-realview/include/mach/board-eb.h
22     @@ -47,7 +47,7 @@
23     #define REALVIEW_EB_USB_BASE 0x4F000000 /* USB */
24    
25     #ifdef CONFIG_REALVIEW_EB_ARM11MP_REVB
26     -#define REALVIEW_EB11MP_PRIV_MEM_BASE 0x1F000000
27     +#define REALVIEW_EB11MP_PRIV_MEM_BASE 0x10100000
28     #define REALVIEW_EB11MP_L220_BASE 0x10102000 /* L220 registers */
29     #define REALVIEW_EB11MP_SYS_PLD_CTRL1 0xD8 /* Register offset for MPCore sysctl */
30     #else
31     diff --git a/arch/arm/mm/cache-v7.S b/arch/arm/mm/cache-v7.S
32     index cd95664..7539ec2 100644
33     --- a/arch/arm/mm/cache-v7.S
34     +++ b/arch/arm/mm/cache-v7.S
35     @@ -44,8 +44,10 @@ ENDPROC(v7_flush_icache_all)
36     ENTRY(v7_flush_dcache_louis)
37     dmb @ ensure ordering with previous memory accesses
38     mrc p15, 1, r0, c0, c0, 1 @ read clidr, r0 = clidr
39     - ands r3, r0, #0xe00000 @ extract LoUIS from clidr
40     - mov r3, r3, lsr #20 @ r3 = LoUIS * 2
41     + ALT_SMP(ands r3, r0, #(7 << 21)) @ extract LoUIS from clidr
42     + ALT_UP(ands r3, r0, #(7 << 27)) @ extract LoUU from clidr
43     + ALT_SMP(mov r3, r3, lsr #20) @ r3 = LoUIS * 2
44     + ALT_UP(mov r3, r3, lsr #26) @ r3 = LoUU * 2
45     moveq pc, lr @ return if level == 0
46     mov r10, #0 @ r10 (starting level) = 0
47     b flush_levels @ start flushing cache levels
48     diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
49     index 941dfb9..99b47b9 100644
50     --- a/arch/arm/mm/mmu.c
51     +++ b/arch/arm/mm/mmu.c
52     @@ -488,7 +488,7 @@ static void __init build_mem_type_table(void)
53     #endif
54    
55     for (i = 0; i < 16; i++) {
56     - unsigned long v = pgprot_val(protection_map[i]);
57     + pteval_t v = pgprot_val(protection_map[i]);
58     protection_map[i] = __pgprot(v | user_pgprot);
59     }
60    
61     diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
62     index 14aba2d..64b1339 100644
63     --- a/arch/arm64/include/asm/pgtable.h
64     +++ b/arch/arm64/include/asm/pgtable.h
65     @@ -159,6 +159,8 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
66     {
67     if (pte_present_exec_user(pte))
68     __sync_icache_dcache(pte, addr);
69     + if (!pte_dirty(pte))
70     + pte = pte_wrprotect(pte);
71     set_pte(ptep, pte);
72     }
73    
74     diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h
75     index 656a6f2..660f210 100644
76     --- a/arch/arm64/include/asm/unistd32.h
77     +++ b/arch/arm64/include/asm/unistd32.h
78     @@ -393,7 +393,7 @@ __SYSCALL(368, compat_sys_fanotify_mark_wrapper)
79     __SYSCALL(369, sys_prlimit64)
80     __SYSCALL(370, sys_name_to_handle_at)
81     __SYSCALL(371, compat_sys_open_by_handle_at)
82     -__SYSCALL(372, sys_clock_adjtime)
83     +__SYSCALL(372, compat_sys_clock_adjtime)
84     __SYSCALL(373, sys_syncfs)
85    
86     #define __NR_compat_syscalls 374
87     diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
88     index 8807ba2..051bb52 100644
89     --- a/arch/arm64/kernel/signal.c
90     +++ b/arch/arm64/kernel/signal.c
91     @@ -41,6 +41,8 @@
92     struct rt_sigframe {
93     struct siginfo info;
94     struct ucontext uc;
95     + u64 fp;
96     + u64 lr;
97     };
98    
99     static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
100     @@ -175,6 +177,10 @@ static int setup_sigframe(struct rt_sigframe __user *sf,
101     struct aux_context __user *aux =
102     (struct aux_context __user *)sf->uc.uc_mcontext.__reserved;
103    
104     + /* set up the stack frame for unwinding */
105     + __put_user_error(regs->regs[29], &sf->fp, err);
106     + __put_user_error(regs->regs[30], &sf->lr, err);
107     +
108     for (i = 0; i < 31; i++)
109     __put_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
110     err);
111     @@ -210,9 +216,6 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
112     if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
113     sp = sp_top = current->sas_ss_sp + current->sas_ss_size;
114    
115     - /* room for stack frame (FP, LR) */
116     - sp -= 16;
117     -
118     sp = (sp - framesize) & ~15;
119     frame = (void __user *)sp;
120    
121     @@ -225,20 +228,14 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
122     return frame;
123     }
124    
125     -static int setup_return(struct pt_regs *regs, struct k_sigaction *ka,
126     - void __user *frame, int usig)
127     +static void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
128     + void __user *frame, int usig)
129     {
130     - int err = 0;
131     __sigrestore_t sigtramp;
132     - unsigned long __user *sp = (unsigned long __user *)regs->sp;
133     -
134     - /* set up the stack frame */
135     - __put_user_error(regs->regs[29], sp - 2, err);
136     - __put_user_error(regs->regs[30], sp - 1, err);
137    
138     regs->regs[0] = usig;
139     - regs->regs[29] = regs->sp - 16;
140     regs->sp = (unsigned long)frame;
141     + regs->regs[29] = regs->sp + offsetof(struct rt_sigframe, fp);
142     regs->pc = (unsigned long)ka->sa.sa_handler;
143    
144     if (ka->sa.sa_flags & SA_RESTORER)
145     @@ -247,8 +244,6 @@ static int setup_return(struct pt_regs *regs, struct k_sigaction *ka,
146     sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp);
147    
148     regs->regs[30] = (unsigned long)sigtramp;
149     -
150     - return err;
151     }
152    
153     static int setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
154     @@ -272,13 +267,13 @@ static int setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
155     err |= __copy_to_user(&frame->uc.uc_stack, &stack, sizeof(stack));
156    
157     err |= setup_sigframe(frame, regs, set);
158     - if (err == 0)
159     - err = setup_return(regs, ka, frame, usig);
160     -
161     - if (err == 0 && ka->sa.sa_flags & SA_SIGINFO) {
162     - err |= copy_siginfo_to_user(&frame->info, info);
163     - regs->regs[1] = (unsigned long)&frame->info;
164     - regs->regs[2] = (unsigned long)&frame->uc;
165     + if (err == 0) {
166     + setup_return(regs, ka, frame, usig);
167     + if (ka->sa.sa_flags & SA_SIGINFO) {
168     + err |= copy_siginfo_to_user(&frame->info, info);
169     + regs->regs[1] = (unsigned long)&frame->info;
170     + regs->regs[2] = (unsigned long)&frame->uc;
171     + }
172     }
173    
174     return err;
175     diff --git a/arch/cris/include/asm/io.h b/arch/cris/include/asm/io.h
176     index 32567bc..ac12ae2 100644
177     --- a/arch/cris/include/asm/io.h
178     +++ b/arch/cris/include/asm/io.h
179     @@ -133,12 +133,39 @@ static inline void writel(unsigned int b, volatile void __iomem *addr)
180     #define insb(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,1,count) : 0)
181     #define insw(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,2,count) : 0)
182     #define insl(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,4,count) : 0)
183     -#define outb(data,port) if (cris_iops) cris_iops->write_io(port,(void*)(unsigned)data,1,1)
184     -#define outw(data,port) if (cris_iops) cris_iops->write_io(port,(void*)(unsigned)data,2,1)
185     -#define outl(data,port) if (cris_iops) cris_iops->write_io(port,(void*)(unsigned)data,4,1)
186     -#define outsb(port,addr,count) if(cris_iops) cris_iops->write_io(port,(void*)addr,1,count)
187     -#define outsw(port,addr,count) if(cris_iops) cris_iops->write_io(port,(void*)addr,2,count)
188     -#define outsl(port,addr,count) if(cris_iops) cris_iops->write_io(port,(void*)addr,3,count)
189     +static inline void outb(unsigned char data, unsigned int port)
190     +{
191     + if (cris_iops)
192     + cris_iops->write_io(port, (void *) &data, 1, 1);
193     +}
194     +static inline void outw(unsigned short data, unsigned int port)
195     +{
196     + if (cris_iops)
197     + cris_iops->write_io(port, (void *) &data, 2, 1);
198     +}
199     +static inline void outl(unsigned int data, unsigned int port)
200     +{
201     + if (cris_iops)
202     + cris_iops->write_io(port, (void *) &data, 4, 1);
203     +}
204     +static inline void outsb(unsigned int port, const void *addr,
205     + unsigned long count)
206     +{
207     + if (cris_iops)
208     + cris_iops->write_io(port, (void *)addr, 1, count);
209     +}
210     +static inline void outsw(unsigned int port, const void *addr,
211     + unsigned long count)
212     +{
213     + if (cris_iops)
214     + cris_iops->write_io(port, (void *)addr, 2, count);
215     +}
216     +static inline void outsl(unsigned int port, const void *addr,
217     + unsigned long count)
218     +{
219     + if (cris_iops)
220     + cris_iops->write_io(port, (void *)addr, 4, count);
221     +}
222    
223     /*
224     * Convert a physical pointer to a virtual kernel pointer for /dev/mem
225     diff --git a/arch/sparc/crypto/aes_asm.S b/arch/sparc/crypto/aes_asm.S
226     index 23f6cbb..1cda8aa 100644
227     --- a/arch/sparc/crypto/aes_asm.S
228     +++ b/arch/sparc/crypto/aes_asm.S
229     @@ -1024,7 +1024,11 @@ ENTRY(aes_sparc64_ecb_encrypt_256)
230     add %o2, 0x20, %o2
231     brlz,pt %o3, 11f
232     nop
233     -10: ldx [%o1 + 0x00], %g3
234     +10: ldd [%o0 + 0xd0], %f56
235     + ldd [%o0 + 0xd8], %f58
236     + ldd [%o0 + 0xe0], %f60
237     + ldd [%o0 + 0xe8], %f62
238     + ldx [%o1 + 0x00], %g3
239     ldx [%o1 + 0x08], %g7
240     xor %g1, %g3, %g3
241     xor %g2, %g7, %g7
242     @@ -1128,9 +1132,9 @@ ENTRY(aes_sparc64_ecb_decrypt_256)
243     /* %o0=&key[key_len], %o1=input, %o2=output, %o3=len */
244     ldx [%o0 - 0x10], %g1
245     subcc %o3, 0x10, %o3
246     + ldx [%o0 - 0x08], %g2
247     be 10f
248     - ldx [%o0 - 0x08], %g2
249     - sub %o0, 0xf0, %o0
250     + sub %o0, 0xf0, %o0
251     1: ldx [%o1 + 0x00], %g3
252     ldx [%o1 + 0x08], %g7
253     ldx [%o1 + 0x10], %o4
254     @@ -1154,7 +1158,11 @@ ENTRY(aes_sparc64_ecb_decrypt_256)
255     add %o2, 0x20, %o2
256     brlz,pt %o3, 11f
257     nop
258     -10: ldx [%o1 + 0x00], %g3
259     +10: ldd [%o0 + 0x18], %f56
260     + ldd [%o0 + 0x10], %f58
261     + ldd [%o0 + 0x08], %f60
262     + ldd [%o0 + 0x00], %f62
263     + ldx [%o1 + 0x00], %g3
264     ldx [%o1 + 0x08], %g7
265     xor %g1, %g3, %g3
266     xor %g2, %g7, %g7
267     @@ -1511,11 +1519,11 @@ ENTRY(aes_sparc64_ctr_crypt_256)
268     add %o2, 0x20, %o2
269     brlz,pt %o3, 11f
270     nop
271     - ldd [%o0 + 0xd0], %f56
272     +10: ldd [%o0 + 0xd0], %f56
273     ldd [%o0 + 0xd8], %f58
274     ldd [%o0 + 0xe0], %f60
275     ldd [%o0 + 0xe8], %f62
276     -10: xor %g1, %g3, %o5
277     + xor %g1, %g3, %o5
278     MOVXTOD_O5_F0
279     xor %g2, %g7, %o5
280     MOVXTOD_O5_F2
281     diff --git a/arch/sparc/crypto/aes_glue.c b/arch/sparc/crypto/aes_glue.c
282     index 3965d1d..503e6d9 100644
283     --- a/arch/sparc/crypto/aes_glue.c
284     +++ b/arch/sparc/crypto/aes_glue.c
285     @@ -222,6 +222,7 @@ static int ecb_encrypt(struct blkcipher_desc *desc,
286    
287     blkcipher_walk_init(&walk, dst, src, nbytes);
288     err = blkcipher_walk_virt(desc, &walk);
289     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
290    
291     ctx->ops->load_encrypt_keys(&ctx->key[0]);
292     while ((nbytes = walk.nbytes)) {
293     @@ -251,6 +252,7 @@ static int ecb_decrypt(struct blkcipher_desc *desc,
294    
295     blkcipher_walk_init(&walk, dst, src, nbytes);
296     err = blkcipher_walk_virt(desc, &walk);
297     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
298    
299     ctx->ops->load_decrypt_keys(&ctx->key[0]);
300     key_end = &ctx->key[ctx->expanded_key_length / sizeof(u64)];
301     @@ -280,6 +282,7 @@ static int cbc_encrypt(struct blkcipher_desc *desc,
302    
303     blkcipher_walk_init(&walk, dst, src, nbytes);
304     err = blkcipher_walk_virt(desc, &walk);
305     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
306    
307     ctx->ops->load_encrypt_keys(&ctx->key[0]);
308     while ((nbytes = walk.nbytes)) {
309     @@ -309,6 +312,7 @@ static int cbc_decrypt(struct blkcipher_desc *desc,
310    
311     blkcipher_walk_init(&walk, dst, src, nbytes);
312     err = blkcipher_walk_virt(desc, &walk);
313     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
314    
315     ctx->ops->load_decrypt_keys(&ctx->key[0]);
316     key_end = &ctx->key[ctx->expanded_key_length / sizeof(u64)];
317     @@ -329,6 +333,22 @@ static int cbc_decrypt(struct blkcipher_desc *desc,
318     return err;
319     }
320    
321     +static void ctr_crypt_final(struct crypto_sparc64_aes_ctx *ctx,
322     + struct blkcipher_walk *walk)
323     +{
324     + u8 *ctrblk = walk->iv;
325     + u64 keystream[AES_BLOCK_SIZE / sizeof(u64)];
326     + u8 *src = walk->src.virt.addr;
327     + u8 *dst = walk->dst.virt.addr;
328     + unsigned int nbytes = walk->nbytes;
329     +
330     + ctx->ops->ecb_encrypt(&ctx->key[0], (const u64 *)ctrblk,
331     + keystream, AES_BLOCK_SIZE);
332     + crypto_xor((u8 *) keystream, src, nbytes);
333     + memcpy(dst, keystream, nbytes);
334     + crypto_inc(ctrblk, AES_BLOCK_SIZE);
335     +}
336     +
337     static int ctr_crypt(struct blkcipher_desc *desc,
338     struct scatterlist *dst, struct scatterlist *src,
339     unsigned int nbytes)
340     @@ -338,10 +358,11 @@ static int ctr_crypt(struct blkcipher_desc *desc,
341     int err;
342    
343     blkcipher_walk_init(&walk, dst, src, nbytes);
344     - err = blkcipher_walk_virt(desc, &walk);
345     + err = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE);
346     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
347    
348     ctx->ops->load_encrypt_keys(&ctx->key[0]);
349     - while ((nbytes = walk.nbytes)) {
350     + while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
351     unsigned int block_len = nbytes & AES_BLOCK_MASK;
352    
353     if (likely(block_len)) {
354     @@ -353,6 +374,10 @@ static int ctr_crypt(struct blkcipher_desc *desc,
355     nbytes &= AES_BLOCK_SIZE - 1;
356     err = blkcipher_walk_done(desc, &walk, nbytes);
357     }
358     + if (walk.nbytes) {
359     + ctr_crypt_final(ctx, &walk);
360     + err = blkcipher_walk_done(desc, &walk, 0);
361     + }
362     fprs_write(0);
363     return err;
364     }
365     @@ -418,7 +443,7 @@ static struct crypto_alg algs[] = { {
366     .cra_driver_name = "ctr-aes-sparc64",
367     .cra_priority = SPARC_CR_OPCODE_PRIORITY,
368     .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
369     - .cra_blocksize = AES_BLOCK_SIZE,
370     + .cra_blocksize = 1,
371     .cra_ctxsize = sizeof(struct crypto_sparc64_aes_ctx),
372     .cra_alignmask = 7,
373     .cra_type = &crypto_blkcipher_type,
374     diff --git a/arch/sparc/crypto/camellia_glue.c b/arch/sparc/crypto/camellia_glue.c
375     index 62c89af..888f626 100644
376     --- a/arch/sparc/crypto/camellia_glue.c
377     +++ b/arch/sparc/crypto/camellia_glue.c
378     @@ -98,6 +98,7 @@ static int __ecb_crypt(struct blkcipher_desc *desc,
379    
380     blkcipher_walk_init(&walk, dst, src, nbytes);
381     err = blkcipher_walk_virt(desc, &walk);
382     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
383    
384     if (encrypt)
385     key = &ctx->encrypt_key[0];
386     @@ -160,6 +161,7 @@ static int cbc_encrypt(struct blkcipher_desc *desc,
387    
388     blkcipher_walk_init(&walk, dst, src, nbytes);
389     err = blkcipher_walk_virt(desc, &walk);
390     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
391    
392     key = &ctx->encrypt_key[0];
393     camellia_sparc64_load_keys(key, ctx->key_len);
394     @@ -198,6 +200,7 @@ static int cbc_decrypt(struct blkcipher_desc *desc,
395    
396     blkcipher_walk_init(&walk, dst, src, nbytes);
397     err = blkcipher_walk_virt(desc, &walk);
398     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
399    
400     key = &ctx->decrypt_key[0];
401     camellia_sparc64_load_keys(key, ctx->key_len);
402     diff --git a/arch/sparc/crypto/des_asm.S b/arch/sparc/crypto/des_asm.S
403     index 30b6e90..b5c8fc2 100644
404     --- a/arch/sparc/crypto/des_asm.S
405     +++ b/arch/sparc/crypto/des_asm.S
406     @@ -376,6 +376,7 @@ ENTRY(des3_ede_sparc64_ecb_crypt)
407     1: ldd [%o1 + 0x00], %f60
408     DES3_LOOP_BODY(60)
409     std %f60, [%o2 + 0x00]
410     + add %o1, 0x08, %o1
411     subcc %o3, 0x08, %o3
412     bne,pt %icc, 1b
413     add %o2, 0x08, %o2
414     diff --git a/arch/sparc/crypto/des_glue.c b/arch/sparc/crypto/des_glue.c
415     index 41524ce..3065bc6 100644
416     --- a/arch/sparc/crypto/des_glue.c
417     +++ b/arch/sparc/crypto/des_glue.c
418     @@ -100,6 +100,7 @@ static int __ecb_crypt(struct blkcipher_desc *desc,
419    
420     blkcipher_walk_init(&walk, dst, src, nbytes);
421     err = blkcipher_walk_virt(desc, &walk);
422     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
423    
424     if (encrypt)
425     des_sparc64_load_keys(&ctx->encrypt_expkey[0]);
426     @@ -147,6 +148,7 @@ static int cbc_encrypt(struct blkcipher_desc *desc,
427    
428     blkcipher_walk_init(&walk, dst, src, nbytes);
429     err = blkcipher_walk_virt(desc, &walk);
430     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
431    
432     des_sparc64_load_keys(&ctx->encrypt_expkey[0]);
433     while ((nbytes = walk.nbytes)) {
434     @@ -177,6 +179,7 @@ static int cbc_decrypt(struct blkcipher_desc *desc,
435    
436     blkcipher_walk_init(&walk, dst, src, nbytes);
437     err = blkcipher_walk_virt(desc, &walk);
438     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
439    
440     des_sparc64_load_keys(&ctx->decrypt_expkey[0]);
441     while ((nbytes = walk.nbytes)) {
442     @@ -266,6 +269,7 @@ static int __ecb3_crypt(struct blkcipher_desc *desc,
443    
444     blkcipher_walk_init(&walk, dst, src, nbytes);
445     err = blkcipher_walk_virt(desc, &walk);
446     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
447    
448     if (encrypt)
449     K = &ctx->encrypt_expkey[0];
450     @@ -317,6 +321,7 @@ static int cbc3_encrypt(struct blkcipher_desc *desc,
451    
452     blkcipher_walk_init(&walk, dst, src, nbytes);
453     err = blkcipher_walk_virt(desc, &walk);
454     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
455    
456     K = &ctx->encrypt_expkey[0];
457     des3_ede_sparc64_load_keys(K);
458     @@ -352,6 +357,7 @@ static int cbc3_decrypt(struct blkcipher_desc *desc,
459    
460     blkcipher_walk_init(&walk, dst, src, nbytes);
461     err = blkcipher_walk_virt(desc, &walk);
462     + desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
463    
464     K = &ctx->decrypt_expkey[0];
465     des3_ede_sparc64_load_keys(K);
466     diff --git a/arch/sparc/include/asm/hugetlb.h b/arch/sparc/include/asm/hugetlb.h
467     index 8c5eed6..9661e9b 100644
468     --- a/arch/sparc/include/asm/hugetlb.h
469     +++ b/arch/sparc/include/asm/hugetlb.h
470     @@ -61,14 +61,20 @@ static inline pte_t huge_pte_wrprotect(pte_t pte)
471     static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
472     unsigned long addr, pte_t *ptep)
473     {
474     - ptep_set_wrprotect(mm, addr, ptep);
475     + pte_t old_pte = *ptep;
476     + set_huge_pte_at(mm, addr, ptep, pte_wrprotect(old_pte));
477     }
478    
479     static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
480     unsigned long addr, pte_t *ptep,
481     pte_t pte, int dirty)
482     {
483     - return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
484     + int changed = !pte_same(*ptep, pte);
485     + if (changed) {
486     + set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
487     + flush_tlb_page(vma, addr);
488     + }
489     + return changed;
490     }
491    
492     static inline pte_t huge_ptep_get(pte_t *ptep)
493     diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
494     index 720e973f..487d9f3 100644
495     --- a/arch/x86/pci/common.c
496     +++ b/arch/x86/pci/common.c
497     @@ -433,7 +433,8 @@ static const struct dmi_system_id __devinitconst pciprobe_dmi_table[] = {
498     .callback = set_scan_all,
499     .ident = "Stratus/NEC ftServer",
500     .matches = {
501     - DMI_MATCH(DMI_SYS_VENDOR, "ftServer"),
502     + DMI_MATCH(DMI_SYS_VENDOR, "Stratus"),
503     + DMI_MATCH(DMI_PRODUCT_NAME, "ftServer"),
504     },
505     },
506     {}
507     diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
508     index 1fcb867..c441834 100644
509     --- a/drivers/acpi/scan.c
510     +++ b/drivers/acpi/scan.c
511     @@ -1227,7 +1227,7 @@ static void acpi_device_set_id(struct acpi_device *device)
512     acpi_add_id(device, ACPI_DOCK_HID);
513     else if (!acpi_ibm_smbus_match(device))
514     acpi_add_id(device, ACPI_SMBUS_IBM_HID);
515     - else if (!acpi_device_hid(device) &&
516     + else if (list_empty(&device->pnp.ids) &&
517     ACPI_IS_ROOT_DEVICE(device->parent)) {
518     acpi_add_id(device, ACPI_BUS_HID); /* \_SB, LNXSYBUS */
519     strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
520     diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
521     index 847ed55..813aa38 100644
522     --- a/drivers/acpi/sleep.c
523     +++ b/drivers/acpi/sleep.c
524     @@ -109,6 +109,180 @@ void __init acpi_old_suspend_ordering(void)
525     old_suspend_ordering = true;
526     }
527    
528     +static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
529     +{
530     + acpi_old_suspend_ordering();
531     + return 0;
532     +}
533     +
534     +static int __init init_nvs_nosave(const struct dmi_system_id *d)
535     +{
536     + acpi_nvs_nosave();
537     + return 0;
538     +}
539     +
540     +static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
541     + {
542     + .callback = init_old_suspend_ordering,
543     + .ident = "Abit KN9 (nForce4 variant)",
544     + .matches = {
545     + DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
546     + DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
547     + },
548     + },
549     + {
550     + .callback = init_old_suspend_ordering,
551     + .ident = "HP xw4600 Workstation",
552     + .matches = {
553     + DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
554     + DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
555     + },
556     + },
557     + {
558     + .callback = init_old_suspend_ordering,
559     + .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
560     + .matches = {
561     + DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
562     + DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
563     + },
564     + },
565     + {
566     + .callback = init_old_suspend_ordering,
567     + .ident = "Panasonic CF51-2L",
568     + .matches = {
569     + DMI_MATCH(DMI_BOARD_VENDOR,
570     + "Matsushita Electric Industrial Co.,Ltd."),
571     + DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
572     + },
573     + },
574     + {
575     + .callback = init_nvs_nosave,
576     + .ident = "Sony Vaio VGN-FW21E",
577     + .matches = {
578     + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
579     + DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
580     + },
581     + },
582     + {
583     + .callback = init_nvs_nosave,
584     + .ident = "Sony Vaio VPCEB17FX",
585     + .matches = {
586     + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
587     + DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
588     + },
589     + },
590     + {
591     + .callback = init_nvs_nosave,
592     + .ident = "Sony Vaio VGN-SR11M",
593     + .matches = {
594     + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
595     + DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
596     + },
597     + },
598     + {
599     + .callback = init_nvs_nosave,
600     + .ident = "Everex StepNote Series",
601     + .matches = {
602     + DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
603     + DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
604     + },
605     + },
606     + {
607     + .callback = init_nvs_nosave,
608     + .ident = "Sony Vaio VPCEB1Z1E",
609     + .matches = {
610     + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
611     + DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
612     + },
613     + },
614     + {
615     + .callback = init_nvs_nosave,
616     + .ident = "Sony Vaio VGN-NW130D",
617     + .matches = {
618     + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
619     + DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
620     + },
621     + },
622     + {
623     + .callback = init_nvs_nosave,
624     + .ident = "Sony Vaio VPCCW29FX",
625     + .matches = {
626     + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
627     + DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
628     + },
629     + },
630     + {
631     + .callback = init_nvs_nosave,
632     + .ident = "Averatec AV1020-ED2",
633     + .matches = {
634     + DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
635     + DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
636     + },
637     + },
638     + {
639     + .callback = init_old_suspend_ordering,
640     + .ident = "Asus A8N-SLI DELUXE",
641     + .matches = {
642     + DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
643     + DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
644     + },
645     + },
646     + {
647     + .callback = init_old_suspend_ordering,
648     + .ident = "Asus A8N-SLI Premium",
649     + .matches = {
650     + DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
651     + DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
652     + },
653     + },
654     + {
655     + .callback = init_nvs_nosave,
656     + .ident = "Sony Vaio VGN-SR26GN_P",
657     + .matches = {
658     + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
659     + DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
660     + },
661     + },
662     + {
663     + .callback = init_nvs_nosave,
664     + .ident = "Sony Vaio VPCEB1S1E",
665     + .matches = {
666     + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
667     + DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1S1E"),
668     + },
669     + },
670     + {
671     + .callback = init_nvs_nosave,
672     + .ident = "Sony Vaio VGN-FW520F",
673     + .matches = {
674     + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
675     + DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
676     + },
677     + },
678     + {
679     + .callback = init_nvs_nosave,
680     + .ident = "Asus K54C",
681     + .matches = {
682     + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
683     + DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
684     + },
685     + },
686     + {
687     + .callback = init_nvs_nosave,
688     + .ident = "Asus K54HR",
689     + .matches = {
690     + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
691     + DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
692     + },
693     + },
694     + {},
695     +};
696     +
697     +static void acpi_sleep_dmi_check(void)
698     +{
699     + dmi_check_system(acpisleep_dmi_table);
700     +}
701     +
702     /**
703     * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
704     */
705     @@ -224,6 +398,7 @@ static void acpi_pm_end(void)
706     }
707     #else /* !CONFIG_ACPI_SLEEP */
708     #define acpi_target_sleep_state ACPI_STATE_S0
709     +static inline void acpi_sleep_dmi_check(void) {}
710     #endif /* CONFIG_ACPI_SLEEP */
711    
712     #ifdef CONFIG_SUSPEND
713     @@ -382,175 +557,6 @@ static const struct platform_suspend_ops acpi_suspend_ops_old = {
714     .end = acpi_pm_end,
715     .recover = acpi_pm_finish,
716     };
717     -
718     -static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
719     -{
720     - old_suspend_ordering = true;
721     - return 0;
722     -}
723     -
724     -static int __init init_nvs_nosave(const struct dmi_system_id *d)
725     -{
726     - acpi_nvs_nosave();
727     - return 0;
728     -}
729     -
730     -static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
731     - {
732     - .callback = init_old_suspend_ordering,
733     - .ident = "Abit KN9 (nForce4 variant)",
734     - .matches = {
735     - DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
736     - DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
737     - },
738     - },
739     - {
740     - .callback = init_old_suspend_ordering,
741     - .ident = "HP xw4600 Workstation",
742     - .matches = {
743     - DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
744     - DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
745     - },
746     - },
747     - {
748     - .callback = init_old_suspend_ordering,
749     - .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
750     - .matches = {
751     - DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
752     - DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
753     - },
754     - },
755     - {
756     - .callback = init_old_suspend_ordering,
757     - .ident = "Panasonic CF51-2L",
758     - .matches = {
759     - DMI_MATCH(DMI_BOARD_VENDOR,
760     - "Matsushita Electric Industrial Co.,Ltd."),
761     - DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
762     - },
763     - },
764     - {
765     - .callback = init_nvs_nosave,
766     - .ident = "Sony Vaio VGN-FW21E",
767     - .matches = {
768     - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
769     - DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
770     - },
771     - },
772     - {
773     - .callback = init_nvs_nosave,
774     - .ident = "Sony Vaio VPCEB17FX",
775     - .matches = {
776     - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
777     - DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
778     - },
779     - },
780     - {
781     - .callback = init_nvs_nosave,
782     - .ident = "Sony Vaio VGN-SR11M",
783     - .matches = {
784     - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
785     - DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
786     - },
787     - },
788     - {
789     - .callback = init_nvs_nosave,
790     - .ident = "Everex StepNote Series",
791     - .matches = {
792     - DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
793     - DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
794     - },
795     - },
796     - {
797     - .callback = init_nvs_nosave,
798     - .ident = "Sony Vaio VPCEB1Z1E",
799     - .matches = {
800     - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
801     - DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
802     - },
803     - },
804     - {
805     - .callback = init_nvs_nosave,
806     - .ident = "Sony Vaio VGN-NW130D",
807     - .matches = {
808     - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
809     - DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
810     - },
811     - },
812     - {
813     - .callback = init_nvs_nosave,
814     - .ident = "Sony Vaio VPCCW29FX",
815     - .matches = {
816     - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
817     - DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
818     - },
819     - },
820     - {
821     - .callback = init_nvs_nosave,
822     - .ident = "Averatec AV1020-ED2",
823     - .matches = {
824     - DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
825     - DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
826     - },
827     - },
828     - {
829     - .callback = init_old_suspend_ordering,
830     - .ident = "Asus A8N-SLI DELUXE",
831     - .matches = {
832     - DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
833     - DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
834     - },
835     - },
836     - {
837     - .callback = init_old_suspend_ordering,
838     - .ident = "Asus A8N-SLI Premium",
839     - .matches = {
840     - DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
841     - DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
842     - },
843     - },
844     - {
845     - .callback = init_nvs_nosave,
846     - .ident = "Sony Vaio VGN-SR26GN_P",
847     - .matches = {
848     - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
849     - DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
850     - },
851     - },
852     - {
853     - .callback = init_nvs_nosave,
854     - .ident = "Sony Vaio VPCEB1S1E",
855     - .matches = {
856     - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
857     - DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1S1E"),
858     - },
859     - },
860     - {
861     - .callback = init_nvs_nosave,
862     - .ident = "Sony Vaio VGN-FW520F",
863     - .matches = {
864     - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
865     - DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
866     - },
867     - },
868     - {
869     - .callback = init_nvs_nosave,
870     - .ident = "Asus K54C",
871     - .matches = {
872     - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
873     - DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
874     - },
875     - },
876     - {
877     - .callback = init_nvs_nosave,
878     - .ident = "Asus K54HR",
879     - .matches = {
880     - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
881     - DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
882     - },
883     - },
884     - {},
885     -};
886     #endif /* CONFIG_SUSPEND */
887    
888     #ifdef CONFIG_HIBERNATION
889     @@ -881,13 +887,13 @@ int __init acpi_sleep_init(void)
890     u8 type_a, type_b;
891     #ifdef CONFIG_SUSPEND
892     int i = 0;
893     -
894     - dmi_check_system(acpisleep_dmi_table);
895     #endif
896    
897     if (acpi_disabled)
898     return 0;
899    
900     + acpi_sleep_dmi_check();
901     +
902     sleep_states[ACPI_STATE_S0] = 1;
903     printk(KERN_INFO PREFIX "(supports S0");
904    
905     diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
906     index 5b0ba3f..ef01ac0 100644
907     --- a/drivers/ata/libata-acpi.c
908     +++ b/drivers/ata/libata-acpi.c
909     @@ -76,6 +76,9 @@ acpi_handle ata_dev_acpi_handle(struct ata_device *dev)
910     acpi_integer adr;
911     struct ata_port *ap = dev->link->ap;
912    
913     + if (dev->flags & ATA_DFLAG_ACPI_DISABLED)
914     + return NULL;
915     +
916     if (ap->flags & ATA_FLAG_ACPI_SATA) {
917     if (!sata_pmp_attached(ap))
918     adr = SATA_ADR(ap->port_no, NO_PORT_MULT);
919     @@ -945,6 +948,7 @@ int ata_acpi_on_devcfg(struct ata_device *dev)
920     return rc;
921     }
922    
923     + dev->flags |= ATA_DFLAG_ACPI_DISABLED;
924     ata_dev_warn(dev, "ACPI: failed the second time, disabled\n");
925    
926     /* We can safely continue if no _GTF command has been executed
927     diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
928     index 9851093..1853a45 100644
929     --- a/drivers/atm/solos-pci.c
930     +++ b/drivers/atm/solos-pci.c
931     @@ -967,10 +967,11 @@ static uint32_t fpga_tx(struct solos_card *card)
932     for (port = 0; tx_pending; tx_pending >>= 1, port++) {
933     if (tx_pending & 1) {
934     struct sk_buff *oldskb = card->tx_skb[port];
935     - if (oldskb)
936     + if (oldskb) {
937     pci_unmap_single(card->dev, SKB_CB(oldskb)->dma_addr,
938     oldskb->len, PCI_DMA_TODEVICE);
939     -
940     + card->tx_skb[port] = NULL;
941     + }
942     spin_lock(&card->tx_queue_lock);
943     skb = skb_dequeue(&card->tx_queue[port]);
944     if (!skb)
945     diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
946     index 8945f4e..be5f7aa 100644
947     --- a/drivers/base/firmware_class.c
948     +++ b/drivers/base/firmware_class.c
949     @@ -143,7 +143,7 @@ struct fw_cache_entry {
950     };
951    
952     struct firmware_priv {
953     - struct timer_list timeout;
954     + struct delayed_work timeout_work;
955     bool nowait;
956     struct device dev;
957     struct firmware_buf *buf;
958     @@ -246,7 +246,6 @@ static void __fw_free_buf(struct kref *ref)
959     __func__, buf->fw_id, buf, buf->data,
960     (unsigned int)buf->size);
961    
962     - spin_lock(&fwc->lock);
963     list_del(&buf->list);
964     spin_unlock(&fwc->lock);
965    
966     @@ -263,7 +262,10 @@ static void __fw_free_buf(struct kref *ref)
967    
968     static void fw_free_buf(struct firmware_buf *buf)
969     {
970     - kref_put(&buf->ref, __fw_free_buf);
971     + struct firmware_cache *fwc = buf->fwc;
972     + spin_lock(&fwc->lock);
973     + if (!kref_put(&buf->ref, __fw_free_buf))
974     + spin_unlock(&fwc->lock);
975     }
976    
977     /* direct firmware loading support */
978     @@ -667,11 +669,18 @@ static struct bin_attribute firmware_attr_data = {
979     .write = firmware_data_write,
980     };
981    
982     -static void firmware_class_timeout(u_long data)
983     +static void firmware_class_timeout_work(struct work_struct *work)
984     {
985     - struct firmware_priv *fw_priv = (struct firmware_priv *) data;
986     + struct firmware_priv *fw_priv = container_of(work,
987     + struct firmware_priv, timeout_work.work);
988    
989     + mutex_lock(&fw_lock);
990     + if (test_bit(FW_STATUS_DONE, &(fw_priv->buf->status))) {
991     + mutex_unlock(&fw_lock);
992     + return;
993     + }
994     fw_load_abort(fw_priv);
995     + mutex_unlock(&fw_lock);
996     }
997    
998     static struct firmware_priv *
999     @@ -690,8 +699,8 @@ fw_create_instance(struct firmware *firmware, const char *fw_name,
1000    
1001     fw_priv->nowait = nowait;
1002     fw_priv->fw = firmware;
1003     - setup_timer(&fw_priv->timeout,
1004     - firmware_class_timeout, (u_long) fw_priv);
1005     + INIT_DELAYED_WORK(&fw_priv->timeout_work,
1006     + firmware_class_timeout_work);
1007    
1008     f_dev = &fw_priv->dev;
1009    
1010     @@ -858,7 +867,9 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent,
1011     dev_dbg(f_dev->parent, "firmware: direct-loading"
1012     " firmware %s\n", buf->fw_id);
1013    
1014     + mutex_lock(&fw_lock);
1015     set_bit(FW_STATUS_DONE, &buf->status);
1016     + mutex_unlock(&fw_lock);
1017     complete_all(&buf->completion);
1018     direct_load = 1;
1019     goto handle_fw;
1020     @@ -894,15 +905,14 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent,
1021     dev_set_uevent_suppress(f_dev, false);
1022     dev_dbg(f_dev, "firmware: requesting %s\n", buf->fw_id);
1023     if (timeout != MAX_SCHEDULE_TIMEOUT)
1024     - mod_timer(&fw_priv->timeout,
1025     - round_jiffies_up(jiffies + timeout));
1026     + schedule_delayed_work(&fw_priv->timeout_work, timeout);
1027    
1028     kobject_uevent(&fw_priv->dev.kobj, KOBJ_ADD);
1029     }
1030    
1031     wait_for_completion(&buf->completion);
1032    
1033     - del_timer_sync(&fw_priv->timeout);
1034     + cancel_delayed_work_sync(&fw_priv->timeout_work);
1035    
1036     handle_fw:
1037     mutex_lock(&fw_lock);
1038     diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
1039     index ee82f2f..a1d4ede 100644
1040     --- a/drivers/bluetooth/btusb.c
1041     +++ b/drivers/bluetooth/btusb.c
1042     @@ -96,6 +96,7 @@ static struct usb_device_id btusb_table[] = {
1043     { USB_DEVICE(0x0c10, 0x0000) },
1044    
1045     /* Broadcom BCM20702A0 */
1046     + { USB_DEVICE(0x0b05, 0x17b5) },
1047     { USB_DEVICE(0x04ca, 0x2003) },
1048     { USB_DEVICE(0x0489, 0xe042) },
1049     { USB_DEVICE(0x413c, 0x8197) },
1050     diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
1051     index f4109fd..52146db 100644
1052     --- a/drivers/hid/hid-core.c
1053     +++ b/drivers/hid/hid-core.c
1054     @@ -1538,6 +1538,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1055     { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1056     { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1057     { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1058     + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) },
1059     { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
1060     { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1061     { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1062     diff --git a/drivers/input/joystick/walkera0701.c b/drivers/input/joystick/walkera0701.c
1063     index 4dfa1ee..f8f892b 100644
1064     --- a/drivers/input/joystick/walkera0701.c
1065     +++ b/drivers/input/joystick/walkera0701.c
1066     @@ -196,6 +196,7 @@ static void walkera0701_close(struct input_dev *dev)
1067     struct walkera_dev *w = input_get_drvdata(dev);
1068    
1069     parport_disable_irq(w->parport);
1070     + hrtimer_cancel(&w->timer);
1071     }
1072    
1073     static int walkera0701_connect(struct walkera_dev *w, int parport)
1074     @@ -224,6 +225,9 @@ static int walkera0701_connect(struct walkera_dev *w, int parport)
1075     if (parport_claim(w->pardevice))
1076     goto init_err1;
1077    
1078     + hrtimer_init(&w->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1079     + w->timer.function = timer_handler;
1080     +
1081     w->input_dev = input_allocate_device();
1082     if (!w->input_dev)
1083     goto init_err2;
1084     @@ -254,8 +258,6 @@ static int walkera0701_connect(struct walkera_dev *w, int parport)
1085     if (err)
1086     goto init_err3;
1087    
1088     - hrtimer_init(&w->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1089     - w->timer.function = timer_handler;
1090     return 0;
1091    
1092     init_err3:
1093     @@ -271,7 +273,6 @@ static int walkera0701_connect(struct walkera_dev *w, int parport)
1094    
1095     static void walkera0701_disconnect(struct walkera_dev *w)
1096     {
1097     - hrtimer_cancel(&w->timer);
1098     input_unregister_device(w->input_dev);
1099     parport_release(w->pardevice);
1100     parport_unregister_device(w->pardevice);
1101     diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
1102     index 6a68041..59347d0 100644
1103     --- a/drivers/input/keyboard/gpio_keys.c
1104     +++ b/drivers/input/keyboard/gpio_keys.c
1105     @@ -587,6 +587,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
1106    
1107     i = 0;
1108     for_each_child_of_node(node, pp) {
1109     + int gpio;
1110     enum of_gpio_flags flags;
1111    
1112     if (!of_find_property(pp, "gpios", NULL)) {
1113     @@ -595,9 +596,19 @@ gpio_keys_get_devtree_pdata(struct device *dev)
1114     continue;
1115     }
1116    
1117     + gpio = of_get_gpio_flags(pp, 0, &flags);
1118     + if (gpio < 0) {
1119     + error = gpio;
1120     + if (error != -EPROBE_DEFER)
1121     + dev_err(dev,
1122     + "Failed to get gpio flags, error: %d\n",
1123     + error);
1124     + goto err_free_pdata;
1125     + }
1126     +
1127     button = &pdata->buttons[i++];
1128    
1129     - button->gpio = of_get_gpio_flags(pp, 0, &flags);
1130     + button->gpio = gpio;
1131     button->active_low = flags & OF_GPIO_ACTIVE_LOW;
1132    
1133     if (of_property_read_u32(pp, "linux,code", &button->code)) {
1134     diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
1135     index f2142de..8490930 100644
1136     --- a/drivers/input/keyboard/gpio_keys_polled.c
1137     +++ b/drivers/input/keyboard/gpio_keys_polled.c
1138     @@ -136,6 +136,7 @@ gpio_keys_polled_get_devtree_pdata(struct device *dev)
1139    
1140     i = 0;
1141     for_each_child_of_node(node, pp) {
1142     + int gpio;
1143     enum of_gpio_flags flags;
1144    
1145     if (!of_find_property(pp, "gpios", NULL)) {
1146     @@ -144,9 +145,19 @@ gpio_keys_polled_get_devtree_pdata(struct device *dev)
1147     continue;
1148     }
1149    
1150     + gpio = of_get_gpio_flags(pp, 0, &flags);
1151     + if (gpio < 0) {
1152     + error = gpio;
1153     + if (error != -EPROBE_DEFER)
1154     + dev_err(dev,
1155     + "Failed to get gpio flags, error: %d\n",
1156     + error);
1157     + goto err_free_pdata;
1158     + }
1159     +
1160     button = &pdata->buttons[i++];
1161    
1162     - button->gpio = of_get_gpio_flags(pp, 0, &flags);
1163     + button->gpio = gpio;
1164     button->active_low = flags & OF_GPIO_ACTIVE_LOW;
1165    
1166     if (of_property_read_u32(pp, "linux,code", &button->code)) {
1167     diff --git a/drivers/input/mouse/sentelic.c b/drivers/input/mouse/sentelic.c
1168     index e582922..cc7e0d4 100644
1169     --- a/drivers/input/mouse/sentelic.c
1170     +++ b/drivers/input/mouse/sentelic.c
1171     @@ -791,7 +791,7 @@ static psmouse_ret_t fsp_process_byte(struct psmouse *psmouse)
1172     fsp_set_slot(dev, 0, fgrs > 0, abs_x, abs_y);
1173     fsp_set_slot(dev, 1, false, 0, 0);
1174     }
1175     - if (fgrs > 0) {
1176     + if (fgrs == 1 || (fgrs == 2 && !(packet[0] & FSP_PB0_MFMC_FGR2))) {
1177     input_report_abs(dev, ABS_X, abs_x);
1178     input_report_abs(dev, ABS_Y, abs_y);
1179     }
1180     diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
1181     index d6cc77a..5f306f7 100644
1182     --- a/drivers/input/serio/i8042-x86ia64io.h
1183     +++ b/drivers/input/serio/i8042-x86ia64io.h
1184     @@ -921,6 +921,7 @@ static int __init i8042_platform_init(void)
1185     int retval;
1186    
1187     #ifdef CONFIG_X86
1188     + u8 a20_on = 0xdf;
1189     /* Just return if pre-detection shows no i8042 controller exist */
1190     if (!x86_platform.i8042_detect())
1191     return -ENODEV;
1192     @@ -960,6 +961,14 @@ static int __init i8042_platform_init(void)
1193    
1194     if (dmi_check_system(i8042_dmi_dritek_table))
1195     i8042_dritek = true;
1196     +
1197     + /*
1198     + * A20 was already enabled during early kernel init. But some buggy
1199     + * BIOSes (in MSI Laptops) require A20 to be enabled using 8042 to
1200     + * resume from S3. So we do it here and hope that nothing breaks.
1201     + */
1202     + i8042_command(&a20_on, 0x10d1);
1203     + i8042_command(NULL, 0x00ff); /* Null command for SMM firmware */
1204     #endif /* CONFIG_X86 */
1205    
1206     return retval;
1207     diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
1208     index 0a67031..c2bfe92 100644
1209     --- a/drivers/input/tablet/wacom_wac.c
1210     +++ b/drivers/input/tablet/wacom_wac.c
1211     @@ -2034,7 +2034,8 @@ static const struct wacom_features wacom_features_0xD1 =
1212     .touch_max = 2 };
1213     static const struct wacom_features wacom_features_0xD2 =
1214     { "Wacom Bamboo Craft", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
1215     - 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1216     + 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1217     + .touch_max = 2 };
1218     static const struct wacom_features wacom_features_0xD3 =
1219     { "Wacom Bamboo 2FG 6x8", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
1220     31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1221     diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
1222     index 8d082b4..d971817 100644
1223     --- a/drivers/misc/sgi-xp/xpc_main.c
1224     +++ b/drivers/misc/sgi-xp/xpc_main.c
1225     @@ -53,6 +53,10 @@
1226     #include <linux/kthread.h>
1227     #include "xpc.h"
1228    
1229     +#ifdef CONFIG_X86_64
1230     +#include <asm/traps.h>
1231     +#endif
1232     +
1233     /* define two XPC debug device structures to be used with dev_dbg() et al */
1234    
1235     struct device_driver xpc_dbg_name = {
1236     @@ -1079,6 +1083,9 @@ xpc_system_reboot(struct notifier_block *nb, unsigned long event, void *unused)
1237     return NOTIFY_DONE;
1238     }
1239    
1240     +/* Used to only allow one cpu to complete disconnect */
1241     +static unsigned int xpc_die_disconnecting;
1242     +
1243     /*
1244     * Notify other partitions to deactivate from us by first disengaging from all
1245     * references to our memory.
1246     @@ -1092,6 +1099,9 @@ xpc_die_deactivate(void)
1247     long keep_waiting;
1248     long wait_to_print;
1249    
1250     + if (cmpxchg(&xpc_die_disconnecting, 0, 1))
1251     + return;
1252     +
1253     /* keep xpc_hb_checker thread from doing anything (just in case) */
1254     xpc_exiting = 1;
1255    
1256     @@ -1159,7 +1169,7 @@ xpc_die_deactivate(void)
1257     * about the lack of a heartbeat.
1258     */
1259     static int
1260     -xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
1261     +xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
1262     {
1263     #ifdef CONFIG_IA64 /* !!! temporary kludge */
1264     switch (event) {
1265     @@ -1191,7 +1201,27 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
1266     break;
1267     }
1268     #else
1269     - xpc_die_deactivate();
1270     + struct die_args *die_args = _die_args;
1271     +
1272     + switch (event) {
1273     + case DIE_TRAP:
1274     + if (die_args->trapnr == X86_TRAP_DF)
1275     + xpc_die_deactivate();
1276     +
1277     + if (((die_args->trapnr == X86_TRAP_MF) ||
1278     + (die_args->trapnr == X86_TRAP_XF)) &&
1279     + !user_mode_vm(die_args->regs))
1280     + xpc_die_deactivate();
1281     +
1282     + break;
1283     + case DIE_INT3:
1284     + case DIE_DEBUG:
1285     + break;
1286     + case DIE_OOPS:
1287     + case DIE_GPF:
1288     + default:
1289     + xpc_die_deactivate();
1290     + }
1291     #endif
1292    
1293     return NOTIFY_DONE;
1294     diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
1295     index 963e2cc..8233e5e 100644
1296     --- a/drivers/net/can/dev.c
1297     +++ b/drivers/net/can/dev.c
1298     @@ -609,8 +609,7 @@ void close_candev(struct net_device *dev)
1299     {
1300     struct can_priv *priv = netdev_priv(dev);
1301    
1302     - if (del_timer_sync(&priv->restart_timer))
1303     - dev_put(dev);
1304     + del_timer_sync(&priv->restart_timer);
1305     can_flush_echo_skb(dev);
1306     }
1307     EXPORT_SYMBOL_GPL(close_candev);
1308     diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
1309     index d012982..c4c593d 100644
1310     --- a/drivers/net/usb/cdc_ether.c
1311     +++ b/drivers/net/usb/cdc_ether.c
1312     @@ -487,6 +487,7 @@ static const struct driver_info wwan_info = {
1313     #define HUAWEI_VENDOR_ID 0x12D1
1314     #define NOVATEL_VENDOR_ID 0x1410
1315     #define ZTE_VENDOR_ID 0x19D2
1316     +#define DELL_VENDOR_ID 0x413C
1317    
1318     static const struct usb_device_id products [] = {
1319     /*
1320     @@ -618,6 +619,20 @@ static const struct usb_device_id products [] = {
1321     .driver_info = 0,
1322     },
1323    
1324     +/* Dell Wireless 5800 (Novatel E362) - handled by qmi_wwan */
1325     +{
1326     + USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x8195, USB_CLASS_COMM,
1327     + USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
1328     + .driver_info = 0,
1329     +},
1330     +
1331     +/* Dell Wireless 5800 (Novatel E362) - handled by qmi_wwan */
1332     +{
1333     + USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x8196, USB_CLASS_COMM,
1334     + USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
1335     + .driver_info = 0,
1336     +},
1337     +
1338     /*
1339     * WHITELIST!!!
1340     *
1341     diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
1342     index 1ea91f4..9b950f5 100644
1343     --- a/drivers/net/usb/qmi_wwan.c
1344     +++ b/drivers/net/usb/qmi_wwan.c
1345     @@ -383,6 +383,20 @@ static const struct usb_device_id products[] = {
1346     USB_CDC_PROTO_NONE),
1347     .driver_info = (unsigned long)&qmi_wwan_info,
1348     },
1349     + { /* Dell Wireless 5800 (Novatel E362) */
1350     + USB_DEVICE_AND_INTERFACE_INFO(0x413C, 0x8195,
1351     + USB_CLASS_COMM,
1352     + USB_CDC_SUBCLASS_ETHERNET,
1353     + USB_CDC_PROTO_NONE),
1354     + .driver_info = (unsigned long)&qmi_wwan_info,
1355     + },
1356     + { /* Dell Wireless 5800 V2 (Novatel E362) */
1357     + USB_DEVICE_AND_INTERFACE_INFO(0x413C, 0x8196,
1358     + USB_CLASS_COMM,
1359     + USB_CDC_SUBCLASS_ETHERNET,
1360     + USB_CDC_PROTO_NONE),
1361     + .driver_info = (unsigned long)&qmi_wwan_info,
1362     + },
1363    
1364     /* 3. Combined interface devices matching on interface number */
1365     {QMI_FIXED_INTF(0x12d1, 0x140c, 1)}, /* Huawei E173 */
1366     diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c
1367     index 777cd74..38bc5a7 100644
1368     --- a/drivers/net/wireless/b43/dma.c
1369     +++ b/drivers/net/wireless/b43/dma.c
1370     @@ -409,7 +409,10 @@ static inline
1371     struct b43_dmadesc_meta *meta)
1372     {
1373     if (meta->skb) {
1374     - dev_kfree_skb_any(meta->skb);
1375     + if (ring->tx)
1376     + ieee80211_free_txskb(ring->dev->wl->hw, meta->skb);
1377     + else
1378     + dev_kfree_skb_any(meta->skb);
1379     meta->skb = NULL;
1380     }
1381     }
1382     @@ -1454,7 +1457,7 @@ int b43_dma_tx(struct b43_wldev *dev, struct sk_buff *skb)
1383     if (unlikely(err == -ENOKEY)) {
1384     /* Drop this packet, as we don't have the encryption key
1385     * anymore and must not transmit it unencrypted. */
1386     - dev_kfree_skb_any(skb);
1387     + ieee80211_free_txskb(dev->wl->hw, skb);
1388     err = 0;
1389     goto out;
1390     }
1391     diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
1392     index c5a99c8..2911e20 100644
1393     --- a/drivers/net/wireless/b43/main.c
1394     +++ b/drivers/net/wireless/b43/main.c
1395     @@ -3397,7 +3397,7 @@ static void b43_tx_work(struct work_struct *work)
1396     break;
1397     }
1398     if (unlikely(err))
1399     - dev_kfree_skb(skb); /* Drop it */
1400     + ieee80211_free_txskb(wl->hw, skb);
1401     err = 0;
1402     }
1403    
1404     @@ -3419,7 +3419,7 @@ static void b43_op_tx(struct ieee80211_hw *hw,
1405    
1406     if (unlikely(skb->len < 2 + 2 + 6)) {
1407     /* Too short, this can't be a valid frame. */
1408     - dev_kfree_skb_any(skb);
1409     + ieee80211_free_txskb(hw, skb);
1410     return;
1411     }
1412     B43_WARN_ON(skb_shinfo(skb)->nr_frags);
1413     @@ -4229,8 +4229,12 @@ redo:
1414    
1415     /* Drain all TX queues. */
1416     for (queue_num = 0; queue_num < B43_QOS_QUEUE_NUM; queue_num++) {
1417     - while (skb_queue_len(&wl->tx_queue[queue_num]))
1418     - dev_kfree_skb(skb_dequeue(&wl->tx_queue[queue_num]));
1419     + while (skb_queue_len(&wl->tx_queue[queue_num])) {
1420     + struct sk_buff *skb;
1421     +
1422     + skb = skb_dequeue(&wl->tx_queue[queue_num]);
1423     + ieee80211_free_txskb(wl->hw, skb);
1424     + }
1425     }
1426    
1427     b43_mac_suspend(dev);
1428     diff --git a/drivers/net/wireless/b43/pio.c b/drivers/net/wireless/b43/pio.c
1429     index 3533ab8..a73ff8c 100644
1430     --- a/drivers/net/wireless/b43/pio.c
1431     +++ b/drivers/net/wireless/b43/pio.c
1432     @@ -196,7 +196,7 @@ static void b43_pio_cancel_tx_packets(struct b43_pio_txqueue *q)
1433     for (i = 0; i < ARRAY_SIZE(q->packets); i++) {
1434     pack = &(q->packets[i]);
1435     if (pack->skb) {
1436     - dev_kfree_skb_any(pack->skb);
1437     + ieee80211_free_txskb(q->dev->wl->hw, pack->skb);
1438     pack->skb = NULL;
1439     }
1440     }
1441     @@ -552,7 +552,7 @@ int b43_pio_tx(struct b43_wldev *dev, struct sk_buff *skb)
1442     if (unlikely(err == -ENOKEY)) {
1443     /* Drop this packet, as we don't have the encryption key
1444     * anymore and must not transmit it unencrypted. */
1445     - dev_kfree_skb_any(skb);
1446     + ieee80211_free_txskb(dev->wl->hw, skb);
1447     err = 0;
1448     goto out;
1449     }
1450     diff --git a/drivers/net/wireless/b43legacy/b43legacy.h b/drivers/net/wireless/b43legacy/b43legacy.h
1451     index a29da67..482476f 100644
1452     --- a/drivers/net/wireless/b43legacy/b43legacy.h
1453     +++ b/drivers/net/wireless/b43legacy/b43legacy.h
1454     @@ -13,6 +13,7 @@
1455    
1456     #include <linux/ssb/ssb.h>
1457     #include <linux/ssb/ssb_driver_chipcommon.h>
1458     +#include <linux/completion.h>
1459    
1460     #include <net/mac80211.h>
1461    
1462     @@ -733,6 +734,10 @@ struct b43legacy_wldev {
1463    
1464     /* Firmware data */
1465     struct b43legacy_firmware fw;
1466     + const struct firmware *fwp; /* needed to pass fw pointer */
1467     +
1468     + /* completion struct for firmware loading */
1469     + struct completion fw_load_complete;
1470    
1471     /* Devicelist in struct b43legacy_wl (all 802.11 cores) */
1472     struct list_head list;
1473     diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
1474     index 18e208e..8c3f70e 100644
1475     --- a/drivers/net/wireless/b43legacy/main.c
1476     +++ b/drivers/net/wireless/b43legacy/main.c
1477     @@ -1513,9 +1513,17 @@ static void b43legacy_print_fw_helptext(struct b43legacy_wl *wl)
1478     "and download the correct firmware (version 3).\n");
1479     }
1480    
1481     +static void b43legacy_fw_cb(const struct firmware *firmware, void *context)
1482     +{
1483     + struct b43legacy_wldev *dev = context;
1484     +
1485     + dev->fwp = firmware;
1486     + complete(&dev->fw_load_complete);
1487     +}
1488     +
1489     static int do_request_fw(struct b43legacy_wldev *dev,
1490     const char *name,
1491     - const struct firmware **fw)
1492     + const struct firmware **fw, bool async)
1493     {
1494     char path[sizeof(modparam_fwpostfix) + 32];
1495     struct b43legacy_fw_header *hdr;
1496     @@ -1528,7 +1536,24 @@ static int do_request_fw(struct b43legacy_wldev *dev,
1497     snprintf(path, ARRAY_SIZE(path),
1498     "b43legacy%s/%s.fw",
1499     modparam_fwpostfix, name);
1500     - err = request_firmware(fw, path, dev->dev->dev);
1501     + b43legacyinfo(dev->wl, "Loading firmware %s\n", path);
1502     + if (async) {
1503     + init_completion(&dev->fw_load_complete);
1504     + err = request_firmware_nowait(THIS_MODULE, 1, path,
1505     + dev->dev->dev, GFP_KERNEL,
1506     + dev, b43legacy_fw_cb);
1507     + if (err) {
1508     + b43legacyerr(dev->wl, "Unable to load firmware\n");
1509     + return err;
1510     + }
1511     + /* stall here until fw ready */
1512     + wait_for_completion(&dev->fw_load_complete);
1513     + if (!dev->fwp)
1514     + err = -EINVAL;
1515     + *fw = dev->fwp;
1516     + } else {
1517     + err = request_firmware(fw, path, dev->dev->dev);
1518     + }
1519     if (err) {
1520     b43legacyerr(dev->wl, "Firmware file \"%s\" not found "
1521     "or load failed.\n", path);
1522     @@ -1580,7 +1605,7 @@ static void b43legacy_request_firmware(struct work_struct *work)
1523     filename = "ucode4";
1524     else
1525     filename = "ucode5";
1526     - err = do_request_fw(dev, filename, &fw->ucode);
1527     + err = do_request_fw(dev, filename, &fw->ucode, true);
1528     if (err)
1529     goto err_load;
1530     }
1531     @@ -1589,7 +1614,7 @@ static void b43legacy_request_firmware(struct work_struct *work)
1532     filename = "pcm4";
1533     else
1534     filename = "pcm5";
1535     - err = do_request_fw(dev, filename, &fw->pcm);
1536     + err = do_request_fw(dev, filename, &fw->pcm, false);
1537     if (err)
1538     goto err_load;
1539     }
1540     @@ -1607,7 +1632,7 @@ static void b43legacy_request_firmware(struct work_struct *work)
1541     default:
1542     goto err_no_initvals;
1543     }
1544     - err = do_request_fw(dev, filename, &fw->initvals);
1545     + err = do_request_fw(dev, filename, &fw->initvals, false);
1546     if (err)
1547     goto err_load;
1548     }
1549     @@ -1627,7 +1652,7 @@ static void b43legacy_request_firmware(struct work_struct *work)
1550     default:
1551     goto err_no_initvals;
1552     }
1553     - err = do_request_fw(dev, filename, &fw->initvals_band);
1554     + err = do_request_fw(dev, filename, &fw->initvals_band, false);
1555     if (err)
1556     goto err_load;
1557     }
1558     diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
1559     index effb044..4191294 100644
1560     --- a/drivers/net/wireless/p54/p54usb.c
1561     +++ b/drivers/net/wireless/p54/p54usb.c
1562     @@ -47,6 +47,7 @@ static struct usb_device_id p54u_table[] = {
1563     {USB_DEVICE(0x0411, 0x0050)}, /* Buffalo WLI2-USB2-G54 */
1564     {USB_DEVICE(0x045e, 0x00c2)}, /* Microsoft MN-710 */
1565     {USB_DEVICE(0x0506, 0x0a11)}, /* 3COM 3CRWE254G72 */
1566     + {USB_DEVICE(0x0675, 0x0530)}, /* DrayTek Vigor 530 */
1567     {USB_DEVICE(0x06b9, 0x0120)}, /* Thomson SpeedTouch 120g */
1568     {USB_DEVICE(0x0707, 0xee06)}, /* SMC 2862W-G */
1569     {USB_DEVICE(0x07aa, 0x001c)}, /* Corega CG-WLUSB2GT */
1570     @@ -82,6 +83,8 @@ static struct usb_device_id p54u_table[] = {
1571     {USB_DEVICE(0x06a9, 0x000e)}, /* Westell 802.11g USB (A90-211WG-01) */
1572     {USB_DEVICE(0x06b9, 0x0121)}, /* Thomson SpeedTouch 121g */
1573     {USB_DEVICE(0x0707, 0xee13)}, /* SMC 2862W-G version 2 */
1574     + {USB_DEVICE(0x0803, 0x4310)}, /* Zoom 4410a */
1575     + {USB_DEVICE(0x083a, 0x4503)}, /* T-Com Sinus 154 data II */
1576     {USB_DEVICE(0x083a, 0x4521)}, /* Siemens Gigaset USB Adapter 54 version 2 */
1577     {USB_DEVICE(0x083a, 0xc501)}, /* Zoom Wireless-G 4410 */
1578     {USB_DEVICE(0x083a, 0xf503)}, /* Accton FD7050E ver 1010ec */
1579     @@ -101,6 +104,7 @@ static struct usb_device_id p54u_table[] = {
1580     {USB_DEVICE(0x13B1, 0x000C)}, /* Linksys WUSB54AG */
1581     {USB_DEVICE(0x1413, 0x5400)}, /* Telsey 802.11g USB2.0 Adapter */
1582     {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */
1583     + /* {USB_DEVICE(0x15a9, 0x0002)}, * Also SparkLAN WL-682 with 3887 */
1584     {USB_DEVICE(0x1668, 0x1050)}, /* Actiontec 802UIG-1 */
1585     {USB_DEVICE(0x1740, 0x1000)}, /* Senao NUB-350 */
1586     {USB_DEVICE(0x2001, 0x3704)}, /* DLink DWL-G122 rev A2 */
1587     diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c
1588     index e3ea4b3..46ccbf7 100644
1589     --- a/drivers/net/wireless/rtlwifi/usb.c
1590     +++ b/drivers/net/wireless/rtlwifi/usb.c
1591     @@ -210,17 +210,16 @@ static void _usb_writeN_sync(struct rtl_priv *rtlpriv, u32 addr, void *data,
1592     u16 index = REALTEK_USB_VENQT_CMD_IDX;
1593     int pipe = usb_sndctrlpipe(udev, 0); /* write_out */
1594     u8 *buffer;
1595     - dma_addr_t dma_addr;
1596    
1597     - wvalue = (u16)(addr&0x0000ffff);
1598     - buffer = usb_alloc_coherent(udev, (size_t)len, GFP_ATOMIC, &dma_addr);
1599     + wvalue = (u16)(addr & 0x0000ffff);
1600     + buffer = kmalloc(len, GFP_ATOMIC);
1601     if (!buffer)
1602     return;
1603     memcpy(buffer, data, len);
1604     usb_control_msg(udev, pipe, request, reqtype, wvalue,
1605     index, buffer, len, 50);
1606    
1607     - usb_free_coherent(udev, (size_t)len, buffer, dma_addr);
1608     + kfree(buffer);
1609     }
1610    
1611     static void _rtl_usb_io_handler_init(struct device *dev,
1612     diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
1613     index 6c94fc9..6c66c5b 100644
1614     --- a/drivers/pci/pci-driver.c
1615     +++ b/drivers/pci/pci-driver.c
1616     @@ -256,31 +256,26 @@ struct drv_dev_and_id {
1617     static long local_pci_probe(void *_ddi)
1618     {
1619     struct drv_dev_and_id *ddi = _ddi;
1620     - struct device *dev = &ddi->dev->dev;
1621     - struct device *parent = dev->parent;
1622     + struct pci_dev *pci_dev = ddi->dev;
1623     + struct pci_driver *pci_drv = ddi->drv;
1624     + struct device *dev = &pci_dev->dev;
1625     int rc;
1626    
1627     - /* The parent bridge must be in active state when probing */
1628     - if (parent)
1629     - pm_runtime_get_sync(parent);
1630     - /* Unbound PCI devices are always set to disabled and suspended.
1631     - * During probe, the device is set to enabled and active and the
1632     - * usage count is incremented. If the driver supports runtime PM,
1633     - * it should call pm_runtime_put_noidle() in its probe routine and
1634     - * pm_runtime_get_noresume() in its remove routine.
1635     + /*
1636     + * Unbound PCI devices are always put in D0, regardless of
1637     + * runtime PM status. During probe, the device is set to
1638     + * active and the usage count is incremented. If the driver
1639     + * supports runtime PM, it should call pm_runtime_put_noidle()
1640     + * in its probe routine and pm_runtime_get_noresume() in its
1641     + * remove routine.
1642     */
1643     - pm_runtime_get_noresume(dev);
1644     - pm_runtime_set_active(dev);
1645     - pm_runtime_enable(dev);
1646     -
1647     - rc = ddi->drv->probe(ddi->dev, ddi->id);
1648     + pm_runtime_get_sync(dev);
1649     + pci_dev->driver = pci_drv;
1650     + rc = pci_drv->probe(pci_dev, ddi->id);
1651     if (rc) {
1652     - pm_runtime_disable(dev);
1653     - pm_runtime_set_suspended(dev);
1654     - pm_runtime_put_noidle(dev);
1655     + pci_dev->driver = NULL;
1656     + pm_runtime_put_sync(dev);
1657     }
1658     - if (parent)
1659     - pm_runtime_put(parent);
1660     return rc;
1661     }
1662    
1663     @@ -330,10 +325,8 @@ __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
1664     id = pci_match_device(drv, pci_dev);
1665     if (id)
1666     error = pci_call_probe(drv, pci_dev, id);
1667     - if (error >= 0) {
1668     - pci_dev->driver = drv;
1669     + if (error >= 0)
1670     error = 0;
1671     - }
1672     }
1673     return error;
1674     }
1675     @@ -369,9 +362,7 @@ static int pci_device_remove(struct device * dev)
1676     }
1677    
1678     /* Undo the runtime PM settings in local_pci_probe() */
1679     - pm_runtime_disable(dev);
1680     - pm_runtime_set_suspended(dev);
1681     - pm_runtime_put_noidle(dev);
1682     + pm_runtime_put_sync(dev);
1683    
1684     /*
1685     * If the device is still on, set the power state as "unknown",
1686     @@ -994,6 +985,13 @@ static int pci_pm_runtime_suspend(struct device *dev)
1687     pci_power_t prev = pci_dev->current_state;
1688     int error;
1689    
1690     + /*
1691     + * If pci_dev->driver is not set (unbound), the device should
1692     + * always remain in D0 regardless of the runtime PM status
1693     + */
1694     + if (!pci_dev->driver)
1695     + return 0;
1696     +
1697     if (!pm || !pm->runtime_suspend)
1698     return -ENOSYS;
1699    
1700     @@ -1029,6 +1027,13 @@ static int pci_pm_runtime_resume(struct device *dev)
1701     struct pci_dev *pci_dev = to_pci_dev(dev);
1702     const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1703    
1704     + /*
1705     + * If pci_dev->driver is not set (unbound), the device should
1706     + * always remain in D0 regardless of the runtime PM status
1707     + */
1708     + if (!pci_dev->driver)
1709     + return 0;
1710     +
1711     if (!pm || !pm->runtime_resume)
1712     return -ENOSYS;
1713    
1714     @@ -1046,8 +1051,16 @@ static int pci_pm_runtime_resume(struct device *dev)
1715    
1716     static int pci_pm_runtime_idle(struct device *dev)
1717     {
1718     + struct pci_dev *pci_dev = to_pci_dev(dev);
1719     const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1720    
1721     + /*
1722     + * If pci_dev->driver is not set (unbound), the device should
1723     + * always remain in D0 regardless of the runtime PM status
1724     + */
1725     + if (!pci_dev->driver)
1726     + goto out;
1727     +
1728     if (!pm)
1729     return -ENOSYS;
1730    
1731     @@ -1057,8 +1070,8 @@ static int pci_pm_runtime_idle(struct device *dev)
1732     return ret;
1733     }
1734    
1735     +out:
1736     pm_runtime_suspend(dev);
1737     -
1738     return 0;
1739     }
1740    
1741     diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
1742     index aabf647..8e06adb 100644
1743     --- a/drivers/pci/pci.c
1744     +++ b/drivers/pci/pci.c
1745     @@ -1900,6 +1900,8 @@ void pci_pm_init(struct pci_dev *dev)
1746     u16 pmc;
1747    
1748     pm_runtime_forbid(&dev->dev);
1749     + pm_runtime_set_active(&dev->dev);
1750     + pm_runtime_enable(&dev->dev);
1751     device_enable_async_suspend(&dev->dev);
1752     dev->wakeup_prepared = false;
1753    
1754     diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
1755     index 0761d90..ebb3e5f 100644
1756     --- a/drivers/pci/pcie/portdrv_pci.c
1757     +++ b/drivers/pci/pcie/portdrv_pci.c
1758     @@ -134,10 +134,28 @@ static int pcie_port_runtime_resume(struct device *dev)
1759     return 0;
1760     }
1761    
1762     +static int pci_dev_pme_poll(struct pci_dev *pdev, void *data)
1763     +{
1764     + bool *pme_poll = data;
1765     +
1766     + if (pdev->pme_poll)
1767     + *pme_poll = true;
1768     + return 0;
1769     +}
1770     +
1771     static int pcie_port_runtime_idle(struct device *dev)
1772     {
1773     + struct pci_dev *pdev = to_pci_dev(dev);
1774     + bool pme_poll = false;
1775     +
1776     + /*
1777     + * If any subordinate device needs pme poll, we should keep
1778     + * the port in D0, because we need port in D0 to poll it.
1779     + */
1780     + pci_walk_bus(pdev->subordinate, pci_dev_pme_poll, &pme_poll);
1781     /* Delay for a short while to prevent too frequent suspend/resume */
1782     - pm_schedule_suspend(dev, 10);
1783     + if (!pme_poll)
1784     + pm_schedule_suspend(dev, 10);
1785     return -EBUSY;
1786     }
1787     #else
1788     diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
1789     index 7a451ff..7eb4d16 100644
1790     --- a/drivers/pci/quirks.c
1791     +++ b/drivers/pci/quirks.c
1792     @@ -2686,7 +2686,7 @@ static void ricoh_mmc_fixup_r5c832(struct pci_dev *dev)
1793     if (PCI_FUNC(dev->devfn))
1794     return;
1795     /*
1796     - * RICOH 0xe823 SD/MMC card reader fails to recognize
1797     + * RICOH 0xe822 and 0xe823 SD/MMC card readers fail to recognize
1798     * certain types of SD/MMC cards. Lowering the SD base
1799     * clock frequency from 200Mhz to 50Mhz fixes this issue.
1800     *
1801     @@ -2697,7 +2697,8 @@ static void ricoh_mmc_fixup_r5c832(struct pci_dev *dev)
1802     * 0xf9 - Key register for 0x150
1803     * 0xfc - key register for 0xe1
1804     */
1805     - if (dev->device == PCI_DEVICE_ID_RICOH_R5CE823) {
1806     + if (dev->device == PCI_DEVICE_ID_RICOH_R5CE822 ||
1807     + dev->device == PCI_DEVICE_ID_RICOH_R5CE823) {
1808     pci_write_config_byte(dev, 0xf9, 0xfc);
1809     pci_write_config_byte(dev, 0x150, 0x10);
1810     pci_write_config_byte(dev, 0xf9, 0x00);
1811     @@ -2724,6 +2725,8 @@ static void ricoh_mmc_fixup_r5c832(struct pci_dev *dev)
1812     }
1813     DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832);
1814     DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832);
1815     +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE822, ricoh_mmc_fixup_r5c832);
1816     +DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE822, ricoh_mmc_fixup_r5c832);
1817     DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE823, ricoh_mmc_fixup_r5c832);
1818     DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE823, ricoh_mmc_fixup_r5c832);
1819     #endif /*CONFIG_MMC_RICOH_MMC*/
1820     diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
1821     index ec8e914..767f526 100644
1822     --- a/drivers/pnp/pnpacpi/core.c
1823     +++ b/drivers/pnp/pnpacpi/core.c
1824     @@ -58,7 +58,7 @@ static inline int __init is_exclusive_device(struct acpi_device *dev)
1825     if (!(('0' <= (c) && (c) <= '9') || ('A' <= (c) && (c) <= 'F'))) \
1826     return 0
1827     #define TEST_ALPHA(c) \
1828     - if (!('@' <= (c) || (c) <= 'Z')) \
1829     + if (!('A' <= (c) && (c) <= 'Z')) \
1830     return 0
1831     static int __init ispnpidacpi(const char *id)
1832     {
1833     diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
1834     index f8a0aab..5143629 100644
1835     --- a/drivers/rtc/class.c
1836     +++ b/drivers/rtc/class.c
1837     @@ -244,7 +244,6 @@ void rtc_device_unregister(struct rtc_device *rtc)
1838     rtc_proc_del_device(rtc);
1839     device_unregister(&rtc->dev);
1840     rtc->ops = NULL;
1841     - ida_simple_remove(&rtc_ida, rtc->id);
1842     mutex_unlock(&rtc->ops_lock);
1843     put_device(&rtc->dev);
1844     }
1845     diff --git a/drivers/rtc/rtc-vt8500.c b/drivers/rtc/rtc-vt8500.c
1846     index 07bf193..75485c4 100644
1847     --- a/drivers/rtc/rtc-vt8500.c
1848     +++ b/drivers/rtc/rtc-vt8500.c
1849     @@ -70,7 +70,7 @@
1850     | ALARM_SEC_BIT)
1851    
1852     #define VT8500_RTC_CR_ENABLE (1 << 0) /* Enable RTC */
1853     -#define VT8500_RTC_CR_24H (1 << 1) /* 24h time format */
1854     +#define VT8500_RTC_CR_12H (1 << 1) /* 12h time format */
1855     #define VT8500_RTC_CR_SM_ENABLE (1 << 2) /* Enable periodic irqs */
1856     #define VT8500_RTC_CR_SM_SEC (1 << 3) /* 0: 1Hz/60, 1: 1Hz */
1857     #define VT8500_RTC_CR_CALIB (1 << 4) /* Enable calibration */
1858     @@ -119,7 +119,7 @@ static int vt8500_rtc_read_time(struct device *dev, struct rtc_time *tm)
1859     tm->tm_min = bcd2bin((time & TIME_MIN_MASK) >> TIME_MIN_S);
1860     tm->tm_hour = bcd2bin((time & TIME_HOUR_MASK) >> TIME_HOUR_S);
1861     tm->tm_mday = bcd2bin(date & DATE_DAY_MASK);
1862     - tm->tm_mon = bcd2bin((date & DATE_MONTH_MASK) >> DATE_MONTH_S);
1863     + tm->tm_mon = bcd2bin((date & DATE_MONTH_MASK) >> DATE_MONTH_S) - 1;
1864     tm->tm_year = bcd2bin((date & DATE_YEAR_MASK) >> DATE_YEAR_S)
1865     + ((date >> DATE_CENTURY_S) & 1 ? 200 : 100);
1866     tm->tm_wday = (time & TIME_DOW_MASK) >> TIME_DOW_S;
1867     @@ -138,8 +138,9 @@ static int vt8500_rtc_set_time(struct device *dev, struct rtc_time *tm)
1868     }
1869    
1870     writel((bin2bcd(tm->tm_year - 100) << DATE_YEAR_S)
1871     - | (bin2bcd(tm->tm_mon) << DATE_MONTH_S)
1872     - | (bin2bcd(tm->tm_mday)),
1873     + | (bin2bcd(tm->tm_mon + 1) << DATE_MONTH_S)
1874     + | (bin2bcd(tm->tm_mday))
1875     + | ((tm->tm_year >= 200) << DATE_CENTURY_S),
1876     vt8500_rtc->regbase + VT8500_RTC_DS);
1877     writel((bin2bcd(tm->tm_wday) << TIME_DOW_S)
1878     | (bin2bcd(tm->tm_hour) << TIME_HOUR_S)
1879     @@ -249,7 +250,7 @@ static int __devinit vt8500_rtc_probe(struct platform_device *pdev)
1880     }
1881    
1882     /* Enable RTC and set it to 24-hour mode */
1883     - writel(VT8500_RTC_CR_ENABLE | VT8500_RTC_CR_24H,
1884     + writel(VT8500_RTC_CR_ENABLE,
1885     vt8500_rtc->regbase + VT8500_RTC_CR);
1886    
1887     vt8500_rtc->rtc = rtc_device_register("vt8500-rtc", &pdev->dev,
1888     diff --git a/drivers/staging/omapdrm/omap_crtc.c b/drivers/staging/omapdrm/omap_crtc.c
1889     index 732f2ad..5249223 100644
1890     --- a/drivers/staging/omapdrm/omap_crtc.c
1891     +++ b/drivers/staging/omapdrm/omap_crtc.c
1892     @@ -19,7 +19,7 @@
1893    
1894     #include "omap_drv.h"
1895    
1896     -#include "drm_mode.h"
1897     +#include <drm/drm_mode.h>
1898     #include "drm_crtc.h"
1899     #include "drm_crtc_helper.h"
1900    
1901     diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
1902     index f69d029..b726c49 100644
1903     --- a/drivers/usb/chipidea/core.c
1904     +++ b/drivers/usb/chipidea/core.c
1905     @@ -385,8 +385,9 @@ EXPORT_SYMBOL_GPL(ci13xxx_add_device);
1906    
1907     void ci13xxx_remove_device(struct platform_device *pdev)
1908     {
1909     + int id = pdev->id;
1910     platform_device_unregister(pdev);
1911     - ida_simple_remove(&ci_ida, pdev->id);
1912     + ida_simple_remove(&ci_ida, id);
1913     }
1914     EXPORT_SYMBOL_GPL(ci13xxx_remove_device);
1915    
1916     diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
1917     index 1ed5afd..a557658 100644
1918     --- a/drivers/usb/core/message.c
1919     +++ b/drivers/usb/core/message.c
1920     @@ -1806,29 +1806,8 @@ free_interfaces:
1921     goto free_interfaces;
1922     }
1923    
1924     - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1925     - USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
1926     - NULL, 0, USB_CTRL_SET_TIMEOUT);
1927     - if (ret < 0) {
1928     - /* All the old state is gone, so what else can we do?
1929     - * The device is probably useless now anyway.
1930     - */
1931     - cp = NULL;
1932     - }
1933     -
1934     - dev->actconfig = cp;
1935     - if (!cp) {
1936     - usb_set_device_state(dev, USB_STATE_ADDRESS);
1937     - usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
1938     - /* Leave LPM disabled while the device is unconfigured. */
1939     - mutex_unlock(hcd->bandwidth_mutex);
1940     - usb_autosuspend_device(dev);
1941     - goto free_interfaces;
1942     - }
1943     - mutex_unlock(hcd->bandwidth_mutex);
1944     - usb_set_device_state(dev, USB_STATE_CONFIGURED);
1945     -
1946     - /* Initialize the new interface structures and the
1947     + /*
1948     + * Initialize the new interface structures and the
1949     * hc/hcd/usbcore interface/endpoint state.
1950     */
1951     for (i = 0; i < nintf; ++i) {
1952     @@ -1872,6 +1851,35 @@ free_interfaces:
1953     }
1954     kfree(new_interfaces);
1955    
1956     + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1957     + USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
1958     + NULL, 0, USB_CTRL_SET_TIMEOUT);
1959     + if (ret < 0 && cp) {
1960     + /*
1961     + * All the old state is gone, so what else can we do?
1962     + * The device is probably useless now anyway.
1963     + */
1964     + usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
1965     + for (i = 0; i < nintf; ++i) {
1966     + usb_disable_interface(dev, cp->interface[i], true);
1967     + put_device(&cp->interface[i]->dev);
1968     + cp->interface[i] = NULL;
1969     + }
1970     + cp = NULL;
1971     + }
1972     +
1973     + dev->actconfig = cp;
1974     + mutex_unlock(hcd->bandwidth_mutex);
1975     +
1976     + if (!cp) {
1977     + usb_set_device_state(dev, USB_STATE_ADDRESS);
1978     +
1979     + /* Leave LPM disabled while the device is unconfigured. */
1980     + usb_autosuspend_device(dev);
1981     + return ret;
1982     + }
1983     + usb_set_device_state(dev, USB_STATE_CONFIGURED);
1984     +
1985     if (cp->string == NULL &&
1986     !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
1987     cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
1988     diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
1989     index 95bc94f..2dc0f07 100644
1990     --- a/drivers/usb/gadget/f_ecm.c
1991     +++ b/drivers/usb/gadget/f_ecm.c
1992     @@ -808,9 +808,9 @@ fail:
1993     /* we might as well release our claims on endpoints */
1994     if (ecm->notify)
1995     ecm->notify->driver_data = NULL;
1996     - if (ecm->port.out_ep->desc)
1997     + if (ecm->port.out_ep)
1998     ecm->port.out_ep->driver_data = NULL;
1999     - if (ecm->port.in_ep->desc)
2000     + if (ecm->port.in_ep)
2001     ecm->port.in_ep->driver_data = NULL;
2002    
2003     ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
2004     diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
2005     index 1a7b2dd..a9cf2052 100644
2006     --- a/drivers/usb/gadget/f_eem.c
2007     +++ b/drivers/usb/gadget/f_eem.c
2008     @@ -319,10 +319,9 @@ fail:
2009     if (f->hs_descriptors)
2010     usb_free_descriptors(f->hs_descriptors);
2011    
2012     - /* we might as well release our claims on endpoints */
2013     - if (eem->port.out_ep->desc)
2014     + if (eem->port.out_ep)
2015     eem->port.out_ep->driver_data = NULL;
2016     - if (eem->port.in_ep->desc)
2017     + if (eem->port.in_ep)
2018     eem->port.in_ep->driver_data = NULL;
2019    
2020     ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
2021     diff --git a/drivers/usb/gadget/f_midi.c b/drivers/usb/gadget/f_midi.c
2022     index 8ed1259..b2accca 100644
2023     --- a/drivers/usb/gadget/f_midi.c
2024     +++ b/drivers/usb/gadget/f_midi.c
2025     @@ -415,6 +415,7 @@ static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f)
2026     midi->id = NULL;
2027    
2028     usb_free_descriptors(f->descriptors);
2029     + usb_free_descriptors(f->hs_descriptors);
2030     kfree(midi);
2031     }
2032    
2033     diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c
2034     index b651b52..5e04e93 100644
2035     --- a/drivers/usb/gadget/f_ncm.c
2036     +++ b/drivers/usb/gadget/f_ncm.c
2037     @@ -1259,9 +1259,9 @@ fail:
2038     /* we might as well release our claims on endpoints */
2039     if (ncm->notify)
2040     ncm->notify->driver_data = NULL;
2041     - if (ncm->port.out_ep->desc)
2042     + if (ncm->port.out_ep)
2043     ncm->port.out_ep->driver_data = NULL;
2044     - if (ncm->port.in_ep->desc)
2045     + if (ncm->port.in_ep)
2046     ncm->port.in_ep->driver_data = NULL;
2047    
2048     ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
2049     diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
2050     index 8ee9268..a6c19a4 100644
2051     --- a/drivers/usb/gadget/f_phonet.c
2052     +++ b/drivers/usb/gadget/f_phonet.c
2053     @@ -531,7 +531,7 @@ int pn_bind(struct usb_configuration *c, struct usb_function *f)
2054    
2055     req = usb_ep_alloc_request(fp->out_ep, GFP_KERNEL);
2056     if (!req)
2057     - goto err;
2058     + goto err_req;
2059    
2060     req->complete = pn_rx_complete;
2061     fp->out_reqv[i] = req;
2062     @@ -540,14 +540,18 @@ int pn_bind(struct usb_configuration *c, struct usb_function *f)
2063     /* Outgoing USB requests */
2064     fp->in_req = usb_ep_alloc_request(fp->in_ep, GFP_KERNEL);
2065     if (!fp->in_req)
2066     - goto err;
2067     + goto err_req;
2068    
2069     INFO(cdev, "USB CDC Phonet function\n");
2070     INFO(cdev, "using %s, OUT %s, IN %s\n", cdev->gadget->name,
2071     fp->out_ep->name, fp->in_ep->name);
2072     return 0;
2073    
2074     +err_req:
2075     + for (i = 0; i < phonet_rxq_size && fp->out_reqv[i]; i++)
2076     + usb_ep_free_request(fp->out_ep, fp->out_reqv[i]);
2077     err:
2078     +
2079     if (fp->out_ep)
2080     fp->out_ep->driver_data = NULL;
2081     if (fp->in_ep)
2082     diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
2083     index b1681e4..47953fe 100644
2084     --- a/drivers/usb/gadget/f_rndis.c
2085     +++ b/drivers/usb/gadget/f_rndis.c
2086     @@ -803,9 +803,9 @@ fail:
2087     /* we might as well release our claims on endpoints */
2088     if (rndis->notify)
2089     rndis->notify->driver_data = NULL;
2090     - if (rndis->port.out_ep->desc)
2091     + if (rndis->port.out_ep)
2092     rndis->port.out_ep->driver_data = NULL;
2093     - if (rndis->port.in_ep->desc)
2094     + if (rndis->port.in_ep)
2095     rndis->port.in_ep->driver_data = NULL;
2096    
2097     ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
2098     diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
2099     index 4060c0b..deb437c 100644
2100     --- a/drivers/usb/gadget/f_subset.c
2101     +++ b/drivers/usb/gadget/f_subset.c
2102     @@ -370,9 +370,9 @@ fail:
2103     usb_free_descriptors(f->hs_descriptors);
2104    
2105     /* we might as well release our claims on endpoints */
2106     - if (geth->port.out_ep->desc)
2107     + if (geth->port.out_ep)
2108     geth->port.out_ep->driver_data = NULL;
2109     - if (geth->port.in_ep->desc)
2110     + if (geth->port.in_ep)
2111     geth->port.in_ep->driver_data = NULL;
2112    
2113     ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
2114     diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
2115     index 2a8bf06..10f13c1 100644
2116     --- a/drivers/usb/gadget/f_uvc.c
2117     +++ b/drivers/usb/gadget/f_uvc.c
2118     @@ -417,7 +417,6 @@ uvc_register_video(struct uvc_device *uvc)
2119     return -ENOMEM;
2120    
2121     video->parent = &cdev->gadget->dev;
2122     - video->minor = -1;
2123     video->fops = &uvc_v4l2_fops;
2124     video->release = video_device_release;
2125     strncpy(video->name, cdev->gadget->name, sizeof(video->name));
2126     @@ -577,23 +576,12 @@ uvc_function_unbind(struct usb_configuration *c, struct usb_function *f)
2127    
2128     INFO(cdev, "uvc_function_unbind\n");
2129    
2130     - if (uvc->vdev) {
2131     - if (uvc->vdev->minor == -1)
2132     - video_device_release(uvc->vdev);
2133     - else
2134     - video_unregister_device(uvc->vdev);
2135     - uvc->vdev = NULL;
2136     - }
2137     -
2138     - if (uvc->control_ep)
2139     - uvc->control_ep->driver_data = NULL;
2140     - if (uvc->video.ep)
2141     - uvc->video.ep->driver_data = NULL;
2142     + video_unregister_device(uvc->vdev);
2143     + uvc->control_ep->driver_data = NULL;
2144     + uvc->video.ep->driver_data = NULL;
2145    
2146     - if (uvc->control_req) {
2147     - usb_ep_free_request(cdev->gadget->ep0, uvc->control_req);
2148     - kfree(uvc->control_buf);
2149     - }
2150     + usb_ep_free_request(cdev->gadget->ep0, uvc->control_req);
2151     + kfree(uvc->control_buf);
2152    
2153     kfree(f->descriptors);
2154     kfree(f->hs_descriptors);
2155     @@ -740,7 +728,22 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
2156     return 0;
2157    
2158     error:
2159     - uvc_function_unbind(c, f);
2160     + if (uvc->vdev)
2161     + video_device_release(uvc->vdev);
2162     +
2163     + if (uvc->control_ep)
2164     + uvc->control_ep->driver_data = NULL;
2165     + if (uvc->video.ep)
2166     + uvc->video.ep->driver_data = NULL;
2167     +
2168     + if (uvc->control_req) {
2169     + usb_ep_free_request(cdev->gadget->ep0, uvc->control_req);
2170     + kfree(uvc->control_buf);
2171     + }
2172     +
2173     + kfree(f->descriptors);
2174     + kfree(f->hs_descriptors);
2175     + kfree(f->ss_descriptors);
2176     return ret;
2177     }
2178    
2179     diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c
2180     index 97e68b3..4959609 100644
2181     --- a/drivers/usb/gadget/tcm_usb_gadget.c
2182     +++ b/drivers/usb/gadget/tcm_usb_gadget.c
2183     @@ -2139,6 +2139,7 @@ static struct usb_descriptor_header *uasp_fs_function_desc[] = {
2184     (struct usb_descriptor_header *) &uasp_status_pipe_desc,
2185     (struct usb_descriptor_header *) &uasp_fs_cmd_desc,
2186     (struct usb_descriptor_header *) &uasp_cmd_pipe_desc,
2187     + NULL,
2188     };
2189    
2190     static struct usb_descriptor_header *uasp_hs_function_desc[] = {
2191     diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
2192     index 2cb7d37..f42b68e 100644
2193     --- a/drivers/usb/host/ehci-pci.c
2194     +++ b/drivers/usb/host/ehci-pci.c
2195     @@ -334,7 +334,8 @@ static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
2196     pdev->vendor == PCI_VENDOR_ID_INTEL &&
2197     (pdev->device == 0x1E26 ||
2198     pdev->device == 0x8C2D ||
2199     - pdev->device == 0x8C26);
2200     + pdev->device == 0x8C26 ||
2201     + pdev->device == 0x9C26);
2202     }
2203    
2204     static void ehci_enable_xhci_companion(void)
2205     diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
2206     index 39f9e4a..eb5563a 100644
2207     --- a/drivers/usb/host/pci-quirks.c
2208     +++ b/drivers/usb/host/pci-quirks.c
2209     @@ -723,6 +723,7 @@ static int handshake(void __iomem *ptr, u32 mask, u32 done,
2210     }
2211    
2212     #define PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI 0x8C31
2213     +#define PCI_DEVICE_ID_INTEL_LYNX_POINT_LP_XHCI 0x9C31
2214    
2215     bool usb_is_intel_ppt_switchable_xhci(struct pci_dev *pdev)
2216     {
2217     @@ -736,7 +737,8 @@ bool usb_is_intel_lpt_switchable_xhci(struct pci_dev *pdev)
2218     {
2219     return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
2220     pdev->vendor == PCI_VENDOR_ID_INTEL &&
2221     - pdev->device == PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI;
2222     + (pdev->device == PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI ||
2223     + pdev->device == PCI_DEVICE_ID_INTEL_LYNX_POINT_LP_XHCI);
2224     }
2225    
2226     bool usb_is_intel_switchable_xhci(struct pci_dev *pdev)
2227     diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
2228     index 487bc08..fb51c70 100644
2229     --- a/drivers/usb/host/xhci-mem.c
2230     +++ b/drivers/usb/host/xhci-mem.c
2231     @@ -205,7 +205,12 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
2232    
2233     next = xhci_segment_alloc(xhci, cycle_state, flags);
2234     if (!next) {
2235     - xhci_free_segments_for_ring(xhci, *first);
2236     + prev = *first;
2237     + while (prev) {
2238     + next = prev->next;
2239     + xhci_segment_free(xhci, prev);
2240     + prev = next;
2241     + }
2242     return -ENOMEM;
2243     }
2244     xhci_link_segments(xhci, prev, next, type);
2245     @@ -258,7 +263,7 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
2246     return ring;
2247    
2248     fail:
2249     - xhci_ring_free(xhci, ring);
2250     + kfree(ring);
2251     return NULL;
2252     }
2253    
2254     diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
2255     index 4e1a894..1189cf3 100644
2256     --- a/drivers/usb/host/xhci-ring.c
2257     +++ b/drivers/usb/host/xhci-ring.c
2258     @@ -3071,11 +3071,11 @@ static u32 xhci_td_remainder(unsigned int remainder)
2259     }
2260    
2261     /*
2262     - * For xHCI 1.0 host controllers, TD size is the number of packets remaining in
2263     - * the TD (*not* including this TRB).
2264     + * For xHCI 1.0 host controllers, TD size is the number of max packet sized
2265     + * packets remaining in the TD (*not* including this TRB).
2266     *
2267     * Total TD packet count = total_packet_count =
2268     - * roundup(TD size in bytes / wMaxPacketSize)
2269     + * DIV_ROUND_UP(TD size in bytes / wMaxPacketSize)
2270     *
2271     * Packets transferred up to and including this TRB = packets_transferred =
2272     * rounddown(total bytes transferred including this TRB / wMaxPacketSize)
2273     @@ -3083,15 +3083,16 @@ static u32 xhci_td_remainder(unsigned int remainder)
2274     * TD size = total_packet_count - packets_transferred
2275     *
2276     * It must fit in bits 21:17, so it can't be bigger than 31.
2277     + * The last TRB in a TD must have the TD size set to zero.
2278     */
2279     -
2280     static u32 xhci_v1_0_td_remainder(int running_total, int trb_buff_len,
2281     - unsigned int total_packet_count, struct urb *urb)
2282     + unsigned int total_packet_count, struct urb *urb,
2283     + unsigned int num_trbs_left)
2284     {
2285     int packets_transferred;
2286    
2287     /* One TRB with a zero-length data packet. */
2288     - if (running_total == 0 && trb_buff_len == 0)
2289     + if (num_trbs_left == 0 || (running_total == 0 && trb_buff_len == 0))
2290     return 0;
2291    
2292     /* All the TRB queueing functions don't count the current TRB in
2293     @@ -3100,7 +3101,9 @@ static u32 xhci_v1_0_td_remainder(int running_total, int trb_buff_len,
2294     packets_transferred = (running_total + trb_buff_len) /
2295     usb_endpoint_maxp(&urb->ep->desc);
2296    
2297     - return xhci_td_remainder(total_packet_count - packets_transferred);
2298     + if ((total_packet_count - packets_transferred) > 31)
2299     + return 31 << 17;
2300     + return (total_packet_count - packets_transferred) << 17;
2301     }
2302    
2303     static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2304     @@ -3127,7 +3130,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2305    
2306     num_trbs = count_sg_trbs_needed(xhci, urb);
2307     num_sgs = urb->num_mapped_sgs;
2308     - total_packet_count = roundup(urb->transfer_buffer_length,
2309     + total_packet_count = DIV_ROUND_UP(urb->transfer_buffer_length,
2310     usb_endpoint_maxp(&urb->ep->desc));
2311    
2312     trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id],
2313     @@ -3210,7 +3213,8 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2314     running_total);
2315     } else {
2316     remainder = xhci_v1_0_td_remainder(running_total,
2317     - trb_buff_len, total_packet_count, urb);
2318     + trb_buff_len, total_packet_count, urb,
2319     + num_trbs - 1);
2320     }
2321     length_field = TRB_LEN(trb_buff_len) |
2322     remainder |
2323     @@ -3318,7 +3322,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2324     start_cycle = ep_ring->cycle_state;
2325    
2326     running_total = 0;
2327     - total_packet_count = roundup(urb->transfer_buffer_length,
2328     + total_packet_count = DIV_ROUND_UP(urb->transfer_buffer_length,
2329     usb_endpoint_maxp(&urb->ep->desc));
2330     /* How much data is in the first TRB? */
2331     addr = (u64) urb->transfer_dma;
2332     @@ -3364,7 +3368,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2333     running_total);
2334     } else {
2335     remainder = xhci_v1_0_td_remainder(running_total,
2336     - trb_buff_len, total_packet_count, urb);
2337     + trb_buff_len, total_packet_count, urb,
2338     + num_trbs - 1);
2339     }
2340     length_field = TRB_LEN(trb_buff_len) |
2341     remainder |
2342     @@ -3627,7 +3632,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2343     addr = start_addr + urb->iso_frame_desc[i].offset;
2344     td_len = urb->iso_frame_desc[i].length;
2345     td_remain_len = td_len;
2346     - total_packet_count = roundup(td_len,
2347     + total_packet_count = DIV_ROUND_UP(td_len,
2348     usb_endpoint_maxp(&urb->ep->desc));
2349     /* A zero-length transfer still involves at least one packet. */
2350     if (total_packet_count == 0)
2351     @@ -3706,7 +3711,8 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2352     } else {
2353     remainder = xhci_v1_0_td_remainder(
2354     running_total, trb_buff_len,
2355     - total_packet_count, urb);
2356     + total_packet_count, urb,
2357     + (trbs_per_td - j - 1));
2358     }
2359     length_field = TRB_LEN(trb_buff_len) |
2360     remainder |
2361     diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
2362     index c9e419f..389829e 100644
2363     --- a/drivers/usb/host/xhci.c
2364     +++ b/drivers/usb/host/xhci.c
2365     @@ -480,7 +480,7 @@ static bool compliance_mode_recovery_timer_quirk_check(void)
2366     if (strstr(dmi_product_name, "Z420") ||
2367     strstr(dmi_product_name, "Z620") ||
2368     strstr(dmi_product_name, "Z820") ||
2369     - strstr(dmi_product_name, "Z1"))
2370     + strstr(dmi_product_name, "Z1 Workstation"))
2371     return true;
2372    
2373     return false;
2374     @@ -2254,7 +2254,7 @@ static bool xhci_is_async_ep(unsigned int ep_type)
2375    
2376     static bool xhci_is_sync_in_ep(unsigned int ep_type)
2377     {
2378     - return (ep_type == ISOC_IN_EP || ep_type != INT_IN_EP);
2379     + return (ep_type == ISOC_IN_EP || ep_type == INT_IN_EP);
2380     }
2381    
2382     static unsigned int xhci_get_ss_bw_consumed(struct xhci_bw_info *ep_bw)
2383     diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
2384     index e19da82..3a6c2fd 100644
2385     --- a/drivers/usb/musb/cppi_dma.c
2386     +++ b/drivers/usb/musb/cppi_dma.c
2387     @@ -1314,6 +1314,7 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
2388    
2389     return IRQ_HANDLED;
2390     }
2391     +EXPORT_SYMBOL_GPL(cppi_interrupt);
2392    
2393     /* Instantiate a software object representing a DMA controller. */
2394     struct dma_controller *__devinit
2395     diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
2396     index ff5f112..72b9239 100644
2397     --- a/drivers/usb/musb/musb_dsps.c
2398     +++ b/drivers/usb/musb/musb_dsps.c
2399     @@ -377,7 +377,8 @@ static int dsps_musb_init(struct musb *musb)
2400     /* mentor core register starts at offset of 0x400 from musb base */
2401     musb->mregs += wrp->musb_core_offset;
2402    
2403     - /* Get the NOP PHY */
2404     + /* NOP driver needs change if supporting dual instance */
2405     + usb_nop_xceiv_register();
2406     musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
2407     if (IS_ERR_OR_NULL(musb->xceiv))
2408     return -ENODEV;
2409     diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
2410     index e639584..286c30c 100644
2411     --- a/drivers/virtio/virtio_ring.c
2412     +++ b/drivers/virtio/virtio_ring.c
2413     @@ -135,6 +135,13 @@ static int vring_add_indirect(struct vring_virtqueue *vq,
2414     unsigned head;
2415     int i;
2416    
2417     + /*
2418     + * We require lowmem mappings for the descriptors because
2419     + * otherwise virt_to_phys will give us bogus addresses in the
2420     + * virtqueue.
2421     + */
2422     + gfp &= ~(__GFP_HIGHMEM | __GFP_HIGH);
2423     +
2424     desc = kmalloc((out + in) * sizeof(struct vring_desc), gfp);
2425     if (!desc)
2426     return -ENOMEM;
2427     diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
2428     index 790b3cd..772428d 100644
2429     --- a/fs/binfmt_misc.c
2430     +++ b/fs/binfmt_misc.c
2431     @@ -176,7 +176,10 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
2432     goto _error;
2433     bprm->argc ++;
2434    
2435     - bprm->interp = iname; /* for binfmt_script */
2436     + /* Update interp in case binfmt_script needs it. */
2437     + retval = bprm_change_interp(iname, bprm);
2438     + if (retval < 0)
2439     + goto _error;
2440    
2441     interp_file = open_exec (iname);
2442     retval = PTR_ERR (interp_file);
2443     diff --git a/fs/binfmt_script.c b/fs/binfmt_script.c
2444     index d3b8c1f..df49d48 100644
2445     --- a/fs/binfmt_script.c
2446     +++ b/fs/binfmt_script.c
2447     @@ -82,7 +82,9 @@ static int load_script(struct linux_binprm *bprm,struct pt_regs *regs)
2448     retval = copy_strings_kernel(1, &i_name, bprm);
2449     if (retval) return retval;
2450     bprm->argc++;
2451     - bprm->interp = interp;
2452     + retval = bprm_change_interp(interp, bprm);
2453     + if (retval < 0)
2454     + return retval;
2455    
2456     /*
2457     * OK, now restart the process with the interpreter's dentry.
2458     diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
2459     index 1c576e8..dd538b4 100644
2460     --- a/fs/cifs/readdir.c
2461     +++ b/fs/cifs/readdir.c
2462     @@ -66,18 +66,21 @@ static inline void dump_cifs_file_struct(struct file *file, char *label)
2463     #endif /* DEBUG2 */
2464    
2465     /*
2466     + * Attempt to preload the dcache with the results from the FIND_FIRST/NEXT
2467     + *
2468     * Find the dentry that matches "name". If there isn't one, create one. If it's
2469     * a negative dentry or the uniqueid changed, then drop it and recreate it.
2470     */
2471     -static struct dentry *
2472     -cifs_readdir_lookup(struct dentry *parent, struct qstr *name,
2473     +static void
2474     +cifs_prime_dcache(struct dentry *parent, struct qstr *name,
2475     struct cifs_fattr *fattr)
2476     {
2477     struct dentry *dentry, *alias;
2478     struct inode *inode;
2479     struct super_block *sb = parent->d_inode->i_sb;
2480     + struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
2481    
2482     - cFYI(1, "For %s", name->name);
2483     + cFYI(1, "%s: for %s", __func__, name->name);
2484    
2485     if (parent->d_op && parent->d_op->d_hash)
2486     parent->d_op->d_hash(parent, parent->d_inode, name);
2487     @@ -87,37 +90,42 @@ cifs_readdir_lookup(struct dentry *parent, struct qstr *name,
2488     dentry = d_lookup(parent, name);
2489     if (dentry) {
2490     int err;
2491     +
2492     inode = dentry->d_inode;
2493     - /* update inode in place if i_ino didn't change */
2494     - if (inode && CIFS_I(inode)->uniqueid == fattr->cf_uniqueid) {
2495     - cifs_fattr_to_inode(inode, fattr);
2496     - return dentry;
2497     + if (inode) {
2498     + /*
2499     + * If we're generating inode numbers, then we don't
2500     + * want to clobber the existing one with the one that
2501     + * the readdir code created.
2502     + */
2503     + if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM))
2504     + fattr->cf_uniqueid = CIFS_I(inode)->uniqueid;
2505     +
2506     + /* update inode in place if i_ino didn't change */
2507     + if (CIFS_I(inode)->uniqueid == fattr->cf_uniqueid) {
2508     + cifs_fattr_to_inode(inode, fattr);
2509     + goto out;
2510     + }
2511     }
2512     err = d_invalidate(dentry);
2513     dput(dentry);
2514     if (err)
2515     - return NULL;
2516     + return;
2517     }
2518    
2519     dentry = d_alloc(parent, name);
2520     - if (dentry == NULL)
2521     - return NULL;
2522     + if (!dentry)
2523     + return;
2524    
2525     inode = cifs_iget(sb, fattr);
2526     - if (!inode) {
2527     - dput(dentry);
2528     - return NULL;
2529     - }
2530     + if (!inode)
2531     + goto out;
2532    
2533     alias = d_materialise_unique(dentry, inode);
2534     - if (alias != NULL) {
2535     - dput(dentry);
2536     - if (IS_ERR(alias))
2537     - return NULL;
2538     - dentry = alias;
2539     - }
2540     -
2541     - return dentry;
2542     + if (alias && !IS_ERR(alias))
2543     + dput(alias);
2544     +out:
2545     + dput(dentry);
2546     }
2547    
2548     static void
2549     @@ -652,7 +660,6 @@ static int cifs_filldir(char *find_entry, struct file *file, filldir_t filldir,
2550     struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
2551     struct cifs_dirent de = { NULL, };
2552     struct cifs_fattr fattr;
2553     - struct dentry *dentry;
2554     struct qstr name;
2555     int rc = 0;
2556     ino_t ino;
2557     @@ -723,13 +730,11 @@ static int cifs_filldir(char *find_entry, struct file *file, filldir_t filldir,
2558     */
2559     fattr.cf_flags |= CIFS_FATTR_NEED_REVAL;
2560    
2561     - ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid);
2562     - dentry = cifs_readdir_lookup(file->f_dentry, &name, &fattr);
2563     + cifs_prime_dcache(file->f_dentry, &name, &fattr);
2564    
2565     + ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid);
2566     rc = filldir(dirent, name.name, name.len, file->f_pos, ino,
2567     fattr.cf_dtype);
2568     -
2569     - dput(dentry);
2570     return rc;
2571     }
2572    
2573     diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
2574     index 34cea27..591bf19 100644
2575     --- a/fs/cifs/smb1ops.c
2576     +++ b/fs/cifs/smb1ops.c
2577     @@ -53,6 +53,13 @@ send_nt_cancel(struct TCP_Server_Info *server, void *buf,
2578     mutex_unlock(&server->srv_mutex);
2579     return rc;
2580     }
2581     +
2582     + /*
2583     + * The response to this call was already factored into the sequence
2584     + * number when the call went out, so we must adjust it back downward
2585     + * after signing here.
2586     + */
2587     + --server->sequence_number;
2588     rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
2589     mutex_unlock(&server->srv_mutex);
2590    
2591     diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
2592     index cf33622..e7f9dbc 100644
2593     --- a/fs/cifs/smb2pdu.c
2594     +++ b/fs/cifs/smb2pdu.c
2595     @@ -425,7 +425,7 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
2596     }
2597    
2598     cFYI(1, "sec_flags 0x%x", sec_flags);
2599     - if (sec_flags & CIFSSEC_MUST_SIGN) {
2600     + if ((sec_flags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) {
2601     cFYI(1, "Signing required");
2602     if (!(server->sec_mode & (SMB2_NEGOTIATE_SIGNING_REQUIRED |
2603     SMB2_NEGOTIATE_SIGNING_ENABLED))) {
2604     diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
2605     index 76d974c..1a52868 100644
2606     --- a/fs/cifs/transport.c
2607     +++ b/fs/cifs/transport.c
2608     @@ -144,9 +144,6 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec,
2609    
2610     *sent = 0;
2611    
2612     - if (ssocket == NULL)
2613     - return -ENOTSOCK; /* BB eventually add reconnect code here */
2614     -
2615     smb_msg.msg_name = (struct sockaddr *) &server->dstaddr;
2616     smb_msg.msg_namelen = sizeof(struct sockaddr);
2617     smb_msg.msg_control = NULL;
2618     @@ -291,6 +288,9 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
2619     struct socket *ssocket = server->ssocket;
2620     int val = 1;
2621    
2622     + if (ssocket == NULL)
2623     + return -ENOTSOCK;
2624     +
2625     cFYI(1, "Sending smb: smb_len=%u", smb_buf_length);
2626     dump_smb(iov[0].iov_base, iov[0].iov_len);
2627    
2628     diff --git a/fs/dcache.c b/fs/dcache.c
2629     index 3a463d0..0d0adb6 100644
2630     --- a/fs/dcache.c
2631     +++ b/fs/dcache.c
2632     @@ -1583,7 +1583,7 @@ EXPORT_SYMBOL(d_find_any_alias);
2633     */
2634     struct dentry *d_obtain_alias(struct inode *inode)
2635     {
2636     - static const struct qstr anonstring = { .name = "" };
2637     + static const struct qstr anonstring = QSTR_INIT("/", 1);
2638     struct dentry *tmp;
2639     struct dentry *res;
2640    
2641     diff --git a/fs/exec.c b/fs/exec.c
2642     index 0039055..c6e6de4 100644
2643     --- a/fs/exec.c
2644     +++ b/fs/exec.c
2645     @@ -1175,9 +1175,24 @@ void free_bprm(struct linux_binprm *bprm)
2646     mutex_unlock(&current->signal->cred_guard_mutex);
2647     abort_creds(bprm->cred);
2648     }
2649     + /* If a binfmt changed the interp, free it. */
2650     + if (bprm->interp != bprm->filename)
2651     + kfree(bprm->interp);
2652     kfree(bprm);
2653     }
2654    
2655     +int bprm_change_interp(char *interp, struct linux_binprm *bprm)
2656     +{
2657     + /* If a binfmt changed the interp, free it first. */
2658     + if (bprm->interp != bprm->filename)
2659     + kfree(bprm->interp);
2660     + bprm->interp = kstrdup(interp, GFP_KERNEL);
2661     + if (!bprm->interp)
2662     + return -ENOMEM;
2663     + return 0;
2664     +}
2665     +EXPORT_SYMBOL(bprm_change_interp);
2666     +
2667     /*
2668     * install the new credentials for this executable
2669     */
2670     diff --git a/fs/file_table.c b/fs/file_table.c
2671     index a72bf9d..de9e965 100644
2672     --- a/fs/file_table.c
2673     +++ b/fs/file_table.c
2674     @@ -458,8 +458,8 @@ void mark_files_ro(struct super_block *sb)
2675     spin_unlock(&f->f_lock);
2676     if (file_check_writeable(f) != 0)
2677     continue;
2678     + __mnt_drop_write(f->f_path.mnt);
2679     file_release_write(f);
2680     - mnt_drop_write_file(f);
2681     } while_file_list_for_each_entry;
2682     lg_global_unlock(&files_lglock);
2683     }
2684     diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
2685     index 76b4a7a..36b2e7a 100644
2686     --- a/fs/nfs/callback_proc.c
2687     +++ b/fs/nfs/callback_proc.c
2688     @@ -205,7 +205,7 @@ static u32 initiate_bulk_draining(struct nfs_client *clp,
2689    
2690     list_for_each_entry(lo, &server->layouts, plh_layouts) {
2691     ino = igrab(lo->plh_inode);
2692     - if (ino)
2693     + if (!ino)
2694     continue;
2695     spin_lock(&ino->i_lock);
2696     /* Is this layout in the process of being freed? */
2697     diff --git a/fs/nfs/client.c b/fs/nfs/client.c
2698     index 8b39a42..5e8d24d 100644
2699     --- a/fs/nfs/client.c
2700     +++ b/fs/nfs/client.c
2701     @@ -615,8 +615,7 @@ EXPORT_SYMBOL_GPL(nfs_create_rpc_client);
2702     */
2703     static void nfs_destroy_server(struct nfs_server *server)
2704     {
2705     - if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) ||
2706     - !(server->flags & NFS_MOUNT_LOCAL_FCNTL))
2707     + if (server->nlm_host)
2708     nlmclnt_done(server->nlm_host);
2709     }
2710    
2711     diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
2712     index b9e66b7..c99f07e 100644
2713     --- a/fs/nfs/dir.c
2714     +++ b/fs/nfs/dir.c
2715     @@ -1156,11 +1156,14 @@ static int nfs_dentry_delete(const struct dentry *dentry)
2716    
2717     }
2718    
2719     +/* Ensure that we revalidate inode->i_nlink */
2720     static void nfs_drop_nlink(struct inode *inode)
2721     {
2722     spin_lock(&inode->i_lock);
2723     - if (inode->i_nlink > 0)
2724     - drop_nlink(inode);
2725     + /* drop the inode if we're reasonably sure this is the last link */
2726     + if (inode->i_nlink == 1)
2727     + clear_nlink(inode);
2728     + NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
2729     spin_unlock(&inode->i_lock);
2730     }
2731    
2732     @@ -1175,8 +1178,8 @@ static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
2733     NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
2734    
2735     if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
2736     - drop_nlink(inode);
2737     nfs_complete_unlink(dentry, inode);
2738     + nfs_drop_nlink(inode);
2739     }
2740     iput(inode);
2741     }
2742     @@ -1647,10 +1650,8 @@ static int nfs_safe_remove(struct dentry *dentry)
2743     if (inode != NULL) {
2744     NFS_PROTO(inode)->return_delegation(inode);
2745     error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
2746     - /* The VFS may want to delete this inode */
2747     if (error == 0)
2748     nfs_drop_nlink(inode);
2749     - nfs_mark_for_revalidate(inode);
2750     } else
2751     error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
2752     if (error == -ENOENT)
2753     @@ -2147,12 +2148,16 @@ static int nfs_open_permission_mask(int openflags)
2754     {
2755     int mask = 0;
2756    
2757     - if ((openflags & O_ACCMODE) != O_WRONLY)
2758     - mask |= MAY_READ;
2759     - if ((openflags & O_ACCMODE) != O_RDONLY)
2760     - mask |= MAY_WRITE;
2761     - if (openflags & __FMODE_EXEC)
2762     - mask |= MAY_EXEC;
2763     + if (openflags & __FMODE_EXEC) {
2764     + /* ONLY check exec rights */
2765     + mask = MAY_EXEC;
2766     + } else {
2767     + if ((openflags & O_ACCMODE) != O_WRONLY)
2768     + mask |= MAY_READ;
2769     + if ((openflags & O_ACCMODE) != O_RDONLY)
2770     + mask |= MAY_WRITE;
2771     + }
2772     +
2773     return mask;
2774     }
2775    
2776     diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
2777     index cae26cb..594f4e7 100644
2778     --- a/fs/nfs/direct.c
2779     +++ b/fs/nfs/direct.c
2780     @@ -266,14 +266,6 @@ static void nfs_direct_read_completion(struct nfs_pgio_header *hdr)
2781     struct nfs_page *req = nfs_list_entry(hdr->pages.next);
2782     struct page *page = req->wb_page;
2783    
2784     - if (test_bit(NFS_IOHDR_EOF, &hdr->flags)) {
2785     - if (bytes > hdr->good_bytes)
2786     - zero_user(page, 0, PAGE_SIZE);
2787     - else if (hdr->good_bytes - bytes < PAGE_SIZE)
2788     - zero_user_segment(page,
2789     - hdr->good_bytes & ~PAGE_MASK,
2790     - PAGE_SIZE);
2791     - }
2792     if (!PageCompound(page)) {
2793     if (test_bit(NFS_IOHDR_ERROR, &hdr->flags)) {
2794     if (bytes < hdr->good_bytes)
2795     diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
2796     index 5eec442..4432b2f 100644
2797     --- a/fs/nfs/nfs4proc.c
2798     +++ b/fs/nfs/nfs4proc.c
2799     @@ -1721,7 +1721,8 @@ static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
2800    
2801     static int nfs4_opendata_access(struct rpc_cred *cred,
2802     struct nfs4_opendata *opendata,
2803     - struct nfs4_state *state, fmode_t fmode)
2804     + struct nfs4_state *state, fmode_t fmode,
2805     + int openflags)
2806     {
2807     struct nfs_access_entry cache;
2808     u32 mask;
2809     @@ -1733,11 +1734,14 @@ static int nfs4_opendata_access(struct rpc_cred *cred,
2810    
2811     mask = 0;
2812     /* don't check MAY_WRITE - a newly created file may not have
2813     - * write mode bits, but POSIX allows the creating process to write */
2814     - if (fmode & FMODE_READ)
2815     - mask |= MAY_READ;
2816     - if (fmode & FMODE_EXEC)
2817     - mask |= MAY_EXEC;
2818     + * write mode bits, but POSIX allows the creating process to write.
2819     + * use openflags to check for exec, because fmode won't
2820     + * always have FMODE_EXEC set when file open for exec. */
2821     + if (openflags & __FMODE_EXEC) {
2822     + /* ONLY check for exec rights */
2823     + mask = MAY_EXEC;
2824     + } else if (fmode & FMODE_READ)
2825     + mask = MAY_READ;
2826    
2827     cache.cred = cred;
2828     cache.jiffies = jiffies;
2829     @@ -2009,7 +2013,7 @@ static int _nfs4_do_open(struct inode *dir,
2830     if (server->caps & NFS_CAP_POSIX_LOCK)
2831     set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
2832    
2833     - status = nfs4_opendata_access(cred, opendata, state, fmode);
2834     + status = nfs4_opendata_access(cred, opendata, state, fmode, flags);
2835     if (status != 0)
2836     goto err_opendata_put;
2837    
2838     @@ -3937,8 +3941,13 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
2839     goto out_free;
2840     }
2841     nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len);
2842     - if (buf)
2843     + if (buf) {
2844     + if (res.acl_len > buflen) {
2845     + ret = -ERANGE;
2846     + goto out_free;
2847     + }
2848     _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len);
2849     + }
2850     out_ok:
2851     ret = res.acl_len;
2852     out_free:
2853     @@ -6138,13 +6147,26 @@ static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
2854     rpc_call_start(task);
2855     }
2856    
2857     +static void nfs41_sequence_prepare_privileged(struct rpc_task *task, void *data)
2858     +{
2859     + rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
2860     + nfs41_sequence_prepare(task, data);
2861     +}
2862     +
2863     static const struct rpc_call_ops nfs41_sequence_ops = {
2864     .rpc_call_done = nfs41_sequence_call_done,
2865     .rpc_call_prepare = nfs41_sequence_prepare,
2866     .rpc_release = nfs41_sequence_release,
2867     };
2868    
2869     -static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
2870     +static const struct rpc_call_ops nfs41_sequence_privileged_ops = {
2871     + .rpc_call_done = nfs41_sequence_call_done,
2872     + .rpc_call_prepare = nfs41_sequence_prepare_privileged,
2873     + .rpc_release = nfs41_sequence_release,
2874     +};
2875     +
2876     +static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred,
2877     + const struct rpc_call_ops *seq_ops)
2878     {
2879     struct nfs4_sequence_data *calldata;
2880     struct rpc_message msg = {
2881     @@ -6154,7 +6176,7 @@ static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_
2882     struct rpc_task_setup task_setup_data = {
2883     .rpc_client = clp->cl_rpcclient,
2884     .rpc_message = &msg,
2885     - .callback_ops = &nfs41_sequence_ops,
2886     + .callback_ops = seq_ops,
2887     .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT,
2888     };
2889    
2890     @@ -6181,7 +6203,7 @@ static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cr
2891    
2892     if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0)
2893     return 0;
2894     - task = _nfs41_proc_sequence(clp, cred);
2895     + task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_ops);
2896     if (IS_ERR(task))
2897     ret = PTR_ERR(task);
2898     else
2899     @@ -6195,7 +6217,7 @@ static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
2900     struct rpc_task *task;
2901     int ret;
2902    
2903     - task = _nfs41_proc_sequence(clp, cred);
2904     + task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_privileged_ops);
2905     if (IS_ERR(task)) {
2906     ret = PTR_ERR(task);
2907     goto out;
2908     diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
2909     index 2878f97..b7f7538 100644
2910     --- a/fs/nfs/pnfs.c
2911     +++ b/fs/nfs/pnfs.c
2912     @@ -254,7 +254,7 @@ static void
2913     pnfs_layout_set_fail_bit(struct pnfs_layout_hdr *lo, int fail_bit)
2914     {
2915     lo->plh_retry_timestamp = jiffies;
2916     - if (test_and_set_bit(fail_bit, &lo->plh_flags))
2917     + if (!test_and_set_bit(fail_bit, &lo->plh_flags))
2918     atomic_inc(&lo->plh_refcount);
2919     }
2920    
2921     diff --git a/fs/nfs/read.c b/fs/nfs/read.c
2922     index b6bdb18..a5e5d98 100644
2923     --- a/fs/nfs/read.c
2924     +++ b/fs/nfs/read.c
2925     @@ -91,12 +91,16 @@ void nfs_readdata_release(struct nfs_read_data *rdata)
2926     put_nfs_open_context(rdata->args.context);
2927     if (rdata->pages.pagevec != rdata->pages.page_array)
2928     kfree(rdata->pages.pagevec);
2929     - if (rdata != &read_header->rpc_data)
2930     - kfree(rdata);
2931     - else
2932     + if (rdata == &read_header->rpc_data) {
2933     rdata->header = NULL;
2934     + rdata = NULL;
2935     + }
2936     if (atomic_dec_and_test(&hdr->refcnt))
2937     hdr->completion_ops->completion(hdr);
2938     + /* Note: we only free the rpc_task after callbacks are done.
2939     + * See the comment in rpc_free_task() for why
2940     + */
2941     + kfree(rdata);
2942     }
2943     EXPORT_SYMBOL_GPL(nfs_readdata_release);
2944    
2945     diff --git a/fs/nfs/super.c b/fs/nfs/super.c
2946     index 652d3f7..00be08f 100644
2947     --- a/fs/nfs/super.c
2948     +++ b/fs/nfs/super.c
2949     @@ -1150,7 +1150,7 @@ static int nfs_get_option_str(substring_t args[], char **option)
2950     {
2951     kfree(*option);
2952     *option = match_strdup(args);
2953     - return !option;
2954     + return !*option;
2955     }
2956    
2957     static int nfs_get_option_ul(substring_t args[], unsigned long *option)
2958     diff --git a/fs/nfs/write.c b/fs/nfs/write.c
2959     index 9347ab7..8b67dc3 100644
2960     --- a/fs/nfs/write.c
2961     +++ b/fs/nfs/write.c
2962     @@ -126,12 +126,16 @@ void nfs_writedata_release(struct nfs_write_data *wdata)
2963     put_nfs_open_context(wdata->args.context);
2964     if (wdata->pages.pagevec != wdata->pages.page_array)
2965     kfree(wdata->pages.pagevec);
2966     - if (wdata != &write_header->rpc_data)
2967     - kfree(wdata);
2968     - else
2969     + if (wdata == &write_header->rpc_data) {
2970     wdata->header = NULL;
2971     + wdata = NULL;
2972     + }
2973     if (atomic_dec_and_test(&hdr->refcnt))
2974     hdr->completion_ops->completion(hdr);
2975     + /* Note: we only free the rpc_task after callbacks are done.
2976     + * See the comment in rpc_free_task() for why
2977     + */
2978     + kfree(wdata);
2979     }
2980     EXPORT_SYMBOL_GPL(nfs_writedata_release);
2981    
2982     @@ -202,7 +206,6 @@ out:
2983     /* A writeback failed: mark the page as bad, and invalidate the page cache */
2984     static void nfs_set_pageerror(struct page *page)
2985     {
2986     - SetPageError(page);
2987     nfs_zap_mapping(page_file_mapping(page)->host, page_file_mapping(page));
2988     }
2989    
2990     @@ -884,7 +887,7 @@ static bool nfs_write_pageuptodate(struct page *page, struct inode *inode)
2991     {
2992     if (nfs_have_delegated_attributes(inode))
2993     goto out;
2994     - if (NFS_I(inode)->cache_validity & NFS_INO_REVAL_PAGECACHE)
2995     + if (NFS_I(inode)->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE))
2996     return false;
2997     out:
2998     return PageUptodate(page) != 0;
2999     diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
3000     index 6c9a4b2..f75af01 100644
3001     --- a/fs/nfsd/nfs4proc.c
3002     +++ b/fs/nfsd/nfs4proc.c
3003     @@ -194,6 +194,7 @@ static __be32
3004     do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
3005     {
3006     struct svc_fh *resfh;
3007     + int accmode;
3008     __be32 status;
3009    
3010     resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
3011     @@ -253,9 +254,10 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o
3012     /* set reply cache */
3013     fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
3014     &resfh->fh_handle);
3015     - if (!open->op_created)
3016     - status = do_open_permission(rqstp, resfh, open,
3017     - NFSD_MAY_NOP);
3018     + accmode = NFSD_MAY_NOP;
3019     + if (open->op_created)
3020     + accmode |= NFSD_MAY_OWNER_OVERRIDE;
3021     + status = do_open_permission(rqstp, resfh, open, accmode);
3022     set_change_info(&open->op_cinfo, current_fh);
3023     fh_dup2(current_fh, resfh);
3024     out:
3025     diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
3026     index d0237f8..503e15e 100644
3027     --- a/fs/nfsd/nfs4state.c
3028     +++ b/fs/nfsd/nfs4state.c
3029     @@ -2340,7 +2340,7 @@ nfsd4_init_slabs(void)
3030     if (openowner_slab == NULL)
3031     goto out_nomem;
3032     lockowner_slab = kmem_cache_create("nfsd4_lockowners",
3033     - sizeof(struct nfs4_openowner), 0, 0, NULL);
3034     + sizeof(struct nfs4_lockowner), 0, 0, NULL);
3035     if (lockowner_slab == NULL)
3036     goto out_nomem;
3037     file_slab = kmem_cache_create("nfsd4_files",
3038     diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
3039     index fd548d1..ac6850f 100644
3040     --- a/fs/nfsd/nfs4xdr.c
3041     +++ b/fs/nfsd/nfs4xdr.c
3042     @@ -2946,11 +2946,16 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
3043     len = maxcount;
3044     v = 0;
3045     while (len > 0) {
3046     - pn = resp->rqstp->rq_resused++;
3047     + pn = resp->rqstp->rq_resused;
3048     + if (!resp->rqstp->rq_respages[pn]) { /* ran out of pages */
3049     + maxcount -= len;
3050     + break;
3051     + }
3052     resp->rqstp->rq_vec[v].iov_base =
3053     page_address(resp->rqstp->rq_respages[pn]);
3054     resp->rqstp->rq_vec[v].iov_len =
3055     len < PAGE_SIZE ? len : PAGE_SIZE;
3056     + resp->rqstp->rq_resused++;
3057     v++;
3058     len -= PAGE_SIZE;
3059     }
3060     @@ -2996,6 +3001,8 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
3061     return nfserr;
3062     if (resp->xbuf->page_len)
3063     return nfserr_resource;
3064     + if (!resp->rqstp->rq_respages[resp->rqstp->rq_resused])
3065     + return nfserr_resource;
3066    
3067     page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]);
3068    
3069     @@ -3045,6 +3052,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
3070     return nfserr;
3071     if (resp->xbuf->page_len)
3072     return nfserr_resource;
3073     + if (!resp->rqstp->rq_respages[resp->rqstp->rq_resused])
3074     + return nfserr_resource;
3075    
3076     RESERVE_SPACE(NFS4_VERIFIER_SIZE);
3077     savep = p;
3078     diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
3079     index 2013aa00..30d3784 100644
3080     --- a/fs/nfsd/nfssvc.c
3081     +++ b/fs/nfsd/nfssvc.c
3082     @@ -640,7 +640,7 @@ nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
3083     }
3084    
3085     /* Store reply in cache. */
3086     - nfsd_cache_update(rqstp, proc->pc_cachetype, statp + 1);
3087     + nfsd_cache_update(rqstp, rqstp->rq_cachetype, statp + 1);
3088     return 1;
3089     }
3090    
3091     diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
3092     index c120b48..f59169e 100644
3093     --- a/fs/nfsd/vfs.c
3094     +++ b/fs/nfsd/vfs.c
3095     @@ -1485,13 +1485,19 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
3096     case NFS3_CREATE_EXCLUSIVE:
3097     if ( dchild->d_inode->i_mtime.tv_sec == v_mtime
3098     && dchild->d_inode->i_atime.tv_sec == v_atime
3099     - && dchild->d_inode->i_size == 0 )
3100     + && dchild->d_inode->i_size == 0 ) {
3101     + if (created)
3102     + *created = 1;
3103     break;
3104     + }
3105     case NFS4_CREATE_EXCLUSIVE4_1:
3106     if ( dchild->d_inode->i_mtime.tv_sec == v_mtime
3107     && dchild->d_inode->i_atime.tv_sec == v_atime
3108     - && dchild->d_inode->i_size == 0 )
3109     + && dchild->d_inode->i_size == 0 ) {
3110     + if (created)
3111     + *created = 1;
3112     goto set_attr;
3113     + }
3114     /* fallthru */
3115     case NFS3_CREATE_GUARDED:
3116     err = nfserr_exist;
3117     diff --git a/fs/proc/array.c b/fs/proc/array.c
3118     index c1c207c..bd31e02 100644
3119     --- a/fs/proc/array.c
3120     +++ b/fs/proc/array.c
3121     @@ -212,7 +212,7 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
3122     group_info = cred->group_info;
3123     task_unlock(p);
3124    
3125     - for (g = 0; g < min(group_info->ngroups, NGROUPS_SMALL); g++)
3126     + for (g = 0; g < group_info->ngroups; g++)
3127     seq_printf(m, "%d ",
3128     from_kgid_munged(user_ns, GROUP_AT(group_info, g)));
3129     put_cred(cred);
3130     diff --git a/fs/splice.c b/fs/splice.c
3131     index 13e5b47..48c7bd1 100644
3132     --- a/fs/splice.c
3133     +++ b/fs/splice.c
3134     @@ -696,8 +696,10 @@ static int pipe_to_sendpage(struct pipe_inode_info *pipe,
3135     return -EINVAL;
3136    
3137     more = (sd->flags & SPLICE_F_MORE) ? MSG_MORE : 0;
3138     - if (sd->len < sd->total_len)
3139     +
3140     + if (sd->len < sd->total_len && pipe->nrbufs > 1)
3141     more |= MSG_SENDPAGE_NOTLAST;
3142     +
3143     return file->f_op->sendpage(file, buf->page, buf->offset,
3144     sd->len, &pos, more);
3145     }
3146     diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
3147     index e57e2da..e0e9ee0 100644
3148     --- a/fs/xfs/xfs_aops.c
3149     +++ b/fs/xfs/xfs_aops.c
3150     @@ -124,7 +124,7 @@ xfs_setfilesize_trans_alloc(
3151     ioend->io_append_trans = tp;
3152    
3153     /*
3154     - * We will pass freeze protection with a transaction. So tell lockdep
3155     + * We may pass freeze protection with a transaction. So tell lockdep
3156     * we released it.
3157     */
3158     rwsem_release(&ioend->io_inode->i_sb->s_writers.lock_map[SB_FREEZE_FS-1],
3159     @@ -149,11 +149,13 @@ xfs_setfilesize(
3160     xfs_fsize_t isize;
3161    
3162     /*
3163     - * The transaction was allocated in the I/O submission thread,
3164     - * thus we need to mark ourselves as beeing in a transaction
3165     - * manually.
3166     + * The transaction may have been allocated in the I/O submission thread,
3167     + * thus we need to mark ourselves as beeing in a transaction manually.
3168     + * Similarly for freeze protection.
3169     */
3170     current_set_flags_nested(&tp->t_pflags, PF_FSTRANS);
3171     + rwsem_acquire_read(&VFS_I(ip)->i_sb->s_writers.lock_map[SB_FREEZE_FS-1],
3172     + 0, 1, _THIS_IP_);
3173    
3174     xfs_ilock(ip, XFS_ILOCK_EXCL);
3175     isize = xfs_new_eof(ip, ioend->io_offset + ioend->io_size);
3176     @@ -187,7 +189,8 @@ xfs_finish_ioend(
3177    
3178     if (ioend->io_type == XFS_IO_UNWRITTEN)
3179     queue_work(mp->m_unwritten_workqueue, &ioend->io_work);
3180     - else if (ioend->io_append_trans)
3181     + else if (ioend->io_append_trans ||
3182     + (ioend->io_isdirect && xfs_ioend_is_append(ioend)))
3183     queue_work(mp->m_data_workqueue, &ioend->io_work);
3184     else
3185     xfs_destroy_ioend(ioend);
3186     @@ -205,15 +208,6 @@ xfs_end_io(
3187     struct xfs_inode *ip = XFS_I(ioend->io_inode);
3188     int error = 0;
3189    
3190     - if (ioend->io_append_trans) {
3191     - /*
3192     - * We've got freeze protection passed with the transaction.
3193     - * Tell lockdep about it.
3194     - */
3195     - rwsem_acquire_read(
3196     - &ioend->io_inode->i_sb->s_writers.lock_map[SB_FREEZE_FS-1],
3197     - 0, 1, _THIS_IP_);
3198     - }
3199     if (XFS_FORCED_SHUTDOWN(ip->i_mount)) {
3200     ioend->io_error = -EIO;
3201     goto done;
3202     @@ -226,35 +220,31 @@ xfs_end_io(
3203     * range to normal written extens after the data I/O has finished.
3204     */
3205     if (ioend->io_type == XFS_IO_UNWRITTEN) {
3206     + error = xfs_iomap_write_unwritten(ip, ioend->io_offset,
3207     + ioend->io_size);
3208     + } else if (ioend->io_isdirect && xfs_ioend_is_append(ioend)) {
3209     /*
3210     - * For buffered I/O we never preallocate a transaction when
3211     - * doing the unwritten extent conversion, but for direct I/O
3212     - * we do not know if we are converting an unwritten extent
3213     - * or not at the point where we preallocate the transaction.
3214     + * For direct I/O we do not know if we need to allocate blocks
3215     + * or not so we can't preallocate an append transaction as that
3216     + * results in nested reservations and log space deadlocks. Hence
3217     + * allocate the transaction here. While this is sub-optimal and
3218     + * can block IO completion for some time, we're stuck with doing
3219     + * it this way until we can pass the ioend to the direct IO
3220     + * allocation callbacks and avoid nesting that way.
3221     */
3222     - if (ioend->io_append_trans) {
3223     - ASSERT(ioend->io_isdirect);
3224     -
3225     - current_set_flags_nested(
3226     - &ioend->io_append_trans->t_pflags, PF_FSTRANS);
3227     - xfs_trans_cancel(ioend->io_append_trans, 0);
3228     - }
3229     -
3230     - error = xfs_iomap_write_unwritten(ip, ioend->io_offset,
3231     - ioend->io_size);
3232     - if (error) {
3233     - ioend->io_error = -error;
3234     + error = xfs_setfilesize_trans_alloc(ioend);
3235     + if (error)
3236     goto done;
3237     - }
3238     + error = xfs_setfilesize(ioend);
3239     } else if (ioend->io_append_trans) {
3240     error = xfs_setfilesize(ioend);
3241     - if (error)
3242     - ioend->io_error = -error;
3243     } else {
3244     ASSERT(!xfs_ioend_is_append(ioend));
3245     }
3246    
3247     done:
3248     + if (error)
3249     + ioend->io_error = -error;
3250     xfs_destroy_ioend(ioend);
3251     }
3252    
3253     @@ -1432,25 +1422,21 @@ xfs_vm_direct_IO(
3254     size_t size = iov_length(iov, nr_segs);
3255    
3256     /*
3257     - * We need to preallocate a transaction for a size update
3258     - * here. In the case that this write both updates the size
3259     - * and converts at least on unwritten extent we will cancel
3260     - * the still clean transaction after the I/O has finished.
3261     + * We cannot preallocate a size update transaction here as we
3262     + * don't know whether allocation is necessary or not. Hence we
3263     + * can only tell IO completion that one is necessary if we are
3264     + * not doing unwritten extent conversion.
3265     */
3266     iocb->private = ioend = xfs_alloc_ioend(inode, XFS_IO_DIRECT);
3267     - if (offset + size > XFS_I(inode)->i_d.di_size) {
3268     - ret = xfs_setfilesize_trans_alloc(ioend);
3269     - if (ret)
3270     - goto out_destroy_ioend;
3271     + if (offset + size > XFS_I(inode)->i_d.di_size)
3272     ioend->io_isdirect = 1;
3273     - }
3274    
3275     ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iov,
3276     offset, nr_segs,
3277     xfs_get_blocks_direct,
3278     xfs_end_io_direct_write, NULL, 0);
3279     if (ret != -EIOCBQUEUED && iocb->private)
3280     - goto out_trans_cancel;
3281     + goto out_destroy_ioend;
3282     } else {
3283     ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iov,
3284     offset, nr_segs,
3285     @@ -1460,15 +1446,6 @@ xfs_vm_direct_IO(
3286    
3287     return ret;
3288    
3289     -out_trans_cancel:
3290     - if (ioend->io_append_trans) {
3291     - current_set_flags_nested(&ioend->io_append_trans->t_pflags,
3292     - PF_FSTRANS);
3293     - rwsem_acquire_read(
3294     - &inode->i_sb->s_writers.lock_map[SB_FREEZE_FS-1],
3295     - 0, 1, _THIS_IP_);
3296     - xfs_trans_cancel(ioend->io_append_trans, 0);
3297     - }
3298     out_destroy_ioend:
3299     xfs_destroy_ioend(ioend);
3300     return ret;
3301     diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
3302     index 4dad756..a54c292 100644
3303     --- a/fs/xfs/xfs_log.c
3304     +++ b/fs/xfs/xfs_log.c
3305     @@ -458,7 +458,8 @@ xfs_log_reserve(
3306     tic->t_trans_type = t_type;
3307     *ticp = tic;
3308    
3309     - xlog_grant_push_ail(log, tic->t_unit_res * tic->t_cnt);
3310     + xlog_grant_push_ail(log, tic->t_cnt ? tic->t_unit_res * tic->t_cnt
3311     + : tic->t_unit_res);
3312    
3313     trace_xfs_log_reserve(log, tic);
3314    
3315     diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
3316     index 2e86fa0..335a340 100644
3317     --- a/fs/xfs/xfs_qm.c
3318     +++ b/fs/xfs/xfs_qm.c
3319     @@ -1453,7 +1453,7 @@ xfs_qm_dqreclaim_one(
3320     int error;
3321    
3322     if (!xfs_dqlock_nowait(dqp))
3323     - goto out_busy;
3324     + goto out_move_tail;
3325    
3326     /*
3327     * This dquot has acquired a reference in the meantime remove it from
3328     @@ -1476,7 +1476,7 @@ xfs_qm_dqreclaim_one(
3329     * getting flushed to disk, we don't want to reclaim it.
3330     */
3331     if (!xfs_dqflock_nowait(dqp))
3332     - goto out_busy;
3333     + goto out_unlock_move_tail;
3334    
3335     if (XFS_DQ_IS_DIRTY(dqp)) {
3336     struct xfs_buf *bp = NULL;
3337     @@ -1487,7 +1487,7 @@ xfs_qm_dqreclaim_one(
3338     if (error) {
3339     xfs_warn(mp, "%s: dquot %p flush failed",
3340     __func__, dqp);
3341     - goto out_busy;
3342     + goto out_unlock_move_tail;
3343     }
3344    
3345     xfs_buf_delwri_queue(bp, buffer_list);
3346     @@ -1496,7 +1496,7 @@ xfs_qm_dqreclaim_one(
3347     * Give the dquot another try on the freelist, as the
3348     * flushing will take some time.
3349     */
3350     - goto out_busy;
3351     + goto out_unlock_move_tail;
3352     }
3353     xfs_dqfunlock(dqp);
3354    
3355     @@ -1515,14 +1515,13 @@ xfs_qm_dqreclaim_one(
3356     XFS_STATS_INC(xs_qm_dqreclaims);
3357     return;
3358    
3359     -out_busy:
3360     - xfs_dqunlock(dqp);
3361     -
3362     /*
3363     * Move the dquot to the tail of the list so that we don't spin on it.
3364     */
3365     +out_unlock_move_tail:
3366     + xfs_dqunlock(dqp);
3367     +out_move_tail:
3368     list_move_tail(&dqp->q_lru, &qi->qi_lru_list);
3369     -
3370     trace_xfs_dqreclaim_busy(dqp);
3371     XFS_STATS_INC(xs_qm_dqreclaim_misses);
3372     }
3373     diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
3374     index ed6642a..25f01d0 100644
3375     --- a/include/asm-generic/tlb.h
3376     +++ b/include/asm-generic/tlb.h
3377     @@ -78,6 +78,14 @@ struct mmu_gather_batch {
3378     #define MAX_GATHER_BATCH \
3379     ((PAGE_SIZE - sizeof(struct mmu_gather_batch)) / sizeof(void *))
3380    
3381     +/*
3382     + * Limit the maximum number of mmu_gather batches to reduce a risk of soft
3383     + * lockups for non-preemptible kernels on huge machines when a lot of memory
3384     + * is zapped during unmapping.
3385     + * 10K pages freed at once should be safe even without a preemption point.
3386     + */
3387     +#define MAX_GATHER_BATCH_COUNT (10000UL/MAX_GATHER_BATCH)
3388     +
3389     /* struct mmu_gather is an opaque type used by the mm code for passing around
3390     * any data needed by arch specific code for tlb_remove_page.
3391     */
3392     @@ -96,6 +104,7 @@ struct mmu_gather {
3393     struct mmu_gather_batch *active;
3394     struct mmu_gather_batch local;
3395     struct page *__pages[MMU_GATHER_BUNDLE];
3396     + unsigned int batch_count;
3397     };
3398    
3399     #define HAVE_GENERIC_MMU_GATHER
3400     diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
3401     index cfcc6bf..de0628e 100644
3402     --- a/include/linux/binfmts.h
3403     +++ b/include/linux/binfmts.h
3404     @@ -114,6 +114,7 @@ extern int setup_arg_pages(struct linux_binprm * bprm,
3405     unsigned long stack_top,
3406     int executable_stack);
3407     extern int bprm_mm_init(struct linux_binprm *bprm);
3408     +extern int bprm_change_interp(char *interp, struct linux_binprm *bprm);
3409     extern int copy_strings_kernel(int argc, const char *const *argv,
3410     struct linux_binprm *bprm);
3411     extern int prepare_bprm_creds(struct linux_binprm *bprm);
3412     diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
3413     index f8a030c..4cd1d0f 100644
3414     --- a/include/linux/cgroup.h
3415     +++ b/include/linux/cgroup.h
3416     @@ -34,7 +34,6 @@ extern int cgroup_lock_is_held(void);
3417     extern bool cgroup_lock_live_group(struct cgroup *cgrp);
3418     extern void cgroup_unlock(void);
3419     extern void cgroup_fork(struct task_struct *p);
3420     -extern void cgroup_fork_callbacks(struct task_struct *p);
3421     extern void cgroup_post_fork(struct task_struct *p);
3422     extern void cgroup_exit(struct task_struct *p, int run_callbacks);
3423     extern int cgroupstats_build(struct cgroupstats *stats,
3424     diff --git a/include/linux/freezer.h b/include/linux/freezer.h
3425     index d09af4b..ee89932 100644
3426     --- a/include/linux/freezer.h
3427     +++ b/include/linux/freezer.h
3428     @@ -75,28 +75,62 @@ static inline bool cgroup_freezing(struct task_struct *task)
3429     */
3430    
3431    
3432     -/* Tell the freezer not to count the current task as freezable. */
3433     +/**
3434     + * freezer_do_not_count - tell freezer to ignore %current
3435     + *
3436     + * Tell freezers to ignore the current task when determining whether the
3437     + * target frozen state is reached. IOW, the current task will be
3438     + * considered frozen enough by freezers.
3439     + *
3440     + * The caller shouldn't do anything which isn't allowed for a frozen task
3441     + * until freezer_cont() is called. Usually, freezer[_do_not]_count() pair
3442     + * wrap a scheduling operation and nothing much else.
3443     + */
3444     static inline void freezer_do_not_count(void)
3445     {
3446     current->flags |= PF_FREEZER_SKIP;
3447     }
3448    
3449     -/*
3450     - * Tell the freezer to count the current task as freezable again and try to
3451     - * freeze it.
3452     +/**
3453     + * freezer_count - tell freezer to stop ignoring %current
3454     + *
3455     + * Undo freezer_do_not_count(). It tells freezers that %current should be
3456     + * considered again and tries to freeze if freezing condition is already in
3457     + * effect.
3458     */
3459     static inline void freezer_count(void)
3460     {
3461     current->flags &= ~PF_FREEZER_SKIP;
3462     + /*
3463     + * If freezing is in progress, the following paired with smp_mb()
3464     + * in freezer_should_skip() ensures that either we see %true
3465     + * freezing() or freezer_should_skip() sees !PF_FREEZER_SKIP.
3466     + */
3467     + smp_mb();
3468     try_to_freeze();
3469     }
3470    
3471     -/*
3472     - * Check if the task should be counted as freezable by the freezer
3473     +/**
3474     + * freezer_should_skip - whether to skip a task when determining frozen
3475     + * state is reached
3476     + * @p: task in quesion
3477     + *
3478     + * This function is used by freezers after establishing %true freezing() to
3479     + * test whether a task should be skipped when determining the target frozen
3480     + * state is reached. IOW, if this function returns %true, @p is considered
3481     + * frozen enough.
3482     */
3483     -static inline int freezer_should_skip(struct task_struct *p)
3484     +static inline bool freezer_should_skip(struct task_struct *p)
3485     {
3486     - return !!(p->flags & PF_FREEZER_SKIP);
3487     + /*
3488     + * The following smp_mb() paired with the one in freezer_count()
3489     + * ensures that either freezer_count() sees %true freezing() or we
3490     + * see cleared %PF_FREEZER_SKIP and return %false. This makes it
3491     + * impossible for a task to slip frozen state testing after
3492     + * clearing %PF_FREEZER_SKIP.
3493     + */
3494     + smp_mb();
3495     + return p->flags & PF_FREEZER_SKIP;
3496     }
3497    
3498     /*
3499     diff --git a/include/linux/hugetlb_cgroup.h b/include/linux/hugetlb_cgroup.h
3500     index d73878c..ce8217f 100644
3501     --- a/include/linux/hugetlb_cgroup.h
3502     +++ b/include/linux/hugetlb_cgroup.h
3503     @@ -62,7 +62,7 @@ extern void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
3504     struct page *page);
3505     extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
3506     struct hugetlb_cgroup *h_cg);
3507     -extern int hugetlb_cgroup_file_init(int idx) __init;
3508     +extern void hugetlb_cgroup_file_init(void) __init;
3509     extern void hugetlb_cgroup_migrate(struct page *oldhpage,
3510     struct page *newhpage);
3511    
3512     @@ -111,9 +111,8 @@ hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
3513     return;
3514     }
3515    
3516     -static inline int __init hugetlb_cgroup_file_init(int idx)
3517     +static inline void hugetlb_cgroup_file_init(void)
3518     {
3519     - return 0;
3520     }
3521    
3522     static inline void hugetlb_cgroup_migrate(struct page *oldhpage,
3523     diff --git a/include/linux/kernel.h b/include/linux/kernel.h
3524     index 7d8dfc7..b35fd0d 100644
3525     --- a/include/linux/kernel.h
3526     +++ b/include/linux/kernel.h
3527     @@ -77,13 +77,15 @@
3528    
3529     /*
3530     * Divide positive or negative dividend by positive divisor and round
3531     - * to closest integer. Result is undefined for negative divisors.
3532     + * to closest integer. Result is undefined for negative divisors and
3533     + * for negative dividends if the divisor variable type is unsigned.
3534     */
3535     #define DIV_ROUND_CLOSEST(x, divisor)( \
3536     { \
3537     typeof(x) __x = x; \
3538     typeof(divisor) __d = divisor; \
3539     - (((typeof(x))-1) > 0 || (__x) > 0) ? \
3540     + (((typeof(x))-1) > 0 || \
3541     + ((typeof(divisor))-1) > 0 || (__x) > 0) ? \
3542     (((__x) + ((__d) / 2)) / (__d)) : \
3543     (((__x) - ((__d) / 2)) / (__d)); \
3544     } \
3545     diff --git a/include/linux/libata.h b/include/linux/libata.h
3546     index 77eeeda..e931c9a 100644
3547     --- a/include/linux/libata.h
3548     +++ b/include/linux/libata.h
3549     @@ -163,6 +163,7 @@ enum {
3550    
3551     ATA_DFLAG_DA = (1 << 26), /* device supports Device Attention */
3552     ATA_DFLAG_DEVSLP = (1 << 27), /* device supports Device Sleep */
3553     + ATA_DFLAG_ACPI_DISABLED = (1 << 28), /* ACPI for the device is disabled */
3554    
3555     ATA_DEV_UNKNOWN = 0, /* unknown device */
3556     ATA_DEV_ATA = 1, /* ATA device */
3557     diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
3558     index b5d1384..70473da 100644
3559     --- a/include/linux/page-flags.h
3560     +++ b/include/linux/page-flags.h
3561     @@ -362,7 +362,7 @@ static inline void ClearPageCompound(struct page *page)
3562     * pages on the LRU and/or pagecache.
3563     */
3564     TESTPAGEFLAG(Compound, compound)
3565     -__PAGEFLAG(Head, compound)
3566     +__SETPAGEFLAG(Head, compound) __CLEARPAGEFLAG(Head, compound)
3567    
3568     /*
3569     * PG_reclaim is used in combination with PG_compound to mark the
3570     @@ -374,8 +374,14 @@ __PAGEFLAG(Head, compound)
3571     * PG_compound & PG_reclaim => Tail page
3572     * PG_compound & ~PG_reclaim => Head page
3573     */
3574     +#define PG_head_mask ((1L << PG_compound))
3575     #define PG_head_tail_mask ((1L << PG_compound) | (1L << PG_reclaim))
3576    
3577     +static inline int PageHead(struct page *page)
3578     +{
3579     + return ((page->flags & PG_head_tail_mask) == PG_head_mask);
3580     +}
3581     +
3582     static inline int PageTail(struct page *page)
3583     {
3584     return ((page->flags & PG_head_tail_mask) == PG_head_tail_mask);
3585     diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
3586     index 9d36b82..d16ad56 100644
3587     --- a/include/linux/pci_ids.h
3588     +++ b/include/linux/pci_ids.h
3589     @@ -1568,6 +1568,7 @@
3590     #define PCI_DEVICE_ID_RICOH_RL5C476 0x0476
3591     #define PCI_DEVICE_ID_RICOH_RL5C478 0x0478
3592     #define PCI_DEVICE_ID_RICOH_R5C822 0x0822
3593     +#define PCI_DEVICE_ID_RICOH_R5CE822 0xe822
3594     #define PCI_DEVICE_ID_RICOH_R5CE823 0xe823
3595     #define PCI_DEVICE_ID_RICOH_R5C832 0x0832
3596     #define PCI_DEVICE_ID_RICOH_R5C843 0x0843
3597     diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
3598     index 4fd8a4b..e5062c9 100644
3599     --- a/include/net/gro_cells.h
3600     +++ b/include/net/gro_cells.h
3601     @@ -17,7 +17,6 @@ struct gro_cells {
3602    
3603     static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)
3604     {
3605     - unsigned long flags;
3606     struct gro_cell *cell = gcells->cells;
3607     struct net_device *dev = skb->dev;
3608    
3609     @@ -35,32 +34,37 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
3610     return;
3611     }
3612    
3613     - spin_lock_irqsave(&cell->napi_skbs.lock, flags);
3614     + /* We run in BH context */
3615     + spin_lock(&cell->napi_skbs.lock);
3616    
3617     __skb_queue_tail(&cell->napi_skbs, skb);
3618     if (skb_queue_len(&cell->napi_skbs) == 1)
3619     napi_schedule(&cell->napi);
3620    
3621     - spin_unlock_irqrestore(&cell->napi_skbs.lock, flags);
3622     + spin_unlock(&cell->napi_skbs.lock);
3623     }
3624    
3625     +/* called unser BH context */
3626     static inline int gro_cell_poll(struct napi_struct *napi, int budget)
3627     {
3628     struct gro_cell *cell = container_of(napi, struct gro_cell, napi);
3629     struct sk_buff *skb;
3630     int work_done = 0;
3631    
3632     + spin_lock(&cell->napi_skbs.lock);
3633     while (work_done < budget) {
3634     - skb = skb_dequeue(&cell->napi_skbs);
3635     + skb = __skb_dequeue(&cell->napi_skbs);
3636     if (!skb)
3637     break;
3638     -
3639     + spin_unlock(&cell->napi_skbs.lock);
3640     napi_gro_receive(napi, skb);
3641     work_done++;
3642     + spin_lock(&cell->napi_skbs.lock);
3643     }
3644    
3645     if (work_done < budget)
3646     napi_complete(napi);
3647     + spin_unlock(&cell->napi_skbs.lock);
3648     return work_done;
3649     }
3650    
3651     diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
3652     index ba1d361..1832927 100644
3653     --- a/include/net/inet_connection_sock.h
3654     +++ b/include/net/inet_connection_sock.h
3655     @@ -318,6 +318,7 @@ extern void inet_csk_reqsk_queue_prune(struct sock *parent,
3656     const unsigned long max_rto);
3657    
3658     extern void inet_csk_destroy_sock(struct sock *sk);
3659     +extern void inet_csk_prepare_forced_close(struct sock *sk);
3660    
3661     /*
3662     * LISTEN is a special case for poll..
3663     diff --git a/include/net/ndisc.h b/include/net/ndisc.h
3664     index 980d263..6b305d7 100644
3665     --- a/include/net/ndisc.h
3666     +++ b/include/net/ndisc.h
3667     @@ -78,6 +78,13 @@ struct ra_msg {
3668     __be32 retrans_timer;
3669     };
3670    
3671     +struct rd_msg {
3672     + struct icmp6hdr icmph;
3673     + struct in6_addr target;
3674     + struct in6_addr dest;
3675     + __u8 opt[0];
3676     +};
3677     +
3678     struct nd_opt_hdr {
3679     __u8 nd_opt_type;
3680     __u8 nd_opt_len;
3681     diff --git a/kernel/cgroup.c b/kernel/cgroup.c
3682     index f24f724..ad99830 100644
3683     --- a/kernel/cgroup.c
3684     +++ b/kernel/cgroup.c
3685     @@ -2744,9 +2744,7 @@ static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry,
3686     dentry->d_fsdata = cgrp;
3687     inc_nlink(parent->d_inode);
3688     rcu_assign_pointer(cgrp->dentry, dentry);
3689     - dget(dentry);
3690     }
3691     - dput(dentry);
3692    
3693     return error;
3694     }
3695     @@ -2791,12 +2789,6 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cgroup_subsys *subsys,
3696    
3697     simple_xattrs_init(&cft->xattrs);
3698    
3699     - /* does @cft->flags tell us to skip creation on @cgrp? */
3700     - if ((cft->flags & CFTYPE_NOT_ON_ROOT) && !cgrp->parent)
3701     - return 0;
3702     - if ((cft->flags & CFTYPE_ONLY_ON_ROOT) && cgrp->parent)
3703     - return 0;
3704     -
3705     if (subsys && !test_bit(ROOT_NOPREFIX, &cgrp->root->flags)) {
3706     strcpy(name, subsys->name);
3707     strcat(name, ".");
3708     @@ -2837,6 +2829,12 @@ static int cgroup_addrm_files(struct cgroup *cgrp, struct cgroup_subsys *subsys,
3709     int err, ret = 0;
3710    
3711     for (cft = cfts; cft->name[0] != '\0'; cft++) {
3712     + /* does cft->flags tell us to skip this file on @cgrp? */
3713     + if ((cft->flags & CFTYPE_NOT_ON_ROOT) && !cgrp->parent)
3714     + continue;
3715     + if ((cft->flags & CFTYPE_ONLY_ON_ROOT) && cgrp->parent)
3716     + continue;
3717     +
3718     if (is_add)
3719     err = cgroup_add_file(cgrp, subsys, cft);
3720     else
3721     @@ -4832,44 +4830,19 @@ void cgroup_fork(struct task_struct *child)
3722     }
3723    
3724     /**
3725     - * cgroup_fork_callbacks - run fork callbacks
3726     - * @child: the new task
3727     - *
3728     - * Called on a new task very soon before adding it to the
3729     - * tasklist. No need to take any locks since no-one can
3730     - * be operating on this task.
3731     - */
3732     -void cgroup_fork_callbacks(struct task_struct *child)
3733     -{
3734     - if (need_forkexit_callback) {
3735     - int i;
3736     - for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
3737     - struct cgroup_subsys *ss = subsys[i];
3738     -
3739     - /*
3740     - * forkexit callbacks are only supported for
3741     - * builtin subsystems.
3742     - */
3743     - if (!ss || ss->module)
3744     - continue;
3745     -
3746     - if (ss->fork)
3747     - ss->fork(child);
3748     - }
3749     - }
3750     -}
3751     -
3752     -/**
3753     * cgroup_post_fork - called on a new task after adding it to the task list
3754     * @child: the task in question
3755     *
3756     - * Adds the task to the list running through its css_set if necessary.
3757     - * Has to be after the task is visible on the task list in case we race
3758     - * with the first call to cgroup_iter_start() - to guarantee that the
3759     - * new task ends up on its list.
3760     + * Adds the task to the list running through its css_set if necessary and
3761     + * call the subsystem fork() callbacks. Has to be after the task is
3762     + * visible on the task list in case we race with the first call to
3763     + * cgroup_iter_start() - to guarantee that the new task ends up on its
3764     + * list.
3765     */
3766     void cgroup_post_fork(struct task_struct *child)
3767     {
3768     + int i;
3769     +
3770     /*
3771     * use_task_css_set_links is set to 1 before we walk the tasklist
3772     * under the tasklist_lock and we read it here after we added the child
3773     @@ -4889,7 +4862,30 @@ void cgroup_post_fork(struct task_struct *child)
3774     task_unlock(child);
3775     write_unlock(&css_set_lock);
3776     }
3777     +
3778     + /*
3779     + * Call ss->fork(). This must happen after @child is linked on
3780     + * css_set; otherwise, @child might change state between ->fork()
3781     + * and addition to css_set.
3782     + */
3783     + if (need_forkexit_callback) {
3784     + for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
3785     + struct cgroup_subsys *ss = subsys[i];
3786     +
3787     + /*
3788     + * fork/exit callbacks are supported only for
3789     + * builtin subsystems and we don't need further
3790     + * synchronization as they never go away.
3791     + */
3792     + if (!ss || ss->module)
3793     + continue;
3794     +
3795     + if (ss->fork)
3796     + ss->fork(child);
3797     + }
3798     + }
3799     }
3800     +
3801     /**
3802     * cgroup_exit - detach cgroup from exiting task
3803     * @tsk: pointer to task_struct of exiting process
3804     diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
3805     index b1724ce..12bfedb 100644
3806     --- a/kernel/cgroup_freezer.c
3807     +++ b/kernel/cgroup_freezer.c
3808     @@ -186,23 +186,15 @@ static void freezer_fork(struct task_struct *task)
3809     {
3810     struct freezer *freezer;
3811    
3812     - /*
3813     - * No lock is needed, since the task isn't on tasklist yet,
3814     - * so it can't be moved to another cgroup, which means the
3815     - * freezer won't be removed and will be valid during this
3816     - * function call. Nevertheless, apply RCU read-side critical
3817     - * section to suppress RCU lockdep false positives.
3818     - */
3819     rcu_read_lock();
3820     freezer = task_freezer(task);
3821     - rcu_read_unlock();
3822    
3823     /*
3824     * The root cgroup is non-freezable, so we can skip the
3825     * following check.
3826     */
3827     if (!freezer->css.cgroup->parent)
3828     - return;
3829     + goto out;
3830    
3831     spin_lock_irq(&freezer->lock);
3832     BUG_ON(freezer->state == CGROUP_FROZEN);
3833     @@ -210,7 +202,10 @@ static void freezer_fork(struct task_struct *task)
3834     /* Locking avoids race with FREEZING -> THAWED transitions. */
3835     if (freezer->state == CGROUP_FREEZING)
3836     freeze_task(task);
3837     +
3838     spin_unlock_irq(&freezer->lock);
3839     +out:
3840     + rcu_read_unlock();
3841     }
3842    
3843     /*
3844     diff --git a/kernel/fork.c b/kernel/fork.c
3845     index 8b20ab7..acc4cb6 100644
3846     --- a/kernel/fork.c
3847     +++ b/kernel/fork.c
3848     @@ -1135,7 +1135,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
3849     {
3850     int retval;
3851     struct task_struct *p;
3852     - int cgroup_callbacks_done = 0;
3853    
3854     if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
3855     return ERR_PTR(-EINVAL);
3856     @@ -1393,12 +1392,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
3857     INIT_LIST_HEAD(&p->thread_group);
3858     p->task_works = NULL;
3859    
3860     - /* Now that the task is set up, run cgroup callbacks if
3861     - * necessary. We need to run them before the task is visible
3862     - * on the tasklist. */
3863     - cgroup_fork_callbacks(p);
3864     - cgroup_callbacks_done = 1;
3865     -
3866     /* Need tasklist lock for parent etc handling! */
3867     write_lock_irq(&tasklist_lock);
3868    
3869     @@ -1503,7 +1496,7 @@ bad_fork_cleanup_cgroup:
3870     #endif
3871     if (clone_flags & CLONE_THREAD)
3872     threadgroup_change_end(current);
3873     - cgroup_exit(p, cgroup_callbacks_done);
3874     + cgroup_exit(p, 0);
3875     delayacct_tsk_free(p);
3876     module_put(task_thread_info(p)->exec_domain->module);
3877     bad_fork_cleanup_count:
3878     diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
3879     index 4c69326..e48caf8 100644
3880     --- a/kernel/irq/manage.c
3881     +++ b/kernel/irq/manage.c
3882     @@ -716,6 +716,7 @@ static void
3883     irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *action)
3884     {
3885     cpumask_var_t mask;
3886     + bool valid = true;
3887    
3888     if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags))
3889     return;
3890     @@ -730,10 +731,18 @@ irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *action)
3891     }
3892    
3893     raw_spin_lock_irq(&desc->lock);
3894     - cpumask_copy(mask, desc->irq_data.affinity);
3895     + /*
3896     + * This code is triggered unconditionally. Check the affinity
3897     + * mask pointer. For CPU_MASK_OFFSTACK=n this is optimized out.
3898     + */
3899     + if (desc->irq_data.affinity)
3900     + cpumask_copy(mask, desc->irq_data.affinity);
3901     + else
3902     + valid = false;
3903     raw_spin_unlock_irq(&desc->lock);
3904    
3905     - set_cpus_allowed_ptr(current, mask);
3906     + if (valid)
3907     + set_cpus_allowed_ptr(current, mask);
3908     free_cpumask_var(mask);
3909     }
3910     #else
3911     @@ -936,6 +945,16 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
3912     */
3913     get_task_struct(t);
3914     new->thread = t;
3915     + /*
3916     + * Tell the thread to set its affinity. This is
3917     + * important for shared interrupt handlers as we do
3918     + * not invoke setup_affinity() for the secondary
3919     + * handlers as everything is already set up. Even for
3920     + * interrupts marked with IRQF_NO_BALANCE this is
3921     + * correct as we want the thread to move to the cpu(s)
3922     + * on which the requesting code placed the interrupt.
3923     + */
3924     + set_bit(IRQTF_AFFINITY, &new->thread_flags);
3925     }
3926    
3927     if (!alloc_cpumask_var(&mask, GFP_KERNEL)) {
3928     diff --git a/kernel/printk.c b/kernel/printk.c
3929     index 2d607f4..f8e0b5a 100644
3930     --- a/kernel/printk.c
3931     +++ b/kernel/printk.c
3932     @@ -847,10 +847,11 @@ static size_t print_time(u64 ts, char *buf)
3933     if (!printk_time)
3934     return 0;
3935    
3936     + rem_nsec = do_div(ts, 1000000000);
3937     +
3938     if (!buf)
3939     - return 15;
3940     + return snprintf(NULL, 0, "[%5lu.000000] ", (unsigned long)ts);
3941    
3942     - rem_nsec = do_div(ts, 1000000000);
3943     return sprintf(buf, "[%5lu.%06lu] ",
3944     (unsigned long)ts, rem_nsec / 1000);
3945     }
3946     diff --git a/kernel/signal.c b/kernel/signal.c
3947     index 0af8868..e4d4014 100644
3948     --- a/kernel/signal.c
3949     +++ b/kernel/signal.c
3950     @@ -3221,6 +3221,7 @@ SYSCALL_DEFINE1(ssetmask, int, newmask)
3951     int old = current->blocked.sig[0];
3952     sigset_t newset;
3953    
3954     + siginitset(&newset, newmask);
3955     set_current_blocked(&newset);
3956    
3957     return old;
3958     diff --git a/lib/atomic64.c b/lib/atomic64.c
3959     index 9785378..08a4f06 100644
3960     --- a/lib/atomic64.c
3961     +++ b/lib/atomic64.c
3962     @@ -31,7 +31,11 @@
3963     static union {
3964     raw_spinlock_t lock;
3965     char pad[L1_CACHE_BYTES];
3966     -} atomic64_lock[NR_LOCKS] __cacheline_aligned_in_smp;
3967     +} atomic64_lock[NR_LOCKS] __cacheline_aligned_in_smp = {
3968     + [0 ... (NR_LOCKS - 1)] = {
3969     + .lock = __RAW_SPIN_LOCK_UNLOCKED(atomic64_lock.lock),
3970     + },
3971     +};
3972    
3973     static inline raw_spinlock_t *lock_addr(const atomic64_t *v)
3974     {
3975     @@ -173,14 +177,3 @@ int atomic64_add_unless(atomic64_t *v, long long a, long long u)
3976     return ret;
3977     }
3978     EXPORT_SYMBOL(atomic64_add_unless);
3979     -
3980     -static int init_atomic64_lock(void)
3981     -{
3982     - int i;
3983     -
3984     - for (i = 0; i < NR_LOCKS; ++i)
3985     - raw_spin_lock_init(&atomic64_lock[i].lock);
3986     - return 0;
3987     -}
3988     -
3989     -pure_initcall(init_atomic64_lock);
3990     diff --git a/mm/highmem.c b/mm/highmem.c
3991     index 2da13a5..09fc744 100644
3992     --- a/mm/highmem.c
3993     +++ b/mm/highmem.c
3994     @@ -105,6 +105,7 @@ struct page *kmap_to_page(void *vaddr)
3995    
3996     return virt_to_page(addr);
3997     }
3998     +EXPORT_SYMBOL(kmap_to_page);
3999    
4000     static void flush_all_zero_pkmaps(void)
4001     {
4002     diff --git a/mm/hugetlb.c b/mm/hugetlb.c
4003     index 59a0059..f198aca 100644
4004     --- a/mm/hugetlb.c
4005     +++ b/mm/hugetlb.c
4006     @@ -1906,14 +1906,12 @@ static int __init hugetlb_init(void)
4007     default_hstate.max_huge_pages = default_hstate_max_huge_pages;
4008    
4009     hugetlb_init_hstates();
4010     -
4011     gather_bootmem_prealloc();
4012     -
4013     report_hugepages();
4014    
4015     hugetlb_sysfs_init();
4016     -
4017     hugetlb_register_all_nodes();
4018     + hugetlb_cgroup_file_init();
4019    
4020     return 0;
4021     }
4022     @@ -1943,13 +1941,6 @@ void __init hugetlb_add_hstate(unsigned order)
4023     h->next_nid_to_free = first_node(node_states[N_HIGH_MEMORY]);
4024     snprintf(h->name, HSTATE_NAME_LEN, "hugepages-%lukB",
4025     huge_page_size(h)/1024);
4026     - /*
4027     - * Add cgroup control files only if the huge page consists
4028     - * of more than two normal pages. This is because we use
4029     - * page[2].lru.next for storing cgoup details.
4030     - */
4031     - if (order >= HUGETLB_CGROUP_MIN_ORDER)
4032     - hugetlb_cgroup_file_init(hugetlb_max_hstate - 1);
4033    
4034     parsed_hstate = h;
4035     }
4036     diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
4037     index a3f358f..a0143e5 100644
4038     --- a/mm/hugetlb_cgroup.c
4039     +++ b/mm/hugetlb_cgroup.c
4040     @@ -340,7 +340,7 @@ static char *mem_fmt(char *buf, int size, unsigned long hsize)
4041     return buf;
4042     }
4043    
4044     -int __init hugetlb_cgroup_file_init(int idx)
4045     +static void __init __hugetlb_cgroup_file_init(int idx)
4046     {
4047     char buf[32];
4048     struct cftype *cft;
4049     @@ -382,7 +382,22 @@ int __init hugetlb_cgroup_file_init(int idx)
4050    
4051     WARN_ON(cgroup_add_cftypes(&hugetlb_subsys, h->cgroup_files));
4052    
4053     - return 0;
4054     + return;
4055     +}
4056     +
4057     +void __init hugetlb_cgroup_file_init(void)
4058     +{
4059     + struct hstate *h;
4060     +
4061     + for_each_hstate(h) {
4062     + /*
4063     + * Add cgroup control files only if the huge page consists
4064     + * of more than two normal pages. This is because we use
4065     + * page[2].lru.next for storing cgroup details.
4066     + */
4067     + if (huge_page_order(h) >= HUGETLB_CGROUP_MIN_ORDER)
4068     + __hugetlb_cgroup_file_init(hstate_index(h));
4069     + }
4070     }
4071    
4072     /*
4073     diff --git a/mm/memory.c b/mm/memory.c
4074     index 221fc9f..f2973b2 100644
4075     --- a/mm/memory.c
4076     +++ b/mm/memory.c
4077     @@ -182,10 +182,14 @@ static int tlb_next_batch(struct mmu_gather *tlb)
4078     return 1;
4079     }
4080    
4081     + if (tlb->batch_count == MAX_GATHER_BATCH_COUNT)
4082     + return 0;
4083     +
4084     batch = (void *)__get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0);
4085     if (!batch)
4086     return 0;
4087    
4088     + tlb->batch_count++;
4089     batch->next = NULL;
4090     batch->nr = 0;
4091     batch->max = MAX_GATHER_BATCH;
4092     @@ -214,6 +218,7 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, bool fullmm)
4093     tlb->local.nr = 0;
4094     tlb->local.max = ARRAY_SIZE(tlb->__pages);
4095     tlb->active = &tlb->local;
4096     + tlb->batch_count = 0;
4097    
4098     #ifdef CONFIG_HAVE_RCU_TABLE_FREE
4099     tlb->batch = NULL;
4100     diff --git a/mm/mempolicy.c b/mm/mempolicy.c
4101     index 4ea600d..002c281 100644
4102     --- a/mm/mempolicy.c
4103     +++ b/mm/mempolicy.c
4104     @@ -2372,8 +2372,7 @@ void numa_default_policy(void)
4105     */
4106    
4107     /*
4108     - * "local" is pseudo-policy: MPOL_PREFERRED with MPOL_F_LOCAL flag
4109     - * Used only for mpol_parse_str() and mpol_to_str()
4110     + * "local" is implemented internally by MPOL_PREFERRED with MPOL_F_LOCAL flag.
4111     */
4112     #define MPOL_LOCAL MPOL_MAX
4113     static const char * const policy_modes[] =
4114     @@ -2388,28 +2387,21 @@ static const char * const policy_modes[] =
4115    
4116     #ifdef CONFIG_TMPFS
4117     /**
4118     - * mpol_parse_str - parse string to mempolicy
4119     + * mpol_parse_str - parse string to mempolicy, for tmpfs mpol mount option.
4120     * @str: string containing mempolicy to parse
4121     * @mpol: pointer to struct mempolicy pointer, returned on success.
4122     - * @no_context: flag whether to "contextualize" the mempolicy
4123     + * @unused: redundant argument, to be removed later.
4124     *
4125     * Format of input:
4126     * <mode>[=<flags>][:<nodelist>]
4127     *
4128     - * if @no_context is true, save the input nodemask in w.user_nodemask in
4129     - * the returned mempolicy. This will be used to "clone" the mempolicy in
4130     - * a specific context [cpuset] at a later time. Used to parse tmpfs mpol
4131     - * mount option. Note that if 'static' or 'relative' mode flags were
4132     - * specified, the input nodemask will already have been saved. Saving
4133     - * it again is redundant, but safe.
4134     - *
4135     * On success, returns 0, else 1
4136     */
4137     -int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
4138     +int mpol_parse_str(char *str, struct mempolicy **mpol, int unused)
4139     {
4140     struct mempolicy *new = NULL;
4141     unsigned short mode;
4142     - unsigned short uninitialized_var(mode_flags);
4143     + unsigned short mode_flags;
4144     nodemask_t nodes;
4145     char *nodelist = strchr(str, ':');
4146     char *flags = strchr(str, '=');
4147     @@ -2497,24 +2489,23 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
4148     if (IS_ERR(new))
4149     goto out;
4150    
4151     - if (no_context) {
4152     - /* save for contextualization */
4153     - new->w.user_nodemask = nodes;
4154     - } else {
4155     - int ret;
4156     - NODEMASK_SCRATCH(scratch);
4157     - if (scratch) {
4158     - task_lock(current);
4159     - ret = mpol_set_nodemask(new, &nodes, scratch);
4160     - task_unlock(current);
4161     - } else
4162     - ret = -ENOMEM;
4163     - NODEMASK_SCRATCH_FREE(scratch);
4164     - if (ret) {
4165     - mpol_put(new);
4166     - goto out;
4167     - }
4168     - }
4169     + /*
4170     + * Save nodes for mpol_to_str() to show the tmpfs mount options
4171     + * for /proc/mounts, /proc/pid/mounts and /proc/pid/mountinfo.
4172     + */
4173     + if (mode != MPOL_PREFERRED)
4174     + new->v.nodes = nodes;
4175     + else if (nodelist)
4176     + new->v.preferred_node = first_node(nodes);
4177     + else
4178     + new->flags |= MPOL_F_LOCAL;
4179     +
4180     + /*
4181     + * Save nodes for contextualization: this will be used to "clone"
4182     + * the mempolicy in a specific context [cpuset] at a later time.
4183     + */
4184     + new->w.user_nodemask = nodes;
4185     +
4186     err = 0;
4187    
4188     out:
4189     @@ -2534,13 +2525,13 @@ out:
4190     * @buffer: to contain formatted mempolicy string
4191     * @maxlen: length of @buffer
4192     * @pol: pointer to mempolicy to be formatted
4193     - * @no_context: "context free" mempolicy - use nodemask in w.user_nodemask
4194     + * @unused: redundant argument, to be removed later.
4195     *
4196     * Convert a mempolicy into a string.
4197     * Returns the number of characters in buffer (if positive)
4198     * or an error (negative)
4199     */
4200     -int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
4201     +int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int unused)
4202     {
4203     char *p = buffer;
4204     int l;
4205     @@ -2566,7 +2557,7 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
4206     case MPOL_PREFERRED:
4207     nodes_clear(nodes);
4208     if (flags & MPOL_F_LOCAL)
4209     - mode = MPOL_LOCAL; /* pseudo-policy */
4210     + mode = MPOL_LOCAL;
4211     else
4212     node_set(pol->v.preferred_node, nodes);
4213     break;
4214     @@ -2574,10 +2565,7 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
4215     case MPOL_BIND:
4216     /* Fall through */
4217     case MPOL_INTERLEAVE:
4218     - if (no_context)
4219     - nodes = pol->w.user_nodemask;
4220     - else
4221     - nodes = pol->v.nodes;
4222     + nodes = pol->v.nodes;
4223     break;
4224    
4225     default:
4226     diff --git a/mm/page-writeback.c b/mm/page-writeback.c
4227     index 830893b..c0fa8bd 100644
4228     --- a/mm/page-writeback.c
4229     +++ b/mm/page-writeback.c
4230     @@ -201,6 +201,18 @@ static unsigned long highmem_dirtyable_memory(unsigned long total)
4231     zone_reclaimable_pages(z) - z->dirty_balance_reserve;
4232     }
4233     /*
4234     + * Unreclaimable memory (kernel memory or anonymous memory
4235     + * without swap) can bring down the dirtyable pages below
4236     + * the zone's dirty balance reserve and the above calculation
4237     + * will underflow. However we still want to add in nodes
4238     + * which are below threshold (negative values) to get a more
4239     + * accurate calculation but make sure that the total never
4240     + * underflows.
4241     + */
4242     + if ((long)x < 0)
4243     + x = 0;
4244     +
4245     + /*
4246     * Make sure that the number of highmem pages is never larger
4247     * than the number of the total dirtyable memory. This can only
4248     * occur in very strange VM situations but we want to make sure
4249     @@ -222,8 +234,8 @@ static unsigned long global_dirtyable_memory(void)
4250     {
4251     unsigned long x;
4252    
4253     - x = global_page_state(NR_FREE_PAGES) + global_reclaimable_pages() -
4254     - dirty_balance_reserve;
4255     + x = global_page_state(NR_FREE_PAGES) + global_reclaimable_pages();
4256     + x -= min(x, dirty_balance_reserve);
4257    
4258     if (!vm_highmem_is_dirtyable)
4259     x -= highmem_dirtyable_memory(x);
4260     @@ -290,9 +302,12 @@ static unsigned long zone_dirtyable_memory(struct zone *zone)
4261     * highmem zone can hold its share of dirty pages, so we don't
4262     * care about vm_highmem_is_dirtyable here.
4263     */
4264     - return zone_page_state(zone, NR_FREE_PAGES) +
4265     - zone_reclaimable_pages(zone) -
4266     - zone->dirty_balance_reserve;
4267     + unsigned long nr_pages = zone_page_state(zone, NR_FREE_PAGES) +
4268     + zone_reclaimable_pages(zone);
4269     +
4270     + /* don't allow this to underflow */
4271     + nr_pages -= min(nr_pages, zone->dirty_balance_reserve);
4272     + return nr_pages;
4273     }
4274    
4275     /**
4276     diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
4277     index 35b8911..fd05c81 100644
4278     --- a/net/9p/trans_virtio.c
4279     +++ b/net/9p/trans_virtio.c
4280     @@ -39,6 +39,7 @@
4281     #include <linux/inet.h>
4282     #include <linux/idr.h>
4283     #include <linux/file.h>
4284     +#include <linux/highmem.h>
4285     #include <linux/slab.h>
4286     #include <net/9p/9p.h>
4287     #include <linux/parser.h>
4288     @@ -325,7 +326,7 @@ static int p9_get_mapped_pages(struct virtio_chan *chan,
4289     int count = nr_pages;
4290     while (nr_pages) {
4291     s = rest_of_page(data);
4292     - pages[index++] = virt_to_page(data);
4293     + pages[index++] = kmap_to_page(data);
4294     data += s;
4295     nr_pages--;
4296     }
4297     diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
4298     index b02b75d..c6fcc76 100644
4299     --- a/net/batman-adv/bat_iv_ogm.c
4300     +++ b/net/batman-adv/bat_iv_ogm.c
4301     @@ -119,7 +119,7 @@ batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
4302     unsigned int msecs;
4303    
4304     msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
4305     - msecs += (random32() % 2 * BATADV_JITTER);
4306     + msecs += random32() % (2 * BATADV_JITTER);
4307    
4308     return jiffies + msecs_to_jiffies(msecs);
4309     }
4310     diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
4311     index a0a2f97..e48bfdb 100644
4312     --- a/net/bluetooth/hci_core.c
4313     +++ b/net/bluetooth/hci_core.c
4314     @@ -1793,6 +1793,8 @@ void hci_unregister_dev(struct hci_dev *hdev)
4315     for (i = 0; i < NUM_REASSEMBLY; i++)
4316     kfree_skb(hdev->reassembly[i]);
4317    
4318     + cancel_work_sync(&hdev->power_on);
4319     +
4320     if (!test_bit(HCI_INIT, &hdev->flags) &&
4321     !test_bit(HCI_SETUP, &hdev->dev_flags)) {
4322     hci_dev_lock(hdev);
4323     diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
4324     index b3226f3..868a909 100644
4325     --- a/net/bluetooth/rfcomm/sock.c
4326     +++ b/net/bluetooth/rfcomm/sock.c
4327     @@ -467,7 +467,7 @@ static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int f
4328     long timeo;
4329     int err = 0;
4330    
4331     - lock_sock(sk);
4332     + lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
4333    
4334     if (sk->sk_type != SOCK_STREAM) {
4335     err = -EINVAL;
4336     @@ -504,7 +504,7 @@ static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int f
4337    
4338     release_sock(sk);
4339     timeo = schedule_timeout(timeo);
4340     - lock_sock(sk);
4341     + lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
4342     }
4343     __set_current_state(TASK_RUNNING);
4344     remove_wait_queue(sk_sleep(sk), &wait);
4345     diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
4346     index dc42b91..caa109d 100644
4347     --- a/net/bluetooth/sco.c
4348     +++ b/net/bluetooth/sco.c
4349     @@ -131,15 +131,6 @@ static int sco_conn_del(struct hci_conn *hcon, int err)
4350     sco_sock_clear_timer(sk);
4351     sco_chan_del(sk, err);
4352     bh_unlock_sock(sk);
4353     -
4354     - sco_conn_lock(conn);
4355     - conn->sk = NULL;
4356     - sco_pi(sk)->conn = NULL;
4357     - sco_conn_unlock(conn);
4358     -
4359     - if (conn->hcon)
4360     - hci_conn_put(conn->hcon);
4361     -
4362     sco_sock_kill(sk);
4363     }
4364    
4365     @@ -830,6 +821,16 @@ static void sco_chan_del(struct sock *sk, int err)
4366    
4367     BT_DBG("sk %p, conn %p, err %d", sk, conn, err);
4368    
4369     + if (conn) {
4370     + sco_conn_lock(conn);
4371     + conn->sk = NULL;
4372     + sco_pi(sk)->conn = NULL;
4373     + sco_conn_unlock(conn);
4374     +
4375     + if (conn->hcon)
4376     + hci_conn_put(conn->hcon);
4377     + }
4378     +
4379     sk->sk_state = BT_CLOSED;
4380     sk->sk_err = err;
4381     sk->sk_state_change(sk);
4382     diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
4383     index 176ecdb..4f9f5eb 100644
4384     --- a/net/dccp/ipv4.c
4385     +++ b/net/dccp/ipv4.c
4386     @@ -439,8 +439,8 @@ exit:
4387     NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_LISTENDROPS);
4388     return NULL;
4389     put_and_exit:
4390     - bh_unlock_sock(newsk);
4391     - sock_put(newsk);
4392     + inet_csk_prepare_forced_close(newsk);
4393     + dccp_done(newsk);
4394     goto exit;
4395     }
4396    
4397     diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
4398     index 56840b2..6e05981 100644
4399     --- a/net/dccp/ipv6.c
4400     +++ b/net/dccp/ipv6.c
4401     @@ -585,7 +585,8 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
4402     newinet->inet_rcv_saddr = LOOPBACK4_IPV6;
4403    
4404     if (__inet_inherit_port(sk, newsk) < 0) {
4405     - sock_put(newsk);
4406     + inet_csk_prepare_forced_close(newsk);
4407     + dccp_done(newsk);
4408     goto out;
4409     }
4410     __inet6_hash(newsk, NULL);
4411     diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
4412     index d34ce29..13a13e8 100644
4413     --- a/net/ipv4/inet_connection_sock.c
4414     +++ b/net/ipv4/inet_connection_sock.c
4415     @@ -699,6 +699,22 @@ void inet_csk_destroy_sock(struct sock *sk)
4416     }
4417     EXPORT_SYMBOL(inet_csk_destroy_sock);
4418    
4419     +/* This function allows to force a closure of a socket after the call to
4420     + * tcp/dccp_create_openreq_child().
4421     + */
4422     +void inet_csk_prepare_forced_close(struct sock *sk)
4423     +{
4424     + /* sk_clone_lock locked the socket and set refcnt to 2 */
4425     + bh_unlock_sock(sk);
4426     + sock_put(sk);
4427     +
4428     + /* The below has to be done to allow calling inet_csk_destroy_sock */
4429     + sock_set_flag(sk, SOCK_DEAD);
4430     + percpu_counter_inc(sk->sk_prot->orphan_count);
4431     + inet_sk(sk)->inet_num = 0;
4432     +}
4433     +EXPORT_SYMBOL(inet_csk_prepare_forced_close);
4434     +
4435     int inet_csk_listen_start(struct sock *sk, const int nr_table_entries)
4436     {
4437     struct inet_sock *inet = inet_sk(sk);
4438     diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
4439     index 0c4a643..bc3cb46 100644
4440     --- a/net/ipv4/tcp_ipv4.c
4441     +++ b/net/ipv4/tcp_ipv4.c
4442     @@ -1774,10 +1774,8 @@ exit:
4443     NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_LISTENDROPS);
4444     return NULL;
4445     put_and_exit:
4446     - tcp_clear_xmit_timers(newsk);
4447     - tcp_cleanup_congestion_control(newsk);
4448     - bh_unlock_sock(newsk);
4449     - sock_put(newsk);
4450     + inet_csk_prepare_forced_close(newsk);
4451     + tcp_done(newsk);
4452     goto exit;
4453     }
4454     EXPORT_SYMBOL(tcp_v4_syn_recv_sock);
4455     diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
4456     index 2edce30..89dab79 100644
4457     --- a/net/ipv6/ndisc.c
4458     +++ b/net/ipv6/ndisc.c
4459     @@ -1333,6 +1333,12 @@ out:
4460    
4461     static void ndisc_redirect_rcv(struct sk_buff *skb)
4462     {
4463     + u8 *hdr;
4464     + struct ndisc_options ndopts;
4465     + struct rd_msg *msg = (struct rd_msg *)skb_transport_header(skb);
4466     + u32 ndoptlen = skb->tail - (skb->transport_header +
4467     + offsetof(struct rd_msg, opt));
4468     +
4469     #ifdef CONFIG_IPV6_NDISC_NODETYPE
4470     switch (skb->ndisc_nodetype) {
4471     case NDISC_NODETYPE_HOST:
4472     @@ -1349,6 +1355,17 @@ static void ndisc_redirect_rcv(struct sk_buff *skb)
4473     return;
4474     }
4475    
4476     + if (!ndisc_parse_options(msg->opt, ndoptlen, &ndopts))
4477     + return;
4478     +
4479     + if (!ndopts.nd_opts_rh)
4480     + return;
4481     +
4482     + hdr = (u8 *)ndopts.nd_opts_rh;
4483     + hdr += 8;
4484     + if (!pskb_pull(skb, hdr - skb_transport_header(skb)))
4485     + return;
4486     +
4487     icmpv6_notify(skb, NDISC_REDIRECT, 0, 0);
4488     }
4489    
4490     diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
4491     index 26175bf..73f2a6b 100644
4492     --- a/net/ipv6/tcp_ipv6.c
4493     +++ b/net/ipv6/tcp_ipv6.c
4494     @@ -1384,7 +1384,8 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
4495     #endif
4496    
4497     if (__inet_inherit_port(sk, newsk) < 0) {
4498     - sock_put(newsk);
4499     + inet_csk_prepare_forced_close(newsk);
4500     + tcp_done(newsk);
4501     goto out;
4502     }
4503     __inet6_hash(newsk, NULL);
4504     diff --git a/net/mac802154/wpan.c b/net/mac802154/wpan.c
4505     index f30f6d4..c5e24c8 100644
4506     --- a/net/mac802154/wpan.c
4507     +++ b/net/mac802154/wpan.c
4508     @@ -387,7 +387,7 @@ void mac802154_wpan_setup(struct net_device *dev)
4509    
4510     static int mac802154_process_data(struct net_device *dev, struct sk_buff *skb)
4511     {
4512     - return netif_rx(skb);
4513     + return netif_rx_ni(skb);
4514     }
4515    
4516     static int
4517     diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
4518     index 9d75b77..e9ea2f3 100644
4519     --- a/net/sched/sch_htb.c
4520     +++ b/net/sched/sch_htb.c
4521     @@ -874,7 +874,7 @@ ok:
4522     q->now = psched_get_time();
4523     start_at = jiffies;
4524    
4525     - next_event = q->now + 5 * PSCHED_TICKS_PER_SEC;
4526     + next_event = q->now + 5LLU * PSCHED_TICKS_PER_SEC;
4527    
4528     for (level = 0; level < TC_HTB_MAXDEPTH; level++) {
4529     /* common case optimization - skip event handler quickly */
4530     diff --git a/net/sctp/probe.c b/net/sctp/probe.c
4531     index bc6cd75..5f7518d 100644
4532     --- a/net/sctp/probe.c
4533     +++ b/net/sctp/probe.c
4534     @@ -122,7 +122,8 @@ static const struct file_operations sctpprobe_fops = {
4535     .llseek = noop_llseek,
4536     };
4537    
4538     -sctp_disposition_t jsctp_sf_eat_sack(const struct sctp_endpoint *ep,
4539     +sctp_disposition_t jsctp_sf_eat_sack(struct net *net,
4540     + const struct sctp_endpoint *ep,
4541     const struct sctp_association *asoc,
4542     const sctp_subtype_t type,
4543     void *arg,
4544     diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
4545     index f9d870e..a9652d6 100644
4546     --- a/sound/pci/hda/hda_intel.c
4547     +++ b/sound/pci/hda/hda_intel.c
4548     @@ -2557,10 +2557,6 @@ static int azx_runtime_suspend(struct device *dev)
4549     struct snd_card *card = dev_get_drvdata(dev);
4550     struct azx *chip = card->private_data;
4551    
4552     - if (!power_save_controller ||
4553     - !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
4554     - return -EAGAIN;
4555     -
4556     azx_stop_chip(chip);
4557     azx_clear_irq_pending(chip);
4558     return 0;
4559     @@ -2575,12 +2571,25 @@ static int azx_runtime_resume(struct device *dev)
4560     azx_init_chip(chip, 1);
4561     return 0;
4562     }
4563     +
4564     +static int azx_runtime_idle(struct device *dev)
4565     +{
4566     + struct snd_card *card = dev_get_drvdata(dev);
4567     + struct azx *chip = card->private_data;
4568     +
4569     + if (!power_save_controller ||
4570     + !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
4571     + return -EBUSY;
4572     +
4573     + return 0;
4574     +}
4575     +
4576     #endif /* CONFIG_PM_RUNTIME */
4577    
4578     #ifdef CONFIG_PM
4579     static const struct dev_pm_ops azx_pm = {
4580     SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume)
4581     - SET_RUNTIME_PM_OPS(azx_runtime_suspend, azx_runtime_resume, NULL)
4582     + SET_RUNTIME_PM_OPS(azx_runtime_suspend, azx_runtime_resume, azx_runtime_idle)
4583     };
4584    
4585     #define AZX_PM_OPS &azx_pm
4586     diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
4587     index 03b1dc3..a7b522a 100644
4588     --- a/sound/pci/hda/patch_conexant.c
4589     +++ b/sound/pci/hda/patch_conexant.c
4590     @@ -4453,6 +4453,7 @@ static const struct snd_pci_quirk cxt5051_fixups[] = {
4591     };
4592    
4593     static const struct snd_pci_quirk cxt5066_fixups[] = {
4594     + SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
4595     SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4596     SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4597     SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4598     diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
4599     index 71555cc..4642c68 100644
4600     --- a/sound/pci/hda/patch_hdmi.c
4601     +++ b/sound/pci/hda/patch_hdmi.c
4602     @@ -431,9 +431,11 @@ static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
4603     if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
4604     snd_hda_codec_write(codec, pin_nid, 0,
4605     AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
4606     - /* Disable pin out until stream is active*/
4607     + /* Enable pin out: some machines with GM965 gets broken output when
4608     + * the pin is disabled or changed while using with HDMI
4609     + */
4610     snd_hda_codec_write(codec, pin_nid, 0,
4611     - AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4612     + AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4613     }
4614    
4615     static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
4616     @@ -1338,7 +1340,6 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4617     struct hdmi_spec *spec = codec->spec;
4618     int pin_idx = hinfo_to_pin_index(spec, hinfo);
4619     hda_nid_t pin_nid = spec->pins[pin_idx].pin_nid;
4620     - int pinctl;
4621     bool non_pcm;
4622    
4623     non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
4624     @@ -1347,11 +1348,6 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4625    
4626     hdmi_setup_audio_infoframe(codec, pin_idx, non_pcm, substream);
4627    
4628     - pinctl = snd_hda_codec_read(codec, pin_nid, 0,
4629     - AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4630     - snd_hda_codec_write(codec, pin_nid, 0,
4631     - AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl | PIN_OUT);
4632     -
4633     return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
4634     }
4635    
4636     @@ -1371,7 +1367,6 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
4637     int cvt_idx, pin_idx;
4638     struct hdmi_spec_per_cvt *per_cvt;
4639     struct hdmi_spec_per_pin *per_pin;
4640     - int pinctl;
4641    
4642     if (hinfo->nid) {
4643     cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
4644     @@ -1388,11 +1383,6 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
4645     return -EINVAL;
4646     per_pin = &spec->pins[pin_idx];
4647    
4648     - pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
4649     - AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4650     - snd_hda_codec_write(codec, per_pin->pin_nid, 0,
4651     - AC_VERB_SET_PIN_WIDGET_CONTROL,
4652     - pinctl & ~PIN_OUT);
4653     snd_hda_spdif_ctls_unassign(codec, pin_idx);
4654     per_pin->chmap_set = false;
4655     memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
4656     diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
4657     index ad68d22..4bbabdc 100644
4658     --- a/sound/pci/hda/patch_realtek.c
4659     +++ b/sound/pci/hda/patch_realtek.c
4660     @@ -5986,6 +5986,30 @@ static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4661     spec->automute_hook = alc269_quanta_automute;
4662     }
4663    
4664     +/* update mute-LED according to the speaker mute state via mic1 VREF pin */
4665     +static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
4666     +{
4667     + struct hda_codec *codec = private_data;
4668     + unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
4669     + AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
4670     + snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
4671     +}
4672     +
4673     +static void alc269_fixup_mic1_mute(struct hda_codec *codec,
4674     + const struct alc_fixup *fix, int action)
4675     +{
4676     + struct alc_spec *spec = codec->spec;
4677     + switch (action) {
4678     + case ALC_FIXUP_ACT_BUILD:
4679     + spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
4680     + snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
4681     + /* fallthru */
4682     + case ALC_FIXUP_ACT_INIT:
4683     + snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4684     + break;
4685     + }
4686     +}
4687     +
4688     /* update mute-LED according to the speaker mute state via mic2 VREF pin */
4689     static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
4690     {
4691     @@ -6027,6 +6051,7 @@ enum {
4692     ALC269_FIXUP_DMIC,
4693     ALC269VB_FIXUP_AMIC,
4694     ALC269VB_FIXUP_DMIC,
4695     + ALC269_FIXUP_MIC1_MUTE_LED,
4696     ALC269_FIXUP_MIC2_MUTE_LED,
4697     ALC269_FIXUP_INV_DMIC,
4698     ALC269_FIXUP_LENOVO_DOCK,
4699     @@ -6153,6 +6178,10 @@ static const struct alc_fixup alc269_fixups[] = {
4700     { }
4701     },
4702     },
4703     + [ALC269_FIXUP_MIC1_MUTE_LED] = {
4704     + .type = ALC_FIXUP_FUNC,
4705     + .v.func = alc269_fixup_mic1_mute,
4706     + },
4707     [ALC269_FIXUP_MIC2_MUTE_LED] = {
4708     .type = ALC_FIXUP_FUNC,
4709     .v.func = alc269_fixup_mic2_mute,
4710     @@ -6181,6 +6210,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4711     SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
4712     SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
4713     SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
4714     + SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
4715     SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
4716     SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
4717     SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
4718     @@ -6535,8 +6565,8 @@ static void alc861vd_fixup_dallas(struct hda_codec *codec,
4719     const struct alc_fixup *fix, int action)
4720     {
4721     if (action == ALC_FIXUP_ACT_PRE_PROBE) {
4722     - snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
4723     - snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
4724     + snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
4725     + snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
4726     }
4727     }
4728    
4729     diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
4730     index 9ba8af0..f3bae20 100644
4731     --- a/sound/pci/hda/patch_sigmatel.c
4732     +++ b/sound/pci/hda/patch_sigmatel.c
4733     @@ -1724,7 +1724,7 @@ static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
4734     SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
4735     "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
4736     SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
4737     - "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
4738     + "HP Pavilion dv7", STAC_HP_DV7_4000),
4739     SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
4740     "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
4741     SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
4742     diff --git a/sound/usb/midi.c b/sound/usb/midi.c
4743     index eeefbce..34b9bb7 100644
4744     --- a/sound/usb/midi.c
4745     +++ b/sound/usb/midi.c
4746     @@ -116,6 +116,7 @@ struct snd_usb_midi {
4747     struct list_head list;
4748     struct timer_list error_timer;
4749     spinlock_t disc_lock;
4750     + struct rw_semaphore disc_rwsem;
4751     struct mutex mutex;
4752     u32 usb_id;
4753     int next_midi_device;
4754     @@ -125,8 +126,10 @@ struct snd_usb_midi {
4755     struct snd_usb_midi_in_endpoint *in;
4756     } endpoints[MIDI_MAX_ENDPOINTS];
4757     unsigned long input_triggered;
4758     - unsigned int opened;
4759     + bool autopm_reference;
4760     + unsigned int opened[2];
4761     unsigned char disconnected;
4762     + unsigned char input_running;
4763    
4764     struct snd_kcontrol *roland_load_ctl;
4765     };
4766     @@ -148,7 +151,6 @@ struct snd_usb_midi_out_endpoint {
4767     struct snd_usb_midi_out_endpoint* ep;
4768     struct snd_rawmidi_substream *substream;
4769     int active;
4770     - bool autopm_reference;
4771     uint8_t cable; /* cable number << 4 */
4772     uint8_t state;
4773     #define STATE_UNKNOWN 0
4774     @@ -1033,29 +1035,58 @@ static void update_roland_altsetting(struct snd_usb_midi* umidi)
4775     snd_usbmidi_input_start(&umidi->list);
4776     }
4777    
4778     -static void substream_open(struct snd_rawmidi_substream *substream, int open)
4779     +static int substream_open(struct snd_rawmidi_substream *substream, int dir,
4780     + int open)
4781     {
4782     struct snd_usb_midi* umidi = substream->rmidi->private_data;
4783     struct snd_kcontrol *ctl;
4784     + int err;
4785     +
4786     + down_read(&umidi->disc_rwsem);
4787     + if (umidi->disconnected) {
4788     + up_read(&umidi->disc_rwsem);
4789     + return open ? -ENODEV : 0;
4790     + }
4791    
4792     mutex_lock(&umidi->mutex);
4793     if (open) {
4794     - if (umidi->opened++ == 0 && umidi->roland_load_ctl) {
4795     - ctl = umidi->roland_load_ctl;
4796     - ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4797     - snd_ctl_notify(umidi->card,
4798     + if (!umidi->opened[0] && !umidi->opened[1]) {
4799     + err = usb_autopm_get_interface(umidi->iface);
4800     + umidi->autopm_reference = err >= 0;
4801     + if (err < 0 && err != -EACCES) {
4802     + mutex_unlock(&umidi->mutex);
4803     + up_read(&umidi->disc_rwsem);
4804     + return -EIO;
4805     + }
4806     + if (umidi->roland_load_ctl) {
4807     + ctl = umidi->roland_load_ctl;
4808     + ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4809     + snd_ctl_notify(umidi->card,
4810     SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
4811     - update_roland_altsetting(umidi);
4812     + update_roland_altsetting(umidi);
4813     + }
4814     }
4815     + umidi->opened[dir]++;
4816     + if (umidi->opened[1])
4817     + snd_usbmidi_input_start(&umidi->list);
4818     } else {
4819     - if (--umidi->opened == 0 && umidi->roland_load_ctl) {
4820     - ctl = umidi->roland_load_ctl;
4821     - ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4822     - snd_ctl_notify(umidi->card,
4823     + umidi->opened[dir]--;
4824     + if (!umidi->opened[1])
4825     + snd_usbmidi_input_stop(&umidi->list);
4826     + if (!umidi->opened[0] && !umidi->opened[1]) {
4827     + if (umidi->roland_load_ctl) {
4828     + ctl = umidi->roland_load_ctl;
4829     + ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4830     + snd_ctl_notify(umidi->card,
4831     SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
4832     + }
4833     + if (umidi->autopm_reference)
4834     + usb_autopm_put_interface(umidi->iface);
4835     }
4836     }
4837     mutex_unlock(&umidi->mutex);
4838     + up_read(&umidi->disc_rwsem);
4839     + return 0;
4840     }
4841    
4842     static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
4843     @@ -1063,7 +1094,6 @@ static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
4844     struct snd_usb_midi* umidi = substream->rmidi->private_data;
4845     struct usbmidi_out_port* port = NULL;
4846     int i, j;
4847     - int err;
4848    
4849     for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
4850     if (umidi->endpoints[i].out)
4851     @@ -1076,25 +1106,15 @@ static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
4852     snd_BUG();
4853     return -ENXIO;
4854     }
4855     - err = usb_autopm_get_interface(umidi->iface);
4856     - port->autopm_reference = err >= 0;
4857     - if (err < 0 && err != -EACCES)
4858     - return -EIO;
4859     +
4860     substream->runtime->private_data = port;
4861     port->state = STATE_UNKNOWN;
4862     - substream_open(substream, 1);
4863     - return 0;
4864     + return substream_open(substream, 0, 1);
4865     }
4866    
4867     static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream)
4868     {
4869     - struct snd_usb_midi* umidi = substream->rmidi->private_data;
4870     - struct usbmidi_out_port *port = substream->runtime->private_data;
4871     -
4872     - substream_open(substream, 0);
4873     - if (port->autopm_reference)
4874     - usb_autopm_put_interface(umidi->iface);
4875     - return 0;
4876     + return substream_open(substream, 0, 0);
4877     }
4878    
4879     static void snd_usbmidi_output_trigger(struct snd_rawmidi_substream *substream, int up)
4880     @@ -1147,14 +1167,12 @@ static void snd_usbmidi_output_drain(struct snd_rawmidi_substream *substream)
4881    
4882     static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream)
4883     {
4884     - substream_open(substream, 1);
4885     - return 0;
4886     + return substream_open(substream, 1, 1);
4887     }
4888    
4889     static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream)
4890     {
4891     - substream_open(substream, 0);
4892     - return 0;
4893     + return substream_open(substream, 1, 0);
4894     }
4895    
4896     static void snd_usbmidi_input_trigger(struct snd_rawmidi_substream *substream, int up)
4897     @@ -1403,9 +1421,12 @@ void snd_usbmidi_disconnect(struct list_head* p)
4898     * a timer may submit an URB. To reliably break the cycle
4899     * a flag under lock must be used
4900     */
4901     + down_write(&umidi->disc_rwsem);
4902     spin_lock_irq(&umidi->disc_lock);
4903     umidi->disconnected = 1;
4904     spin_unlock_irq(&umidi->disc_lock);
4905     + up_write(&umidi->disc_rwsem);
4906     +
4907     for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
4908     struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i];
4909     if (ep->out)
4910     @@ -2060,12 +2081,15 @@ void snd_usbmidi_input_stop(struct list_head* p)
4911     unsigned int i, j;
4912    
4913     umidi = list_entry(p, struct snd_usb_midi, list);
4914     + if (!umidi->input_running)
4915     + return;
4916     for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
4917     struct snd_usb_midi_endpoint* ep = &umidi->endpoints[i];
4918     if (ep->in)
4919     for (j = 0; j < INPUT_URBS; ++j)
4920     usb_kill_urb(ep->in->urbs[j]);
4921     }
4922     + umidi->input_running = 0;
4923     }
4924    
4925     static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep)
4926     @@ -2090,8 +2114,11 @@ void snd_usbmidi_input_start(struct list_head* p)
4927     int i;
4928    
4929     umidi = list_entry(p, struct snd_usb_midi, list);
4930     + if (umidi->input_running || !umidi->opened[1])
4931     + return;
4932     for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
4933     snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
4934     + umidi->input_running = 1;
4935     }
4936    
4937     /*
4938     @@ -2117,6 +2144,7 @@ int snd_usbmidi_create(struct snd_card *card,
4939     umidi->usb_protocol_ops = &snd_usbmidi_standard_ops;
4940     init_timer(&umidi->error_timer);
4941     spin_lock_init(&umidi->disc_lock);
4942     + init_rwsem(&umidi->disc_rwsem);
4943     mutex_init(&umidi->mutex);
4944     umidi->usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor),
4945     le16_to_cpu(umidi->dev->descriptor.idProduct));
4946     @@ -2229,9 +2257,6 @@ int snd_usbmidi_create(struct snd_card *card,
4947     }
4948    
4949     list_add_tail(&umidi->list, midi_list);
4950     -
4951     - for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
4952     - snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
4953     return 0;
4954     }
4955