Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.9 commit in: /
Date: Thu, 17 Oct 2019 22:21:10
Message-Id: 1571350849.398f49b48283feeacc2e0ed33dc6951e0978ada1.mpagano@gentoo
1 commit: 398f49b48283feeacc2e0ed33dc6951e0978ada1
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Thu Oct 17 22:20:49 2019 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Thu Oct 17 22:20:49 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=398f49b4
7
8 Linux patch 4.9.197
9
10 Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>
11
12 0000_README | 4 +
13 1196_linux-4.9.197.patch | 3881 ++++++++++++++++++++++++++++++++++++++++++++++
14 2 files changed, 3885 insertions(+)
15
16 diff --git a/0000_README b/0000_README
17 index f84136e..e071b11 100644
18 --- a/0000_README
19 +++ b/0000_README
20 @@ -827,6 +827,10 @@ Patch: 1195_linux-4.9.196.patch
21 From: http://www.kernel.org
22 Desc: Linux 4.9.196
23
24 +Patch: 1196_linux-4.9.197.patch
25 +From: http://www.kernel.org
26 +Desc: Linux 4.9.197
27 +
28 Patch: 1500_XATTR_USER_PREFIX.patch
29 From: https://bugs.gentoo.org/show_bug.cgi?id=470644
30 Desc: Support for namespace user.pax.* on tmpfs.
31
32 diff --git a/1196_linux-4.9.197.patch b/1196_linux-4.9.197.patch
33 new file mode 100644
34 index 0000000..887973d
35 --- /dev/null
36 +++ b/1196_linux-4.9.197.patch
37 @@ -0,0 +1,3881 @@
38 +diff --git a/Documentation/usb/rio.txt b/Documentation/usb/rio.txt
39 +deleted file mode 100644
40 +index aee715af7db7..000000000000
41 +--- a/Documentation/usb/rio.txt
42 ++++ /dev/null
43 +@@ -1,138 +0,0 @@
44 +-Copyright (C) 1999, 2000 Bruce Tenison
45 +-Portions Copyright (C) 1999, 2000 David Nelson
46 +-Thanks to David Nelson for guidance and the usage of the scanner.txt
47 +-and scanner.c files to model our driver and this informative file.
48 +-
49 +-Mar. 2, 2000
50 +-
51 +-CHANGES
52 +-
53 +-- Initial Revision
54 +-
55 +-
56 +-OVERVIEW
57 +-
58 +-This README will address issues regarding how to configure the kernel
59 +-to access a RIO 500 mp3 player.
60 +-Before I explain how to use this to access the Rio500 please be warned:
61 +-
62 +-W A R N I N G:
63 +---------------
64 +-
65 +-Please note that this software is still under development. The authors
66 +-are in no way responsible for any damage that may occur, no matter how
67 +-inconsequential.
68 +-
69 +-It seems that the Rio has a problem when sending .mp3 with low batteries.
70 +-I suggest when the batteries are low and you want to transfer stuff that you
71 +-replace it with a fresh one. In my case, what happened is I lost two 16kb
72 +-blocks (they are no longer usable to store information to it). But I don't
73 +-know if that's normal or not; it could simply be a problem with the flash
74 +-memory.
75 +-
76 +-In an extreme case, I left my Rio playing overnight and the batteries wore
77 +-down to nothing and appear to have corrupted the flash memory. My RIO
78 +-needed to be replaced as a result. Diamond tech support is aware of the
79 +-problem. Do NOT allow your batteries to wear down to nothing before
80 +-changing them. It appears RIO 500 firmware does not handle low battery
81 +-power well at all.
82 +-
83 +-On systems with OHCI controllers, the kernel OHCI code appears to have
84 +-power on problems with some chipsets. If you are having problems
85 +-connecting to your RIO 500, try turning it on first and then plugging it
86 +-into the USB cable.
87 +-
88 +-Contact information:
89 +---------------------
90 +-
91 +- The main page for the project is hosted at sourceforge.net in the following
92 +- URL: <http://rio500.sourceforge.net>. You can also go to the project's
93 +- sourceforge home page at: <http://sourceforge.net/projects/rio500/>.
94 +- There is also a mailing list: rio500-users@×××××××××××××××××.net
95 +-
96 +-Authors:
97 +--------
98 +-
99 +-Most of the code was written by Cesar Miquel <miquel@××××××.ar>. Keith
100 +-Clayton <kclayton@×××.net> is incharge of the PPC port and making sure
101 +-things work there. Bruce Tenison <btenison@×××××.net> is adding support
102 +-for .fon files and also does testing. The program will mostly sure be
103 +-re-written and Pete Ikusz along with the rest will re-design it. I would
104 +-also like to thank Tri Nguyen <tmn_3022000@×××××××.com> who provided use
105 +-with some important information regarding the communication with the Rio.
106 +-
107 +-ADDITIONAL INFORMATION and Userspace tools
108 +-
109 +-http://rio500.sourceforge.net/
110 +-
111 +-
112 +-REQUIREMENTS
113 +-
114 +-A host with a USB port. Ideally, either a UHCI (Intel) or OHCI
115 +-(Compaq and others) hardware port should work.
116 +-
117 +-A Linux development kernel (2.3.x) with USB support enabled or a
118 +-backported version to linux-2.2.x. See http://www.linux-usb.org for
119 +-more information on accomplishing this.
120 +-
121 +-A Linux kernel with RIO 500 support enabled.
122 +-
123 +-'lspci' which is only needed to determine the type of USB hardware
124 +-available in your machine.
125 +-
126 +-CONFIGURATION
127 +-
128 +-Using `lspci -v`, determine the type of USB hardware available.
129 +-
130 +- If you see something like:
131 +-
132 +- USB Controller: ......
133 +- Flags: .....
134 +- I/O ports at ....
135 +-
136 +- Then you have a UHCI based controller.
137 +-
138 +- If you see something like:
139 +-
140 +- USB Controller: .....
141 +- Flags: ....
142 +- Memory at .....
143 +-
144 +- Then you have a OHCI based controller.
145 +-
146 +-Using `make menuconfig` or your preferred method for configuring the
147 +-kernel, select 'Support for USB', 'OHCI/UHCI' depending on your
148 +-hardware (determined from the steps above), 'USB Diamond Rio500 support', and
149 +-'Preliminary USB device filesystem'. Compile and install the modules
150 +-(you may need to execute `depmod -a` to update the module
151 +-dependencies).
152 +-
153 +-Add a device for the USB rio500:
154 +- `mknod /dev/usb/rio500 c 180 64`
155 +-
156 +-Set appropriate permissions for /dev/usb/rio500 (don't forget about
157 +-group and world permissions). Both read and write permissions are
158 +-required for proper operation.
159 +-
160 +-Load the appropriate modules (if compiled as modules):
161 +-
162 +- OHCI:
163 +- modprobe usbcore
164 +- modprobe usb-ohci
165 +- modprobe rio500
166 +-
167 +- UHCI:
168 +- modprobe usbcore
169 +- modprobe usb-uhci (or uhci)
170 +- modprobe rio500
171 +-
172 +-That's it. The Rio500 Utils at: http://rio500.sourceforge.net should
173 +-be able to access the rio500.
174 +-
175 +-BUGS
176 +-
177 +-If you encounter any problems feel free to drop me an email.
178 +-
179 +-Bruce Tenison
180 +-btenison@×××××.net
181 +-
182 +diff --git a/MAINTAINERS b/MAINTAINERS
183 +index 98ee40591a9b..fcaab221553e 100644
184 +--- a/MAINTAINERS
185 ++++ b/MAINTAINERS
186 +@@ -12473,13 +12473,6 @@ W: http://www.linux-usb.org/usbnet
187 + S: Maintained
188 + F: drivers/net/usb/dm9601.c
189 +
190 +-USB DIAMOND RIO500 DRIVER
191 +-M: Cesar Miquel <miquel@××××××.ar>
192 +-L: rio500-users@×××××××××××××××××.net
193 +-W: http://rio500.sourceforge.net
194 +-S: Maintained
195 +-F: drivers/usb/misc/rio500*
196 +-
197 + USB EHCI DRIVER
198 + M: Alan Stern <stern@×××××××××××××××.edu>
199 + L: linux-usb@×××××××××××.org
200 +diff --git a/Makefile b/Makefile
201 +index 194c35eff19c..e62456010d34 100644
202 +--- a/Makefile
203 ++++ b/Makefile
204 +@@ -1,6 +1,6 @@
205 + VERSION = 4
206 + PATCHLEVEL = 9
207 +-SUBLEVEL = 196
208 ++SUBLEVEL = 197
209 + EXTRAVERSION =
210 + NAME = Roaring Lionus
211 +
212 +diff --git a/arch/arm/configs/badge4_defconfig b/arch/arm/configs/badge4_defconfig
213 +index d59009878312..067d73e3b28b 100644
214 +--- a/arch/arm/configs/badge4_defconfig
215 ++++ b/arch/arm/configs/badge4_defconfig
216 +@@ -97,7 +97,6 @@ CONFIG_USB_SERIAL_PL2303=m
217 + CONFIG_USB_SERIAL_CYBERJACK=m
218 + CONFIG_USB_SERIAL_XIRCOM=m
219 + CONFIG_USB_SERIAL_OMNINET=m
220 +-CONFIG_USB_RIO500=m
221 + CONFIG_EXT2_FS=m
222 + CONFIG_EXT3_FS=m
223 + CONFIG_MSDOS_FS=y
224 +diff --git a/arch/arm/configs/corgi_defconfig b/arch/arm/configs/corgi_defconfig
225 +index c1470a00f55a..031d9d3549b9 100644
226 +--- a/arch/arm/configs/corgi_defconfig
227 ++++ b/arch/arm/configs/corgi_defconfig
228 +@@ -207,7 +207,6 @@ CONFIG_USB_SERIAL_XIRCOM=m
229 + CONFIG_USB_SERIAL_OMNINET=m
230 + CONFIG_USB_EMI62=m
231 + CONFIG_USB_EMI26=m
232 +-CONFIG_USB_RIO500=m
233 + CONFIG_USB_LEGOTOWER=m
234 + CONFIG_USB_LCD=m
235 + CONFIG_USB_LED=m
236 +diff --git a/arch/arm/configs/pxa_defconfig b/arch/arm/configs/pxa_defconfig
237 +index a016ecc0084b..178ee84dffa1 100644
238 +--- a/arch/arm/configs/pxa_defconfig
239 ++++ b/arch/arm/configs/pxa_defconfig
240 +@@ -591,7 +591,6 @@ CONFIG_USB_SERIAL_XIRCOM=m
241 + CONFIG_USB_SERIAL_OMNINET=m
242 + CONFIG_USB_EMI62=m
243 + CONFIG_USB_EMI26=m
244 +-CONFIG_USB_RIO500=m
245 + CONFIG_USB_LEGOTOWER=m
246 + CONFIG_USB_LCD=m
247 + CONFIG_USB_LED=m
248 +diff --git a/arch/arm/configs/s3c2410_defconfig b/arch/arm/configs/s3c2410_defconfig
249 +index 60d3fecd7a22..dc873d23d603 100644
250 +--- a/arch/arm/configs/s3c2410_defconfig
251 ++++ b/arch/arm/configs/s3c2410_defconfig
252 +@@ -354,7 +354,6 @@ CONFIG_USB_EMI62=m
253 + CONFIG_USB_EMI26=m
254 + CONFIG_USB_ADUTUX=m
255 + CONFIG_USB_SEVSEG=m
256 +-CONFIG_USB_RIO500=m
257 + CONFIG_USB_LEGOTOWER=m
258 + CONFIG_USB_LCD=m
259 + CONFIG_USB_LED=m
260 +diff --git a/arch/arm/configs/spitz_defconfig b/arch/arm/configs/spitz_defconfig
261 +index a1ede1966baf..7d9aa284cb6f 100644
262 +--- a/arch/arm/configs/spitz_defconfig
263 ++++ b/arch/arm/configs/spitz_defconfig
264 +@@ -202,7 +202,6 @@ CONFIG_USB_SERIAL_XIRCOM=m
265 + CONFIG_USB_SERIAL_OMNINET=m
266 + CONFIG_USB_EMI62=m
267 + CONFIG_USB_EMI26=m
268 +-CONFIG_USB_RIO500=m
269 + CONFIG_USB_LEGOTOWER=m
270 + CONFIG_USB_LCD=m
271 + CONFIG_USB_LED=m
272 +diff --git a/arch/mips/configs/mtx1_defconfig b/arch/mips/configs/mtx1_defconfig
273 +index f3f60056bc27..fb5651b99ab2 100644
274 +--- a/arch/mips/configs/mtx1_defconfig
275 ++++ b/arch/mips/configs/mtx1_defconfig
276 +@@ -637,7 +637,6 @@ CONFIG_USB_SERIAL_OMNINET=m
277 + CONFIG_USB_EMI62=m
278 + CONFIG_USB_EMI26=m
279 + CONFIG_USB_ADUTUX=m
280 +-CONFIG_USB_RIO500=m
281 + CONFIG_USB_LEGOTOWER=m
282 + CONFIG_USB_LCD=m
283 + CONFIG_USB_LED=m
284 +diff --git a/arch/mips/configs/rm200_defconfig b/arch/mips/configs/rm200_defconfig
285 +index c2b4e3f33a73..4f6b45f64c2f 100644
286 +--- a/arch/mips/configs/rm200_defconfig
287 ++++ b/arch/mips/configs/rm200_defconfig
288 +@@ -350,7 +350,6 @@ CONFIG_USB_SERIAL_SAFE_PADDED=y
289 + CONFIG_USB_SERIAL_CYBERJACK=m
290 + CONFIG_USB_SERIAL_XIRCOM=m
291 + CONFIG_USB_SERIAL_OMNINET=m
292 +-CONFIG_USB_RIO500=m
293 + CONFIG_USB_LEGOTOWER=m
294 + CONFIG_USB_LCD=m
295 + CONFIG_USB_LED=m
296 +diff --git a/arch/mips/loongson64/Platform b/arch/mips/loongson64/Platform
297 +index 0fce4608aa88..12abf14aed4a 100644
298 +--- a/arch/mips/loongson64/Platform
299 ++++ b/arch/mips/loongson64/Platform
300 +@@ -43,6 +43,10 @@ else
301 + $(call cc-option,-march=mips64r2,-mips64r2 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS64)
302 + endif
303 +
304 ++# Some -march= flags enable MMI instructions, and GCC complains about that
305 ++# support being enabled alongside -msoft-float. Thus explicitly disable MMI.
306 ++cflags-y += $(call cc-option,-mno-loongson-mmi)
307 ++
308 + #
309 + # Loongson Machines' Support
310 + #
311 +diff --git a/arch/mips/vdso/Makefile b/arch/mips/vdso/Makefile
312 +index 247ca2e9add9..adfaee2dce34 100644
313 +--- a/arch/mips/vdso/Makefile
314 ++++ b/arch/mips/vdso/Makefile
315 +@@ -8,6 +8,7 @@ ccflags-vdso := \
316 + $(filter -mmicromips,$(KBUILD_CFLAGS)) \
317 + $(filter -march=%,$(KBUILD_CFLAGS)) \
318 + $(filter -m%-float,$(KBUILD_CFLAGS)) \
319 ++ $(filter -mno-loongson-%,$(KBUILD_CFLAGS)) \
320 + -D__VDSO__
321 + cflags-vdso := $(ccflags-vdso) \
322 + $(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) \
323 +diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
324 +index 7fb61ebc99a2..c34a44e04c87 100644
325 +--- a/arch/powerpc/platforms/powernv/opal.c
326 ++++ b/arch/powerpc/platforms/powernv/opal.c
327 +@@ -579,7 +579,10 @@ static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj,
328 + bin_attr->size);
329 + }
330 +
331 +-static BIN_ATTR_RO(symbol_map, 0);
332 ++static struct bin_attribute symbol_map_attr = {
333 ++ .attr = {.name = "symbol_map", .mode = 0400},
334 ++ .read = symbol_map_read
335 ++};
336 +
337 + static void opal_export_symmap(void)
338 + {
339 +@@ -596,10 +599,10 @@ static void opal_export_symmap(void)
340 + return;
341 +
342 + /* Setup attributes */
343 +- bin_attr_symbol_map.private = __va(be64_to_cpu(syms[0]));
344 +- bin_attr_symbol_map.size = be64_to_cpu(syms[1]);
345 ++ symbol_map_attr.private = __va(be64_to_cpu(syms[0]));
346 ++ symbol_map_attr.size = be64_to_cpu(syms[1]);
347 +
348 +- rc = sysfs_create_bin_file(opal_kobj, &bin_attr_symbol_map);
349 ++ rc = sysfs_create_bin_file(opal_kobj, &symbol_map_attr);
350 + if (rc)
351 + pr_warn("Error %d creating OPAL symbols file\n", rc);
352 + }
353 +diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
354 +index 239f29508f0b..69ac47241b19 100644
355 +--- a/arch/s390/kernel/topology.c
356 ++++ b/arch/s390/kernel/topology.c
357 +@@ -256,7 +256,8 @@ int arch_update_cpu_topology(void)
358 + topology_update_polarization_simple();
359 + for_each_online_cpu(cpu) {
360 + dev = get_cpu_device(cpu);
361 +- kobject_uevent(&dev->kobj, KOBJ_CHANGE);
362 ++ if (dev)
363 ++ kobject_uevent(&dev->kobj, KOBJ_CHANGE);
364 + }
365 + return rc;
366 + }
367 +diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
368 +index ea20b60edde7..3dc96b455e0c 100644
369 +--- a/arch/s390/kvm/kvm-s390.c
370 ++++ b/arch/s390/kvm/kvm-s390.c
371 +@@ -3033,7 +3033,7 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu,
372 + const u64 supported_flags = KVM_S390_MEMOP_F_INJECT_EXCEPTION
373 + | KVM_S390_MEMOP_F_CHECK_ONLY;
374 +
375 +- if (mop->flags & ~supported_flags)
376 ++ if (mop->flags & ~supported_flags || mop->ar >= NUM_ACRS || !mop->size)
377 + return -EINVAL;
378 +
379 + if (mop->size > MEM_OP_MAX_SIZE)
380 +diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
381 +index 0b40cc442bda..58b1b766e84e 100644
382 +--- a/arch/x86/include/asm/mwait.h
383 ++++ b/arch/x86/include/asm/mwait.h
384 +@@ -19,7 +19,7 @@
385 + #define MWAIT_ECX_INTERRUPT_BREAK 0x1
386 + #define MWAITX_ECX_TIMER_ENABLE BIT(1)
387 + #define MWAITX_MAX_LOOPS ((u32)-1)
388 +-#define MWAITX_DISABLE_CSTATES 0xf
389 ++#define MWAITX_DISABLE_CSTATES 0xf0
390 +
391 + static inline void __monitor(const void *eax, unsigned long ecx,
392 + unsigned long edx)
393 +diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
394 +index 7ab13ad53a59..6b66d1f0d185 100644
395 +--- a/arch/x86/kvm/vmx.c
396 ++++ b/arch/x86/kvm/vmx.c
397 +@@ -7668,7 +7668,7 @@ static int handle_vmread(struct kvm_vcpu *vcpu)
398 + /* _system ok, as nested_vmx_check_permission verified cpl=0 */
399 + if (kvm_write_guest_virt_system(vcpu, gva, &field_value,
400 + (is_long_mode(vcpu) ? 8 : 4),
401 +- NULL))
402 ++ &e))
403 + kvm_inject_page_fault(vcpu, &e);
404 + }
405 +
406 +diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
407 +index 9758524ee99f..71a3759a2d4e 100644
408 +--- a/arch/x86/lib/delay.c
409 ++++ b/arch/x86/lib/delay.c
410 +@@ -112,8 +112,8 @@ static void delay_mwaitx(unsigned long __loops)
411 + __monitorx(raw_cpu_ptr(&cpu_tss), 0, 0);
412 +
413 + /*
414 +- * AMD, like Intel, supports the EAX hint and EAX=0xf
415 +- * means, do not enter any deep C-state and we use it
416 ++ * AMD, like Intel's MWAIT version, supports the EAX hint and
417 ++ * EAX=0xf0 means, do not enter any deep C-state and we use it
418 + * here in delay() to minimize wakeup latency.
419 + */
420 + __mwaitx(MWAITX_DISABLE_CSTATES, delay, MWAITX_ECX_TIMER_ENABLE);
421 +diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
422 +index f8ac768ed5d7..413e1f35773f 100644
423 +--- a/drivers/crypto/caam/caamalg.c
424 ++++ b/drivers/crypto/caam/caamalg.c
425 +@@ -75,7 +75,7 @@
426 + #define DESC_AEAD_BASE (4 * CAAM_CMD_SZ)
427 + #define DESC_AEAD_ENC_LEN (DESC_AEAD_BASE + 11 * CAAM_CMD_SZ)
428 + #define DESC_AEAD_DEC_LEN (DESC_AEAD_BASE + 15 * CAAM_CMD_SZ)
429 +-#define DESC_AEAD_GIVENC_LEN (DESC_AEAD_ENC_LEN + 9 * CAAM_CMD_SZ)
430 ++#define DESC_AEAD_GIVENC_LEN (DESC_AEAD_ENC_LEN + 10 * CAAM_CMD_SZ)
431 +
432 + /* Note: Nonce is counted in enckeylen */
433 + #define DESC_AEAD_CTR_RFC3686_LEN (4 * CAAM_CMD_SZ)
434 +@@ -474,6 +474,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead)
435 + u32 geniv, moveiv;
436 + u32 ctx1_iv_off = 0;
437 + u32 *desc;
438 ++ u32 *wait_cmd;
439 + const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
440 + OP_ALG_AAI_CTR_MOD128);
441 + const bool is_rfc3686 = alg->caam.rfc3686;
442 +@@ -736,6 +737,14 @@ copy_iv:
443 +
444 + /* Will read cryptlen */
445 + append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
446 ++
447 ++ /*
448 ++ * Wait for IV transfer (ofifo -> class2) to finish before starting
449 ++ * ciphertext transfer (ofifo -> external memory).
450 ++ */
451 ++ wait_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | JUMP_COND_NIFP);
452 ++ set_jump_tgt_here(desc, wait_cmd);
453 ++
454 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | KEY_VLF |
455 + FIFOLD_TYPE_MSG1OUT2 | FIFOLD_TYPE_LASTBOTH);
456 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
457 +diff --git a/drivers/crypto/qat/qat_common/adf_common_drv.h b/drivers/crypto/qat/qat_common/adf_common_drv.h
458 +index 980e07475012..0d596a99f564 100644
459 +--- a/drivers/crypto/qat/qat_common/adf_common_drv.h
460 ++++ b/drivers/crypto/qat/qat_common/adf_common_drv.h
461 +@@ -95,7 +95,7 @@ struct service_hndl {
462 +
463 + static inline int get_current_node(void)
464 + {
465 +- return topology_physical_package_id(smp_processor_id());
466 ++ return topology_physical_package_id(raw_smp_processor_id());
467 + }
468 +
469 + int adf_service_register(struct service_hndl *service);
470 +diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
471 +index 2f47c5b5f4cb..d89457d62a24 100644
472 +--- a/drivers/firmware/efi/efi.c
473 ++++ b/drivers/firmware/efi/efi.c
474 +@@ -243,6 +243,9 @@ static __init int efivar_ssdt_load(void)
475 + void *data;
476 + int ret;
477 +
478 ++ if (!efivar_ssdt[0])
479 ++ return 0;
480 ++
481 + ret = efivar_init(efivar_ssdt_iter, &entries, true, &entries);
482 +
483 + list_for_each_entry_safe(entry, aux, &entries, list) {
484 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
485 +index 3938fca1ea8e..24941a7b659f 100644
486 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
487 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
488 +@@ -430,6 +430,9 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
489 + if (sh_num == AMDGPU_INFO_MMR_SH_INDEX_MASK)
490 + sh_num = 0xffffffff;
491 +
492 ++ if (info->read_mmr_reg.count > 128)
493 ++ return -EINVAL;
494 ++
495 + regs = kmalloc_array(info->read_mmr_reg.count, sizeof(*regs), GFP_KERNEL);
496 + if (!regs)
497 + return -ENOMEM;
498 +diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c
499 +index da27f8edba50..44d6c29e2644 100644
500 +--- a/drivers/hwtracing/coresight/coresight-etm4x.c
501 ++++ b/drivers/hwtracing/coresight/coresight-etm4x.c
502 +@@ -181,6 +181,12 @@ static void etm4_enable_hw(void *info)
503 + if (coresight_timeout(drvdata->base, TRCSTATR, TRCSTATR_IDLE_BIT, 0))
504 + dev_err(drvdata->dev,
505 + "timeout while waiting for Idle Trace Status\n");
506 ++ /*
507 ++ * As recommended by section 4.3.7 ("Synchronization when using the
508 ++ * memory-mapped interface") of ARM IHI 0064D
509 ++ */
510 ++ dsb(sy);
511 ++ isb();
512 +
513 + CS_LOCK(drvdata->base);
514 +
515 +@@ -323,8 +329,12 @@ static void etm4_disable_hw(void *info)
516 + /* EN, bit[0] Trace unit enable bit */
517 + control &= ~0x1;
518 +
519 +- /* make sure everything completes before disabling */
520 +- mb();
521 ++ /*
522 ++ * Make sure everything completes before disabling, as recommended
523 ++ * by section 7.3.77 ("TRCVICTLR, ViewInst Main Control Register,
524 ++ * SSTATUS") of ARM IHI 0064D
525 ++ */
526 ++ dsb(sy);
527 + isb();
528 + writel_relaxed(control, drvdata->base + TRCPRGCTLR);
529 +
530 +diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
531 +index 9704090b7908..cd6dbe95125b 100644
532 +--- a/drivers/iio/adc/ad799x.c
533 ++++ b/drivers/iio/adc/ad799x.c
534 +@@ -817,10 +817,10 @@ static int ad799x_probe(struct i2c_client *client,
535 +
536 + ret = ad799x_write_config(st, st->chip_config->default_config);
537 + if (ret < 0)
538 +- goto error_disable_reg;
539 ++ goto error_disable_vref;
540 + ret = ad799x_read_config(st);
541 + if (ret < 0)
542 +- goto error_disable_reg;
543 ++ goto error_disable_vref;
544 + st->config = ret;
545 +
546 + ret = iio_triggered_buffer_setup(indio_dev, NULL,
547 +diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
548 +index 78c9b3a6453a..be55477de2ac 100644
549 +--- a/drivers/iio/light/opt3001.c
550 ++++ b/drivers/iio/light/opt3001.c
551 +@@ -695,6 +695,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
552 + struct iio_dev *iio = _iio;
553 + struct opt3001 *opt = iio_priv(iio);
554 + int ret;
555 ++ bool wake_result_ready_queue = false;
556 +
557 + if (!opt->ok_to_ignore_lock)
558 + mutex_lock(&opt->lock);
559 +@@ -729,13 +730,16 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
560 + }
561 + opt->result = ret;
562 + opt->result_ready = true;
563 +- wake_up(&opt->result_ready_queue);
564 ++ wake_result_ready_queue = true;
565 + }
566 +
567 + out:
568 + if (!opt->ok_to_ignore_lock)
569 + mutex_unlock(&opt->lock);
570 +
571 ++ if (wake_result_ready_queue)
572 ++ wake_up(&opt->result_ready_queue);
573 ++
574 + return IRQ_HANDLED;
575 + }
576 +
577 +diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
578 +index 1c48f2f1e14a..7297fd261df9 100644
579 +--- a/drivers/media/usb/stkwebcam/stk-webcam.c
580 ++++ b/drivers/media/usb/stkwebcam/stk-webcam.c
581 +@@ -647,8 +647,7 @@ static int v4l_stk_release(struct file *fp)
582 + dev->owner = NULL;
583 + }
584 +
585 +- if (is_present(dev))
586 +- usb_autopm_put_interface(dev->interface);
587 ++ usb_autopm_put_interface(dev->interface);
588 + mutex_unlock(&dev->lock);
589 + return v4l2_fh_release(fp);
590 + }
591 +diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
592 +index d8c448beab24..ec0b3d025867 100644
593 +--- a/drivers/net/can/spi/mcp251x.c
594 ++++ b/drivers/net/can/spi/mcp251x.c
595 +@@ -627,7 +627,7 @@ static int mcp251x_setup(struct net_device *net, struct mcp251x_priv *priv,
596 + static int mcp251x_hw_reset(struct spi_device *spi)
597 + {
598 + struct mcp251x_priv *priv = spi_get_drvdata(spi);
599 +- u8 reg;
600 ++ unsigned long timeout;
601 + int ret;
602 +
603 + /* Wait for oscillator startup timer after power up */
604 +@@ -641,10 +641,19 @@ static int mcp251x_hw_reset(struct spi_device *spi)
605 + /* Wait for oscillator startup timer after reset */
606 + mdelay(MCP251X_OST_DELAY_MS);
607 +
608 +- reg = mcp251x_read_reg(spi, CANSTAT);
609 +- if ((reg & CANCTRL_REQOP_MASK) != CANCTRL_REQOP_CONF)
610 +- return -ENODEV;
611 +-
612 ++ /* Wait for reset to finish */
613 ++ timeout = jiffies + HZ;
614 ++ while ((mcp251x_read_reg(spi, CANSTAT) & CANCTRL_REQOP_MASK) !=
615 ++ CANCTRL_REQOP_CONF) {
616 ++ usleep_range(MCP251X_OST_DELAY_MS * 1000,
617 ++ MCP251X_OST_DELAY_MS * 1000 * 2);
618 ++
619 ++ if (time_after(jiffies, timeout)) {
620 ++ dev_err(&spi->dev,
621 ++ "MCP251x didn't enter in conf mode after reset\n");
622 ++ return -EBUSY;
623 ++ }
624 ++ }
625 + return 0;
626 + }
627 +
628 +diff --git a/drivers/net/ieee802154/atusb.c b/drivers/net/ieee802154/atusb.c
629 +index f186e0460cde..12df6cfb423a 100644
630 +--- a/drivers/net/ieee802154/atusb.c
631 ++++ b/drivers/net/ieee802154/atusb.c
632 +@@ -838,10 +838,11 @@ static void atusb_disconnect(struct usb_interface *interface)
633 +
634 + ieee802154_unregister_hw(atusb->hw);
635 +
636 ++ usb_put_dev(atusb->usb_dev);
637 ++
638 + ieee802154_free_hw(atusb->hw);
639 +
640 + usb_set_intfdata(interface, NULL);
641 +- usb_put_dev(atusb->usb_dev);
642 +
643 + pr_debug("atusb_disconnect done\n");
644 + }
645 +diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
646 +index e443b0d0b236..0d59c128f734 100644
647 +--- a/drivers/s390/cio/ccwgroup.c
648 ++++ b/drivers/s390/cio/ccwgroup.c
649 +@@ -369,7 +369,7 @@ int ccwgroup_create_dev(struct device *parent, struct ccwgroup_driver *gdrv,
650 + goto error;
651 + }
652 + /* Check for trailing stuff. */
653 +- if (i == num_devices && strlen(buf) > 0) {
654 ++ if (i == num_devices && buf && strlen(buf) > 0) {
655 + rc = -EINVAL;
656 + goto error;
657 + }
658 +diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
659 +index 3d2b20ee613f..39a2b0cde9e4 100644
660 +--- a/drivers/s390/cio/css.c
661 ++++ b/drivers/s390/cio/css.c
662 +@@ -1120,6 +1120,8 @@ device_initcall(cio_settle_init);
663 +
664 + int sch_is_pseudo_sch(struct subchannel *sch)
665 + {
666 ++ if (!sch->dev.parent)
667 ++ return 0;
668 + return sch == to_css(sch->dev.parent)->pseudo_subchannel;
669 + }
670 +
671 +diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
672 +index 587f68aa466c..d9ba8c0f1353 100644
673 +--- a/drivers/staging/fbtft/fbtft-core.c
674 ++++ b/drivers/staging/fbtft/fbtft-core.c
675 +@@ -247,7 +247,7 @@ static int fbtft_request_gpios_dt(struct fbtft_par *par)
676 + static int fbtft_backlight_update_status(struct backlight_device *bd)
677 + {
678 + struct fbtft_par *par = bl_get_data(bd);
679 +- bool polarity = !!(bd->props.state & BL_CORE_DRIVER1);
680 ++ bool polarity = par->polarity;
681 +
682 + fbtft_par_dbg(DEBUG_BACKLIGHT, par,
683 + "%s: polarity=%d, power=%d, fb_blank=%d\n",
684 +@@ -296,7 +296,7 @@ void fbtft_register_backlight(struct fbtft_par *par)
685 + /* Assume backlight is off, get polarity from current state of pin */
686 + bl_props.power = FB_BLANK_POWERDOWN;
687 + if (!gpio_get_value(par->gpio.led[0]))
688 +- bl_props.state |= BL_CORE_DRIVER1;
689 ++ par->polarity = true;
690 +
691 + bd = backlight_device_register(dev_driver_string(par->info->device),
692 + par->info->device, par, &fbtft_bl_ops, &bl_props);
693 +@@ -814,7 +814,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
694 + if (par->gamma.curves && gamma) {
695 + if (fbtft_gamma_parse_str(par,
696 + par->gamma.curves, gamma, strlen(gamma)))
697 +- goto alloc_fail;
698 ++ goto release_framebuf;
699 + }
700 +
701 + /* Transmit buffer */
702 +@@ -839,7 +839,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
703 + txbuf = devm_kzalloc(par->info->device, txbuflen, GFP_KERNEL);
704 + }
705 + if (!txbuf)
706 +- goto alloc_fail;
707 ++ goto release_framebuf;
708 + par->txbuf.buf = txbuf;
709 + par->txbuf.len = txbuflen;
710 + }
711 +@@ -875,6 +875,9 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
712 +
713 + return info;
714 +
715 ++release_framebuf:
716 ++ framebuffer_release(info);
717 ++
718 + alloc_fail:
719 + vfree(vmem);
720 +
721 +diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h
722 +index 89c4b5b76ce6..027531990674 100644
723 +--- a/drivers/staging/fbtft/fbtft.h
724 ++++ b/drivers/staging/fbtft/fbtft.h
725 +@@ -241,6 +241,7 @@ struct fbtft_par {
726 + ktime_t update_time;
727 + bool bgr;
728 + void *extra;
729 ++ bool polarity;
730 + };
731 +
732 + #define NUMARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int))
733 +diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
734 +index 22e5116e74f8..bcdbf38b6916 100644
735 +--- a/drivers/staging/vt6655/device_main.c
736 ++++ b/drivers/staging/vt6655/device_main.c
737 +@@ -1673,8 +1673,10 @@ vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
738 +
739 + priv->hw->max_signal = 100;
740 +
741 +- if (vnt_init(priv))
742 ++ if (vnt_init(priv)) {
743 ++ device_free_info(priv);
744 + return -ENODEV;
745 ++ }
746 +
747 + device_print_info(priv);
748 + pci_set_drvdata(pcid, priv);
749 +diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
750 +index cd82ae34ddfa..57603be42c50 100644
751 +--- a/drivers/thermal/thermal_core.c
752 ++++ b/drivers/thermal/thermal_core.c
753 +@@ -402,7 +402,7 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
754 + mod_delayed_work(system_freezable_wq, &tz->poll_queue,
755 + msecs_to_jiffies(delay));
756 + else
757 +- cancel_delayed_work(&tz->poll_queue);
758 ++ cancel_delayed_work_sync(&tz->poll_queue);
759 + }
760 +
761 + static void monitor_thermal_zone(struct thermal_zone_device *tz)
762 +diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
763 +index 817bb0d3f326..9a54aafe8405 100644
764 +--- a/drivers/tty/serial/uartlite.c
765 ++++ b/drivers/tty/serial/uartlite.c
766 +@@ -746,7 +746,8 @@ err_uart:
767 + static void __exit ulite_exit(void)
768 + {
769 + platform_driver_unregister(&ulite_platform_driver);
770 +- uart_unregister_driver(&ulite_uart_driver);
771 ++ if (ulite_uart_driver.state)
772 ++ uart_unregister_driver(&ulite_uart_driver);
773 + }
774 +
775 + module_init(ulite_init);
776 +diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
777 +index 071964c7847f..0669fbb0ec25 100644
778 +--- a/drivers/usb/class/usblp.c
779 ++++ b/drivers/usb/class/usblp.c
780 +@@ -474,10 +474,12 @@ static int usblp_release(struct inode *inode, struct file *file)
781 +
782 + mutex_lock(&usblp_mutex);
783 + usblp->used = 0;
784 +- if (usblp->present) {
785 ++ if (usblp->present)
786 + usblp_unlink_urbs(usblp);
787 +- usb_autopm_put_interface(usblp->intf);
788 +- } else /* finish cleanup from disconnect */
789 ++
790 ++ usb_autopm_put_interface(usblp->intf);
791 ++
792 ++ if (!usblp->present) /* finish cleanup from disconnect */
793 + usblp_cleanup(usblp);
794 + mutex_unlock(&usblp_mutex);
795 + return 0;
796 +diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
797 +index ab89fa3b4118..2f7023a289c9 100644
798 +--- a/drivers/usb/gadget/udc/dummy_hcd.c
799 ++++ b/drivers/usb/gadget/udc/dummy_hcd.c
800 +@@ -50,6 +50,7 @@
801 + #define DRIVER_VERSION "02 May 2005"
802 +
803 + #define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */
804 ++#define POWER_BUDGET_3 900 /* in mA */
805 +
806 + static const char driver_name[] = "dummy_hcd";
807 + static const char driver_desc[] = "USB Host+Gadget Emulator";
808 +@@ -2433,7 +2434,7 @@ static int dummy_start_ss(struct dummy_hcd *dum_hcd)
809 + dum_hcd->rh_state = DUMMY_RH_RUNNING;
810 + dum_hcd->stream_en_ep = 0;
811 + INIT_LIST_HEAD(&dum_hcd->urbp_list);
812 +- dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET;
813 ++ dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET_3;
814 + dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING;
815 + dummy_hcd_to_hcd(dum_hcd)->uses_new_polling = 1;
816 + #ifdef CONFIG_USB_OTG
817 +diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
818 +index d2e3917cbd91..69ad9817076a 100644
819 +--- a/drivers/usb/host/xhci-ring.c
820 ++++ b/drivers/usb/host/xhci-ring.c
821 +@@ -3200,10 +3200,10 @@ static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len,
822 + if (usb_urb_dir_out(urb)) {
823 + len = sg_pcopy_to_buffer(urb->sg, urb->num_sgs,
824 + seg->bounce_buf, new_buff_len, enqd_len);
825 +- if (len != seg->bounce_len)
826 ++ if (len != new_buff_len)
827 + xhci_warn(xhci,
828 + "WARN Wrong bounce buffer write length: %zu != %d\n",
829 +- len, seg->bounce_len);
830 ++ len, new_buff_len);
831 + seg->bounce_dma = dma_map_single(dev, seg->bounce_buf,
832 + max_pkt, DMA_TO_DEVICE);
833 + } else {
834 +diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
835 +index ebdd82091a42..755016729f12 100644
836 +--- a/drivers/usb/host/xhci.c
837 ++++ b/drivers/usb/host/xhci.c
838 +@@ -985,7 +985,7 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
839 + command |= CMD_CSS;
840 + writel(command, &xhci->op_regs->command);
841 + if (xhci_handshake(&xhci->op_regs->status,
842 +- STS_SAVE, 0, 10 * 1000)) {
843 ++ STS_SAVE, 0, 20 * 1000)) {
844 + xhci_warn(xhci, "WARN: xHC save state timeout\n");
845 + spin_unlock_irq(&xhci->lock);
846 + return -ETIMEDOUT;
847 +@@ -1045,6 +1045,18 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
848 + hibernated = true;
849 +
850 + if (!hibernated) {
851 ++ /*
852 ++ * Some controllers might lose power during suspend, so wait
853 ++ * for controller not ready bit to clear, just as in xHC init.
854 ++ */
855 ++ retval = xhci_handshake(&xhci->op_regs->status,
856 ++ STS_CNR, 0, 10 * 1000 * 1000);
857 ++ if (retval) {
858 ++ xhci_warn(xhci, "Controller not ready at resume %d\n",
859 ++ retval);
860 ++ spin_unlock_irq(&xhci->lock);
861 ++ return retval;
862 ++ }
863 + /* step 1: restore register */
864 + xhci_restore_registers(xhci);
865 + /* step 2: initialize command ring buffer */
866 +@@ -4510,12 +4522,12 @@ static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci,
867 + alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev,
868 + desc, state, timeout);
869 +
870 +- /* If we found we can't enable hub-initiated LPM, or
871 ++ /* If we found we can't enable hub-initiated LPM, and
872 + * the U1 or U2 exit latency was too high to allow
873 +- * device-initiated LPM as well, just stop searching.
874 ++ * device-initiated LPM as well, then we will disable LPM
875 ++ * for this device, so stop searching any further.
876 + */
877 +- if (alt_timeout == USB3_LPM_DISABLED ||
878 +- alt_timeout == USB3_LPM_DEVICE_INITIATED) {
879 ++ if (alt_timeout == USB3_LPM_DISABLED) {
880 + *timeout = alt_timeout;
881 + return -E2BIG;
882 + }
883 +@@ -4626,10 +4638,12 @@ static u16 xhci_calculate_lpm_timeout(struct usb_hcd *hcd,
884 + if (intf->dev.driver) {
885 + driver = to_usb_driver(intf->dev.driver);
886 + if (driver && driver->disable_hub_initiated_lpm) {
887 +- dev_dbg(&udev->dev, "Hub-initiated %s disabled "
888 +- "at request of driver %s\n",
889 +- state_name, driver->name);
890 +- return xhci_get_timeout_no_hub_lpm(udev, state);
891 ++ dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n",
892 ++ state_name, driver->name);
893 ++ timeout = xhci_get_timeout_no_hub_lpm(udev,
894 ++ state);
895 ++ if (timeout == USB3_LPM_DISABLED)
896 ++ return timeout;
897 + }
898 + }
899 +
900 +diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
901 +index a4dbb0cd80da..0fecc002fa9f 100644
902 +--- a/drivers/usb/image/microtek.c
903 ++++ b/drivers/usb/image/microtek.c
904 +@@ -724,6 +724,10 @@ static int mts_usb_probe(struct usb_interface *intf,
905 +
906 + }
907 +
908 ++ if (ep_in_current != &ep_in_set[2]) {
909 ++ MTS_WARNING("couldn't find two input bulk endpoints. Bailing out.\n");
910 ++ return -ENODEV;
911 ++ }
912 +
913 + if ( ep_out == -1 ) {
914 + MTS_WARNING( "couldn't find an output bulk endpoint. Bailing out.\n" );
915 +diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
916 +index 47b357760afc..2de07a3653a0 100644
917 +--- a/drivers/usb/misc/Kconfig
918 ++++ b/drivers/usb/misc/Kconfig
919 +@@ -46,16 +46,6 @@ config USB_SEVSEG
920 + To compile this driver as a module, choose M here: the
921 + module will be called usbsevseg.
922 +
923 +-config USB_RIO500
924 +- tristate "USB Diamond Rio500 support"
925 +- help
926 +- Say Y here if you want to connect a USB Rio500 mp3 player to your
927 +- computer's USB port. Please read <file:Documentation/usb/rio.txt>
928 +- for more information.
929 +-
930 +- To compile this driver as a module, choose M here: the
931 +- module will be called rio500.
932 +-
933 + config USB_LEGOTOWER
934 + tristate "USB Lego Infrared Tower support"
935 + help
936 +diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
937 +index 3d1992750da4..2b21872cd733 100644
938 +--- a/drivers/usb/misc/Makefile
939 ++++ b/drivers/usb/misc/Makefile
940 +@@ -16,7 +16,6 @@ obj-$(CONFIG_USB_ISIGHTFW) += isight_firmware.o
941 + obj-$(CONFIG_USB_LCD) += usblcd.o
942 + obj-$(CONFIG_USB_LD) += ldusb.o
943 + obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
944 +-obj-$(CONFIG_USB_RIO500) += rio500.o
945 + obj-$(CONFIG_USB_TEST) += usbtest.o
946 + obj-$(CONFIG_USB_EHSET_TEST_FIXTURE) += ehset.o
947 + obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
948 +diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
949 +index 564268fca07a..f0c071da68d1 100644
950 +--- a/drivers/usb/misc/adutux.c
951 ++++ b/drivers/usb/misc/adutux.c
952 +@@ -80,6 +80,7 @@ struct adu_device {
953 + char serial_number[8];
954 +
955 + int open_count; /* number of times this port has been opened */
956 ++ unsigned long disconnected:1;
957 +
958 + char *read_buffer_primary;
959 + int read_buffer_length;
960 +@@ -121,7 +122,7 @@ static void adu_abort_transfers(struct adu_device *dev)
961 + {
962 + unsigned long flags;
963 +
964 +- if (dev->udev == NULL)
965 ++ if (dev->disconnected)
966 + return;
967 +
968 + /* shutdown transfer */
969 +@@ -151,6 +152,7 @@ static void adu_delete(struct adu_device *dev)
970 + kfree(dev->read_buffer_secondary);
971 + kfree(dev->interrupt_in_buffer);
972 + kfree(dev->interrupt_out_buffer);
973 ++ usb_put_dev(dev->udev);
974 + kfree(dev);
975 + }
976 +
977 +@@ -244,7 +246,7 @@ static int adu_open(struct inode *inode, struct file *file)
978 + }
979 +
980 + dev = usb_get_intfdata(interface);
981 +- if (!dev || !dev->udev) {
982 ++ if (!dev) {
983 + retval = -ENODEV;
984 + goto exit_no_device;
985 + }
986 +@@ -327,7 +329,7 @@ static int adu_release(struct inode *inode, struct file *file)
987 + }
988 +
989 + adu_release_internal(dev);
990 +- if (dev->udev == NULL) {
991 ++ if (dev->disconnected) {
992 + /* the device was unplugged before the file was released */
993 + if (!dev->open_count) /* ... and we're the last user */
994 + adu_delete(dev);
995 +@@ -356,7 +358,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
996 + return -ERESTARTSYS;
997 +
998 + /* verify that the device wasn't unplugged */
999 +- if (dev->udev == NULL) {
1000 ++ if (dev->disconnected) {
1001 + retval = -ENODEV;
1002 + pr_err("No device or device unplugged %d\n", retval);
1003 + goto exit;
1004 +@@ -525,7 +527,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
1005 + goto exit_nolock;
1006 +
1007 + /* verify that the device wasn't unplugged */
1008 +- if (dev->udev == NULL) {
1009 ++ if (dev->disconnected) {
1010 + retval = -ENODEV;
1011 + pr_err("No device or device unplugged %d\n", retval);
1012 + goto exit;
1013 +@@ -679,7 +681,7 @@ static int adu_probe(struct usb_interface *interface,
1014 +
1015 + mutex_init(&dev->mtx);
1016 + spin_lock_init(&dev->buflock);
1017 +- dev->udev = udev;
1018 ++ dev->udev = usb_get_dev(udev);
1019 + init_waitqueue_head(&dev->read_wait);
1020 + init_waitqueue_head(&dev->write_wait);
1021 +
1022 +@@ -789,19 +791,21 @@ error:
1023 + static void adu_disconnect(struct usb_interface *interface)
1024 + {
1025 + struct adu_device *dev;
1026 +- int minor;
1027 +
1028 + dev = usb_get_intfdata(interface);
1029 +
1030 +- mutex_lock(&dev->mtx); /* not interruptible */
1031 +- dev->udev = NULL; /* poison */
1032 +- minor = dev->minor;
1033 + usb_deregister_dev(interface, &adu_class);
1034 +- mutex_unlock(&dev->mtx);
1035 ++
1036 ++ usb_poison_urb(dev->interrupt_in_urb);
1037 ++ usb_poison_urb(dev->interrupt_out_urb);
1038 +
1039 + mutex_lock(&adutux_mutex);
1040 + usb_set_intfdata(interface, NULL);
1041 +
1042 ++ mutex_lock(&dev->mtx); /* not interruptible */
1043 ++ dev->disconnected = 1;
1044 ++ mutex_unlock(&dev->mtx);
1045 ++
1046 + /* if the device is not opened, then we clean up right now */
1047 + if (!dev->open_count)
1048 + adu_delete(dev);
1049 +diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
1050 +index efecb87428b1..64f2eeffaa00 100644
1051 +--- a/drivers/usb/misc/chaoskey.c
1052 ++++ b/drivers/usb/misc/chaoskey.c
1053 +@@ -108,6 +108,7 @@ static void chaoskey_free(struct chaoskey *dev)
1054 + usb_free_urb(dev->urb);
1055 + kfree(dev->name);
1056 + kfree(dev->buf);
1057 ++ usb_put_intf(dev->interface);
1058 + kfree(dev);
1059 + }
1060 + }
1061 +@@ -157,6 +158,8 @@ static int chaoskey_probe(struct usb_interface *interface,
1062 + if (dev == NULL)
1063 + goto out;
1064 +
1065 ++ dev->interface = usb_get_intf(interface);
1066 ++
1067 + dev->buf = kmalloc(size, GFP_KERNEL);
1068 +
1069 + if (dev->buf == NULL)
1070 +@@ -190,8 +193,6 @@ static int chaoskey_probe(struct usb_interface *interface,
1071 + strcat(dev->name, udev->serial);
1072 + }
1073 +
1074 +- dev->interface = interface;
1075 +-
1076 + dev->in_ep = in_ep;
1077 +
1078 + if (le16_to_cpu(udev->descriptor.idVendor) != ALEA_VENDOR_ID)
1079 +diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
1080 +index 318e087f8442..1b83946bfb18 100644
1081 +--- a/drivers/usb/misc/iowarrior.c
1082 ++++ b/drivers/usb/misc/iowarrior.c
1083 +@@ -89,6 +89,7 @@ struct iowarrior {
1084 + char chip_serial[9]; /* the serial number string of the chip connected */
1085 + int report_size; /* number of bytes in a report */
1086 + u16 product_id;
1087 ++ struct usb_anchor submitted;
1088 + };
1089 +
1090 + /*--------------*/
1091 +@@ -248,6 +249,7 @@ static inline void iowarrior_delete(struct iowarrior *dev)
1092 + kfree(dev->int_in_buffer);
1093 + usb_free_urb(dev->int_in_urb);
1094 + kfree(dev->read_queue);
1095 ++ usb_put_intf(dev->interface);
1096 + kfree(dev);
1097 + }
1098 +
1099 +@@ -434,11 +436,13 @@ static ssize_t iowarrior_write(struct file *file,
1100 + retval = -EFAULT;
1101 + goto error;
1102 + }
1103 ++ usb_anchor_urb(int_out_urb, &dev->submitted);
1104 + retval = usb_submit_urb(int_out_urb, GFP_KERNEL);
1105 + if (retval) {
1106 + dev_dbg(&dev->interface->dev,
1107 + "submit error %d for urb nr.%d\n",
1108 + retval, atomic_read(&dev->write_busy));
1109 ++ usb_unanchor_urb(int_out_urb);
1110 + goto error;
1111 + }
1112 + /* submit was ok */
1113 +@@ -776,11 +780,13 @@ static int iowarrior_probe(struct usb_interface *interface,
1114 + init_waitqueue_head(&dev->write_wait);
1115 +
1116 + dev->udev = udev;
1117 +- dev->interface = interface;
1118 ++ dev->interface = usb_get_intf(interface);
1119 +
1120 + iface_desc = interface->cur_altsetting;
1121 + dev->product_id = le16_to_cpu(udev->descriptor.idProduct);
1122 +
1123 ++ init_usb_anchor(&dev->submitted);
1124 ++
1125 + /* set up the endpoint information */
1126 + for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1127 + endpoint = &iface_desc->endpoint[i].desc;
1128 +@@ -886,8 +892,6 @@ static void iowarrior_disconnect(struct usb_interface *interface)
1129 + dev = usb_get_intfdata(interface);
1130 + mutex_lock(&iowarrior_open_disc_lock);
1131 + usb_set_intfdata(interface, NULL);
1132 +- /* prevent device read, write and ioctl */
1133 +- dev->present = 0;
1134 +
1135 + minor = dev->minor;
1136 + mutex_unlock(&iowarrior_open_disc_lock);
1137 +@@ -898,8 +902,7 @@ static void iowarrior_disconnect(struct usb_interface *interface)
1138 + mutex_lock(&dev->mutex);
1139 +
1140 + /* prevent device read, write and ioctl */
1141 +-
1142 +- mutex_unlock(&dev->mutex);
1143 ++ dev->present = 0;
1144 +
1145 + if (dev->opened) {
1146 + /* There is a process that holds a filedescriptor to the device ,
1147 +@@ -907,10 +910,13 @@ static void iowarrior_disconnect(struct usb_interface *interface)
1148 + Deleting the device is postponed until close() was called.
1149 + */
1150 + usb_kill_urb(dev->int_in_urb);
1151 ++ usb_kill_anchored_urbs(&dev->submitted);
1152 + wake_up_interruptible(&dev->read_wait);
1153 + wake_up_interruptible(&dev->write_wait);
1154 ++ mutex_unlock(&dev->mutex);
1155 + } else {
1156 + /* no process is using the device, cleanup now */
1157 ++ mutex_unlock(&dev->mutex);
1158 + iowarrior_delete(dev);
1159 + }
1160 +
1161 +diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
1162 +index c5e3032a4d6b..eee69c9e9a12 100644
1163 +--- a/drivers/usb/misc/ldusb.c
1164 ++++ b/drivers/usb/misc/ldusb.c
1165 +@@ -158,6 +158,7 @@ MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in
1166 + struct ld_usb {
1167 + struct mutex mutex; /* locks this structure */
1168 + struct usb_interface* intf; /* save off the usb interface pointer */
1169 ++ unsigned long disconnected:1;
1170 +
1171 + int open_count; /* number of times this port has been opened */
1172 +
1173 +@@ -197,12 +198,10 @@ static void ld_usb_abort_transfers(struct ld_usb *dev)
1174 + /* shutdown transfer */
1175 + if (dev->interrupt_in_running) {
1176 + dev->interrupt_in_running = 0;
1177 +- if (dev->intf)
1178 +- usb_kill_urb(dev->interrupt_in_urb);
1179 ++ usb_kill_urb(dev->interrupt_in_urb);
1180 + }
1181 + if (dev->interrupt_out_busy)
1182 +- if (dev->intf)
1183 +- usb_kill_urb(dev->interrupt_out_urb);
1184 ++ usb_kill_urb(dev->interrupt_out_urb);
1185 + }
1186 +
1187 + /**
1188 +@@ -210,8 +209,6 @@ static void ld_usb_abort_transfers(struct ld_usb *dev)
1189 + */
1190 + static void ld_usb_delete(struct ld_usb *dev)
1191 + {
1192 +- ld_usb_abort_transfers(dev);
1193 +-
1194 + /* free data structures */
1195 + usb_free_urb(dev->interrupt_in_urb);
1196 + usb_free_urb(dev->interrupt_out_urb);
1197 +@@ -267,7 +264,7 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
1198 +
1199 + resubmit:
1200 + /* resubmit if we're still running */
1201 +- if (dev->interrupt_in_running && !dev->buffer_overflow && dev->intf) {
1202 ++ if (dev->interrupt_in_running && !dev->buffer_overflow) {
1203 + retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
1204 + if (retval) {
1205 + dev_err(&dev->intf->dev,
1206 +@@ -396,7 +393,7 @@ static int ld_usb_release(struct inode *inode, struct file *file)
1207 + retval = -ENODEV;
1208 + goto unlock_exit;
1209 + }
1210 +- if (dev->intf == NULL) {
1211 ++ if (dev->disconnected) {
1212 + /* the device was unplugged before the file was released */
1213 + mutex_unlock(&dev->mutex);
1214 + /* unlock here as ld_usb_delete frees dev */
1215 +@@ -427,7 +424,7 @@ static unsigned int ld_usb_poll(struct file *file, poll_table *wait)
1216 +
1217 + dev = file->private_data;
1218 +
1219 +- if (!dev->intf)
1220 ++ if (dev->disconnected)
1221 + return POLLERR | POLLHUP;
1222 +
1223 + poll_wait(file, &dev->read_wait, wait);
1224 +@@ -466,7 +463,7 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
1225 + }
1226 +
1227 + /* verify that the device wasn't unplugged */
1228 +- if (dev->intf == NULL) {
1229 ++ if (dev->disconnected) {
1230 + retval = -ENODEV;
1231 + printk(KERN_ERR "ldusb: No device or device unplugged %d\n", retval);
1232 + goto unlock_exit;
1233 +@@ -546,7 +543,7 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
1234 + }
1235 +
1236 + /* verify that the device wasn't unplugged */
1237 +- if (dev->intf == NULL) {
1238 ++ if (dev->disconnected) {
1239 + retval = -ENODEV;
1240 + printk(KERN_ERR "ldusb: No device or device unplugged %d\n", retval);
1241 + goto unlock_exit;
1242 +@@ -768,6 +765,9 @@ static void ld_usb_disconnect(struct usb_interface *intf)
1243 + /* give back our minor */
1244 + usb_deregister_dev(intf, &ld_usb_class);
1245 +
1246 ++ usb_poison_urb(dev->interrupt_in_urb);
1247 ++ usb_poison_urb(dev->interrupt_out_urb);
1248 ++
1249 + mutex_lock(&dev->mutex);
1250 +
1251 + /* if the device is not opened, then we clean up right now */
1252 +@@ -775,7 +775,7 @@ static void ld_usb_disconnect(struct usb_interface *intf)
1253 + mutex_unlock(&dev->mutex);
1254 + ld_usb_delete(dev);
1255 + } else {
1256 +- dev->intf = NULL;
1257 ++ dev->disconnected = 1;
1258 + /* wake up pollers */
1259 + wake_up_interruptible_all(&dev->read_wait);
1260 + wake_up_interruptible_all(&dev->write_wait);
1261 +diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
1262 +index c2e2b2ea32d8..321756fc4d29 100644
1263 +--- a/drivers/usb/misc/legousbtower.c
1264 ++++ b/drivers/usb/misc/legousbtower.c
1265 +@@ -185,7 +185,6 @@ static const struct usb_device_id tower_table[] = {
1266 + };
1267 +
1268 + MODULE_DEVICE_TABLE (usb, tower_table);
1269 +-static DEFINE_MUTEX(open_disc_mutex);
1270 +
1271 + #define LEGO_USB_TOWER_MINOR_BASE 160
1272 +
1273 +@@ -197,6 +196,7 @@ struct lego_usb_tower {
1274 + unsigned char minor; /* the starting minor number for this device */
1275 +
1276 + int open_count; /* number of times this port has been opened */
1277 ++ unsigned long disconnected:1;
1278 +
1279 + char* read_buffer;
1280 + size_t read_buffer_length; /* this much came in */
1281 +@@ -296,14 +296,13 @@ static inline void lego_usb_tower_debug_data(struct device *dev,
1282 + */
1283 + static inline void tower_delete (struct lego_usb_tower *dev)
1284 + {
1285 +- tower_abort_transfers (dev);
1286 +-
1287 + /* free data structures */
1288 + usb_free_urb(dev->interrupt_in_urb);
1289 + usb_free_urb(dev->interrupt_out_urb);
1290 + kfree (dev->read_buffer);
1291 + kfree (dev->interrupt_in_buffer);
1292 + kfree (dev->interrupt_out_buffer);
1293 ++ usb_put_dev(dev->udev);
1294 + kfree (dev);
1295 + }
1296 +
1297 +@@ -338,18 +337,14 @@ static int tower_open (struct inode *inode, struct file *file)
1298 + goto exit;
1299 + }
1300 +
1301 +- mutex_lock(&open_disc_mutex);
1302 + dev = usb_get_intfdata(interface);
1303 +-
1304 + if (!dev) {
1305 +- mutex_unlock(&open_disc_mutex);
1306 + retval = -ENODEV;
1307 + goto exit;
1308 + }
1309 +
1310 + /* lock this device */
1311 + if (mutex_lock_interruptible(&dev->lock)) {
1312 +- mutex_unlock(&open_disc_mutex);
1313 + retval = -ERESTARTSYS;
1314 + goto exit;
1315 + }
1316 +@@ -357,12 +352,9 @@ static int tower_open (struct inode *inode, struct file *file)
1317 +
1318 + /* allow opening only once */
1319 + if (dev->open_count) {
1320 +- mutex_unlock(&open_disc_mutex);
1321 + retval = -EBUSY;
1322 + goto unlock_exit;
1323 + }
1324 +- dev->open_count = 1;
1325 +- mutex_unlock(&open_disc_mutex);
1326 +
1327 + /* reset the tower */
1328 + result = usb_control_msg (dev->udev,
1329 +@@ -402,13 +394,14 @@ static int tower_open (struct inode *inode, struct file *file)
1330 + dev_err(&dev->udev->dev,
1331 + "Couldn't submit interrupt_in_urb %d\n", retval);
1332 + dev->interrupt_in_running = 0;
1333 +- dev->open_count = 0;
1334 + goto unlock_exit;
1335 + }
1336 +
1337 + /* save device in the file's private structure */
1338 + file->private_data = dev;
1339 +
1340 ++ dev->open_count = 1;
1341 ++
1342 + unlock_exit:
1343 + mutex_unlock(&dev->lock);
1344 +
1345 +@@ -429,10 +422,9 @@ static int tower_release (struct inode *inode, struct file *file)
1346 +
1347 + if (dev == NULL) {
1348 + retval = -ENODEV;
1349 +- goto exit_nolock;
1350 ++ goto exit;
1351 + }
1352 +
1353 +- mutex_lock(&open_disc_mutex);
1354 + if (mutex_lock_interruptible(&dev->lock)) {
1355 + retval = -ERESTARTSYS;
1356 + goto exit;
1357 +@@ -444,7 +436,8 @@ static int tower_release (struct inode *inode, struct file *file)
1358 + retval = -ENODEV;
1359 + goto unlock_exit;
1360 + }
1361 +- if (dev->udev == NULL) {
1362 ++
1363 ++ if (dev->disconnected) {
1364 + /* the device was unplugged before the file was released */
1365 +
1366 + /* unlock here as tower_delete frees dev */
1367 +@@ -462,10 +455,7 @@ static int tower_release (struct inode *inode, struct file *file)
1368 +
1369 + unlock_exit:
1370 + mutex_unlock(&dev->lock);
1371 +-
1372 + exit:
1373 +- mutex_unlock(&open_disc_mutex);
1374 +-exit_nolock:
1375 + return retval;
1376 + }
1377 +
1378 +@@ -483,10 +473,9 @@ static void tower_abort_transfers (struct lego_usb_tower *dev)
1379 + if (dev->interrupt_in_running) {
1380 + dev->interrupt_in_running = 0;
1381 + mb();
1382 +- if (dev->udev)
1383 +- usb_kill_urb (dev->interrupt_in_urb);
1384 ++ usb_kill_urb(dev->interrupt_in_urb);
1385 + }
1386 +- if (dev->interrupt_out_busy && dev->udev)
1387 ++ if (dev->interrupt_out_busy)
1388 + usb_kill_urb(dev->interrupt_out_urb);
1389 + }
1390 +
1391 +@@ -522,7 +511,7 @@ static unsigned int tower_poll (struct file *file, poll_table *wait)
1392 +
1393 + dev = file->private_data;
1394 +
1395 +- if (!dev->udev)
1396 ++ if (dev->disconnected)
1397 + return POLLERR | POLLHUP;
1398 +
1399 + poll_wait(file, &dev->read_wait, wait);
1400 +@@ -569,7 +558,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
1401 + }
1402 +
1403 + /* verify that the device wasn't unplugged */
1404 +- if (dev->udev == NULL) {
1405 ++ if (dev->disconnected) {
1406 + retval = -ENODEV;
1407 + pr_err("No device or device unplugged %d\n", retval);
1408 + goto unlock_exit;
1409 +@@ -655,7 +644,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
1410 + }
1411 +
1412 + /* verify that the device wasn't unplugged */
1413 +- if (dev->udev == NULL) {
1414 ++ if (dev->disconnected) {
1415 + retval = -ENODEV;
1416 + pr_err("No device or device unplugged %d\n", retval);
1417 + goto unlock_exit;
1418 +@@ -764,7 +753,7 @@ static void tower_interrupt_in_callback (struct urb *urb)
1419 +
1420 + resubmit:
1421 + /* resubmit if we're still running */
1422 +- if (dev->interrupt_in_running && dev->udev) {
1423 ++ if (dev->interrupt_in_running) {
1424 + retval = usb_submit_urb (dev->interrupt_in_urb, GFP_ATOMIC);
1425 + if (retval)
1426 + dev_err(&dev->udev->dev,
1427 +@@ -830,8 +819,9 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
1428 +
1429 + mutex_init(&dev->lock);
1430 +
1431 +- dev->udev = udev;
1432 ++ dev->udev = usb_get_dev(udev);
1433 + dev->open_count = 0;
1434 ++ dev->disconnected = 0;
1435 +
1436 + dev->read_buffer = NULL;
1437 + dev->read_buffer_length = 0;
1438 +@@ -911,8 +901,10 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
1439 + get_version_reply,
1440 + sizeof(*get_version_reply),
1441 + 1000);
1442 +- if (result < 0) {
1443 +- dev_err(idev, "LEGO USB Tower get version control request failed\n");
1444 ++ if (result < sizeof(*get_version_reply)) {
1445 ++ if (result >= 0)
1446 ++ result = -EIO;
1447 ++ dev_err(idev, "get version request failed: %d\n", result);
1448 + retval = result;
1449 + goto error;
1450 + }
1451 +@@ -930,7 +922,6 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
1452 + if (retval) {
1453 + /* something prevented us from registering this driver */
1454 + dev_err(idev, "Not able to get a minor for this device.\n");
1455 +- usb_set_intfdata (interface, NULL);
1456 + goto error;
1457 + }
1458 + dev->minor = interface->minor;
1459 +@@ -962,23 +953,24 @@ static void tower_disconnect (struct usb_interface *interface)
1460 + int minor;
1461 +
1462 + dev = usb_get_intfdata (interface);
1463 +- mutex_lock(&open_disc_mutex);
1464 +- usb_set_intfdata (interface, NULL);
1465 +
1466 + minor = dev->minor;
1467 +
1468 +- /* give back our minor */
1469 ++ /* give back our minor and prevent further open() */
1470 + usb_deregister_dev (interface, &tower_class);
1471 +
1472 ++ /* stop I/O */
1473 ++ usb_poison_urb(dev->interrupt_in_urb);
1474 ++ usb_poison_urb(dev->interrupt_out_urb);
1475 ++
1476 + mutex_lock(&dev->lock);
1477 +- mutex_unlock(&open_disc_mutex);
1478 +
1479 + /* if the device is not opened, then we clean up right now */
1480 + if (!dev->open_count) {
1481 + mutex_unlock(&dev->lock);
1482 + tower_delete (dev);
1483 + } else {
1484 +- dev->udev = NULL;
1485 ++ dev->disconnected = 1;
1486 + /* wake up pollers */
1487 + wake_up_interruptible_all(&dev->read_wait);
1488 + wake_up_interruptible_all(&dev->write_wait);
1489 +diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
1490 +deleted file mode 100644
1491 +index 6e761fabffca..000000000000
1492 +--- a/drivers/usb/misc/rio500.c
1493 ++++ /dev/null
1494 +@@ -1,578 +0,0 @@
1495 +-/* -*- linux-c -*- */
1496 +-
1497 +-/*
1498 +- * Driver for USB Rio 500
1499 +- *
1500 +- * Cesar Miquel (miquel@××××××.ar)
1501 +- *
1502 +- * based on hp_scanner.c by David E. Nelson (dnelson@××××.net)
1503 +- *
1504 +- * This program is free software; you can redistribute it and/or
1505 +- * modify it under the terms of the GNU General Public License as
1506 +- * published by the Free Software Foundation; either version 2 of the
1507 +- * License, or (at your option) any later version.
1508 +- *
1509 +- * This program is distributed in the hope that it will be useful, but
1510 +- * WITHOUT ANY WARRANTY; without even the implied warranty of
1511 +- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1512 +- * General Public License for more details.
1513 +- *
1514 +- * You should have received a copy of the GNU General Public License
1515 +- * along with this program; if not, write to the Free Software
1516 +- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1517 +- *
1518 +- * Based upon mouse.c (Brad Keryan) and printer.c (Michael Gee).
1519 +- *
1520 +- * Changelog:
1521 +- * 30/05/2003 replaced lock/unlock kernel with up/down
1522 +- * Daniele Bellucci bellucda@×××××××.it
1523 +- * */
1524 +-
1525 +-#include <linux/module.h>
1526 +-#include <linux/kernel.h>
1527 +-#include <linux/signal.h>
1528 +-#include <linux/sched.h>
1529 +-#include <linux/mutex.h>
1530 +-#include <linux/errno.h>
1531 +-#include <linux/random.h>
1532 +-#include <linux/poll.h>
1533 +-#include <linux/slab.h>
1534 +-#include <linux/spinlock.h>
1535 +-#include <linux/usb.h>
1536 +-#include <linux/wait.h>
1537 +-
1538 +-#include "rio500_usb.h"
1539 +-
1540 +-/*
1541 +- * Version Information
1542 +- */
1543 +-#define DRIVER_VERSION "v1.1"
1544 +-#define DRIVER_AUTHOR "Cesar Miquel <miquel@××××××.ar>"
1545 +-#define DRIVER_DESC "USB Rio 500 driver"
1546 +-
1547 +-#define RIO_MINOR 64
1548 +-
1549 +-/* stall/wait timeout for rio */
1550 +-#define NAK_TIMEOUT (HZ)
1551 +-
1552 +-#define IBUF_SIZE 0x1000
1553 +-
1554 +-/* Size of the rio buffer */
1555 +-#define OBUF_SIZE 0x10000
1556 +-
1557 +-struct rio_usb_data {
1558 +- struct usb_device *rio_dev; /* init: probe_rio */
1559 +- unsigned int ifnum; /* Interface number of the USB device */
1560 +- int isopen; /* nz if open */
1561 +- int present; /* Device is present on the bus */
1562 +- char *obuf, *ibuf; /* transfer buffers */
1563 +- char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */
1564 +- wait_queue_head_t wait_q; /* for timeouts */
1565 +- struct mutex lock; /* general race avoidance */
1566 +-};
1567 +-
1568 +-static DEFINE_MUTEX(rio500_mutex);
1569 +-static struct rio_usb_data rio_instance;
1570 +-
1571 +-static int open_rio(struct inode *inode, struct file *file)
1572 +-{
1573 +- struct rio_usb_data *rio = &rio_instance;
1574 +-
1575 +- /* against disconnect() */
1576 +- mutex_lock(&rio500_mutex);
1577 +- mutex_lock(&(rio->lock));
1578 +-
1579 +- if (rio->isopen || !rio->present) {
1580 +- mutex_unlock(&(rio->lock));
1581 +- mutex_unlock(&rio500_mutex);
1582 +- return -EBUSY;
1583 +- }
1584 +- rio->isopen = 1;
1585 +-
1586 +- init_waitqueue_head(&rio->wait_q);
1587 +-
1588 +- mutex_unlock(&(rio->lock));
1589 +-
1590 +- dev_info(&rio->rio_dev->dev, "Rio opened.\n");
1591 +- mutex_unlock(&rio500_mutex);
1592 +-
1593 +- return 0;
1594 +-}
1595 +-
1596 +-static int close_rio(struct inode *inode, struct file *file)
1597 +-{
1598 +- struct rio_usb_data *rio = &rio_instance;
1599 +-
1600 +- /* against disconnect() */
1601 +- mutex_lock(&rio500_mutex);
1602 +- mutex_lock(&(rio->lock));
1603 +-
1604 +- rio->isopen = 0;
1605 +- if (!rio->present) {
1606 +- /* cleanup has been delayed */
1607 +- kfree(rio->ibuf);
1608 +- kfree(rio->obuf);
1609 +- rio->ibuf = NULL;
1610 +- rio->obuf = NULL;
1611 +- } else {
1612 +- dev_info(&rio->rio_dev->dev, "Rio closed.\n");
1613 +- }
1614 +- mutex_unlock(&(rio->lock));
1615 +- mutex_unlock(&rio500_mutex);
1616 +- return 0;
1617 +-}
1618 +-
1619 +-static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
1620 +-{
1621 +- struct RioCommand rio_cmd;
1622 +- struct rio_usb_data *rio = &rio_instance;
1623 +- void __user *data;
1624 +- unsigned char *buffer;
1625 +- int result, requesttype;
1626 +- int retries;
1627 +- int retval=0;
1628 +-
1629 +- mutex_lock(&(rio->lock));
1630 +- /* Sanity check to make sure rio is connected, powered, etc */
1631 +- if (rio->present == 0 || rio->rio_dev == NULL) {
1632 +- retval = -ENODEV;
1633 +- goto err_out;
1634 +- }
1635 +-
1636 +- switch (cmd) {
1637 +- case RIO_RECV_COMMAND:
1638 +- data = (void __user *) arg;
1639 +- if (data == NULL)
1640 +- break;
1641 +- if (copy_from_user(&rio_cmd, data, sizeof(struct RioCommand))) {
1642 +- retval = -EFAULT;
1643 +- goto err_out;
1644 +- }
1645 +- if (rio_cmd.length < 0 || rio_cmd.length > PAGE_SIZE) {
1646 +- retval = -EINVAL;
1647 +- goto err_out;
1648 +- }
1649 +- buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
1650 +- if (buffer == NULL) {
1651 +- retval = -ENOMEM;
1652 +- goto err_out;
1653 +- }
1654 +- if (copy_from_user(buffer, rio_cmd.buffer, rio_cmd.length)) {
1655 +- retval = -EFAULT;
1656 +- free_page((unsigned long) buffer);
1657 +- goto err_out;
1658 +- }
1659 +-
1660 +- requesttype = rio_cmd.requesttype | USB_DIR_IN |
1661 +- USB_TYPE_VENDOR | USB_RECIP_DEVICE;
1662 +- dev_dbg(&rio->rio_dev->dev,
1663 +- "sending command:reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
1664 +- requesttype, rio_cmd.request, rio_cmd.value,
1665 +- rio_cmd.index, rio_cmd.length);
1666 +- /* Send rio control message */
1667 +- retries = 3;
1668 +- while (retries) {
1669 +- result = usb_control_msg(rio->rio_dev,
1670 +- usb_rcvctrlpipe(rio-> rio_dev, 0),
1671 +- rio_cmd.request,
1672 +- requesttype,
1673 +- rio_cmd.value,
1674 +- rio_cmd.index, buffer,
1675 +- rio_cmd.length,
1676 +- jiffies_to_msecs(rio_cmd.timeout));
1677 +- if (result == -ETIMEDOUT)
1678 +- retries--;
1679 +- else if (result < 0) {
1680 +- dev_err(&rio->rio_dev->dev,
1681 +- "Error executing ioctrl. code = %d\n",
1682 +- result);
1683 +- retries = 0;
1684 +- } else {
1685 +- dev_dbg(&rio->rio_dev->dev,
1686 +- "Executed ioctl. Result = %d (data=%02x)\n",
1687 +- result, buffer[0]);
1688 +- if (copy_to_user(rio_cmd.buffer, buffer,
1689 +- rio_cmd.length)) {
1690 +- free_page((unsigned long) buffer);
1691 +- retval = -EFAULT;
1692 +- goto err_out;
1693 +- }
1694 +- retries = 0;
1695 +- }
1696 +-
1697 +- /* rio_cmd.buffer contains a raw stream of single byte
1698 +- data which has been returned from rio. Data is
1699 +- interpreted at application level. For data that
1700 +- will be cast to data types longer than 1 byte, data
1701 +- will be little_endian and will potentially need to
1702 +- be swapped at the app level */
1703 +-
1704 +- }
1705 +- free_page((unsigned long) buffer);
1706 +- break;
1707 +-
1708 +- case RIO_SEND_COMMAND:
1709 +- data = (void __user *) arg;
1710 +- if (data == NULL)
1711 +- break;
1712 +- if (copy_from_user(&rio_cmd, data, sizeof(struct RioCommand))) {
1713 +- retval = -EFAULT;
1714 +- goto err_out;
1715 +- }
1716 +- if (rio_cmd.length < 0 || rio_cmd.length > PAGE_SIZE) {
1717 +- retval = -EINVAL;
1718 +- goto err_out;
1719 +- }
1720 +- buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
1721 +- if (buffer == NULL) {
1722 +- retval = -ENOMEM;
1723 +- goto err_out;
1724 +- }
1725 +- if (copy_from_user(buffer, rio_cmd.buffer, rio_cmd.length)) {
1726 +- free_page((unsigned long)buffer);
1727 +- retval = -EFAULT;
1728 +- goto err_out;
1729 +- }
1730 +-
1731 +- requesttype = rio_cmd.requesttype | USB_DIR_OUT |
1732 +- USB_TYPE_VENDOR | USB_RECIP_DEVICE;
1733 +- dev_dbg(&rio->rio_dev->dev,
1734 +- "sending command: reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
1735 +- requesttype, rio_cmd.request, rio_cmd.value,
1736 +- rio_cmd.index, rio_cmd.length);
1737 +- /* Send rio control message */
1738 +- retries = 3;
1739 +- while (retries) {
1740 +- result = usb_control_msg(rio->rio_dev,
1741 +- usb_sndctrlpipe(rio-> rio_dev, 0),
1742 +- rio_cmd.request,
1743 +- requesttype,
1744 +- rio_cmd.value,
1745 +- rio_cmd.index, buffer,
1746 +- rio_cmd.length,
1747 +- jiffies_to_msecs(rio_cmd.timeout));
1748 +- if (result == -ETIMEDOUT)
1749 +- retries--;
1750 +- else if (result < 0) {
1751 +- dev_err(&rio->rio_dev->dev,
1752 +- "Error executing ioctrl. code = %d\n",
1753 +- result);
1754 +- retries = 0;
1755 +- } else {
1756 +- dev_dbg(&rio->rio_dev->dev,
1757 +- "Executed ioctl. Result = %d\n", result);
1758 +- retries = 0;
1759 +-
1760 +- }
1761 +-
1762 +- }
1763 +- free_page((unsigned long) buffer);
1764 +- break;
1765 +-
1766 +- default:
1767 +- retval = -ENOTTY;
1768 +- break;
1769 +- }
1770 +-
1771 +-
1772 +-err_out:
1773 +- mutex_unlock(&(rio->lock));
1774 +- return retval;
1775 +-}
1776 +-
1777 +-static ssize_t
1778 +-write_rio(struct file *file, const char __user *buffer,
1779 +- size_t count, loff_t * ppos)
1780 +-{
1781 +- DEFINE_WAIT(wait);
1782 +- struct rio_usb_data *rio = &rio_instance;
1783 +-
1784 +- unsigned long copy_size;
1785 +- unsigned long bytes_written = 0;
1786 +- unsigned int partial;
1787 +-
1788 +- int result = 0;
1789 +- int maxretry;
1790 +- int errn = 0;
1791 +- int intr;
1792 +-
1793 +- intr = mutex_lock_interruptible(&(rio->lock));
1794 +- if (intr)
1795 +- return -EINTR;
1796 +- /* Sanity check to make sure rio is connected, powered, etc */
1797 +- if (rio->present == 0 || rio->rio_dev == NULL) {
1798 +- mutex_unlock(&(rio->lock));
1799 +- return -ENODEV;
1800 +- }
1801 +-
1802 +-
1803 +-
1804 +- do {
1805 +- unsigned long thistime;
1806 +- char *obuf = rio->obuf;
1807 +-
1808 +- thistime = copy_size =
1809 +- (count >= OBUF_SIZE) ? OBUF_SIZE : count;
1810 +- if (copy_from_user(rio->obuf, buffer, copy_size)) {
1811 +- errn = -EFAULT;
1812 +- goto error;
1813 +- }
1814 +- maxretry = 5;
1815 +- while (thistime) {
1816 +- if (!rio->rio_dev) {
1817 +- errn = -ENODEV;
1818 +- goto error;
1819 +- }
1820 +- if (signal_pending(current)) {
1821 +- mutex_unlock(&(rio->lock));
1822 +- return bytes_written ? bytes_written : -EINTR;
1823 +- }
1824 +-
1825 +- result = usb_bulk_msg(rio->rio_dev,
1826 +- usb_sndbulkpipe(rio->rio_dev, 2),
1827 +- obuf, thistime, &partial, 5000);
1828 +-
1829 +- dev_dbg(&rio->rio_dev->dev,
1830 +- "write stats: result:%d thistime:%lu partial:%u\n",
1831 +- result, thistime, partial);
1832 +-
1833 +- if (result == -ETIMEDOUT) { /* NAK - so hold for a while */
1834 +- if (!maxretry--) {
1835 +- errn = -ETIME;
1836 +- goto error;
1837 +- }
1838 +- prepare_to_wait(&rio->wait_q, &wait, TASK_INTERRUPTIBLE);
1839 +- schedule_timeout(NAK_TIMEOUT);
1840 +- finish_wait(&rio->wait_q, &wait);
1841 +- continue;
1842 +- } else if (!result && partial) {
1843 +- obuf += partial;
1844 +- thistime -= partial;
1845 +- } else
1846 +- break;
1847 +- }
1848 +- if (result) {
1849 +- dev_err(&rio->rio_dev->dev, "Write Whoops - %x\n",
1850 +- result);
1851 +- errn = -EIO;
1852 +- goto error;
1853 +- }
1854 +- bytes_written += copy_size;
1855 +- count -= copy_size;
1856 +- buffer += copy_size;
1857 +- } while (count > 0);
1858 +-
1859 +- mutex_unlock(&(rio->lock));
1860 +-
1861 +- return bytes_written ? bytes_written : -EIO;
1862 +-
1863 +-error:
1864 +- mutex_unlock(&(rio->lock));
1865 +- return errn;
1866 +-}
1867 +-
1868 +-static ssize_t
1869 +-read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
1870 +-{
1871 +- DEFINE_WAIT(wait);
1872 +- struct rio_usb_data *rio = &rio_instance;
1873 +- ssize_t read_count;
1874 +- unsigned int partial;
1875 +- int this_read;
1876 +- int result;
1877 +- int maxretry = 10;
1878 +- char *ibuf;
1879 +- int intr;
1880 +-
1881 +- intr = mutex_lock_interruptible(&(rio->lock));
1882 +- if (intr)
1883 +- return -EINTR;
1884 +- /* Sanity check to make sure rio is connected, powered, etc */
1885 +- if (rio->present == 0 || rio->rio_dev == NULL) {
1886 +- mutex_unlock(&(rio->lock));
1887 +- return -ENODEV;
1888 +- }
1889 +-
1890 +- ibuf = rio->ibuf;
1891 +-
1892 +- read_count = 0;
1893 +-
1894 +-
1895 +- while (count > 0) {
1896 +- if (signal_pending(current)) {
1897 +- mutex_unlock(&(rio->lock));
1898 +- return read_count ? read_count : -EINTR;
1899 +- }
1900 +- if (!rio->rio_dev) {
1901 +- mutex_unlock(&(rio->lock));
1902 +- return -ENODEV;
1903 +- }
1904 +- this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count;
1905 +-
1906 +- result = usb_bulk_msg(rio->rio_dev,
1907 +- usb_rcvbulkpipe(rio->rio_dev, 1),
1908 +- ibuf, this_read, &partial,
1909 +- 8000);
1910 +-
1911 +- dev_dbg(&rio->rio_dev->dev,
1912 +- "read stats: result:%d this_read:%u partial:%u\n",
1913 +- result, this_read, partial);
1914 +-
1915 +- if (partial) {
1916 +- count = this_read = partial;
1917 +- } else if (result == -ETIMEDOUT || result == 15) { /* FIXME: 15 ??? */
1918 +- if (!maxretry--) {
1919 +- mutex_unlock(&(rio->lock));
1920 +- dev_err(&rio->rio_dev->dev,
1921 +- "read_rio: maxretry timeout\n");
1922 +- return -ETIME;
1923 +- }
1924 +- prepare_to_wait(&rio->wait_q, &wait, TASK_INTERRUPTIBLE);
1925 +- schedule_timeout(NAK_TIMEOUT);
1926 +- finish_wait(&rio->wait_q, &wait);
1927 +- continue;
1928 +- } else if (result != -EREMOTEIO) {
1929 +- mutex_unlock(&(rio->lock));
1930 +- dev_err(&rio->rio_dev->dev,
1931 +- "Read Whoops - result:%u partial:%u this_read:%u\n",
1932 +- result, partial, this_read);
1933 +- return -EIO;
1934 +- } else {
1935 +- mutex_unlock(&(rio->lock));
1936 +- return (0);
1937 +- }
1938 +-
1939 +- if (this_read) {
1940 +- if (copy_to_user(buffer, ibuf, this_read)) {
1941 +- mutex_unlock(&(rio->lock));
1942 +- return -EFAULT;
1943 +- }
1944 +- count -= this_read;
1945 +- read_count += this_read;
1946 +- buffer += this_read;
1947 +- }
1948 +- }
1949 +- mutex_unlock(&(rio->lock));
1950 +- return read_count;
1951 +-}
1952 +-
1953 +-static const struct file_operations usb_rio_fops = {
1954 +- .owner = THIS_MODULE,
1955 +- .read = read_rio,
1956 +- .write = write_rio,
1957 +- .unlocked_ioctl = ioctl_rio,
1958 +- .open = open_rio,
1959 +- .release = close_rio,
1960 +- .llseek = noop_llseek,
1961 +-};
1962 +-
1963 +-static struct usb_class_driver usb_rio_class = {
1964 +- .name = "rio500%d",
1965 +- .fops = &usb_rio_fops,
1966 +- .minor_base = RIO_MINOR,
1967 +-};
1968 +-
1969 +-static int probe_rio(struct usb_interface *intf,
1970 +- const struct usb_device_id *id)
1971 +-{
1972 +- struct usb_device *dev = interface_to_usbdev(intf);
1973 +- struct rio_usb_data *rio = &rio_instance;
1974 +- int retval = 0;
1975 +-
1976 +- mutex_lock(&rio500_mutex);
1977 +- if (rio->present) {
1978 +- dev_info(&intf->dev, "Second USB Rio at address %d refused\n", dev->devnum);
1979 +- retval = -EBUSY;
1980 +- goto bail_out;
1981 +- } else {
1982 +- dev_info(&intf->dev, "USB Rio found at address %d\n", dev->devnum);
1983 +- }
1984 +-
1985 +- retval = usb_register_dev(intf, &usb_rio_class);
1986 +- if (retval) {
1987 +- dev_err(&dev->dev,
1988 +- "Not able to get a minor for this device.\n");
1989 +- retval = -ENOMEM;
1990 +- goto bail_out;
1991 +- }
1992 +-
1993 +- rio->rio_dev = dev;
1994 +-
1995 +- if (!(rio->obuf = kmalloc(OBUF_SIZE, GFP_KERNEL))) {
1996 +- dev_err(&dev->dev,
1997 +- "probe_rio: Not enough memory for the output buffer\n");
1998 +- usb_deregister_dev(intf, &usb_rio_class);
1999 +- retval = -ENOMEM;
2000 +- goto bail_out;
2001 +- }
2002 +- dev_dbg(&intf->dev, "obuf address:%p\n", rio->obuf);
2003 +-
2004 +- if (!(rio->ibuf = kmalloc(IBUF_SIZE, GFP_KERNEL))) {
2005 +- dev_err(&dev->dev,
2006 +- "probe_rio: Not enough memory for the input buffer\n");
2007 +- usb_deregister_dev(intf, &usb_rio_class);
2008 +- kfree(rio->obuf);
2009 +- retval = -ENOMEM;
2010 +- goto bail_out;
2011 +- }
2012 +- dev_dbg(&intf->dev, "ibuf address:%p\n", rio->ibuf);
2013 +-
2014 +- mutex_init(&(rio->lock));
2015 +-
2016 +- usb_set_intfdata (intf, rio);
2017 +- rio->present = 1;
2018 +-bail_out:
2019 +- mutex_unlock(&rio500_mutex);
2020 +-
2021 +- return retval;
2022 +-}
2023 +-
2024 +-static void disconnect_rio(struct usb_interface *intf)
2025 +-{
2026 +- struct rio_usb_data *rio = usb_get_intfdata (intf);
2027 +-
2028 +- usb_set_intfdata (intf, NULL);
2029 +- mutex_lock(&rio500_mutex);
2030 +- if (rio) {
2031 +- usb_deregister_dev(intf, &usb_rio_class);
2032 +-
2033 +- mutex_lock(&(rio->lock));
2034 +- if (rio->isopen) {
2035 +- rio->isopen = 0;
2036 +- /* better let it finish - the release will do whats needed */
2037 +- rio->rio_dev = NULL;
2038 +- mutex_unlock(&(rio->lock));
2039 +- mutex_unlock(&rio500_mutex);
2040 +- return;
2041 +- }
2042 +- kfree(rio->ibuf);
2043 +- kfree(rio->obuf);
2044 +-
2045 +- dev_info(&intf->dev, "USB Rio disconnected.\n");
2046 +-
2047 +- rio->present = 0;
2048 +- mutex_unlock(&(rio->lock));
2049 +- }
2050 +- mutex_unlock(&rio500_mutex);
2051 +-}
2052 +-
2053 +-static const struct usb_device_id rio_table[] = {
2054 +- { USB_DEVICE(0x0841, 1) }, /* Rio 500 */
2055 +- { } /* Terminating entry */
2056 +-};
2057 +-
2058 +-MODULE_DEVICE_TABLE (usb, rio_table);
2059 +-
2060 +-static struct usb_driver rio_driver = {
2061 +- .name = "rio500",
2062 +- .probe = probe_rio,
2063 +- .disconnect = disconnect_rio,
2064 +- .id_table = rio_table,
2065 +-};
2066 +-
2067 +-module_usb_driver(rio_driver);
2068 +-
2069 +-MODULE_AUTHOR( DRIVER_AUTHOR );
2070 +-MODULE_DESCRIPTION( DRIVER_DESC );
2071 +-MODULE_LICENSE("GPL");
2072 +-
2073 +diff --git a/drivers/usb/misc/rio500_usb.h b/drivers/usb/misc/rio500_usb.h
2074 +deleted file mode 100644
2075 +index 359abc98e706..000000000000
2076 +--- a/drivers/usb/misc/rio500_usb.h
2077 ++++ /dev/null
2078 +@@ -1,37 +0,0 @@
2079 +-/* ----------------------------------------------------------------------
2080 +-
2081 +- Copyright (C) 2000 Cesar Miquel (miquel@××××××.ar)
2082 +-
2083 +- This program is free software; you can redistribute it and/or modify
2084 +- it under the terms of the GNU General Public License as published by
2085 +- the Free Software Foundation; either version 2 of the License, or
2086 +- (at your option) any later version.
2087 +-
2088 +- This program is distributed in the hope that it will be useful,
2089 +- but WITHOUT ANY WARRANTY; without even the implied warranty of
2090 +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2091 +- GNU General Public License for more details.
2092 +-
2093 +- You should have received a copy of the GNU General Public License
2094 +- along with this program; if not, write to the Free Software
2095 +- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2096 +-
2097 +- ---------------------------------------------------------------------- */
2098 +-
2099 +-
2100 +-
2101 +-#define RIO_SEND_COMMAND 0x1
2102 +-#define RIO_RECV_COMMAND 0x2
2103 +-
2104 +-#define RIO_DIR_OUT 0x0
2105 +-#define RIO_DIR_IN 0x1
2106 +-
2107 +-struct RioCommand {
2108 +- short length;
2109 +- int request;
2110 +- int requesttype;
2111 +- int value;
2112 +- int index;
2113 +- void __user *buffer;
2114 +- int timeout;
2115 +-};
2116 +diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
2117 +index 9f48419abc46..35a736eaf864 100644
2118 +--- a/drivers/usb/misc/usblcd.c
2119 ++++ b/drivers/usb/misc/usblcd.c
2120 +@@ -17,6 +17,7 @@
2121 + #include <linux/slab.h>
2122 + #include <linux/errno.h>
2123 + #include <linux/mutex.h>
2124 ++#include <linux/rwsem.h>
2125 + #include <linux/uaccess.h>
2126 + #include <linux/usb.h>
2127 +
2128 +@@ -56,6 +57,8 @@ struct usb_lcd {
2129 + using up all RAM */
2130 + struct usb_anchor submitted; /* URBs to wait for
2131 + before suspend */
2132 ++ struct rw_semaphore io_rwsem;
2133 ++ unsigned long disconnected:1;
2134 + };
2135 + #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref)
2136 +
2137 +@@ -141,6 +144,13 @@ static ssize_t lcd_read(struct file *file, char __user * buffer,
2138 +
2139 + dev = file->private_data;
2140 +
2141 ++ down_read(&dev->io_rwsem);
2142 ++
2143 ++ if (dev->disconnected) {
2144 ++ retval = -ENODEV;
2145 ++ goto out_up_io;
2146 ++ }
2147 ++
2148 + /* do a blocking bulk read to get data from the device */
2149 + retval = usb_bulk_msg(dev->udev,
2150 + usb_rcvbulkpipe(dev->udev,
2151 +@@ -157,6 +167,9 @@ static ssize_t lcd_read(struct file *file, char __user * buffer,
2152 + retval = bytes_read;
2153 + }
2154 +
2155 ++out_up_io:
2156 ++ up_read(&dev->io_rwsem);
2157 ++
2158 + return retval;
2159 + }
2160 +
2161 +@@ -236,11 +249,18 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer,
2162 + if (r < 0)
2163 + return -EINTR;
2164 +
2165 ++ down_read(&dev->io_rwsem);
2166 ++
2167 ++ if (dev->disconnected) {
2168 ++ retval = -ENODEV;
2169 ++ goto err_up_io;
2170 ++ }
2171 ++
2172 + /* create a urb, and a buffer for it, and copy the data to the urb */
2173 + urb = usb_alloc_urb(0, GFP_KERNEL);
2174 + if (!urb) {
2175 + retval = -ENOMEM;
2176 +- goto err_no_buf;
2177 ++ goto err_up_io;
2178 + }
2179 +
2180 + buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL,
2181 +@@ -277,6 +297,7 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer,
2182 + the USB core will eventually free it entirely */
2183 + usb_free_urb(urb);
2184 +
2185 ++ up_read(&dev->io_rwsem);
2186 + exit:
2187 + return count;
2188 + error_unanchor:
2189 +@@ -284,7 +305,8 @@ error_unanchor:
2190 + error:
2191 + usb_free_coherent(dev->udev, count, buf, urb->transfer_dma);
2192 + usb_free_urb(urb);
2193 +-err_no_buf:
2194 ++err_up_io:
2195 ++ up_read(&dev->io_rwsem);
2196 + up(&dev->limit_sem);
2197 + return retval;
2198 + }
2199 +@@ -325,6 +347,7 @@ static int lcd_probe(struct usb_interface *interface,
2200 + goto error;
2201 + kref_init(&dev->kref);
2202 + sema_init(&dev->limit_sem, USB_LCD_CONCURRENT_WRITES);
2203 ++ init_rwsem(&dev->io_rwsem);
2204 + init_usb_anchor(&dev->submitted);
2205 +
2206 + dev->udev = usb_get_dev(interface_to_usbdev(interface));
2207 +@@ -432,6 +455,12 @@ static void lcd_disconnect(struct usb_interface *interface)
2208 + /* give back our minor */
2209 + usb_deregister_dev(interface, &lcd_class);
2210 +
2211 ++ down_write(&dev->io_rwsem);
2212 ++ dev->disconnected = 1;
2213 ++ up_write(&dev->io_rwsem);
2214 ++
2215 ++ usb_kill_anchored_urbs(&dev->submitted);
2216 ++
2217 + /* decrement our usage count */
2218 + kref_put(&dev->kref, lcd_delete);
2219 +
2220 +diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
2221 +index 9744e5f996c1..2350502f9054 100644
2222 +--- a/drivers/usb/misc/yurex.c
2223 ++++ b/drivers/usb/misc/yurex.c
2224 +@@ -64,6 +64,7 @@ struct usb_yurex {
2225 +
2226 + struct kref kref;
2227 + struct mutex io_mutex;
2228 ++ unsigned long disconnected:1;
2229 + struct fasync_struct *async_queue;
2230 + wait_queue_head_t waitq;
2231 +
2232 +@@ -111,6 +112,7 @@ static void yurex_delete(struct kref *kref)
2233 + dev->int_buffer, dev->urb->transfer_dma);
2234 + usb_free_urb(dev->urb);
2235 + }
2236 ++ usb_put_intf(dev->interface);
2237 + usb_put_dev(dev->udev);
2238 + kfree(dev);
2239 + }
2240 +@@ -136,6 +138,7 @@ static void yurex_interrupt(struct urb *urb)
2241 + switch (status) {
2242 + case 0: /*success*/
2243 + break;
2244 ++ /* The device is terminated or messed up, give up */
2245 + case -EOVERFLOW:
2246 + dev_err(&dev->interface->dev,
2247 + "%s - overflow with length %d, actual length is %d\n",
2248 +@@ -144,12 +147,13 @@ static void yurex_interrupt(struct urb *urb)
2249 + case -ENOENT:
2250 + case -ESHUTDOWN:
2251 + case -EILSEQ:
2252 +- /* The device is terminated, clean up */
2253 ++ case -EPROTO:
2254 ++ case -ETIME:
2255 + return;
2256 + default:
2257 + dev_err(&dev->interface->dev,
2258 + "%s - unknown status received: %d\n", __func__, status);
2259 +- goto exit;
2260 ++ return;
2261 + }
2262 +
2263 + /* handle received message */
2264 +@@ -181,7 +185,6 @@ static void yurex_interrupt(struct urb *urb)
2265 + break;
2266 + }
2267 +
2268 +-exit:
2269 + retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
2270 + if (retval) {
2271 + dev_err(&dev->interface->dev, "%s - usb_submit_urb failed: %d\n",
2272 +@@ -208,7 +211,7 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_
2273 + init_waitqueue_head(&dev->waitq);
2274 +
2275 + dev->udev = usb_get_dev(interface_to_usbdev(interface));
2276 +- dev->interface = interface;
2277 ++ dev->interface = usb_get_intf(interface);
2278 +
2279 + /* set up the endpoint information */
2280 + iface_desc = interface->cur_altsetting;
2281 +@@ -325,8 +328,9 @@ static void yurex_disconnect(struct usb_interface *interface)
2282 +
2283 + /* prevent more I/O from starting */
2284 + usb_poison_urb(dev->urb);
2285 ++ usb_poison_urb(dev->cntl_urb);
2286 + mutex_lock(&dev->io_mutex);
2287 +- dev->interface = NULL;
2288 ++ dev->disconnected = 1;
2289 + mutex_unlock(&dev->io_mutex);
2290 +
2291 + /* wakeup waiters */
2292 +@@ -414,7 +418,7 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
2293 + dev = file->private_data;
2294 +
2295 + mutex_lock(&dev->io_mutex);
2296 +- if (!dev->interface) { /* already disconnected */
2297 ++ if (dev->disconnected) { /* already disconnected */
2298 + mutex_unlock(&dev->io_mutex);
2299 + return -ENODEV;
2300 + }
2301 +@@ -449,7 +453,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
2302 + goto error;
2303 +
2304 + mutex_lock(&dev->io_mutex);
2305 +- if (!dev->interface) { /* already disconnected */
2306 ++ if (dev->disconnected) { /* already disconnected */
2307 + mutex_unlock(&dev->io_mutex);
2308 + retval = -ENODEV;
2309 + goto error;
2310 +diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h
2311 +index 8c5fc12ad778..b8620aa6b72e 100644
2312 +--- a/drivers/usb/renesas_usbhs/common.h
2313 ++++ b/drivers/usb/renesas_usbhs/common.h
2314 +@@ -213,6 +213,7 @@ struct usbhs_priv;
2315 + /* DCPCTR */
2316 + #define BSTS (1 << 15) /* Buffer Status */
2317 + #define SUREQ (1 << 14) /* Sending SETUP Token */
2318 ++#define INBUFM (1 << 14) /* (PIPEnCTR) Transfer Buffer Monitor */
2319 + #define CSSTS (1 << 12) /* CSSTS Status */
2320 + #define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
2321 + #define SQCLR (1 << 8) /* Toggle Bit Clear */
2322 +diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
2323 +index 696560529e6a..f6a1ae8abb21 100644
2324 +--- a/drivers/usb/renesas_usbhs/fifo.c
2325 ++++ b/drivers/usb/renesas_usbhs/fifo.c
2326 +@@ -98,7 +98,7 @@ static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
2327 + list_del_init(&pkt->node);
2328 + }
2329 +
2330 +-static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
2331 ++struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
2332 + {
2333 + if (list_empty(&pipe->list))
2334 + return NULL;
2335 +diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h
2336 +index 8b98507d7abc..c1fb39252b23 100644
2337 +--- a/drivers/usb/renesas_usbhs/fifo.h
2338 ++++ b/drivers/usb/renesas_usbhs/fifo.h
2339 +@@ -106,5 +106,6 @@ void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
2340 + void *buf, int len, int zero, int sequence);
2341 + struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
2342 + void usbhs_pkt_start(struct usbhs_pipe *pipe);
2343 ++struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe);
2344 +
2345 + #endif /* RENESAS_USB_FIFO_H */
2346 +diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
2347 +index 5984fb134cf4..6898ca1ef98c 100644
2348 +--- a/drivers/usb/renesas_usbhs/mod_gadget.c
2349 ++++ b/drivers/usb/renesas_usbhs/mod_gadget.c
2350 +@@ -729,8 +729,7 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
2351 + struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
2352 + struct device *dev = usbhsg_gpriv_to_dev(gpriv);
2353 + unsigned long flags;
2354 +-
2355 +- usbhsg_pipe_disable(uep);
2356 ++ int ret = 0;
2357 +
2358 + dev_dbg(dev, "set halt %d (pipe %d)\n",
2359 + halt, usbhs_pipe_number(pipe));
2360 +@@ -738,6 +737,18 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
2361 + /******************** spin lock ********************/
2362 + usbhs_lock(priv, flags);
2363 +
2364 ++ /*
2365 ++ * According to usb_ep_set_halt()'s description, this function should
2366 ++ * return -EAGAIN if the IN endpoint has any queue or data. Note
2367 ++ * that the usbhs_pipe_is_dir_in() returns false if the pipe is an
2368 ++ * IN endpoint in the gadget mode.
2369 ++ */
2370 ++ if (!usbhs_pipe_is_dir_in(pipe) && (__usbhsf_pkt_get(pipe) ||
2371 ++ usbhs_pipe_contains_transmittable_data(pipe))) {
2372 ++ ret = -EAGAIN;
2373 ++ goto out;
2374 ++ }
2375 ++
2376 + if (halt)
2377 + usbhs_pipe_stall(pipe);
2378 + else
2379 +@@ -748,10 +759,11 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
2380 + else
2381 + usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE);
2382 +
2383 ++out:
2384 + usbhs_unlock(priv, flags);
2385 + /******************** spin unlock ******************/
2386 +
2387 +- return 0;
2388 ++ return ret;
2389 + }
2390 +
2391 + static int usbhsg_ep_set_halt(struct usb_ep *ep, int value)
2392 +diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c
2393 +index 9396a8c14af8..8db4ca7d5d45 100644
2394 +--- a/drivers/usb/renesas_usbhs/pipe.c
2395 ++++ b/drivers/usb/renesas_usbhs/pipe.c
2396 +@@ -286,6 +286,21 @@ int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe)
2397 + return -EBUSY;
2398 + }
2399 +
2400 ++bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe)
2401 ++{
2402 ++ u16 val;
2403 ++
2404 ++ /* Do not support for DCP pipe */
2405 ++ if (usbhs_pipe_is_dcp(pipe))
2406 ++ return false;
2407 ++
2408 ++ val = usbhsp_pipectrl_get(pipe);
2409 ++ if (val & INBUFM)
2410 ++ return true;
2411 ++
2412 ++ return false;
2413 ++}
2414 ++
2415 + /*
2416 + * PID ctrl
2417 + */
2418 +diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h
2419 +index 95185fdb29b1..e4144704ee02 100644
2420 +--- a/drivers/usb/renesas_usbhs/pipe.h
2421 ++++ b/drivers/usb/renesas_usbhs/pipe.h
2422 +@@ -90,6 +90,7 @@ void usbhs_pipe_init(struct usbhs_priv *priv,
2423 + int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe);
2424 + void usbhs_pipe_clear(struct usbhs_pipe *pipe);
2425 + int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe);
2426 ++bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe);
2427 + void usbhs_pipe_enable(struct usbhs_pipe *pipe);
2428 + void usbhs_pipe_disable(struct usbhs_pipe *pipe);
2429 + void usbhs_pipe_stall(struct usbhs_pipe *pipe);
2430 +diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
2431 +index 63ff1a4f2e41..f94d11615b45 100644
2432 +--- a/drivers/usb/serial/ftdi_sio.c
2433 ++++ b/drivers/usb/serial/ftdi_sio.c
2434 +@@ -1025,6 +1025,9 @@ static const struct usb_device_id id_table_combined[] = {
2435 + /* EZPrototypes devices */
2436 + { USB_DEVICE(EZPROTOTYPES_VID, HJELMSLUND_USB485_ISO_PID) },
2437 + { USB_DEVICE_INTERFACE_NUMBER(UNJO_VID, UNJO_ISODEBUG_V1_PID, 1) },
2438 ++ /* Sienna devices */
2439 ++ { USB_DEVICE(FTDI_VID, FTDI_SIENNA_PID) },
2440 ++ { USB_DEVICE(ECHELON_VID, ECHELON_U20_PID) },
2441 + { } /* Terminating entry */
2442 + };
2443 +
2444 +diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
2445 +index ed6b36674c15..2e8161f79b49 100644
2446 +--- a/drivers/usb/serial/ftdi_sio_ids.h
2447 ++++ b/drivers/usb/serial/ftdi_sio_ids.h
2448 +@@ -38,6 +38,9 @@
2449 +
2450 + #define FTDI_LUMEL_PD12_PID 0x6002
2451 +
2452 ++/* Sienna Serial Interface by Secyourit GmbH */
2453 ++#define FTDI_SIENNA_PID 0x8348
2454 ++
2455 + /* Cyber Cortex AV by Fabulous Silicon (http://fabuloussilicon.com) */
2456 + #define CYBER_CORTEX_AV_PID 0x8698
2457 +
2458 +@@ -687,6 +690,12 @@
2459 + #define BANDB_TTL3USB9M_PID 0xAC50
2460 + #define BANDB_ZZ_PROG1_USB_PID 0xBA02
2461 +
2462 ++/*
2463 ++ * Echelon USB Serial Interface
2464 ++ */
2465 ++#define ECHELON_VID 0x0920
2466 ++#define ECHELON_U20_PID 0x7500
2467 ++
2468 + /*
2469 + * Intrepid Control Systems (http://www.intrepidcs.com/) ValueCAN and NeoVI
2470 + */
2471 +diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
2472 +index 1f9414bdd649..185ef1d8c6cd 100644
2473 +--- a/drivers/usb/serial/keyspan.c
2474 ++++ b/drivers/usb/serial/keyspan.c
2475 +@@ -1250,8 +1250,8 @@ static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
2476 +
2477 + ep_desc = find_ep(serial, endpoint);
2478 + if (!ep_desc) {
2479 +- /* leak the urb, something's wrong and the callers don't care */
2480 +- return urb;
2481 ++ usb_free_urb(urb);
2482 ++ return NULL;
2483 + }
2484 + if (usb_endpoint_xfer_int(ep_desc)) {
2485 + ep_type_name = "INT";
2486 +diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
2487 +index 1bceb11f3782..00a6e62a68a8 100644
2488 +--- a/drivers/usb/serial/option.c
2489 ++++ b/drivers/usb/serial/option.c
2490 +@@ -421,6 +421,7 @@ static void option_instat_callback(struct urb *urb);
2491 + #define CINTERION_PRODUCT_PH8_AUDIO 0x0083
2492 + #define CINTERION_PRODUCT_AHXX_2RMNET 0x0084
2493 + #define CINTERION_PRODUCT_AHXX_AUDIO 0x0085
2494 ++#define CINTERION_PRODUCT_CLS8 0x00b0
2495 +
2496 + /* Olivetti products */
2497 + #define OLIVETTI_VENDOR_ID 0x0b3c
2498 +@@ -1149,6 +1150,14 @@ static const struct usb_device_id option_ids[] = {
2499 + .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) | RSVD(3) },
2500 + { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, TELIT_PRODUCT_LE922_USBCFG5, 0xff),
2501 + .driver_info = RSVD(0) | RSVD(1) | NCTRL(2) | RSVD(3) },
2502 ++ { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1050, 0xff), /* Telit FN980 (rmnet) */
2503 ++ .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) },
2504 ++ { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1051, 0xff), /* Telit FN980 (MBIM) */
2505 ++ .driver_info = NCTRL(0) | RSVD(1) },
2506 ++ { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1052, 0xff), /* Telit FN980 (RNDIS) */
2507 ++ .driver_info = NCTRL(2) | RSVD(3) },
2508 ++ { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1053, 0xff), /* Telit FN980 (ECM) */
2509 ++ .driver_info = NCTRL(0) | RSVD(1) },
2510 + { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910),
2511 + .driver_info = NCTRL(0) | RSVD(1) | RSVD(3) },
2512 + { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910_DUAL_MODEM),
2513 +@@ -1842,6 +1851,8 @@ static const struct usb_device_id option_ids[] = {
2514 + .driver_info = RSVD(4) },
2515 + { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX_2RMNET, 0xff) },
2516 + { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX_AUDIO, 0xff) },
2517 ++ { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_CLS8, 0xff),
2518 ++ .driver_info = RSVD(0) | RSVD(4) },
2519 + { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDM) },
2520 + { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDMNET) },
2521 + { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC25_MDM) },
2522 +diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
2523 +index 4a037b4a79cf..a894c0fdc04b 100644
2524 +--- a/drivers/usb/serial/usb-serial.c
2525 ++++ b/drivers/usb/serial/usb-serial.c
2526 +@@ -315,10 +315,7 @@ static void serial_cleanup(struct tty_struct *tty)
2527 + serial = port->serial;
2528 + owner = serial->type->driver.owner;
2529 +
2530 +- mutex_lock(&serial->disc_mutex);
2531 +- if (!serial->disconnected)
2532 +- usb_autopm_put_interface(serial->interface);
2533 +- mutex_unlock(&serial->disc_mutex);
2534 ++ usb_autopm_put_interface(serial->interface);
2535 +
2536 + usb_serial_put(serial);
2537 + module_put(owner);
2538 +diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
2539 +index 5133a0792eb0..f24374486623 100644
2540 +--- a/drivers/usb/usb-skeleton.c
2541 ++++ b/drivers/usb/usb-skeleton.c
2542 +@@ -63,6 +63,7 @@ struct usb_skel {
2543 + spinlock_t err_lock; /* lock for errors */
2544 + struct kref kref;
2545 + struct mutex io_mutex; /* synchronize I/O with disconnect */
2546 ++ unsigned long disconnected:1;
2547 + wait_queue_head_t bulk_in_wait; /* to wait for an ongoing read */
2548 + };
2549 + #define to_skel_dev(d) container_of(d, struct usb_skel, kref)
2550 +@@ -75,6 +76,7 @@ static void skel_delete(struct kref *kref)
2551 + struct usb_skel *dev = to_skel_dev(kref);
2552 +
2553 + usb_free_urb(dev->bulk_in_urb);
2554 ++ usb_put_intf(dev->interface);
2555 + usb_put_dev(dev->udev);
2556 + kfree(dev->bulk_in_buffer);
2557 + kfree(dev);
2558 +@@ -126,10 +128,7 @@ static int skel_release(struct inode *inode, struct file *file)
2559 + return -ENODEV;
2560 +
2561 + /* allow the device to be autosuspended */
2562 +- mutex_lock(&dev->io_mutex);
2563 +- if (dev->interface)
2564 +- usb_autopm_put_interface(dev->interface);
2565 +- mutex_unlock(&dev->io_mutex);
2566 ++ usb_autopm_put_interface(dev->interface);
2567 +
2568 + /* decrement the count on our device */
2569 + kref_put(&dev->kref, skel_delete);
2570 +@@ -241,7 +240,7 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count,
2571 + if (rv < 0)
2572 + return rv;
2573 +
2574 +- if (!dev->interface) { /* disconnect() was called */
2575 ++ if (dev->disconnected) { /* disconnect() was called */
2576 + rv = -ENODEV;
2577 + goto exit;
2578 + }
2579 +@@ -422,7 +421,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer,
2580 +
2581 + /* this lock makes sure we don't submit URBs to gone devices */
2582 + mutex_lock(&dev->io_mutex);
2583 +- if (!dev->interface) { /* disconnect() was called */
2584 ++ if (dev->disconnected) { /* disconnect() was called */
2585 + mutex_unlock(&dev->io_mutex);
2586 + retval = -ENODEV;
2587 + goto error;
2588 +@@ -509,7 +508,7 @@ static int skel_probe(struct usb_interface *interface,
2589 + init_waitqueue_head(&dev->bulk_in_wait);
2590 +
2591 + dev->udev = usb_get_dev(interface_to_usbdev(interface));
2592 +- dev->interface = interface;
2593 ++ dev->interface = usb_get_intf(interface);
2594 +
2595 + /* set up the endpoint information */
2596 + /* use only the first bulk-in and bulk-out endpoints */
2597 +@@ -582,7 +581,7 @@ static void skel_disconnect(struct usb_interface *interface)
2598 +
2599 + /* prevent more I/O from starting */
2600 + mutex_lock(&dev->io_mutex);
2601 +- dev->interface = NULL;
2602 ++ dev->disconnected = 1;
2603 + mutex_unlock(&dev->io_mutex);
2604 +
2605 + usb_kill_anchored_urbs(&dev->submitted);
2606 +diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
2607 +index 5098982e1a58..e5c162b05376 100644
2608 +--- a/drivers/watchdog/imx2_wdt.c
2609 ++++ b/drivers/watchdog/imx2_wdt.c
2610 +@@ -58,7 +58,7 @@
2611 +
2612 + #define IMX2_WDT_WMCR 0x08 /* Misc Register */
2613 +
2614 +-#define IMX2_WDT_MAX_TIME 128
2615 ++#define IMX2_WDT_MAX_TIME 128U
2616 + #define IMX2_WDT_DEFAULT_TIME 60 /* in seconds */
2617 +
2618 + #define WDOG_SEC_TO_COUNT(s) ((s * 2 - 1) << 8)
2619 +@@ -183,7 +183,7 @@ static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
2620 + {
2621 + unsigned int actual;
2622 +
2623 +- actual = min(new_timeout, wdog->max_hw_heartbeat_ms * 1000);
2624 ++ actual = min(new_timeout, IMX2_WDT_MAX_TIME);
2625 + __imx2_wdt_set_timeout(wdog, actual);
2626 + wdog->timeout = new_timeout;
2627 + return 0;
2628 +diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c
2629 +index 7494dbeb4409..db58aaa4dc59 100644
2630 +--- a/drivers/xen/pci.c
2631 ++++ b/drivers/xen/pci.c
2632 +@@ -29,6 +29,8 @@
2633 + #include "../pci/pci.h"
2634 + #ifdef CONFIG_PCI_MMCONFIG
2635 + #include <asm/pci_x86.h>
2636 ++
2637 ++static int xen_mcfg_late(void);
2638 + #endif
2639 +
2640 + static bool __read_mostly pci_seg_supported = true;
2641 +@@ -40,7 +42,18 @@ static int xen_add_device(struct device *dev)
2642 + #ifdef CONFIG_PCI_IOV
2643 + struct pci_dev *physfn = pci_dev->physfn;
2644 + #endif
2645 +-
2646 ++#ifdef CONFIG_PCI_MMCONFIG
2647 ++ static bool pci_mcfg_reserved = false;
2648 ++ /*
2649 ++ * Reserve MCFG areas in Xen on first invocation due to this being
2650 ++ * potentially called from inside of acpi_init immediately after
2651 ++ * MCFG table has been finally parsed.
2652 ++ */
2653 ++ if (!pci_mcfg_reserved) {
2654 ++ xen_mcfg_late();
2655 ++ pci_mcfg_reserved = true;
2656 ++ }
2657 ++#endif
2658 + if (pci_seg_supported) {
2659 + struct {
2660 + struct physdev_pci_device_add add;
2661 +@@ -213,7 +226,7 @@ static int __init register_xen_pci_notifier(void)
2662 + arch_initcall(register_xen_pci_notifier);
2663 +
2664 + #ifdef CONFIG_PCI_MMCONFIG
2665 +-static int __init xen_mcfg_late(void)
2666 ++static int xen_mcfg_late(void)
2667 + {
2668 + struct pci_mmcfg_region *cfg;
2669 + int rc;
2670 +@@ -252,8 +265,4 @@ static int __init xen_mcfg_late(void)
2671 + }
2672 + return 0;
2673 + }
2674 +-/*
2675 +- * Needs to be done after acpi_init which are subsys_initcall.
2676 +- */
2677 +-subsys_initcall_sync(xen_mcfg_late);
2678 + #endif
2679 +diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
2680 +index 79ff727254bb..e963b83afc71 100644
2681 +--- a/fs/9p/vfs_file.c
2682 ++++ b/fs/9p/vfs_file.c
2683 +@@ -528,6 +528,7 @@ v9fs_mmap_file_mmap(struct file *filp, struct vm_area_struct *vma)
2684 + v9inode = V9FS_I(inode);
2685 + mutex_lock(&v9inode->v_mutex);
2686 + if (!v9inode->writeback_fid &&
2687 ++ (vma->vm_flags & VM_SHARED) &&
2688 + (vma->vm_flags & VM_WRITE)) {
2689 + /*
2690 + * clone a fid and add it to writeback_fid
2691 +@@ -629,6 +630,8 @@ static void v9fs_mmap_vm_close(struct vm_area_struct *vma)
2692 + (vma->vm_end - vma->vm_start - 1),
2693 + };
2694 +
2695 ++ if (!(vma->vm_flags & VM_SHARED))
2696 ++ return;
2697 +
2698 + p9_debug(P9_DEBUG_VFS, "9p VMA close, %p, flushing", vma);
2699 +
2700 +diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
2701 +index 339fdf6355df..7fcddaaca8a5 100644
2702 +--- a/fs/ceph/inode.c
2703 ++++ b/fs/ceph/inode.c
2704 +@@ -800,7 +800,12 @@ static int fill_inode(struct inode *inode, struct page *locked_page,
2705 + ci->i_version = le64_to_cpu(info->version);
2706 + inode->i_version++;
2707 + inode->i_rdev = le32_to_cpu(info->rdev);
2708 +- inode->i_blkbits = fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
2709 ++ /* directories have fl_stripe_unit set to zero */
2710 ++ if (le32_to_cpu(info->layout.fl_stripe_unit))
2711 ++ inode->i_blkbits =
2712 ++ fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
2713 ++ else
2714 ++ inode->i_blkbits = CEPH_BLOCK_SHIFT;
2715 +
2716 + if ((new_version || (new_issued & CEPH_CAP_AUTH_SHARED)) &&
2717 + (issued & CEPH_CAP_AUTH_EXCL) == 0) {
2718 +diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
2719 +index 67cb9d078bfa..3139fbd4c34e 100644
2720 +--- a/fs/ceph/mds_client.c
2721 ++++ b/fs/ceph/mds_client.c
2722 +@@ -3410,7 +3410,9 @@ static void delayed_work(struct work_struct *work)
2723 + pr_info("mds%d hung\n", s->s_mds);
2724 + }
2725 + }
2726 +- if (s->s_state < CEPH_MDS_SESSION_OPEN) {
2727 ++ if (s->s_state == CEPH_MDS_SESSION_NEW ||
2728 ++ s->s_state == CEPH_MDS_SESSION_RESTARTING ||
2729 ++ s->s_state == CEPH_MDS_SESSION_REJECTED) {
2730 + /* this mds is failed or recovering, just wait */
2731 + ceph_put_mds_session(s);
2732 + continue;
2733 +diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
2734 +index e98e24eaa6a8..d6475dcce9df 100644
2735 +--- a/fs/cifs/dir.c
2736 ++++ b/fs/cifs/dir.c
2737 +@@ -830,10 +830,16 @@ lookup_out:
2738 + static int
2739 + cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
2740 + {
2741 ++ struct inode *inode;
2742 ++
2743 + if (flags & LOOKUP_RCU)
2744 + return -ECHILD;
2745 +
2746 + if (d_really_is_positive(direntry)) {
2747 ++ inode = d_inode(direntry);
2748 ++ if ((flags & LOOKUP_REVAL) && !CIFS_CACHE_READ(CIFS_I(inode)))
2749 ++ CIFS_I(inode)->time = 0; /* force reval */
2750 ++
2751 + if (cifs_revalidate_dentry(direntry))
2752 + return 0;
2753 + else {
2754 +@@ -844,7 +850,7 @@ cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
2755 + * attributes will have been updated by
2756 + * cifs_revalidate_dentry().
2757 + */
2758 +- if (IS_AUTOMOUNT(d_inode(direntry)) &&
2759 ++ if (IS_AUTOMOUNT(inode) &&
2760 + !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
2761 + spin_lock(&direntry->d_lock);
2762 + direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
2763 +diff --git a/fs/cifs/file.c b/fs/cifs/file.c
2764 +index df3ee0b6264f..3504ef015493 100644
2765 +--- a/fs/cifs/file.c
2766 ++++ b/fs/cifs/file.c
2767 +@@ -252,6 +252,12 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
2768 + rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
2769 + xid, fid);
2770 +
2771 ++ if (rc) {
2772 ++ server->ops->close(xid, tcon, fid);
2773 ++ if (rc == -ESTALE)
2774 ++ rc = -EOPENSTALE;
2775 ++ }
2776 ++
2777 + out:
2778 + kfree(buf);
2779 + return rc;
2780 +diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
2781 +index 786f67bee43a..b1c0961e6b3f 100644
2782 +--- a/fs/cifs/inode.c
2783 ++++ b/fs/cifs/inode.c
2784 +@@ -405,6 +405,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
2785 + /* if uniqueid is different, return error */
2786 + if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
2787 + CIFS_I(*pinode)->uniqueid != fattr.cf_uniqueid)) {
2788 ++ CIFS_I(*pinode)->time = 0; /* force reval */
2789 + rc = -ESTALE;
2790 + goto cgiiu_exit;
2791 + }
2792 +@@ -412,6 +413,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
2793 + /* if filetype is different, return error */
2794 + if (unlikely(((*pinode)->i_mode & S_IFMT) !=
2795 + (fattr.cf_mode & S_IFMT))) {
2796 ++ CIFS_I(*pinode)->time = 0; /* force reval */
2797 + rc = -ESTALE;
2798 + goto cgiiu_exit;
2799 + }
2800 +@@ -917,6 +919,7 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
2801 + /* if uniqueid is different, return error */
2802 + if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
2803 + CIFS_I(*inode)->uniqueid != fattr.cf_uniqueid)) {
2804 ++ CIFS_I(*inode)->time = 0; /* force reval */
2805 + rc = -ESTALE;
2806 + goto cgii_exit;
2807 + }
2808 +@@ -924,6 +927,7 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
2809 + /* if filetype is different, return error */
2810 + if (unlikely(((*inode)->i_mode & S_IFMT) !=
2811 + (fattr.cf_mode & S_IFMT))) {
2812 ++ CIFS_I(*inode)->time = 0; /* force reval */
2813 + rc = -ESTALE;
2814 + goto cgii_exit;
2815 + }
2816 +diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
2817 +index c5b6b7165489..d9aba9700726 100644
2818 +--- a/fs/fuse/cuse.c
2819 ++++ b/fs/fuse/cuse.c
2820 +@@ -513,6 +513,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)
2821 + rc = cuse_send_init(cc);
2822 + if (rc) {
2823 + fuse_dev_free(fud);
2824 ++ fuse_conn_put(&cc->fc);
2825 + return rc;
2826 + }
2827 + file->private_data = fud;
2828 +diff --git a/fs/libfs.c b/fs/libfs.c
2829 +index 9588780ad43e..9dc0e1ed8228 100644
2830 +--- a/fs/libfs.c
2831 ++++ b/fs/libfs.c
2832 +@@ -85,58 +85,47 @@ int dcache_dir_close(struct inode *inode, struct file *file)
2833 + EXPORT_SYMBOL(dcache_dir_close);
2834 +
2835 + /* parent is locked at least shared */
2836 +-static struct dentry *next_positive(struct dentry *parent,
2837 +- struct list_head *from,
2838 +- int count)
2839 ++/*
2840 ++ * Returns an element of siblings' list.
2841 ++ * We are looking for <count>th positive after <p>; if
2842 ++ * found, dentry is grabbed and passed to caller via *<res>.
2843 ++ * If no such element exists, the anchor of list is returned
2844 ++ * and *<res> is set to NULL.
2845 ++ */
2846 ++static struct list_head *scan_positives(struct dentry *cursor,
2847 ++ struct list_head *p,
2848 ++ loff_t count,
2849 ++ struct dentry **res)
2850 + {
2851 +- unsigned *seq = &parent->d_inode->i_dir_seq, n;
2852 +- struct dentry *res;
2853 +- struct list_head *p;
2854 +- bool skipped;
2855 +- int i;
2856 ++ struct dentry *dentry = cursor->d_parent, *found = NULL;
2857 +
2858 +-retry:
2859 +- i = count;
2860 +- skipped = false;
2861 +- n = smp_load_acquire(seq) & ~1;
2862 +- res = NULL;
2863 +- rcu_read_lock();
2864 +- for (p = from->next; p != &parent->d_subdirs; p = p->next) {
2865 ++ spin_lock(&dentry->d_lock);
2866 ++ while ((p = p->next) != &dentry->d_subdirs) {
2867 + struct dentry *d = list_entry(p, struct dentry, d_child);
2868 +- if (!simple_positive(d)) {
2869 +- skipped = true;
2870 +- } else if (!--i) {
2871 +- res = d;
2872 +- break;
2873 ++ // we must at least skip cursors, to avoid livelocks
2874 ++ if (d->d_flags & DCACHE_DENTRY_CURSOR)
2875 ++ continue;
2876 ++ if (simple_positive(d) && !--count) {
2877 ++ spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
2878 ++ if (simple_positive(d))
2879 ++ found = dget_dlock(d);
2880 ++ spin_unlock(&d->d_lock);
2881 ++ if (likely(found))
2882 ++ break;
2883 ++ count = 1;
2884 ++ }
2885 ++ if (need_resched()) {
2886 ++ list_move(&cursor->d_child, p);
2887 ++ p = &cursor->d_child;
2888 ++ spin_unlock(&dentry->d_lock);
2889 ++ cond_resched();
2890 ++ spin_lock(&dentry->d_lock);
2891 + }
2892 + }
2893 +- rcu_read_unlock();
2894 +- if (skipped) {
2895 +- smp_rmb();
2896 +- if (unlikely(*seq != n))
2897 +- goto retry;
2898 +- }
2899 +- return res;
2900 +-}
2901 +-
2902 +-static void move_cursor(struct dentry *cursor, struct list_head *after)
2903 +-{
2904 +- struct dentry *parent = cursor->d_parent;
2905 +- unsigned n, *seq = &parent->d_inode->i_dir_seq;
2906 +- spin_lock(&parent->d_lock);
2907 +- for (;;) {
2908 +- n = *seq;
2909 +- if (!(n & 1) && cmpxchg(seq, n, n + 1) == n)
2910 +- break;
2911 +- cpu_relax();
2912 +- }
2913 +- __list_del(cursor->d_child.prev, cursor->d_child.next);
2914 +- if (after)
2915 +- list_add(&cursor->d_child, after);
2916 +- else
2917 +- list_add_tail(&cursor->d_child, &parent->d_subdirs);
2918 +- smp_store_release(seq, n + 2);
2919 +- spin_unlock(&parent->d_lock);
2920 ++ spin_unlock(&dentry->d_lock);
2921 ++ dput(*res);
2922 ++ *res = found;
2923 ++ return p;
2924 + }
2925 +
2926 + loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
2927 +@@ -152,17 +141,28 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
2928 + return -EINVAL;
2929 + }
2930 + if (offset != file->f_pos) {
2931 ++ struct dentry *cursor = file->private_data;
2932 ++ struct dentry *to = NULL;
2933 ++ struct list_head *p;
2934 ++
2935 + file->f_pos = offset;
2936 +- if (file->f_pos >= 2) {
2937 +- struct dentry *cursor = file->private_data;
2938 +- struct dentry *to;
2939 +- loff_t n = file->f_pos - 2;
2940 +-
2941 +- inode_lock_shared(dentry->d_inode);
2942 +- to = next_positive(dentry, &dentry->d_subdirs, n);
2943 +- move_cursor(cursor, to ? &to->d_child : NULL);
2944 +- inode_unlock_shared(dentry->d_inode);
2945 ++ inode_lock_shared(dentry->d_inode);
2946 ++
2947 ++ if (file->f_pos > 2) {
2948 ++ p = scan_positives(cursor, &dentry->d_subdirs,
2949 ++ file->f_pos - 2, &to);
2950 ++ spin_lock(&dentry->d_lock);
2951 ++ list_move(&cursor->d_child, p);
2952 ++ spin_unlock(&dentry->d_lock);
2953 ++ } else {
2954 ++ spin_lock(&dentry->d_lock);
2955 ++ list_del_init(&cursor->d_child);
2956 ++ spin_unlock(&dentry->d_lock);
2957 + }
2958 ++
2959 ++ dput(to);
2960 ++
2961 ++ inode_unlock_shared(dentry->d_inode);
2962 + }
2963 + return offset;
2964 + }
2965 +@@ -184,25 +184,29 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
2966 + {
2967 + struct dentry *dentry = file->f_path.dentry;
2968 + struct dentry *cursor = file->private_data;
2969 +- struct list_head *p = &cursor->d_child;
2970 +- struct dentry *next;
2971 +- bool moved = false;
2972 ++ struct list_head *anchor = &dentry->d_subdirs;
2973 ++ struct dentry *next = NULL;
2974 ++ struct list_head *p;
2975 +
2976 + if (!dir_emit_dots(file, ctx))
2977 + return 0;
2978 +
2979 + if (ctx->pos == 2)
2980 +- p = &dentry->d_subdirs;
2981 +- while ((next = next_positive(dentry, p, 1)) != NULL) {
2982 ++ p = anchor;
2983 ++ else
2984 ++ p = &cursor->d_child;
2985 ++
2986 ++ while ((p = scan_positives(cursor, p, 1, &next)) != anchor) {
2987 + if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
2988 + d_inode(next)->i_ino, dt_type(d_inode(next))))
2989 + break;
2990 +- moved = true;
2991 +- p = &next->d_child;
2992 + ctx->pos++;
2993 + }
2994 +- if (moved)
2995 +- move_cursor(cursor, p);
2996 ++ spin_lock(&dentry->d_lock);
2997 ++ list_move_tail(&cursor->d_child, p);
2998 ++ spin_unlock(&dentry->d_lock);
2999 ++ dput(next);
3000 ++
3001 + return 0;
3002 + }
3003 + EXPORT_SYMBOL(dcache_readdir);
3004 +diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
3005 +index 5e2724a928ed..d7f8d5ce30e3 100644
3006 +--- a/fs/nfs/nfs4xdr.c
3007 ++++ b/fs/nfs/nfs4xdr.c
3008 +@@ -1123,7 +1123,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
3009 + } else
3010 + *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
3011 + }
3012 +- if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
3013 ++ if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
3014 + *p++ = cpu_to_be32(label->lfs);
3015 + *p++ = cpu_to_be32(label->pi);
3016 + *p++ = cpu_to_be32(label->len);
3017 +diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
3018 +index 67d589e0a49f..b16ca13c11d5 100644
3019 +--- a/fs/xfs/xfs_super.c
3020 ++++ b/fs/xfs/xfs_super.c
3021 +@@ -1674,6 +1674,7 @@ xfs_fs_fill_super(
3022 + out_close_devices:
3023 + xfs_close_devices(mp);
3024 + out_free_fsname:
3025 ++ sb->s_fs_info = NULL;
3026 + xfs_free_fsname(mp);
3027 + kfree(mp);
3028 + out:
3029 +@@ -1691,6 +1692,10 @@ xfs_fs_put_super(
3030 + {
3031 + struct xfs_mount *mp = XFS_M(sb);
3032 +
3033 ++ /* if ->fill_super failed, we have no mount to tear down */
3034 ++ if (!sb->s_fs_info)
3035 ++ return;
3036 ++
3037 + xfs_notice(mp, "Unmounting Filesystem");
3038 + xfs_filestream_unmount(mp);
3039 + xfs_unmountfs(mp);
3040 +@@ -1700,6 +1705,8 @@ xfs_fs_put_super(
3041 + xfs_destroy_percpu_counters(mp);
3042 + xfs_destroy_mount_workqueues(mp);
3043 + xfs_close_devices(mp);
3044 ++
3045 ++ sb->s_fs_info = NULL;
3046 + xfs_free_fsname(mp);
3047 + kfree(mp);
3048 + }
3049 +@@ -1719,6 +1726,9 @@ xfs_fs_nr_cached_objects(
3050 + struct super_block *sb,
3051 + struct shrink_control *sc)
3052 + {
3053 ++ /* Paranoia: catch incorrect calls during mount setup or teardown */
3054 ++ if (WARN_ON_ONCE(!sb->s_fs_info))
3055 ++ return 0;
3056 + return xfs_reclaim_inodes_count(XFS_M(sb));
3057 + }
3058 +
3059 +diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
3060 +index a80516fd65c8..d3417c18ee2f 100644
3061 +--- a/include/linux/ieee80211.h
3062 ++++ b/include/linux/ieee80211.h
3063 +@@ -2630,4 +2630,57 @@ static inline bool ieee80211_action_contains_tpc(struct sk_buff *skb)
3064 + return true;
3065 + }
3066 +
3067 ++struct element {
3068 ++ u8 id;
3069 ++ u8 datalen;
3070 ++ u8 data[];
3071 ++} __packed;
3072 ++
3073 ++/* element iteration helpers */
3074 ++#define for_each_element(_elem, _data, _datalen) \
3075 ++ for (_elem = (const struct element *)(_data); \
3076 ++ (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
3077 ++ (int)sizeof(*_elem) && \
3078 ++ (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
3079 ++ (int)sizeof(*_elem) + _elem->datalen; \
3080 ++ _elem = (const struct element *)(_elem->data + _elem->datalen))
3081 ++
3082 ++#define for_each_element_id(element, _id, data, datalen) \
3083 ++ for_each_element(element, data, datalen) \
3084 ++ if (element->id == (_id))
3085 ++
3086 ++#define for_each_element_extid(element, extid, data, datalen) \
3087 ++ for_each_element(element, data, datalen) \
3088 ++ if (element->id == WLAN_EID_EXTENSION && \
3089 ++ element->datalen > 0 && \
3090 ++ element->data[0] == (extid))
3091 ++
3092 ++#define for_each_subelement(sub, element) \
3093 ++ for_each_element(sub, (element)->data, (element)->datalen)
3094 ++
3095 ++#define for_each_subelement_id(sub, id, element) \
3096 ++ for_each_element_id(sub, id, (element)->data, (element)->datalen)
3097 ++
3098 ++#define for_each_subelement_extid(sub, extid, element) \
3099 ++ for_each_element_extid(sub, extid, (element)->data, (element)->datalen)
3100 ++
3101 ++/**
3102 ++ * for_each_element_completed - determine if element parsing consumed all data
3103 ++ * @element: element pointer after for_each_element() or friends
3104 ++ * @data: same data pointer as passed to for_each_element() or friends
3105 ++ * @datalen: same data length as passed to for_each_element() or friends
3106 ++ *
3107 ++ * This function returns %true if all the data was parsed or considered
3108 ++ * while walking the elements. Only use this if your for_each_element()
3109 ++ * loop cannot be broken out of, otherwise it always returns %false.
3110 ++ *
3111 ++ * If some data was malformed, this returns %false since the last parsed
3112 ++ * element will not fill the whole remaining data.
3113 ++ */
3114 ++static inline bool for_each_element_completed(const struct element *element,
3115 ++ const void *data, size_t datalen)
3116 ++{
3117 ++ return (const u8 *)element == (const u8 *)data + datalen;
3118 ++}
3119 ++
3120 + #endif /* LINUX_IEEE80211_H */
3121 +diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
3122 +index f60d755f7ac6..ab9fa975f880 100644
3123 +--- a/include/sound/soc-dapm.h
3124 ++++ b/include/sound/soc-dapm.h
3125 +@@ -339,6 +339,8 @@ struct device;
3126 + #define SND_SOC_DAPM_WILL_PMD 0x80 /* called at start of sequence */
3127 + #define SND_SOC_DAPM_PRE_POST_PMD \
3128 + (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD)
3129 ++#define SND_SOC_DAPM_PRE_POST_PMU \
3130 ++ (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU)
3131 +
3132 + /* convenience event type detection */
3133 + #define SND_SOC_DAPM_EVENT_ON(e) \
3134 +diff --git a/kernel/elfcore.c b/kernel/elfcore.c
3135 +index e556751d15d9..a2b29b9bdfcb 100644
3136 +--- a/kernel/elfcore.c
3137 ++++ b/kernel/elfcore.c
3138 +@@ -2,6 +2,7 @@
3139 + #include <linux/fs.h>
3140 + #include <linux/mm.h>
3141 + #include <linux/binfmts.h>
3142 ++#include <linux/elfcore.h>
3143 +
3144 + Elf_Half __weak elf_core_extra_phdrs(void)
3145 + {
3146 +diff --git a/kernel/fork.c b/kernel/fork.c
3147 +index 1c21d13a3874..288504431a53 100644
3148 +--- a/kernel/fork.c
3149 ++++ b/kernel/fork.c
3150 +@@ -2356,7 +2356,7 @@ int sysctl_max_threads(struct ctl_table *table, int write,
3151 + struct ctl_table t;
3152 + int ret;
3153 + int threads = max_threads;
3154 +- int min = MIN_THREADS;
3155 ++ int min = 1;
3156 + int max = MAX_THREADS;
3157 +
3158 + t = *table;
3159 +@@ -2368,7 +2368,7 @@ int sysctl_max_threads(struct ctl_table *table, int write,
3160 + if (ret || !write)
3161 + return ret;
3162 +
3163 +- set_max_threads(threads);
3164 ++ max_threads = threads;
3165 +
3166 + return 0;
3167 + }
3168 +diff --git a/kernel/panic.c b/kernel/panic.c
3169 +index eb7bc6d60927..89198dca0180 100644
3170 +--- a/kernel/panic.c
3171 ++++ b/kernel/panic.c
3172 +@@ -144,6 +144,7 @@ void panic(const char *fmt, ...)
3173 + * after setting panic_cpu) from invoking panic() again.
3174 + */
3175 + local_irq_disable();
3176 ++ preempt_disable_notrace();
3177 +
3178 + /*
3179 + * It's possible to come here directly from a panic-assertion and
3180 +diff --git a/kernel/sched/core.c b/kernel/sched/core.c
3181 +index 63be0bcfa286..82cec9a666e7 100644
3182 +--- a/kernel/sched/core.c
3183 ++++ b/kernel/sched/core.c
3184 +@@ -1162,7 +1162,8 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
3185 + if (cpumask_equal(&p->cpus_allowed, new_mask))
3186 + goto out;
3187 +
3188 +- if (!cpumask_intersects(new_mask, cpu_valid_mask)) {
3189 ++ dest_cpu = cpumask_any_and(cpu_valid_mask, new_mask);
3190 ++ if (dest_cpu >= nr_cpu_ids) {
3191 + ret = -EINVAL;
3192 + goto out;
3193 + }
3194 +@@ -1183,7 +1184,6 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
3195 + if (cpumask_test_cpu(task_cpu(p), new_mask))
3196 + goto out;
3197 +
3198 +- dest_cpu = cpumask_any_and(cpu_valid_mask, new_mask);
3199 + if (task_running(rq, p) || p->state == TASK_WAKING) {
3200 + struct migration_arg arg = { p, dest_cpu };
3201 + /* Need help from migration thread: drop lock and wait. */
3202 +diff --git a/kernel/time/timer.c b/kernel/time/timer.c
3203 +index b625cc7fcc1c..b5603248d841 100644
3204 +--- a/kernel/time/timer.c
3205 ++++ b/kernel/time/timer.c
3206 +@@ -1586,21 +1586,23 @@ void timer_clear_idle(void)
3207 + static int collect_expired_timers(struct timer_base *base,
3208 + struct hlist_head *heads)
3209 + {
3210 ++ unsigned long now = READ_ONCE(jiffies);
3211 ++
3212 + /*
3213 + * NOHZ optimization. After a long idle sleep we need to forward the
3214 + * base to current jiffies. Avoid a loop by searching the bitfield for
3215 + * the next expiring timer.
3216 + */
3217 +- if ((long)(jiffies - base->clk) > 2) {
3218 ++ if ((long)(now - base->clk) > 2) {
3219 + unsigned long next = __next_timer_interrupt(base);
3220 +
3221 + /*
3222 + * If the next timer is ahead of time forward to current
3223 + * jiffies, otherwise forward to the next expiry time:
3224 + */
3225 +- if (time_after(next, jiffies)) {
3226 ++ if (time_after(next, now)) {
3227 + /* The call site will increment clock! */
3228 +- base->clk = jiffies - 1;
3229 ++ base->clk = now - 1;
3230 + return 0;
3231 + }
3232 + base->clk = next;
3233 +diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
3234 +index 70b82f4fd417..827ba2caea09 100644
3235 +--- a/kernel/trace/trace.c
3236 ++++ b/kernel/trace/trace.c
3237 +@@ -3700,9 +3700,14 @@ static int show_traces_open(struct inode *inode, struct file *file)
3238 + if (tracing_disabled)
3239 + return -ENODEV;
3240 +
3241 ++ if (trace_array_get(tr) < 0)
3242 ++ return -ENODEV;
3243 ++
3244 + ret = seq_open(file, &show_traces_seq_ops);
3245 +- if (ret)
3246 ++ if (ret) {
3247 ++ trace_array_put(tr);
3248 + return ret;
3249 ++ }
3250 +
3251 + m = file->private_data;
3252 + m->private = tr;
3253 +@@ -3710,6 +3715,14 @@ static int show_traces_open(struct inode *inode, struct file *file)
3254 + return 0;
3255 + }
3256 +
3257 ++static int show_traces_release(struct inode *inode, struct file *file)
3258 ++{
3259 ++ struct trace_array *tr = inode->i_private;
3260 ++
3261 ++ trace_array_put(tr);
3262 ++ return seq_release(inode, file);
3263 ++}
3264 ++
3265 + static ssize_t
3266 + tracing_write_stub(struct file *filp, const char __user *ubuf,
3267 + size_t count, loff_t *ppos)
3268 +@@ -3740,8 +3753,8 @@ static const struct file_operations tracing_fops = {
3269 + static const struct file_operations show_traces_fops = {
3270 + .open = show_traces_open,
3271 + .read = seq_read,
3272 +- .release = seq_release,
3273 + .llseek = seq_lseek,
3274 ++ .release = show_traces_release,
3275 + };
3276 +
3277 + static ssize_t
3278 +diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
3279 +index f00b0131c8f9..5fe23f0ee7db 100644
3280 +--- a/kernel/trace/trace_hwlat.c
3281 ++++ b/kernel/trace/trace_hwlat.c
3282 +@@ -151,7 +151,7 @@ void trace_hwlat_callback(bool enter)
3283 + if (enter)
3284 + nmi_ts_start = time_get();
3285 + else
3286 +- nmi_total_ts = time_get() - nmi_ts_start;
3287 ++ nmi_total_ts += time_get() - nmi_ts_start;
3288 + }
3289 +
3290 + if (enter)
3291 +@@ -257,6 +257,8 @@ static int get_sample(void)
3292 + /* Keep a running maximum ever recorded hardware latency */
3293 + if (sample > tr->max_latency)
3294 + tr->max_latency = sample;
3295 ++ if (outer_sample > tr->max_latency)
3296 ++ tr->max_latency = outer_sample;
3297 + }
3298 +
3299 + out:
3300 +diff --git a/mm/usercopy.c b/mm/usercopy.c
3301 +index 7683c22551ff..c2de343baad4 100644
3302 +--- a/mm/usercopy.c
3303 ++++ b/mm/usercopy.c
3304 +@@ -15,6 +15,7 @@
3305 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3306 +
3307 + #include <linux/mm.h>
3308 ++#include <linux/highmem.h>
3309 + #include <linux/slab.h>
3310 + #include <asm/sections.h>
3311 +
3312 +@@ -217,7 +218,12 @@ static inline const char *check_heap_object(const void *ptr, unsigned long n,
3313 + if (!virt_addr_valid(ptr))
3314 + return NULL;
3315 +
3316 +- page = virt_to_head_page(ptr);
3317 ++ /*
3318 ++ * When CONFIG_HIGHMEM=y, kmap_to_page() will give either the
3319 ++ * highmem page or fallback to virt_to_page(). The following
3320 ++ * is effectively a highmem-aware virt_to_head_page().
3321 ++ */
3322 ++ page = compound_head(kmap_to_page((void *)ptr));
3323 +
3324 + /* Check slab allocator for flags and size. */
3325 + if (PageSlab(page))
3326 +diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
3327 +index d6e629315771..7aa1ca7ec638 100644
3328 +--- a/net/wireless/nl80211.c
3329 ++++ b/net/wireless/nl80211.c
3330 +@@ -213,6 +213,36 @@ cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
3331 + return __cfg80211_rdev_from_attrs(netns, info->attrs);
3332 + }
3333 +
3334 ++static int validate_beacon_head(const struct nlattr *attr)
3335 ++{
3336 ++ const u8 *data = nla_data(attr);
3337 ++ unsigned int len = nla_len(attr);
3338 ++ const struct element *elem;
3339 ++ const struct ieee80211_mgmt *mgmt = (void *)data;
3340 ++ unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
3341 ++ u.beacon.variable);
3342 ++
3343 ++ if (len < fixedlen)
3344 ++ goto err;
3345 ++
3346 ++ if (ieee80211_hdrlen(mgmt->frame_control) !=
3347 ++ offsetof(struct ieee80211_mgmt, u.beacon))
3348 ++ goto err;
3349 ++
3350 ++ data += fixedlen;
3351 ++ len -= fixedlen;
3352 ++
3353 ++ for_each_element(elem, data, len) {
3354 ++ /* nothing */
3355 ++ }
3356 ++
3357 ++ if (for_each_element_completed(elem, data, len))
3358 ++ return 0;
3359 ++
3360 ++err:
3361 ++ return -EINVAL;
3362 ++}
3363 ++
3364 + /* policy for the attributes */
3365 + static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
3366 + [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
3367 +@@ -2069,6 +2099,8 @@ static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
3368 +
3369 + control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
3370 +
3371 ++ memset(chandef, 0, sizeof(*chandef));
3372 ++
3373 + chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
3374 + chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
3375 + chandef->center_freq1 = control_freq;
3376 +@@ -2538,7 +2570,7 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
3377 +
3378 + if (rdev->ops->get_channel) {
3379 + int ret;
3380 +- struct cfg80211_chan_def chandef;
3381 ++ struct cfg80211_chan_def chandef = {};
3382 +
3383 + ret = rdev_get_channel(rdev, wdev, &chandef);
3384 + if (ret == 0) {
3385 +@@ -3678,6 +3710,11 @@ static int nl80211_parse_beacon(struct nlattr *attrs[],
3386 + memset(bcn, 0, sizeof(*bcn));
3387 +
3388 + if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3389 ++ int ret = validate_beacon_head(attrs[NL80211_ATTR_BEACON_HEAD]);
3390 ++
3391 ++ if (ret)
3392 ++ return ret;
3393 ++
3394 + bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3395 + bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
3396 + if (!bcn->head_len)
3397 +diff --git a/net/wireless/reg.c b/net/wireless/reg.c
3398 +index d1378340d590..44befe9f9ff0 100644
3399 +--- a/net/wireless/reg.c
3400 ++++ b/net/wireless/reg.c
3401 +@@ -1564,7 +1564,7 @@ static void reg_call_notifier(struct wiphy *wiphy,
3402 +
3403 + static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev)
3404 + {
3405 +- struct cfg80211_chan_def chandef;
3406 ++ struct cfg80211_chan_def chandef = {};
3407 + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
3408 + enum nl80211_iftype iftype;
3409 +
3410 +diff --git a/net/wireless/scan.c b/net/wireless/scan.c
3411 +index 435f904c1be5..c60be11b5e08 100644
3412 +--- a/net/wireless/scan.c
3413 ++++ b/net/wireless/scan.c
3414 +@@ -407,6 +407,8 @@ const u8 *cfg80211_find_ie_match(u8 eid, const u8 *ies, int len,
3415 + const u8 *match, int match_len,
3416 + int match_offset)
3417 + {
3418 ++ const struct element *elem;
3419 ++
3420 + /* match_offset can't be smaller than 2, unless match_len is
3421 + * zero, in which case match_offset must be zero as well.
3422 + */
3423 +@@ -414,14 +416,10 @@ const u8 *cfg80211_find_ie_match(u8 eid, const u8 *ies, int len,
3424 + (!match_len && match_offset)))
3425 + return NULL;
3426 +
3427 +- while (len >= 2 && len >= ies[1] + 2) {
3428 +- if ((ies[0] == eid) &&
3429 +- (ies[1] + 2 >= match_offset + match_len) &&
3430 +- !memcmp(ies + match_offset, match, match_len))
3431 +- return ies;
3432 +-
3433 +- len -= ies[1] + 2;
3434 +- ies += ies[1] + 2;
3435 ++ for_each_element_id(elem, eid, ies, len) {
3436 ++ if (elem->datalen >= match_offset - 2 + match_len &&
3437 ++ !memcmp(elem->data + match_offset - 2, match, match_len))
3438 ++ return (void *)elem;
3439 + }
3440 +
3441 + return NULL;
3442 +diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
3443 +index a220156cf217..b3baa34714e3 100644
3444 +--- a/net/wireless/wext-compat.c
3445 ++++ b/net/wireless/wext-compat.c
3446 +@@ -799,7 +799,7 @@ static int cfg80211_wext_giwfreq(struct net_device *dev,
3447 + {
3448 + struct wireless_dev *wdev = dev->ieee80211_ptr;
3449 + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
3450 +- struct cfg80211_chan_def chandef;
3451 ++ struct cfg80211_chan_def chandef = {};
3452 + int ret;
3453 +
3454 + switch (wdev->iftype) {
3455 +diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
3456 +index 20e66291ca99..5155c343406e 100644
3457 +--- a/security/integrity/ima/ima_crypto.c
3458 ++++ b/security/integrity/ima/ima_crypto.c
3459 +@@ -298,8 +298,11 @@ static int ima_calc_file_hash_atfm(struct file *file,
3460 + rbuf_len = min_t(loff_t, i_size - offset, rbuf_size[active]);
3461 + rc = integrity_kernel_read(file, offset, rbuf[active],
3462 + rbuf_len);
3463 +- if (rc != rbuf_len)
3464 ++ if (rc != rbuf_len) {
3465 ++ if (rc >= 0)
3466 ++ rc = -EINVAL;
3467 + goto out3;
3468 ++ }
3469 +
3470 + if (rbuf[1] && offset) {
3471 + /* Using two buffers, and it is not the first
3472 +diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
3473 +index d81ac4e499aa..7406ea5c9a4f 100644
3474 +--- a/sound/soc/codecs/sgtl5000.c
3475 ++++ b/sound/soc/codecs/sgtl5000.c
3476 +@@ -35,6 +35,13 @@
3477 + #define SGTL5000_DAP_REG_OFFSET 0x0100
3478 + #define SGTL5000_MAX_REG_OFFSET 0x013A
3479 +
3480 ++/* Delay for the VAG ramp up */
3481 ++#define SGTL5000_VAG_POWERUP_DELAY 500 /* ms */
3482 ++/* Delay for the VAG ramp down */
3483 ++#define SGTL5000_VAG_POWERDOWN_DELAY 500 /* ms */
3484 ++
3485 ++#define SGTL5000_OUTPUTS_MUTE (SGTL5000_HP_MUTE | SGTL5000_LINE_OUT_MUTE)
3486 ++
3487 + /* default value of sgtl5000 registers */
3488 + static const struct reg_default sgtl5000_reg_defaults[] = {
3489 + { SGTL5000_CHIP_DIG_POWER, 0x0000 },
3490 +@@ -99,6 +106,13 @@ enum sgtl5000_micbias_resistor {
3491 + SGTL5000_MICBIAS_8K = 8,
3492 + };
3493 +
3494 ++enum {
3495 ++ HP_POWER_EVENT,
3496 ++ DAC_POWER_EVENT,
3497 ++ ADC_POWER_EVENT,
3498 ++ LAST_POWER_EVENT = ADC_POWER_EVENT
3499 ++};
3500 ++
3501 + /* sgtl5000 private structure in codec */
3502 + struct sgtl5000_priv {
3503 + int sysclk; /* sysclk rate */
3504 +@@ -111,8 +125,117 @@ struct sgtl5000_priv {
3505 + int revision;
3506 + u8 micbias_resistor;
3507 + u8 micbias_voltage;
3508 ++ u16 mute_state[LAST_POWER_EVENT + 1];
3509 + };
3510 +
3511 ++static inline int hp_sel_input(struct snd_soc_component *component)
3512 ++{
3513 ++ unsigned int ana_reg = 0;
3514 ++
3515 ++ snd_soc_component_read(component, SGTL5000_CHIP_ANA_CTRL, &ana_reg);
3516 ++
3517 ++ return (ana_reg & SGTL5000_HP_SEL_MASK) >> SGTL5000_HP_SEL_SHIFT;
3518 ++}
3519 ++
3520 ++static inline u16 mute_output(struct snd_soc_component *component,
3521 ++ u16 mute_mask)
3522 ++{
3523 ++ unsigned int mute_reg = 0;
3524 ++
3525 ++ snd_soc_component_read(component, SGTL5000_CHIP_ANA_CTRL, &mute_reg);
3526 ++
3527 ++ snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
3528 ++ mute_mask, mute_mask);
3529 ++ return mute_reg;
3530 ++}
3531 ++
3532 ++static inline void restore_output(struct snd_soc_component *component,
3533 ++ u16 mute_mask, u16 mute_reg)
3534 ++{
3535 ++ snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
3536 ++ mute_mask, mute_reg);
3537 ++}
3538 ++
3539 ++static void vag_power_on(struct snd_soc_component *component, u32 source)
3540 ++{
3541 ++ unsigned int ana_reg = 0;
3542 ++
3543 ++ snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER, &ana_reg);
3544 ++
3545 ++ if (ana_reg & SGTL5000_VAG_POWERUP)
3546 ++ return;
3547 ++
3548 ++ snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
3549 ++ SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
3550 ++
3551 ++ /* When VAG powering on to get local loop from Line-In, the sleep
3552 ++ * is required to avoid loud pop.
3553 ++ */
3554 ++ if (hp_sel_input(component) == SGTL5000_HP_SEL_LINE_IN &&
3555 ++ source == HP_POWER_EVENT)
3556 ++ msleep(SGTL5000_VAG_POWERUP_DELAY);
3557 ++}
3558 ++
3559 ++static int vag_power_consumers(struct snd_soc_component *component,
3560 ++ u16 ana_pwr_reg, u32 source)
3561 ++{
3562 ++ int consumers = 0;
3563 ++
3564 ++ /* count dac/adc consumers unconditional */
3565 ++ if (ana_pwr_reg & SGTL5000_DAC_POWERUP)
3566 ++ consumers++;
3567 ++ if (ana_pwr_reg & SGTL5000_ADC_POWERUP)
3568 ++ consumers++;
3569 ++
3570 ++ /*
3571 ++ * If the event comes from HP and Line-In is selected,
3572 ++ * current action is 'DAC to be powered down'.
3573 ++ * As HP_POWERUP is not set when HP muxed to line-in,
3574 ++ * we need to keep VAG power ON.
3575 ++ */
3576 ++ if (source == HP_POWER_EVENT) {
3577 ++ if (hp_sel_input(component) == SGTL5000_HP_SEL_LINE_IN)
3578 ++ consumers++;
3579 ++ } else {
3580 ++ if (ana_pwr_reg & SGTL5000_HP_POWERUP)
3581 ++ consumers++;
3582 ++ }
3583 ++
3584 ++ return consumers;
3585 ++}
3586 ++
3587 ++static void vag_power_off(struct snd_soc_component *component, u32 source)
3588 ++{
3589 ++ unsigned int ana_pwr = SGTL5000_VAG_POWERUP;
3590 ++
3591 ++ snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER, &ana_pwr);
3592 ++
3593 ++ if (!(ana_pwr & SGTL5000_VAG_POWERUP))
3594 ++ return;
3595 ++
3596 ++ /*
3597 ++ * This function calls when any of VAG power consumers is disappearing.
3598 ++ * Thus, if there is more than one consumer at the moment, as minimum
3599 ++ * one consumer will definitely stay after the end of the current
3600 ++ * event.
3601 ++ * Don't clear VAG_POWERUP if 2 or more consumers of VAG present:
3602 ++ * - LINE_IN (for HP events) / HP (for DAC/ADC events)
3603 ++ * - DAC
3604 ++ * - ADC
3605 ++ * (the current consumer is disappearing right now)
3606 ++ */
3607 ++ if (vag_power_consumers(component, ana_pwr, source) >= 2)
3608 ++ return;
3609 ++
3610 ++ snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
3611 ++ SGTL5000_VAG_POWERUP, 0);
3612 ++ /* In power down case, we need wait 400-1000 ms
3613 ++ * when VAG fully ramped down.
3614 ++ * As longer we wait, as smaller pop we've got.
3615 ++ */
3616 ++ msleep(SGTL5000_VAG_POWERDOWN_DELAY);
3617 ++}
3618 ++
3619 + /*
3620 + * mic_bias power on/off share the same register bits with
3621 + * output impedance of mic bias, when power on mic bias, we
3622 +@@ -144,36 +267,46 @@ static int mic_bias_event(struct snd_soc_dapm_widget *w,
3623 + return 0;
3624 + }
3625 +
3626 +-/*
3627 +- * As manual described, ADC/DAC only works when VAG powerup,
3628 +- * So enabled VAG before ADC/DAC up.
3629 +- * In power down case, we need wait 400ms when vag fully ramped down.
3630 +- */
3631 +-static int power_vag_event(struct snd_soc_dapm_widget *w,
3632 +- struct snd_kcontrol *kcontrol, int event)
3633 ++static int vag_and_mute_control(struct snd_soc_component *component,
3634 ++ int event, int event_source)
3635 + {
3636 +- struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
3637 +- const u32 mask = SGTL5000_DAC_POWERUP | SGTL5000_ADC_POWERUP;
3638 ++ static const u16 mute_mask[] = {
3639 ++ /*
3640 ++ * Mask for HP_POWER_EVENT.
3641 ++ * Muxing Headphones have to be wrapped with mute/unmute
3642 ++ * headphones only.
3643 ++ */
3644 ++ SGTL5000_HP_MUTE,
3645 ++ /*
3646 ++ * Masks for DAC_POWER_EVENT/ADC_POWER_EVENT.
3647 ++ * Muxing DAC or ADC block have to be wrapped with mute/unmute
3648 ++ * both headphones and line-out.
3649 ++ */
3650 ++ SGTL5000_OUTPUTS_MUTE,
3651 ++ SGTL5000_OUTPUTS_MUTE
3652 ++ };
3653 ++
3654 ++ struct sgtl5000_priv *sgtl5000 =
3655 ++ snd_soc_component_get_drvdata(component);
3656 +
3657 + switch (event) {
3658 ++ case SND_SOC_DAPM_PRE_PMU:
3659 ++ sgtl5000->mute_state[event_source] =
3660 ++ mute_output(component, mute_mask[event_source]);
3661 ++ break;
3662 + case SND_SOC_DAPM_POST_PMU:
3663 +- snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
3664 +- SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
3665 +- msleep(400);
3666 ++ vag_power_on(component, event_source);
3667 ++ restore_output(component, mute_mask[event_source],
3668 ++ sgtl5000->mute_state[event_source]);
3669 + break;
3670 +-
3671 + case SND_SOC_DAPM_PRE_PMD:
3672 +- /*
3673 +- * Don't clear VAG_POWERUP, when both DAC and ADC are
3674 +- * operational to prevent inadvertently starving the
3675 +- * other one of them.
3676 +- */
3677 +- if ((snd_soc_read(codec, SGTL5000_CHIP_ANA_POWER) &
3678 +- mask) != mask) {
3679 +- snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
3680 +- SGTL5000_VAG_POWERUP, 0);
3681 +- msleep(400);
3682 +- }
3683 ++ sgtl5000->mute_state[event_source] =
3684 ++ mute_output(component, mute_mask[event_source]);
3685 ++ vag_power_off(component, event_source);
3686 ++ break;
3687 ++ case SND_SOC_DAPM_POST_PMD:
3688 ++ restore_output(component, mute_mask[event_source],
3689 ++ sgtl5000->mute_state[event_source]);
3690 + break;
3691 + default:
3692 + break;
3693 +@@ -182,6 +315,41 @@ static int power_vag_event(struct snd_soc_dapm_widget *w,
3694 + return 0;
3695 + }
3696 +
3697 ++/*
3698 ++ * Mute Headphone when power it up/down.
3699 ++ * Control VAG power on HP power path.
3700 ++ */
3701 ++static int headphone_pga_event(struct snd_soc_dapm_widget *w,
3702 ++ struct snd_kcontrol *kcontrol, int event)
3703 ++{
3704 ++ struct snd_soc_component *component =
3705 ++ snd_soc_dapm_to_component(w->dapm);
3706 ++
3707 ++ return vag_and_mute_control(component, event, HP_POWER_EVENT);
3708 ++}
3709 ++
3710 ++/* As manual describes, ADC/DAC powering up/down requires
3711 ++ * to mute outputs to avoid pops.
3712 ++ * Control VAG power on ADC/DAC power path.
3713 ++ */
3714 ++static int adc_updown_depop(struct snd_soc_dapm_widget *w,
3715 ++ struct snd_kcontrol *kcontrol, int event)
3716 ++{
3717 ++ struct snd_soc_component *component =
3718 ++ snd_soc_dapm_to_component(w->dapm);
3719 ++
3720 ++ return vag_and_mute_control(component, event, ADC_POWER_EVENT);
3721 ++}
3722 ++
3723 ++static int dac_updown_depop(struct snd_soc_dapm_widget *w,
3724 ++ struct snd_kcontrol *kcontrol, int event)
3725 ++{
3726 ++ struct snd_soc_component *component =
3727 ++ snd_soc_dapm_to_component(w->dapm);
3728 ++
3729 ++ return vag_and_mute_control(component, event, DAC_POWER_EVENT);
3730 ++}
3731 ++
3732 + /* input sources for ADC */
3733 + static const char *adc_mux_text[] = {
3734 + "MIC_IN", "LINE_IN"
3735 +@@ -217,7 +385,10 @@ static const struct snd_soc_dapm_widget sgtl5000_dapm_widgets[] = {
3736 + mic_bias_event,
3737 + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
3738 +
3739 +- SND_SOC_DAPM_PGA("HP", SGTL5000_CHIP_ANA_POWER, 4, 0, NULL, 0),
3740 ++ SND_SOC_DAPM_PGA_E("HP", SGTL5000_CHIP_ANA_POWER, 4, 0, NULL, 0,
3741 ++ headphone_pga_event,
3742 ++ SND_SOC_DAPM_PRE_POST_PMU |
3743 ++ SND_SOC_DAPM_PRE_POST_PMD),
3744 + SND_SOC_DAPM_PGA("LO", SGTL5000_CHIP_ANA_POWER, 0, 0, NULL, 0),
3745 +
3746 + SND_SOC_DAPM_MUX("Capture Mux", SND_SOC_NOPM, 0, 0, &adc_mux),
3747 +@@ -233,11 +404,12 @@ static const struct snd_soc_dapm_widget sgtl5000_dapm_widgets[] = {
3748 + 0, SGTL5000_CHIP_DIG_POWER,
3749 + 1, 0),
3750 +
3751 +- SND_SOC_DAPM_ADC("ADC", "Capture", SGTL5000_CHIP_ANA_POWER, 1, 0),
3752 +- SND_SOC_DAPM_DAC("DAC", "Playback", SGTL5000_CHIP_ANA_POWER, 3, 0),
3753 +-
3754 +- SND_SOC_DAPM_PRE("VAG_POWER_PRE", power_vag_event),
3755 +- SND_SOC_DAPM_POST("VAG_POWER_POST", power_vag_event),
3756 ++ SND_SOC_DAPM_ADC_E("ADC", "Capture", SGTL5000_CHIP_ANA_POWER, 1, 0,
3757 ++ adc_updown_depop, SND_SOC_DAPM_PRE_POST_PMU |
3758 ++ SND_SOC_DAPM_PRE_POST_PMD),
3759 ++ SND_SOC_DAPM_DAC_E("DAC", "Playback", SGTL5000_CHIP_ANA_POWER, 3, 0,
3760 ++ dac_updown_depop, SND_SOC_DAPM_PRE_POST_PMU |
3761 ++ SND_SOC_DAPM_PRE_POST_PMD),
3762 + };
3763 +
3764 + /* routes for sgtl5000 */
3765 +diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
3766 +index def61125ac36..62f4cacf253a 100644
3767 +--- a/tools/lib/traceevent/event-parse.c
3768 ++++ b/tools/lib/traceevent/event-parse.c
3769 +@@ -267,10 +267,10 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
3770 + errno = ENOMEM;
3771 + return -1;
3772 + }
3773 ++ pevent->cmdlines = cmdlines;
3774 +
3775 + cmdlines[pevent->cmdline_count].comm = strdup(comm);
3776 + if (!cmdlines[pevent->cmdline_count].comm) {
3777 +- free(cmdlines);
3778 + errno = ENOMEM;
3779 + return -1;
3780 + }
3781 +@@ -281,7 +281,6 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
3782 + pevent->cmdline_count++;
3783 +
3784 + qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
3785 +- pevent->cmdlines = cmdlines;
3786 +
3787 + return 0;
3788 + }
3789 +diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
3790 +index 43d5f35e9074..5cb58f3afa35 100644
3791 +--- a/tools/perf/builtin-stat.c
3792 ++++ b/tools/perf/builtin-stat.c
3793 +@@ -2564,8 +2564,11 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
3794 + fprintf(output, "[ perf stat: executing run #%d ... ]\n",
3795 + run_idx + 1);
3796 +
3797 ++ if (run_idx != 0)
3798 ++ perf_evlist__reset_prev_raw_counts(evsel_list);
3799 ++
3800 + status = run_perf_stat(argc, argv);
3801 +- if (forever && status != -1) {
3802 ++ if (forever && status != -1 && !interval) {
3803 + print_counters(NULL, argc, argv);
3804 + perf_stat__reset_stats();
3805 + }
3806 +diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
3807 +index 258b19b251a8..b3d947b98a7c 100644
3808 +--- a/tools/perf/util/header.c
3809 ++++ b/tools/perf/util/header.c
3810 +@@ -949,7 +949,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev
3811 +
3812 + scnprintf(file, PATH_MAX, "%s/shared_cpu_list", path);
3813 + if (sysfs__read_str(file, &cache->map, &len)) {
3814 +- free(cache->map);
3815 ++ free(cache->size);
3816 + free(cache->type);
3817 + return -1;
3818 + }
3819 +diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
3820 +index 95f0884aae02..7e2e8aa95467 100644
3821 +--- a/tools/perf/util/jitdump.c
3822 ++++ b/tools/perf/util/jitdump.c
3823 +@@ -369,7 +369,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
3824 + size_t size;
3825 + u16 idr_size;
3826 + const char *sym;
3827 +- uint32_t count;
3828 ++ uint64_t count;
3829 + int ret, csize;
3830 + pid_t pid, tid;
3831 + struct {
3832 +@@ -391,7 +391,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
3833 + return -1;
3834 +
3835 + filename = event->mmap2.filename;
3836 +- size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%u.so",
3837 ++ size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%" PRIu64 ".so",
3838 + jd->dir,
3839 + pid,
3840 + count);
3841 +@@ -493,7 +493,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
3842 + return -1;
3843 +
3844 + filename = event->mmap2.filename;
3845 +- size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%"PRIu64,
3846 ++ size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%" PRIu64 ".so",
3847 + jd->dir,
3848 + pid,
3849 + jr->move.code_index);
3850 +diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
3851 +index 621f6527b790..4887dd5eb80f 100644
3852 +--- a/tools/perf/util/llvm-utils.c
3853 ++++ b/tools/perf/util/llvm-utils.c
3854 +@@ -220,14 +220,14 @@ static int detect_kbuild_dir(char **kbuild_dir)
3855 + const char *prefix_dir = "";
3856 + const char *suffix_dir = "";
3857 +
3858 ++ /* _UTSNAME_LENGTH is 65 */
3859 ++ char release[128];
3860 ++
3861 + char *autoconf_path;
3862 +
3863 + int err;
3864 +
3865 + if (!test_dir) {
3866 +- /* _UTSNAME_LENGTH is 65 */
3867 +- char release[128];
3868 +-
3869 + err = fetch_kernel_version(NULL, release,
3870 + sizeof(release));
3871 + if (err)
3872 +diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
3873 +index 39345c2ddfc2..d4f872f1750e 100644
3874 +--- a/tools/perf/util/stat.c
3875 ++++ b/tools/perf/util/stat.c
3876 +@@ -145,6 +145,15 @@ static void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel)
3877 + evsel->prev_raw_counts = NULL;
3878 + }
3879 +
3880 ++static void perf_evsel__reset_prev_raw_counts(struct perf_evsel *evsel)
3881 ++{
3882 ++ if (evsel->prev_raw_counts) {
3883 ++ evsel->prev_raw_counts->aggr.val = 0;
3884 ++ evsel->prev_raw_counts->aggr.ena = 0;
3885 ++ evsel->prev_raw_counts->aggr.run = 0;
3886 ++ }
3887 ++}
3888 ++
3889 + static int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw)
3890 + {
3891 + int ncpus = perf_evsel__nr_cpus(evsel);
3892 +@@ -195,6 +204,14 @@ void perf_evlist__reset_stats(struct perf_evlist *evlist)
3893 + }
3894 + }
3895 +
3896 ++void perf_evlist__reset_prev_raw_counts(struct perf_evlist *evlist)
3897 ++{
3898 ++ struct perf_evsel *evsel;
3899 ++
3900 ++ evlist__for_each_entry(evlist, evsel)
3901 ++ perf_evsel__reset_prev_raw_counts(evsel);
3902 ++}
3903 ++
3904 + static void zero_per_pkg(struct perf_evsel *counter)
3905 + {
3906 + if (counter->per_pkg_mask)
3907 +diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
3908 +index c29bb94c48a4..b8845aceac31 100644
3909 +--- a/tools/perf/util/stat.h
3910 ++++ b/tools/perf/util/stat.h
3911 +@@ -94,6 +94,7 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
3912 + int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
3913 + void perf_evlist__free_stats(struct perf_evlist *evlist);
3914 + void perf_evlist__reset_stats(struct perf_evlist *evlist);
3915 ++void perf_evlist__reset_prev_raw_counts(struct perf_evlist *evlist);
3916 +
3917 + int perf_stat_process_counter(struct perf_stat_config *config,
3918 + struct perf_evsel *counter);