Magellan Linux

Annotation of /trunk/kernel-alx-legacy/patches-4.9/0296-4.9.197-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


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