Magellan Linux

Contents of /trunk/kernel-alx/patches-4.4/0101-4.4.2-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2793 - (show annotations) (download)
Mon May 30 12:45:29 2016 UTC (7 years, 10 months ago) by niro
File size: 169991 byte(s)
-linux-4.4.2
1 diff --git a/Makefile b/Makefile
2 index c6a265b52c93..e7a2958eb771 100644
3 --- a/Makefile
4 +++ b/Makefile
5 @@ -1,6 +1,6 @@
6 VERSION = 4
7 PATCHLEVEL = 4
8 -SUBLEVEL = 1
9 +SUBLEVEL = 2
10 EXTRAVERSION =
11 NAME = Blurry Fish Butt
12
13 diff --git a/arch/parisc/include/asm/hugetlb.h b/arch/parisc/include/asm/hugetlb.h
14 index 7d56a9ccb752..a65d888716c4 100644
15 --- a/arch/parisc/include/asm/hugetlb.h
16 +++ b/arch/parisc/include/asm/hugetlb.h
17 @@ -54,24 +54,12 @@ static inline pte_t huge_pte_wrprotect(pte_t pte)
18 return pte_wrprotect(pte);
19 }
20
21 -static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
22 - unsigned long addr, pte_t *ptep)
23 -{
24 - pte_t old_pte = *ptep;
25 - set_huge_pte_at(mm, addr, ptep, pte_wrprotect(old_pte));
26 -}
27 +void huge_ptep_set_wrprotect(struct mm_struct *mm,
28 + unsigned long addr, pte_t *ptep);
29
30 -static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
31 +int huge_ptep_set_access_flags(struct vm_area_struct *vma,
32 unsigned long addr, pte_t *ptep,
33 - pte_t pte, int dirty)
34 -{
35 - int changed = !pte_same(*ptep, pte);
36 - if (changed) {
37 - set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
38 - flush_tlb_page(vma, addr);
39 - }
40 - return changed;
41 -}
42 + pte_t pte, int dirty);
43
44 static inline pte_t huge_ptep_get(pte_t *ptep)
45 {
46 diff --git a/arch/parisc/include/uapi/asm/siginfo.h b/arch/parisc/include/uapi/asm/siginfo.h
47 index d7034728f377..1c75565d984b 100644
48 --- a/arch/parisc/include/uapi/asm/siginfo.h
49 +++ b/arch/parisc/include/uapi/asm/siginfo.h
50 @@ -1,6 +1,10 @@
51 #ifndef _PARISC_SIGINFO_H
52 #define _PARISC_SIGINFO_H
53
54 +#if defined(__LP64__)
55 +#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
56 +#endif
57 +
58 #include <asm-generic/siginfo.h>
59
60 #undef NSIGTRAP
61 diff --git a/arch/parisc/mm/hugetlbpage.c b/arch/parisc/mm/hugetlbpage.c
62 index f6fdc77a72bd..54ba39262b82 100644
63 --- a/arch/parisc/mm/hugetlbpage.c
64 +++ b/arch/parisc/mm/hugetlbpage.c
65 @@ -105,15 +105,13 @@ static inline void purge_tlb_entries_huge(struct mm_struct *mm, unsigned long ad
66 addr |= _HUGE_PAGE_SIZE_ENCODING_DEFAULT;
67
68 for (i = 0; i < (1 << (HPAGE_SHIFT-REAL_HPAGE_SHIFT)); i++) {
69 - mtsp(mm->context, 1);
70 - pdtlb(addr);
71 - if (unlikely(split_tlb))
72 - pitlb(addr);
73 + purge_tlb_entries(mm, addr);
74 addr += (1UL << REAL_HPAGE_SHIFT);
75 }
76 }
77
78 -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
79 +/* __set_huge_pte_at() must be called holding the pa_tlb_lock. */
80 +static void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
81 pte_t *ptep, pte_t entry)
82 {
83 unsigned long addr_start;
84 @@ -123,14 +121,9 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
85 addr_start = addr;
86
87 for (i = 0; i < (1 << HUGETLB_PAGE_ORDER); i++) {
88 - /* Directly write pte entry. We could call set_pte_at(mm, addr, ptep, entry)
89 - * instead, but then we get double locking on pa_tlb_lock. */
90 - *ptep = entry;
91 + set_pte(ptep, entry);
92 ptep++;
93
94 - /* Drop the PAGE_SIZE/non-huge tlb entry */
95 - purge_tlb_entries(mm, addr);
96 -
97 addr += PAGE_SIZE;
98 pte_val(entry) += PAGE_SIZE;
99 }
100 @@ -138,18 +131,61 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
101 purge_tlb_entries_huge(mm, addr_start);
102 }
103
104 +void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
105 + pte_t *ptep, pte_t entry)
106 +{
107 + unsigned long flags;
108 +
109 + purge_tlb_start(flags);
110 + __set_huge_pte_at(mm, addr, ptep, entry);
111 + purge_tlb_end(flags);
112 +}
113 +
114
115 pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
116 pte_t *ptep)
117 {
118 + unsigned long flags;
119 pte_t entry;
120
121 + purge_tlb_start(flags);
122 entry = *ptep;
123 - set_huge_pte_at(mm, addr, ptep, __pte(0));
124 + __set_huge_pte_at(mm, addr, ptep, __pte(0));
125 + purge_tlb_end(flags);
126
127 return entry;
128 }
129
130 +
131 +void huge_ptep_set_wrprotect(struct mm_struct *mm,
132 + unsigned long addr, pte_t *ptep)
133 +{
134 + unsigned long flags;
135 + pte_t old_pte;
136 +
137 + purge_tlb_start(flags);
138 + old_pte = *ptep;
139 + __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(old_pte));
140 + purge_tlb_end(flags);
141 +}
142 +
143 +int huge_ptep_set_access_flags(struct vm_area_struct *vma,
144 + unsigned long addr, pte_t *ptep,
145 + pte_t pte, int dirty)
146 +{
147 + unsigned long flags;
148 + int changed;
149 +
150 + purge_tlb_start(flags);
151 + changed = !pte_same(*ptep, pte);
152 + if (changed) {
153 + __set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
154 + }
155 + purge_tlb_end(flags);
156 + return changed;
157 +}
158 +
159 +
160 int pmd_huge(pmd_t pmd)
161 {
162 return 0;
163 diff --git a/arch/x86/crypto/chacha20-ssse3-x86_64.S b/arch/x86/crypto/chacha20-ssse3-x86_64.S
164 index 712b13047b41..3a33124e9112 100644
165 --- a/arch/x86/crypto/chacha20-ssse3-x86_64.S
166 +++ b/arch/x86/crypto/chacha20-ssse3-x86_64.S
167 @@ -157,7 +157,9 @@ ENTRY(chacha20_4block_xor_ssse3)
168 # done with the slightly better performing SSSE3 byte shuffling,
169 # 7/12-bit word rotation uses traditional shift+OR.
170
171 - sub $0x40,%rsp
172 + mov %rsp,%r11
173 + sub $0x80,%rsp
174 + and $~63,%rsp
175
176 # x0..15[0-3] = s0..3[0..3]
177 movq 0x00(%rdi),%xmm1
178 @@ -620,6 +622,6 @@ ENTRY(chacha20_4block_xor_ssse3)
179 pxor %xmm1,%xmm15
180 movdqu %xmm15,0xf0(%rsi)
181
182 - add $0x40,%rsp
183 + mov %r11,%rsp
184 ret
185 ENDPROC(chacha20_4block_xor_ssse3)
186 diff --git a/block/blk-merge.c b/block/blk-merge.c
187 index e01405a3e8b3..b966db8f3556 100644
188 --- a/block/blk-merge.c
189 +++ b/block/blk-merge.c
190 @@ -68,6 +68,18 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q,
191 return bio_split(bio, q->limits.max_write_same_sectors, GFP_NOIO, bs);
192 }
193
194 +static inline unsigned get_max_io_size(struct request_queue *q,
195 + struct bio *bio)
196 +{
197 + unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector);
198 + unsigned mask = queue_logical_block_size(q) - 1;
199 +
200 + /* aligned to logical block size */
201 + sectors &= ~(mask >> 9);
202 +
203 + return sectors;
204 +}
205 +
206 static struct bio *blk_bio_segment_split(struct request_queue *q,
207 struct bio *bio,
208 struct bio_set *bs,
209 @@ -79,11 +91,9 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
210 unsigned front_seg_size = bio->bi_seg_front_size;
211 bool do_split = true;
212 struct bio *new = NULL;
213 + const unsigned max_sectors = get_max_io_size(q, bio);
214
215 bio_for_each_segment(bv, bio, iter) {
216 - if (sectors + (bv.bv_len >> 9) > queue_max_sectors(q))
217 - goto split;
218 -
219 /*
220 * If the queue doesn't support SG gaps and adding this
221 * offset would create a gap, disallow it.
222 @@ -91,6 +101,21 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
223 if (bvprvp && bvec_gap_to_prev(q, bvprvp, bv.bv_offset))
224 goto split;
225
226 + if (sectors + (bv.bv_len >> 9) > max_sectors) {
227 + /*
228 + * Consider this a new segment if we're splitting in
229 + * the middle of this vector.
230 + */
231 + if (nsegs < queue_max_segments(q) &&
232 + sectors < max_sectors) {
233 + nsegs++;
234 + sectors = max_sectors;
235 + }
236 + if (sectors)
237 + goto split;
238 + /* Make this single bvec as the 1st segment */
239 + }
240 +
241 if (bvprvp && blk_queue_cluster(q)) {
242 if (seg_size + bv.bv_len > queue_max_segment_size(q))
243 goto new_segment;
244 diff --git a/crypto/af_alg.c b/crypto/af_alg.c
245 index a8e7aa3e257b..f5e18c2a4852 100644
246 --- a/crypto/af_alg.c
247 +++ b/crypto/af_alg.c
248 @@ -76,6 +76,8 @@ int af_alg_register_type(const struct af_alg_type *type)
249 goto unlock;
250
251 type->ops->owner = THIS_MODULE;
252 + if (type->ops_nokey)
253 + type->ops_nokey->owner = THIS_MODULE;
254 node->type = type;
255 list_add(&node->list, &alg_types);
256 err = 0;
257 @@ -125,6 +127,26 @@ int af_alg_release(struct socket *sock)
258 }
259 EXPORT_SYMBOL_GPL(af_alg_release);
260
261 +void af_alg_release_parent(struct sock *sk)
262 +{
263 + struct alg_sock *ask = alg_sk(sk);
264 + unsigned int nokey = ask->nokey_refcnt;
265 + bool last = nokey && !ask->refcnt;
266 +
267 + sk = ask->parent;
268 + ask = alg_sk(sk);
269 +
270 + lock_sock(sk);
271 + ask->nokey_refcnt -= nokey;
272 + if (!last)
273 + last = !--ask->refcnt;
274 + release_sock(sk);
275 +
276 + if (last)
277 + sock_put(sk);
278 +}
279 +EXPORT_SYMBOL_GPL(af_alg_release_parent);
280 +
281 static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
282 {
283 const u32 forbidden = CRYPTO_ALG_INTERNAL;
284 @@ -133,6 +155,7 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
285 struct sockaddr_alg *sa = (void *)uaddr;
286 const struct af_alg_type *type;
287 void *private;
288 + int err;
289
290 if (sock->state == SS_CONNECTED)
291 return -EINVAL;
292 @@ -160,16 +183,22 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
293 return PTR_ERR(private);
294 }
295
296 + err = -EBUSY;
297 lock_sock(sk);
298 + if (ask->refcnt | ask->nokey_refcnt)
299 + goto unlock;
300
301 swap(ask->type, type);
302 swap(ask->private, private);
303
304 + err = 0;
305 +
306 +unlock:
307 release_sock(sk);
308
309 alg_do_release(type, private);
310
311 - return 0;
312 + return err;
313 }
314
315 static int alg_setkey(struct sock *sk, char __user *ukey,
316 @@ -202,11 +231,15 @@ static int alg_setsockopt(struct socket *sock, int level, int optname,
317 struct sock *sk = sock->sk;
318 struct alg_sock *ask = alg_sk(sk);
319 const struct af_alg_type *type;
320 - int err = -ENOPROTOOPT;
321 + int err = -EBUSY;
322
323 lock_sock(sk);
324 + if (ask->refcnt)
325 + goto unlock;
326 +
327 type = ask->type;
328
329 + err = -ENOPROTOOPT;
330 if (level != SOL_ALG || !type)
331 goto unlock;
332
333 @@ -238,6 +271,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock)
334 struct alg_sock *ask = alg_sk(sk);
335 const struct af_alg_type *type;
336 struct sock *sk2;
337 + unsigned int nokey;
338 int err;
339
340 lock_sock(sk);
341 @@ -257,20 +291,29 @@ int af_alg_accept(struct sock *sk, struct socket *newsock)
342 security_sk_clone(sk, sk2);
343
344 err = type->accept(ask->private, sk2);
345 - if (err) {
346 - sk_free(sk2);
347 +
348 + nokey = err == -ENOKEY;
349 + if (nokey && type->accept_nokey)
350 + err = type->accept_nokey(ask->private, sk2);
351 +
352 + if (err)
353 goto unlock;
354 - }
355
356 sk2->sk_family = PF_ALG;
357
358 - sock_hold(sk);
359 + if (nokey || !ask->refcnt++)
360 + sock_hold(sk);
361 + ask->nokey_refcnt += nokey;
362 alg_sk(sk2)->parent = sk;
363 alg_sk(sk2)->type = type;
364 + alg_sk(sk2)->nokey_refcnt = nokey;
365
366 newsock->ops = type->ops;
367 newsock->state = SS_CONNECTED;
368
369 + if (nokey)
370 + newsock->ops = type->ops_nokey;
371 +
372 err = 0;
373
374 unlock:
375 diff --git a/crypto/ahash.c b/crypto/ahash.c
376 index 9c1dc8d6106a..d19b52324cf5 100644
377 --- a/crypto/ahash.c
378 +++ b/crypto/ahash.c
379 @@ -451,6 +451,7 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
380 struct ahash_alg *alg = crypto_ahash_alg(hash);
381
382 hash->setkey = ahash_nosetkey;
383 + hash->has_setkey = false;
384 hash->export = ahash_no_export;
385 hash->import = ahash_no_import;
386
387 @@ -463,8 +464,10 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
388 hash->finup = alg->finup ?: ahash_def_finup;
389 hash->digest = alg->digest;
390
391 - if (alg->setkey)
392 + if (alg->setkey) {
393 hash->setkey = alg->setkey;
394 + hash->has_setkey = true;
395 + }
396 if (alg->export)
397 hash->export = alg->export;
398 if (alg->import)
399 diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
400 index b4c24fe3dcfb..68a5ceaa04c8 100644
401 --- a/crypto/algif_hash.c
402 +++ b/crypto/algif_hash.c
403 @@ -34,6 +34,11 @@ struct hash_ctx {
404 struct ahash_request req;
405 };
406
407 +struct algif_hash_tfm {
408 + struct crypto_ahash *hash;
409 + bool has_key;
410 +};
411 +
412 static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
413 size_t ignored)
414 {
415 @@ -49,7 +54,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
416
417 lock_sock(sk);
418 if (!ctx->more) {
419 - err = crypto_ahash_init(&ctx->req);
420 + err = af_alg_wait_for_completion(crypto_ahash_init(&ctx->req),
421 + &ctx->completion);
422 if (err)
423 goto unlock;
424 }
425 @@ -120,6 +126,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page,
426 } else {
427 if (!ctx->more) {
428 err = crypto_ahash_init(&ctx->req);
429 + err = af_alg_wait_for_completion(err, &ctx->completion);
430 if (err)
431 goto unlock;
432 }
433 @@ -235,19 +242,151 @@ static struct proto_ops algif_hash_ops = {
434 .accept = hash_accept,
435 };
436
437 +static int hash_check_key(struct socket *sock)
438 +{
439 + int err = 0;
440 + struct sock *psk;
441 + struct alg_sock *pask;
442 + struct algif_hash_tfm *tfm;
443 + struct sock *sk = sock->sk;
444 + struct alg_sock *ask = alg_sk(sk);
445 +
446 + lock_sock(sk);
447 + if (ask->refcnt)
448 + goto unlock_child;
449 +
450 + psk = ask->parent;
451 + pask = alg_sk(ask->parent);
452 + tfm = pask->private;
453 +
454 + err = -ENOKEY;
455 + lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
456 + if (!tfm->has_key)
457 + goto unlock;
458 +
459 + if (!pask->refcnt++)
460 + sock_hold(psk);
461 +
462 + ask->refcnt = 1;
463 + sock_put(psk);
464 +
465 + err = 0;
466 +
467 +unlock:
468 + release_sock(psk);
469 +unlock_child:
470 + release_sock(sk);
471 +
472 + return err;
473 +}
474 +
475 +static int hash_sendmsg_nokey(struct socket *sock, struct msghdr *msg,
476 + size_t size)
477 +{
478 + int err;
479 +
480 + err = hash_check_key(sock);
481 + if (err)
482 + return err;
483 +
484 + return hash_sendmsg(sock, msg, size);
485 +}
486 +
487 +static ssize_t hash_sendpage_nokey(struct socket *sock, struct page *page,
488 + int offset, size_t size, int flags)
489 +{
490 + int err;
491 +
492 + err = hash_check_key(sock);
493 + if (err)
494 + return err;
495 +
496 + return hash_sendpage(sock, page, offset, size, flags);
497 +}
498 +
499 +static int hash_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
500 + size_t ignored, int flags)
501 +{
502 + int err;
503 +
504 + err = hash_check_key(sock);
505 + if (err)
506 + return err;
507 +
508 + return hash_recvmsg(sock, msg, ignored, flags);
509 +}
510 +
511 +static int hash_accept_nokey(struct socket *sock, struct socket *newsock,
512 + int flags)
513 +{
514 + int err;
515 +
516 + err = hash_check_key(sock);
517 + if (err)
518 + return err;
519 +
520 + return hash_accept(sock, newsock, flags);
521 +}
522 +
523 +static struct proto_ops algif_hash_ops_nokey = {
524 + .family = PF_ALG,
525 +
526 + .connect = sock_no_connect,
527 + .socketpair = sock_no_socketpair,
528 + .getname = sock_no_getname,
529 + .ioctl = sock_no_ioctl,
530 + .listen = sock_no_listen,
531 + .shutdown = sock_no_shutdown,
532 + .getsockopt = sock_no_getsockopt,
533 + .mmap = sock_no_mmap,
534 + .bind = sock_no_bind,
535 + .setsockopt = sock_no_setsockopt,
536 + .poll = sock_no_poll,
537 +
538 + .release = af_alg_release,
539 + .sendmsg = hash_sendmsg_nokey,
540 + .sendpage = hash_sendpage_nokey,
541 + .recvmsg = hash_recvmsg_nokey,
542 + .accept = hash_accept_nokey,
543 +};
544 +
545 static void *hash_bind(const char *name, u32 type, u32 mask)
546 {
547 - return crypto_alloc_ahash(name, type, mask);
548 + struct algif_hash_tfm *tfm;
549 + struct crypto_ahash *hash;
550 +
551 + tfm = kzalloc(sizeof(*tfm), GFP_KERNEL);
552 + if (!tfm)
553 + return ERR_PTR(-ENOMEM);
554 +
555 + hash = crypto_alloc_ahash(name, type, mask);
556 + if (IS_ERR(hash)) {
557 + kfree(tfm);
558 + return ERR_CAST(hash);
559 + }
560 +
561 + tfm->hash = hash;
562 +
563 + return tfm;
564 }
565
566 static void hash_release(void *private)
567 {
568 - crypto_free_ahash(private);
569 + struct algif_hash_tfm *tfm = private;
570 +
571 + crypto_free_ahash(tfm->hash);
572 + kfree(tfm);
573 }
574
575 static int hash_setkey(void *private, const u8 *key, unsigned int keylen)
576 {
577 - return crypto_ahash_setkey(private, key, keylen);
578 + struct algif_hash_tfm *tfm = private;
579 + int err;
580 +
581 + err = crypto_ahash_setkey(tfm->hash, key, keylen);
582 + tfm->has_key = !err;
583 +
584 + return err;
585 }
586
587 static void hash_sock_destruct(struct sock *sk)
588 @@ -261,12 +400,14 @@ static void hash_sock_destruct(struct sock *sk)
589 af_alg_release_parent(sk);
590 }
591
592 -static int hash_accept_parent(void *private, struct sock *sk)
593 +static int hash_accept_parent_nokey(void *private, struct sock *sk)
594 {
595 struct hash_ctx *ctx;
596 struct alg_sock *ask = alg_sk(sk);
597 - unsigned len = sizeof(*ctx) + crypto_ahash_reqsize(private);
598 - unsigned ds = crypto_ahash_digestsize(private);
599 + struct algif_hash_tfm *tfm = private;
600 + struct crypto_ahash *hash = tfm->hash;
601 + unsigned len = sizeof(*ctx) + crypto_ahash_reqsize(hash);
602 + unsigned ds = crypto_ahash_digestsize(hash);
603
604 ctx = sock_kmalloc(sk, len, GFP_KERNEL);
605 if (!ctx)
606 @@ -286,7 +427,7 @@ static int hash_accept_parent(void *private, struct sock *sk)
607
608 ask->private = ctx;
609
610 - ahash_request_set_tfm(&ctx->req, private);
611 + ahash_request_set_tfm(&ctx->req, hash);
612 ahash_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG,
613 af_alg_complete, &ctx->completion);
614
615 @@ -295,12 +436,24 @@ static int hash_accept_parent(void *private, struct sock *sk)
616 return 0;
617 }
618
619 +static int hash_accept_parent(void *private, struct sock *sk)
620 +{
621 + struct algif_hash_tfm *tfm = private;
622 +
623 + if (!tfm->has_key && crypto_ahash_has_setkey(tfm->hash))
624 + return -ENOKEY;
625 +
626 + return hash_accept_parent_nokey(private, sk);
627 +}
628 +
629 static const struct af_alg_type algif_type_hash = {
630 .bind = hash_bind,
631 .release = hash_release,
632 .setkey = hash_setkey,
633 .accept = hash_accept_parent,
634 + .accept_nokey = hash_accept_parent_nokey,
635 .ops = &algif_hash_ops,
636 + .ops_nokey = &algif_hash_ops_nokey,
637 .name = "hash",
638 .owner = THIS_MODULE
639 };
640 diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
641 index 634b4d1ab681..f5e9f9310b48 100644
642 --- a/crypto/algif_skcipher.c
643 +++ b/crypto/algif_skcipher.c
644 @@ -31,6 +31,11 @@ struct skcipher_sg_list {
645 struct scatterlist sg[0];
646 };
647
648 +struct skcipher_tfm {
649 + struct crypto_skcipher *skcipher;
650 + bool has_key;
651 +};
652 +
653 struct skcipher_ctx {
654 struct list_head tsgl;
655 struct af_alg_sgl rsgl;
656 @@ -60,18 +65,10 @@ struct skcipher_async_req {
657 struct skcipher_async_rsgl first_sgl;
658 struct list_head list;
659 struct scatterlist *tsg;
660 - char iv[];
661 + atomic_t *inflight;
662 + struct skcipher_request req;
663 };
664
665 -#define GET_SREQ(areq, ctx) (struct skcipher_async_req *)((char *)areq + \
666 - crypto_skcipher_reqsize(crypto_skcipher_reqtfm(&ctx->req)))
667 -
668 -#define GET_REQ_SIZE(ctx) \
669 - crypto_skcipher_reqsize(crypto_skcipher_reqtfm(&ctx->req))
670 -
671 -#define GET_IV_SIZE(ctx) \
672 - crypto_skcipher_ivsize(crypto_skcipher_reqtfm(&ctx->req))
673 -
674 #define MAX_SGL_ENTS ((4096 - sizeof(struct skcipher_sg_list)) / \
675 sizeof(struct scatterlist) - 1)
676
677 @@ -97,15 +94,12 @@ static void skcipher_free_async_sgls(struct skcipher_async_req *sreq)
678
679 static void skcipher_async_cb(struct crypto_async_request *req, int err)
680 {
681 - struct sock *sk = req->data;
682 - struct alg_sock *ask = alg_sk(sk);
683 - struct skcipher_ctx *ctx = ask->private;
684 - struct skcipher_async_req *sreq = GET_SREQ(req, ctx);
685 + struct skcipher_async_req *sreq = req->data;
686 struct kiocb *iocb = sreq->iocb;
687
688 - atomic_dec(&ctx->inflight);
689 + atomic_dec(sreq->inflight);
690 skcipher_free_async_sgls(sreq);
691 - kfree(req);
692 + kzfree(sreq);
693 iocb->ki_complete(iocb, err, err);
694 }
695
696 @@ -301,8 +295,11 @@ static int skcipher_sendmsg(struct socket *sock, struct msghdr *msg,
697 {
698 struct sock *sk = sock->sk;
699 struct alg_sock *ask = alg_sk(sk);
700 + struct sock *psk = ask->parent;
701 + struct alg_sock *pask = alg_sk(psk);
702 struct skcipher_ctx *ctx = ask->private;
703 - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(&ctx->req);
704 + struct skcipher_tfm *skc = pask->private;
705 + struct crypto_skcipher *tfm = skc->skcipher;
706 unsigned ivsize = crypto_skcipher_ivsize(tfm);
707 struct skcipher_sg_list *sgl;
708 struct af_alg_control con = {};
709 @@ -387,7 +384,8 @@ static int skcipher_sendmsg(struct socket *sock, struct msghdr *msg,
710
711 sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
712 sg = sgl->sg;
713 - sg_unmark_end(sg + sgl->cur);
714 + if (sgl->cur)
715 + sg_unmark_end(sg + sgl->cur - 1);
716 do {
717 i = sgl->cur;
718 plen = min_t(int, len, PAGE_SIZE);
719 @@ -503,37 +501,43 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
720 {
721 struct sock *sk = sock->sk;
722 struct alg_sock *ask = alg_sk(sk);
723 + struct sock *psk = ask->parent;
724 + struct alg_sock *pask = alg_sk(psk);
725 struct skcipher_ctx *ctx = ask->private;
726 + struct skcipher_tfm *skc = pask->private;
727 + struct crypto_skcipher *tfm = skc->skcipher;
728 struct skcipher_sg_list *sgl;
729 struct scatterlist *sg;
730 struct skcipher_async_req *sreq;
731 struct skcipher_request *req;
732 struct skcipher_async_rsgl *last_rsgl = NULL;
733 - unsigned int txbufs = 0, len = 0, tx_nents = skcipher_all_sg_nents(ctx);
734 - unsigned int reqlen = sizeof(struct skcipher_async_req) +
735 - GET_REQ_SIZE(ctx) + GET_IV_SIZE(ctx);
736 + unsigned int txbufs = 0, len = 0, tx_nents;
737 + unsigned int reqsize = crypto_skcipher_reqsize(tfm);
738 + unsigned int ivsize = crypto_skcipher_ivsize(tfm);
739 int err = -ENOMEM;
740 bool mark = false;
741 + char *iv;
742
743 - lock_sock(sk);
744 - req = kmalloc(reqlen, GFP_KERNEL);
745 - if (unlikely(!req))
746 - goto unlock;
747 + sreq = kzalloc(sizeof(*sreq) + reqsize + ivsize, GFP_KERNEL);
748 + if (unlikely(!sreq))
749 + goto out;
750
751 - sreq = GET_SREQ(req, ctx);
752 + req = &sreq->req;
753 + iv = (char *)(req + 1) + reqsize;
754 sreq->iocb = msg->msg_iocb;
755 - memset(&sreq->first_sgl, '\0', sizeof(struct skcipher_async_rsgl));
756 INIT_LIST_HEAD(&sreq->list);
757 + sreq->inflight = &ctx->inflight;
758 +
759 + lock_sock(sk);
760 + tx_nents = skcipher_all_sg_nents(ctx);
761 sreq->tsg = kcalloc(tx_nents, sizeof(*sg), GFP_KERNEL);
762 - if (unlikely(!sreq->tsg)) {
763 - kfree(req);
764 + if (unlikely(!sreq->tsg))
765 goto unlock;
766 - }
767 sg_init_table(sreq->tsg, tx_nents);
768 - memcpy(sreq->iv, ctx->iv, GET_IV_SIZE(ctx));
769 - skcipher_request_set_tfm(req, crypto_skcipher_reqtfm(&ctx->req));
770 - skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
771 - skcipher_async_cb, sk);
772 + memcpy(iv, ctx->iv, ivsize);
773 + skcipher_request_set_tfm(req, tfm);
774 + skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP,
775 + skcipher_async_cb, sreq);
776
777 while (iov_iter_count(&msg->msg_iter)) {
778 struct skcipher_async_rsgl *rsgl;
779 @@ -609,20 +613,22 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
780 sg_mark_end(sreq->tsg + txbufs - 1);
781
782 skcipher_request_set_crypt(req, sreq->tsg, sreq->first_sgl.sgl.sg,
783 - len, sreq->iv);
784 + len, iv);
785 err = ctx->enc ? crypto_skcipher_encrypt(req) :
786 crypto_skcipher_decrypt(req);
787 if (err == -EINPROGRESS) {
788 atomic_inc(&ctx->inflight);
789 err = -EIOCBQUEUED;
790 + sreq = NULL;
791 goto unlock;
792 }
793 free:
794 skcipher_free_async_sgls(sreq);
795 - kfree(req);
796 unlock:
797 skcipher_wmem_wakeup(sk);
798 release_sock(sk);
799 + kzfree(sreq);
800 +out:
801 return err;
802 }
803
804 @@ -631,9 +637,12 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg,
805 {
806 struct sock *sk = sock->sk;
807 struct alg_sock *ask = alg_sk(sk);
808 + struct sock *psk = ask->parent;
809 + struct alg_sock *pask = alg_sk(psk);
810 struct skcipher_ctx *ctx = ask->private;
811 - unsigned bs = crypto_skcipher_blocksize(crypto_skcipher_reqtfm(
812 - &ctx->req));
813 + struct skcipher_tfm *skc = pask->private;
814 + struct crypto_skcipher *tfm = skc->skcipher;
815 + unsigned bs = crypto_skcipher_blocksize(tfm);
816 struct skcipher_sg_list *sgl;
817 struct scatterlist *sg;
818 int err = -EAGAIN;
819 @@ -642,13 +651,6 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg,
820
821 lock_sock(sk);
822 while (msg_data_left(msg)) {
823 - sgl = list_first_entry(&ctx->tsgl,
824 - struct skcipher_sg_list, list);
825 - sg = sgl->sg;
826 -
827 - while (!sg->length)
828 - sg++;
829 -
830 if (!ctx->used) {
831 err = skcipher_wait_for_data(sk, flags);
832 if (err)
833 @@ -669,6 +671,13 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg,
834 if (!used)
835 goto free;
836
837 + sgl = list_first_entry(&ctx->tsgl,
838 + struct skcipher_sg_list, list);
839 + sg = sgl->sg;
840 +
841 + while (!sg->length)
842 + sg++;
843 +
844 skcipher_request_set_crypt(&ctx->req, sg, ctx->rsgl.sg, used,
845 ctx->iv);
846
847 @@ -748,19 +757,139 @@ static struct proto_ops algif_skcipher_ops = {
848 .poll = skcipher_poll,
849 };
850
851 +static int skcipher_check_key(struct socket *sock)
852 +{
853 + int err = 0;
854 + struct sock *psk;
855 + struct alg_sock *pask;
856 + struct skcipher_tfm *tfm;
857 + struct sock *sk = sock->sk;
858 + struct alg_sock *ask = alg_sk(sk);
859 +
860 + lock_sock(sk);
861 + if (ask->refcnt)
862 + goto unlock_child;
863 +
864 + psk = ask->parent;
865 + pask = alg_sk(ask->parent);
866 + tfm = pask->private;
867 +
868 + err = -ENOKEY;
869 + lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
870 + if (!tfm->has_key)
871 + goto unlock;
872 +
873 + if (!pask->refcnt++)
874 + sock_hold(psk);
875 +
876 + ask->refcnt = 1;
877 + sock_put(psk);
878 +
879 + err = 0;
880 +
881 +unlock:
882 + release_sock(psk);
883 +unlock_child:
884 + release_sock(sk);
885 +
886 + return err;
887 +}
888 +
889 +static int skcipher_sendmsg_nokey(struct socket *sock, struct msghdr *msg,
890 + size_t size)
891 +{
892 + int err;
893 +
894 + err = skcipher_check_key(sock);
895 + if (err)
896 + return err;
897 +
898 + return skcipher_sendmsg(sock, msg, size);
899 +}
900 +
901 +static ssize_t skcipher_sendpage_nokey(struct socket *sock, struct page *page,
902 + int offset, size_t size, int flags)
903 +{
904 + int err;
905 +
906 + err = skcipher_check_key(sock);
907 + if (err)
908 + return err;
909 +
910 + return skcipher_sendpage(sock, page, offset, size, flags);
911 +}
912 +
913 +static int skcipher_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
914 + size_t ignored, int flags)
915 +{
916 + int err;
917 +
918 + err = skcipher_check_key(sock);
919 + if (err)
920 + return err;
921 +
922 + return skcipher_recvmsg(sock, msg, ignored, flags);
923 +}
924 +
925 +static struct proto_ops algif_skcipher_ops_nokey = {
926 + .family = PF_ALG,
927 +
928 + .connect = sock_no_connect,
929 + .socketpair = sock_no_socketpair,
930 + .getname = sock_no_getname,
931 + .ioctl = sock_no_ioctl,
932 + .listen = sock_no_listen,
933 + .shutdown = sock_no_shutdown,
934 + .getsockopt = sock_no_getsockopt,
935 + .mmap = sock_no_mmap,
936 + .bind = sock_no_bind,
937 + .accept = sock_no_accept,
938 + .setsockopt = sock_no_setsockopt,
939 +
940 + .release = af_alg_release,
941 + .sendmsg = skcipher_sendmsg_nokey,
942 + .sendpage = skcipher_sendpage_nokey,
943 + .recvmsg = skcipher_recvmsg_nokey,
944 + .poll = skcipher_poll,
945 +};
946 +
947 static void *skcipher_bind(const char *name, u32 type, u32 mask)
948 {
949 - return crypto_alloc_skcipher(name, type, mask);
950 + struct skcipher_tfm *tfm;
951 + struct crypto_skcipher *skcipher;
952 +
953 + tfm = kzalloc(sizeof(*tfm), GFP_KERNEL);
954 + if (!tfm)
955 + return ERR_PTR(-ENOMEM);
956 +
957 + skcipher = crypto_alloc_skcipher(name, type, mask);
958 + if (IS_ERR(skcipher)) {
959 + kfree(tfm);
960 + return ERR_CAST(skcipher);
961 + }
962 +
963 + tfm->skcipher = skcipher;
964 +
965 + return tfm;
966 }
967
968 static void skcipher_release(void *private)
969 {
970 - crypto_free_skcipher(private);
971 + struct skcipher_tfm *tfm = private;
972 +
973 + crypto_free_skcipher(tfm->skcipher);
974 + kfree(tfm);
975 }
976
977 static int skcipher_setkey(void *private, const u8 *key, unsigned int keylen)
978 {
979 - return crypto_skcipher_setkey(private, key, keylen);
980 + struct skcipher_tfm *tfm = private;
981 + int err;
982 +
983 + err = crypto_skcipher_setkey(tfm->skcipher, key, keylen);
984 + tfm->has_key = !err;
985 +
986 + return err;
987 }
988
989 static void skcipher_wait(struct sock *sk)
990 @@ -788,24 +917,26 @@ static void skcipher_sock_destruct(struct sock *sk)
991 af_alg_release_parent(sk);
992 }
993
994 -static int skcipher_accept_parent(void *private, struct sock *sk)
995 +static int skcipher_accept_parent_nokey(void *private, struct sock *sk)
996 {
997 struct skcipher_ctx *ctx;
998 struct alg_sock *ask = alg_sk(sk);
999 - unsigned int len = sizeof(*ctx) + crypto_skcipher_reqsize(private);
1000 + struct skcipher_tfm *tfm = private;
1001 + struct crypto_skcipher *skcipher = tfm->skcipher;
1002 + unsigned int len = sizeof(*ctx) + crypto_skcipher_reqsize(skcipher);
1003
1004 ctx = sock_kmalloc(sk, len, GFP_KERNEL);
1005 if (!ctx)
1006 return -ENOMEM;
1007
1008 - ctx->iv = sock_kmalloc(sk, crypto_skcipher_ivsize(private),
1009 + ctx->iv = sock_kmalloc(sk, crypto_skcipher_ivsize(skcipher),
1010 GFP_KERNEL);
1011 if (!ctx->iv) {
1012 sock_kfree_s(sk, ctx, len);
1013 return -ENOMEM;
1014 }
1015
1016 - memset(ctx->iv, 0, crypto_skcipher_ivsize(private));
1017 + memset(ctx->iv, 0, crypto_skcipher_ivsize(skcipher));
1018
1019 INIT_LIST_HEAD(&ctx->tsgl);
1020 ctx->len = len;
1021 @@ -818,8 +949,9 @@ static int skcipher_accept_parent(void *private, struct sock *sk)
1022
1023 ask->private = ctx;
1024
1025 - skcipher_request_set_tfm(&ctx->req, private);
1026 - skcipher_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1027 + skcipher_request_set_tfm(&ctx->req, skcipher);
1028 + skcipher_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_SLEEP |
1029 + CRYPTO_TFM_REQ_MAY_BACKLOG,
1030 af_alg_complete, &ctx->completion);
1031
1032 sk->sk_destruct = skcipher_sock_destruct;
1033 @@ -827,12 +959,24 @@ static int skcipher_accept_parent(void *private, struct sock *sk)
1034 return 0;
1035 }
1036
1037 +static int skcipher_accept_parent(void *private, struct sock *sk)
1038 +{
1039 + struct skcipher_tfm *tfm = private;
1040 +
1041 + if (!tfm->has_key && crypto_skcipher_has_setkey(tfm->skcipher))
1042 + return -ENOKEY;
1043 +
1044 + return skcipher_accept_parent_nokey(private, sk);
1045 +}
1046 +
1047 static const struct af_alg_type algif_type_skcipher = {
1048 .bind = skcipher_bind,
1049 .release = skcipher_release,
1050 .setkey = skcipher_setkey,
1051 .accept = skcipher_accept_parent,
1052 + .accept_nokey = skcipher_accept_parent_nokey,
1053 .ops = &algif_skcipher_ops,
1054 + .ops_nokey = &algif_skcipher_ops_nokey,
1055 .name = "skcipher",
1056 .owner = THIS_MODULE
1057 };
1058 diff --git a/crypto/crc32c_generic.c b/crypto/crc32c_generic.c
1059 index 06f1b60f02b2..4c0a0e271876 100644
1060 --- a/crypto/crc32c_generic.c
1061 +++ b/crypto/crc32c_generic.c
1062 @@ -172,4 +172,3 @@ MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations wrapper for lib/crc32c");
1063 MODULE_LICENSE("GPL");
1064 MODULE_ALIAS_CRYPTO("crc32c");
1065 MODULE_ALIAS_CRYPTO("crc32c-generic");
1066 -MODULE_SOFTDEP("pre: crc32c");
1067 diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
1068 index 237f3795cfaa..43fe85f20d57 100644
1069 --- a/crypto/crypto_user.c
1070 +++ b/crypto/crypto_user.c
1071 @@ -499,6 +499,7 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1072 if (link->dump == NULL)
1073 return -EINVAL;
1074
1075 + down_read(&crypto_alg_sem);
1076 list_for_each_entry(alg, &crypto_alg_list, cra_list)
1077 dump_alloc += CRYPTO_REPORT_MAXSIZE;
1078
1079 @@ -508,8 +509,11 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1080 .done = link->done,
1081 .min_dump_alloc = dump_alloc,
1082 };
1083 - return netlink_dump_start(crypto_nlsk, skb, nlh, &c);
1084 + err = netlink_dump_start(crypto_nlsk, skb, nlh, &c);
1085 }
1086 + up_read(&crypto_alg_sem);
1087 +
1088 + return err;
1089 }
1090
1091 err = nlmsg_parse(nlh, crypto_msg_min[type], attrs, CRYPTOCFGA_MAX,
1092 diff --git a/crypto/shash.c b/crypto/shash.c
1093 index ecb1e3d39bf0..359754591653 100644
1094 --- a/crypto/shash.c
1095 +++ b/crypto/shash.c
1096 @@ -354,9 +354,10 @@ int crypto_init_shash_ops_async(struct crypto_tfm *tfm)
1097 crt->final = shash_async_final;
1098 crt->finup = shash_async_finup;
1099 crt->digest = shash_async_digest;
1100 + crt->setkey = shash_async_setkey;
1101 +
1102 + crt->has_setkey = alg->setkey != shash_no_setkey;
1103
1104 - if (alg->setkey)
1105 - crt->setkey = shash_async_setkey;
1106 if (alg->export)
1107 crt->export = shash_async_export;
1108 if (alg->import)
1109 diff --git a/crypto/skcipher.c b/crypto/skcipher.c
1110 index 7591928be7ca..d199c0b1751c 100644
1111 --- a/crypto/skcipher.c
1112 +++ b/crypto/skcipher.c
1113 @@ -118,6 +118,7 @@ static int crypto_init_skcipher_ops_blkcipher(struct crypto_tfm *tfm)
1114 skcipher->decrypt = skcipher_decrypt_blkcipher;
1115
1116 skcipher->ivsize = crypto_blkcipher_ivsize(blkcipher);
1117 + skcipher->has_setkey = calg->cra_blkcipher.max_keysize;
1118
1119 return 0;
1120 }
1121 @@ -210,6 +211,7 @@ static int crypto_init_skcipher_ops_ablkcipher(struct crypto_tfm *tfm)
1122 skcipher->ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1123 skcipher->reqsize = crypto_ablkcipher_reqsize(ablkcipher) +
1124 sizeof(struct ablkcipher_request);
1125 + skcipher->has_setkey = calg->cra_ablkcipher.max_keysize;
1126
1127 return 0;
1128 }
1129 diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
1130 index cdfbcc54821f..99921aa0daca 100644
1131 --- a/drivers/ata/ahci.c
1132 +++ b/drivers/ata/ahci.c
1133 @@ -264,6 +264,26 @@ static const struct pci_device_id ahci_pci_tbl[] = {
1134 { PCI_VDEVICE(INTEL, 0x3b2b), board_ahci }, /* PCH RAID */
1135 { PCI_VDEVICE(INTEL, 0x3b2c), board_ahci }, /* PCH RAID */
1136 { PCI_VDEVICE(INTEL, 0x3b2f), board_ahci }, /* PCH AHCI */
1137 + { PCI_VDEVICE(INTEL, 0x19b0), board_ahci }, /* DNV AHCI */
1138 + { PCI_VDEVICE(INTEL, 0x19b1), board_ahci }, /* DNV AHCI */
1139 + { PCI_VDEVICE(INTEL, 0x19b2), board_ahci }, /* DNV AHCI */
1140 + { PCI_VDEVICE(INTEL, 0x19b3), board_ahci }, /* DNV AHCI */
1141 + { PCI_VDEVICE(INTEL, 0x19b4), board_ahci }, /* DNV AHCI */
1142 + { PCI_VDEVICE(INTEL, 0x19b5), board_ahci }, /* DNV AHCI */
1143 + { PCI_VDEVICE(INTEL, 0x19b6), board_ahci }, /* DNV AHCI */
1144 + { PCI_VDEVICE(INTEL, 0x19b7), board_ahci }, /* DNV AHCI */
1145 + { PCI_VDEVICE(INTEL, 0x19bE), board_ahci }, /* DNV AHCI */
1146 + { PCI_VDEVICE(INTEL, 0x19bF), board_ahci }, /* DNV AHCI */
1147 + { PCI_VDEVICE(INTEL, 0x19c0), board_ahci }, /* DNV AHCI */
1148 + { PCI_VDEVICE(INTEL, 0x19c1), board_ahci }, /* DNV AHCI */
1149 + { PCI_VDEVICE(INTEL, 0x19c2), board_ahci }, /* DNV AHCI */
1150 + { PCI_VDEVICE(INTEL, 0x19c3), board_ahci }, /* DNV AHCI */
1151 + { PCI_VDEVICE(INTEL, 0x19c4), board_ahci }, /* DNV AHCI */
1152 + { PCI_VDEVICE(INTEL, 0x19c5), board_ahci }, /* DNV AHCI */
1153 + { PCI_VDEVICE(INTEL, 0x19c6), board_ahci }, /* DNV AHCI */
1154 + { PCI_VDEVICE(INTEL, 0x19c7), board_ahci }, /* DNV AHCI */
1155 + { PCI_VDEVICE(INTEL, 0x19cE), board_ahci }, /* DNV AHCI */
1156 + { PCI_VDEVICE(INTEL, 0x19cF), board_ahci }, /* DNV AHCI */
1157 { PCI_VDEVICE(INTEL, 0x1c02), board_ahci }, /* CPT AHCI */
1158 { PCI_VDEVICE(INTEL, 0x1c03), board_ahci }, /* CPT AHCI */
1159 { PCI_VDEVICE(INTEL, 0x1c04), board_ahci }, /* CPT RAID */
1160 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
1161 index 4665512dae44..1f225cc1827f 100644
1162 --- a/drivers/ata/libahci.c
1163 +++ b/drivers/ata/libahci.c
1164 @@ -495,8 +495,8 @@ void ahci_save_initial_config(struct device *dev, struct ahci_host_priv *hpriv)
1165 }
1166 }
1167
1168 - /* fabricate port_map from cap.nr_ports */
1169 - if (!port_map) {
1170 + /* fabricate port_map from cap.nr_ports for < AHCI 1.3 */
1171 + if (!port_map && vers < 0x10300) {
1172 port_map = (1 << ahci_nr_ports(cap)) - 1;
1173 dev_warn(dev, "forcing PORTS_IMPL to 0x%x\n", port_map);
1174
1175 diff --git a/drivers/base/platform.c b/drivers/base/platform.c
1176 index 1dd6d3bf1098..176b59f5bc47 100644
1177 --- a/drivers/base/platform.c
1178 +++ b/drivers/base/platform.c
1179 @@ -513,10 +513,15 @@ static int platform_drv_probe(struct device *_dev)
1180 return ret;
1181
1182 ret = dev_pm_domain_attach(_dev, true);
1183 - if (ret != -EPROBE_DEFER && drv->probe) {
1184 - ret = drv->probe(dev);
1185 - if (ret)
1186 - dev_pm_domain_detach(_dev, true);
1187 + if (ret != -EPROBE_DEFER) {
1188 + if (drv->probe) {
1189 + ret = drv->probe(dev);
1190 + if (ret)
1191 + dev_pm_domain_detach(_dev, true);
1192 + } else {
1193 + /* don't fail if just dev_pm_domain_attach failed */
1194 + ret = 0;
1195 + }
1196 }
1197
1198 if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
1199 diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
1200 index 5cb13ca3a3ac..c53617752b93 100644
1201 --- a/drivers/block/zram/zcomp.c
1202 +++ b/drivers/block/zram/zcomp.c
1203 @@ -76,7 +76,7 @@ static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm)
1204 */
1205 static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp)
1206 {
1207 - struct zcomp_strm *zstrm = kmalloc(sizeof(*zstrm), GFP_KERNEL);
1208 + struct zcomp_strm *zstrm = kmalloc(sizeof(*zstrm), GFP_NOIO);
1209 if (!zstrm)
1210 return NULL;
1211
1212 @@ -85,7 +85,7 @@ static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp)
1213 * allocate 2 pages. 1 for compressed data, plus 1 extra for the
1214 * case when compressed size is larger than the original one
1215 */
1216 - zstrm->buffer = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1);
1217 + zstrm->buffer = (void *)__get_free_pages(GFP_NOIO | __GFP_ZERO, 1);
1218 if (!zstrm->private || !zstrm->buffer) {
1219 zcomp_strm_free(comp, zstrm);
1220 zstrm = NULL;
1221 diff --git a/drivers/block/zram/zcomp_lz4.c b/drivers/block/zram/zcomp_lz4.c
1222 index f2afb7e988c3..dd6083124276 100644
1223 --- a/drivers/block/zram/zcomp_lz4.c
1224 +++ b/drivers/block/zram/zcomp_lz4.c
1225 @@ -10,17 +10,36 @@
1226 #include <linux/kernel.h>
1227 #include <linux/slab.h>
1228 #include <linux/lz4.h>
1229 +#include <linux/vmalloc.h>
1230 +#include <linux/mm.h>
1231
1232 #include "zcomp_lz4.h"
1233
1234 static void *zcomp_lz4_create(void)
1235 {
1236 - return kzalloc(LZ4_MEM_COMPRESS, GFP_KERNEL);
1237 + void *ret;
1238 +
1239 + /*
1240 + * This function can be called in swapout/fs write path
1241 + * so we can't use GFP_FS|IO. And it assumes we already
1242 + * have at least one stream in zram initialization so we
1243 + * don't do best effort to allocate more stream in here.
1244 + * A default stream will work well without further multiple
1245 + * streams. That's why we use NORETRY | NOWARN.
1246 + */
1247 + ret = kzalloc(LZ4_MEM_COMPRESS, GFP_NOIO | __GFP_NORETRY |
1248 + __GFP_NOWARN);
1249 + if (!ret)
1250 + ret = __vmalloc(LZ4_MEM_COMPRESS,
1251 + GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN |
1252 + __GFP_ZERO | __GFP_HIGHMEM,
1253 + PAGE_KERNEL);
1254 + return ret;
1255 }
1256
1257 static void zcomp_lz4_destroy(void *private)
1258 {
1259 - kfree(private);
1260 + kvfree(private);
1261 }
1262
1263 static int zcomp_lz4_compress(const unsigned char *src, unsigned char *dst,
1264 diff --git a/drivers/block/zram/zcomp_lzo.c b/drivers/block/zram/zcomp_lzo.c
1265 index da1bc47d588e..edc549920fa0 100644
1266 --- a/drivers/block/zram/zcomp_lzo.c
1267 +++ b/drivers/block/zram/zcomp_lzo.c
1268 @@ -10,17 +10,36 @@
1269 #include <linux/kernel.h>
1270 #include <linux/slab.h>
1271 #include <linux/lzo.h>
1272 +#include <linux/vmalloc.h>
1273 +#include <linux/mm.h>
1274
1275 #include "zcomp_lzo.h"
1276
1277 static void *lzo_create(void)
1278 {
1279 - return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
1280 + void *ret;
1281 +
1282 + /*
1283 + * This function can be called in swapout/fs write path
1284 + * so we can't use GFP_FS|IO. And it assumes we already
1285 + * have at least one stream in zram initialization so we
1286 + * don't do best effort to allocate more stream in here.
1287 + * A default stream will work well without further multiple
1288 + * streams. That's why we use NORETRY | NOWARN.
1289 + */
1290 + ret = kzalloc(LZO1X_MEM_COMPRESS, GFP_NOIO | __GFP_NORETRY |
1291 + __GFP_NOWARN);
1292 + if (!ret)
1293 + ret = __vmalloc(LZO1X_MEM_COMPRESS,
1294 + GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN |
1295 + __GFP_ZERO | __GFP_HIGHMEM,
1296 + PAGE_KERNEL);
1297 + return ret;
1298 }
1299
1300 static void lzo_destroy(void *private)
1301 {
1302 - kfree(private);
1303 + kvfree(private);
1304 }
1305
1306 static int lzo_compress(const unsigned char *src, unsigned char *dst,
1307 diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
1308 index 47915d736f8d..370c2f76016d 100644
1309 --- a/drivers/block/zram/zram_drv.c
1310 +++ b/drivers/block/zram/zram_drv.c
1311 @@ -1325,7 +1325,6 @@ static int zram_remove(struct zram *zram)
1312
1313 pr_info("Removed device: %s\n", zram->disk->disk_name);
1314
1315 - idr_remove(&zram_index_idr, zram->disk->first_minor);
1316 blk_cleanup_queue(zram->disk->queue);
1317 del_gendisk(zram->disk);
1318 put_disk(zram->disk);
1319 @@ -1367,10 +1366,12 @@ static ssize_t hot_remove_store(struct class *class,
1320 mutex_lock(&zram_index_mutex);
1321
1322 zram = idr_find(&zram_index_idr, dev_id);
1323 - if (zram)
1324 + if (zram) {
1325 ret = zram_remove(zram);
1326 - else
1327 + idr_remove(&zram_index_idr, dev_id);
1328 + } else {
1329 ret = -ENODEV;
1330 + }
1331
1332 mutex_unlock(&zram_index_mutex);
1333 return ret ? ret : count;
1334 diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
1335 index 660d8c06540b..3178f84d2757 100644
1336 --- a/drivers/crypto/atmel-sha.c
1337 +++ b/drivers/crypto/atmel-sha.c
1338 @@ -783,7 +783,7 @@ static void atmel_sha_finish_req(struct ahash_request *req, int err)
1339 dd->flags &= ~(SHA_FLAGS_BUSY | SHA_FLAGS_FINAL | SHA_FLAGS_CPU |
1340 SHA_FLAGS_DMA_READY | SHA_FLAGS_OUTPUT_READY);
1341
1342 - clk_disable_unprepare(dd->iclk);
1343 + clk_disable(dd->iclk);
1344
1345 if (req->base.complete)
1346 req->base.complete(&req->base, err);
1347 @@ -796,7 +796,7 @@ static int atmel_sha_hw_init(struct atmel_sha_dev *dd)
1348 {
1349 int err;
1350
1351 - err = clk_prepare_enable(dd->iclk);
1352 + err = clk_enable(dd->iclk);
1353 if (err)
1354 return err;
1355
1356 @@ -823,7 +823,7 @@ static void atmel_sha_hw_version_init(struct atmel_sha_dev *dd)
1357 dev_info(dd->dev,
1358 "version: 0x%x\n", dd->hw_version);
1359
1360 - clk_disable_unprepare(dd->iclk);
1361 + clk_disable(dd->iclk);
1362 }
1363
1364 static int atmel_sha_handle_queue(struct atmel_sha_dev *dd,
1365 @@ -1411,6 +1411,10 @@ static int atmel_sha_probe(struct platform_device *pdev)
1366 goto res_err;
1367 }
1368
1369 + err = clk_prepare(sha_dd->iclk);
1370 + if (err)
1371 + goto res_err;
1372 +
1373 atmel_sha_hw_version_init(sha_dd);
1374
1375 atmel_sha_get_cap(sha_dd);
1376 @@ -1422,12 +1426,12 @@ static int atmel_sha_probe(struct platform_device *pdev)
1377 if (IS_ERR(pdata)) {
1378 dev_err(&pdev->dev, "platform data not available\n");
1379 err = PTR_ERR(pdata);
1380 - goto res_err;
1381 + goto iclk_unprepare;
1382 }
1383 }
1384 if (!pdata->dma_slave) {
1385 err = -ENXIO;
1386 - goto res_err;
1387 + goto iclk_unprepare;
1388 }
1389 err = atmel_sha_dma_init(sha_dd, pdata);
1390 if (err)
1391 @@ -1458,6 +1462,8 @@ err_algs:
1392 if (sha_dd->caps.has_dma)
1393 atmel_sha_dma_cleanup(sha_dd);
1394 err_sha_dma:
1395 +iclk_unprepare:
1396 + clk_unprepare(sha_dd->iclk);
1397 res_err:
1398 tasklet_kill(&sha_dd->done_task);
1399 sha_dd_err:
1400 @@ -1484,12 +1490,7 @@ static int atmel_sha_remove(struct platform_device *pdev)
1401 if (sha_dd->caps.has_dma)
1402 atmel_sha_dma_cleanup(sha_dd);
1403
1404 - iounmap(sha_dd->io_base);
1405 -
1406 - clk_put(sha_dd->iclk);
1407 -
1408 - if (sha_dd->irq >= 0)
1409 - free_irq(sha_dd->irq, sha_dd);
1410 + clk_unprepare(sha_dd->iclk);
1411
1412 return 0;
1413 }
1414 diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
1415 index 8abb4bc548cc..69d4a1326fee 100644
1416 --- a/drivers/crypto/caam/ctrl.c
1417 +++ b/drivers/crypto/caam/ctrl.c
1418 @@ -534,8 +534,8 @@ static int caam_probe(struct platform_device *pdev)
1419 * long pointers in master configuration register
1420 */
1421 clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK, MCFGR_AWCACHE_CACH |
1422 - MCFGR_WDENABLE | (sizeof(dma_addr_t) == sizeof(u64) ?
1423 - MCFGR_LONG_PTR : 0));
1424 + MCFGR_AWCACHE_BUFF | MCFGR_WDENABLE |
1425 + (sizeof(dma_addr_t) == sizeof(u64) ? MCFGR_LONG_PTR : 0));
1426
1427 /*
1428 * Read the Compile Time paramters and SCFGR to determine
1429 diff --git a/drivers/crypto/marvell/cesa.c b/drivers/crypto/marvell/cesa.c
1430 index 0643e3366e33..c0656e7f37b5 100644
1431 --- a/drivers/crypto/marvell/cesa.c
1432 +++ b/drivers/crypto/marvell/cesa.c
1433 @@ -306,7 +306,7 @@ static int mv_cesa_dev_dma_init(struct mv_cesa_dev *cesa)
1434 return -ENOMEM;
1435
1436 dma->padding_pool = dmam_pool_create("cesa_padding", dev, 72, 1, 0);
1437 - if (!dma->cache_pool)
1438 + if (!dma->padding_pool)
1439 return -ENOMEM;
1440
1441 cesa->dma = dma;
1442 diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-core.c b/drivers/crypto/sunxi-ss/sun4i-ss-core.c
1443 index eab6fe227fa0..107cd2a41cae 100644
1444 --- a/drivers/crypto/sunxi-ss/sun4i-ss-core.c
1445 +++ b/drivers/crypto/sunxi-ss/sun4i-ss-core.c
1446 @@ -39,6 +39,7 @@ static struct sun4i_ss_alg_template ss_algs[] = {
1447 .import = sun4i_hash_import_md5,
1448 .halg = {
1449 .digestsize = MD5_DIGEST_SIZE,
1450 + .statesize = sizeof(struct md5_state),
1451 .base = {
1452 .cra_name = "md5",
1453 .cra_driver_name = "md5-sun4i-ss",
1454 @@ -66,6 +67,7 @@ static struct sun4i_ss_alg_template ss_algs[] = {
1455 .import = sun4i_hash_import_sha1,
1456 .halg = {
1457 .digestsize = SHA1_DIGEST_SIZE,
1458 + .statesize = sizeof(struct sha1_state),
1459 .base = {
1460 .cra_name = "sha1",
1461 .cra_driver_name = "sha1-sun4i-ss",
1462 diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
1463 index 3d664d01305e..2b8ff18d3713 100644
1464 --- a/drivers/hid/hid-multitouch.c
1465 +++ b/drivers/hid/hid-multitouch.c
1466 @@ -357,8 +357,19 @@ static void mt_feature_mapping(struct hid_device *hdev,
1467 break;
1468 }
1469
1470 - td->inputmode = field->report->id;
1471 - td->inputmode_index = usage->usage_index;
1472 + if (td->inputmode < 0) {
1473 + td->inputmode = field->report->id;
1474 + td->inputmode_index = usage->usage_index;
1475 + } else {
1476 + /*
1477 + * Some elan panels wrongly declare 2 input mode
1478 + * features, and silently ignore when we set the
1479 + * value in the second field. Skip the second feature
1480 + * and hope for the best.
1481 + */
1482 + dev_info(&hdev->dev,
1483 + "Ignoring the extra HID_DG_INPUTMODE\n");
1484 + }
1485
1486 break;
1487 case HID_DG_CONTACTMAX:
1488 diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
1489 index 36712e9f56c2..5dd426fee8cc 100644
1490 --- a/drivers/hid/usbhid/hid-core.c
1491 +++ b/drivers/hid/usbhid/hid-core.c
1492 @@ -477,8 +477,6 @@ static void hid_ctrl(struct urb *urb)
1493 struct usbhid_device *usbhid = hid->driver_data;
1494 int unplug = 0, status = urb->status;
1495
1496 - spin_lock(&usbhid->lock);
1497 -
1498 switch (status) {
1499 case 0: /* success */
1500 if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN)
1501 @@ -498,6 +496,8 @@ static void hid_ctrl(struct urb *urb)
1502 hid_warn(urb->dev, "ctrl urb status %d received\n", status);
1503 }
1504
1505 + spin_lock(&usbhid->lock);
1506 +
1507 if (unplug) {
1508 usbhid->ctrltail = usbhid->ctrlhead;
1509 } else {
1510 diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
1511 index 7df97777662d..dad768caa9c5 100644
1512 --- a/drivers/iommu/io-pgtable-arm.c
1513 +++ b/drivers/iommu/io-pgtable-arm.c
1514 @@ -405,17 +405,18 @@ static void __arm_lpae_free_pgtable(struct arm_lpae_io_pgtable *data, int lvl,
1515 arm_lpae_iopte *start, *end;
1516 unsigned long table_size;
1517
1518 - /* Only leaf entries at the last level */
1519 - if (lvl == ARM_LPAE_MAX_LEVELS - 1)
1520 - return;
1521 -
1522 if (lvl == ARM_LPAE_START_LVL(data))
1523 table_size = data->pgd_size;
1524 else
1525 table_size = 1UL << data->pg_shift;
1526
1527 start = ptep;
1528 - end = (void *)ptep + table_size;
1529 +
1530 + /* Only leaf entries at the last level */
1531 + if (lvl == ARM_LPAE_MAX_LEVELS - 1)
1532 + end = ptep;
1533 + else
1534 + end = (void *)ptep + table_size;
1535
1536 while (ptep != end) {
1537 arm_lpae_iopte pte = *ptep++;
1538 diff --git a/drivers/md/md.c b/drivers/md/md.c
1539 index 61aacab424cf..b1e1f6b95782 100644
1540 --- a/drivers/md/md.c
1541 +++ b/drivers/md/md.c
1542 @@ -2017,28 +2017,32 @@ int md_integrity_register(struct mddev *mddev)
1543 }
1544 EXPORT_SYMBOL(md_integrity_register);
1545
1546 -/* Disable data integrity if non-capable/non-matching disk is being added */
1547 -void md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev)
1548 +/*
1549 + * Attempt to add an rdev, but only if it is consistent with the current
1550 + * integrity profile
1551 + */
1552 +int md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev)
1553 {
1554 struct blk_integrity *bi_rdev;
1555 struct blk_integrity *bi_mddev;
1556 + char name[BDEVNAME_SIZE];
1557
1558 if (!mddev->gendisk)
1559 - return;
1560 + return 0;
1561
1562 bi_rdev = bdev_get_integrity(rdev->bdev);
1563 bi_mddev = blk_get_integrity(mddev->gendisk);
1564
1565 if (!bi_mddev) /* nothing to do */
1566 - return;
1567 - if (rdev->raid_disk < 0) /* skip spares */
1568 - return;
1569 - if (bi_rdev && blk_integrity_compare(mddev->gendisk,
1570 - rdev->bdev->bd_disk) >= 0)
1571 - return;
1572 - WARN_ON_ONCE(!mddev->suspended);
1573 - printk(KERN_NOTICE "disabling data integrity on %s\n", mdname(mddev));
1574 - blk_integrity_unregister(mddev->gendisk);
1575 + return 0;
1576 +
1577 + if (blk_integrity_compare(mddev->gendisk, rdev->bdev->bd_disk) != 0) {
1578 + printk(KERN_NOTICE "%s: incompatible integrity profile for %s\n",
1579 + mdname(mddev), bdevname(rdev->bdev, name));
1580 + return -ENXIO;
1581 + }
1582 +
1583 + return 0;
1584 }
1585 EXPORT_SYMBOL(md_integrity_add_rdev);
1586
1587 diff --git a/drivers/md/md.h b/drivers/md/md.h
1588 index ca0b643fe3c1..dfa57b41541b 100644
1589 --- a/drivers/md/md.h
1590 +++ b/drivers/md/md.h
1591 @@ -657,7 +657,7 @@ extern void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev);
1592 extern void md_set_array_sectors(struct mddev *mddev, sector_t array_sectors);
1593 extern int md_check_no_bitmap(struct mddev *mddev);
1594 extern int md_integrity_register(struct mddev *mddev);
1595 -extern void md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev);
1596 +extern int md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev);
1597 extern int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale);
1598
1599 extern void mddev_init(struct mddev *mddev);
1600 diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
1601 index 7331a80d89f1..0a72ab6e6c20 100644
1602 --- a/drivers/md/multipath.c
1603 +++ b/drivers/md/multipath.c
1604 @@ -257,6 +257,9 @@ static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev)
1605 disk_stack_limits(mddev->gendisk, rdev->bdev,
1606 rdev->data_offset << 9);
1607
1608 + err = md_integrity_add_rdev(rdev, mddev);
1609 + if (err)
1610 + break;
1611 spin_lock_irq(&conf->device_lock);
1612 mddev->degraded--;
1613 rdev->raid_disk = path;
1614 @@ -264,9 +267,6 @@ static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev)
1615 spin_unlock_irq(&conf->device_lock);
1616 rcu_assign_pointer(p->rdev, rdev);
1617 err = 0;
1618 - mddev_suspend(mddev);
1619 - md_integrity_add_rdev(rdev, mddev);
1620 - mddev_resume(mddev);
1621 break;
1622 }
1623
1624 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
1625 index e2169ff6e0f0..c4b913409226 100644
1626 --- a/drivers/md/raid1.c
1627 +++ b/drivers/md/raid1.c
1628 @@ -1589,6 +1589,9 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
1629 if (mddev->recovery_disabled == conf->recovery_disabled)
1630 return -EBUSY;
1631
1632 + if (md_integrity_add_rdev(rdev, mddev))
1633 + return -ENXIO;
1634 +
1635 if (rdev->raid_disk >= 0)
1636 first = last = rdev->raid_disk;
1637
1638 @@ -1632,9 +1635,6 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
1639 break;
1640 }
1641 }
1642 - mddev_suspend(mddev);
1643 - md_integrity_add_rdev(rdev, mddev);
1644 - mddev_resume(mddev);
1645 if (mddev->queue && blk_queue_discard(bdev_get_queue(rdev->bdev)))
1646 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mddev->queue);
1647 print_conf(conf);
1648 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
1649 index 84e597e1c489..ce959b4ae4df 100644
1650 --- a/drivers/md/raid10.c
1651 +++ b/drivers/md/raid10.c
1652 @@ -1698,6 +1698,9 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
1653 if (rdev->saved_raid_disk < 0 && !_enough(conf, 1, -1))
1654 return -EINVAL;
1655
1656 + if (md_integrity_add_rdev(rdev, mddev))
1657 + return -ENXIO;
1658 +
1659 if (rdev->raid_disk >= 0)
1660 first = last = rdev->raid_disk;
1661
1662 @@ -1739,9 +1742,6 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
1663 rcu_assign_pointer(p->rdev, rdev);
1664 break;
1665 }
1666 - mddev_suspend(mddev);
1667 - md_integrity_add_rdev(rdev, mddev);
1668 - mddev_resume(mddev);
1669 if (mddev->queue && blk_queue_discard(bdev_get_queue(rdev->bdev)))
1670 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mddev->queue);
1671
1672 diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
1673 index 728d2cc8a3e7..175a76114953 100644
1674 --- a/drivers/media/i2c/ir-kbd-i2c.c
1675 +++ b/drivers/media/i2c/ir-kbd-i2c.c
1676 @@ -478,7 +478,6 @@ static const struct i2c_device_id ir_kbd_id[] = {
1677 { "ir_rx_z8f0811_hdpvr", 0 },
1678 { }
1679 };
1680 -MODULE_DEVICE_TABLE(i2c, ir_kbd_id);
1681
1682 static struct i2c_driver ir_kbd_driver = {
1683 .driver = {
1684 diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c
1685 index 1d2c310ce838..94f816244407 100644
1686 --- a/drivers/media/pci/saa7134/saa7134-alsa.c
1687 +++ b/drivers/media/pci/saa7134/saa7134-alsa.c
1688 @@ -1211,6 +1211,8 @@ static int alsa_device_init(struct saa7134_dev *dev)
1689
1690 static int alsa_device_exit(struct saa7134_dev *dev)
1691 {
1692 + if (!snd_saa7134_cards[dev->nr])
1693 + return 1;
1694
1695 snd_card_free(snd_saa7134_cards[dev->nr]);
1696 snd_saa7134_cards[dev->nr] = NULL;
1697 @@ -1260,7 +1262,8 @@ static void saa7134_alsa_exit(void)
1698 int idx;
1699
1700 for (idx = 0; idx < SNDRV_CARDS; idx++) {
1701 - snd_card_free(snd_saa7134_cards[idx]);
1702 + if (snd_saa7134_cards[idx])
1703 + snd_card_free(snd_saa7134_cards[idx]);
1704 }
1705
1706 saa7134_dmasound_init = NULL;
1707 diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
1708 index ece544efccc3..3ff583f165cd 100644
1709 --- a/drivers/mtd/nand/nand_base.c
1710 +++ b/drivers/mtd/nand/nand_base.c
1711 @@ -3995,6 +3995,9 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
1712 return ret;
1713 }
1714
1715 + if (!mtd->name && mtd->dev.parent)
1716 + mtd->name = dev_name(mtd->dev.parent);
1717 +
1718 /* Set the default functions */
1719 nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16);
1720
1721 diff --git a/drivers/net/wireless/realtek/rtlwifi/regd.c b/drivers/net/wireless/realtek/rtlwifi/regd.c
1722 index a62bf0a65c32..5be34118e0af 100644
1723 --- a/drivers/net/wireless/realtek/rtlwifi/regd.c
1724 +++ b/drivers/net/wireless/realtek/rtlwifi/regd.c
1725 @@ -351,7 +351,6 @@ static const struct ieee80211_regdomain *_rtl_regdomain_select(
1726 case COUNTRY_CODE_SPAIN:
1727 case COUNTRY_CODE_FRANCE:
1728 case COUNTRY_CODE_ISRAEL:
1729 - case COUNTRY_CODE_WORLD_WIDE_13:
1730 return &rtl_regdom_12_13;
1731 case COUNTRY_CODE_MKK:
1732 case COUNTRY_CODE_MKK1:
1733 @@ -360,6 +359,7 @@ static const struct ieee80211_regdomain *_rtl_regdomain_select(
1734 return &rtl_regdom_14_60_64;
1735 case COUNTRY_CODE_GLOBAL_DOMAIN:
1736 return &rtl_regdom_14;
1737 + case COUNTRY_CODE_WORLD_WIDE_13:
1738 case COUNTRY_CODE_WORLD_WIDE_13_5G_ALL:
1739 return &rtl_regdom_12_13_5g_all;
1740 default:
1741 diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
1742 index 142bdff4ed60..4159f9b14db6 100644
1743 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
1744 +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
1745 @@ -95,8 +95,6 @@ int rtl8821ae_init_sw_vars(struct ieee80211_hw *hw)
1746 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1747
1748 rtl8821ae_bt_reg_init(hw);
1749 - rtlpci->msi_support = rtlpriv->cfg->mod_params->msi_support;
1750 - rtlpci->int_clear = rtlpriv->cfg->mod_params->int_clear;
1751 rtlpriv->btcoexist.btc_ops = rtl_btc_get_ops_pointer();
1752
1753 rtlpriv->dm.dm_initialgain_enable = 1;
1754 @@ -168,12 +166,15 @@ int rtl8821ae_init_sw_vars(struct ieee80211_hw *hw)
1755 rtlpriv->psc.swctrl_lps = rtlpriv->cfg->mod_params->swctrl_lps;
1756 rtlpriv->psc.fwctrl_lps = rtlpriv->cfg->mod_params->fwctrl_lps;
1757 rtlpci->msi_support = rtlpriv->cfg->mod_params->msi_support;
1758 - rtlpci->msi_support = rtlpriv->cfg->mod_params->int_clear;
1759 + rtlpci->int_clear = rtlpriv->cfg->mod_params->int_clear;
1760 + rtlpriv->cfg->mod_params->sw_crypto =
1761 + rtlpriv->cfg->mod_params->sw_crypto;
1762 + rtlpriv->cfg->mod_params->disable_watchdog =
1763 + rtlpriv->cfg->mod_params->disable_watchdog;
1764 if (rtlpriv->cfg->mod_params->disable_watchdog)
1765 pr_info("watchdog disabled\n");
1766 rtlpriv->psc.reg_fwctrl_lps = 3;
1767 rtlpriv->psc.reg_max_lps_awakeintvl = 5;
1768 - rtlpci->msi_support = rtlpriv->cfg->mod_params->msi_support;
1769
1770 /* for ASPM, you can close aspm through
1771 * set const_support_pciaspm = 0
1772 diff --git a/drivers/net/wireless/ti/wlcore/io.h b/drivers/net/wireless/ti/wlcore/io.h
1773 index 0305729d0986..10cf3747694d 100644
1774 --- a/drivers/net/wireless/ti/wlcore/io.h
1775 +++ b/drivers/net/wireless/ti/wlcore/io.h
1776 @@ -207,19 +207,23 @@ static inline int __must_check wlcore_write_reg(struct wl1271 *wl, int reg,
1777
1778 static inline void wl1271_power_off(struct wl1271 *wl)
1779 {
1780 - int ret;
1781 + int ret = 0;
1782
1783 if (!test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags))
1784 return;
1785
1786 - ret = wl->if_ops->power(wl->dev, false);
1787 + if (wl->if_ops->power)
1788 + ret = wl->if_ops->power(wl->dev, false);
1789 if (!ret)
1790 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
1791 }
1792
1793 static inline int wl1271_power_on(struct wl1271 *wl)
1794 {
1795 - int ret = wl->if_ops->power(wl->dev, true);
1796 + int ret = 0;
1797 +
1798 + if (wl->if_ops->power)
1799 + ret = wl->if_ops->power(wl->dev, true);
1800 if (ret == 0)
1801 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
1802
1803 diff --git a/drivers/net/wireless/ti/wlcore/spi.c b/drivers/net/wireless/ti/wlcore/spi.c
1804 index 236b41090827..44f059f7f34e 100644
1805 --- a/drivers/net/wireless/ti/wlcore/spi.c
1806 +++ b/drivers/net/wireless/ti/wlcore/spi.c
1807 @@ -73,7 +73,10 @@
1808 */
1809 #define SPI_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
1810
1811 -#define WSPI_MAX_NUM_OF_CHUNKS (SPI_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE)
1812 +/* Maximum number of SPI write chunks */
1813 +#define WSPI_MAX_NUM_OF_CHUNKS \
1814 + ((SPI_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE) + 1)
1815 +
1816
1817 struct wl12xx_spi_glue {
1818 struct device *dev;
1819 @@ -268,9 +271,10 @@ static int __must_check wl12xx_spi_raw_write(struct device *child, int addr,
1820 void *buf, size_t len, bool fixed)
1821 {
1822 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
1823 - struct spi_transfer t[2 * (WSPI_MAX_NUM_OF_CHUNKS + 1)];
1824 + /* SPI write buffers - 2 for each chunk */
1825 + struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
1826 struct spi_message m;
1827 - u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
1828 + u32 commands[WSPI_MAX_NUM_OF_CHUNKS]; /* 1 command per chunk */
1829 u32 *cmd;
1830 u32 chunk_len;
1831 int i;
1832 diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
1833 index d3346d23963b..89b3befc7155 100644
1834 --- a/drivers/pci/bus.c
1835 +++ b/drivers/pci/bus.c
1836 @@ -140,6 +140,8 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
1837 type_mask |= IORESOURCE_TYPE_BITS;
1838
1839 pci_bus_for_each_resource(bus, r, i) {
1840 + resource_size_t min_used = min;
1841 +
1842 if (!r)
1843 continue;
1844
1845 @@ -163,12 +165,12 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
1846 * overrides "min".
1847 */
1848 if (avail.start)
1849 - min = avail.start;
1850 + min_used = avail.start;
1851
1852 max = avail.end;
1853
1854 /* Ok, try it out.. */
1855 - ret = allocate_resource(r, res, size, min, max,
1856 + ret = allocate_resource(r, res, size, min_used, max,
1857 align, alignf, alignf_data);
1858 if (ret == 0)
1859 return 0;
1860 diff --git a/drivers/pci/host/pci-dra7xx.c b/drivers/pci/host/pci-dra7xx.c
1861 index 8c3688046c02..923607bdabc5 100644
1862 --- a/drivers/pci/host/pci-dra7xx.c
1863 +++ b/drivers/pci/host/pci-dra7xx.c
1864 @@ -302,7 +302,8 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
1865 }
1866
1867 ret = devm_request_irq(&pdev->dev, pp->irq,
1868 - dra7xx_pcie_msi_irq_handler, IRQF_SHARED,
1869 + dra7xx_pcie_msi_irq_handler,
1870 + IRQF_SHARED | IRQF_NO_THREAD,
1871 "dra7-pcie-msi", pp);
1872 if (ret) {
1873 dev_err(&pdev->dev, "failed to request irq\n");
1874 diff --git a/drivers/pci/host/pci-exynos.c b/drivers/pci/host/pci-exynos.c
1875 index 01095e1160a4..d997d22d4231 100644
1876 --- a/drivers/pci/host/pci-exynos.c
1877 +++ b/drivers/pci/host/pci-exynos.c
1878 @@ -522,7 +522,8 @@ static int __init exynos_add_pcie_port(struct pcie_port *pp,
1879
1880 ret = devm_request_irq(&pdev->dev, pp->msi_irq,
1881 exynos_pcie_msi_irq_handler,
1882 - IRQF_SHARED, "exynos-pcie", pp);
1883 + IRQF_SHARED | IRQF_NO_THREAD,
1884 + "exynos-pcie", pp);
1885 if (ret) {
1886 dev_err(&pdev->dev, "failed to request msi irq\n");
1887 return ret;
1888 diff --git a/drivers/pci/host/pci-imx6.c b/drivers/pci/host/pci-imx6.c
1889 index 22e8224126fd..9ce7cd148c86 100644
1890 --- a/drivers/pci/host/pci-imx6.c
1891 +++ b/drivers/pci/host/pci-imx6.c
1892 @@ -537,7 +537,8 @@ static int __init imx6_add_pcie_port(struct pcie_port *pp,
1893
1894 ret = devm_request_irq(&pdev->dev, pp->msi_irq,
1895 imx6_pcie_msi_handler,
1896 - IRQF_SHARED, "mx6-pcie-msi", pp);
1897 + IRQF_SHARED | IRQF_NO_THREAD,
1898 + "mx6-pcie-msi", pp);
1899 if (ret) {
1900 dev_err(&pdev->dev, "failed to request MSI irq\n");
1901 return ret;
1902 diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
1903 index 3018ae52e092..30323114c53c 100644
1904 --- a/drivers/pci/host/pci-tegra.c
1905 +++ b/drivers/pci/host/pci-tegra.c
1906 @@ -1288,7 +1288,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie)
1907
1908 msi->irq = err;
1909
1910 - err = request_irq(msi->irq, tegra_pcie_msi_irq, 0,
1911 + err = request_irq(msi->irq, tegra_pcie_msi_irq, IRQF_NO_THREAD,
1912 tegra_msi_irq_chip.name, pcie);
1913 if (err < 0) {
1914 dev_err(&pdev->dev, "failed to request IRQ: %d\n", err);
1915 diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
1916 index f4fa6c537448..414c33686621 100644
1917 --- a/drivers/pci/host/pcie-rcar.c
1918 +++ b/drivers/pci/host/pcie-rcar.c
1919 @@ -720,14 +720,16 @@ static int rcar_pcie_enable_msi(struct rcar_pcie *pcie)
1920
1921 /* Two irqs are for MSI, but they are also used for non-MSI irqs */
1922 err = devm_request_irq(&pdev->dev, msi->irq1, rcar_pcie_msi_irq,
1923 - IRQF_SHARED, rcar_msi_irq_chip.name, pcie);
1924 + IRQF_SHARED | IRQF_NO_THREAD,
1925 + rcar_msi_irq_chip.name, pcie);
1926 if (err < 0) {
1927 dev_err(&pdev->dev, "failed to request IRQ: %d\n", err);
1928 goto err;
1929 }
1930
1931 err = devm_request_irq(&pdev->dev, msi->irq2, rcar_pcie_msi_irq,
1932 - IRQF_SHARED, rcar_msi_irq_chip.name, pcie);
1933 + IRQF_SHARED | IRQF_NO_THREAD,
1934 + rcar_msi_irq_chip.name, pcie);
1935 if (err < 0) {
1936 dev_err(&pdev->dev, "failed to request IRQ: %d\n", err);
1937 goto err;
1938 diff --git a/drivers/pci/host/pcie-spear13xx.c b/drivers/pci/host/pcie-spear13xx.c
1939 index b95b7563c052..a6cd8233e8c0 100644
1940 --- a/drivers/pci/host/pcie-spear13xx.c
1941 +++ b/drivers/pci/host/pcie-spear13xx.c
1942 @@ -279,7 +279,8 @@ static int spear13xx_add_pcie_port(struct pcie_port *pp,
1943 return -ENODEV;
1944 }
1945 ret = devm_request_irq(dev, pp->irq, spear13xx_pcie_irq_handler,
1946 - IRQF_SHARED, "spear1340-pcie", pp);
1947 + IRQF_SHARED | IRQF_NO_THREAD,
1948 + "spear1340-pcie", pp);
1949 if (ret) {
1950 dev_err(dev, "failed to request irq %d\n", pp->irq);
1951 return ret;
1952 diff --git a/drivers/pci/host/pcie-xilinx.c b/drivers/pci/host/pcie-xilinx.c
1953 index 3c7a0d580b1e..4cfa46360d12 100644
1954 --- a/drivers/pci/host/pcie-xilinx.c
1955 +++ b/drivers/pci/host/pcie-xilinx.c
1956 @@ -781,7 +781,8 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie_port *port)
1957
1958 port->irq = irq_of_parse_and_map(node, 0);
1959 err = devm_request_irq(dev, port->irq, xilinx_pcie_intr_handler,
1960 - IRQF_SHARED, "xilinx-pcie", port);
1961 + IRQF_SHARED | IRQF_NO_THREAD,
1962 + "xilinx-pcie", port);
1963 if (err) {
1964 dev_err(dev, "unable to request irq %d\n", port->irq);
1965 return err;
1966 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
1967 index e49c2bce551d..cf000b331eed 100644
1968 --- a/drivers/tty/n_tty.c
1969 +++ b/drivers/tty/n_tty.c
1970 @@ -258,16 +258,13 @@ static void n_tty_check_throttle(struct tty_struct *tty)
1971
1972 static void n_tty_check_unthrottle(struct tty_struct *tty)
1973 {
1974 - if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1975 - tty->link->ldisc->ops->write_wakeup == n_tty_write_wakeup) {
1976 + if (tty->driver->type == TTY_DRIVER_TYPE_PTY) {
1977 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE)
1978 return;
1979 if (!tty->count)
1980 return;
1981 n_tty_kick_worker(tty);
1982 - n_tty_write_wakeup(tty->link);
1983 - if (waitqueue_active(&tty->link->write_wait))
1984 - wake_up_interruptible_poll(&tty->link->write_wait, POLLOUT);
1985 + tty_wakeup(tty->link);
1986 return;
1987 }
1988
1989 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
1990 index bcc8e1e8bb72..7cef54334b12 100644
1991 --- a/drivers/tty/tty_io.c
1992 +++ b/drivers/tty/tty_io.c
1993 @@ -1462,13 +1462,13 @@ static int tty_reopen(struct tty_struct *tty)
1994 {
1995 struct tty_driver *driver = tty->driver;
1996
1997 - if (!tty->count)
1998 - return -EIO;
1999 -
2000 if (driver->type == TTY_DRIVER_TYPE_PTY &&
2001 driver->subtype == PTY_TYPE_MASTER)
2002 return -EIO;
2003
2004 + if (!tty->count)
2005 + return -EAGAIN;
2006 +
2007 if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN))
2008 return -EBUSY;
2009
2010 @@ -2069,7 +2069,12 @@ retry_open:
2011
2012 if (tty) {
2013 mutex_unlock(&tty_mutex);
2014 - tty_lock(tty);
2015 + retval = tty_lock_interruptible(tty);
2016 + if (retval) {
2017 + if (retval == -EINTR)
2018 + retval = -ERESTARTSYS;
2019 + goto err_unref;
2020 + }
2021 /* safe to drop the kref from tty_driver_lookup_tty() */
2022 tty_kref_put(tty);
2023 retval = tty_reopen(tty);
2024 @@ -2087,7 +2092,11 @@ retry_open:
2025
2026 if (IS_ERR(tty)) {
2027 retval = PTR_ERR(tty);
2028 - goto err_file;
2029 + if (retval != -EAGAIN || signal_pending(current))
2030 + goto err_file;
2031 + tty_free_file(filp);
2032 + schedule();
2033 + goto retry_open;
2034 }
2035
2036 tty_add_file(tty, filp);
2037 @@ -2156,6 +2165,7 @@ retry_open:
2038 return 0;
2039 err_unlock:
2040 mutex_unlock(&tty_mutex);
2041 +err_unref:
2042 /* after locks to avoid deadlock */
2043 if (!IS_ERR_OR_NULL(driver))
2044 tty_driver_kref_put(driver);
2045 @@ -2653,6 +2663,28 @@ static int tiocsetd(struct tty_struct *tty, int __user *p)
2046 }
2047
2048 /**
2049 + * tiocgetd - get line discipline
2050 + * @tty: tty device
2051 + * @p: pointer to user data
2052 + *
2053 + * Retrieves the line discipline id directly from the ldisc.
2054 + *
2055 + * Locking: waits for ldisc reference (in case the line discipline
2056 + * is changing or the tty is being hungup)
2057 + */
2058 +
2059 +static int tiocgetd(struct tty_struct *tty, int __user *p)
2060 +{
2061 + struct tty_ldisc *ld;
2062 + int ret;
2063 +
2064 + ld = tty_ldisc_ref_wait(tty);
2065 + ret = put_user(ld->ops->num, p);
2066 + tty_ldisc_deref(ld);
2067 + return ret;
2068 +}
2069 +
2070 +/**
2071 * send_break - performed time break
2072 * @tty: device to break on
2073 * @duration: timeout in mS
2074 @@ -2878,7 +2910,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2075 case TIOCGSID:
2076 return tiocgsid(tty, real_tty, p);
2077 case TIOCGETD:
2078 - return put_user(tty->ldisc->ops->num, (int __user *)p);
2079 + return tiocgetd(tty, p);
2080 case TIOCSETD:
2081 return tiocsetd(tty, p);
2082 case TIOCVHANGUP:
2083 diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
2084 index 0efcf713b756..d09293bc0e04 100644
2085 --- a/drivers/tty/tty_mutex.c
2086 +++ b/drivers/tty/tty_mutex.c
2087 @@ -22,6 +22,14 @@ void __lockfunc tty_lock(struct tty_struct *tty)
2088 }
2089 EXPORT_SYMBOL(tty_lock);
2090
2091 +int tty_lock_interruptible(struct tty_struct *tty)
2092 +{
2093 + if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
2094 + return -EIO;
2095 + tty_kref_get(tty);
2096 + return mutex_lock_interruptible(&tty->legacy_mutex);
2097 +}
2098 +
2099 void __lockfunc tty_unlock(struct tty_struct *tty)
2100 {
2101 if (tty->magic != TTY_MAGIC) {
2102 diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
2103 index 26ca4f910cb0..e4c70dce3e7c 100644
2104 --- a/drivers/usb/class/cdc-acm.c
2105 +++ b/drivers/usb/class/cdc-acm.c
2106 @@ -428,7 +428,8 @@ static void acm_read_bulk_callback(struct urb *urb)
2107 set_bit(rb->index, &acm->read_urbs_free);
2108 dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n",
2109 __func__, status);
2110 - return;
2111 + if ((status != -ENOENT) || (urb->actual_length == 0))
2112 + return;
2113 }
2114
2115 usb_mark_last_busy(acm->dev);
2116 @@ -1404,6 +1405,8 @@ made_compressed_probe:
2117 usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
2118 NULL, acm->writesize, acm_write_bulk, snd);
2119 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2120 + if (quirks & SEND_ZERO_PACKET)
2121 + snd->urb->transfer_flags |= URB_ZERO_PACKET;
2122 snd->instance = acm;
2123 }
2124
2125 @@ -1861,6 +1864,10 @@ static const struct usb_device_id acm_ids[] = {
2126 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
2127 USB_CDC_ACM_PROTO_AT_CDMA) },
2128
2129 + { USB_DEVICE(0x1519, 0x0452), /* Intel 7260 modem */
2130 + .driver_info = SEND_ZERO_PACKET,
2131 + },
2132 +
2133 { }
2134 };
2135
2136 diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
2137 index dd9af38e7cda..ccfaba9ab4e4 100644
2138 --- a/drivers/usb/class/cdc-acm.h
2139 +++ b/drivers/usb/class/cdc-acm.h
2140 @@ -134,3 +134,4 @@ struct acm {
2141 #define IGNORE_DEVICE BIT(5)
2142 #define QUIRK_CONTROL_LINE_STATE BIT(6)
2143 #define CLEAR_HALT_CONDITIONS BIT(7)
2144 +#define SEND_ZERO_PACKET BIT(8)
2145 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
2146 index 8683436788c3..1560f3f3e756 100644
2147 --- a/drivers/usb/core/hub.c
2148 +++ b/drivers/usb/core/hub.c
2149 @@ -5386,7 +5386,6 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
2150 }
2151
2152 bos = udev->bos;
2153 - udev->bos = NULL;
2154
2155 for (i = 0; i < SET_CONFIG_TRIES; ++i) {
2156
2157 @@ -5479,8 +5478,11 @@ done:
2158 usb_set_usb2_hardware_lpm(udev, 1);
2159 usb_unlocked_enable_lpm(udev);
2160 usb_enable_ltm(udev);
2161 - usb_release_bos_descriptor(udev);
2162 - udev->bos = bos;
2163 + /* release the new BOS descriptor allocated by hub_port_init() */
2164 + if (udev->bos != bos) {
2165 + usb_release_bos_descriptor(udev);
2166 + udev->bos = bos;
2167 + }
2168 return 0;
2169
2170 re_enumerate:
2171 diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
2172 index c62109091d12..c2d65206ec6c 100644
2173 --- a/drivers/usb/host/xhci-pci.c
2174 +++ b/drivers/usb/host/xhci-pci.c
2175 @@ -28,7 +28,9 @@
2176 #include "xhci.h"
2177 #include "xhci-trace.h"
2178
2179 -#define PORT2_SSIC_CONFIG_REG2 0x883c
2180 +#define SSIC_PORT_NUM 2
2181 +#define SSIC_PORT_CFG2 0x880c
2182 +#define SSIC_PORT_CFG2_OFFSET 0x30
2183 #define PROG_DONE (1 << 30)
2184 #define SSIC_PORT_UNUSED (1 << 31)
2185
2186 @@ -45,6 +47,7 @@
2187 #define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5
2188 #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f
2189 #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI 0x9d2f
2190 +#define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI 0x0aa8
2191
2192 static const char hcd_name[] = "xhci_hcd";
2193
2194 @@ -152,7 +155,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
2195 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
2196 (pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
2197 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
2198 - pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI)) {
2199 + pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
2200 + pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI)) {
2201 xhci->quirks |= XHCI_PME_STUCK_QUIRK;
2202 }
2203 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
2204 @@ -322,28 +326,36 @@ static void xhci_pme_quirk(struct usb_hcd *hcd, bool suspend)
2205 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
2206 u32 val;
2207 void __iomem *reg;
2208 + int i;
2209
2210 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
2211 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI) {
2212
2213 - reg = (void __iomem *) xhci->cap_regs + PORT2_SSIC_CONFIG_REG2;
2214 -
2215 - /* Notify SSIC that SSIC profile programming is not done */
2216 - val = readl(reg) & ~PROG_DONE;
2217 - writel(val, reg);
2218 -
2219 - /* Mark SSIC port as unused(suspend) or used(resume) */
2220 - val = readl(reg);
2221 - if (suspend)
2222 - val |= SSIC_PORT_UNUSED;
2223 - else
2224 - val &= ~SSIC_PORT_UNUSED;
2225 - writel(val, reg);
2226 -
2227 - /* Notify SSIC that SSIC profile programming is done */
2228 - val = readl(reg) | PROG_DONE;
2229 - writel(val, reg);
2230 - readl(reg);
2231 + for (i = 0; i < SSIC_PORT_NUM; i++) {
2232 + reg = (void __iomem *) xhci->cap_regs +
2233 + SSIC_PORT_CFG2 +
2234 + i * SSIC_PORT_CFG2_OFFSET;
2235 +
2236 + /*
2237 + * Notify SSIC that SSIC profile programming
2238 + * is not done.
2239 + */
2240 + val = readl(reg) & ~PROG_DONE;
2241 + writel(val, reg);
2242 +
2243 + /* Mark SSIC port as unused(suspend) or used(resume) */
2244 + val = readl(reg);
2245 + if (suspend)
2246 + val |= SSIC_PORT_UNUSED;
2247 + else
2248 + val &= ~SSIC_PORT_UNUSED;
2249 + writel(val, reg);
2250 +
2251 + /* Notify SSIC that SSIC profile programming is done */
2252 + val = readl(reg) | PROG_DONE;
2253 + writel(val, reg);
2254 + readl(reg);
2255 + }
2256 }
2257
2258 reg = (void __iomem *) xhci->cap_regs + 0x80a4;
2259 diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
2260 index 0d19a6d61a71..970a30e155cb 100644
2261 --- a/drivers/usb/phy/phy-msm-usb.c
2262 +++ b/drivers/usb/phy/phy-msm-usb.c
2263 @@ -1599,6 +1599,8 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg)
2264 &motg->id.nb);
2265 if (ret < 0) {
2266 dev_err(&pdev->dev, "register ID notifier failed\n");
2267 + extcon_unregister_notifier(motg->vbus.extcon,
2268 + EXTCON_USB, &motg->vbus.nb);
2269 return ret;
2270 }
2271
2272 @@ -1660,15 +1662,6 @@ static int msm_otg_probe(struct platform_device *pdev)
2273 if (!motg)
2274 return -ENOMEM;
2275
2276 - pdata = dev_get_platdata(&pdev->dev);
2277 - if (!pdata) {
2278 - if (!np)
2279 - return -ENXIO;
2280 - ret = msm_otg_read_dt(pdev, motg);
2281 - if (ret)
2282 - return ret;
2283 - }
2284 -
2285 motg->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg),
2286 GFP_KERNEL);
2287 if (!motg->phy.otg)
2288 @@ -1710,6 +1703,15 @@ static int msm_otg_probe(struct platform_device *pdev)
2289 if (!motg->regs)
2290 return -ENOMEM;
2291
2292 + pdata = dev_get_platdata(&pdev->dev);
2293 + if (!pdata) {
2294 + if (!np)
2295 + return -ENXIO;
2296 + ret = msm_otg_read_dt(pdev, motg);
2297 + if (ret)
2298 + return ret;
2299 + }
2300 +
2301 /*
2302 * NOTE: The PHYs can be multiplexed between the chipidea controller
2303 * and the dwc3 controller, using a single bit. It is important that
2304 @@ -1717,8 +1719,10 @@ static int msm_otg_probe(struct platform_device *pdev)
2305 */
2306 if (motg->phy_number) {
2307 phy_select = devm_ioremap_nocache(&pdev->dev, USB2_PHY_SEL, 4);
2308 - if (!phy_select)
2309 - return -ENOMEM;
2310 + if (!phy_select) {
2311 + ret = -ENOMEM;
2312 + goto unregister_extcon;
2313 + }
2314 /* Enable second PHY with the OTG port */
2315 writel(0x1, phy_select);
2316 }
2317 @@ -1728,7 +1732,8 @@ static int msm_otg_probe(struct platform_device *pdev)
2318 motg->irq = platform_get_irq(pdev, 0);
2319 if (motg->irq < 0) {
2320 dev_err(&pdev->dev, "platform_get_irq failed\n");
2321 - return motg->irq;
2322 + ret = motg->irq;
2323 + goto unregister_extcon;
2324 }
2325
2326 regs[0].supply = "vddcx";
2327 @@ -1737,7 +1742,7 @@ static int msm_otg_probe(struct platform_device *pdev)
2328
2329 ret = devm_regulator_bulk_get(motg->phy.dev, ARRAY_SIZE(regs), regs);
2330 if (ret)
2331 - return ret;
2332 + goto unregister_extcon;
2333
2334 motg->vddcx = regs[0].consumer;
2335 motg->v3p3 = regs[1].consumer;
2336 @@ -1834,6 +1839,12 @@ disable_clks:
2337 clk_disable_unprepare(motg->clk);
2338 if (!IS_ERR(motg->core_clk))
2339 clk_disable_unprepare(motg->core_clk);
2340 +unregister_extcon:
2341 + extcon_unregister_notifier(motg->id.extcon,
2342 + EXTCON_USB_HOST, &motg->id.nb);
2343 + extcon_unregister_notifier(motg->vbus.extcon,
2344 + EXTCON_USB, &motg->vbus.nb);
2345 +
2346 return ret;
2347 }
2348
2349 diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
2350 index 59b2126b21a3..1dd9919081f8 100644
2351 --- a/drivers/usb/serial/cp210x.c
2352 +++ b/drivers/usb/serial/cp210x.c
2353 @@ -98,6 +98,7 @@ static const struct usb_device_id id_table[] = {
2354 { USB_DEVICE(0x10C4, 0x81AC) }, /* MSD Dash Hawk */
2355 { USB_DEVICE(0x10C4, 0x81AD) }, /* INSYS USB Modem */
2356 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */
2357 + { USB_DEVICE(0x10C4, 0x81D7) }, /* IAI Corp. RCB-CV-USB USB to RS485 Adaptor */
2358 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */
2359 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */
2360 { USB_DEVICE(0x10C4, 0x81E8) }, /* Zephyr Bioharness */
2361 diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
2362 index a5a0376bbd48..8c660ae401d8 100644
2363 --- a/drivers/usb/serial/ftdi_sio.c
2364 +++ b/drivers/usb/serial/ftdi_sio.c
2365 @@ -824,6 +824,7 @@ static const struct usb_device_id id_table_combined[] = {
2366 { USB_DEVICE(FTDI_VID, FTDI_TURTELIZER_PID),
2367 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
2368 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) },
2369 + { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_SCU18) },
2370 { USB_DEVICE(FTDI_VID, FTDI_REU_TINY_PID) },
2371
2372 /* Papouch devices based on FTDI chip */
2373 diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
2374 index 67c6d4469730..a84df2513994 100644
2375 --- a/drivers/usb/serial/ftdi_sio_ids.h
2376 +++ b/drivers/usb/serial/ftdi_sio_ids.h
2377 @@ -615,6 +615,7 @@
2378 */
2379 #define RATOC_VENDOR_ID 0x0584
2380 #define RATOC_PRODUCT_ID_USB60F 0xb020
2381 +#define RATOC_PRODUCT_ID_SCU18 0xb03a
2382
2383 /*
2384 * Infineon Technologies
2385 diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
2386 index f2280606b73c..db86e512e0fc 100644
2387 --- a/drivers/usb/serial/option.c
2388 +++ b/drivers/usb/serial/option.c
2389 @@ -268,6 +268,8 @@ static void option_instat_callback(struct urb *urb);
2390 #define TELIT_PRODUCT_CC864_SINGLE 0x1006
2391 #define TELIT_PRODUCT_DE910_DUAL 0x1010
2392 #define TELIT_PRODUCT_UE910_V2 0x1012
2393 +#define TELIT_PRODUCT_LE922_USBCFG0 0x1042
2394 +#define TELIT_PRODUCT_LE922_USBCFG3 0x1043
2395 #define TELIT_PRODUCT_LE920 0x1200
2396 #define TELIT_PRODUCT_LE910 0x1201
2397
2398 @@ -615,6 +617,16 @@ static const struct option_blacklist_info telit_le920_blacklist = {
2399 .reserved = BIT(1) | BIT(5),
2400 };
2401
2402 +static const struct option_blacklist_info telit_le922_blacklist_usbcfg0 = {
2403 + .sendsetup = BIT(2),
2404 + .reserved = BIT(0) | BIT(1) | BIT(3),
2405 +};
2406 +
2407 +static const struct option_blacklist_info telit_le922_blacklist_usbcfg3 = {
2408 + .sendsetup = BIT(0),
2409 + .reserved = BIT(1) | BIT(2) | BIT(3),
2410 +};
2411 +
2412 static const struct usb_device_id option_ids[] = {
2413 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
2414 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
2415 @@ -1160,6 +1172,10 @@ static const struct usb_device_id option_ids[] = {
2416 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_CC864_SINGLE) },
2417 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_DE910_DUAL) },
2418 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UE910_V2) },
2419 + { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE922_USBCFG0),
2420 + .driver_info = (kernel_ulong_t)&telit_le922_blacklist_usbcfg0 },
2421 + { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE922_USBCFG3),
2422 + .driver_info = (kernel_ulong_t)&telit_le922_blacklist_usbcfg3 },
2423 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE910),
2424 .driver_info = (kernel_ulong_t)&telit_le910_blacklist },
2425 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920),
2426 @@ -1679,7 +1695,7 @@ static const struct usb_device_id option_ids[] = {
2427 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_EU3_P) },
2428 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_PH8),
2429 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
2430 - { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX) },
2431 + { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX, 0xff) },
2432 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_PLXX),
2433 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
2434 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDM) },
2435 diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
2436 index 60afb39eb73c..337a0be89fcf 100644
2437 --- a/drivers/usb/serial/visor.c
2438 +++ b/drivers/usb/serial/visor.c
2439 @@ -544,6 +544,11 @@ static int treo_attach(struct usb_serial *serial)
2440 (serial->num_interrupt_in == 0))
2441 return 0;
2442
2443 + if (serial->num_bulk_in < 2 || serial->num_interrupt_in < 2) {
2444 + dev_err(&serial->interface->dev, "missing endpoints\n");
2445 + return -ENODEV;
2446 + }
2447 +
2448 /*
2449 * It appears that Treos and Kyoceras want to use the
2450 * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint,
2451 @@ -597,8 +602,10 @@ static int clie_5_attach(struct usb_serial *serial)
2452 */
2453
2454 /* some sanity check */
2455 - if (serial->num_ports < 2)
2456 - return -1;
2457 + if (serial->num_bulk_out < 2) {
2458 + dev_err(&serial->interface->dev, "missing bulk out endpoints\n");
2459 + return -ENODEV;
2460 + }
2461
2462 /* port 0 now uses the modified endpoint Address */
2463 port = serial->port[0];
2464 diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c
2465 index c5882b36e558..9a16d1e75a49 100644
2466 --- a/fs/ext4/crypto_key.c
2467 +++ b/fs/ext4/crypto_key.c
2468 @@ -213,9 +213,11 @@ retry:
2469 res = -ENOKEY;
2470 goto out;
2471 }
2472 + down_read(&keyring_key->sem);
2473 ukp = user_key_payload(keyring_key);
2474 if (ukp->datalen != sizeof(struct ext4_encryption_key)) {
2475 res = -EINVAL;
2476 + up_read(&keyring_key->sem);
2477 goto out;
2478 }
2479 master_key = (struct ext4_encryption_key *)ukp->data;
2480 @@ -226,10 +228,12 @@ retry:
2481 "ext4: key size incorrect: %d\n",
2482 master_key->size);
2483 res = -ENOKEY;
2484 + up_read(&keyring_key->sem);
2485 goto out;
2486 }
2487 res = ext4_derive_key_aes(ctx.nonce, master_key->raw,
2488 raw_key);
2489 + up_read(&keyring_key->sem);
2490 if (res)
2491 goto out;
2492 got_key:
2493 diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
2494 index 89818036f035..343b0f1f15b1 100644
2495 --- a/fs/nfs/nfs4proc.c
2496 +++ b/fs/nfs/nfs4proc.c
2497 @@ -8054,7 +8054,6 @@ static void nfs4_layoutreturn_release(void *calldata)
2498 pnfs_set_layout_stateid(lo, &lrp->res.stateid, true);
2499 pnfs_mark_matching_lsegs_invalid(lo, &freeme, &lrp->args.range);
2500 pnfs_clear_layoutreturn_waitbit(lo);
2501 - lo->plh_block_lgets--;
2502 spin_unlock(&lo->plh_inode->i_lock);
2503 pnfs_free_lseg_list(&freeme);
2504 pnfs_put_layout_hdr(lrp->args.layout);
2505 diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c
2506 index 84f2f8079466..4e2162b355db 100644
2507 --- a/fs/ocfs2/dlm/dlmmaster.c
2508 +++ b/fs/ocfs2/dlm/dlmmaster.c
2509 @@ -2519,6 +2519,11 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm,
2510 spin_lock(&dlm->master_lock);
2511 ret = dlm_add_migration_mle(dlm, res, mle, &oldmle, name,
2512 namelen, target, dlm->node_num);
2513 + /* get an extra reference on the mle.
2514 + * otherwise the assert_master from the new
2515 + * master will destroy this.
2516 + */
2517 + dlm_get_mle_inuse(mle);
2518 spin_unlock(&dlm->master_lock);
2519 spin_unlock(&dlm->spinlock);
2520
2521 @@ -2554,6 +2559,7 @@ fail:
2522 if (mle_added) {
2523 dlm_mle_detach_hb_events(dlm, mle);
2524 dlm_put_mle(mle);
2525 + dlm_put_mle_inuse(mle);
2526 } else if (mle) {
2527 kmem_cache_free(dlm_mle_cache, mle);
2528 mle = NULL;
2529 @@ -2571,17 +2577,6 @@ fail:
2530 * ensure that all assert_master work is flushed. */
2531 flush_workqueue(dlm->dlm_worker);
2532
2533 - /* get an extra reference on the mle.
2534 - * otherwise the assert_master from the new
2535 - * master will destroy this.
2536 - * also, make sure that all callers of dlm_get_mle
2537 - * take both dlm->spinlock and dlm->master_lock */
2538 - spin_lock(&dlm->spinlock);
2539 - spin_lock(&dlm->master_lock);
2540 - dlm_get_mle_inuse(mle);
2541 - spin_unlock(&dlm->master_lock);
2542 - spin_unlock(&dlm->spinlock);
2543 -
2544 /* notify new node and send all lock state */
2545 /* call send_one_lockres with migration flag.
2546 * this serves as notice to the target node that a
2547 @@ -3312,6 +3307,15 @@ top:
2548 mle->new_master != dead_node)
2549 continue;
2550
2551 + if (mle->new_master == dead_node && mle->inuse) {
2552 + mlog(ML_NOTICE, "%s: target %u died during "
2553 + "migration from %u, the MLE is "
2554 + "still keep used, ignore it!\n",
2555 + dlm->name, dead_node,
2556 + mle->master);
2557 + continue;
2558 + }
2559 +
2560 /* If we have reached this point, this mle needs to be
2561 * removed from the list and freed. */
2562 dlm_clean_migration_mle(dlm, mle);
2563 diff --git a/fs/ocfs2/dlm/dlmrecovery.c b/fs/ocfs2/dlm/dlmrecovery.c
2564 index 9e4f862d20fe..42f0cae93a0a 100644
2565 --- a/fs/ocfs2/dlm/dlmrecovery.c
2566 +++ b/fs/ocfs2/dlm/dlmrecovery.c
2567 @@ -2360,6 +2360,8 @@ static void dlm_do_local_recovery_cleanup(struct dlm_ctxt *dlm, u8 dead_node)
2568 break;
2569 }
2570 }
2571 + dlm_lockres_clear_refmap_bit(dlm, res,
2572 + dead_node);
2573 spin_unlock(&res->spinlock);
2574 continue;
2575 }
2576 diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
2577 index 20276e340339..b002acf50203 100644
2578 --- a/fs/ocfs2/dlmglue.c
2579 +++ b/fs/ocfs2/dlmglue.c
2580 @@ -1390,6 +1390,7 @@ static int __ocfs2_cluster_lock(struct ocfs2_super *osb,
2581 unsigned int gen;
2582 int noqueue_attempted = 0;
2583 int dlm_locked = 0;
2584 + int kick_dc = 0;
2585
2586 if (!(lockres->l_flags & OCFS2_LOCK_INITIALIZED)) {
2587 mlog_errno(-EINVAL);
2588 @@ -1524,7 +1525,12 @@ update_holders:
2589 unlock:
2590 lockres_clear_flags(lockres, OCFS2_LOCK_UPCONVERT_FINISHING);
2591
2592 + /* ocfs2_unblock_lock reques on seeing OCFS2_LOCK_UPCONVERT_FINISHING */
2593 + kick_dc = (lockres->l_flags & OCFS2_LOCK_BLOCKED);
2594 +
2595 spin_unlock_irqrestore(&lockres->l_lock, flags);
2596 + if (kick_dc)
2597 + ocfs2_wake_downconvert_thread(osb);
2598 out:
2599 /*
2600 * This is helping work around a lock inversion between the page lock
2601 diff --git a/include/crypto/hash.h b/include/crypto/hash.h
2602 index 3d69c93d50e8..6361892ea737 100644
2603 --- a/include/crypto/hash.h
2604 +++ b/include/crypto/hash.h
2605 @@ -204,6 +204,7 @@ struct crypto_ahash {
2606 unsigned int keylen);
2607
2608 unsigned int reqsize;
2609 + bool has_setkey;
2610 struct crypto_tfm base;
2611 };
2612
2613 @@ -375,6 +376,11 @@ static inline void *ahash_request_ctx(struct ahash_request *req)
2614 int crypto_ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
2615 unsigned int keylen);
2616
2617 +static inline bool crypto_ahash_has_setkey(struct crypto_ahash *tfm)
2618 +{
2619 + return tfm->has_setkey;
2620 +}
2621 +
2622 /**
2623 * crypto_ahash_finup() - update and finalize message digest
2624 * @req: reference to the ahash_request handle that holds all information
2625 diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h
2626 index 018afb264ac2..a2bfd7843f18 100644
2627 --- a/include/crypto/if_alg.h
2628 +++ b/include/crypto/if_alg.h
2629 @@ -30,6 +30,9 @@ struct alg_sock {
2630
2631 struct sock *parent;
2632
2633 + unsigned int refcnt;
2634 + unsigned int nokey_refcnt;
2635 +
2636 const struct af_alg_type *type;
2637 void *private;
2638 };
2639 @@ -50,9 +53,11 @@ struct af_alg_type {
2640 void (*release)(void *private);
2641 int (*setkey)(void *private, const u8 *key, unsigned int keylen);
2642 int (*accept)(void *private, struct sock *sk);
2643 + int (*accept_nokey)(void *private, struct sock *sk);
2644 int (*setauthsize)(void *private, unsigned int authsize);
2645
2646 struct proto_ops *ops;
2647 + struct proto_ops *ops_nokey;
2648 struct module *owner;
2649 char name[14];
2650 };
2651 @@ -67,6 +72,7 @@ int af_alg_register_type(const struct af_alg_type *type);
2652 int af_alg_unregister_type(const struct af_alg_type *type);
2653
2654 int af_alg_release(struct socket *sock);
2655 +void af_alg_release_parent(struct sock *sk);
2656 int af_alg_accept(struct sock *sk, struct socket *newsock);
2657
2658 int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len);
2659 @@ -83,11 +89,6 @@ static inline struct alg_sock *alg_sk(struct sock *sk)
2660 return (struct alg_sock *)sk;
2661 }
2662
2663 -static inline void af_alg_release_parent(struct sock *sk)
2664 -{
2665 - sock_put(alg_sk(sk)->parent);
2666 -}
2667 -
2668 static inline void af_alg_init_completion(struct af_alg_completion *completion)
2669 {
2670 init_completion(&completion->completion);
2671 diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
2672 index d8dd41fb034f..fd8742a40ff3 100644
2673 --- a/include/crypto/skcipher.h
2674 +++ b/include/crypto/skcipher.h
2675 @@ -61,6 +61,8 @@ struct crypto_skcipher {
2676 unsigned int ivsize;
2677 unsigned int reqsize;
2678
2679 + bool has_setkey;
2680 +
2681 struct crypto_tfm base;
2682 };
2683
2684 @@ -305,6 +307,11 @@ static inline int crypto_skcipher_setkey(struct crypto_skcipher *tfm,
2685 return tfm->setkey(tfm, key, keylen);
2686 }
2687
2688 +static inline bool crypto_skcipher_has_setkey(struct crypto_skcipher *tfm)
2689 +{
2690 + return tfm->has_setkey;
2691 +}
2692 +
2693 /**
2694 * crypto_skcipher_reqtfm() - obtain cipher handle from request
2695 * @req: skcipher_request out of which the cipher handle is to be obtained
2696 diff --git a/include/linux/console.h b/include/linux/console.h
2697 index bd194343c346..ea731af2451e 100644
2698 --- a/include/linux/console.h
2699 +++ b/include/linux/console.h
2700 @@ -150,6 +150,7 @@ extern int console_trylock(void);
2701 extern void console_unlock(void);
2702 extern void console_conditional_schedule(void);
2703 extern void console_unblank(void);
2704 +extern void console_flush_on_panic(void);
2705 extern struct tty_driver *console_device(int *);
2706 extern void console_stop(struct console *);
2707 extern void console_start(struct console *);
2708 diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
2709 index 76dd4f0da5ca..2ead22dd74a0 100644
2710 --- a/include/linux/hrtimer.h
2711 +++ b/include/linux/hrtimer.h
2712 @@ -87,7 +87,8 @@ enum hrtimer_restart {
2713 * @function: timer expiry callback function
2714 * @base: pointer to the timer base (per cpu and per clock)
2715 * @state: state information (See bit values above)
2716 - * @start_pid: timer statistics field to store the pid of the task which
2717 + * @is_rel: Set if the timer was armed relative
2718 + * @start_pid: timer statistics field to store the pid of the task which
2719 * started the timer
2720 * @start_site: timer statistics field to store the site where the timer
2721 * was started
2722 @@ -101,7 +102,8 @@ struct hrtimer {
2723 ktime_t _softexpires;
2724 enum hrtimer_restart (*function)(struct hrtimer *);
2725 struct hrtimer_clock_base *base;
2726 - unsigned long state;
2727 + u8 state;
2728 + u8 is_rel;
2729 #ifdef CONFIG_TIMER_STATS
2730 int start_pid;
2731 void *start_site;
2732 @@ -321,6 +323,27 @@ static inline void clock_was_set_delayed(void) { }
2733
2734 #endif
2735
2736 +static inline ktime_t
2737 +__hrtimer_expires_remaining_adjusted(const struct hrtimer *timer, ktime_t now)
2738 +{
2739 + ktime_t rem = ktime_sub(timer->node.expires, now);
2740 +
2741 + /*
2742 + * Adjust relative timers for the extra we added in
2743 + * hrtimer_start_range_ns() to prevent short timeouts.
2744 + */
2745 + if (IS_ENABLED(CONFIG_TIME_LOW_RES) && timer->is_rel)
2746 + rem.tv64 -= hrtimer_resolution;
2747 + return rem;
2748 +}
2749 +
2750 +static inline ktime_t
2751 +hrtimer_expires_remaining_adjusted(const struct hrtimer *timer)
2752 +{
2753 + return __hrtimer_expires_remaining_adjusted(timer,
2754 + timer->base->get_time());
2755 +}
2756 +
2757 extern void clock_was_set(void);
2758 #ifdef CONFIG_TIMERFD
2759 extern void timerfd_clock_was_set(void);
2760 @@ -390,7 +413,12 @@ static inline void hrtimer_restart(struct hrtimer *timer)
2761 }
2762
2763 /* Query timers: */
2764 -extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
2765 +extern ktime_t __hrtimer_get_remaining(const struct hrtimer *timer, bool adjust);
2766 +
2767 +static inline ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
2768 +{
2769 + return __hrtimer_get_remaining(timer, false);
2770 +}
2771
2772 extern u64 hrtimer_get_next_event(void);
2773
2774 diff --git a/include/linux/tty.h b/include/linux/tty.h
2775 index 5e31f1b99037..6b6e811f4575 100644
2776 --- a/include/linux/tty.h
2777 +++ b/include/linux/tty.h
2778 @@ -654,6 +654,7 @@ extern long vt_compat_ioctl(struct tty_struct *tty,
2779 /* tty_mutex.c */
2780 /* functions for preparation of BKL removal */
2781 extern void __lockfunc tty_lock(struct tty_struct *tty);
2782 +extern int tty_lock_interruptible(struct tty_struct *tty);
2783 extern void __lockfunc tty_unlock(struct tty_struct *tty);
2784 extern void __lockfunc tty_lock_slave(struct tty_struct *tty);
2785 extern void __lockfunc tty_unlock_slave(struct tty_struct *tty);
2786 diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h
2787 index f6cbef78db62..3b91ad5d5115 100644
2788 --- a/include/sound/rawmidi.h
2789 +++ b/include/sound/rawmidi.h
2790 @@ -167,6 +167,10 @@ int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
2791 int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count);
2792 int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
2793 unsigned char *buffer, int count);
2794 +int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
2795 + unsigned char *buffer, int count);
2796 +int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream,
2797 + int count);
2798
2799 /* main midi functions */
2800
2801 diff --git a/kernel/panic.c b/kernel/panic.c
2802 index 4b150bc0c6c1..41e2b54f36b5 100644
2803 --- a/kernel/panic.c
2804 +++ b/kernel/panic.c
2805 @@ -157,8 +157,7 @@ void panic(const char *fmt, ...)
2806 * panic() is not being callled from OOPS.
2807 */
2808 debug_locks_off();
2809 - console_trylock();
2810 - console_unlock();
2811 + console_flush_on_panic();
2812
2813 if (!panic_blink)
2814 panic_blink = no_blink;
2815 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
2816 index 2ce8826f1053..c048e34b177f 100644
2817 --- a/kernel/printk/printk.c
2818 +++ b/kernel/printk/printk.c
2819 @@ -2233,13 +2233,24 @@ void console_unlock(void)
2820 static u64 seen_seq;
2821 unsigned long flags;
2822 bool wake_klogd = false;
2823 - bool retry;
2824 + bool do_cond_resched, retry;
2825
2826 if (console_suspended) {
2827 up_console_sem();
2828 return;
2829 }
2830
2831 + /*
2832 + * Console drivers are called under logbuf_lock, so
2833 + * @console_may_schedule should be cleared before; however, we may
2834 + * end up dumping a lot of lines, for example, if called from
2835 + * console registration path, and should invoke cond_resched()
2836 + * between lines if allowable. Not doing so can cause a very long
2837 + * scheduling stall on a slow console leading to RCU stall and
2838 + * softlockup warnings which exacerbate the issue with more
2839 + * messages practically incapacitating the system.
2840 + */
2841 + do_cond_resched = console_may_schedule;
2842 console_may_schedule = 0;
2843
2844 /* flush buffered message fragment immediately to console */
2845 @@ -2311,6 +2322,9 @@ skip:
2846 call_console_drivers(level, ext_text, ext_len, text, len);
2847 start_critical_timings();
2848 local_irq_restore(flags);
2849 +
2850 + if (do_cond_resched)
2851 + cond_resched();
2852 }
2853 console_locked = 0;
2854
2855 @@ -2378,6 +2392,25 @@ void console_unblank(void)
2856 console_unlock();
2857 }
2858
2859 +/**
2860 + * console_flush_on_panic - flush console content on panic
2861 + *
2862 + * Immediately output all pending messages no matter what.
2863 + */
2864 +void console_flush_on_panic(void)
2865 +{
2866 + /*
2867 + * If someone else is holding the console lock, trylock will fail
2868 + * and may_schedule may be set. Ignore and proceed to unlock so
2869 + * that messages are flushed out. As this can be called from any
2870 + * context and we don't want to get preempted while flushing,
2871 + * ensure may_schedule is cleared.
2872 + */
2873 + console_trylock();
2874 + console_may_schedule = 0;
2875 + console_unlock();
2876 +}
2877 +
2878 /*
2879 * Return the console tty driver structure and its associated index
2880 */
2881 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
2882 index 732e993b564b..eb70592f03f6 100644
2883 --- a/kernel/sched/core.c
2884 +++ b/kernel/sched/core.c
2885 @@ -6738,7 +6738,7 @@ static void sched_init_numa(void)
2886
2887 sched_domains_numa_masks[i][j] = mask;
2888
2889 - for (k = 0; k < nr_node_ids; k++) {
2890 + for_each_node(k) {
2891 if (node_distance(j, k) > sched_domains_numa_distance[i])
2892 continue;
2893
2894 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
2895 index 435b8850dd80..fa909f9fd559 100644
2896 --- a/kernel/time/hrtimer.c
2897 +++ b/kernel/time/hrtimer.c
2898 @@ -897,10 +897,10 @@ static int enqueue_hrtimer(struct hrtimer *timer,
2899 */
2900 static void __remove_hrtimer(struct hrtimer *timer,
2901 struct hrtimer_clock_base *base,
2902 - unsigned long newstate, int reprogram)
2903 + u8 newstate, int reprogram)
2904 {
2905 struct hrtimer_cpu_base *cpu_base = base->cpu_base;
2906 - unsigned int state = timer->state;
2907 + u8 state = timer->state;
2908
2909 timer->state = newstate;
2910 if (!(state & HRTIMER_STATE_ENQUEUED))
2911 @@ -930,7 +930,7 @@ static inline int
2912 remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base, bool restart)
2913 {
2914 if (hrtimer_is_queued(timer)) {
2915 - unsigned long state = timer->state;
2916 + u8 state = timer->state;
2917 int reprogram;
2918
2919 /*
2920 @@ -954,6 +954,22 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base, bool rest
2921 return 0;
2922 }
2923
2924 +static inline ktime_t hrtimer_update_lowres(struct hrtimer *timer, ktime_t tim,
2925 + const enum hrtimer_mode mode)
2926 +{
2927 +#ifdef CONFIG_TIME_LOW_RES
2928 + /*
2929 + * CONFIG_TIME_LOW_RES indicates that the system has no way to return
2930 + * granular time values. For relative timers we add hrtimer_resolution
2931 + * (i.e. one jiffie) to prevent short timeouts.
2932 + */
2933 + timer->is_rel = mode & HRTIMER_MODE_REL;
2934 + if (timer->is_rel)
2935 + tim = ktime_add_safe(tim, ktime_set(0, hrtimer_resolution));
2936 +#endif
2937 + return tim;
2938 +}
2939 +
2940 /**
2941 * hrtimer_start_range_ns - (re)start an hrtimer on the current CPU
2942 * @timer: the timer to be added
2943 @@ -974,19 +990,10 @@ void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
2944 /* Remove an active timer from the queue: */
2945 remove_hrtimer(timer, base, true);
2946
2947 - if (mode & HRTIMER_MODE_REL) {
2948 + if (mode & HRTIMER_MODE_REL)
2949 tim = ktime_add_safe(tim, base->get_time());
2950 - /*
2951 - * CONFIG_TIME_LOW_RES is a temporary way for architectures
2952 - * to signal that they simply return xtime in
2953 - * do_gettimeoffset(). In this case we want to round up by
2954 - * resolution when starting a relative timer, to avoid short
2955 - * timeouts. This will go away with the GTOD framework.
2956 - */
2957 -#ifdef CONFIG_TIME_LOW_RES
2958 - tim = ktime_add_safe(tim, ktime_set(0, hrtimer_resolution));
2959 -#endif
2960 - }
2961 +
2962 + tim = hrtimer_update_lowres(timer, tim, mode);
2963
2964 hrtimer_set_expires_range_ns(timer, tim, delta_ns);
2965
2966 @@ -1074,19 +1081,23 @@ EXPORT_SYMBOL_GPL(hrtimer_cancel);
2967 /**
2968 * hrtimer_get_remaining - get remaining time for the timer
2969 * @timer: the timer to read
2970 + * @adjust: adjust relative timers when CONFIG_TIME_LOW_RES=y
2971 */
2972 -ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
2973 +ktime_t __hrtimer_get_remaining(const struct hrtimer *timer, bool adjust)
2974 {
2975 unsigned long flags;
2976 ktime_t rem;
2977
2978 lock_hrtimer_base(timer, &flags);
2979 - rem = hrtimer_expires_remaining(timer);
2980 + if (IS_ENABLED(CONFIG_TIME_LOW_RES) && adjust)
2981 + rem = hrtimer_expires_remaining_adjusted(timer);
2982 + else
2983 + rem = hrtimer_expires_remaining(timer);
2984 unlock_hrtimer_base(timer, &flags);
2985
2986 return rem;
2987 }
2988 -EXPORT_SYMBOL_GPL(hrtimer_get_remaining);
2989 +EXPORT_SYMBOL_GPL(__hrtimer_get_remaining);
2990
2991 #ifdef CONFIG_NO_HZ_COMMON
2992 /**
2993 @@ -1220,6 +1231,14 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base,
2994 fn = timer->function;
2995
2996 /*
2997 + * Clear the 'is relative' flag for the TIME_LOW_RES case. If the
2998 + * timer is restarted with a period then it becomes an absolute
2999 + * timer. If its not restarted it does not matter.
3000 + */
3001 + if (IS_ENABLED(CONFIG_TIME_LOW_RES))
3002 + timer->is_rel = false;
3003 +
3004 + /*
3005 * Because we run timers from hardirq context, there is no chance
3006 * they get migrated to another cpu, therefore its safe to unlock
3007 * the timer base.
3008 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
3009 index f75e35b60149..ba7d8b288bb3 100644
3010 --- a/kernel/time/timer_list.c
3011 +++ b/kernel/time/timer_list.c
3012 @@ -69,7 +69,7 @@ print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
3013 print_name_offset(m, taddr);
3014 SEQ_printf(m, ", ");
3015 print_name_offset(m, timer->function);
3016 - SEQ_printf(m, ", S:%02lx", timer->state);
3017 + SEQ_printf(m, ", S:%02x", timer->state);
3018 #ifdef CONFIG_TIMER_STATS
3019 SEQ_printf(m, ", ");
3020 print_name_offset(m, timer->start_site);
3021 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
3022 index 87fb9801bd9e..d9293402ee68 100644
3023 --- a/kernel/trace/trace.c
3024 +++ b/kernel/trace/trace.c
3025 @@ -1751,7 +1751,7 @@ void trace_buffer_unlock_commit_regs(struct trace_array *tr,
3026 {
3027 __buffer_unlock_commit(buffer, event);
3028
3029 - ftrace_trace_stack(tr, buffer, flags, 6, pc, regs);
3030 + ftrace_trace_stack(tr, buffer, flags, 0, pc, regs);
3031 ftrace_trace_userstack(buffer, flags, pc);
3032 }
3033 EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs);
3034 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
3035 index dda9e6742950..202df6cffcca 100644
3036 --- a/kernel/trace/trace_stack.c
3037 +++ b/kernel/trace/trace_stack.c
3038 @@ -126,6 +126,13 @@ check_stack(unsigned long ip, unsigned long *stack)
3039 }
3040
3041 /*
3042 + * Some archs may not have the passed in ip in the dump.
3043 + * If that happens, we need to show everything.
3044 + */
3045 + if (i == stack_trace_max.nr_entries)
3046 + i = 0;
3047 +
3048 + /*
3049 * Now find where in the stack these are.
3050 */
3051 x = 0;
3052 diff --git a/lib/libcrc32c.c b/lib/libcrc32c.c
3053 index 6a08ce7d6adc..acf9da449f81 100644
3054 --- a/lib/libcrc32c.c
3055 +++ b/lib/libcrc32c.c
3056 @@ -74,3 +74,4 @@ module_exit(libcrc32c_mod_fini);
3057 MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
3058 MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
3059 MODULE_LICENSE("GPL");
3060 +MODULE_SOFTDEP("pre: crc32c");
3061 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
3062 index 7340353f8aea..cbe6f0b96f29 100644
3063 --- a/mm/backing-dev.c
3064 +++ b/mm/backing-dev.c
3065 @@ -989,7 +989,7 @@ long wait_iff_congested(struct zone *zone, int sync, long timeout)
3066 * here rather than calling cond_resched().
3067 */
3068 if (current->flags & PF_WQ_WORKER)
3069 - schedule_timeout(1);
3070 + schedule_timeout_uninterruptible(1);
3071 else
3072 cond_resched();
3073
3074 diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
3075 index 9f15bdd9163c..fc083996e40a 100644
3076 --- a/mm/zsmalloc.c
3077 +++ b/mm/zsmalloc.c
3078 @@ -309,7 +309,12 @@ static void free_handle(struct zs_pool *pool, unsigned long handle)
3079
3080 static void record_obj(unsigned long handle, unsigned long obj)
3081 {
3082 - *(unsigned long *)handle = obj;
3083 + /*
3084 + * lsb of @obj represents handle lock while other bits
3085 + * represent object value the handle is pointing so
3086 + * updating shouldn't do store tearing.
3087 + */
3088 + WRITE_ONCE(*(unsigned long *)handle, obj);
3089 }
3090
3091 /* zpool driver */
3092 @@ -1635,6 +1640,13 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class,
3093 free_obj = obj_malloc(d_page, class, handle);
3094 zs_object_copy(free_obj, used_obj, class);
3095 index++;
3096 + /*
3097 + * record_obj updates handle's value to free_obj and it will
3098 + * invalidate lock bit(ie, HANDLE_PIN_BIT) of handle, which
3099 + * breaks synchronization using pin_tag(e,g, zs_free) so
3100 + * let's keep the lock bit.
3101 + */
3102 + free_obj |= BIT(HANDLE_PIN_BIT);
3103 record_obj(handle, free_obj);
3104 unpin_tag(handle);
3105 obj_free(pool, class, used_obj);
3106 diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c
3107 index 1334e02ae8f4..3d145a3ffccf 100644
3108 --- a/security/integrity/evm/evm_main.c
3109 +++ b/security/integrity/evm/evm_main.c
3110 @@ -23,6 +23,7 @@
3111 #include <linux/integrity.h>
3112 #include <linux/evm.h>
3113 #include <crypto/hash.h>
3114 +#include <crypto/algapi.h>
3115 #include "evm.h"
3116
3117 int evm_initialized;
3118 @@ -148,7 +149,7 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,
3119 xattr_value_len, calc.digest);
3120 if (rc)
3121 break;
3122 - rc = memcmp(xattr_data->digest, calc.digest,
3123 + rc = crypto_memneq(xattr_data->digest, calc.digest,
3124 sizeof(calc.digest));
3125 if (rc)
3126 rc = -EINVAL;
3127 diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
3128 index b123c42e7dc8..b554d7f9e3be 100644
3129 --- a/sound/core/compress_offload.c
3130 +++ b/sound/core/compress_offload.c
3131 @@ -44,6 +44,13 @@
3132 #include <sound/compress_offload.h>
3133 #include <sound/compress_driver.h>
3134
3135 +/* struct snd_compr_codec_caps overflows the ioctl bit size for some
3136 + * architectures, so we need to disable the relevant ioctls.
3137 + */
3138 +#if _IOC_SIZEBITS < 14
3139 +#define COMPR_CODEC_CAPS_OVERFLOW
3140 +#endif
3141 +
3142 /* TODO:
3143 * - add substream support for multiple devices in case of
3144 * SND_DYNAMIC_MINORS is not used
3145 @@ -438,6 +445,7 @@ out:
3146 return retval;
3147 }
3148
3149 +#ifndef COMPR_CODEC_CAPS_OVERFLOW
3150 static int
3151 snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg)
3152 {
3153 @@ -461,6 +469,7 @@ out:
3154 kfree(caps);
3155 return retval;
3156 }
3157 +#endif /* !COMPR_CODEC_CAPS_OVERFLOW */
3158
3159 /* revisit this with snd_pcm_preallocate_xxx */
3160 static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
3161 @@ -799,9 +808,11 @@ static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
3162 case _IOC_NR(SNDRV_COMPRESS_GET_CAPS):
3163 retval = snd_compr_get_caps(stream, arg);
3164 break;
3165 +#ifndef COMPR_CODEC_CAPS_OVERFLOW
3166 case _IOC_NR(SNDRV_COMPRESS_GET_CODEC_CAPS):
3167 retval = snd_compr_get_codec_caps(stream, arg);
3168 break;
3169 +#endif
3170 case _IOC_NR(SNDRV_COMPRESS_SET_PARAMS):
3171 retval = snd_compr_set_params(stream, arg);
3172 break;
3173 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
3174 index 58550cc93f28..33e72c809e50 100644
3175 --- a/sound/core/oss/pcm_oss.c
3176 +++ b/sound/core/oss/pcm_oss.c
3177 @@ -834,7 +834,8 @@ static int choose_rate(struct snd_pcm_substream *substream,
3178 return snd_pcm_hw_param_near(substream, params, SNDRV_PCM_HW_PARAM_RATE, best_rate, NULL);
3179 }
3180
3181 -static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
3182 +static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
3183 + bool trylock)
3184 {
3185 struct snd_pcm_runtime *runtime = substream->runtime;
3186 struct snd_pcm_hw_params *params, *sparams;
3187 @@ -848,7 +849,10 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
3188 struct snd_mask sformat_mask;
3189 struct snd_mask mask;
3190
3191 - if (mutex_lock_interruptible(&runtime->oss.params_lock))
3192 + if (trylock) {
3193 + if (!(mutex_trylock(&runtime->oss.params_lock)))
3194 + return -EAGAIN;
3195 + } else if (mutex_lock_interruptible(&runtime->oss.params_lock))
3196 return -EINTR;
3197 sw_params = kmalloc(sizeof(*sw_params), GFP_KERNEL);
3198 params = kmalloc(sizeof(*params), GFP_KERNEL);
3199 @@ -1092,7 +1096,7 @@ static int snd_pcm_oss_get_active_substream(struct snd_pcm_oss_file *pcm_oss_fil
3200 if (asubstream == NULL)
3201 asubstream = substream;
3202 if (substream->runtime->oss.params) {
3203 - err = snd_pcm_oss_change_params(substream);
3204 + err = snd_pcm_oss_change_params(substream, false);
3205 if (err < 0)
3206 return err;
3207 }
3208 @@ -1132,7 +1136,7 @@ static int snd_pcm_oss_make_ready(struct snd_pcm_substream *substream)
3209 return 0;
3210 runtime = substream->runtime;
3211 if (runtime->oss.params) {
3212 - err = snd_pcm_oss_change_params(substream);
3213 + err = snd_pcm_oss_change_params(substream, false);
3214 if (err < 0)
3215 return err;
3216 }
3217 @@ -2163,7 +2167,7 @@ static int snd_pcm_oss_get_space(struct snd_pcm_oss_file *pcm_oss_file, int stre
3218 runtime = substream->runtime;
3219
3220 if (runtime->oss.params &&
3221 - (err = snd_pcm_oss_change_params(substream)) < 0)
3222 + (err = snd_pcm_oss_change_params(substream, false)) < 0)
3223 return err;
3224
3225 info.fragsize = runtime->oss.period_bytes;
3226 @@ -2800,7 +2804,12 @@ static int snd_pcm_oss_mmap(struct file *file, struct vm_area_struct *area)
3227 return -EIO;
3228
3229 if (runtime->oss.params) {
3230 - if ((err = snd_pcm_oss_change_params(substream)) < 0)
3231 + /* use mutex_trylock() for params_lock for avoiding a deadlock
3232 + * between mmap_sem and params_lock taken by
3233 + * copy_from/to_user() in snd_pcm_oss_write/read()
3234 + */
3235 + err = snd_pcm_oss_change_params(substream, true);
3236 + if (err < 0)
3237 return err;
3238 }
3239 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
3240 diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
3241 index a7759846fbaa..795437b10082 100644
3242 --- a/sound/core/rawmidi.c
3243 +++ b/sound/core/rawmidi.c
3244 @@ -942,31 +942,36 @@ static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
3245 unsigned long flags;
3246 long result = 0, count1;
3247 struct snd_rawmidi_runtime *runtime = substream->runtime;
3248 + unsigned long appl_ptr;
3249
3250 + spin_lock_irqsave(&runtime->lock, flags);
3251 while (count > 0 && runtime->avail) {
3252 count1 = runtime->buffer_size - runtime->appl_ptr;
3253 if (count1 > count)
3254 count1 = count;
3255 - spin_lock_irqsave(&runtime->lock, flags);
3256 if (count1 > (int)runtime->avail)
3257 count1 = runtime->avail;
3258 +
3259 + /* update runtime->appl_ptr before unlocking for userbuf */
3260 + appl_ptr = runtime->appl_ptr;
3261 + runtime->appl_ptr += count1;
3262 + runtime->appl_ptr %= runtime->buffer_size;
3263 + runtime->avail -= count1;
3264 +
3265 if (kernelbuf)
3266 - memcpy(kernelbuf + result, runtime->buffer + runtime->appl_ptr, count1);
3267 + memcpy(kernelbuf + result, runtime->buffer + appl_ptr, count1);
3268 if (userbuf) {
3269 spin_unlock_irqrestore(&runtime->lock, flags);
3270 if (copy_to_user(userbuf + result,
3271 - runtime->buffer + runtime->appl_ptr, count1)) {
3272 + runtime->buffer + appl_ptr, count1)) {
3273 return result > 0 ? result : -EFAULT;
3274 }
3275 spin_lock_irqsave(&runtime->lock, flags);
3276 }
3277 - runtime->appl_ptr += count1;
3278 - runtime->appl_ptr %= runtime->buffer_size;
3279 - runtime->avail -= count1;
3280 - spin_unlock_irqrestore(&runtime->lock, flags);
3281 result += count1;
3282 count -= count1;
3283 }
3284 + spin_unlock_irqrestore(&runtime->lock, flags);
3285 return result;
3286 }
3287
3288 @@ -1055,23 +1060,16 @@ int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
3289 EXPORT_SYMBOL(snd_rawmidi_transmit_empty);
3290
3291 /**
3292 - * snd_rawmidi_transmit_peek - copy data from the internal buffer
3293 + * __snd_rawmidi_transmit_peek - copy data from the internal buffer
3294 * @substream: the rawmidi substream
3295 * @buffer: the buffer pointer
3296 * @count: data size to transfer
3297 *
3298 - * Copies data from the internal output buffer to the given buffer.
3299 - *
3300 - * Call this in the interrupt handler when the midi output is ready,
3301 - * and call snd_rawmidi_transmit_ack() after the transmission is
3302 - * finished.
3303 - *
3304 - * Return: The size of copied data, or a negative error code on failure.
3305 + * This is a variant of snd_rawmidi_transmit_peek() without spinlock.
3306 */
3307 -int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
3308 +int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
3309 unsigned char *buffer, int count)
3310 {
3311 - unsigned long flags;
3312 int result, count1;
3313 struct snd_rawmidi_runtime *runtime = substream->runtime;
3314
3315 @@ -1081,7 +1079,6 @@ int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
3316 return -EINVAL;
3317 }
3318 result = 0;
3319 - spin_lock_irqsave(&runtime->lock, flags);
3320 if (runtime->avail >= runtime->buffer_size) {
3321 /* warning: lowlevel layer MUST trigger down the hardware */
3322 goto __skip;
3323 @@ -1106,25 +1103,47 @@ int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
3324 }
3325 }
3326 __skip:
3327 + return result;
3328 +}
3329 +EXPORT_SYMBOL(__snd_rawmidi_transmit_peek);
3330 +
3331 +/**
3332 + * snd_rawmidi_transmit_peek - copy data from the internal buffer
3333 + * @substream: the rawmidi substream
3334 + * @buffer: the buffer pointer
3335 + * @count: data size to transfer
3336 + *
3337 + * Copies data from the internal output buffer to the given buffer.
3338 + *
3339 + * Call this in the interrupt handler when the midi output is ready,
3340 + * and call snd_rawmidi_transmit_ack() after the transmission is
3341 + * finished.
3342 + *
3343 + * Return: The size of copied data, or a negative error code on failure.
3344 + */
3345 +int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
3346 + unsigned char *buffer, int count)
3347 +{
3348 + struct snd_rawmidi_runtime *runtime = substream->runtime;
3349 + int result;
3350 + unsigned long flags;
3351 +
3352 + spin_lock_irqsave(&runtime->lock, flags);
3353 + result = __snd_rawmidi_transmit_peek(substream, buffer, count);
3354 spin_unlock_irqrestore(&runtime->lock, flags);
3355 return result;
3356 }
3357 EXPORT_SYMBOL(snd_rawmidi_transmit_peek);
3358
3359 /**
3360 - * snd_rawmidi_transmit_ack - acknowledge the transmission
3361 + * __snd_rawmidi_transmit_ack - acknowledge the transmission
3362 * @substream: the rawmidi substream
3363 * @count: the transferred count
3364 *
3365 - * Advances the hardware pointer for the internal output buffer with
3366 - * the given size and updates the condition.
3367 - * Call after the transmission is finished.
3368 - *
3369 - * Return: The advanced size if successful, or a negative error code on failure.
3370 + * This is a variant of __snd_rawmidi_transmit_ack() without spinlock.
3371 */
3372 -int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
3373 +int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
3374 {
3375 - unsigned long flags;
3376 struct snd_rawmidi_runtime *runtime = substream->runtime;
3377
3378 if (runtime->buffer == NULL) {
3379 @@ -1132,7 +1151,6 @@ int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
3380 "snd_rawmidi_transmit_ack: output is not active!!!\n");
3381 return -EINVAL;
3382 }
3383 - spin_lock_irqsave(&runtime->lock, flags);
3384 snd_BUG_ON(runtime->avail + count > runtime->buffer_size);
3385 runtime->hw_ptr += count;
3386 runtime->hw_ptr %= runtime->buffer_size;
3387 @@ -1142,9 +1160,32 @@ int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
3388 if (runtime->drain || snd_rawmidi_ready(substream))
3389 wake_up(&runtime->sleep);
3390 }
3391 - spin_unlock_irqrestore(&runtime->lock, flags);
3392 return count;
3393 }
3394 +EXPORT_SYMBOL(__snd_rawmidi_transmit_ack);
3395 +
3396 +/**
3397 + * snd_rawmidi_transmit_ack - acknowledge the transmission
3398 + * @substream: the rawmidi substream
3399 + * @count: the transferred count
3400 + *
3401 + * Advances the hardware pointer for the internal output buffer with
3402 + * the given size and updates the condition.
3403 + * Call after the transmission is finished.
3404 + *
3405 + * Return: The advanced size if successful, or a negative error code on failure.
3406 + */
3407 +int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
3408 +{
3409 + struct snd_rawmidi_runtime *runtime = substream->runtime;
3410 + int result;
3411 + unsigned long flags;
3412 +
3413 + spin_lock_irqsave(&runtime->lock, flags);
3414 + result = __snd_rawmidi_transmit_ack(substream, count);
3415 + spin_unlock_irqrestore(&runtime->lock, flags);
3416 + return result;
3417 +}
3418 EXPORT_SYMBOL(snd_rawmidi_transmit_ack);
3419
3420 /**
3421 @@ -1160,12 +1201,22 @@ EXPORT_SYMBOL(snd_rawmidi_transmit_ack);
3422 int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
3423 unsigned char *buffer, int count)
3424 {
3425 + struct snd_rawmidi_runtime *runtime = substream->runtime;
3426 + int result;
3427 + unsigned long flags;
3428 +
3429 + spin_lock_irqsave(&runtime->lock, flags);
3430 if (!substream->opened)
3431 - return -EBADFD;
3432 - count = snd_rawmidi_transmit_peek(substream, buffer, count);
3433 - if (count < 0)
3434 - return count;
3435 - return snd_rawmidi_transmit_ack(substream, count);
3436 + result = -EBADFD;
3437 + else {
3438 + count = __snd_rawmidi_transmit_peek(substream, buffer, count);
3439 + if (count <= 0)
3440 + result = count;
3441 + else
3442 + result = __snd_rawmidi_transmit_ack(substream, count);
3443 + }
3444 + spin_unlock_irqrestore(&runtime->lock, flags);
3445 + return result;
3446 }
3447 EXPORT_SYMBOL(snd_rawmidi_transmit);
3448
3449 @@ -1177,8 +1228,9 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
3450 unsigned long flags;
3451 long count1, result;
3452 struct snd_rawmidi_runtime *runtime = substream->runtime;
3453 + unsigned long appl_ptr;
3454
3455 - if (snd_BUG_ON(!kernelbuf && !userbuf))
3456 + if (!kernelbuf && !userbuf)
3457 return -EINVAL;
3458 if (snd_BUG_ON(!runtime->buffer))
3459 return -EINVAL;
3460 @@ -1197,12 +1249,19 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
3461 count1 = count;
3462 if (count1 > (long)runtime->avail)
3463 count1 = runtime->avail;
3464 +
3465 + /* update runtime->appl_ptr before unlocking for userbuf */
3466 + appl_ptr = runtime->appl_ptr;
3467 + runtime->appl_ptr += count1;
3468 + runtime->appl_ptr %= runtime->buffer_size;
3469 + runtime->avail -= count1;
3470 +
3471 if (kernelbuf)
3472 - memcpy(runtime->buffer + runtime->appl_ptr,
3473 + memcpy(runtime->buffer + appl_ptr,
3474 kernelbuf + result, count1);
3475 else if (userbuf) {
3476 spin_unlock_irqrestore(&runtime->lock, flags);
3477 - if (copy_from_user(runtime->buffer + runtime->appl_ptr,
3478 + if (copy_from_user(runtime->buffer + appl_ptr,
3479 userbuf + result, count1)) {
3480 spin_lock_irqsave(&runtime->lock, flags);
3481 result = result > 0 ? result : -EFAULT;
3482 @@ -1210,9 +1269,6 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
3483 }
3484 spin_lock_irqsave(&runtime->lock, flags);
3485 }
3486 - runtime->appl_ptr += count1;
3487 - runtime->appl_ptr %= runtime->buffer_size;
3488 - runtime->avail -= count1;
3489 result += count1;
3490 count -= count1;
3491 }
3492 diff --git a/sound/core/seq/oss/seq_oss_init.c b/sound/core/seq/oss/seq_oss_init.c
3493 index b1221b29728e..6779e82b46dd 100644
3494 --- a/sound/core/seq/oss/seq_oss_init.c
3495 +++ b/sound/core/seq/oss/seq_oss_init.c
3496 @@ -202,7 +202,7 @@ snd_seq_oss_open(struct file *file, int level)
3497
3498 dp->index = i;
3499 if (i >= SNDRV_SEQ_OSS_MAX_CLIENTS) {
3500 - pr_err("ALSA: seq_oss: too many applications\n");
3501 + pr_debug("ALSA: seq_oss: too many applications\n");
3502 rc = -ENOMEM;
3503 goto _error;
3504 }
3505 diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c
3506 index 0f3b38184fe5..b16dbef04174 100644
3507 --- a/sound/core/seq/oss/seq_oss_synth.c
3508 +++ b/sound/core/seq/oss/seq_oss_synth.c
3509 @@ -308,7 +308,7 @@ snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp)
3510 struct seq_oss_synth *rec;
3511 struct seq_oss_synthinfo *info;
3512
3513 - if (snd_BUG_ON(dp->max_synthdev >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS))
3514 + if (snd_BUG_ON(dp->max_synthdev > SNDRV_SEQ_OSS_MAX_SYNTH_DEVS))
3515 return;
3516 for (i = 0; i < dp->max_synthdev; i++) {
3517 info = &dp->synths[i];
3518 diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
3519 index 13cfa815732d..58e79e02f217 100644
3520 --- a/sound/core/seq/seq_clientmgr.c
3521 +++ b/sound/core/seq/seq_clientmgr.c
3522 @@ -678,6 +678,9 @@ static int deliver_to_subscribers(struct snd_seq_client *client,
3523 else
3524 down_read(&grp->list_mutex);
3525 list_for_each_entry(subs, &grp->list_head, src_list) {
3526 + /* both ports ready? */
3527 + if (atomic_read(&subs->ref_count) != 2)
3528 + continue;
3529 event->dest = subs->info.dest;
3530 if (subs->info.flags & SNDRV_SEQ_PORT_SUBS_TIMESTAMP)
3531 /* convert time according to flag with subscription */
3532 diff --git a/sound/core/seq/seq_ports.c b/sound/core/seq/seq_ports.c
3533 index 55170a20ae72..921fb2bd8fad 100644
3534 --- a/sound/core/seq/seq_ports.c
3535 +++ b/sound/core/seq/seq_ports.c
3536 @@ -173,10 +173,6 @@ struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client,
3537 }
3538
3539 /* */
3540 -enum group_type {
3541 - SRC_LIST, DEST_LIST
3542 -};
3543 -
3544 static int subscribe_port(struct snd_seq_client *client,
3545 struct snd_seq_client_port *port,
3546 struct snd_seq_port_subs_info *grp,
3547 @@ -203,6 +199,20 @@ static struct snd_seq_client_port *get_client_port(struct snd_seq_addr *addr,
3548 return NULL;
3549 }
3550
3551 +static void delete_and_unsubscribe_port(struct snd_seq_client *client,
3552 + struct snd_seq_client_port *port,
3553 + struct snd_seq_subscribers *subs,
3554 + bool is_src, bool ack);
3555 +
3556 +static inline struct snd_seq_subscribers *
3557 +get_subscriber(struct list_head *p, bool is_src)
3558 +{
3559 + if (is_src)
3560 + return list_entry(p, struct snd_seq_subscribers, src_list);
3561 + else
3562 + return list_entry(p, struct snd_seq_subscribers, dest_list);
3563 +}
3564 +
3565 /*
3566 * remove all subscribers on the list
3567 * this is called from port_delete, for each src and dest list.
3568 @@ -210,7 +220,7 @@ static struct snd_seq_client_port *get_client_port(struct snd_seq_addr *addr,
3569 static void clear_subscriber_list(struct snd_seq_client *client,
3570 struct snd_seq_client_port *port,
3571 struct snd_seq_port_subs_info *grp,
3572 - int grptype)
3573 + int is_src)
3574 {
3575 struct list_head *p, *n;
3576
3577 @@ -219,15 +229,13 @@ static void clear_subscriber_list(struct snd_seq_client *client,
3578 struct snd_seq_client *c;
3579 struct snd_seq_client_port *aport;
3580
3581 - if (grptype == SRC_LIST) {
3582 - subs = list_entry(p, struct snd_seq_subscribers, src_list);
3583 + subs = get_subscriber(p, is_src);
3584 + if (is_src)
3585 aport = get_client_port(&subs->info.dest, &c);
3586 - } else {
3587 - subs = list_entry(p, struct snd_seq_subscribers, dest_list);
3588 + else
3589 aport = get_client_port(&subs->info.sender, &c);
3590 - }
3591 - list_del(p);
3592 - unsubscribe_port(client, port, grp, &subs->info, 0);
3593 + delete_and_unsubscribe_port(client, port, subs, is_src, false);
3594 +
3595 if (!aport) {
3596 /* looks like the connected port is being deleted.
3597 * we decrease the counter, and when both ports are deleted
3598 @@ -235,21 +243,14 @@ static void clear_subscriber_list(struct snd_seq_client *client,
3599 */
3600 if (atomic_dec_and_test(&subs->ref_count))
3601 kfree(subs);
3602 - } else {
3603 - /* ok we got the connected port */
3604 - struct snd_seq_port_subs_info *agrp;
3605 - agrp = (grptype == SRC_LIST) ? &aport->c_dest : &aport->c_src;
3606 - down_write(&agrp->list_mutex);
3607 - if (grptype == SRC_LIST)
3608 - list_del(&subs->dest_list);
3609 - else
3610 - list_del(&subs->src_list);
3611 - up_write(&agrp->list_mutex);
3612 - unsubscribe_port(c, aport, agrp, &subs->info, 1);
3613 - kfree(subs);
3614 - snd_seq_port_unlock(aport);
3615 - snd_seq_client_unlock(c);
3616 + continue;
3617 }
3618 +
3619 + /* ok we got the connected port */
3620 + delete_and_unsubscribe_port(c, aport, subs, !is_src, true);
3621 + kfree(subs);
3622 + snd_seq_port_unlock(aport);
3623 + snd_seq_client_unlock(c);
3624 }
3625 }
3626
3627 @@ -262,8 +263,8 @@ static int port_delete(struct snd_seq_client *client,
3628 snd_use_lock_sync(&port->use_lock);
3629
3630 /* clear subscribers info */
3631 - clear_subscriber_list(client, port, &port->c_src, SRC_LIST);
3632 - clear_subscriber_list(client, port, &port->c_dest, DEST_LIST);
3633 + clear_subscriber_list(client, port, &port->c_src, true);
3634 + clear_subscriber_list(client, port, &port->c_dest, false);
3635
3636 if (port->private_free)
3637 port->private_free(port->private_data);
3638 @@ -479,85 +480,120 @@ static int match_subs_info(struct snd_seq_port_subscribe *r,
3639 return 0;
3640 }
3641
3642 -
3643 -/* connect two ports */
3644 -int snd_seq_port_connect(struct snd_seq_client *connector,
3645 - struct snd_seq_client *src_client,
3646 - struct snd_seq_client_port *src_port,
3647 - struct snd_seq_client *dest_client,
3648 - struct snd_seq_client_port *dest_port,
3649 - struct snd_seq_port_subscribe *info)
3650 +static int check_and_subscribe_port(struct snd_seq_client *client,
3651 + struct snd_seq_client_port *port,
3652 + struct snd_seq_subscribers *subs,
3653 + bool is_src, bool exclusive, bool ack)
3654 {
3655 - struct snd_seq_port_subs_info *src = &src_port->c_src;
3656 - struct snd_seq_port_subs_info *dest = &dest_port->c_dest;
3657 - struct snd_seq_subscribers *subs, *s;
3658 - int err, src_called = 0;
3659 - unsigned long flags;
3660 - int exclusive;
3661 + struct snd_seq_port_subs_info *grp;
3662 + struct list_head *p;
3663 + struct snd_seq_subscribers *s;
3664 + int err;
3665
3666 - subs = kzalloc(sizeof(*subs), GFP_KERNEL);
3667 - if (! subs)
3668 - return -ENOMEM;
3669 -
3670 - subs->info = *info;
3671 - atomic_set(&subs->ref_count, 2);
3672 -
3673 - down_write(&src->list_mutex);
3674 - down_write_nested(&dest->list_mutex, SINGLE_DEPTH_NESTING);
3675 -
3676 - exclusive = info->flags & SNDRV_SEQ_PORT_SUBS_EXCLUSIVE ? 1 : 0;
3677 + grp = is_src ? &port->c_src : &port->c_dest;
3678 err = -EBUSY;
3679 + down_write(&grp->list_mutex);
3680 if (exclusive) {
3681 - if (! list_empty(&src->list_head) || ! list_empty(&dest->list_head))
3682 + if (!list_empty(&grp->list_head))
3683 goto __error;
3684 } else {
3685 - if (src->exclusive || dest->exclusive)
3686 + if (grp->exclusive)
3687 goto __error;
3688 /* check whether already exists */
3689 - list_for_each_entry(s, &src->list_head, src_list) {
3690 - if (match_subs_info(info, &s->info))
3691 - goto __error;
3692 - }
3693 - list_for_each_entry(s, &dest->list_head, dest_list) {
3694 - if (match_subs_info(info, &s->info))
3695 + list_for_each(p, &grp->list_head) {
3696 + s = get_subscriber(p, is_src);
3697 + if (match_subs_info(&subs->info, &s->info))
3698 goto __error;
3699 }
3700 }
3701
3702 - if ((err = subscribe_port(src_client, src_port, src, info,
3703 - connector->number != src_client->number)) < 0)
3704 - goto __error;
3705 - src_called = 1;
3706 -
3707 - if ((err = subscribe_port(dest_client, dest_port, dest, info,
3708 - connector->number != dest_client->number)) < 0)
3709 + err = subscribe_port(client, port, grp, &subs->info, ack);
3710 + if (err < 0) {
3711 + grp->exclusive = 0;
3712 goto __error;
3713 + }
3714
3715 /* add to list */
3716 - write_lock_irqsave(&src->list_lock, flags);
3717 - // write_lock(&dest->list_lock); // no other lock yet
3718 - list_add_tail(&subs->src_list, &src->list_head);
3719 - list_add_tail(&subs->dest_list, &dest->list_head);
3720 - // write_unlock(&dest->list_lock); // no other lock yet
3721 - write_unlock_irqrestore(&src->list_lock, flags);
3722 + write_lock_irq(&grp->list_lock);
3723 + if (is_src)
3724 + list_add_tail(&subs->src_list, &grp->list_head);
3725 + else
3726 + list_add_tail(&subs->dest_list, &grp->list_head);
3727 + grp->exclusive = exclusive;
3728 + atomic_inc(&subs->ref_count);
3729 + write_unlock_irq(&grp->list_lock);
3730 + err = 0;
3731 +
3732 + __error:
3733 + up_write(&grp->list_mutex);
3734 + return err;
3735 +}
3736
3737 - src->exclusive = dest->exclusive = exclusive;
3738 +static void delete_and_unsubscribe_port(struct snd_seq_client *client,
3739 + struct snd_seq_client_port *port,
3740 + struct snd_seq_subscribers *subs,
3741 + bool is_src, bool ack)
3742 +{
3743 + struct snd_seq_port_subs_info *grp;
3744 +
3745 + grp = is_src ? &port->c_src : &port->c_dest;
3746 + down_write(&grp->list_mutex);
3747 + write_lock_irq(&grp->list_lock);
3748 + if (is_src)
3749 + list_del(&subs->src_list);
3750 + else
3751 + list_del(&subs->dest_list);
3752 + grp->exclusive = 0;
3753 + write_unlock_irq(&grp->list_lock);
3754 + up_write(&grp->list_mutex);
3755 +
3756 + unsubscribe_port(client, port, grp, &subs->info, ack);
3757 +}
3758 +
3759 +/* connect two ports */
3760 +int snd_seq_port_connect(struct snd_seq_client *connector,
3761 + struct snd_seq_client *src_client,
3762 + struct snd_seq_client_port *src_port,
3763 + struct snd_seq_client *dest_client,
3764 + struct snd_seq_client_port *dest_port,
3765 + struct snd_seq_port_subscribe *info)
3766 +{
3767 + struct snd_seq_subscribers *subs;
3768 + bool exclusive;
3769 + int err;
3770 +
3771 + subs = kzalloc(sizeof(*subs), GFP_KERNEL);
3772 + if (!subs)
3773 + return -ENOMEM;
3774 +
3775 + subs->info = *info;
3776 + atomic_set(&subs->ref_count, 0);
3777 + INIT_LIST_HEAD(&subs->src_list);
3778 + INIT_LIST_HEAD(&subs->dest_list);
3779 +
3780 + exclusive = !!(info->flags & SNDRV_SEQ_PORT_SUBS_EXCLUSIVE);
3781 +
3782 + err = check_and_subscribe_port(src_client, src_port, subs, true,
3783 + exclusive,
3784 + connector->number != src_client->number);
3785 + if (err < 0)
3786 + goto error;
3787 + err = check_and_subscribe_port(dest_client, dest_port, subs, false,
3788 + exclusive,
3789 + connector->number != dest_client->number);
3790 + if (err < 0)
3791 + goto error_dest;
3792
3793 - up_write(&dest->list_mutex);
3794 - up_write(&src->list_mutex);
3795 return 0;
3796
3797 - __error:
3798 - if (src_called)
3799 - unsubscribe_port(src_client, src_port, src, info,
3800 - connector->number != src_client->number);
3801 + error_dest:
3802 + delete_and_unsubscribe_port(src_client, src_port, subs, true,
3803 + connector->number != src_client->number);
3804 + error:
3805 kfree(subs);
3806 - up_write(&dest->list_mutex);
3807 - up_write(&src->list_mutex);
3808 return err;
3809 }
3810
3811 -
3812 /* remove the connection */
3813 int snd_seq_port_disconnect(struct snd_seq_client *connector,
3814 struct snd_seq_client *src_client,
3815 @@ -567,37 +603,28 @@ int snd_seq_port_disconnect(struct snd_seq_client *connector,
3816 struct snd_seq_port_subscribe *info)
3817 {
3818 struct snd_seq_port_subs_info *src = &src_port->c_src;
3819 - struct snd_seq_port_subs_info *dest = &dest_port->c_dest;
3820 struct snd_seq_subscribers *subs;
3821 int err = -ENOENT;
3822 - unsigned long flags;
3823
3824 down_write(&src->list_mutex);
3825 - down_write_nested(&dest->list_mutex, SINGLE_DEPTH_NESTING);
3826 -
3827 /* look for the connection */
3828 list_for_each_entry(subs, &src->list_head, src_list) {
3829 if (match_subs_info(info, &subs->info)) {
3830 - write_lock_irqsave(&src->list_lock, flags);
3831 - // write_lock(&dest->list_lock); // no lock yet
3832 - list_del(&subs->src_list);
3833 - list_del(&subs->dest_list);
3834 - // write_unlock(&dest->list_lock);
3835 - write_unlock_irqrestore(&src->list_lock, flags);
3836 - src->exclusive = dest->exclusive = 0;
3837 - unsubscribe_port(src_client, src_port, src, info,
3838 - connector->number != src_client->number);
3839 - unsubscribe_port(dest_client, dest_port, dest, info,
3840 - connector->number != dest_client->number);
3841 - kfree(subs);
3842 + atomic_dec(&subs->ref_count); /* mark as not ready */
3843 err = 0;
3844 break;
3845 }
3846 }
3847 -
3848 - up_write(&dest->list_mutex);
3849 up_write(&src->list_mutex);
3850 - return err;
3851 + if (err < 0)
3852 + return err;
3853 +
3854 + delete_and_unsubscribe_port(src_client, src_port, subs, true,
3855 + connector->number != src_client->number);
3856 + delete_and_unsubscribe_port(dest_client, dest_port, subs, false,
3857 + connector->number != dest_client->number);
3858 + kfree(subs);
3859 + return 0;
3860 }
3861
3862
3863 diff --git a/sound/core/seq/seq_timer.c b/sound/core/seq/seq_timer.c
3864 index 82b220c769c1..293104926098 100644
3865 --- a/sound/core/seq/seq_timer.c
3866 +++ b/sound/core/seq/seq_timer.c
3867 @@ -90,6 +90,9 @@ void snd_seq_timer_delete(struct snd_seq_timer **tmr)
3868
3869 void snd_seq_timer_defaults(struct snd_seq_timer * tmr)
3870 {
3871 + unsigned long flags;
3872 +
3873 + spin_lock_irqsave(&tmr->lock, flags);
3874 /* setup defaults */
3875 tmr->ppq = 96; /* 96 PPQ */
3876 tmr->tempo = 500000; /* 120 BPM */
3877 @@ -105,21 +108,25 @@ void snd_seq_timer_defaults(struct snd_seq_timer * tmr)
3878 tmr->preferred_resolution = seq_default_timer_resolution;
3879
3880 tmr->skew = tmr->skew_base = SKEW_BASE;
3881 + spin_unlock_irqrestore(&tmr->lock, flags);
3882 }
3883
3884 -void snd_seq_timer_reset(struct snd_seq_timer * tmr)
3885 +static void seq_timer_reset(struct snd_seq_timer *tmr)
3886 {
3887 - unsigned long flags;
3888 -
3889 - spin_lock_irqsave(&tmr->lock, flags);
3890 -
3891 /* reset time & songposition */
3892 tmr->cur_time.tv_sec = 0;
3893 tmr->cur_time.tv_nsec = 0;
3894
3895 tmr->tick.cur_tick = 0;
3896 tmr->tick.fraction = 0;
3897 +}
3898 +
3899 +void snd_seq_timer_reset(struct snd_seq_timer *tmr)
3900 +{
3901 + unsigned long flags;
3902
3903 + spin_lock_irqsave(&tmr->lock, flags);
3904 + seq_timer_reset(tmr);
3905 spin_unlock_irqrestore(&tmr->lock, flags);
3906 }
3907
3908 @@ -138,8 +145,11 @@ static void snd_seq_timer_interrupt(struct snd_timer_instance *timeri,
3909 tmr = q->timer;
3910 if (tmr == NULL)
3911 return;
3912 - if (!tmr->running)
3913 + spin_lock_irqsave(&tmr->lock, flags);
3914 + if (!tmr->running) {
3915 + spin_unlock_irqrestore(&tmr->lock, flags);
3916 return;
3917 + }
3918
3919 resolution *= ticks;
3920 if (tmr->skew != tmr->skew_base) {
3921 @@ -148,8 +158,6 @@ static void snd_seq_timer_interrupt(struct snd_timer_instance *timeri,
3922 (((resolution & 0xffff) * tmr->skew) >> 16);
3923 }
3924
3925 - spin_lock_irqsave(&tmr->lock, flags);
3926 -
3927 /* update timer */
3928 snd_seq_inc_time_nsec(&tmr->cur_time, resolution);
3929
3930 @@ -296,26 +304,30 @@ int snd_seq_timer_open(struct snd_seq_queue *q)
3931 t->callback = snd_seq_timer_interrupt;
3932 t->callback_data = q;
3933 t->flags |= SNDRV_TIMER_IFLG_AUTO;
3934 + spin_lock_irq(&tmr->lock);
3935 tmr->timeri = t;
3936 + spin_unlock_irq(&tmr->lock);
3937 return 0;
3938 }
3939
3940 int snd_seq_timer_close(struct snd_seq_queue *q)
3941 {
3942 struct snd_seq_timer *tmr;
3943 + struct snd_timer_instance *t;
3944
3945 tmr = q->timer;
3946 if (snd_BUG_ON(!tmr))
3947 return -EINVAL;
3948 - if (tmr->timeri) {
3949 - snd_timer_stop(tmr->timeri);
3950 - snd_timer_close(tmr->timeri);
3951 - tmr->timeri = NULL;
3952 - }
3953 + spin_lock_irq(&tmr->lock);
3954 + t = tmr->timeri;
3955 + tmr->timeri = NULL;
3956 + spin_unlock_irq(&tmr->lock);
3957 + if (t)
3958 + snd_timer_close(t);
3959 return 0;
3960 }
3961
3962 -int snd_seq_timer_stop(struct snd_seq_timer * tmr)
3963 +static int seq_timer_stop(struct snd_seq_timer *tmr)
3964 {
3965 if (! tmr->timeri)
3966 return -EINVAL;
3967 @@ -326,6 +338,17 @@ int snd_seq_timer_stop(struct snd_seq_timer * tmr)
3968 return 0;
3969 }
3970
3971 +int snd_seq_timer_stop(struct snd_seq_timer *tmr)
3972 +{
3973 + unsigned long flags;
3974 + int err;
3975 +
3976 + spin_lock_irqsave(&tmr->lock, flags);
3977 + err = seq_timer_stop(tmr);
3978 + spin_unlock_irqrestore(&tmr->lock, flags);
3979 + return err;
3980 +}
3981 +
3982 static int initialize_timer(struct snd_seq_timer *tmr)
3983 {
3984 struct snd_timer *t;
3985 @@ -358,13 +381,13 @@ static int initialize_timer(struct snd_seq_timer *tmr)
3986 return 0;
3987 }
3988
3989 -int snd_seq_timer_start(struct snd_seq_timer * tmr)
3990 +static int seq_timer_start(struct snd_seq_timer *tmr)
3991 {
3992 if (! tmr->timeri)
3993 return -EINVAL;
3994 if (tmr->running)
3995 - snd_seq_timer_stop(tmr);
3996 - snd_seq_timer_reset(tmr);
3997 + seq_timer_stop(tmr);
3998 + seq_timer_reset(tmr);
3999 if (initialize_timer(tmr) < 0)
4000 return -EINVAL;
4001 snd_timer_start(tmr->timeri, tmr->ticks);
4002 @@ -373,14 +396,25 @@ int snd_seq_timer_start(struct snd_seq_timer * tmr)
4003 return 0;
4004 }
4005
4006 -int snd_seq_timer_continue(struct snd_seq_timer * tmr)
4007 +int snd_seq_timer_start(struct snd_seq_timer *tmr)
4008 +{
4009 + unsigned long flags;
4010 + int err;
4011 +
4012 + spin_lock_irqsave(&tmr->lock, flags);
4013 + err = seq_timer_start(tmr);
4014 + spin_unlock_irqrestore(&tmr->lock, flags);
4015 + return err;
4016 +}
4017 +
4018 +static int seq_timer_continue(struct snd_seq_timer *tmr)
4019 {
4020 if (! tmr->timeri)
4021 return -EINVAL;
4022 if (tmr->running)
4023 return -EBUSY;
4024 if (! tmr->initialized) {
4025 - snd_seq_timer_reset(tmr);
4026 + seq_timer_reset(tmr);
4027 if (initialize_timer(tmr) < 0)
4028 return -EINVAL;
4029 }
4030 @@ -390,11 +424,24 @@ int snd_seq_timer_continue(struct snd_seq_timer * tmr)
4031 return 0;
4032 }
4033
4034 +int snd_seq_timer_continue(struct snd_seq_timer *tmr)
4035 +{
4036 + unsigned long flags;
4037 + int err;
4038 +
4039 + spin_lock_irqsave(&tmr->lock, flags);
4040 + err = seq_timer_continue(tmr);
4041 + spin_unlock_irqrestore(&tmr->lock, flags);
4042 + return err;
4043 +}
4044 +
4045 /* return current 'real' time. use timeofday() to get better granularity. */
4046 snd_seq_real_time_t snd_seq_timer_get_cur_time(struct snd_seq_timer *tmr)
4047 {
4048 snd_seq_real_time_t cur_time;
4049 + unsigned long flags;
4050
4051 + spin_lock_irqsave(&tmr->lock, flags);
4052 cur_time = tmr->cur_time;
4053 if (tmr->running) {
4054 struct timeval tm;
4055 @@ -410,7 +457,7 @@ snd_seq_real_time_t snd_seq_timer_get_cur_time(struct snd_seq_timer *tmr)
4056 }
4057 snd_seq_sanity_real_time(&cur_time);
4058 }
4059 -
4060 + spin_unlock_irqrestore(&tmr->lock, flags);
4061 return cur_time;
4062 }
4063
4064 diff --git a/sound/core/seq/seq_virmidi.c b/sound/core/seq/seq_virmidi.c
4065 index 56e0f4cd3f82..81134e067184 100644
4066 --- a/sound/core/seq/seq_virmidi.c
4067 +++ b/sound/core/seq/seq_virmidi.c
4068 @@ -155,21 +155,26 @@ static void snd_virmidi_output_trigger(struct snd_rawmidi_substream *substream,
4069 struct snd_virmidi *vmidi = substream->runtime->private_data;
4070 int count, res;
4071 unsigned char buf[32], *pbuf;
4072 + unsigned long flags;
4073
4074 if (up) {
4075 vmidi->trigger = 1;
4076 if (vmidi->seq_mode == SNDRV_VIRMIDI_SEQ_DISPATCH &&
4077 !(vmidi->rdev->flags & SNDRV_VIRMIDI_SUBSCRIBE)) {
4078 - snd_rawmidi_transmit_ack(substream, substream->runtime->buffer_size - substream->runtime->avail);
4079 - return; /* ignored */
4080 + while (snd_rawmidi_transmit(substream, buf,
4081 + sizeof(buf)) > 0) {
4082 + /* ignored */
4083 + }
4084 + return;
4085 }
4086 if (vmidi->event.type != SNDRV_SEQ_EVENT_NONE) {
4087 if (snd_seq_kernel_client_dispatch(vmidi->client, &vmidi->event, in_atomic(), 0) < 0)
4088 return;
4089 vmidi->event.type = SNDRV_SEQ_EVENT_NONE;
4090 }
4091 + spin_lock_irqsave(&substream->runtime->lock, flags);
4092 while (1) {
4093 - count = snd_rawmidi_transmit_peek(substream, buf, sizeof(buf));
4094 + count = __snd_rawmidi_transmit_peek(substream, buf, sizeof(buf));
4095 if (count <= 0)
4096 break;
4097 pbuf = buf;
4098 @@ -179,16 +184,18 @@ static void snd_virmidi_output_trigger(struct snd_rawmidi_substream *substream,
4099 snd_midi_event_reset_encode(vmidi->parser);
4100 continue;
4101 }
4102 - snd_rawmidi_transmit_ack(substream, res);
4103 + __snd_rawmidi_transmit_ack(substream, res);
4104 pbuf += res;
4105 count -= res;
4106 if (vmidi->event.type != SNDRV_SEQ_EVENT_NONE) {
4107 if (snd_seq_kernel_client_dispatch(vmidi->client, &vmidi->event, in_atomic(), 0) < 0)
4108 - return;
4109 + goto out;
4110 vmidi->event.type = SNDRV_SEQ_EVENT_NONE;
4111 }
4112 }
4113 }
4114 + out:
4115 + spin_unlock_irqrestore(&substream->runtime->lock, flags);
4116 } else {
4117 vmidi->trigger = 0;
4118 }
4119 @@ -254,9 +261,13 @@ static int snd_virmidi_output_open(struct snd_rawmidi_substream *substream)
4120 */
4121 static int snd_virmidi_input_close(struct snd_rawmidi_substream *substream)
4122 {
4123 + struct snd_virmidi_dev *rdev = substream->rmidi->private_data;
4124 struct snd_virmidi *vmidi = substream->runtime->private_data;
4125 - snd_midi_event_free(vmidi->parser);
4126 +
4127 + write_lock_irq(&rdev->filelist_lock);
4128 list_del(&vmidi->list);
4129 + write_unlock_irq(&rdev->filelist_lock);
4130 + snd_midi_event_free(vmidi->parser);
4131 substream->runtime->private_data = NULL;
4132 kfree(vmidi);
4133 return 0;
4134 diff --git a/sound/core/timer.c b/sound/core/timer.c
4135 index 0a049c4578f1..f24c9fccf008 100644
4136 --- a/sound/core/timer.c
4137 +++ b/sound/core/timer.c
4138 @@ -305,8 +305,7 @@ int snd_timer_open(struct snd_timer_instance **ti,
4139 return 0;
4140 }
4141
4142 -static int _snd_timer_stop(struct snd_timer_instance *timeri,
4143 - int keep_flag, int event);
4144 +static int _snd_timer_stop(struct snd_timer_instance *timeri, int event);
4145
4146 /*
4147 * close a timer instance
4148 @@ -348,7 +347,7 @@ int snd_timer_close(struct snd_timer_instance *timeri)
4149 spin_unlock_irq(&timer->lock);
4150 mutex_lock(&register_mutex);
4151 list_del(&timeri->open_list);
4152 - if (timer && list_empty(&timer->open_list_head) &&
4153 + if (list_empty(&timer->open_list_head) &&
4154 timer->hw.close)
4155 timer->hw.close(timer);
4156 /* remove slave links */
4157 @@ -423,7 +422,7 @@ static void snd_timer_notify1(struct snd_timer_instance *ti, int event)
4158 spin_lock_irqsave(&timer->lock, flags);
4159 list_for_each_entry(ts, &ti->slave_active_head, active_list)
4160 if (ts->ccallback)
4161 - ts->ccallback(ti, event + 100, &tstamp, resolution);
4162 + ts->ccallback(ts, event + 100, &tstamp, resolution);
4163 spin_unlock_irqrestore(&timer->lock, flags);
4164 }
4165
4166 @@ -452,6 +451,10 @@ static int snd_timer_start_slave(struct snd_timer_instance *timeri)
4167 unsigned long flags;
4168
4169 spin_lock_irqsave(&slave_active_lock, flags);
4170 + if (timeri->flags & SNDRV_TIMER_IFLG_RUNNING) {
4171 + spin_unlock_irqrestore(&slave_active_lock, flags);
4172 + return -EBUSY;
4173 + }
4174 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING;
4175 if (timeri->master && timeri->timer) {
4176 spin_lock(&timeri->timer->lock);
4177 @@ -476,7 +479,8 @@ int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks)
4178 return -EINVAL;
4179 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) {
4180 result = snd_timer_start_slave(timeri);
4181 - snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_START);
4182 + if (result >= 0)
4183 + snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_START);
4184 return result;
4185 }
4186 timer = timeri->timer;
4187 @@ -485,16 +489,22 @@ int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks)
4188 if (timer->card && timer->card->shutdown)
4189 return -ENODEV;
4190 spin_lock_irqsave(&timer->lock, flags);
4191 + if (timeri->flags & (SNDRV_TIMER_IFLG_RUNNING |
4192 + SNDRV_TIMER_IFLG_START)) {
4193 + result = -EBUSY;
4194 + goto unlock;
4195 + }
4196 timeri->ticks = timeri->cticks = ticks;
4197 timeri->pticks = 0;
4198 result = snd_timer_start1(timer, timeri, ticks);
4199 + unlock:
4200 spin_unlock_irqrestore(&timer->lock, flags);
4201 - snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_START);
4202 + if (result >= 0)
4203 + snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_START);
4204 return result;
4205 }
4206
4207 -static int _snd_timer_stop(struct snd_timer_instance * timeri,
4208 - int keep_flag, int event)
4209 +static int _snd_timer_stop(struct snd_timer_instance *timeri, int event)
4210 {
4211 struct snd_timer *timer;
4212 unsigned long flags;
4213 @@ -503,19 +513,30 @@ static int _snd_timer_stop(struct snd_timer_instance * timeri,
4214 return -ENXIO;
4215
4216 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) {
4217 - if (!keep_flag) {
4218 - spin_lock_irqsave(&slave_active_lock, flags);
4219 - timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
4220 - list_del_init(&timeri->ack_list);
4221 - list_del_init(&timeri->active_list);
4222 + spin_lock_irqsave(&slave_active_lock, flags);
4223 + if (!(timeri->flags & SNDRV_TIMER_IFLG_RUNNING)) {
4224 spin_unlock_irqrestore(&slave_active_lock, flags);
4225 + return -EBUSY;
4226 }
4227 + if (timeri->timer)
4228 + spin_lock(&timeri->timer->lock);
4229 + timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
4230 + list_del_init(&timeri->ack_list);
4231 + list_del_init(&timeri->active_list);
4232 + if (timeri->timer)
4233 + spin_unlock(&timeri->timer->lock);
4234 + spin_unlock_irqrestore(&slave_active_lock, flags);
4235 goto __end;
4236 }
4237 timer = timeri->timer;
4238 if (!timer)
4239 return -EINVAL;
4240 spin_lock_irqsave(&timer->lock, flags);
4241 + if (!(timeri->flags & (SNDRV_TIMER_IFLG_RUNNING |
4242 + SNDRV_TIMER_IFLG_START))) {
4243 + spin_unlock_irqrestore(&timer->lock, flags);
4244 + return -EBUSY;
4245 + }
4246 list_del_init(&timeri->ack_list);
4247 list_del_init(&timeri->active_list);
4248 if (timer->card && timer->card->shutdown) {
4249 @@ -534,9 +555,7 @@ static int _snd_timer_stop(struct snd_timer_instance * timeri,
4250 }
4251 }
4252 }
4253 - if (!keep_flag)
4254 - timeri->flags &=
4255 - ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START);
4256 + timeri->flags &= ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START);
4257 spin_unlock_irqrestore(&timer->lock, flags);
4258 __end:
4259 if (event != SNDRV_TIMER_EVENT_RESOLUTION)
4260 @@ -555,7 +574,7 @@ int snd_timer_stop(struct snd_timer_instance *timeri)
4261 unsigned long flags;
4262 int err;
4263
4264 - err = _snd_timer_stop(timeri, 0, SNDRV_TIMER_EVENT_STOP);
4265 + err = _snd_timer_stop(timeri, SNDRV_TIMER_EVENT_STOP);
4266 if (err < 0)
4267 return err;
4268 timer = timeri->timer;
4269 @@ -587,10 +606,15 @@ int snd_timer_continue(struct snd_timer_instance *timeri)
4270 if (timer->card && timer->card->shutdown)
4271 return -ENODEV;
4272 spin_lock_irqsave(&timer->lock, flags);
4273 + if (timeri->flags & SNDRV_TIMER_IFLG_RUNNING) {
4274 + result = -EBUSY;
4275 + goto unlock;
4276 + }
4277 if (!timeri->cticks)
4278 timeri->cticks = 1;
4279 timeri->pticks = 0;
4280 result = snd_timer_start1(timer, timeri, timer->sticks);
4281 + unlock:
4282 spin_unlock_irqrestore(&timer->lock, flags);
4283 snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_CONTINUE);
4284 return result;
4285 @@ -601,7 +625,7 @@ int snd_timer_continue(struct snd_timer_instance *timeri)
4286 */
4287 int snd_timer_pause(struct snd_timer_instance * timeri)
4288 {
4289 - return _snd_timer_stop(timeri, 0, SNDRV_TIMER_EVENT_PAUSE);
4290 + return _snd_timer_stop(timeri, SNDRV_TIMER_EVENT_PAUSE);
4291 }
4292
4293 /*
4294 @@ -724,8 +748,8 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
4295 ti->cticks = ti->ticks;
4296 } else {
4297 ti->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
4298 - if (--timer->running)
4299 - list_del_init(&ti->active_list);
4300 + --timer->running;
4301 + list_del_init(&ti->active_list);
4302 }
4303 if ((timer->hw.flags & SNDRV_TIMER_HW_TASKLET) ||
4304 (ti->flags & SNDRV_TIMER_IFLG_FAST))
4305 @@ -1900,6 +1924,7 @@ static ssize_t snd_timer_user_read(struct file *file, char __user *buffer,
4306 {
4307 struct snd_timer_user *tu;
4308 long result = 0, unit;
4309 + int qhead;
4310 int err = 0;
4311
4312 tu = file->private_data;
4313 @@ -1911,7 +1936,7 @@ static ssize_t snd_timer_user_read(struct file *file, char __user *buffer,
4314
4315 if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) {
4316 err = -EAGAIN;
4317 - break;
4318 + goto _error;
4319 }
4320
4321 set_current_state(TASK_INTERRUPTIBLE);
4322 @@ -1926,42 +1951,37 @@ static ssize_t snd_timer_user_read(struct file *file, char __user *buffer,
4323
4324 if (tu->disconnected) {
4325 err = -ENODEV;
4326 - break;
4327 + goto _error;
4328 }
4329 if (signal_pending(current)) {
4330 err = -ERESTARTSYS;
4331 - break;
4332 + goto _error;
4333 }
4334 }
4335
4336 + qhead = tu->qhead++;
4337 + tu->qhead %= tu->queue_size;
4338 spin_unlock_irq(&tu->qlock);
4339 - if (err < 0)
4340 - goto _error;
4341
4342 if (tu->tread) {
4343 - if (copy_to_user(buffer, &tu->tqueue[tu->qhead++],
4344 - sizeof(struct snd_timer_tread))) {
4345 + if (copy_to_user(buffer, &tu->tqueue[qhead],
4346 + sizeof(struct snd_timer_tread)))
4347 err = -EFAULT;
4348 - goto _error;
4349 - }
4350 } else {
4351 - if (copy_to_user(buffer, &tu->queue[tu->qhead++],
4352 - sizeof(struct snd_timer_read))) {
4353 + if (copy_to_user(buffer, &tu->queue[qhead],
4354 + sizeof(struct snd_timer_read)))
4355 err = -EFAULT;
4356 - goto _error;
4357 - }
4358 }
4359
4360 - tu->qhead %= tu->queue_size;
4361 -
4362 - result += unit;
4363 - buffer += unit;
4364 -
4365 spin_lock_irq(&tu->qlock);
4366 tu->qused--;
4367 + if (err < 0)
4368 + goto _error;
4369 + result += unit;
4370 + buffer += unit;
4371 }
4372 - spin_unlock_irq(&tu->qlock);
4373 _error:
4374 + spin_unlock_irq(&tu->qlock);
4375 return result > 0 ? result : err;
4376 }
4377
4378 diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
4379 index 016e451ed506..a9f7a75702d2 100644
4380 --- a/sound/drivers/dummy.c
4381 +++ b/sound/drivers/dummy.c
4382 @@ -109,6 +109,9 @@ struct dummy_timer_ops {
4383 snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *);
4384 };
4385
4386 +#define get_dummy_ops(substream) \
4387 + (*(const struct dummy_timer_ops **)(substream)->runtime->private_data)
4388 +
4389 struct dummy_model {
4390 const char *name;
4391 int (*playback_constraints)(struct snd_pcm_runtime *runtime);
4392 @@ -137,7 +140,6 @@ struct snd_dummy {
4393 int iobox;
4394 struct snd_kcontrol *cd_volume_ctl;
4395 struct snd_kcontrol *cd_switch_ctl;
4396 - const struct dummy_timer_ops *timer_ops;
4397 };
4398
4399 /*
4400 @@ -231,6 +233,8 @@ static struct dummy_model *dummy_models[] = {
4401 */
4402
4403 struct dummy_systimer_pcm {
4404 + /* ops must be the first item */
4405 + const struct dummy_timer_ops *timer_ops;
4406 spinlock_t lock;
4407 struct timer_list timer;
4408 unsigned long base_time;
4409 @@ -366,6 +370,8 @@ static struct dummy_timer_ops dummy_systimer_ops = {
4410 */
4411
4412 struct dummy_hrtimer_pcm {
4413 + /* ops must be the first item */
4414 + const struct dummy_timer_ops *timer_ops;
4415 ktime_t base_time;
4416 ktime_t period_time;
4417 atomic_t running;
4418 @@ -492,31 +498,25 @@ static struct dummy_timer_ops dummy_hrtimer_ops = {
4419
4420 static int dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
4421 {
4422 - struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
4423 -
4424 switch (cmd) {
4425 case SNDRV_PCM_TRIGGER_START:
4426 case SNDRV_PCM_TRIGGER_RESUME:
4427 - return dummy->timer_ops->start(substream);
4428 + return get_dummy_ops(substream)->start(substream);
4429 case SNDRV_PCM_TRIGGER_STOP:
4430 case SNDRV_PCM_TRIGGER_SUSPEND:
4431 - return dummy->timer_ops->stop(substream);
4432 + return get_dummy_ops(substream)->stop(substream);
4433 }
4434 return -EINVAL;
4435 }
4436
4437 static int dummy_pcm_prepare(struct snd_pcm_substream *substream)
4438 {
4439 - struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
4440 -
4441 - return dummy->timer_ops->prepare(substream);
4442 + return get_dummy_ops(substream)->prepare(substream);
4443 }
4444
4445 static snd_pcm_uframes_t dummy_pcm_pointer(struct snd_pcm_substream *substream)
4446 {
4447 - struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
4448 -
4449 - return dummy->timer_ops->pointer(substream);
4450 + return get_dummy_ops(substream)->pointer(substream);
4451 }
4452
4453 static struct snd_pcm_hardware dummy_pcm_hardware = {
4454 @@ -562,17 +562,19 @@ static int dummy_pcm_open(struct snd_pcm_substream *substream)
4455 struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
4456 struct dummy_model *model = dummy->model;
4457 struct snd_pcm_runtime *runtime = substream->runtime;
4458 + const struct dummy_timer_ops *ops;
4459 int err;
4460
4461 - dummy->timer_ops = &dummy_systimer_ops;
4462 + ops = &dummy_systimer_ops;
4463 #ifdef CONFIG_HIGH_RES_TIMERS
4464 if (hrtimer)
4465 - dummy->timer_ops = &dummy_hrtimer_ops;
4466 + ops = &dummy_hrtimer_ops;
4467 #endif
4468
4469 - err = dummy->timer_ops->create(substream);
4470 + err = ops->create(substream);
4471 if (err < 0)
4472 return err;
4473 + get_dummy_ops(substream) = ops;
4474
4475 runtime->hw = dummy->pcm_hw;
4476 if (substream->pcm->device & 1) {
4477 @@ -594,7 +596,7 @@ static int dummy_pcm_open(struct snd_pcm_substream *substream)
4478 err = model->capture_constraints(substream->runtime);
4479 }
4480 if (err < 0) {
4481 - dummy->timer_ops->free(substream);
4482 + get_dummy_ops(substream)->free(substream);
4483 return err;
4484 }
4485 return 0;
4486 @@ -602,8 +604,7 @@ static int dummy_pcm_open(struct snd_pcm_substream *substream)
4487
4488 static int dummy_pcm_close(struct snd_pcm_substream *substream)
4489 {
4490 - struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
4491 - dummy->timer_ops->free(substream);
4492 + get_dummy_ops(substream)->free(substream);
4493 return 0;
4494 }
4495
4496 diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c
4497 index 926e5dcbb66a..5022c9b97ddf 100644
4498 --- a/sound/firewire/bebob/bebob_stream.c
4499 +++ b/sound/firewire/bebob/bebob_stream.c
4500 @@ -47,14 +47,16 @@ static const unsigned int bridgeco_freq_table[] = {
4501 [6] = 0x07,
4502 };
4503
4504 -static unsigned int
4505 -get_formation_index(unsigned int rate)
4506 +static int
4507 +get_formation_index(unsigned int rate, unsigned int *index)
4508 {
4509 unsigned int i;
4510
4511 for (i = 0; i < ARRAY_SIZE(snd_bebob_rate_table); i++) {
4512 - if (snd_bebob_rate_table[i] == rate)
4513 - return i;
4514 + if (snd_bebob_rate_table[i] == rate) {
4515 + *index = i;
4516 + return 0;
4517 + }
4518 }
4519 return -EINVAL;
4520 }
4521 @@ -425,7 +427,9 @@ make_both_connections(struct snd_bebob *bebob, unsigned int rate)
4522 goto end;
4523
4524 /* confirm params for both streams */
4525 - index = get_formation_index(rate);
4526 + err = get_formation_index(rate, &index);
4527 + if (err < 0)
4528 + goto end;
4529 pcm_channels = bebob->tx_stream_formations[index].pcm;
4530 midi_channels = bebob->tx_stream_formations[index].midi;
4531 err = amdtp_am824_set_parameters(&bebob->tx_stream, rate,
4532 diff --git a/sound/isa/Kconfig b/sound/isa/Kconfig
4533 index 0216475fc759..37adcc6cbe6b 100644
4534 --- a/sound/isa/Kconfig
4535 +++ b/sound/isa/Kconfig
4536 @@ -3,6 +3,7 @@
4537 config SND_WSS_LIB
4538 tristate
4539 select SND_PCM
4540 + select SND_TIMER
4541
4542 config SND_SB_COMMON
4543 tristate
4544 @@ -42,6 +43,7 @@ config SND_AD1816A
4545 select SND_OPL3_LIB
4546 select SND_MPU401_UART
4547 select SND_PCM
4548 + select SND_TIMER
4549 help
4550 Say Y here to include support for Analog Devices SoundPort
4551 AD1816A or compatible sound chips.
4552 @@ -209,6 +211,7 @@ config SND_GUSCLASSIC
4553 tristate "Gravis UltraSound Classic"
4554 select SND_RAWMIDI
4555 select SND_PCM
4556 + select SND_TIMER
4557 help
4558 Say Y here to include support for Gravis UltraSound Classic
4559 soundcards.
4560 @@ -221,6 +224,7 @@ config SND_GUSEXTREME
4561 select SND_OPL3_LIB
4562 select SND_MPU401_UART
4563 select SND_PCM
4564 + select SND_TIMER
4565 help
4566 Say Y here to include support for Gravis UltraSound Extreme
4567 soundcards.
4568 diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
4569 index 656ce39bddbc..8f6594a7d37f 100644
4570 --- a/sound/pci/Kconfig
4571 +++ b/sound/pci/Kconfig
4572 @@ -155,6 +155,7 @@ config SND_AZT3328
4573 select SND_PCM
4574 select SND_RAWMIDI
4575 select SND_AC97_CODEC
4576 + select SND_TIMER
4577 depends on ZONE_DMA
4578 help
4579 Say Y here to include support for Aztech AZF3328 (PCI168)
4580 @@ -463,6 +464,7 @@ config SND_EMU10K1
4581 select SND_HWDEP
4582 select SND_RAWMIDI
4583 select SND_AC97_CODEC
4584 + select SND_TIMER
4585 depends on ZONE_DMA
4586 help
4587 Say Y to include support for Sound Blaster PCI 512, Live!,
4588 @@ -889,6 +891,7 @@ config SND_YMFPCI
4589 select SND_OPL3_LIB
4590 select SND_MPU401_UART
4591 select SND_AC97_CODEC
4592 + select SND_TIMER
4593 help
4594 Say Y here to include support for Yamaha PCI audio chips -
4595 YMF724, YMF724F, YMF740, YMF740C, YMF744, YMF754.
4596 diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
4597 index c6e8a651cea1..5c4fa8eba1d0 100644
4598 --- a/sound/pci/hda/hda_generic.c
4599 +++ b/sound/pci/hda/hda_generic.c
4600 @@ -771,9 +771,6 @@ static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
4601 unsigned int caps;
4602 unsigned int mask, val;
4603
4604 - if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
4605 - return;
4606 -
4607 caps = query_amp_caps(codec, nid, dir);
4608 val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
4609 mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
4610 @@ -784,12 +781,22 @@ static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
4611 update_amp(codec, nid, dir, idx, mask, val);
4612 }
4613
4614 +static void check_and_activate_amp(struct hda_codec *codec, hda_nid_t nid,
4615 + int dir, int idx, int idx_to_check,
4616 + bool enable)
4617 +{
4618 + /* check whether the given amp is still used by others */
4619 + if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
4620 + return;
4621 + activate_amp(codec, nid, dir, idx, idx_to_check, enable);
4622 +}
4623 +
4624 static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
4625 int i, bool enable)
4626 {
4627 hda_nid_t nid = path->path[i];
4628 init_amp(codec, nid, HDA_OUTPUT, 0);
4629 - activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
4630 + check_and_activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
4631 }
4632
4633 static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
4634 @@ -817,9 +824,16 @@ static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
4635 * when aa-mixer is available, we need to enable the path as well
4636 */
4637 for (n = 0; n < nums; n++) {
4638 - if (n != idx && (!add_aamix || conn[n] != spec->mixer_merge_nid))
4639 - continue;
4640 - activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
4641 + if (n != idx) {
4642 + if (conn[n] != spec->mixer_merge_nid)
4643 + continue;
4644 + /* when aamix is disabled, force to off */
4645 + if (!add_aamix) {
4646 + activate_amp(codec, nid, HDA_INPUT, n, n, false);
4647 + continue;
4648 + }
4649 + }
4650 + check_and_activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
4651 }
4652 }
4653
4654 @@ -1580,6 +1594,12 @@ static bool map_singles(struct hda_codec *codec, int outs,
4655 return found;
4656 }
4657
4658 +static inline bool has_aamix_out_paths(struct hda_gen_spec *spec)
4659 +{
4660 + return spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
4661 + spec->aamix_out_paths[2];
4662 +}
4663 +
4664 /* create a new path including aamix if available, and return its index */
4665 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
4666 {
4667 @@ -2422,25 +2442,51 @@ static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
4668 }
4669 }
4670
4671 +/* re-initialize the output paths; only called from loopback_mixing_put() */
4672 +static void update_output_paths(struct hda_codec *codec, int num_outs,
4673 + const int *paths)
4674 +{
4675 + struct hda_gen_spec *spec = codec->spec;
4676 + struct nid_path *path;
4677 + int i;
4678 +
4679 + for (i = 0; i < num_outs; i++) {
4680 + path = snd_hda_get_path_from_idx(codec, paths[i]);
4681 + if (path)
4682 + snd_hda_activate_path(codec, path, path->active,
4683 + spec->aamix_mode);
4684 + }
4685 +}
4686 +
4687 static int loopback_mixing_put(struct snd_kcontrol *kcontrol,
4688 struct snd_ctl_elem_value *ucontrol)
4689 {
4690 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4691 struct hda_gen_spec *spec = codec->spec;
4692 + const struct auto_pin_cfg *cfg = &spec->autocfg;
4693 unsigned int val = ucontrol->value.enumerated.item[0];
4694
4695 if (val == spec->aamix_mode)
4696 return 0;
4697 spec->aamix_mode = val;
4698 - update_aamix_paths(codec, val, spec->out_paths[0],
4699 - spec->aamix_out_paths[0],
4700 - spec->autocfg.line_out_type);
4701 - update_aamix_paths(codec, val, spec->hp_paths[0],
4702 - spec->aamix_out_paths[1],
4703 - AUTO_PIN_HP_OUT);
4704 - update_aamix_paths(codec, val, spec->speaker_paths[0],
4705 - spec->aamix_out_paths[2],
4706 - AUTO_PIN_SPEAKER_OUT);
4707 + if (has_aamix_out_paths(spec)) {
4708 + update_aamix_paths(codec, val, spec->out_paths[0],
4709 + spec->aamix_out_paths[0],
4710 + cfg->line_out_type);
4711 + update_aamix_paths(codec, val, spec->hp_paths[0],
4712 + spec->aamix_out_paths[1],
4713 + AUTO_PIN_HP_OUT);
4714 + update_aamix_paths(codec, val, spec->speaker_paths[0],
4715 + spec->aamix_out_paths[2],
4716 + AUTO_PIN_SPEAKER_OUT);
4717 + } else {
4718 + update_output_paths(codec, cfg->line_outs, spec->out_paths);
4719 + if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4720 + update_output_paths(codec, cfg->hp_outs, spec->hp_paths);
4721 + if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4722 + update_output_paths(codec, cfg->speaker_outs,
4723 + spec->speaker_paths);
4724 + }
4725 return 1;
4726 }
4727
4728 @@ -2458,12 +2504,13 @@ static int create_loopback_mixing_ctl(struct hda_codec *codec)
4729
4730 if (!spec->mixer_nid)
4731 return 0;
4732 - if (!(spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
4733 - spec->aamix_out_paths[2]))
4734 - return 0;
4735 if (!snd_hda_gen_add_kctl(spec, NULL, &loopback_mixing_enum))
4736 return -ENOMEM;
4737 spec->have_aamix_ctl = 1;
4738 + /* if no explicit aamix path is present (e.g. for Realtek codecs),
4739 + * enable aamix as default -- just for compatibility
4740 + */
4741 + spec->aamix_mode = !has_aamix_out_paths(spec);
4742 return 0;
4743 }
4744
4745 @@ -3998,9 +4045,9 @@ static void pin_power_callback(struct hda_codec *codec,
4746 struct hda_jack_callback *jack,
4747 bool on)
4748 {
4749 - if (jack && jack->tbl->nid)
4750 + if (jack && jack->nid)
4751 sync_power_state_change(codec,
4752 - set_pin_power_jack(codec, jack->tbl->nid, on));
4753 + set_pin_power_jack(codec, jack->nid, on));
4754 }
4755
4756 /* callback only doing power up -- called at first */
4757 @@ -5664,6 +5711,8 @@ static void init_aamix_paths(struct hda_codec *codec)
4758
4759 if (!spec->have_aamix_ctl)
4760 return;
4761 + if (!has_aamix_out_paths(spec))
4762 + return;
4763 update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
4764 spec->aamix_out_paths[0],
4765 spec->autocfg.line_out_type);
4766 diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
4767 index 614baff1f5d7..02a86ba5ba22 100644
4768 --- a/sound/pci/hda/hda_intel.c
4769 +++ b/sound/pci/hda/hda_intel.c
4770 @@ -90,6 +90,8 @@ enum {
4771 #define NVIDIA_HDA_ENABLE_COHBIT 0x01
4772
4773 /* Defines for Intel SCH HDA snoop control */
4774 +#define INTEL_HDA_CGCTL 0x48
4775 +#define INTEL_HDA_CGCTL_MISCBDCGE (0x1 << 6)
4776 #define INTEL_SCH_HDA_DEVC 0x78
4777 #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
4778
4779 @@ -528,10 +530,21 @@ static void hda_intel_init_chip(struct azx *chip, bool full_reset)
4780 {
4781 struct hdac_bus *bus = azx_bus(chip);
4782 struct pci_dev *pci = chip->pci;
4783 + u32 val;
4784
4785 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
4786 snd_hdac_set_codec_wakeup(bus, true);
4787 + if (IS_BROXTON(pci)) {
4788 + pci_read_config_dword(pci, INTEL_HDA_CGCTL, &val);
4789 + val = val & ~INTEL_HDA_CGCTL_MISCBDCGE;
4790 + pci_write_config_dword(pci, INTEL_HDA_CGCTL, val);
4791 + }
4792 azx_init_chip(chip, full_reset);
4793 + if (IS_BROXTON(pci)) {
4794 + pci_read_config_dword(pci, INTEL_HDA_CGCTL, &val);
4795 + val = val | INTEL_HDA_CGCTL_MISCBDCGE;
4796 + pci_write_config_dword(pci, INTEL_HDA_CGCTL, val);
4797 + }
4798 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
4799 snd_hdac_set_codec_wakeup(bus, false);
4800
4801 diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
4802 index c945e257d368..a33234e04d4f 100644
4803 --- a/sound/pci/hda/hda_jack.c
4804 +++ b/sound/pci/hda/hda_jack.c
4805 @@ -259,7 +259,7 @@ snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
4806 if (!callback)
4807 return ERR_PTR(-ENOMEM);
4808 callback->func = func;
4809 - callback->tbl = jack;
4810 + callback->nid = jack->nid;
4811 callback->next = jack->callback;
4812 jack->callback = callback;
4813 }
4814 diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
4815 index 858708a044f5..e9814c0168ea 100644
4816 --- a/sound/pci/hda/hda_jack.h
4817 +++ b/sound/pci/hda/hda_jack.h
4818 @@ -21,7 +21,7 @@ struct hda_jack_callback;
4819 typedef void (*hda_jack_callback_fn) (struct hda_codec *, struct hda_jack_callback *);
4820
4821 struct hda_jack_callback {
4822 - struct hda_jack_tbl *tbl;
4823 + hda_nid_t nid;
4824 hda_jack_callback_fn func;
4825 unsigned int private_data; /* arbitrary data */
4826 struct hda_jack_callback *next;
4827 diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
4828 index 4ef2259f88ca..9ceb2bc36e68 100644
4829 --- a/sound/pci/hda/patch_ca0132.c
4830 +++ b/sound/pci/hda/patch_ca0132.c
4831 @@ -4427,13 +4427,16 @@ static void ca0132_process_dsp_response(struct hda_codec *codec,
4832 static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
4833 {
4834 struct ca0132_spec *spec = codec->spec;
4835 + struct hda_jack_tbl *tbl;
4836
4837 /* Delay enabling the HP amp, to let the mic-detection
4838 * state machine run.
4839 */
4840 cancel_delayed_work_sync(&spec->unsol_hp_work);
4841 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
4842 - cb->tbl->block_report = 1;
4843 + tbl = snd_hda_jack_tbl_get(codec, cb->nid);
4844 + if (tbl)
4845 + tbl->block_report = 1;
4846 }
4847
4848 static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
4849 diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
4850 index a12ae8ac0914..c1c855a6c0af 100644
4851 --- a/sound/pci/hda/patch_cirrus.c
4852 +++ b/sound/pci/hda/patch_cirrus.c
4853 @@ -614,6 +614,7 @@ enum {
4854 CS4208_MAC_AUTO,
4855 CS4208_MBA6,
4856 CS4208_MBP11,
4857 + CS4208_MACMINI,
4858 CS4208_GPIO0,
4859 };
4860
4861 @@ -621,6 +622,7 @@ static const struct hda_model_fixup cs4208_models[] = {
4862 { .id = CS4208_GPIO0, .name = "gpio0" },
4863 { .id = CS4208_MBA6, .name = "mba6" },
4864 { .id = CS4208_MBP11, .name = "mbp11" },
4865 + { .id = CS4208_MACMINI, .name = "macmini" },
4866 {}
4867 };
4868
4869 @@ -632,6 +634,7 @@ static const struct snd_pci_quirk cs4208_fixup_tbl[] = {
4870 /* codec SSID matching */
4871 static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = {
4872 SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11),
4873 + SND_PCI_QUIRK(0x106b, 0x6c00, "MacMini 7,1", CS4208_MACMINI),
4874 SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6),
4875 SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6),
4876 SND_PCI_QUIRK(0x106b, 0x7b00, "MacBookPro 12,1", CS4208_MBP11),
4877 @@ -666,6 +669,24 @@ static void cs4208_fixup_mac(struct hda_codec *codec,
4878 snd_hda_apply_fixup(codec, action);
4879 }
4880
4881 +/* MacMini 7,1 has the inverted jack detection */
4882 +static void cs4208_fixup_macmini(struct hda_codec *codec,
4883 + const struct hda_fixup *fix, int action)
4884 +{
4885 + static const struct hda_pintbl pincfgs[] = {
4886 + { 0x18, 0x00ab9150 }, /* mic (audio-in) jack: disable detect */
4887 + { 0x21, 0x004be140 }, /* SPDIF: disable detect */
4888 + { }
4889 + };
4890 +
4891 + if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4892 + /* HP pin (0x10) has an inverted detection */
4893 + codec->inv_jack_detect = 1;
4894 + /* disable the bogus Mic and SPDIF jack detections */
4895 + snd_hda_apply_pincfgs(codec, pincfgs);
4896 + }
4897 +}
4898 +
4899 static int cs4208_spdif_sw_put(struct snd_kcontrol *kcontrol,
4900 struct snd_ctl_elem_value *ucontrol)
4901 {
4902 @@ -709,6 +730,12 @@ static const struct hda_fixup cs4208_fixups[] = {
4903 .chained = true,
4904 .chain_id = CS4208_GPIO0,
4905 },
4906 + [CS4208_MACMINI] = {
4907 + .type = HDA_FIXUP_FUNC,
4908 + .v.func = cs4208_fixup_macmini,
4909 + .chained = true,
4910 + .chain_id = CS4208_GPIO0,
4911 + },
4912 [CS4208_GPIO0] = {
4913 .type = HDA_FIXUP_FUNC,
4914 .v.func = cs4208_fixup_gpio0,
4915 diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
4916 index 4b6fb668c91c..70c945603379 100644
4917 --- a/sound/pci/hda/patch_hdmi.c
4918 +++ b/sound/pci/hda/patch_hdmi.c
4919 @@ -438,7 +438,8 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
4920 eld = &per_pin->sink_eld;
4921
4922 mutex_lock(&per_pin->lock);
4923 - if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
4924 + if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
4925 + eld->eld_size > ELD_MAX_SIZE) {
4926 mutex_unlock(&per_pin->lock);
4927 snd_BUG();
4928 return -EINVAL;
4929 @@ -1183,7 +1184,7 @@ static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid)
4930 static void jack_callback(struct hda_codec *codec,
4931 struct hda_jack_callback *jack)
4932 {
4933 - check_presence_and_report(codec, jack->tbl->nid);
4934 + check_presence_and_report(codec, jack->nid);
4935 }
4936
4937 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
4938 diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
4939 index 33753244f48f..efd4980cffb8 100644
4940 --- a/sound/pci/hda/patch_realtek.c
4941 +++ b/sound/pci/hda/patch_realtek.c
4942 @@ -282,7 +282,7 @@ static void alc_update_knob_master(struct hda_codec *codec,
4943 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
4944 if (!uctl)
4945 return;
4946 - val = snd_hda_codec_read(codec, jack->tbl->nid, 0,
4947 + val = snd_hda_codec_read(codec, jack->nid, 0,
4948 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
4949 val &= HDA_AMP_VOLMASK;
4950 uctl->value.integer.value[0] = val;
4951 @@ -327,6 +327,7 @@ static void alc_fill_eapd_coef(struct hda_codec *codec)
4952 case 0x10ec0292:
4953 alc_update_coef_idx(codec, 0x4, 1<<15, 0);
4954 break;
4955 + case 0x10ec0225:
4956 case 0x10ec0233:
4957 case 0x10ec0255:
4958 case 0x10ec0256:
4959 @@ -900,6 +901,7 @@ static struct alc_codec_rename_pci_table rename_pci_tbl[] = {
4960 { 0x10ec0899, 0x1028, 0, "ALC3861" },
4961 { 0x10ec0298, 0x1028, 0, "ALC3266" },
4962 { 0x10ec0256, 0x1028, 0, "ALC3246" },
4963 + { 0x10ec0225, 0x1028, 0, "ALC3253" },
4964 { 0x10ec0670, 0x1025, 0, "ALC669X" },
4965 { 0x10ec0676, 0x1025, 0, "ALC679X" },
4966 { 0x10ec0282, 0x1043, 0, "ALC3229" },
4967 @@ -1785,7 +1787,6 @@ enum {
4968 ALC882_FIXUP_NO_PRIMARY_HP,
4969 ALC887_FIXUP_ASUS_BASS,
4970 ALC887_FIXUP_BASS_CHMAP,
4971 - ALC882_FIXUP_DISABLE_AAMIX,
4972 };
4973
4974 static void alc889_fixup_coef(struct hda_codec *codec,
4975 @@ -1947,8 +1948,6 @@ static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
4976
4977 static void alc_fixup_bass_chmap(struct hda_codec *codec,
4978 const struct hda_fixup *fix, int action);
4979 -static void alc_fixup_disable_aamix(struct hda_codec *codec,
4980 - const struct hda_fixup *fix, int action);
4981
4982 static const struct hda_fixup alc882_fixups[] = {
4983 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
4984 @@ -2186,10 +2185,6 @@ static const struct hda_fixup alc882_fixups[] = {
4985 .type = HDA_FIXUP_FUNC,
4986 .v.func = alc_fixup_bass_chmap,
4987 },
4988 - [ALC882_FIXUP_DISABLE_AAMIX] = {
4989 - .type = HDA_FIXUP_FUNC,
4990 - .v.func = alc_fixup_disable_aamix,
4991 - },
4992 };
4993
4994 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4995 @@ -2228,6 +2223,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4996 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
4997 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
4998 SND_PCI_QUIRK(0x104d, 0x9043, "Sony Vaio VGC-LN51JGB", ALC882_FIXUP_NO_PRIMARY_HP),
4999 + SND_PCI_QUIRK(0x104d, 0x9044, "Sony VAIO AiO", ALC882_FIXUP_NO_PRIMARY_HP),
5000
5001 /* All Apple entries are in codec SSIDs */
5002 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5003 @@ -2257,7 +2253,6 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5004 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
5005 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
5006 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3/Z87X-UD3H", ALC889_FIXUP_FRONT_HP_NO_PRESENCE),
5007 - SND_PCI_QUIRK(0x1458, 0xa182, "Gigabyte Z170X-UD3", ALC882_FIXUP_DISABLE_AAMIX),
5008 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
5009 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5010 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
5011 @@ -2651,6 +2646,7 @@ enum {
5012 ALC269_TYPE_ALC298,
5013 ALC269_TYPE_ALC255,
5014 ALC269_TYPE_ALC256,
5015 + ALC269_TYPE_ALC225,
5016 };
5017
5018 /*
5019 @@ -2680,6 +2676,7 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
5020 case ALC269_TYPE_ALC298:
5021 case ALC269_TYPE_ALC255:
5022 case ALC269_TYPE_ALC256:
5023 + case ALC269_TYPE_ALC225:
5024 ssids = alc269_ssids;
5025 break;
5026 default:
5027 @@ -3658,6 +3655,16 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec)
5028 WRITE_COEF(0xb7, 0x802b),
5029 {}
5030 };
5031 + static struct coef_fw coef0225[] = {
5032 + UPDATE_COEF(0x4a, 1<<8, 0),
5033 + UPDATE_COEFEX(0x57, 0x05, 1<<14, 0),
5034 + UPDATE_COEF(0x63, 3<<14, 3<<14),
5035 + UPDATE_COEF(0x4a, 3<<4, 2<<4),
5036 + UPDATE_COEF(0x4a, 3<<10, 3<<10),
5037 + UPDATE_COEF(0x45, 0x3f<<10, 0x34<<10),
5038 + UPDATE_COEF(0x4a, 3<<10, 0),
5039 + {}
5040 + };
5041
5042 switch (codec->core.vendor_id) {
5043 case 0x10ec0255:
5044 @@ -3682,6 +3689,9 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec)
5045 case 0x10ec0668:
5046 alc_process_coef_fw(codec, coef0668);
5047 break;
5048 + case 0x10ec0225:
5049 + alc_process_coef_fw(codec, coef0225);
5050 + break;
5051 }
5052 codec_dbg(codec, "Headset jack set to unplugged mode.\n");
5053 }
5054 @@ -3727,6 +3737,13 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
5055 UPDATE_COEF(0xc3, 0, 1<<12),
5056 {}
5057 };
5058 + static struct coef_fw coef0225[] = {
5059 + UPDATE_COEFEX(0x57, 0x05, 1<<14, 1<<14),
5060 + UPDATE_COEF(0x4a, 3<<4, 2<<4),
5061 + UPDATE_COEF(0x63, 3<<14, 0),
5062 + {}
5063 + };
5064 +
5065
5066 switch (codec->core.vendor_id) {
5067 case 0x10ec0255:
5068 @@ -3772,6 +3789,12 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
5069 alc_process_coef_fw(codec, coef0688);
5070 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
5071 break;
5072 + case 0x10ec0225:
5073 + alc_update_coef_idx(codec, 0x45, 0x3f<<10, 0x31<<10);
5074 + snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
5075 + alc_process_coef_fw(codec, coef0225);
5076 + snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
5077 + break;
5078 }
5079 codec_dbg(codec, "Headset jack set to mic-in mode.\n");
5080 }
5081 @@ -3884,6 +3907,13 @@ static void alc_headset_mode_ctia(struct hda_codec *codec)
5082 WRITE_COEF(0xc3, 0x0000),
5083 {}
5084 };
5085 + static struct coef_fw coef0225[] = {
5086 + UPDATE_COEF(0x45, 0x3f<<10, 0x35<<10),
5087 + UPDATE_COEF(0x49, 1<<8, 1<<8),
5088 + UPDATE_COEF(0x4a, 7<<6, 7<<6),
5089 + UPDATE_COEF(0x4a, 3<<4, 3<<4),
5090 + {}
5091 + };
5092
5093 switch (codec->core.vendor_id) {
5094 case 0x10ec0255:
5095 @@ -3912,6 +3942,9 @@ static void alc_headset_mode_ctia(struct hda_codec *codec)
5096 case 0x10ec0668:
5097 alc_process_coef_fw(codec, coef0688);
5098 break;
5099 + case 0x10ec0225:
5100 + alc_process_coef_fw(codec, coef0225);
5101 + break;
5102 }
5103 codec_dbg(codec, "Headset jack set to iPhone-style headset mode.\n");
5104 }
5105 @@ -3955,6 +3988,13 @@ static void alc_headset_mode_omtp(struct hda_codec *codec)
5106 WRITE_COEF(0xc3, 0x0000),
5107 {}
5108 };
5109 + static struct coef_fw coef0225[] = {
5110 + UPDATE_COEF(0x45, 0x3f<<10, 0x39<<10),
5111 + UPDATE_COEF(0x49, 1<<8, 1<<8),
5112 + UPDATE_COEF(0x4a, 7<<6, 7<<6),
5113 + UPDATE_COEF(0x4a, 3<<4, 3<<4),
5114 + {}
5115 + };
5116
5117 switch (codec->core.vendor_id) {
5118 case 0x10ec0255:
5119 @@ -3983,6 +4023,9 @@ static void alc_headset_mode_omtp(struct hda_codec *codec)
5120 case 0x10ec0668:
5121 alc_process_coef_fw(codec, coef0688);
5122 break;
5123 + case 0x10ec0225:
5124 + alc_process_coef_fw(codec, coef0225);
5125 + break;
5126 }
5127 codec_dbg(codec, "Headset jack set to Nokia-style headset mode.\n");
5128 }
5129 @@ -4014,6 +4057,11 @@ static void alc_determine_headset_type(struct hda_codec *codec)
5130 WRITE_COEF(0xc3, 0x0c00),
5131 {}
5132 };
5133 + static struct coef_fw coef0225[] = {
5134 + UPDATE_COEF(0x45, 0x3f<<10, 0x34<<10),
5135 + UPDATE_COEF(0x49, 1<<8, 1<<8),
5136 + {}
5137 + };
5138
5139 switch (codec->core.vendor_id) {
5140 case 0x10ec0255:
5141 @@ -4058,6 +4106,12 @@ static void alc_determine_headset_type(struct hda_codec *codec)
5142 val = alc_read_coef_idx(codec, 0xbe);
5143 is_ctia = (val & 0x1c02) == 0x1c02;
5144 break;
5145 + case 0x10ec0225:
5146 + alc_process_coef_fw(codec, coef0225);
5147 + msleep(800);
5148 + val = alc_read_coef_idx(codec, 0x46);
5149 + is_ctia = (val & 0x00f0) == 0x00f0;
5150 + break;
5151 }
5152
5153 codec_dbg(codec, "Headset jack detected iPhone-style headset: %s\n",
5154 @@ -5560,6 +5614,9 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
5155 {.id = ALC292_FIXUP_TPT440, .name = "tpt440"},
5156 {}
5157 };
5158 +#define ALC225_STANDARD_PINS \
5159 + {0x12, 0xb7a60130}, \
5160 + {0x21, 0x04211020}
5161
5162 #define ALC256_STANDARD_PINS \
5163 {0x12, 0x90a60140}, \
5164 @@ -5581,6 +5638,12 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
5165 {0x21, 0x03211020}
5166
5167 static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
5168 + SND_HDA_PIN_QUIRK(0x10ec0225, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
5169 + ALC225_STANDARD_PINS,
5170 + {0x14, 0x901701a0}),
5171 + SND_HDA_PIN_QUIRK(0x10ec0225, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
5172 + ALC225_STANDARD_PINS,
5173 + {0x14, 0x901701b0}),
5174 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE,
5175 {0x14, 0x90170110},
5176 {0x21, 0x02211020}),
5177 @@ -5906,6 +5969,9 @@ static int patch_alc269(struct hda_codec *codec)
5178 spec->gen.mixer_nid = 0; /* ALC256 does not have any loopback mixer path */
5179 alc_update_coef_idx(codec, 0x36, 1 << 13, 1 << 5); /* Switch pcbeep path to Line in path*/
5180 break;
5181 + case 0x10ec0225:
5182 + spec->codec_variant = ALC269_TYPE_ALC225;
5183 + break;
5184 }
5185
5186 if (snd_hda_codec_read(codec, 0x51, 0, AC_VERB_PARAMETERS, 0) == 0x10ec5505) {
5187 @@ -6796,6 +6862,7 @@ static int patch_alc680(struct hda_codec *codec)
5188 */
5189 static const struct hda_device_id snd_hda_id_realtek[] = {
5190 HDA_CODEC_ENTRY(0x10ec0221, "ALC221", patch_alc269),
5191 + HDA_CODEC_ENTRY(0x10ec0225, "ALC225", patch_alc269),
5192 HDA_CODEC_ENTRY(0x10ec0231, "ALC231", patch_alc269),
5193 HDA_CODEC_ENTRY(0x10ec0233, "ALC233", patch_alc269),
5194 HDA_CODEC_ENTRY(0x10ec0235, "ALC233", patch_alc269),
5195 diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
5196 index 2c7c5eb8b1e9..37b70f8e878f 100644
5197 --- a/sound/pci/hda/patch_sigmatel.c
5198 +++ b/sound/pci/hda/patch_sigmatel.c
5199 @@ -493,9 +493,9 @@ static void jack_update_power(struct hda_codec *codec,
5200 if (!spec->num_pwrs)
5201 return;
5202
5203 - if (jack && jack->tbl->nid) {
5204 - stac_toggle_power_map(codec, jack->tbl->nid,
5205 - snd_hda_jack_detect(codec, jack->tbl->nid),
5206 + if (jack && jack->nid) {
5207 + stac_toggle_power_map(codec, jack->nid,
5208 + snd_hda_jack_detect(codec, jack->nid),
5209 true);
5210 return;
5211 }
5212 diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
5213 index 3e3c7f6be29d..b74840b5becf 100644
5214 --- a/sound/soc/codecs/rt5645.c
5215 +++ b/sound/soc/codecs/rt5645.c
5216 @@ -621,7 +621,7 @@ static const struct snd_kcontrol_new rt5645_snd_controls[] = {
5217
5218 /* IN1/IN2 Control */
5219 SOC_SINGLE_TLV("IN1 Boost", RT5645_IN1_CTRL1,
5220 - RT5645_BST_SFT1, 8, 0, bst_tlv),
5221 + RT5645_BST_SFT1, 12, 0, bst_tlv),
5222 SOC_SINGLE_TLV("IN2 Boost", RT5645_IN2_CTRL,
5223 RT5645_BST_SFT2, 8, 0, bst_tlv),
5224
5225 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
5226 index c86dc96e8986..65b936e251ea 100644
5227 --- a/sound/soc/soc-pcm.c
5228 +++ b/sound/soc/soc-pcm.c
5229 @@ -1743,7 +1743,8 @@ int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
5230 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
5231 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
5232 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) &&
5233 - (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
5234 + (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
5235 + (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
5236 continue;
5237
5238 dev_dbg(be->dev, "ASoC: hw_free BE %s\n",
5239 diff --git a/sound/sparc/Kconfig b/sound/sparc/Kconfig
5240 index d75deba5617d..dfcd38647606 100644
5241 --- a/sound/sparc/Kconfig
5242 +++ b/sound/sparc/Kconfig
5243 @@ -22,6 +22,7 @@ config SND_SUN_AMD7930
5244 config SND_SUN_CS4231
5245 tristate "Sun CS4231"
5246 select SND_PCM
5247 + select SND_TIMER
5248 help
5249 Say Y here to include support for CS4231 sound device on Sun.
5250
5251 diff --git a/sound/usb/midi.c b/sound/usb/midi.c
5252 index 5b4c58c3e2c5..b21b76690b31 100644
5253 --- a/sound/usb/midi.c
5254 +++ b/sound/usb/midi.c
5255 @@ -2454,7 +2454,6 @@ int snd_usbmidi_create(struct snd_card *card,
5256 else
5257 err = snd_usbmidi_create_endpoints(umidi, endpoints);
5258 if (err < 0) {
5259 - snd_usbmidi_free(umidi);
5260 return err;
5261 }
5262
5263 diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
5264 index 23ea6d800c4c..4f6ce1cac8e2 100644
5265 --- a/sound/usb/quirks.c
5266 +++ b/sound/usb/quirks.c
5267 @@ -1121,6 +1121,7 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
5268 switch (chip->usb_id) {
5269 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */
5270 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */
5271 + case USB_ID(0x045E, 0x076F): /* MS Lifecam HD-6000 */
5272 case USB_ID(0x045E, 0x0772): /* MS Lifecam Studio */
5273 case USB_ID(0x045E, 0x0779): /* MS Lifecam HD-3000 */
5274 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
5275 @@ -1205,8 +1206,12 @@ void snd_usb_set_interface_quirk(struct usb_device *dev)
5276 * "Playback Design" products need a 50ms delay after setting the
5277 * USB interface.
5278 */
5279 - if (le16_to_cpu(dev->descriptor.idVendor) == 0x23ba)
5280 + switch (le16_to_cpu(dev->descriptor.idVendor)) {
5281 + case 0x23ba: /* Playback Design */
5282 + case 0x0644: /* TEAC Corp. */
5283 mdelay(50);
5284 + break;
5285 + }
5286 }
5287
5288 void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
5289 @@ -1221,6 +1226,14 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
5290 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
5291 mdelay(20);
5292
5293 + /*
5294 + * "TEAC Corp." products need a 20ms delay after each
5295 + * class compliant request
5296 + */
5297 + if ((le16_to_cpu(dev->descriptor.idVendor) == 0x0644) &&
5298 + (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
5299 + mdelay(20);
5300 +
5301 /* Marantz/Denon devices with USB DAC functionality need a delay
5302 * after each class compliant request
5303 */
5304 @@ -1269,7 +1282,7 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
5305 case USB_ID(0x20b1, 0x3008): /* iFi Audio micro/nano iDSD */
5306 case USB_ID(0x20b1, 0x2008): /* Matrix Audio X-Sabre */
5307 case USB_ID(0x20b1, 0x300a): /* Matrix Audio Mini-i Pro */
5308 - case USB_ID(0x22d8, 0x0416): /* OPPO HA-1*/
5309 + case USB_ID(0x22d9, 0x0416): /* OPPO HA-1 */
5310 if (fp->altsetting == 2)
5311 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
5312 break;
5313 @@ -1278,6 +1291,7 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
5314 case USB_ID(0x20b1, 0x2009): /* DIYINHK DSD DXD 384kHz USB to I2S/DSD */
5315 case USB_ID(0x20b1, 0x2023): /* JLsounds I2SoverUSB */
5316 case USB_ID(0x20b1, 0x3023): /* Aune X1S 32BIT/384 DSD DAC */
5317 + case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */
5318 if (fp->altsetting == 3)
5319 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
5320 break;