Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.4 commit in: /
Date: Thu, 17 Oct 2019 22:18:22
Message-Id: 1571350674.71ec30f97ea667e987e0de30f7592909cfa96685.mpagano@gentoo
1 commit: 71ec30f97ea667e987e0de30f7592909cfa96685
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Thu Oct 17 22:17:54 2019 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Thu Oct 17 22:17:54 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=71ec30f9
7
8 Linux patch 4.4.197
9
10 Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>
11
12 0000_README | 4 +
13 1196_linux-4.4.197.patch | 3532 ++++++++++++++++++++++++++++++++++++++++++++++
14 2 files changed, 3536 insertions(+)
15
16 diff --git a/0000_README b/0000_README
17 index 1b517d0..e5ffd05 100644
18 --- a/0000_README
19 +++ b/0000_README
20 @@ -827,6 +827,10 @@ Patch: 1195_linux-4.4.196.patch
21 From: http://www.kernel.org
22 Desc: Linux 4.4.196
23
24 +Patch: 1196_linux-4.4.197.patch
25 +From: http://www.kernel.org
26 +Desc: Linux 4.4.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.4.197.patch b/1196_linux-4.4.197.patch
33 new file mode 100644
34 index 0000000..17fb3bd
35 --- /dev/null
36 +++ b/1196_linux-4.4.197.patch
37 @@ -0,0 +1,3532 @@
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 20a31b357929..e1a15f7507fa 100644
184 +--- a/MAINTAINERS
185 ++++ b/MAINTAINERS
186 +@@ -11100,13 +11100,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 9eaf50527883..5c150d32cae7 100644
202 +--- a/Makefile
203 ++++ b/Makefile
204 +@@ -1,6 +1,6 @@
205 + VERSION = 4
206 + PATCHLEVEL = 4
207 +-SUBLEVEL = 196
208 ++SUBLEVEL = 197
209 + EXTRAVERSION =
210 + NAME = Blurry Fish Butt
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/s3c2410_defconfig b/arch/arm/configs/s3c2410_defconfig
237 +index 01116ee1284b..a199b0e1a6ea 100644
238 +--- a/arch/arm/configs/s3c2410_defconfig
239 ++++ b/arch/arm/configs/s3c2410_defconfig
240 +@@ -354,7 +354,6 @@ CONFIG_USB_EMI62=m
241 + CONFIG_USB_EMI26=m
242 + CONFIG_USB_ADUTUX=m
243 + CONFIG_USB_SEVSEG=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/spitz_defconfig b/arch/arm/configs/spitz_defconfig
249 +index a1ede1966baf..7d9aa284cb6f 100644
250 +--- a/arch/arm/configs/spitz_defconfig
251 ++++ b/arch/arm/configs/spitz_defconfig
252 +@@ -202,7 +202,6 @@ CONFIG_USB_SERIAL_XIRCOM=m
253 + CONFIG_USB_SERIAL_OMNINET=m
254 + CONFIG_USB_EMI62=m
255 + CONFIG_USB_EMI26=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/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
261 +index 0a66f8241f18..518eaa63e633 100644
262 +--- a/arch/arm64/include/asm/cpufeature.h
263 ++++ b/arch/arm64/include/asm/cpufeature.h
264 +@@ -88,9 +88,10 @@ struct arm64_cpu_capabilities {
265 +
266 + struct { /* Feature register checking */
267 + u32 sys_reg;
268 +- int field_pos;
269 +- int min_field_value;
270 +- int hwcap_type;
271 ++ u8 field_pos;
272 ++ u8 min_field_value;
273 ++ u8 hwcap_type;
274 ++ bool sign;
275 + unsigned long hwcap;
276 + };
277 + };
278 +@@ -120,15 +121,15 @@ static inline void cpus_set_cap(unsigned int num)
279 + }
280 +
281 + static inline int __attribute_const__
282 +-cpuid_feature_extract_field_width(u64 features, int field, int width)
283 ++cpuid_feature_extract_signed_field_width(u64 features, int field, int width)
284 + {
285 + return (s64)(features << (64 - width - field)) >> (64 - width);
286 + }
287 +
288 + static inline int __attribute_const__
289 +-cpuid_feature_extract_field(u64 features, int field)
290 ++cpuid_feature_extract_signed_field(u64 features, int field)
291 + {
292 +- return cpuid_feature_extract_field_width(features, field, 4);
293 ++ return cpuid_feature_extract_signed_field_width(features, field, 4);
294 + }
295 +
296 + static inline unsigned int __attribute_const__
297 +@@ -148,17 +149,23 @@ static inline u64 arm64_ftr_mask(struct arm64_ftr_bits *ftrp)
298 + return (u64)GENMASK(ftrp->shift + ftrp->width - 1, ftrp->shift);
299 + }
300 +
301 ++static inline int __attribute_const__
302 ++cpuid_feature_extract_field(u64 features, int field, bool sign)
303 ++{
304 ++ return (sign) ?
305 ++ cpuid_feature_extract_signed_field(features, field) :
306 ++ cpuid_feature_extract_unsigned_field(features, field);
307 ++}
308 ++
309 + static inline s64 arm64_ftr_value(struct arm64_ftr_bits *ftrp, u64 val)
310 + {
311 +- return ftrp->sign ?
312 +- cpuid_feature_extract_field_width(val, ftrp->shift, ftrp->width) :
313 +- cpuid_feature_extract_unsigned_field_width(val, ftrp->shift, ftrp->width);
314 ++ return (s64)cpuid_feature_extract_field(val, ftrp->shift, ftrp->sign);
315 + }
316 +
317 + static inline bool id_aa64mmfr0_mixed_endian_el0(u64 mmfr0)
318 + {
319 +- return cpuid_feature_extract_field(mmfr0, ID_AA64MMFR0_BIGENDEL_SHIFT) == 0x1 ||
320 +- cpuid_feature_extract_field(mmfr0, ID_AA64MMFR0_BIGENDEL0_SHIFT) == 0x1;
321 ++ return cpuid_feature_extract_unsigned_field(mmfr0, ID_AA64MMFR0_BIGENDEL_SHIFT) == 0x1 ||
322 ++ cpuid_feature_extract_unsigned_field(mmfr0, ID_AA64MMFR0_BIGENDEL0_SHIFT) == 0x1;
323 + }
324 +
325 + void __init setup_cpu_features(void);
326 +diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
327 +index 062484d34450..a0118a07a4a5 100644
328 +--- a/arch/arm64/kernel/cpufeature.c
329 ++++ b/arch/arm64/kernel/cpufeature.c
330 +@@ -600,7 +600,7 @@ u64 read_system_reg(u32 id)
331 + static bool
332 + feature_matches(u64 reg, const struct arm64_cpu_capabilities *entry)
333 + {
334 +- int val = cpuid_feature_extract_field(reg, entry->field_pos);
335 ++ int val = cpuid_feature_extract_field(reg, entry->field_pos, entry->sign);
336 +
337 + return val >= entry->min_field_value;
338 + }
339 +@@ -636,6 +636,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
340 + .matches = has_useable_gicv3_cpuif,
341 + .sys_reg = SYS_ID_AA64PFR0_EL1,
342 + .field_pos = ID_AA64PFR0_GIC_SHIFT,
343 ++ .sign = FTR_UNSIGNED,
344 + .min_field_value = 1,
345 + },
346 + #ifdef CONFIG_ARM64_PAN
347 +@@ -645,6 +646,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
348 + .matches = has_cpuid_feature,
349 + .sys_reg = SYS_ID_AA64MMFR1_EL1,
350 + .field_pos = ID_AA64MMFR1_PAN_SHIFT,
351 ++ .sign = FTR_UNSIGNED,
352 + .min_field_value = 1,
353 + .enable = cpu_enable_pan,
354 + },
355 +@@ -656,6 +658,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
356 + .matches = has_cpuid_feature,
357 + .sys_reg = SYS_ID_AA64ISAR0_EL1,
358 + .field_pos = ID_AA64ISAR0_ATOMICS_SHIFT,
359 ++ .sign = FTR_UNSIGNED,
360 + .min_field_value = 2,
361 + },
362 + #endif /* CONFIG_AS_LSE && CONFIG_ARM64_LSE_ATOMICS */
363 +@@ -665,37 +668,39 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
364 + .matches = has_cpuid_feature,
365 + .sys_reg = SYS_ID_AA64PFR0_EL1,
366 + .field_pos = ID_AA64PFR0_EL0_SHIFT,
367 ++ .sign = FTR_UNSIGNED,
368 + .min_field_value = ID_AA64PFR0_EL0_32BIT_64BIT,
369 + },
370 + {},
371 + };
372 +
373 +-#define HWCAP_CAP(reg, field, min_value, type, cap) \
374 ++#define HWCAP_CAP(reg, field, s, min_value, type, cap) \
375 + { \
376 + .desc = #cap, \
377 + .matches = has_cpuid_feature, \
378 + .sys_reg = reg, \
379 + .field_pos = field, \
380 ++ .sign = s, \
381 + .min_field_value = min_value, \
382 + .hwcap_type = type, \
383 + .hwcap = cap, \
384 + }
385 +
386 + static const struct arm64_cpu_capabilities arm64_hwcaps[] = {
387 +- HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, 2, CAP_HWCAP, HWCAP_PMULL),
388 +- HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, 1, CAP_HWCAP, HWCAP_AES),
389 +- HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA1_SHIFT, 1, CAP_HWCAP, HWCAP_SHA1),
390 +- HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, 1, CAP_HWCAP, HWCAP_SHA2),
391 +- HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_CRC32_SHIFT, 1, CAP_HWCAP, HWCAP_CRC32),
392 +- HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_ATOMICS_SHIFT, 2, CAP_HWCAP, HWCAP_ATOMICS),
393 +- HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, 0, CAP_HWCAP, HWCAP_FP),
394 +- HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, 0, CAP_HWCAP, HWCAP_ASIMD),
395 ++ HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, HWCAP_PMULL),
396 ++ HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_AES),
397 ++ HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA1_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SHA1),
398 ++ HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SHA2),
399 ++ HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_CRC32_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_CRC32),
400 ++ HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_ATOMICS_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, HWCAP_ATOMICS),
401 ++ HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, HWCAP_FP),
402 ++ HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, HWCAP_ASIMD),
403 + #ifdef CONFIG_COMPAT
404 +- HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_AES_SHIFT, 2, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_PMULL),
405 +- HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_AES_SHIFT, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_AES),
406 +- HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_SHA1_SHIFT, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_SHA1),
407 +- HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_SHA2_SHIFT, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_SHA2),
408 +- HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_CRC32_SHIFT, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_CRC32),
409 ++ HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_AES_SHIFT, FTR_UNSIGNED, 2, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_PMULL),
410 ++ HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_AES_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_AES),
411 ++ HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_SHA1_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_SHA1),
412 ++ HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_SHA2_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_SHA2),
413 ++ HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_CRC32_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_CRC32),
414 + #endif
415 + {},
416 + };
417 +diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
418 +index c8875b64be90..8e7675e5ce4a 100644
419 +--- a/arch/arm64/kernel/debug-monitors.c
420 ++++ b/arch/arm64/kernel/debug-monitors.c
421 +@@ -34,7 +34,7 @@
422 + /* Determine debug architecture. */
423 + u8 debug_monitors_arch(void)
424 + {
425 +- return cpuid_feature_extract_field(read_system_reg(SYS_ID_AA64DFR0_EL1),
426 ++ return cpuid_feature_extract_unsigned_field(read_system_reg(SYS_ID_AA64DFR0_EL1),
427 + ID_AA64DFR0_DEBUGVER_SHIFT);
428 + }
429 +
430 +diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
431 +index c2489f62c4fb..0a587e7b9b6e 100644
432 +--- a/arch/arm64/kvm/sys_regs.c
433 ++++ b/arch/arm64/kvm/sys_regs.c
434 +@@ -687,7 +687,7 @@ static bool trap_dbgidr(struct kvm_vcpu *vcpu,
435 + } else {
436 + u64 dfr = read_system_reg(SYS_ID_AA64DFR0_EL1);
437 + u64 pfr = read_system_reg(SYS_ID_AA64PFR0_EL1);
438 +- u32 el3 = !!cpuid_feature_extract_field(pfr, ID_AA64PFR0_EL3_SHIFT);
439 ++ u32 el3 = !!cpuid_feature_extract_unsigned_field(pfr, ID_AA64PFR0_EL3_SHIFT);
440 +
441 + p->regval = ((((dfr >> ID_AA64DFR0_WRPS_SHIFT) & 0xf) << 28) |
442 + (((dfr >> ID_AA64DFR0_BRPS_SHIFT) & 0xf) << 24) |
443 +diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c
444 +index e87f53ff5f58..5c8759cd66f1 100644
445 +--- a/arch/arm64/mm/context.c
446 ++++ b/arch/arm64/mm/context.c
447 +@@ -187,7 +187,8 @@ switch_mm_fastpath:
448 +
449 + static int asids_init(void)
450 + {
451 +- int fld = cpuid_feature_extract_field(read_cpuid(ID_AA64MMFR0_EL1), 4);
452 ++ int fld = cpuid_feature_extract_unsigned_field(read_cpuid(ID_AA64MMFR0_EL1),
453 ++ ID_AA64MMFR0_ASID_SHIFT);
454 +
455 + switch (fld) {
456 + default:
457 +diff --git a/arch/mips/configs/mtx1_defconfig b/arch/mips/configs/mtx1_defconfig
458 +index 9b6926d6bb32..6ac662afd5c1 100644
459 +--- a/arch/mips/configs/mtx1_defconfig
460 ++++ b/arch/mips/configs/mtx1_defconfig
461 +@@ -638,7 +638,6 @@ CONFIG_USB_SERIAL_OMNINET=m
462 + CONFIG_USB_EMI62=m
463 + CONFIG_USB_EMI26=m
464 + CONFIG_USB_ADUTUX=m
465 +-CONFIG_USB_RIO500=m
466 + CONFIG_USB_LEGOTOWER=m
467 + CONFIG_USB_LCD=m
468 + CONFIG_USB_LED=m
469 +diff --git a/arch/mips/configs/rm200_defconfig b/arch/mips/configs/rm200_defconfig
470 +index db029f4ff759..4acaa3fb4818 100644
471 +--- a/arch/mips/configs/rm200_defconfig
472 ++++ b/arch/mips/configs/rm200_defconfig
473 +@@ -351,7 +351,6 @@ CONFIG_USB_SERIAL_SAFE_PADDED=y
474 + CONFIG_USB_SERIAL_CYBERJACK=m
475 + CONFIG_USB_SERIAL_XIRCOM=m
476 + CONFIG_USB_SERIAL_OMNINET=m
477 +-CONFIG_USB_RIO500=m
478 + CONFIG_USB_LEGOTOWER=m
479 + CONFIG_USB_LCD=m
480 + CONFIG_USB_LED=m
481 +diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
482 +index b40606051efe..d3787618315f 100644
483 +--- a/arch/powerpc/platforms/powernv/opal.c
484 ++++ b/arch/powerpc/platforms/powernv/opal.c
485 +@@ -580,7 +580,10 @@ static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj,
486 + bin_attr->size);
487 + }
488 +
489 +-static BIN_ATTR_RO(symbol_map, 0);
490 ++static struct bin_attribute symbol_map_attr = {
491 ++ .attr = {.name = "symbol_map", .mode = 0400},
492 ++ .read = symbol_map_read
493 ++};
494 +
495 + static void opal_export_symmap(void)
496 + {
497 +@@ -597,10 +600,10 @@ static void opal_export_symmap(void)
498 + return;
499 +
500 + /* Setup attributes */
501 +- bin_attr_symbol_map.private = __va(be64_to_cpu(syms[0]));
502 +- bin_attr_symbol_map.size = be64_to_cpu(syms[1]);
503 ++ symbol_map_attr.private = __va(be64_to_cpu(syms[0]));
504 ++ symbol_map_attr.size = be64_to_cpu(syms[1]);
505 +
506 +- rc = sysfs_create_bin_file(opal_kobj, &bin_attr_symbol_map);
507 ++ rc = sysfs_create_bin_file(opal_kobj, &symbol_map_attr);
508 + if (rc)
509 + pr_warn("Error %d creating OPAL symbols file\n", rc);
510 + }
511 +diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
512 +index 40b8102fdadb..ff95ddd031d1 100644
513 +--- a/arch/s390/kernel/topology.c
514 ++++ b/arch/s390/kernel/topology.c
515 +@@ -291,7 +291,8 @@ int arch_update_cpu_topology(void)
516 + topology_update_polarization_simple();
517 + for_each_online_cpu(cpu) {
518 + dev = get_cpu_device(cpu);
519 +- kobject_uevent(&dev->kobj, KOBJ_CHANGE);
520 ++ if (dev)
521 ++ kobject_uevent(&dev->kobj, KOBJ_CHANGE);
522 + }
523 + return rc;
524 + }
525 +diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
526 +index 14d2ca9c779e..3e46f62d32ad 100644
527 +--- a/arch/s390/kvm/kvm-s390.c
528 ++++ b/arch/s390/kvm/kvm-s390.c
529 +@@ -2471,7 +2471,7 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu,
530 + const u64 supported_flags = KVM_S390_MEMOP_F_INJECT_EXCEPTION
531 + | KVM_S390_MEMOP_F_CHECK_ONLY;
532 +
533 +- if (mop->flags & ~supported_flags)
534 ++ if (mop->flags & ~supported_flags || mop->ar >= NUM_ACRS || !mop->size)
535 + return -EINVAL;
536 +
537 + if (mop->size > MEM_OP_MAX_SIZE)
538 +diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
539 +index b98dbdaee8ac..1ab7f37150d2 100644
540 +--- a/arch/x86/include/asm/mwait.h
541 ++++ b/arch/x86/include/asm/mwait.h
542 +@@ -19,7 +19,7 @@
543 + #define MWAIT_ECX_INTERRUPT_BREAK 0x1
544 + #define MWAITX_ECX_TIMER_ENABLE BIT(1)
545 + #define MWAITX_MAX_LOOPS ((u32)-1)
546 +-#define MWAITX_DISABLE_CSTATES 0xf
547 ++#define MWAITX_DISABLE_CSTATES 0xf0
548 +
549 + static inline void __monitor(const void *eax, unsigned long ecx,
550 + unsigned long edx)
551 +diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
552 +index 343c8ddad86a..f8f9d1b368bf 100644
553 +--- a/arch/x86/kvm/vmx.c
554 ++++ b/arch/x86/kvm/vmx.c
555 +@@ -7276,7 +7276,7 @@ static int handle_vmread(struct kvm_vcpu *vcpu)
556 + /* _system ok, as nested_vmx_check_permission verified cpl=0 */
557 + if (kvm_write_guest_virt_system(vcpu, gva, &field_value,
558 + (is_long_mode(vcpu) ? 8 : 4),
559 +- NULL))
560 ++ &e))
561 + kvm_inject_page_fault(vcpu, &e);
562 + }
563 +
564 +diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
565 +index 45772560aceb..fc0cc6d08157 100644
566 +--- a/arch/x86/lib/delay.c
567 ++++ b/arch/x86/lib/delay.c
568 +@@ -112,8 +112,8 @@ static void delay_mwaitx(unsigned long __loops)
569 + __monitorx(this_cpu_ptr(&cpu_tss), 0, 0);
570 +
571 + /*
572 +- * AMD, like Intel, supports the EAX hint and EAX=0xf
573 +- * means, do not enter any deep C-state and we use it
574 ++ * AMD, like Intel's MWAIT version, supports the EAX hint and
575 ++ * EAX=0xf0 means, do not enter any deep C-state and we use it
576 + * here in delay() to minimize wakeup latency.
577 + */
578 + __mwaitx(MWAITX_DISABLE_CSTATES, delay, MWAITX_ECX_TIMER_ENABLE);
579 +diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
580 +index f2d1fea23fbf..492432dd5cd6 100644
581 +--- a/drivers/crypto/caam/caamalg.c
582 ++++ b/drivers/crypto/caam/caamalg.c
583 +@@ -75,7 +75,7 @@
584 + #define DESC_AEAD_BASE (4 * CAAM_CMD_SZ)
585 + #define DESC_AEAD_ENC_LEN (DESC_AEAD_BASE + 11 * CAAM_CMD_SZ)
586 + #define DESC_AEAD_DEC_LEN (DESC_AEAD_BASE + 15 * CAAM_CMD_SZ)
587 +-#define DESC_AEAD_GIVENC_LEN (DESC_AEAD_ENC_LEN + 9 * CAAM_CMD_SZ)
588 ++#define DESC_AEAD_GIVENC_LEN (DESC_AEAD_ENC_LEN + 10 * CAAM_CMD_SZ)
589 +
590 + /* Note: Nonce is counted in enckeylen */
591 + #define DESC_AEAD_CTR_RFC3686_LEN (4 * CAAM_CMD_SZ)
592 +@@ -437,6 +437,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead)
593 + u32 geniv, moveiv;
594 + u32 ctx1_iv_off = 0;
595 + u32 *desc;
596 ++ u32 *wait_cmd;
597 + const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
598 + OP_ALG_AAI_CTR_MOD128);
599 + const bool is_rfc3686 = alg->caam.rfc3686;
600 +@@ -702,6 +703,14 @@ copy_iv:
601 +
602 + /* Will read cryptlen */
603 + append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
604 ++
605 ++ /*
606 ++ * Wait for IV transfer (ofifo -> class2) to finish before starting
607 ++ * ciphertext transfer (ofifo -> external memory).
608 ++ */
609 ++ wait_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | JUMP_COND_NIFP);
610 ++ set_jump_tgt_here(desc, wait_cmd);
611 ++
612 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | KEY_VLF |
613 + FIFOLD_TYPE_MSG1OUT2 | FIFOLD_TYPE_LASTBOTH);
614 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
615 +diff --git a/drivers/crypto/qat/qat_common/adf_common_drv.h b/drivers/crypto/qat/qat_common/adf_common_drv.h
616 +index aa1dbeaa9b49..5358162018dd 100644
617 +--- a/drivers/crypto/qat/qat_common/adf_common_drv.h
618 ++++ b/drivers/crypto/qat/qat_common/adf_common_drv.h
619 +@@ -95,7 +95,7 @@ struct service_hndl {
620 +
621 + static inline int get_current_node(void)
622 + {
623 +- return topology_physical_package_id(smp_processor_id());
624 ++ return topology_physical_package_id(raw_smp_processor_id());
625 + }
626 +
627 + int adf_service_register(struct service_hndl *service);
628 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
629 +index a5c824078472..e35e603710b4 100644
630 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
631 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
632 +@@ -406,6 +406,9 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
633 + if (sh_num == AMDGPU_INFO_MMR_SH_INDEX_MASK)
634 + sh_num = 0xffffffff;
635 +
636 ++ if (info->read_mmr_reg.count > 128)
637 ++ return -EINVAL;
638 ++
639 + regs = kmalloc_array(info->read_mmr_reg.count, sizeof(*regs), GFP_KERNEL);
640 + if (!regs)
641 + return -ENOMEM;
642 +diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
643 +index ba82de25a797..46681e399e22 100644
644 +--- a/drivers/iio/adc/ad799x.c
645 ++++ b/drivers/iio/adc/ad799x.c
646 +@@ -822,10 +822,10 @@ static int ad799x_probe(struct i2c_client *client,
647 +
648 + ret = ad799x_write_config(st, st->chip_config->default_config);
649 + if (ret < 0)
650 +- goto error_disable_reg;
651 ++ goto error_disable_vref;
652 + ret = ad799x_read_config(st);
653 + if (ret < 0)
654 +- goto error_disable_reg;
655 ++ goto error_disable_vref;
656 + st->config = ret;
657 +
658 + ret = iio_triggered_buffer_setup(indio_dev, NULL,
659 +diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
660 +index 01e111e72d4b..eecdc50ed282 100644
661 +--- a/drivers/iio/light/opt3001.c
662 ++++ b/drivers/iio/light/opt3001.c
663 +@@ -646,6 +646,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
664 + struct iio_dev *iio = _iio;
665 + struct opt3001 *opt = iio_priv(iio);
666 + int ret;
667 ++ bool wake_result_ready_queue = false;
668 +
669 + if (!opt->ok_to_ignore_lock)
670 + mutex_lock(&opt->lock);
671 +@@ -680,13 +681,16 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
672 + }
673 + opt->result = ret;
674 + opt->result_ready = true;
675 +- wake_up(&opt->result_ready_queue);
676 ++ wake_result_ready_queue = true;
677 + }
678 +
679 + out:
680 + if (!opt->ok_to_ignore_lock)
681 + mutex_unlock(&opt->lock);
682 +
683 ++ if (wake_result_ready_queue)
684 ++ wake_up(&opt->result_ready_queue);
685 ++
686 + return IRQ_HANDLED;
687 + }
688 +
689 +diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
690 +index c21c4c004f97..17ee9cde4156 100644
691 +--- a/drivers/media/usb/stkwebcam/stk-webcam.c
692 ++++ b/drivers/media/usb/stkwebcam/stk-webcam.c
693 +@@ -642,8 +642,7 @@ static int v4l_stk_release(struct file *fp)
694 + dev->owner = NULL;
695 + }
696 +
697 +- if (is_present(dev))
698 +- usb_autopm_put_interface(dev->interface);
699 ++ usb_autopm_put_interface(dev->interface);
700 + mutex_unlock(&dev->lock);
701 + return v4l2_fh_release(fp);
702 + }
703 +diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
704 +index 3bcbfcf0455a..83ddb7d8214a 100644
705 +--- a/drivers/net/can/spi/mcp251x.c
706 ++++ b/drivers/net/can/spi/mcp251x.c
707 +@@ -627,7 +627,7 @@ static int mcp251x_setup(struct net_device *net, struct mcp251x_priv *priv,
708 + static int mcp251x_hw_reset(struct spi_device *spi)
709 + {
710 + struct mcp251x_priv *priv = spi_get_drvdata(spi);
711 +- u8 reg;
712 ++ unsigned long timeout;
713 + int ret;
714 +
715 + /* Wait for oscillator startup timer after power up */
716 +@@ -641,10 +641,19 @@ static int mcp251x_hw_reset(struct spi_device *spi)
717 + /* Wait for oscillator startup timer after reset */
718 + mdelay(MCP251X_OST_DELAY_MS);
719 +
720 +- reg = mcp251x_read_reg(spi, CANSTAT);
721 +- if ((reg & CANCTRL_REQOP_MASK) != CANCTRL_REQOP_CONF)
722 +- return -ENODEV;
723 +-
724 ++ /* Wait for reset to finish */
725 ++ timeout = jiffies + HZ;
726 ++ while ((mcp251x_read_reg(spi, CANSTAT) & CANCTRL_REQOP_MASK) !=
727 ++ CANCTRL_REQOP_CONF) {
728 ++ usleep_range(MCP251X_OST_DELAY_MS * 1000,
729 ++ MCP251X_OST_DELAY_MS * 1000 * 2);
730 ++
731 ++ if (time_after(jiffies, timeout)) {
732 ++ dev_err(&spi->dev,
733 ++ "MCP251x didn't enter in conf mode after reset\n");
734 ++ return -EBUSY;
735 ++ }
736 ++ }
737 + return 0;
738 + }
739 +
740 +diff --git a/drivers/net/ieee802154/atusb.c b/drivers/net/ieee802154/atusb.c
741 +index 3a429f1a8002..d5e0e2aedc55 100644
742 +--- a/drivers/net/ieee802154/atusb.c
743 ++++ b/drivers/net/ieee802154/atusb.c
744 +@@ -756,10 +756,11 @@ static void atusb_disconnect(struct usb_interface *interface)
745 +
746 + ieee802154_unregister_hw(atusb->hw);
747 +
748 ++ usb_put_dev(atusb->usb_dev);
749 ++
750 + ieee802154_free_hw(atusb->hw);
751 +
752 + usb_set_intfdata(interface, NULL);
753 +- usb_put_dev(atusb->usb_dev);
754 +
755 + pr_debug("atusb_disconnect done\n");
756 + }
757 +diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
758 +index e443b0d0b236..0d59c128f734 100644
759 +--- a/drivers/s390/cio/ccwgroup.c
760 ++++ b/drivers/s390/cio/ccwgroup.c
761 +@@ -369,7 +369,7 @@ int ccwgroup_create_dev(struct device *parent, struct ccwgroup_driver *gdrv,
762 + goto error;
763 + }
764 + /* Check for trailing stuff. */
765 +- if (i == num_devices && strlen(buf) > 0) {
766 ++ if (i == num_devices && buf && strlen(buf) > 0) {
767 + rc = -EINVAL;
768 + goto error;
769 + }
770 +diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
771 +index 489e703dc82d..8ecc956ecb59 100644
772 +--- a/drivers/s390/cio/css.c
773 ++++ b/drivers/s390/cio/css.c
774 +@@ -1120,6 +1120,8 @@ device_initcall(cio_settle_init);
775 +
776 + int sch_is_pseudo_sch(struct subchannel *sch)
777 + {
778 ++ if (!sch->dev.parent)
779 ++ return 0;
780 + return sch == to_css(sch->dev.parent)->pseudo_subchannel;
781 + }
782 +
783 +diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
784 +index 18c2b6daf588..15937e0ef4d9 100644
785 +--- a/drivers/staging/fbtft/fbtft-core.c
786 ++++ b/drivers/staging/fbtft/fbtft-core.c
787 +@@ -813,7 +813,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
788 + if (par->gamma.curves && gamma) {
789 + if (fbtft_gamma_parse_str(par,
790 + par->gamma.curves, gamma, strlen(gamma)))
791 +- goto alloc_fail;
792 ++ goto release_framebuf;
793 + }
794 +
795 + /* Transmit buffer */
796 +@@ -836,7 +836,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
797 + txbuf = devm_kzalloc(par->info->device, txbuflen, GFP_KERNEL);
798 + }
799 + if (!txbuf)
800 +- goto alloc_fail;
801 ++ goto release_framebuf;
802 + par->txbuf.buf = txbuf;
803 + par->txbuf.len = txbuflen;
804 + }
805 +@@ -872,6 +872,9 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
806 +
807 + return info;
808 +
809 ++release_framebuf:
810 ++ framebuffer_release(info);
811 ++
812 + alloc_fail:
813 + vfree(vmem);
814 +
815 +diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
816 +index 58b6403458b7..2f3c9217d650 100644
817 +--- a/drivers/staging/vt6655/device_main.c
818 ++++ b/drivers/staging/vt6655/device_main.c
819 +@@ -1668,8 +1668,10 @@ vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
820 +
821 + priv->hw->max_signal = 100;
822 +
823 +- if (vnt_init(priv))
824 ++ if (vnt_init(priv)) {
825 ++ device_free_info(priv);
826 + return -ENODEV;
827 ++ }
828 +
829 + device_print_info(priv);
830 + pci_set_drvdata(pcid, priv);
831 +diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
832 +index 3d5f8f432b5b..929092fc25ef 100644
833 +--- a/drivers/thermal/thermal_core.c
834 ++++ b/drivers/thermal/thermal_core.c
835 +@@ -402,7 +402,7 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
836 + mod_delayed_work(system_freezable_wq, &tz->poll_queue,
837 + msecs_to_jiffies(delay));
838 + else
839 +- cancel_delayed_work(&tz->poll_queue);
840 ++ cancel_delayed_work_sync(&tz->poll_queue);
841 + }
842 +
843 + static void monitor_thermal_zone(struct thermal_zone_device *tz)
844 +diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
845 +index b1c6bd3d483f..c27db21b71ba 100644
846 +--- a/drivers/tty/serial/uartlite.c
847 ++++ b/drivers/tty/serial/uartlite.c
848 +@@ -701,7 +701,8 @@ err_uart:
849 + static void __exit ulite_exit(void)
850 + {
851 + platform_driver_unregister(&ulite_platform_driver);
852 +- uart_unregister_driver(&ulite_uart_driver);
853 ++ if (ulite_uart_driver.state)
854 ++ uart_unregister_driver(&ulite_uart_driver);
855 + }
856 +
857 + module_init(ulite_init);
858 +diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
859 +index 071964c7847f..0669fbb0ec25 100644
860 +--- a/drivers/usb/class/usblp.c
861 ++++ b/drivers/usb/class/usblp.c
862 +@@ -474,10 +474,12 @@ static int usblp_release(struct inode *inode, struct file *file)
863 +
864 + mutex_lock(&usblp_mutex);
865 + usblp->used = 0;
866 +- if (usblp->present) {
867 ++ if (usblp->present)
868 + usblp_unlink_urbs(usblp);
869 +- usb_autopm_put_interface(usblp->intf);
870 +- } else /* finish cleanup from disconnect */
871 ++
872 ++ usb_autopm_put_interface(usblp->intf);
873 ++
874 ++ if (!usblp->present) /* finish cleanup from disconnect */
875 + usblp_cleanup(usblp);
876 + mutex_unlock(&usblp_mutex);
877 + return 0;
878 +diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
879 +index 85f1f282c1d5..0321b9ce9faf 100644
880 +--- a/drivers/usb/gadget/udc/dummy_hcd.c
881 ++++ b/drivers/usb/gadget/udc/dummy_hcd.c
882 +@@ -50,6 +50,7 @@
883 + #define DRIVER_VERSION "02 May 2005"
884 +
885 + #define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */
886 ++#define POWER_BUDGET_3 900 /* in mA */
887 +
888 + static const char driver_name[] = "dummy_hcd";
889 + static const char driver_desc[] = "USB Host+Gadget Emulator";
890 +@@ -2435,7 +2436,7 @@ static int dummy_start_ss(struct dummy_hcd *dum_hcd)
891 + dum_hcd->rh_state = DUMMY_RH_RUNNING;
892 + dum_hcd->stream_en_ep = 0;
893 + INIT_LIST_HEAD(&dum_hcd->urbp_list);
894 +- dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET;
895 ++ dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET_3;
896 + dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING;
897 + dummy_hcd_to_hcd(dum_hcd)->uses_new_polling = 1;
898 + #ifdef CONFIG_USB_OTG
899 +diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
900 +index ed152b8ea645..202c806b972a 100644
901 +--- a/drivers/usb/host/xhci.c
902 ++++ b/drivers/usb/host/xhci.c
903 +@@ -981,7 +981,7 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
904 + command |= CMD_CSS;
905 + writel(command, &xhci->op_regs->command);
906 + if (xhci_handshake(&xhci->op_regs->status,
907 +- STS_SAVE, 0, 10 * 1000)) {
908 ++ STS_SAVE, 0, 20 * 1000)) {
909 + xhci_warn(xhci, "WARN: xHC save state timeout\n");
910 + spin_unlock_irq(&xhci->lock);
911 + return -ETIMEDOUT;
912 +@@ -1041,6 +1041,18 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
913 + hibernated = true;
914 +
915 + if (!hibernated) {
916 ++ /*
917 ++ * Some controllers might lose power during suspend, so wait
918 ++ * for controller not ready bit to clear, just as in xHC init.
919 ++ */
920 ++ retval = xhci_handshake(&xhci->op_regs->status,
921 ++ STS_CNR, 0, 10 * 1000 * 1000);
922 ++ if (retval) {
923 ++ xhci_warn(xhci, "Controller not ready at resume %d\n",
924 ++ retval);
925 ++ spin_unlock_irq(&xhci->lock);
926 ++ return retval;
927 ++ }
928 + /* step 1: restore register */
929 + xhci_restore_registers(xhci);
930 + /* step 2: initialize command ring buffer */
931 +@@ -4529,12 +4541,12 @@ static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci,
932 + alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev,
933 + desc, state, timeout);
934 +
935 +- /* If we found we can't enable hub-initiated LPM, or
936 ++ /* If we found we can't enable hub-initiated LPM, and
937 + * the U1 or U2 exit latency was too high to allow
938 +- * device-initiated LPM as well, just stop searching.
939 ++ * device-initiated LPM as well, then we will disable LPM
940 ++ * for this device, so stop searching any further.
941 + */
942 +- if (alt_timeout == USB3_LPM_DISABLED ||
943 +- alt_timeout == USB3_LPM_DEVICE_INITIATED) {
944 ++ if (alt_timeout == USB3_LPM_DISABLED) {
945 + *timeout = alt_timeout;
946 + return -E2BIG;
947 + }
948 +@@ -4645,10 +4657,12 @@ static u16 xhci_calculate_lpm_timeout(struct usb_hcd *hcd,
949 + if (intf->dev.driver) {
950 + driver = to_usb_driver(intf->dev.driver);
951 + if (driver && driver->disable_hub_initiated_lpm) {
952 +- dev_dbg(&udev->dev, "Hub-initiated %s disabled "
953 +- "at request of driver %s\n",
954 +- state_name, driver->name);
955 +- return xhci_get_timeout_no_hub_lpm(udev, state);
956 ++ dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n",
957 ++ state_name, driver->name);
958 ++ timeout = xhci_get_timeout_no_hub_lpm(udev,
959 ++ state);
960 ++ if (timeout == USB3_LPM_DISABLED)
961 ++ return timeout;
962 + }
963 + }
964 +
965 +diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
966 +index a4dbb0cd80da..0fecc002fa9f 100644
967 +--- a/drivers/usb/image/microtek.c
968 ++++ b/drivers/usb/image/microtek.c
969 +@@ -724,6 +724,10 @@ static int mts_usb_probe(struct usb_interface *intf,
970 +
971 + }
972 +
973 ++ if (ep_in_current != &ep_in_set[2]) {
974 ++ MTS_WARNING("couldn't find two input bulk endpoints. Bailing out.\n");
975 ++ return -ENODEV;
976 ++ }
977 +
978 + if ( ep_out == -1 ) {
979 + MTS_WARNING( "couldn't find an output bulk endpoint. Bailing out.\n" );
980 +diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
981 +index f7a7fc21be8a..c7383c41c90e 100644
982 +--- a/drivers/usb/misc/Kconfig
983 ++++ b/drivers/usb/misc/Kconfig
984 +@@ -46,16 +46,6 @@ config USB_SEVSEG
985 + To compile this driver as a module, choose M here: the
986 + module will be called usbsevseg.
987 +
988 +-config USB_RIO500
989 +- tristate "USB Diamond Rio500 support"
990 +- help
991 +- Say Y here if you want to connect a USB Rio500 mp3 player to your
992 +- computer's USB port. Please read <file:Documentation/usb/rio.txt>
993 +- for more information.
994 +-
995 +- To compile this driver as a module, choose M here: the
996 +- module will be called rio500.
997 +-
998 + config USB_LEGOTOWER
999 + tristate "USB Lego Infrared Tower support"
1000 + help
1001 +diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
1002 +index 45fd4ac39d3e..0cbdd77363f2 100644
1003 +--- a/drivers/usb/misc/Makefile
1004 ++++ b/drivers/usb/misc/Makefile
1005 +@@ -17,7 +17,6 @@ obj-$(CONFIG_USB_LCD) += usblcd.o
1006 + obj-$(CONFIG_USB_LD) += ldusb.o
1007 + obj-$(CONFIG_USB_LED) += usbled.o
1008 + obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
1009 +-obj-$(CONFIG_USB_RIO500) += rio500.o
1010 + obj-$(CONFIG_USB_TEST) += usbtest.o
1011 + obj-$(CONFIG_USB_EHSET_TEST_FIXTURE) += ehset.o
1012 + obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
1013 +diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
1014 +index 3071c0ef909b..6d849e7dc842 100644
1015 +--- a/drivers/usb/misc/adutux.c
1016 ++++ b/drivers/usb/misc/adutux.c
1017 +@@ -80,6 +80,7 @@ struct adu_device {
1018 + char serial_number[8];
1019 +
1020 + int open_count; /* number of times this port has been opened */
1021 ++ unsigned long disconnected:1;
1022 +
1023 + char *read_buffer_primary;
1024 + int read_buffer_length;
1025 +@@ -121,7 +122,7 @@ static void adu_abort_transfers(struct adu_device *dev)
1026 + {
1027 + unsigned long flags;
1028 +
1029 +- if (dev->udev == NULL)
1030 ++ if (dev->disconnected)
1031 + return;
1032 +
1033 + /* shutdown transfer */
1034 +@@ -151,6 +152,7 @@ static void adu_delete(struct adu_device *dev)
1035 + kfree(dev->read_buffer_secondary);
1036 + kfree(dev->interrupt_in_buffer);
1037 + kfree(dev->interrupt_out_buffer);
1038 ++ usb_put_dev(dev->udev);
1039 + kfree(dev);
1040 + }
1041 +
1042 +@@ -244,7 +246,7 @@ static int adu_open(struct inode *inode, struct file *file)
1043 + }
1044 +
1045 + dev = usb_get_intfdata(interface);
1046 +- if (!dev || !dev->udev) {
1047 ++ if (!dev) {
1048 + retval = -ENODEV;
1049 + goto exit_no_device;
1050 + }
1051 +@@ -327,7 +329,7 @@ static int adu_release(struct inode *inode, struct file *file)
1052 + }
1053 +
1054 + adu_release_internal(dev);
1055 +- if (dev->udev == NULL) {
1056 ++ if (dev->disconnected) {
1057 + /* the device was unplugged before the file was released */
1058 + if (!dev->open_count) /* ... and we're the last user */
1059 + adu_delete(dev);
1060 +@@ -356,7 +358,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
1061 + return -ERESTARTSYS;
1062 +
1063 + /* verify that the device wasn't unplugged */
1064 +- if (dev->udev == NULL) {
1065 ++ if (dev->disconnected) {
1066 + retval = -ENODEV;
1067 + pr_err("No device or device unplugged %d\n", retval);
1068 + goto exit;
1069 +@@ -525,7 +527,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
1070 + goto exit_nolock;
1071 +
1072 + /* verify that the device wasn't unplugged */
1073 +- if (dev->udev == NULL) {
1074 ++ if (dev->disconnected) {
1075 + retval = -ENODEV;
1076 + pr_err("No device or device unplugged %d\n", retval);
1077 + goto exit;
1078 +@@ -680,7 +682,7 @@ static int adu_probe(struct usb_interface *interface,
1079 +
1080 + mutex_init(&dev->mtx);
1081 + spin_lock_init(&dev->buflock);
1082 +- dev->udev = udev;
1083 ++ dev->udev = usb_get_dev(udev);
1084 + init_waitqueue_head(&dev->read_wait);
1085 + init_waitqueue_head(&dev->write_wait);
1086 +
1087 +@@ -800,19 +802,21 @@ error:
1088 + static void adu_disconnect(struct usb_interface *interface)
1089 + {
1090 + struct adu_device *dev;
1091 +- int minor;
1092 +
1093 + dev = usb_get_intfdata(interface);
1094 +
1095 +- mutex_lock(&dev->mtx); /* not interruptible */
1096 +- dev->udev = NULL; /* poison */
1097 +- minor = dev->minor;
1098 + usb_deregister_dev(interface, &adu_class);
1099 +- mutex_unlock(&dev->mtx);
1100 ++
1101 ++ usb_poison_urb(dev->interrupt_in_urb);
1102 ++ usb_poison_urb(dev->interrupt_out_urb);
1103 +
1104 + mutex_lock(&adutux_mutex);
1105 + usb_set_intfdata(interface, NULL);
1106 +
1107 ++ mutex_lock(&dev->mtx); /* not interruptible */
1108 ++ dev->disconnected = 1;
1109 ++ mutex_unlock(&dev->mtx);
1110 ++
1111 + /* if the device is not opened, then we clean up right now */
1112 + if (!dev->open_count)
1113 + adu_delete(dev);
1114 +diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
1115 +index 23c794813e6a..a3692811248b 100644
1116 +--- a/drivers/usb/misc/chaoskey.c
1117 ++++ b/drivers/usb/misc/chaoskey.c
1118 +@@ -96,6 +96,7 @@ static void chaoskey_free(struct chaoskey *dev)
1119 + usb_dbg(dev->interface, "free");
1120 + kfree(dev->name);
1121 + kfree(dev->buf);
1122 ++ usb_put_intf(dev->interface);
1123 + kfree(dev);
1124 + }
1125 +
1126 +@@ -144,6 +145,8 @@ static int chaoskey_probe(struct usb_interface *interface,
1127 + if (dev == NULL)
1128 + return -ENOMEM;
1129 +
1130 ++ dev->interface = usb_get_intf(interface);
1131 ++
1132 + dev->buf = kmalloc(size, GFP_KERNEL);
1133 +
1134 + if (dev->buf == NULL) {
1135 +@@ -169,8 +172,6 @@ static int chaoskey_probe(struct usb_interface *interface,
1136 + strcat(dev->name, udev->serial);
1137 + }
1138 +
1139 +- dev->interface = interface;
1140 +-
1141 + dev->in_ep = in_ep;
1142 +
1143 + dev->size = size;
1144 +diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
1145 +index 836fb65c3c72..83342e579233 100644
1146 +--- a/drivers/usb/misc/iowarrior.c
1147 ++++ b/drivers/usb/misc/iowarrior.c
1148 +@@ -89,6 +89,7 @@ struct iowarrior {
1149 + char chip_serial[9]; /* the serial number string of the chip connected */
1150 + int report_size; /* number of bytes in a report */
1151 + u16 product_id;
1152 ++ struct usb_anchor submitted;
1153 + };
1154 +
1155 + /*--------------*/
1156 +@@ -248,6 +249,7 @@ static inline void iowarrior_delete(struct iowarrior *dev)
1157 + kfree(dev->int_in_buffer);
1158 + usb_free_urb(dev->int_in_urb);
1159 + kfree(dev->read_queue);
1160 ++ usb_put_intf(dev->interface);
1161 + kfree(dev);
1162 + }
1163 +
1164 +@@ -436,11 +438,13 @@ static ssize_t iowarrior_write(struct file *file,
1165 + retval = -EFAULT;
1166 + goto error;
1167 + }
1168 ++ usb_anchor_urb(int_out_urb, &dev->submitted);
1169 + retval = usb_submit_urb(int_out_urb, GFP_KERNEL);
1170 + if (retval) {
1171 + dev_dbg(&dev->interface->dev,
1172 + "submit error %d for urb nr.%d\n",
1173 + retval, atomic_read(&dev->write_busy));
1174 ++ usb_unanchor_urb(int_out_urb);
1175 + goto error;
1176 + }
1177 + /* submit was ok */
1178 +@@ -782,11 +786,13 @@ static int iowarrior_probe(struct usb_interface *interface,
1179 + init_waitqueue_head(&dev->write_wait);
1180 +
1181 + dev->udev = udev;
1182 +- dev->interface = interface;
1183 ++ dev->interface = usb_get_intf(interface);
1184 +
1185 + iface_desc = interface->cur_altsetting;
1186 + dev->product_id = le16_to_cpu(udev->descriptor.idProduct);
1187 +
1188 ++ init_usb_anchor(&dev->submitted);
1189 ++
1190 + /* set up the endpoint information */
1191 + for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1192 + endpoint = &iface_desc->endpoint[i].desc;
1193 +@@ -898,8 +904,6 @@ static void iowarrior_disconnect(struct usb_interface *interface)
1194 + dev = usb_get_intfdata(interface);
1195 + mutex_lock(&iowarrior_open_disc_lock);
1196 + usb_set_intfdata(interface, NULL);
1197 +- /* prevent device read, write and ioctl */
1198 +- dev->present = 0;
1199 +
1200 + minor = dev->minor;
1201 + mutex_unlock(&iowarrior_open_disc_lock);
1202 +@@ -910,8 +914,7 @@ static void iowarrior_disconnect(struct usb_interface *interface)
1203 + mutex_lock(&dev->mutex);
1204 +
1205 + /* prevent device read, write and ioctl */
1206 +-
1207 +- mutex_unlock(&dev->mutex);
1208 ++ dev->present = 0;
1209 +
1210 + if (dev->opened) {
1211 + /* There is a process that holds a filedescriptor to the device ,
1212 +@@ -919,10 +922,13 @@ static void iowarrior_disconnect(struct usb_interface *interface)
1213 + Deleting the device is postponed until close() was called.
1214 + */
1215 + usb_kill_urb(dev->int_in_urb);
1216 ++ usb_kill_anchored_urbs(&dev->submitted);
1217 + wake_up_interruptible(&dev->read_wait);
1218 + wake_up_interruptible(&dev->write_wait);
1219 ++ mutex_unlock(&dev->mutex);
1220 + } else {
1221 + /* no process is using the device, cleanup now */
1222 ++ mutex_unlock(&dev->mutex);
1223 + iowarrior_delete(dev);
1224 + }
1225 +
1226 +diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
1227 +index e9113238d9e3..84f12c1bf9e6 100644
1228 +--- a/drivers/usb/misc/ldusb.c
1229 ++++ b/drivers/usb/misc/ldusb.c
1230 +@@ -158,6 +158,7 @@ MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in
1231 + struct ld_usb {
1232 + struct mutex mutex; /* locks this structure */
1233 + struct usb_interface* intf; /* save off the usb interface pointer */
1234 ++ unsigned long disconnected:1;
1235 +
1236 + int open_count; /* number of times this port has been opened */
1237 +
1238 +@@ -197,12 +198,10 @@ static void ld_usb_abort_transfers(struct ld_usb *dev)
1239 + /* shutdown transfer */
1240 + if (dev->interrupt_in_running) {
1241 + dev->interrupt_in_running = 0;
1242 +- if (dev->intf)
1243 +- usb_kill_urb(dev->interrupt_in_urb);
1244 ++ usb_kill_urb(dev->interrupt_in_urb);
1245 + }
1246 + if (dev->interrupt_out_busy)
1247 +- if (dev->intf)
1248 +- usb_kill_urb(dev->interrupt_out_urb);
1249 ++ usb_kill_urb(dev->interrupt_out_urb);
1250 + }
1251 +
1252 + /**
1253 +@@ -210,8 +209,6 @@ static void ld_usb_abort_transfers(struct ld_usb *dev)
1254 + */
1255 + static void ld_usb_delete(struct ld_usb *dev)
1256 + {
1257 +- ld_usb_abort_transfers(dev);
1258 +-
1259 + /* free data structures */
1260 + usb_free_urb(dev->interrupt_in_urb);
1261 + usb_free_urb(dev->interrupt_out_urb);
1262 +@@ -267,7 +264,7 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
1263 +
1264 + resubmit:
1265 + /* resubmit if we're still running */
1266 +- if (dev->interrupt_in_running && !dev->buffer_overflow && dev->intf) {
1267 ++ if (dev->interrupt_in_running && !dev->buffer_overflow) {
1268 + retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
1269 + if (retval) {
1270 + dev_err(&dev->intf->dev,
1271 +@@ -396,7 +393,7 @@ static int ld_usb_release(struct inode *inode, struct file *file)
1272 + retval = -ENODEV;
1273 + goto unlock_exit;
1274 + }
1275 +- if (dev->intf == NULL) {
1276 ++ if (dev->disconnected) {
1277 + /* the device was unplugged before the file was released */
1278 + mutex_unlock(&dev->mutex);
1279 + /* unlock here as ld_usb_delete frees dev */
1280 +@@ -427,7 +424,7 @@ static unsigned int ld_usb_poll(struct file *file, poll_table *wait)
1281 +
1282 + dev = file->private_data;
1283 +
1284 +- if (!dev->intf)
1285 ++ if (dev->disconnected)
1286 + return POLLERR | POLLHUP;
1287 +
1288 + poll_wait(file, &dev->read_wait, wait);
1289 +@@ -466,7 +463,7 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
1290 + }
1291 +
1292 + /* verify that the device wasn't unplugged */
1293 +- if (dev->intf == NULL) {
1294 ++ if (dev->disconnected) {
1295 + retval = -ENODEV;
1296 + printk(KERN_ERR "ldusb: No device or device unplugged %d\n", retval);
1297 + goto unlock_exit;
1298 +@@ -546,7 +543,7 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
1299 + }
1300 +
1301 + /* verify that the device wasn't unplugged */
1302 +- if (dev->intf == NULL) {
1303 ++ if (dev->disconnected) {
1304 + retval = -ENODEV;
1305 + printk(KERN_ERR "ldusb: No device or device unplugged %d\n", retval);
1306 + goto unlock_exit;
1307 +@@ -782,6 +779,9 @@ static void ld_usb_disconnect(struct usb_interface *intf)
1308 + /* give back our minor */
1309 + usb_deregister_dev(intf, &ld_usb_class);
1310 +
1311 ++ usb_poison_urb(dev->interrupt_in_urb);
1312 ++ usb_poison_urb(dev->interrupt_out_urb);
1313 ++
1314 + mutex_lock(&dev->mutex);
1315 +
1316 + /* if the device is not opened, then we clean up right now */
1317 +@@ -789,7 +789,7 @@ static void ld_usb_disconnect(struct usb_interface *intf)
1318 + mutex_unlock(&dev->mutex);
1319 + ld_usb_delete(dev);
1320 + } else {
1321 +- dev->intf = NULL;
1322 ++ dev->disconnected = 1;
1323 + /* wake up pollers */
1324 + wake_up_interruptible_all(&dev->read_wait);
1325 + wake_up_interruptible_all(&dev->write_wait);
1326 +diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
1327 +index 0ec9ee573ffa..20e3d577ae5d 100644
1328 +--- a/drivers/usb/misc/legousbtower.c
1329 ++++ b/drivers/usb/misc/legousbtower.c
1330 +@@ -185,7 +185,6 @@ static const struct usb_device_id tower_table[] = {
1331 + };
1332 +
1333 + MODULE_DEVICE_TABLE (usb, tower_table);
1334 +-static DEFINE_MUTEX(open_disc_mutex);
1335 +
1336 + #define LEGO_USB_TOWER_MINOR_BASE 160
1337 +
1338 +@@ -197,6 +196,7 @@ struct lego_usb_tower {
1339 + unsigned char minor; /* the starting minor number for this device */
1340 +
1341 + int open_count; /* number of times this port has been opened */
1342 ++ unsigned long disconnected:1;
1343 +
1344 + char* read_buffer;
1345 + size_t read_buffer_length; /* this much came in */
1346 +@@ -296,14 +296,13 @@ static inline void lego_usb_tower_debug_data(struct device *dev,
1347 + */
1348 + static inline void tower_delete (struct lego_usb_tower *dev)
1349 + {
1350 +- tower_abort_transfers (dev);
1351 +-
1352 + /* free data structures */
1353 + usb_free_urb(dev->interrupt_in_urb);
1354 + usb_free_urb(dev->interrupt_out_urb);
1355 + kfree (dev->read_buffer);
1356 + kfree (dev->interrupt_in_buffer);
1357 + kfree (dev->interrupt_out_buffer);
1358 ++ usb_put_dev(dev->udev);
1359 + kfree (dev);
1360 + }
1361 +
1362 +@@ -338,18 +337,14 @@ static int tower_open (struct inode *inode, struct file *file)
1363 + goto exit;
1364 + }
1365 +
1366 +- mutex_lock(&open_disc_mutex);
1367 + dev = usb_get_intfdata(interface);
1368 +-
1369 + if (!dev) {
1370 +- mutex_unlock(&open_disc_mutex);
1371 + retval = -ENODEV;
1372 + goto exit;
1373 + }
1374 +
1375 + /* lock this device */
1376 + if (mutex_lock_interruptible(&dev->lock)) {
1377 +- mutex_unlock(&open_disc_mutex);
1378 + retval = -ERESTARTSYS;
1379 + goto exit;
1380 + }
1381 +@@ -357,12 +352,9 @@ static int tower_open (struct inode *inode, struct file *file)
1382 +
1383 + /* allow opening only once */
1384 + if (dev->open_count) {
1385 +- mutex_unlock(&open_disc_mutex);
1386 + retval = -EBUSY;
1387 + goto unlock_exit;
1388 + }
1389 +- dev->open_count = 1;
1390 +- mutex_unlock(&open_disc_mutex);
1391 +
1392 + /* reset the tower */
1393 + result = usb_control_msg (dev->udev,
1394 +@@ -402,13 +394,14 @@ static int tower_open (struct inode *inode, struct file *file)
1395 + dev_err(&dev->udev->dev,
1396 + "Couldn't submit interrupt_in_urb %d\n", retval);
1397 + dev->interrupt_in_running = 0;
1398 +- dev->open_count = 0;
1399 + goto unlock_exit;
1400 + }
1401 +
1402 + /* save device in the file's private structure */
1403 + file->private_data = dev;
1404 +
1405 ++ dev->open_count = 1;
1406 ++
1407 + unlock_exit:
1408 + mutex_unlock(&dev->lock);
1409 +
1410 +@@ -429,10 +422,9 @@ static int tower_release (struct inode *inode, struct file *file)
1411 +
1412 + if (dev == NULL) {
1413 + retval = -ENODEV;
1414 +- goto exit_nolock;
1415 ++ goto exit;
1416 + }
1417 +
1418 +- mutex_lock(&open_disc_mutex);
1419 + if (mutex_lock_interruptible(&dev->lock)) {
1420 + retval = -ERESTARTSYS;
1421 + goto exit;
1422 +@@ -444,7 +436,8 @@ static int tower_release (struct inode *inode, struct file *file)
1423 + retval = -ENODEV;
1424 + goto unlock_exit;
1425 + }
1426 +- if (dev->udev == NULL) {
1427 ++
1428 ++ if (dev->disconnected) {
1429 + /* the device was unplugged before the file was released */
1430 +
1431 + /* unlock here as tower_delete frees dev */
1432 +@@ -462,10 +455,7 @@ static int tower_release (struct inode *inode, struct file *file)
1433 +
1434 + unlock_exit:
1435 + mutex_unlock(&dev->lock);
1436 +-
1437 + exit:
1438 +- mutex_unlock(&open_disc_mutex);
1439 +-exit_nolock:
1440 + return retval;
1441 + }
1442 +
1443 +@@ -483,10 +473,9 @@ static void tower_abort_transfers (struct lego_usb_tower *dev)
1444 + if (dev->interrupt_in_running) {
1445 + dev->interrupt_in_running = 0;
1446 + mb();
1447 +- if (dev->udev)
1448 +- usb_kill_urb (dev->interrupt_in_urb);
1449 ++ usb_kill_urb(dev->interrupt_in_urb);
1450 + }
1451 +- if (dev->interrupt_out_busy && dev->udev)
1452 ++ if (dev->interrupt_out_busy)
1453 + usb_kill_urb(dev->interrupt_out_urb);
1454 + }
1455 +
1456 +@@ -522,7 +511,7 @@ static unsigned int tower_poll (struct file *file, poll_table *wait)
1457 +
1458 + dev = file->private_data;
1459 +
1460 +- if (!dev->udev)
1461 ++ if (dev->disconnected)
1462 + return POLLERR | POLLHUP;
1463 +
1464 + poll_wait(file, &dev->read_wait, wait);
1465 +@@ -569,7 +558,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
1466 + }
1467 +
1468 + /* verify that the device wasn't unplugged */
1469 +- if (dev->udev == NULL) {
1470 ++ if (dev->disconnected) {
1471 + retval = -ENODEV;
1472 + pr_err("No device or device unplugged %d\n", retval);
1473 + goto unlock_exit;
1474 +@@ -655,7 +644,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
1475 + }
1476 +
1477 + /* verify that the device wasn't unplugged */
1478 +- if (dev->udev == NULL) {
1479 ++ if (dev->disconnected) {
1480 + retval = -ENODEV;
1481 + pr_err("No device or device unplugged %d\n", retval);
1482 + goto unlock_exit;
1483 +@@ -764,7 +753,7 @@ static void tower_interrupt_in_callback (struct urb *urb)
1484 +
1485 + resubmit:
1486 + /* resubmit if we're still running */
1487 +- if (dev->interrupt_in_running && dev->udev) {
1488 ++ if (dev->interrupt_in_running) {
1489 + retval = usb_submit_urb (dev->interrupt_in_urb, GFP_ATOMIC);
1490 + if (retval)
1491 + dev_err(&dev->udev->dev,
1492 +@@ -832,8 +821,9 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
1493 +
1494 + mutex_init(&dev->lock);
1495 +
1496 +- dev->udev = udev;
1497 ++ dev->udev = usb_get_dev(udev);
1498 + dev->open_count = 0;
1499 ++ dev->disconnected = 0;
1500 +
1501 + dev->read_buffer = NULL;
1502 + dev->read_buffer_length = 0;
1503 +@@ -923,8 +913,10 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
1504 + get_version_reply,
1505 + sizeof(*get_version_reply),
1506 + 1000);
1507 +- if (result < 0) {
1508 +- dev_err(idev, "LEGO USB Tower get version control request failed\n");
1509 ++ if (result < sizeof(*get_version_reply)) {
1510 ++ if (result >= 0)
1511 ++ result = -EIO;
1512 ++ dev_err(idev, "get version request failed: %d\n", result);
1513 + retval = result;
1514 + goto error;
1515 + }
1516 +@@ -942,7 +934,6 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
1517 + if (retval) {
1518 + /* something prevented us from registering this driver */
1519 + dev_err(idev, "Not able to get a minor for this device.\n");
1520 +- usb_set_intfdata (interface, NULL);
1521 + goto error;
1522 + }
1523 + dev->minor = interface->minor;
1524 +@@ -974,23 +965,24 @@ static void tower_disconnect (struct usb_interface *interface)
1525 + int minor;
1526 +
1527 + dev = usb_get_intfdata (interface);
1528 +- mutex_lock(&open_disc_mutex);
1529 +- usb_set_intfdata (interface, NULL);
1530 +
1531 + minor = dev->minor;
1532 +
1533 +- /* give back our minor */
1534 ++ /* give back our minor and prevent further open() */
1535 + usb_deregister_dev (interface, &tower_class);
1536 +
1537 ++ /* stop I/O */
1538 ++ usb_poison_urb(dev->interrupt_in_urb);
1539 ++ usb_poison_urb(dev->interrupt_out_urb);
1540 ++
1541 + mutex_lock(&dev->lock);
1542 +- mutex_unlock(&open_disc_mutex);
1543 +
1544 + /* if the device is not opened, then we clean up right now */
1545 + if (!dev->open_count) {
1546 + mutex_unlock(&dev->lock);
1547 + tower_delete (dev);
1548 + } else {
1549 +- dev->udev = NULL;
1550 ++ dev->disconnected = 1;
1551 + /* wake up pollers */
1552 + wake_up_interruptible_all(&dev->read_wait);
1553 + wake_up_interruptible_all(&dev->write_wait);
1554 +diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
1555 +deleted file mode 100644
1556 +index 6e761fabffca..000000000000
1557 +--- a/drivers/usb/misc/rio500.c
1558 ++++ /dev/null
1559 +@@ -1,578 +0,0 @@
1560 +-/* -*- linux-c -*- */
1561 +-
1562 +-/*
1563 +- * Driver for USB Rio 500
1564 +- *
1565 +- * Cesar Miquel (miquel@××××××.ar)
1566 +- *
1567 +- * based on hp_scanner.c by David E. Nelson (dnelson@××××.net)
1568 +- *
1569 +- * This program is free software; you can redistribute it and/or
1570 +- * modify it under the terms of the GNU General Public License as
1571 +- * published by the Free Software Foundation; either version 2 of the
1572 +- * License, or (at your option) any later version.
1573 +- *
1574 +- * This program is distributed in the hope that it will be useful, but
1575 +- * WITHOUT ANY WARRANTY; without even the implied warranty of
1576 +- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1577 +- * General Public License for more details.
1578 +- *
1579 +- * You should have received a copy of the GNU General Public License
1580 +- * along with this program; if not, write to the Free Software
1581 +- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1582 +- *
1583 +- * Based upon mouse.c (Brad Keryan) and printer.c (Michael Gee).
1584 +- *
1585 +- * Changelog:
1586 +- * 30/05/2003 replaced lock/unlock kernel with up/down
1587 +- * Daniele Bellucci bellucda@×××××××.it
1588 +- * */
1589 +-
1590 +-#include <linux/module.h>
1591 +-#include <linux/kernel.h>
1592 +-#include <linux/signal.h>
1593 +-#include <linux/sched.h>
1594 +-#include <linux/mutex.h>
1595 +-#include <linux/errno.h>
1596 +-#include <linux/random.h>
1597 +-#include <linux/poll.h>
1598 +-#include <linux/slab.h>
1599 +-#include <linux/spinlock.h>
1600 +-#include <linux/usb.h>
1601 +-#include <linux/wait.h>
1602 +-
1603 +-#include "rio500_usb.h"
1604 +-
1605 +-/*
1606 +- * Version Information
1607 +- */
1608 +-#define DRIVER_VERSION "v1.1"
1609 +-#define DRIVER_AUTHOR "Cesar Miquel <miquel@××××××.ar>"
1610 +-#define DRIVER_DESC "USB Rio 500 driver"
1611 +-
1612 +-#define RIO_MINOR 64
1613 +-
1614 +-/* stall/wait timeout for rio */
1615 +-#define NAK_TIMEOUT (HZ)
1616 +-
1617 +-#define IBUF_SIZE 0x1000
1618 +-
1619 +-/* Size of the rio buffer */
1620 +-#define OBUF_SIZE 0x10000
1621 +-
1622 +-struct rio_usb_data {
1623 +- struct usb_device *rio_dev; /* init: probe_rio */
1624 +- unsigned int ifnum; /* Interface number of the USB device */
1625 +- int isopen; /* nz if open */
1626 +- int present; /* Device is present on the bus */
1627 +- char *obuf, *ibuf; /* transfer buffers */
1628 +- char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */
1629 +- wait_queue_head_t wait_q; /* for timeouts */
1630 +- struct mutex lock; /* general race avoidance */
1631 +-};
1632 +-
1633 +-static DEFINE_MUTEX(rio500_mutex);
1634 +-static struct rio_usb_data rio_instance;
1635 +-
1636 +-static int open_rio(struct inode *inode, struct file *file)
1637 +-{
1638 +- struct rio_usb_data *rio = &rio_instance;
1639 +-
1640 +- /* against disconnect() */
1641 +- mutex_lock(&rio500_mutex);
1642 +- mutex_lock(&(rio->lock));
1643 +-
1644 +- if (rio->isopen || !rio->present) {
1645 +- mutex_unlock(&(rio->lock));
1646 +- mutex_unlock(&rio500_mutex);
1647 +- return -EBUSY;
1648 +- }
1649 +- rio->isopen = 1;
1650 +-
1651 +- init_waitqueue_head(&rio->wait_q);
1652 +-
1653 +- mutex_unlock(&(rio->lock));
1654 +-
1655 +- dev_info(&rio->rio_dev->dev, "Rio opened.\n");
1656 +- mutex_unlock(&rio500_mutex);
1657 +-
1658 +- return 0;
1659 +-}
1660 +-
1661 +-static int close_rio(struct inode *inode, struct file *file)
1662 +-{
1663 +- struct rio_usb_data *rio = &rio_instance;
1664 +-
1665 +- /* against disconnect() */
1666 +- mutex_lock(&rio500_mutex);
1667 +- mutex_lock(&(rio->lock));
1668 +-
1669 +- rio->isopen = 0;
1670 +- if (!rio->present) {
1671 +- /* cleanup has been delayed */
1672 +- kfree(rio->ibuf);
1673 +- kfree(rio->obuf);
1674 +- rio->ibuf = NULL;
1675 +- rio->obuf = NULL;
1676 +- } else {
1677 +- dev_info(&rio->rio_dev->dev, "Rio closed.\n");
1678 +- }
1679 +- mutex_unlock(&(rio->lock));
1680 +- mutex_unlock(&rio500_mutex);
1681 +- return 0;
1682 +-}
1683 +-
1684 +-static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
1685 +-{
1686 +- struct RioCommand rio_cmd;
1687 +- struct rio_usb_data *rio = &rio_instance;
1688 +- void __user *data;
1689 +- unsigned char *buffer;
1690 +- int result, requesttype;
1691 +- int retries;
1692 +- int retval=0;
1693 +-
1694 +- mutex_lock(&(rio->lock));
1695 +- /* Sanity check to make sure rio is connected, powered, etc */
1696 +- if (rio->present == 0 || rio->rio_dev == NULL) {
1697 +- retval = -ENODEV;
1698 +- goto err_out;
1699 +- }
1700 +-
1701 +- switch (cmd) {
1702 +- case RIO_RECV_COMMAND:
1703 +- data = (void __user *) arg;
1704 +- if (data == NULL)
1705 +- break;
1706 +- if (copy_from_user(&rio_cmd, data, sizeof(struct RioCommand))) {
1707 +- retval = -EFAULT;
1708 +- goto err_out;
1709 +- }
1710 +- if (rio_cmd.length < 0 || rio_cmd.length > PAGE_SIZE) {
1711 +- retval = -EINVAL;
1712 +- goto err_out;
1713 +- }
1714 +- buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
1715 +- if (buffer == NULL) {
1716 +- retval = -ENOMEM;
1717 +- goto err_out;
1718 +- }
1719 +- if (copy_from_user(buffer, rio_cmd.buffer, rio_cmd.length)) {
1720 +- retval = -EFAULT;
1721 +- free_page((unsigned long) buffer);
1722 +- goto err_out;
1723 +- }
1724 +-
1725 +- requesttype = rio_cmd.requesttype | USB_DIR_IN |
1726 +- USB_TYPE_VENDOR | USB_RECIP_DEVICE;
1727 +- dev_dbg(&rio->rio_dev->dev,
1728 +- "sending command:reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
1729 +- requesttype, rio_cmd.request, rio_cmd.value,
1730 +- rio_cmd.index, rio_cmd.length);
1731 +- /* Send rio control message */
1732 +- retries = 3;
1733 +- while (retries) {
1734 +- result = usb_control_msg(rio->rio_dev,
1735 +- usb_rcvctrlpipe(rio-> rio_dev, 0),
1736 +- rio_cmd.request,
1737 +- requesttype,
1738 +- rio_cmd.value,
1739 +- rio_cmd.index, buffer,
1740 +- rio_cmd.length,
1741 +- jiffies_to_msecs(rio_cmd.timeout));
1742 +- if (result == -ETIMEDOUT)
1743 +- retries--;
1744 +- else if (result < 0) {
1745 +- dev_err(&rio->rio_dev->dev,
1746 +- "Error executing ioctrl. code = %d\n",
1747 +- result);
1748 +- retries = 0;
1749 +- } else {
1750 +- dev_dbg(&rio->rio_dev->dev,
1751 +- "Executed ioctl. Result = %d (data=%02x)\n",
1752 +- result, buffer[0]);
1753 +- if (copy_to_user(rio_cmd.buffer, buffer,
1754 +- rio_cmd.length)) {
1755 +- free_page((unsigned long) buffer);
1756 +- retval = -EFAULT;
1757 +- goto err_out;
1758 +- }
1759 +- retries = 0;
1760 +- }
1761 +-
1762 +- /* rio_cmd.buffer contains a raw stream of single byte
1763 +- data which has been returned from rio. Data is
1764 +- interpreted at application level. For data that
1765 +- will be cast to data types longer than 1 byte, data
1766 +- will be little_endian and will potentially need to
1767 +- be swapped at the app level */
1768 +-
1769 +- }
1770 +- free_page((unsigned long) buffer);
1771 +- break;
1772 +-
1773 +- case RIO_SEND_COMMAND:
1774 +- data = (void __user *) arg;
1775 +- if (data == NULL)
1776 +- break;
1777 +- if (copy_from_user(&rio_cmd, data, sizeof(struct RioCommand))) {
1778 +- retval = -EFAULT;
1779 +- goto err_out;
1780 +- }
1781 +- if (rio_cmd.length < 0 || rio_cmd.length > PAGE_SIZE) {
1782 +- retval = -EINVAL;
1783 +- goto err_out;
1784 +- }
1785 +- buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
1786 +- if (buffer == NULL) {
1787 +- retval = -ENOMEM;
1788 +- goto err_out;
1789 +- }
1790 +- if (copy_from_user(buffer, rio_cmd.buffer, rio_cmd.length)) {
1791 +- free_page((unsigned long)buffer);
1792 +- retval = -EFAULT;
1793 +- goto err_out;
1794 +- }
1795 +-
1796 +- requesttype = rio_cmd.requesttype | USB_DIR_OUT |
1797 +- USB_TYPE_VENDOR | USB_RECIP_DEVICE;
1798 +- dev_dbg(&rio->rio_dev->dev,
1799 +- "sending command: reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
1800 +- requesttype, rio_cmd.request, rio_cmd.value,
1801 +- rio_cmd.index, rio_cmd.length);
1802 +- /* Send rio control message */
1803 +- retries = 3;
1804 +- while (retries) {
1805 +- result = usb_control_msg(rio->rio_dev,
1806 +- usb_sndctrlpipe(rio-> rio_dev, 0),
1807 +- rio_cmd.request,
1808 +- requesttype,
1809 +- rio_cmd.value,
1810 +- rio_cmd.index, buffer,
1811 +- rio_cmd.length,
1812 +- jiffies_to_msecs(rio_cmd.timeout));
1813 +- if (result == -ETIMEDOUT)
1814 +- retries--;
1815 +- else if (result < 0) {
1816 +- dev_err(&rio->rio_dev->dev,
1817 +- "Error executing ioctrl. code = %d\n",
1818 +- result);
1819 +- retries = 0;
1820 +- } else {
1821 +- dev_dbg(&rio->rio_dev->dev,
1822 +- "Executed ioctl. Result = %d\n", result);
1823 +- retries = 0;
1824 +-
1825 +- }
1826 +-
1827 +- }
1828 +- free_page((unsigned long) buffer);
1829 +- break;
1830 +-
1831 +- default:
1832 +- retval = -ENOTTY;
1833 +- break;
1834 +- }
1835 +-
1836 +-
1837 +-err_out:
1838 +- mutex_unlock(&(rio->lock));
1839 +- return retval;
1840 +-}
1841 +-
1842 +-static ssize_t
1843 +-write_rio(struct file *file, const char __user *buffer,
1844 +- size_t count, loff_t * ppos)
1845 +-{
1846 +- DEFINE_WAIT(wait);
1847 +- struct rio_usb_data *rio = &rio_instance;
1848 +-
1849 +- unsigned long copy_size;
1850 +- unsigned long bytes_written = 0;
1851 +- unsigned int partial;
1852 +-
1853 +- int result = 0;
1854 +- int maxretry;
1855 +- int errn = 0;
1856 +- int intr;
1857 +-
1858 +- intr = mutex_lock_interruptible(&(rio->lock));
1859 +- if (intr)
1860 +- return -EINTR;
1861 +- /* Sanity check to make sure rio is connected, powered, etc */
1862 +- if (rio->present == 0 || rio->rio_dev == NULL) {
1863 +- mutex_unlock(&(rio->lock));
1864 +- return -ENODEV;
1865 +- }
1866 +-
1867 +-
1868 +-
1869 +- do {
1870 +- unsigned long thistime;
1871 +- char *obuf = rio->obuf;
1872 +-
1873 +- thistime = copy_size =
1874 +- (count >= OBUF_SIZE) ? OBUF_SIZE : count;
1875 +- if (copy_from_user(rio->obuf, buffer, copy_size)) {
1876 +- errn = -EFAULT;
1877 +- goto error;
1878 +- }
1879 +- maxretry = 5;
1880 +- while (thistime) {
1881 +- if (!rio->rio_dev) {
1882 +- errn = -ENODEV;
1883 +- goto error;
1884 +- }
1885 +- if (signal_pending(current)) {
1886 +- mutex_unlock(&(rio->lock));
1887 +- return bytes_written ? bytes_written : -EINTR;
1888 +- }
1889 +-
1890 +- result = usb_bulk_msg(rio->rio_dev,
1891 +- usb_sndbulkpipe(rio->rio_dev, 2),
1892 +- obuf, thistime, &partial, 5000);
1893 +-
1894 +- dev_dbg(&rio->rio_dev->dev,
1895 +- "write stats: result:%d thistime:%lu partial:%u\n",
1896 +- result, thistime, partial);
1897 +-
1898 +- if (result == -ETIMEDOUT) { /* NAK - so hold for a while */
1899 +- if (!maxretry--) {
1900 +- errn = -ETIME;
1901 +- goto error;
1902 +- }
1903 +- prepare_to_wait(&rio->wait_q, &wait, TASK_INTERRUPTIBLE);
1904 +- schedule_timeout(NAK_TIMEOUT);
1905 +- finish_wait(&rio->wait_q, &wait);
1906 +- continue;
1907 +- } else if (!result && partial) {
1908 +- obuf += partial;
1909 +- thistime -= partial;
1910 +- } else
1911 +- break;
1912 +- }
1913 +- if (result) {
1914 +- dev_err(&rio->rio_dev->dev, "Write Whoops - %x\n",
1915 +- result);
1916 +- errn = -EIO;
1917 +- goto error;
1918 +- }
1919 +- bytes_written += copy_size;
1920 +- count -= copy_size;
1921 +- buffer += copy_size;
1922 +- } while (count > 0);
1923 +-
1924 +- mutex_unlock(&(rio->lock));
1925 +-
1926 +- return bytes_written ? bytes_written : -EIO;
1927 +-
1928 +-error:
1929 +- mutex_unlock(&(rio->lock));
1930 +- return errn;
1931 +-}
1932 +-
1933 +-static ssize_t
1934 +-read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
1935 +-{
1936 +- DEFINE_WAIT(wait);
1937 +- struct rio_usb_data *rio = &rio_instance;
1938 +- ssize_t read_count;
1939 +- unsigned int partial;
1940 +- int this_read;
1941 +- int result;
1942 +- int maxretry = 10;
1943 +- char *ibuf;
1944 +- int intr;
1945 +-
1946 +- intr = mutex_lock_interruptible(&(rio->lock));
1947 +- if (intr)
1948 +- return -EINTR;
1949 +- /* Sanity check to make sure rio is connected, powered, etc */
1950 +- if (rio->present == 0 || rio->rio_dev == NULL) {
1951 +- mutex_unlock(&(rio->lock));
1952 +- return -ENODEV;
1953 +- }
1954 +-
1955 +- ibuf = rio->ibuf;
1956 +-
1957 +- read_count = 0;
1958 +-
1959 +-
1960 +- while (count > 0) {
1961 +- if (signal_pending(current)) {
1962 +- mutex_unlock(&(rio->lock));
1963 +- return read_count ? read_count : -EINTR;
1964 +- }
1965 +- if (!rio->rio_dev) {
1966 +- mutex_unlock(&(rio->lock));
1967 +- return -ENODEV;
1968 +- }
1969 +- this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count;
1970 +-
1971 +- result = usb_bulk_msg(rio->rio_dev,
1972 +- usb_rcvbulkpipe(rio->rio_dev, 1),
1973 +- ibuf, this_read, &partial,
1974 +- 8000);
1975 +-
1976 +- dev_dbg(&rio->rio_dev->dev,
1977 +- "read stats: result:%d this_read:%u partial:%u\n",
1978 +- result, this_read, partial);
1979 +-
1980 +- if (partial) {
1981 +- count = this_read = partial;
1982 +- } else if (result == -ETIMEDOUT || result == 15) { /* FIXME: 15 ??? */
1983 +- if (!maxretry--) {
1984 +- mutex_unlock(&(rio->lock));
1985 +- dev_err(&rio->rio_dev->dev,
1986 +- "read_rio: maxretry timeout\n");
1987 +- return -ETIME;
1988 +- }
1989 +- prepare_to_wait(&rio->wait_q, &wait, TASK_INTERRUPTIBLE);
1990 +- schedule_timeout(NAK_TIMEOUT);
1991 +- finish_wait(&rio->wait_q, &wait);
1992 +- continue;
1993 +- } else if (result != -EREMOTEIO) {
1994 +- mutex_unlock(&(rio->lock));
1995 +- dev_err(&rio->rio_dev->dev,
1996 +- "Read Whoops - result:%u partial:%u this_read:%u\n",
1997 +- result, partial, this_read);
1998 +- return -EIO;
1999 +- } else {
2000 +- mutex_unlock(&(rio->lock));
2001 +- return (0);
2002 +- }
2003 +-
2004 +- if (this_read) {
2005 +- if (copy_to_user(buffer, ibuf, this_read)) {
2006 +- mutex_unlock(&(rio->lock));
2007 +- return -EFAULT;
2008 +- }
2009 +- count -= this_read;
2010 +- read_count += this_read;
2011 +- buffer += this_read;
2012 +- }
2013 +- }
2014 +- mutex_unlock(&(rio->lock));
2015 +- return read_count;
2016 +-}
2017 +-
2018 +-static const struct file_operations usb_rio_fops = {
2019 +- .owner = THIS_MODULE,
2020 +- .read = read_rio,
2021 +- .write = write_rio,
2022 +- .unlocked_ioctl = ioctl_rio,
2023 +- .open = open_rio,
2024 +- .release = close_rio,
2025 +- .llseek = noop_llseek,
2026 +-};
2027 +-
2028 +-static struct usb_class_driver usb_rio_class = {
2029 +- .name = "rio500%d",
2030 +- .fops = &usb_rio_fops,
2031 +- .minor_base = RIO_MINOR,
2032 +-};
2033 +-
2034 +-static int probe_rio(struct usb_interface *intf,
2035 +- const struct usb_device_id *id)
2036 +-{
2037 +- struct usb_device *dev = interface_to_usbdev(intf);
2038 +- struct rio_usb_data *rio = &rio_instance;
2039 +- int retval = 0;
2040 +-
2041 +- mutex_lock(&rio500_mutex);
2042 +- if (rio->present) {
2043 +- dev_info(&intf->dev, "Second USB Rio at address %d refused\n", dev->devnum);
2044 +- retval = -EBUSY;
2045 +- goto bail_out;
2046 +- } else {
2047 +- dev_info(&intf->dev, "USB Rio found at address %d\n", dev->devnum);
2048 +- }
2049 +-
2050 +- retval = usb_register_dev(intf, &usb_rio_class);
2051 +- if (retval) {
2052 +- dev_err(&dev->dev,
2053 +- "Not able to get a minor for this device.\n");
2054 +- retval = -ENOMEM;
2055 +- goto bail_out;
2056 +- }
2057 +-
2058 +- rio->rio_dev = dev;
2059 +-
2060 +- if (!(rio->obuf = kmalloc(OBUF_SIZE, GFP_KERNEL))) {
2061 +- dev_err(&dev->dev,
2062 +- "probe_rio: Not enough memory for the output buffer\n");
2063 +- usb_deregister_dev(intf, &usb_rio_class);
2064 +- retval = -ENOMEM;
2065 +- goto bail_out;
2066 +- }
2067 +- dev_dbg(&intf->dev, "obuf address:%p\n", rio->obuf);
2068 +-
2069 +- if (!(rio->ibuf = kmalloc(IBUF_SIZE, GFP_KERNEL))) {
2070 +- dev_err(&dev->dev,
2071 +- "probe_rio: Not enough memory for the input buffer\n");
2072 +- usb_deregister_dev(intf, &usb_rio_class);
2073 +- kfree(rio->obuf);
2074 +- retval = -ENOMEM;
2075 +- goto bail_out;
2076 +- }
2077 +- dev_dbg(&intf->dev, "ibuf address:%p\n", rio->ibuf);
2078 +-
2079 +- mutex_init(&(rio->lock));
2080 +-
2081 +- usb_set_intfdata (intf, rio);
2082 +- rio->present = 1;
2083 +-bail_out:
2084 +- mutex_unlock(&rio500_mutex);
2085 +-
2086 +- return retval;
2087 +-}
2088 +-
2089 +-static void disconnect_rio(struct usb_interface *intf)
2090 +-{
2091 +- struct rio_usb_data *rio = usb_get_intfdata (intf);
2092 +-
2093 +- usb_set_intfdata (intf, NULL);
2094 +- mutex_lock(&rio500_mutex);
2095 +- if (rio) {
2096 +- usb_deregister_dev(intf, &usb_rio_class);
2097 +-
2098 +- mutex_lock(&(rio->lock));
2099 +- if (rio->isopen) {
2100 +- rio->isopen = 0;
2101 +- /* better let it finish - the release will do whats needed */
2102 +- rio->rio_dev = NULL;
2103 +- mutex_unlock(&(rio->lock));
2104 +- mutex_unlock(&rio500_mutex);
2105 +- return;
2106 +- }
2107 +- kfree(rio->ibuf);
2108 +- kfree(rio->obuf);
2109 +-
2110 +- dev_info(&intf->dev, "USB Rio disconnected.\n");
2111 +-
2112 +- rio->present = 0;
2113 +- mutex_unlock(&(rio->lock));
2114 +- }
2115 +- mutex_unlock(&rio500_mutex);
2116 +-}
2117 +-
2118 +-static const struct usb_device_id rio_table[] = {
2119 +- { USB_DEVICE(0x0841, 1) }, /* Rio 500 */
2120 +- { } /* Terminating entry */
2121 +-};
2122 +-
2123 +-MODULE_DEVICE_TABLE (usb, rio_table);
2124 +-
2125 +-static struct usb_driver rio_driver = {
2126 +- .name = "rio500",
2127 +- .probe = probe_rio,
2128 +- .disconnect = disconnect_rio,
2129 +- .id_table = rio_table,
2130 +-};
2131 +-
2132 +-module_usb_driver(rio_driver);
2133 +-
2134 +-MODULE_AUTHOR( DRIVER_AUTHOR );
2135 +-MODULE_DESCRIPTION( DRIVER_DESC );
2136 +-MODULE_LICENSE("GPL");
2137 +-
2138 +diff --git a/drivers/usb/misc/rio500_usb.h b/drivers/usb/misc/rio500_usb.h
2139 +deleted file mode 100644
2140 +index 359abc98e706..000000000000
2141 +--- a/drivers/usb/misc/rio500_usb.h
2142 ++++ /dev/null
2143 +@@ -1,37 +0,0 @@
2144 +-/* ----------------------------------------------------------------------
2145 +-
2146 +- Copyright (C) 2000 Cesar Miquel (miquel@××××××.ar)
2147 +-
2148 +- This program is free software; you can redistribute it and/or modify
2149 +- it under the terms of the GNU General Public License as published by
2150 +- the Free Software Foundation; either version 2 of the License, or
2151 +- (at your option) any later version.
2152 +-
2153 +- This program is distributed in the hope that it will be useful,
2154 +- but WITHOUT ANY WARRANTY; without even the implied warranty of
2155 +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2156 +- GNU General Public License for more details.
2157 +-
2158 +- You should have received a copy of the GNU General Public License
2159 +- along with this program; if not, write to the Free Software
2160 +- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2161 +-
2162 +- ---------------------------------------------------------------------- */
2163 +-
2164 +-
2165 +-
2166 +-#define RIO_SEND_COMMAND 0x1
2167 +-#define RIO_RECV_COMMAND 0x2
2168 +-
2169 +-#define RIO_DIR_OUT 0x0
2170 +-#define RIO_DIR_IN 0x1
2171 +-
2172 +-struct RioCommand {
2173 +- short length;
2174 +- int request;
2175 +- int requesttype;
2176 +- int value;
2177 +- int index;
2178 +- void __user *buffer;
2179 +- int timeout;
2180 +-};
2181 +diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
2182 +index 1184390508e9..c77974fab29d 100644
2183 +--- a/drivers/usb/misc/usblcd.c
2184 ++++ b/drivers/usb/misc/usblcd.c
2185 +@@ -17,6 +17,7 @@
2186 + #include <linux/slab.h>
2187 + #include <linux/errno.h>
2188 + #include <linux/mutex.h>
2189 ++#include <linux/rwsem.h>
2190 + #include <linux/uaccess.h>
2191 + #include <linux/usb.h>
2192 +
2193 +@@ -56,6 +57,8 @@ struct usb_lcd {
2194 + using up all RAM */
2195 + struct usb_anchor submitted; /* URBs to wait for
2196 + before suspend */
2197 ++ struct rw_semaphore io_rwsem;
2198 ++ unsigned long disconnected:1;
2199 + };
2200 + #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref)
2201 +
2202 +@@ -141,6 +144,13 @@ static ssize_t lcd_read(struct file *file, char __user * buffer,
2203 +
2204 + dev = file->private_data;
2205 +
2206 ++ down_read(&dev->io_rwsem);
2207 ++
2208 ++ if (dev->disconnected) {
2209 ++ retval = -ENODEV;
2210 ++ goto out_up_io;
2211 ++ }
2212 ++
2213 + /* do a blocking bulk read to get data from the device */
2214 + retval = usb_bulk_msg(dev->udev,
2215 + usb_rcvbulkpipe(dev->udev,
2216 +@@ -157,6 +167,9 @@ static ssize_t lcd_read(struct file *file, char __user * buffer,
2217 + retval = bytes_read;
2218 + }
2219 +
2220 ++out_up_io:
2221 ++ up_read(&dev->io_rwsem);
2222 ++
2223 + return retval;
2224 + }
2225 +
2226 +@@ -236,11 +249,18 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer,
2227 + if (r < 0)
2228 + return -EINTR;
2229 +
2230 ++ down_read(&dev->io_rwsem);
2231 ++
2232 ++ if (dev->disconnected) {
2233 ++ retval = -ENODEV;
2234 ++ goto err_up_io;
2235 ++ }
2236 ++
2237 + /* create a urb, and a buffer for it, and copy the data to the urb */
2238 + urb = usb_alloc_urb(0, GFP_KERNEL);
2239 + if (!urb) {
2240 + retval = -ENOMEM;
2241 +- goto err_no_buf;
2242 ++ goto err_up_io;
2243 + }
2244 +
2245 + buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL,
2246 +@@ -277,6 +297,7 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer,
2247 + the USB core will eventually free it entirely */
2248 + usb_free_urb(urb);
2249 +
2250 ++ up_read(&dev->io_rwsem);
2251 + exit:
2252 + return count;
2253 + error_unanchor:
2254 +@@ -284,7 +305,8 @@ error_unanchor:
2255 + error:
2256 + usb_free_coherent(dev->udev, count, buf, urb->transfer_dma);
2257 + usb_free_urb(urb);
2258 +-err_no_buf:
2259 ++err_up_io:
2260 ++ up_read(&dev->io_rwsem);
2261 + up(&dev->limit_sem);
2262 + return retval;
2263 + }
2264 +@@ -327,6 +349,7 @@ static int lcd_probe(struct usb_interface *interface,
2265 + }
2266 + kref_init(&dev->kref);
2267 + sema_init(&dev->limit_sem, USB_LCD_CONCURRENT_WRITES);
2268 ++ init_rwsem(&dev->io_rwsem);
2269 + init_usb_anchor(&dev->submitted);
2270 +
2271 + dev->udev = usb_get_dev(interface_to_usbdev(interface));
2272 +@@ -437,6 +460,12 @@ static void lcd_disconnect(struct usb_interface *interface)
2273 + /* give back our minor */
2274 + usb_deregister_dev(interface, &lcd_class);
2275 +
2276 ++ down_write(&dev->io_rwsem);
2277 ++ dev->disconnected = 1;
2278 ++ up_write(&dev->io_rwsem);
2279 ++
2280 ++ usb_kill_anchored_urbs(&dev->submitted);
2281 ++
2282 + /* decrement our usage count */
2283 + kref_put(&dev->kref, lcd_delete);
2284 +
2285 +diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
2286 +index 2222ec2275fc..44c6ced5d442 100644
2287 +--- a/drivers/usb/misc/yurex.c
2288 ++++ b/drivers/usb/misc/yurex.c
2289 +@@ -64,6 +64,7 @@ struct usb_yurex {
2290 +
2291 + struct kref kref;
2292 + struct mutex io_mutex;
2293 ++ unsigned long disconnected:1;
2294 + struct fasync_struct *async_queue;
2295 + wait_queue_head_t waitq;
2296 +
2297 +@@ -111,6 +112,7 @@ static void yurex_delete(struct kref *kref)
2298 + dev->int_buffer, dev->urb->transfer_dma);
2299 + usb_free_urb(dev->urb);
2300 + }
2301 ++ usb_put_intf(dev->interface);
2302 + usb_put_dev(dev->udev);
2303 + kfree(dev);
2304 + }
2305 +@@ -136,6 +138,7 @@ static void yurex_interrupt(struct urb *urb)
2306 + switch (status) {
2307 + case 0: /*success*/
2308 + break;
2309 ++ /* The device is terminated or messed up, give up */
2310 + case -EOVERFLOW:
2311 + dev_err(&dev->interface->dev,
2312 + "%s - overflow with length %d, actual length is %d\n",
2313 +@@ -144,12 +147,13 @@ static void yurex_interrupt(struct urb *urb)
2314 + case -ENOENT:
2315 + case -ESHUTDOWN:
2316 + case -EILSEQ:
2317 +- /* The device is terminated, clean up */
2318 ++ case -EPROTO:
2319 ++ case -ETIME:
2320 + return;
2321 + default:
2322 + dev_err(&dev->interface->dev,
2323 + "%s - unknown status received: %d\n", __func__, status);
2324 +- goto exit;
2325 ++ return;
2326 + }
2327 +
2328 + /* handle received message */
2329 +@@ -181,7 +185,6 @@ static void yurex_interrupt(struct urb *urb)
2330 + break;
2331 + }
2332 +
2333 +-exit:
2334 + retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
2335 + if (retval) {
2336 + dev_err(&dev->interface->dev, "%s - usb_submit_urb failed: %d\n",
2337 +@@ -210,7 +213,7 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_
2338 + init_waitqueue_head(&dev->waitq);
2339 +
2340 + dev->udev = usb_get_dev(interface_to_usbdev(interface));
2341 +- dev->interface = interface;
2342 ++ dev->interface = usb_get_intf(interface);
2343 +
2344 + /* set up the endpoint information */
2345 + iface_desc = interface->cur_altsetting;
2346 +@@ -333,8 +336,9 @@ static void yurex_disconnect(struct usb_interface *interface)
2347 +
2348 + /* prevent more I/O from starting */
2349 + usb_poison_urb(dev->urb);
2350 ++ usb_poison_urb(dev->cntl_urb);
2351 + mutex_lock(&dev->io_mutex);
2352 +- dev->interface = NULL;
2353 ++ dev->disconnected = 1;
2354 + mutex_unlock(&dev->io_mutex);
2355 +
2356 + /* wakeup waiters */
2357 +@@ -422,7 +426,7 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
2358 + dev = file->private_data;
2359 +
2360 + mutex_lock(&dev->io_mutex);
2361 +- if (!dev->interface) { /* already disconnected */
2362 ++ if (dev->disconnected) { /* already disconnected */
2363 + mutex_unlock(&dev->io_mutex);
2364 + return -ENODEV;
2365 + }
2366 +@@ -457,7 +461,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
2367 + goto error;
2368 +
2369 + mutex_lock(&dev->io_mutex);
2370 +- if (!dev->interface) { /* already disconnected */
2371 ++ if (dev->disconnected) { /* already disconnected */
2372 + mutex_unlock(&dev->io_mutex);
2373 + retval = -ENODEV;
2374 + goto error;
2375 +diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h
2376 +index 8c5fc12ad778..b8620aa6b72e 100644
2377 +--- a/drivers/usb/renesas_usbhs/common.h
2378 ++++ b/drivers/usb/renesas_usbhs/common.h
2379 +@@ -213,6 +213,7 @@ struct usbhs_priv;
2380 + /* DCPCTR */
2381 + #define BSTS (1 << 15) /* Buffer Status */
2382 + #define SUREQ (1 << 14) /* Sending SETUP Token */
2383 ++#define INBUFM (1 << 14) /* (PIPEnCTR) Transfer Buffer Monitor */
2384 + #define CSSTS (1 << 12) /* CSSTS Status */
2385 + #define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
2386 + #define SQCLR (1 << 8) /* Toggle Bit Clear */
2387 +diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
2388 +index 5e2aa4f85c81..79efb367e5ce 100644
2389 +--- a/drivers/usb/renesas_usbhs/fifo.c
2390 ++++ b/drivers/usb/renesas_usbhs/fifo.c
2391 +@@ -98,7 +98,7 @@ static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
2392 + list_del_init(&pkt->node);
2393 + }
2394 +
2395 +-static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
2396 ++struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
2397 + {
2398 + if (list_empty(&pipe->list))
2399 + return NULL;
2400 +diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h
2401 +index c7d9b86d51bf..3640340e94d6 100644
2402 +--- a/drivers/usb/renesas_usbhs/fifo.h
2403 ++++ b/drivers/usb/renesas_usbhs/fifo.h
2404 +@@ -106,5 +106,6 @@ void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
2405 + void *buf, int len, int zero, int sequence);
2406 + struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
2407 + void usbhs_pkt_start(struct usbhs_pipe *pipe);
2408 ++struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe);
2409 +
2410 + #endif /* RENESAS_USB_FIFO_H */
2411 +diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
2412 +index c5553028e616..efe8d815cf2c 100644
2413 +--- a/drivers/usb/renesas_usbhs/mod_gadget.c
2414 ++++ b/drivers/usb/renesas_usbhs/mod_gadget.c
2415 +@@ -731,8 +731,7 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
2416 + struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
2417 + struct device *dev = usbhsg_gpriv_to_dev(gpriv);
2418 + unsigned long flags;
2419 +-
2420 +- usbhsg_pipe_disable(uep);
2421 ++ int ret = 0;
2422 +
2423 + dev_dbg(dev, "set halt %d (pipe %d)\n",
2424 + halt, usbhs_pipe_number(pipe));
2425 +@@ -740,6 +739,18 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
2426 + /******************** spin lock ********************/
2427 + usbhs_lock(priv, flags);
2428 +
2429 ++ /*
2430 ++ * According to usb_ep_set_halt()'s description, this function should
2431 ++ * return -EAGAIN if the IN endpoint has any queue or data. Note
2432 ++ * that the usbhs_pipe_is_dir_in() returns false if the pipe is an
2433 ++ * IN endpoint in the gadget mode.
2434 ++ */
2435 ++ if (!usbhs_pipe_is_dir_in(pipe) && (__usbhsf_pkt_get(pipe) ||
2436 ++ usbhs_pipe_contains_transmittable_data(pipe))) {
2437 ++ ret = -EAGAIN;
2438 ++ goto out;
2439 ++ }
2440 ++
2441 + if (halt)
2442 + usbhs_pipe_stall(pipe);
2443 + else
2444 +@@ -750,10 +761,11 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
2445 + else
2446 + usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE);
2447 +
2448 ++out:
2449 + usbhs_unlock(priv, flags);
2450 + /******************** spin unlock ******************/
2451 +
2452 +- return 0;
2453 ++ return ret;
2454 + }
2455 +
2456 + static int usbhsg_ep_set_halt(struct usb_ep *ep, int value)
2457 +diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c
2458 +index 4f9c3356127a..75fb41d4e9fc 100644
2459 +--- a/drivers/usb/renesas_usbhs/pipe.c
2460 ++++ b/drivers/usb/renesas_usbhs/pipe.c
2461 +@@ -279,6 +279,21 @@ int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe)
2462 + return -EBUSY;
2463 + }
2464 +
2465 ++bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe)
2466 ++{
2467 ++ u16 val;
2468 ++
2469 ++ /* Do not support for DCP pipe */
2470 ++ if (usbhs_pipe_is_dcp(pipe))
2471 ++ return false;
2472 ++
2473 ++ val = usbhsp_pipectrl_get(pipe);
2474 ++ if (val & INBUFM)
2475 ++ return true;
2476 ++
2477 ++ return false;
2478 ++}
2479 ++
2480 + /*
2481 + * PID ctrl
2482 + */
2483 +diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h
2484 +index b0bc7b603016..b7925d363bb4 100644
2485 +--- a/drivers/usb/renesas_usbhs/pipe.h
2486 ++++ b/drivers/usb/renesas_usbhs/pipe.h
2487 +@@ -89,6 +89,7 @@ void usbhs_pipe_init(struct usbhs_priv *priv,
2488 + int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe);
2489 + void usbhs_pipe_clear(struct usbhs_pipe *pipe);
2490 + int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe);
2491 ++bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe);
2492 + void usbhs_pipe_enable(struct usbhs_pipe *pipe);
2493 + void usbhs_pipe_disable(struct usbhs_pipe *pipe);
2494 + void usbhs_pipe_stall(struct usbhs_pipe *pipe);
2495 +diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
2496 +index 7edcd5a8d175..2998da6bd901 100644
2497 +--- a/drivers/usb/serial/ftdi_sio.c
2498 ++++ b/drivers/usb/serial/ftdi_sio.c
2499 +@@ -1025,6 +1025,9 @@ static const struct usb_device_id id_table_combined[] = {
2500 + /* EZPrototypes devices */
2501 + { USB_DEVICE(EZPROTOTYPES_VID, HJELMSLUND_USB485_ISO_PID) },
2502 + { USB_DEVICE_INTERFACE_NUMBER(UNJO_VID, UNJO_ISODEBUG_V1_PID, 1) },
2503 ++ /* Sienna devices */
2504 ++ { USB_DEVICE(FTDI_VID, FTDI_SIENNA_PID) },
2505 ++ { USB_DEVICE(ECHELON_VID, ECHELON_U20_PID) },
2506 + { } /* Terminating entry */
2507 + };
2508 +
2509 +diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
2510 +index ed6b36674c15..2e8161f79b49 100644
2511 +--- a/drivers/usb/serial/ftdi_sio_ids.h
2512 ++++ b/drivers/usb/serial/ftdi_sio_ids.h
2513 +@@ -38,6 +38,9 @@
2514 +
2515 + #define FTDI_LUMEL_PD12_PID 0x6002
2516 +
2517 ++/* Sienna Serial Interface by Secyourit GmbH */
2518 ++#define FTDI_SIENNA_PID 0x8348
2519 ++
2520 + /* Cyber Cortex AV by Fabulous Silicon (http://fabuloussilicon.com) */
2521 + #define CYBER_CORTEX_AV_PID 0x8698
2522 +
2523 +@@ -687,6 +690,12 @@
2524 + #define BANDB_TTL3USB9M_PID 0xAC50
2525 + #define BANDB_ZZ_PROG1_USB_PID 0xBA02
2526 +
2527 ++/*
2528 ++ * Echelon USB Serial Interface
2529 ++ */
2530 ++#define ECHELON_VID 0x0920
2531 ++#define ECHELON_U20_PID 0x7500
2532 ++
2533 + /*
2534 + * Intrepid Control Systems (http://www.intrepidcs.com/) ValueCAN and NeoVI
2535 + */
2536 +diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
2537 +index 7faa901ee47f..38112be0dbae 100644
2538 +--- a/drivers/usb/serial/keyspan.c
2539 ++++ b/drivers/usb/serial/keyspan.c
2540 +@@ -1249,8 +1249,8 @@ static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
2541 +
2542 + ep_desc = find_ep(serial, endpoint);
2543 + if (!ep_desc) {
2544 +- /* leak the urb, something's wrong and the callers don't care */
2545 +- return urb;
2546 ++ usb_free_urb(urb);
2547 ++ return NULL;
2548 + }
2549 + if (usb_endpoint_xfer_int(ep_desc)) {
2550 + ep_type_name = "INT";
2551 +diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
2552 +index 1bceb11f3782..00a6e62a68a8 100644
2553 +--- a/drivers/usb/serial/option.c
2554 ++++ b/drivers/usb/serial/option.c
2555 +@@ -421,6 +421,7 @@ static void option_instat_callback(struct urb *urb);
2556 + #define CINTERION_PRODUCT_PH8_AUDIO 0x0083
2557 + #define CINTERION_PRODUCT_AHXX_2RMNET 0x0084
2558 + #define CINTERION_PRODUCT_AHXX_AUDIO 0x0085
2559 ++#define CINTERION_PRODUCT_CLS8 0x00b0
2560 +
2561 + /* Olivetti products */
2562 + #define OLIVETTI_VENDOR_ID 0x0b3c
2563 +@@ -1149,6 +1150,14 @@ static const struct usb_device_id option_ids[] = {
2564 + .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) | RSVD(3) },
2565 + { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, TELIT_PRODUCT_LE922_USBCFG5, 0xff),
2566 + .driver_info = RSVD(0) | RSVD(1) | NCTRL(2) | RSVD(3) },
2567 ++ { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1050, 0xff), /* Telit FN980 (rmnet) */
2568 ++ .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) },
2569 ++ { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1051, 0xff), /* Telit FN980 (MBIM) */
2570 ++ .driver_info = NCTRL(0) | RSVD(1) },
2571 ++ { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1052, 0xff), /* Telit FN980 (RNDIS) */
2572 ++ .driver_info = NCTRL(2) | RSVD(3) },
2573 ++ { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1053, 0xff), /* Telit FN980 (ECM) */
2574 ++ .driver_info = NCTRL(0) | RSVD(1) },
2575 + { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910),
2576 + .driver_info = NCTRL(0) | RSVD(1) | RSVD(3) },
2577 + { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910_DUAL_MODEM),
2578 +@@ -1842,6 +1851,8 @@ static const struct usb_device_id option_ids[] = {
2579 + .driver_info = RSVD(4) },
2580 + { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX_2RMNET, 0xff) },
2581 + { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX_AUDIO, 0xff) },
2582 ++ { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_CLS8, 0xff),
2583 ++ .driver_info = RSVD(0) | RSVD(4) },
2584 + { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDM) },
2585 + { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDMNET) },
2586 + { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC25_MDM) },
2587 +diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
2588 +index e7e29c797824..80ba818d3a21 100644
2589 +--- a/drivers/usb/serial/usb-serial.c
2590 ++++ b/drivers/usb/serial/usb-serial.c
2591 +@@ -314,10 +314,7 @@ static void serial_cleanup(struct tty_struct *tty)
2592 + serial = port->serial;
2593 + owner = serial->type->driver.owner;
2594 +
2595 +- mutex_lock(&serial->disc_mutex);
2596 +- if (!serial->disconnected)
2597 +- usb_autopm_put_interface(serial->interface);
2598 +- mutex_unlock(&serial->disc_mutex);
2599 ++ usb_autopm_put_interface(serial->interface);
2600 +
2601 + usb_serial_put(serial);
2602 + module_put(owner);
2603 +diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
2604 +index 545d09b8081d..871c366d9229 100644
2605 +--- a/drivers/usb/usb-skeleton.c
2606 ++++ b/drivers/usb/usb-skeleton.c
2607 +@@ -63,6 +63,7 @@ struct usb_skel {
2608 + spinlock_t err_lock; /* lock for errors */
2609 + struct kref kref;
2610 + struct mutex io_mutex; /* synchronize I/O with disconnect */
2611 ++ unsigned long disconnected:1;
2612 + wait_queue_head_t bulk_in_wait; /* to wait for an ongoing read */
2613 + };
2614 + #define to_skel_dev(d) container_of(d, struct usb_skel, kref)
2615 +@@ -75,6 +76,7 @@ static void skel_delete(struct kref *kref)
2616 + struct usb_skel *dev = to_skel_dev(kref);
2617 +
2618 + usb_free_urb(dev->bulk_in_urb);
2619 ++ usb_put_intf(dev->interface);
2620 + usb_put_dev(dev->udev);
2621 + kfree(dev->bulk_in_buffer);
2622 + kfree(dev);
2623 +@@ -126,10 +128,7 @@ static int skel_release(struct inode *inode, struct file *file)
2624 + return -ENODEV;
2625 +
2626 + /* allow the device to be autosuspended */
2627 +- mutex_lock(&dev->io_mutex);
2628 +- if (dev->interface)
2629 +- usb_autopm_put_interface(dev->interface);
2630 +- mutex_unlock(&dev->io_mutex);
2631 ++ usb_autopm_put_interface(dev->interface);
2632 +
2633 + /* decrement the count on our device */
2634 + kref_put(&dev->kref, skel_delete);
2635 +@@ -241,7 +240,7 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count,
2636 + if (rv < 0)
2637 + return rv;
2638 +
2639 +- if (!dev->interface) { /* disconnect() was called */
2640 ++ if (dev->disconnected) { /* disconnect() was called */
2641 + rv = -ENODEV;
2642 + goto exit;
2643 + }
2644 +@@ -422,7 +421,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer,
2645 +
2646 + /* this lock makes sure we don't submit URBs to gone devices */
2647 + mutex_lock(&dev->io_mutex);
2648 +- if (!dev->interface) { /* disconnect() was called */
2649 ++ if (dev->disconnected) { /* disconnect() was called */
2650 + mutex_unlock(&dev->io_mutex);
2651 + retval = -ENODEV;
2652 + goto error;
2653 +@@ -511,7 +510,7 @@ static int skel_probe(struct usb_interface *interface,
2654 + init_waitqueue_head(&dev->bulk_in_wait);
2655 +
2656 + dev->udev = usb_get_dev(interface_to_usbdev(interface));
2657 +- dev->interface = interface;
2658 ++ dev->interface = usb_get_intf(interface);
2659 +
2660 + /* set up the endpoint information */
2661 + /* use only the first bulk-in and bulk-out endpoints */
2662 +@@ -590,7 +589,7 @@ static void skel_disconnect(struct usb_interface *interface)
2663 +
2664 + /* prevent more I/O from starting */
2665 + mutex_lock(&dev->io_mutex);
2666 +- dev->interface = NULL;
2667 ++ dev->disconnected = 1;
2668 + mutex_unlock(&dev->io_mutex);
2669 +
2670 + usb_kill_anchored_urbs(&dev->submitted);
2671 +diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c
2672 +index 7494dbeb4409..db58aaa4dc59 100644
2673 +--- a/drivers/xen/pci.c
2674 ++++ b/drivers/xen/pci.c
2675 +@@ -29,6 +29,8 @@
2676 + #include "../pci/pci.h"
2677 + #ifdef CONFIG_PCI_MMCONFIG
2678 + #include <asm/pci_x86.h>
2679 ++
2680 ++static int xen_mcfg_late(void);
2681 + #endif
2682 +
2683 + static bool __read_mostly pci_seg_supported = true;
2684 +@@ -40,7 +42,18 @@ static int xen_add_device(struct device *dev)
2685 + #ifdef CONFIG_PCI_IOV
2686 + struct pci_dev *physfn = pci_dev->physfn;
2687 + #endif
2688 +-
2689 ++#ifdef CONFIG_PCI_MMCONFIG
2690 ++ static bool pci_mcfg_reserved = false;
2691 ++ /*
2692 ++ * Reserve MCFG areas in Xen on first invocation due to this being
2693 ++ * potentially called from inside of acpi_init immediately after
2694 ++ * MCFG table has been finally parsed.
2695 ++ */
2696 ++ if (!pci_mcfg_reserved) {
2697 ++ xen_mcfg_late();
2698 ++ pci_mcfg_reserved = true;
2699 ++ }
2700 ++#endif
2701 + if (pci_seg_supported) {
2702 + struct {
2703 + struct physdev_pci_device_add add;
2704 +@@ -213,7 +226,7 @@ static int __init register_xen_pci_notifier(void)
2705 + arch_initcall(register_xen_pci_notifier);
2706 +
2707 + #ifdef CONFIG_PCI_MMCONFIG
2708 +-static int __init xen_mcfg_late(void)
2709 ++static int xen_mcfg_late(void)
2710 + {
2711 + struct pci_mmcfg_region *cfg;
2712 + int rc;
2713 +@@ -252,8 +265,4 @@ static int __init xen_mcfg_late(void)
2714 + }
2715 + return 0;
2716 + }
2717 +-/*
2718 +- * Needs to be done after acpi_init which are subsys_initcall.
2719 +- */
2720 +-subsys_initcall_sync(xen_mcfg_late);
2721 + #endif
2722 +diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
2723 +index 373cc50544e9..9dbf37147126 100644
2724 +--- a/fs/9p/vfs_file.c
2725 ++++ b/fs/9p/vfs_file.c
2726 +@@ -528,6 +528,7 @@ v9fs_mmap_file_mmap(struct file *filp, struct vm_area_struct *vma)
2727 + v9inode = V9FS_I(inode);
2728 + mutex_lock(&v9inode->v_mutex);
2729 + if (!v9inode->writeback_fid &&
2730 ++ (vma->vm_flags & VM_SHARED) &&
2731 + (vma->vm_flags & VM_WRITE)) {
2732 + /*
2733 + * clone a fid and add it to writeback_fid
2734 +@@ -629,6 +630,8 @@ static void v9fs_mmap_vm_close(struct vm_area_struct *vma)
2735 + (vma->vm_end - vma->vm_start - 1),
2736 + };
2737 +
2738 ++ if (!(vma->vm_flags & VM_SHARED))
2739 ++ return;
2740 +
2741 + p9_debug(P9_DEBUG_VFS, "9p VMA close, %p, flushing", vma);
2742 +
2743 +diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
2744 +index a663b676d566..2ad3f4ab4dcf 100644
2745 +--- a/fs/ceph/inode.c
2746 ++++ b/fs/ceph/inode.c
2747 +@@ -725,7 +725,12 @@ static int fill_inode(struct inode *inode, struct page *locked_page,
2748 + ci->i_version = le64_to_cpu(info->version);
2749 + inode->i_version++;
2750 + inode->i_rdev = le32_to_cpu(info->rdev);
2751 +- inode->i_blkbits = fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
2752 ++ /* directories have fl_stripe_unit set to zero */
2753 ++ if (le32_to_cpu(info->layout.fl_stripe_unit))
2754 ++ inode->i_blkbits =
2755 ++ fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
2756 ++ else
2757 ++ inode->i_blkbits = CEPH_BLOCK_SHIFT;
2758 +
2759 + if ((new_version || (new_issued & CEPH_CAP_AUTH_SHARED)) &&
2760 + (issued & CEPH_CAP_AUTH_EXCL) == 0) {
2761 +diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
2762 +index afd317eb9db9..be16da31cbcc 100644
2763 +--- a/fs/cifs/dir.c
2764 ++++ b/fs/cifs/dir.c
2765 +@@ -830,10 +830,16 @@ lookup_out:
2766 + static int
2767 + cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
2768 + {
2769 ++ struct inode *inode;
2770 ++
2771 + if (flags & LOOKUP_RCU)
2772 + return -ECHILD;
2773 +
2774 + if (d_really_is_positive(direntry)) {
2775 ++ inode = d_inode(direntry);
2776 ++ if ((flags & LOOKUP_REVAL) && !CIFS_CACHE_READ(CIFS_I(inode)))
2777 ++ CIFS_I(inode)->time = 0; /* force reval */
2778 ++
2779 + if (cifs_revalidate_dentry(direntry))
2780 + return 0;
2781 + else {
2782 +@@ -844,7 +850,7 @@ cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
2783 + * attributes will have been updated by
2784 + * cifs_revalidate_dentry().
2785 + */
2786 +- if (IS_AUTOMOUNT(d_inode(direntry)) &&
2787 ++ if (IS_AUTOMOUNT(inode) &&
2788 + !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
2789 + spin_lock(&direntry->d_lock);
2790 + direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
2791 +diff --git a/fs/cifs/file.c b/fs/cifs/file.c
2792 +index 309c134fb66f..737cff7bc08a 100644
2793 +--- a/fs/cifs/file.c
2794 ++++ b/fs/cifs/file.c
2795 +@@ -252,6 +252,12 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
2796 + rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
2797 + xid, fid);
2798 +
2799 ++ if (rc) {
2800 ++ server->ops->close(xid, tcon, fid);
2801 ++ if (rc == -ESTALE)
2802 ++ rc = -EOPENSTALE;
2803 ++ }
2804 ++
2805 + out:
2806 + kfree(buf);
2807 + return rc;
2808 +diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
2809 +index 0f210cb5038a..0a219545940d 100644
2810 +--- a/fs/cifs/inode.c
2811 ++++ b/fs/cifs/inode.c
2812 +@@ -405,6 +405,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
2813 + /* if uniqueid is different, return error */
2814 + if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
2815 + CIFS_I(*pinode)->uniqueid != fattr.cf_uniqueid)) {
2816 ++ CIFS_I(*pinode)->time = 0; /* force reval */
2817 + rc = -ESTALE;
2818 + goto cgiiu_exit;
2819 + }
2820 +@@ -412,6 +413,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
2821 + /* if filetype is different, return error */
2822 + if (unlikely(((*pinode)->i_mode & S_IFMT) !=
2823 + (fattr.cf_mode & S_IFMT))) {
2824 ++ CIFS_I(*pinode)->time = 0; /* force reval */
2825 + rc = -ESTALE;
2826 + goto cgiiu_exit;
2827 + }
2828 +@@ -829,8 +831,21 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
2829 + }
2830 + } else
2831 + fattr.cf_uniqueid = iunique(sb, ROOT_I);
2832 +- } else
2833 +- fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid;
2834 ++ } else {
2835 ++ if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) &&
2836 ++ validinum == false && server->ops->get_srv_inum) {
2837 ++ /*
2838 ++ * Pass a NULL tcon to ensure we don't make a round
2839 ++ * trip to the server. This only works for SMB2+.
2840 ++ */
2841 ++ tmprc = server->ops->get_srv_inum(xid,
2842 ++ NULL, cifs_sb, full_path,
2843 ++ &fattr.cf_uniqueid, data);
2844 ++ if (tmprc)
2845 ++ fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid;
2846 ++ } else
2847 ++ fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid;
2848 ++ }
2849 +
2850 + /* query for SFU type info if supported and needed */
2851 + if (fattr.cf_cifsattrs & ATTR_SYSTEM &&
2852 +@@ -871,9 +886,18 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
2853 + } else {
2854 + /* we already have inode, update it */
2855 +
2856 ++ /* if uniqueid is different, return error */
2857 ++ if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
2858 ++ CIFS_I(*inode)->uniqueid != fattr.cf_uniqueid)) {
2859 ++ CIFS_I(*inode)->time = 0; /* force reval */
2860 ++ rc = -ESTALE;
2861 ++ goto cgii_exit;
2862 ++ }
2863 ++
2864 + /* if filetype is different, return error */
2865 + if (unlikely(((*inode)->i_mode & S_IFMT) !=
2866 + (fattr.cf_mode & S_IFMT))) {
2867 ++ CIFS_I(*inode)->time = 0; /* force reval */
2868 + rc = -ESTALE;
2869 + goto cgii_exit;
2870 + }
2871 +diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
2872 +index c5b6b7165489..d9aba9700726 100644
2873 +--- a/fs/fuse/cuse.c
2874 ++++ b/fs/fuse/cuse.c
2875 +@@ -513,6 +513,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)
2876 + rc = cuse_send_init(cc);
2877 + if (rc) {
2878 + fuse_dev_free(fud);
2879 ++ fuse_conn_put(&cc->fc);
2880 + return rc;
2881 + }
2882 + file->private_data = fud;
2883 +diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
2884 +index 1cb50bb898b0..15cd9db6d616 100644
2885 +--- a/fs/nfs/nfs4xdr.c
2886 ++++ b/fs/nfs/nfs4xdr.c
2887 +@@ -1123,7 +1123,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
2888 + } else
2889 + *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
2890 + }
2891 +- if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
2892 ++ if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
2893 + *p++ = cpu_to_be32(label->lfs);
2894 + *p++ = cpu_to_be32(label->pi);
2895 + *p++ = cpu_to_be32(label->len);
2896 +diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
2897 +index ef64a1e1a66a..ff3f5812c0fd 100644
2898 +--- a/fs/xfs/xfs_super.c
2899 ++++ b/fs/xfs/xfs_super.c
2900 +@@ -1572,6 +1572,7 @@ xfs_fs_fill_super(
2901 + out_close_devices:
2902 + xfs_close_devices(mp);
2903 + out_free_fsname:
2904 ++ sb->s_fs_info = NULL;
2905 + xfs_free_fsname(mp);
2906 + kfree(mp);
2907 + out:
2908 +@@ -1589,6 +1590,10 @@ xfs_fs_put_super(
2909 + {
2910 + struct xfs_mount *mp = XFS_M(sb);
2911 +
2912 ++ /* if ->fill_super failed, we have no mount to tear down */
2913 ++ if (!sb->s_fs_info)
2914 ++ return;
2915 ++
2916 + xfs_notice(mp, "Unmounting Filesystem");
2917 + xfs_filestream_unmount(mp);
2918 + xfs_unmountfs(mp);
2919 +@@ -1598,6 +1603,8 @@ xfs_fs_put_super(
2920 + xfs_destroy_percpu_counters(mp);
2921 + xfs_destroy_mount_workqueues(mp);
2922 + xfs_close_devices(mp);
2923 ++
2924 ++ sb->s_fs_info = NULL;
2925 + xfs_free_fsname(mp);
2926 + kfree(mp);
2927 + }
2928 +@@ -1617,6 +1624,9 @@ xfs_fs_nr_cached_objects(
2929 + struct super_block *sb,
2930 + struct shrink_control *sc)
2931 + {
2932 ++ /* Paranoia: catch incorrect calls during mount setup or teardown */
2933 ++ if (WARN_ON_ONCE(!sb->s_fs_info))
2934 ++ return 0;
2935 + return xfs_reclaim_inodes_count(XFS_M(sb));
2936 + }
2937 +
2938 +diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
2939 +index 452c0b0d2f32..149a7a6687e9 100644
2940 +--- a/include/linux/ieee80211.h
2941 ++++ b/include/linux/ieee80211.h
2942 +@@ -2550,4 +2550,57 @@ static inline bool ieee80211_action_contains_tpc(struct sk_buff *skb)
2943 + return true;
2944 + }
2945 +
2946 ++struct element {
2947 ++ u8 id;
2948 ++ u8 datalen;
2949 ++ u8 data[];
2950 ++} __packed;
2951 ++
2952 ++/* element iteration helpers */
2953 ++#define for_each_element(_elem, _data, _datalen) \
2954 ++ for (_elem = (const struct element *)(_data); \
2955 ++ (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
2956 ++ (int)sizeof(*_elem) && \
2957 ++ (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
2958 ++ (int)sizeof(*_elem) + _elem->datalen; \
2959 ++ _elem = (const struct element *)(_elem->data + _elem->datalen))
2960 ++
2961 ++#define for_each_element_id(element, _id, data, datalen) \
2962 ++ for_each_element(element, data, datalen) \
2963 ++ if (element->id == (_id))
2964 ++
2965 ++#define for_each_element_extid(element, extid, data, datalen) \
2966 ++ for_each_element(element, data, datalen) \
2967 ++ if (element->id == WLAN_EID_EXTENSION && \
2968 ++ element->datalen > 0 && \
2969 ++ element->data[0] == (extid))
2970 ++
2971 ++#define for_each_subelement(sub, element) \
2972 ++ for_each_element(sub, (element)->data, (element)->datalen)
2973 ++
2974 ++#define for_each_subelement_id(sub, id, element) \
2975 ++ for_each_element_id(sub, id, (element)->data, (element)->datalen)
2976 ++
2977 ++#define for_each_subelement_extid(sub, extid, element) \
2978 ++ for_each_element_extid(sub, extid, (element)->data, (element)->datalen)
2979 ++
2980 ++/**
2981 ++ * for_each_element_completed - determine if element parsing consumed all data
2982 ++ * @element: element pointer after for_each_element() or friends
2983 ++ * @data: same data pointer as passed to for_each_element() or friends
2984 ++ * @datalen: same data length as passed to for_each_element() or friends
2985 ++ *
2986 ++ * This function returns %true if all the data was parsed or considered
2987 ++ * while walking the elements. Only use this if your for_each_element()
2988 ++ * loop cannot be broken out of, otherwise it always returns %false.
2989 ++ *
2990 ++ * If some data was malformed, this returns %false since the last parsed
2991 ++ * element will not fill the whole remaining data.
2992 ++ */
2993 ++static inline bool for_each_element_completed(const struct element *element,
2994 ++ const void *data, size_t datalen)
2995 ++{
2996 ++ return (const u8 *)element == (const u8 *)data + datalen;
2997 ++}
2998 ++
2999 + #endif /* LINUX_IEEE80211_H */
3000 +diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
3001 +index 95a937eafb79..2fc28324351d 100644
3002 +--- a/include/sound/soc-dapm.h
3003 ++++ b/include/sound/soc-dapm.h
3004 +@@ -335,6 +335,8 @@ struct device;
3005 + #define SND_SOC_DAPM_WILL_PMD 0x80 /* called at start of sequence */
3006 + #define SND_SOC_DAPM_PRE_POST_PMD \
3007 + (SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD)
3008 ++#define SND_SOC_DAPM_PRE_POST_PMU \
3009 ++ (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU)
3010 +
3011 + /* convenience event type detection */
3012 + #define SND_SOC_DAPM_EVENT_ON(e) \
3013 +diff --git a/kernel/elfcore.c b/kernel/elfcore.c
3014 +index e556751d15d9..a2b29b9bdfcb 100644
3015 +--- a/kernel/elfcore.c
3016 ++++ b/kernel/elfcore.c
3017 +@@ -2,6 +2,7 @@
3018 + #include <linux/fs.h>
3019 + #include <linux/mm.h>
3020 + #include <linux/binfmts.h>
3021 ++#include <linux/elfcore.h>
3022 +
3023 + Elf_Half __weak elf_core_extra_phdrs(void)
3024 + {
3025 +diff --git a/kernel/fork.c b/kernel/fork.c
3026 +index bd6aad92819a..a6dc6b3f6a01 100644
3027 +--- a/kernel/fork.c
3028 ++++ b/kernel/fork.c
3029 +@@ -2152,7 +2152,7 @@ int sysctl_max_threads(struct ctl_table *table, int write,
3030 + struct ctl_table t;
3031 + int ret;
3032 + int threads = max_threads;
3033 +- int min = MIN_THREADS;
3034 ++ int min = 1;
3035 + int max = MAX_THREADS;
3036 +
3037 + t = *table;
3038 +@@ -2164,7 +2164,7 @@ int sysctl_max_threads(struct ctl_table *table, int write,
3039 + if (ret || !write)
3040 + return ret;
3041 +
3042 +- set_max_threads(threads);
3043 ++ max_threads = threads;
3044 +
3045 + return 0;
3046 + }
3047 +diff --git a/kernel/panic.c b/kernel/panic.c
3048 +index 1d07cf9af849..dde00886c896 100644
3049 +--- a/kernel/panic.c
3050 ++++ b/kernel/panic.c
3051 +@@ -84,6 +84,7 @@ void panic(const char *fmt, ...)
3052 + * after the panic_lock is acquired) from invoking panic again.
3053 + */
3054 + local_irq_disable();
3055 ++ preempt_disable_notrace();
3056 +
3057 + /*
3058 + * It's possible to come here directly from a panic-assertion and
3059 +diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
3060 +index c82ebd11414a..c6e4e3e7f685 100644
3061 +--- a/kernel/trace/trace.c
3062 ++++ b/kernel/trace/trace.c
3063 +@@ -3370,9 +3370,14 @@ static int show_traces_open(struct inode *inode, struct file *file)
3064 + if (tracing_disabled)
3065 + return -ENODEV;
3066 +
3067 ++ if (trace_array_get(tr) < 0)
3068 ++ return -ENODEV;
3069 ++
3070 + ret = seq_open(file, &show_traces_seq_ops);
3071 +- if (ret)
3072 ++ if (ret) {
3073 ++ trace_array_put(tr);
3074 + return ret;
3075 ++ }
3076 +
3077 + m = file->private_data;
3078 + m->private = tr;
3079 +@@ -3380,6 +3385,14 @@ static int show_traces_open(struct inode *inode, struct file *file)
3080 + return 0;
3081 + }
3082 +
3083 ++static int show_traces_release(struct inode *inode, struct file *file)
3084 ++{
3085 ++ struct trace_array *tr = inode->i_private;
3086 ++
3087 ++ trace_array_put(tr);
3088 ++ return seq_release(inode, file);
3089 ++}
3090 ++
3091 + static ssize_t
3092 + tracing_write_stub(struct file *filp, const char __user *ubuf,
3093 + size_t count, loff_t *ppos)
3094 +@@ -3410,8 +3423,8 @@ static const struct file_operations tracing_fops = {
3095 + static const struct file_operations show_traces_fops = {
3096 + .open = show_traces_open,
3097 + .read = seq_read,
3098 +- .release = seq_release,
3099 + .llseek = seq_lseek,
3100 ++ .release = show_traces_release,
3101 + };
3102 +
3103 + static ssize_t
3104 +diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
3105 +index 1968998e6c6c..95c8e682b491 100644
3106 +--- a/net/wireless/nl80211.c
3107 ++++ b/net/wireless/nl80211.c
3108 +@@ -210,6 +210,36 @@ cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
3109 + return __cfg80211_rdev_from_attrs(netns, info->attrs);
3110 + }
3111 +
3112 ++static int validate_beacon_head(const struct nlattr *attr)
3113 ++{
3114 ++ const u8 *data = nla_data(attr);
3115 ++ unsigned int len = nla_len(attr);
3116 ++ const struct element *elem;
3117 ++ const struct ieee80211_mgmt *mgmt = (void *)data;
3118 ++ unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
3119 ++ u.beacon.variable);
3120 ++
3121 ++ if (len < fixedlen)
3122 ++ goto err;
3123 ++
3124 ++ if (ieee80211_hdrlen(mgmt->frame_control) !=
3125 ++ offsetof(struct ieee80211_mgmt, u.beacon))
3126 ++ goto err;
3127 ++
3128 ++ data += fixedlen;
3129 ++ len -= fixedlen;
3130 ++
3131 ++ for_each_element(elem, data, len) {
3132 ++ /* nothing */
3133 ++ }
3134 ++
3135 ++ if (for_each_element_completed(elem, data, len))
3136 ++ return 0;
3137 ++
3138 ++err:
3139 ++ return -EINVAL;
3140 ++}
3141 ++
3142 + /* policy for the attributes */
3143 + static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
3144 + [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
3145 +@@ -1934,6 +1964,8 @@ static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
3146 +
3147 + control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
3148 +
3149 ++ memset(chandef, 0, sizeof(*chandef));
3150 ++
3151 + chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
3152 + chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
3153 + chandef->center_freq1 = control_freq;
3154 +@@ -2402,7 +2434,7 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
3155 +
3156 + if (rdev->ops->get_channel) {
3157 + int ret;
3158 +- struct cfg80211_chan_def chandef;
3159 ++ struct cfg80211_chan_def chandef = {};
3160 +
3161 + ret = rdev_get_channel(rdev, wdev, &chandef);
3162 + if (ret == 0) {
3163 +@@ -3212,6 +3244,11 @@ static int nl80211_parse_beacon(struct nlattr *attrs[],
3164 + memset(bcn, 0, sizeof(*bcn));
3165 +
3166 + if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3167 ++ int ret = validate_beacon_head(attrs[NL80211_ATTR_BEACON_HEAD]);
3168 ++
3169 ++ if (ret)
3170 ++ return ret;
3171 ++
3172 + bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3173 + bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
3174 + if (!bcn->head_len)
3175 +diff --git a/net/wireless/reg.c b/net/wireless/reg.c
3176 +index 6a670a373e29..437ec52d5e71 100644
3177 +--- a/net/wireless/reg.c
3178 ++++ b/net/wireless/reg.c
3179 +@@ -1604,7 +1604,7 @@ static void reg_call_notifier(struct wiphy *wiphy,
3180 +
3181 + static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev)
3182 + {
3183 +- struct cfg80211_chan_def chandef;
3184 ++ struct cfg80211_chan_def chandef = {};
3185 + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
3186 + enum nl80211_iftype iftype;
3187 +
3188 +diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
3189 +index fd682832a0e3..cd119943612b 100644
3190 +--- a/net/wireless/wext-compat.c
3191 ++++ b/net/wireless/wext-compat.c
3192 +@@ -821,7 +821,7 @@ static int cfg80211_wext_giwfreq(struct net_device *dev,
3193 + {
3194 + struct wireless_dev *wdev = dev->ieee80211_ptr;
3195 + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
3196 +- struct cfg80211_chan_def chandef;
3197 ++ struct cfg80211_chan_def chandef = {};
3198 + int ret;
3199 +
3200 + switch (wdev->iftype) {
3201 +diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
3202 +index a29209fa5674..5c87baaefafb 100644
3203 +--- a/security/integrity/ima/ima_crypto.c
3204 ++++ b/security/integrity/ima/ima_crypto.c
3205 +@@ -298,8 +298,11 @@ static int ima_calc_file_hash_atfm(struct file *file,
3206 + rbuf_len = min_t(loff_t, i_size - offset, rbuf_size[active]);
3207 + rc = integrity_kernel_read(file, offset, rbuf[active],
3208 + rbuf_len);
3209 +- if (rc != rbuf_len)
3210 ++ if (rc != rbuf_len) {
3211 ++ if (rc >= 0)
3212 ++ rc = -EINVAL;
3213 + goto out3;
3214 ++ }
3215 +
3216 + if (rbuf[1] && offset) {
3217 + /* Using two buffers, and it is not the first
3218 +diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
3219 +index 549f853c4092..4808b70ec12c 100644
3220 +--- a/sound/soc/codecs/sgtl5000.c
3221 ++++ b/sound/soc/codecs/sgtl5000.c
3222 +@@ -35,6 +35,13 @@
3223 + #define SGTL5000_DAP_REG_OFFSET 0x0100
3224 + #define SGTL5000_MAX_REG_OFFSET 0x013A
3225 +
3226 ++/* Delay for the VAG ramp up */
3227 ++#define SGTL5000_VAG_POWERUP_DELAY 500 /* ms */
3228 ++/* Delay for the VAG ramp down */
3229 ++#define SGTL5000_VAG_POWERDOWN_DELAY 500 /* ms */
3230 ++
3231 ++#define SGTL5000_OUTPUTS_MUTE (SGTL5000_HP_MUTE | SGTL5000_LINE_OUT_MUTE)
3232 ++
3233 + /* default value of sgtl5000 registers */
3234 + static const struct reg_default sgtl5000_reg_defaults[] = {
3235 + { SGTL5000_CHIP_DIG_POWER, 0x0000 },
3236 +@@ -129,6 +136,13 @@ enum sgtl5000_micbias_resistor {
3237 + SGTL5000_MICBIAS_8K = 8,
3238 + };
3239 +
3240 ++enum {
3241 ++ HP_POWER_EVENT,
3242 ++ DAC_POWER_EVENT,
3243 ++ ADC_POWER_EVENT,
3244 ++ LAST_POWER_EVENT = ADC_POWER_EVENT
3245 ++};
3246 ++
3247 + /* sgtl5000 private structure in codec */
3248 + struct sgtl5000_priv {
3249 + int sysclk; /* sysclk rate */
3250 +@@ -141,8 +155,117 @@ struct sgtl5000_priv {
3251 + int revision;
3252 + u8 micbias_resistor;
3253 + u8 micbias_voltage;
3254 ++ u16 mute_state[LAST_POWER_EVENT + 1];
3255 + };
3256 +
3257 ++static inline int hp_sel_input(struct snd_soc_component *component)
3258 ++{
3259 ++ unsigned int ana_reg = 0;
3260 ++
3261 ++ snd_soc_component_read(component, SGTL5000_CHIP_ANA_CTRL, &ana_reg);
3262 ++
3263 ++ return (ana_reg & SGTL5000_HP_SEL_MASK) >> SGTL5000_HP_SEL_SHIFT;
3264 ++}
3265 ++
3266 ++static inline u16 mute_output(struct snd_soc_component *component,
3267 ++ u16 mute_mask)
3268 ++{
3269 ++ unsigned int mute_reg = 0;
3270 ++
3271 ++ snd_soc_component_read(component, SGTL5000_CHIP_ANA_CTRL, &mute_reg);
3272 ++
3273 ++ snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
3274 ++ mute_mask, mute_mask);
3275 ++ return mute_reg;
3276 ++}
3277 ++
3278 ++static inline void restore_output(struct snd_soc_component *component,
3279 ++ u16 mute_mask, u16 mute_reg)
3280 ++{
3281 ++ snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
3282 ++ mute_mask, mute_reg);
3283 ++}
3284 ++
3285 ++static void vag_power_on(struct snd_soc_component *component, u32 source)
3286 ++{
3287 ++ unsigned int ana_reg = 0;
3288 ++
3289 ++ snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER, &ana_reg);
3290 ++
3291 ++ if (ana_reg & SGTL5000_VAG_POWERUP)
3292 ++ return;
3293 ++
3294 ++ snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
3295 ++ SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
3296 ++
3297 ++ /* When VAG powering on to get local loop from Line-In, the sleep
3298 ++ * is required to avoid loud pop.
3299 ++ */
3300 ++ if (hp_sel_input(component) == SGTL5000_HP_SEL_LINE_IN &&
3301 ++ source == HP_POWER_EVENT)
3302 ++ msleep(SGTL5000_VAG_POWERUP_DELAY);
3303 ++}
3304 ++
3305 ++static int vag_power_consumers(struct snd_soc_component *component,
3306 ++ u16 ana_pwr_reg, u32 source)
3307 ++{
3308 ++ int consumers = 0;
3309 ++
3310 ++ /* count dac/adc consumers unconditional */
3311 ++ if (ana_pwr_reg & SGTL5000_DAC_POWERUP)
3312 ++ consumers++;
3313 ++ if (ana_pwr_reg & SGTL5000_ADC_POWERUP)
3314 ++ consumers++;
3315 ++
3316 ++ /*
3317 ++ * If the event comes from HP and Line-In is selected,
3318 ++ * current action is 'DAC to be powered down'.
3319 ++ * As HP_POWERUP is not set when HP muxed to line-in,
3320 ++ * we need to keep VAG power ON.
3321 ++ */
3322 ++ if (source == HP_POWER_EVENT) {
3323 ++ if (hp_sel_input(component) == SGTL5000_HP_SEL_LINE_IN)
3324 ++ consumers++;
3325 ++ } else {
3326 ++ if (ana_pwr_reg & SGTL5000_HP_POWERUP)
3327 ++ consumers++;
3328 ++ }
3329 ++
3330 ++ return consumers;
3331 ++}
3332 ++
3333 ++static void vag_power_off(struct snd_soc_component *component, u32 source)
3334 ++{
3335 ++ unsigned int ana_pwr = SGTL5000_VAG_POWERUP;
3336 ++
3337 ++ snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER, &ana_pwr);
3338 ++
3339 ++ if (!(ana_pwr & SGTL5000_VAG_POWERUP))
3340 ++ return;
3341 ++
3342 ++ /*
3343 ++ * This function calls when any of VAG power consumers is disappearing.
3344 ++ * Thus, if there is more than one consumer at the moment, as minimum
3345 ++ * one consumer will definitely stay after the end of the current
3346 ++ * event.
3347 ++ * Don't clear VAG_POWERUP if 2 or more consumers of VAG present:
3348 ++ * - LINE_IN (for HP events) / HP (for DAC/ADC events)
3349 ++ * - DAC
3350 ++ * - ADC
3351 ++ * (the current consumer is disappearing right now)
3352 ++ */
3353 ++ if (vag_power_consumers(component, ana_pwr, source) >= 2)
3354 ++ return;
3355 ++
3356 ++ snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
3357 ++ SGTL5000_VAG_POWERUP, 0);
3358 ++ /* In power down case, we need wait 400-1000 ms
3359 ++ * when VAG fully ramped down.
3360 ++ * As longer we wait, as smaller pop we've got.
3361 ++ */
3362 ++ msleep(SGTL5000_VAG_POWERDOWN_DELAY);
3363 ++}
3364 ++
3365 + /*
3366 + * mic_bias power on/off share the same register bits with
3367 + * output impedance of mic bias, when power on mic bias, we
3368 +@@ -174,36 +297,46 @@ static int mic_bias_event(struct snd_soc_dapm_widget *w,
3369 + return 0;
3370 + }
3371 +
3372 +-/*
3373 +- * As manual described, ADC/DAC only works when VAG powerup,
3374 +- * So enabled VAG before ADC/DAC up.
3375 +- * In power down case, we need wait 400ms when vag fully ramped down.
3376 +- */
3377 +-static int power_vag_event(struct snd_soc_dapm_widget *w,
3378 +- struct snd_kcontrol *kcontrol, int event)
3379 ++static int vag_and_mute_control(struct snd_soc_component *component,
3380 ++ int event, int event_source)
3381 + {
3382 +- struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
3383 +- const u32 mask = SGTL5000_DAC_POWERUP | SGTL5000_ADC_POWERUP;
3384 ++ static const u16 mute_mask[] = {
3385 ++ /*
3386 ++ * Mask for HP_POWER_EVENT.
3387 ++ * Muxing Headphones have to be wrapped with mute/unmute
3388 ++ * headphones only.
3389 ++ */
3390 ++ SGTL5000_HP_MUTE,
3391 ++ /*
3392 ++ * Masks for DAC_POWER_EVENT/ADC_POWER_EVENT.
3393 ++ * Muxing DAC or ADC block have to be wrapped with mute/unmute
3394 ++ * both headphones and line-out.
3395 ++ */
3396 ++ SGTL5000_OUTPUTS_MUTE,
3397 ++ SGTL5000_OUTPUTS_MUTE
3398 ++ };
3399 ++
3400 ++ struct sgtl5000_priv *sgtl5000 =
3401 ++ snd_soc_component_get_drvdata(component);
3402 +
3403 + switch (event) {
3404 ++ case SND_SOC_DAPM_PRE_PMU:
3405 ++ sgtl5000->mute_state[event_source] =
3406 ++ mute_output(component, mute_mask[event_source]);
3407 ++ break;
3408 + case SND_SOC_DAPM_POST_PMU:
3409 +- snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
3410 +- SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
3411 +- msleep(400);
3412 ++ vag_power_on(component, event_source);
3413 ++ restore_output(component, mute_mask[event_source],
3414 ++ sgtl5000->mute_state[event_source]);
3415 + break;
3416 +-
3417 + case SND_SOC_DAPM_PRE_PMD:
3418 +- /*
3419 +- * Don't clear VAG_POWERUP, when both DAC and ADC are
3420 +- * operational to prevent inadvertently starving the
3421 +- * other one of them.
3422 +- */
3423 +- if ((snd_soc_read(codec, SGTL5000_CHIP_ANA_POWER) &
3424 +- mask) != mask) {
3425 +- snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
3426 +- SGTL5000_VAG_POWERUP, 0);
3427 +- msleep(400);
3428 +- }
3429 ++ sgtl5000->mute_state[event_source] =
3430 ++ mute_output(component, mute_mask[event_source]);
3431 ++ vag_power_off(component, event_source);
3432 ++ break;
3433 ++ case SND_SOC_DAPM_POST_PMD:
3434 ++ restore_output(component, mute_mask[event_source],
3435 ++ sgtl5000->mute_state[event_source]);
3436 + break;
3437 + default:
3438 + break;
3439 +@@ -212,6 +345,41 @@ static int power_vag_event(struct snd_soc_dapm_widget *w,
3440 + return 0;
3441 + }
3442 +
3443 ++/*
3444 ++ * Mute Headphone when power it up/down.
3445 ++ * Control VAG power on HP power path.
3446 ++ */
3447 ++static int headphone_pga_event(struct snd_soc_dapm_widget *w,
3448 ++ struct snd_kcontrol *kcontrol, int event)
3449 ++{
3450 ++ struct snd_soc_component *component =
3451 ++ snd_soc_dapm_to_component(w->dapm);
3452 ++
3453 ++ return vag_and_mute_control(component, event, HP_POWER_EVENT);
3454 ++}
3455 ++
3456 ++/* As manual describes, ADC/DAC powering up/down requires
3457 ++ * to mute outputs to avoid pops.
3458 ++ * Control VAG power on ADC/DAC power path.
3459 ++ */
3460 ++static int adc_updown_depop(struct snd_soc_dapm_widget *w,
3461 ++ struct snd_kcontrol *kcontrol, int event)
3462 ++{
3463 ++ struct snd_soc_component *component =
3464 ++ snd_soc_dapm_to_component(w->dapm);
3465 ++
3466 ++ return vag_and_mute_control(component, event, ADC_POWER_EVENT);
3467 ++}
3468 ++
3469 ++static int dac_updown_depop(struct snd_soc_dapm_widget *w,
3470 ++ struct snd_kcontrol *kcontrol, int event)
3471 ++{
3472 ++ struct snd_soc_component *component =
3473 ++ snd_soc_dapm_to_component(w->dapm);
3474 ++
3475 ++ return vag_and_mute_control(component, event, DAC_POWER_EVENT);
3476 ++}
3477 ++
3478 + /* input sources for ADC */
3479 + static const char *adc_mux_text[] = {
3480 + "MIC_IN", "LINE_IN"
3481 +@@ -247,7 +415,10 @@ static const struct snd_soc_dapm_widget sgtl5000_dapm_widgets[] = {
3482 + mic_bias_event,
3483 + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
3484 +
3485 +- SND_SOC_DAPM_PGA("HP", SGTL5000_CHIP_ANA_POWER, 4, 0, NULL, 0),
3486 ++ SND_SOC_DAPM_PGA_E("HP", SGTL5000_CHIP_ANA_POWER, 4, 0, NULL, 0,
3487 ++ headphone_pga_event,
3488 ++ SND_SOC_DAPM_PRE_POST_PMU |
3489 ++ SND_SOC_DAPM_PRE_POST_PMD),
3490 + SND_SOC_DAPM_PGA("LO", SGTL5000_CHIP_ANA_POWER, 0, 0, NULL, 0),
3491 +
3492 + SND_SOC_DAPM_MUX("Capture Mux", SND_SOC_NOPM, 0, 0, &adc_mux),
3493 +@@ -263,11 +434,12 @@ static const struct snd_soc_dapm_widget sgtl5000_dapm_widgets[] = {
3494 + 0, SGTL5000_CHIP_DIG_POWER,
3495 + 1, 0),
3496 +
3497 +- SND_SOC_DAPM_ADC("ADC", "Capture", SGTL5000_CHIP_ANA_POWER, 1, 0),
3498 +- SND_SOC_DAPM_DAC("DAC", "Playback", SGTL5000_CHIP_ANA_POWER, 3, 0),
3499 +-
3500 +- SND_SOC_DAPM_PRE("VAG_POWER_PRE", power_vag_event),
3501 +- SND_SOC_DAPM_POST("VAG_POWER_POST", power_vag_event),
3502 ++ SND_SOC_DAPM_ADC_E("ADC", "Capture", SGTL5000_CHIP_ANA_POWER, 1, 0,
3503 ++ adc_updown_depop, SND_SOC_DAPM_PRE_POST_PMU |
3504 ++ SND_SOC_DAPM_PRE_POST_PMD),
3505 ++ SND_SOC_DAPM_DAC_E("DAC", "Playback", SGTL5000_CHIP_ANA_POWER, 3, 0,
3506 ++ dac_updown_depop, SND_SOC_DAPM_PRE_POST_PMU |
3507 ++ SND_SOC_DAPM_PRE_POST_PMD),
3508 + };
3509 +
3510 + /* routes for sgtl5000 */
3511 +diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
3512 +index df3c73e9dea4..9954b069b3ca 100644
3513 +--- a/tools/lib/traceevent/event-parse.c
3514 ++++ b/tools/lib/traceevent/event-parse.c
3515 +@@ -265,10 +265,10 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
3516 + errno = ENOMEM;
3517 + return -1;
3518 + }
3519 ++ pevent->cmdlines = cmdlines;
3520 +
3521 + cmdlines[pevent->cmdline_count].comm = strdup(comm);
3522 + if (!cmdlines[pevent->cmdline_count].comm) {
3523 +- free(cmdlines);
3524 + errno = ENOMEM;
3525 + return -1;
3526 + }
3527 +@@ -279,7 +279,6 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
3528 + pevent->cmdline_count++;
3529 +
3530 + qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
3531 +- pevent->cmdlines = cmdlines;
3532 +
3533 + return 0;
3534 + }
3535 +diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
3536 +index e77880b5094d..65a6922db722 100644
3537 +--- a/tools/perf/builtin-stat.c
3538 ++++ b/tools/perf/builtin-stat.c
3539 +@@ -1416,7 +1416,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
3540 + run_idx + 1);
3541 +
3542 + status = run_perf_stat(argc, argv);
3543 +- if (forever && status != -1) {
3544 ++ if (forever && status != -1 && !interval) {
3545 + print_counters(NULL, argc, argv);
3546 + perf_stat__reset_stats();
3547 + }
3548 +diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
3549 +index 62f6d7dc2dda..9d02aa93ef90 100644
3550 +--- a/tools/perf/util/llvm-utils.c
3551 ++++ b/tools/perf/util/llvm-utils.c
3552 +@@ -214,14 +214,14 @@ static int detect_kbuild_dir(char **kbuild_dir)
3553 + const char *prefix_dir = "";
3554 + const char *suffix_dir = "";
3555 +
3556 ++ /* _UTSNAME_LENGTH is 65 */
3557 ++ char release[128];
3558 ++
3559 + char *autoconf_path;
3560 +
3561 + int err;
3562 +
3563 + if (!test_dir) {
3564 +- /* _UTSNAME_LENGTH is 65 */
3565 +- char release[128];
3566 +-
3567 + err = fetch_kernel_version(NULL, release,
3568 + sizeof(release));
3569 + if (err)