Magellan Linux

Annotation of /trunk/kernel-alx/patches-4.9/0298-4.9.199-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3573 - (hide annotations) (download)
Thu Aug 13 10:21:16 2020 UTC (3 years, 9 months ago) by niro
File size: 96996 byte(s)
linux-199
1 niro 3573 diff --git a/Makefile b/Makefile
2     index 2f11058a0d06..b7f6639f4e7a 100644
3     --- a/Makefile
4     +++ b/Makefile
5     @@ -1,6 +1,6 @@
6     VERSION = 4
7     PATCHLEVEL = 9
8     -SUBLEVEL = 198
9     +SUBLEVEL = 199
10     EXTRAVERSION =
11     NAME = Roaring Lionus
12    
13     diff --git a/arch/mips/fw/sni/sniprom.c b/arch/mips/fw/sni/sniprom.c
14     index 6aa264b9856a..7c6151d412bd 100644
15     --- a/arch/mips/fw/sni/sniprom.c
16     +++ b/arch/mips/fw/sni/sniprom.c
17     @@ -42,7 +42,7 @@
18    
19     /* O32 stack has to be 8-byte aligned. */
20     static u64 o32_stk[4096];
21     -#define O32_STK &o32_stk[sizeof(o32_stk)]
22     +#define O32_STK (&o32_stk[ARRAY_SIZE(o32_stk)])
23    
24     #define __PROM_O32(fun, arg) fun arg __asm__(#fun); \
25     __asm__(#fun " = call_o32")
26     diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
27     index a7ef70220126..31b2913372b5 100644
28     --- a/arch/s390/include/asm/uaccess.h
29     +++ b/arch/s390/include/asm/uaccess.h
30     @@ -151,7 +151,7 @@ unsigned long __must_check __copy_to_user(void __user *to, const void *from,
31     __rc; \
32     })
33    
34     -static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
35     +static __always_inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
36     {
37     unsigned long spec = 0x810000UL;
38     int rc;
39     @@ -181,7 +181,7 @@ static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
40     return rc;
41     }
42    
43     -static inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size)
44     +static __always_inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size)
45     {
46     unsigned long spec = 0x81UL;
47     int rc;
48     diff --git a/arch/s390/mm/cmm.c b/arch/s390/mm/cmm.c
49     index 79ddd580d605..ca6fab51eea1 100644
50     --- a/arch/s390/mm/cmm.c
51     +++ b/arch/s390/mm/cmm.c
52     @@ -306,16 +306,16 @@ static int cmm_timeout_handler(struct ctl_table *ctl, int write,
53     }
54    
55     if (write) {
56     - len = *lenp;
57     - if (copy_from_user(buf, buffer,
58     - len > sizeof(buf) ? sizeof(buf) : len))
59     + len = min(*lenp, sizeof(buf));
60     + if (copy_from_user(buf, buffer, len))
61     return -EFAULT;
62     - buf[sizeof(buf) - 1] = '\0';
63     + buf[len - 1] = '\0';
64     cmm_skip_blanks(buf, &p);
65     nr = simple_strtoul(p, &p, 0);
66     cmm_skip_blanks(p, &p);
67     seconds = simple_strtoul(p, &p, 0);
68     cmm_set_timeout(nr, seconds);
69     + *ppos += *lenp;
70     } else {
71     len = sprintf(buf, "%ld %ld\n",
72     cmm_timeout_pages, cmm_timeout_seconds);
73     @@ -323,9 +323,9 @@ static int cmm_timeout_handler(struct ctl_table *ctl, int write,
74     len = *lenp;
75     if (copy_to_user(buffer, buf, len))
76     return -EFAULT;
77     + *lenp = len;
78     + *ppos += len;
79     }
80     - *lenp = len;
81     - *ppos += len;
82     return 0;
83     }
84    
85     diff --git a/arch/x86/include/asm/intel-family.h b/arch/x86/include/asm/intel-family.h
86     index ba7b6f736414..74ee597beb3e 100644
87     --- a/arch/x86/include/asm/intel-family.h
88     +++ b/arch/x86/include/asm/intel-family.h
89     @@ -5,7 +5,7 @@
90     * "Big Core" Processors (Branded as Core, Xeon, etc...)
91     *
92     * The "_X" parts are generally the EP and EX Xeons, or the
93     - * "Extreme" ones, like Broadwell-E.
94     + * "Extreme" ones, like Broadwell-E, or Atom microserver.
95     *
96     * Things ending in "2" are usually because we have no better
97     * name for them. There's no processor called "SILVERMONT2".
98     @@ -67,6 +67,7 @@
99     #define INTEL_FAM6_ATOM_GOLDMONT 0x5C /* Apollo Lake */
100     #define INTEL_FAM6_ATOM_GOLDMONT_X 0x5F /* Denverton */
101     #define INTEL_FAM6_ATOM_GOLDMONT_PLUS 0x7A /* Gemini Lake */
102     +#define INTEL_FAM6_ATOM_TREMONT_X 0x86 /* Jacobsville */
103    
104     /* Xeon Phi */
105    
106     diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
107     index a0e85f2aff7d..b6669d326545 100644
108     --- a/arch/x86/platform/efi/efi.c
109     +++ b/arch/x86/platform/efi/efi.c
110     @@ -896,9 +896,6 @@ static void __init kexec_enter_virtual_mode(void)
111    
112     if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX))
113     runtime_code_page_mkexec();
114     -
115     - /* clean DUMMY object */
116     - efi_delete_dummy_variable();
117     #endif
118     }
119    
120     diff --git a/drivers/dma/cppi41.c b/drivers/dma/cppi41.c
121     index 2ceb5a26f860..709e1308777a 100644
122     --- a/drivers/dma/cppi41.c
123     +++ b/drivers/dma/cppi41.c
124     @@ -586,9 +586,22 @@ static struct dma_async_tx_descriptor *cppi41_dma_prep_slave_sg(
125     enum dma_transfer_direction dir, unsigned long tx_flags, void *context)
126     {
127     struct cppi41_channel *c = to_cpp41_chan(chan);
128     + struct dma_async_tx_descriptor *txd = NULL;
129     + struct cppi41_dd *cdd = c->cdd;
130     struct cppi41_desc *d;
131     struct scatterlist *sg;
132     unsigned int i;
133     + int error;
134     +
135     + error = pm_runtime_get(cdd->ddev.dev);
136     + if (error < 0) {
137     + pm_runtime_put_noidle(cdd->ddev.dev);
138     +
139     + return NULL;
140     + }
141     +
142     + if (cdd->is_suspended)
143     + goto err_out_not_ready;
144    
145     d = c->desc;
146     for_each_sg(sgl, sg, sg_len, i) {
147     @@ -611,7 +624,13 @@ static struct dma_async_tx_descriptor *cppi41_dma_prep_slave_sg(
148     d++;
149     }
150    
151     - return &c->txd;
152     + txd = &c->txd;
153     +
154     +err_out_not_ready:
155     + pm_runtime_mark_last_busy(cdd->ddev.dev);
156     + pm_runtime_put_autosuspend(cdd->ddev.dev);
157     +
158     + return txd;
159     }
160    
161     static void cppi41_compute_td_desc(struct cppi41_desc *d)
162     diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
163     index f40f7df4b734..c0e54396f250 100644
164     --- a/drivers/firmware/efi/cper.c
165     +++ b/drivers/firmware/efi/cper.c
166     @@ -375,7 +375,7 @@ static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
167     printk("%s""vendor_id: 0x%04x, device_id: 0x%04x\n", pfx,
168     pcie->device_id.vendor_id, pcie->device_id.device_id);
169     p = pcie->device_id.class_code;
170     - printk("%s""class_code: %02x%02x%02x\n", pfx, p[0], p[1], p[2]);
171     + printk("%s""class_code: %02x%02x%02x\n", pfx, p[2], p[1], p[0]);
172     }
173     if (pcie->validation_bits & CPER_PCIE_VALID_SERIAL_NUMBER)
174     printk("%s""serial number: 0x%04x, 0x%04x\n", pfx,
175     diff --git a/drivers/gpio/gpio-max77620.c b/drivers/gpio/gpio-max77620.c
176     index b46b436cb97f..4fe0be5aa294 100644
177     --- a/drivers/gpio/gpio-max77620.c
178     +++ b/drivers/gpio/gpio-max77620.c
179     @@ -167,13 +167,13 @@ static int max77620_gpio_set_debounce(struct gpio_chip *gc,
180     case 0:
181     val = MAX77620_CNFG_GPIO_DBNC_None;
182     break;
183     - case 1 ... 8:
184     + case 1000 ... 8000:
185     val = MAX77620_CNFG_GPIO_DBNC_8ms;
186     break;
187     - case 9 ... 16:
188     + case 9000 ... 16000:
189     val = MAX77620_CNFG_GPIO_DBNC_16ms;
190     break;
191     - case 17 ... 32:
192     + case 17000 ... 32000:
193     val = MAX77620_CNFG_GPIO_DBNC_32ms;
194     break;
195     default:
196     diff --git a/drivers/hid/hid-axff.c b/drivers/hid/hid-axff.c
197     index a594e478a1e2..843aed4dec80 100644
198     --- a/drivers/hid/hid-axff.c
199     +++ b/drivers/hid/hid-axff.c
200     @@ -75,13 +75,20 @@ static int axff_init(struct hid_device *hid)
201     {
202     struct axff_device *axff;
203     struct hid_report *report;
204     - struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
205     + struct hid_input *hidinput;
206     struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list;
207     - struct input_dev *dev = hidinput->input;
208     + struct input_dev *dev;
209     int field_count = 0;
210     int i, j;
211     int error;
212    
213     + if (list_empty(&hid->inputs)) {
214     + hid_err(hid, "no inputs found\n");
215     + return -ENODEV;
216     + }
217     + hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
218     + dev = hidinput->input;
219     +
220     if (list_empty(report_list)) {
221     hid_err(hid, "no output reports found\n");
222     return -ENODEV;
223     diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
224     index ceb4df96e0d5..9aeab4ff2d81 100644
225     --- a/drivers/hid/hid-core.c
226     +++ b/drivers/hid/hid-core.c
227     @@ -959,6 +959,7 @@ int hid_open_report(struct hid_device *device)
228     __u8 *start;
229     __u8 *buf;
230     __u8 *end;
231     + __u8 *next;
232     int ret;
233     static int (*dispatch_type[])(struct hid_parser *parser,
234     struct hid_item *item) = {
235     @@ -1012,7 +1013,8 @@ int hid_open_report(struct hid_device *device)
236     device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
237    
238     ret = -EINVAL;
239     - while ((start = fetch_item(start, end, &item)) != NULL) {
240     + while ((next = fetch_item(start, end, &item)) != NULL) {
241     + start = next;
242    
243     if (item.format != HID_ITEM_FORMAT_SHORT) {
244     hid_err(device, "unexpected long global item\n");
245     @@ -1041,7 +1043,8 @@ int hid_open_report(struct hid_device *device)
246     }
247     }
248    
249     - hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
250     + hid_err(device, "item fetching failed at offset %u/%u\n",
251     + size - (unsigned int)(end - start), size);
252     err:
253     vfree(parser);
254     hid_close_report(device);
255     diff --git a/drivers/hid/hid-dr.c b/drivers/hid/hid-dr.c
256     index 818ea7d93533..309969b8dc2e 100644
257     --- a/drivers/hid/hid-dr.c
258     +++ b/drivers/hid/hid-dr.c
259     @@ -87,13 +87,19 @@ static int drff_init(struct hid_device *hid)
260     {
261     struct drff_device *drff;
262     struct hid_report *report;
263     - struct hid_input *hidinput = list_first_entry(&hid->inputs,
264     - struct hid_input, list);
265     + struct hid_input *hidinput;
266     struct list_head *report_list =
267     &hid->report_enum[HID_OUTPUT_REPORT].report_list;
268     - struct input_dev *dev = hidinput->input;
269     + struct input_dev *dev;
270     int error;
271    
272     + if (list_empty(&hid->inputs)) {
273     + hid_err(hid, "no inputs found\n");
274     + return -ENODEV;
275     + }
276     + hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
277     + dev = hidinput->input;
278     +
279     if (list_empty(report_list)) {
280     hid_err(hid, "no output reports found\n");
281     return -ENODEV;
282     diff --git a/drivers/hid/hid-emsff.c b/drivers/hid/hid-emsff.c
283     index d82d75bb11f7..80f9a02dfa69 100644
284     --- a/drivers/hid/hid-emsff.c
285     +++ b/drivers/hid/hid-emsff.c
286     @@ -59,13 +59,19 @@ static int emsff_init(struct hid_device *hid)
287     {
288     struct emsff_device *emsff;
289     struct hid_report *report;
290     - struct hid_input *hidinput = list_first_entry(&hid->inputs,
291     - struct hid_input, list);
292     + struct hid_input *hidinput;
293     struct list_head *report_list =
294     &hid->report_enum[HID_OUTPUT_REPORT].report_list;
295     - struct input_dev *dev = hidinput->input;
296     + struct input_dev *dev;
297     int error;
298    
299     + if (list_empty(&hid->inputs)) {
300     + hid_err(hid, "no inputs found\n");
301     + return -ENODEV;
302     + }
303     + hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
304     + dev = hidinput->input;
305     +
306     if (list_empty(report_list)) {
307     hid_err(hid, "no output reports found\n");
308     return -ENODEV;
309     diff --git a/drivers/hid/hid-gaff.c b/drivers/hid/hid-gaff.c
310     index 2d8cead3adca..5a02c50443cb 100644
311     --- a/drivers/hid/hid-gaff.c
312     +++ b/drivers/hid/hid-gaff.c
313     @@ -77,14 +77,20 @@ static int gaff_init(struct hid_device *hid)
314     {
315     struct gaff_device *gaff;
316     struct hid_report *report;
317     - struct hid_input *hidinput = list_entry(hid->inputs.next,
318     - struct hid_input, list);
319     + struct hid_input *hidinput;
320     struct list_head *report_list =
321     &hid->report_enum[HID_OUTPUT_REPORT].report_list;
322     struct list_head *report_ptr = report_list;
323     - struct input_dev *dev = hidinput->input;
324     + struct input_dev *dev;
325     int error;
326    
327     + if (list_empty(&hid->inputs)) {
328     + hid_err(hid, "no inputs found\n");
329     + return -ENODEV;
330     + }
331     + hidinput = list_entry(hid->inputs.next, struct hid_input, list);
332     + dev = hidinput->input;
333     +
334     if (list_empty(report_list)) {
335     hid_err(hid, "no output reports found\n");
336     return -ENODEV;
337     diff --git a/drivers/hid/hid-holtekff.c b/drivers/hid/hid-holtekff.c
338     index 9325545fc3ae..3e84551cca9c 100644
339     --- a/drivers/hid/hid-holtekff.c
340     +++ b/drivers/hid/hid-holtekff.c
341     @@ -140,13 +140,19 @@ static int holtekff_init(struct hid_device *hid)
342     {
343     struct holtekff_device *holtekff;
344     struct hid_report *report;
345     - struct hid_input *hidinput = list_entry(hid->inputs.next,
346     - struct hid_input, list);
347     + struct hid_input *hidinput;
348     struct list_head *report_list =
349     &hid->report_enum[HID_OUTPUT_REPORT].report_list;
350     - struct input_dev *dev = hidinput->input;
351     + struct input_dev *dev;
352     int error;
353    
354     + if (list_empty(&hid->inputs)) {
355     + hid_err(hid, "no inputs found\n");
356     + return -ENODEV;
357     + }
358     + hidinput = list_entry(hid->inputs.next, struct hid_input, list);
359     + dev = hidinput->input;
360     +
361     if (list_empty(report_list)) {
362     hid_err(hid, "no output report found\n");
363     return -ENODEV;
364     diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
365     index 0e3fb1a7e421..6909d9c2fc67 100644
366     --- a/drivers/hid/hid-lg2ff.c
367     +++ b/drivers/hid/hid-lg2ff.c
368     @@ -62,11 +62,17 @@ int lg2ff_init(struct hid_device *hid)
369     {
370     struct lg2ff_device *lg2ff;
371     struct hid_report *report;
372     - struct hid_input *hidinput = list_entry(hid->inputs.next,
373     - struct hid_input, list);
374     - struct input_dev *dev = hidinput->input;
375     + struct hid_input *hidinput;
376     + struct input_dev *dev;
377     int error;
378    
379     + if (list_empty(&hid->inputs)) {
380     + hid_err(hid, "no inputs found\n");
381     + return -ENODEV;
382     + }
383     + hidinput = list_entry(hid->inputs.next, struct hid_input, list);
384     + dev = hidinput->input;
385     +
386     /* Check that the report looks ok */
387     report = hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7);
388     if (!report)
389     diff --git a/drivers/hid/hid-lg3ff.c b/drivers/hid/hid-lg3ff.c
390     index 8c2da183d3bc..acf739fc4060 100644
391     --- a/drivers/hid/hid-lg3ff.c
392     +++ b/drivers/hid/hid-lg3ff.c
393     @@ -129,12 +129,19 @@ static const signed short ff3_joystick_ac[] = {
394    
395     int lg3ff_init(struct hid_device *hid)
396     {
397     - struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
398     - struct input_dev *dev = hidinput->input;
399     + struct hid_input *hidinput;
400     + struct input_dev *dev;
401     const signed short *ff_bits = ff3_joystick_ac;
402     int error;
403     int i;
404    
405     + if (list_empty(&hid->inputs)) {
406     + hid_err(hid, "no inputs found\n");
407     + return -ENODEV;
408     + }
409     + hidinput = list_entry(hid->inputs.next, struct hid_input, list);
410     + dev = hidinput->input;
411     +
412     /* Check that the report looks ok */
413     if (!hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 35))
414     return -ENODEV;
415     diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
416     index 127f1335a1da..1b109a5cf922 100644
417     --- a/drivers/hid/hid-lg4ff.c
418     +++ b/drivers/hid/hid-lg4ff.c
419     @@ -1261,8 +1261,8 @@ static int lg4ff_handle_multimode_wheel(struct hid_device *hid, u16 *real_produc
420    
421     int lg4ff_init(struct hid_device *hid)
422     {
423     - struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
424     - struct input_dev *dev = hidinput->input;
425     + struct hid_input *hidinput;
426     + struct input_dev *dev;
427     struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
428     struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
429     const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
430     @@ -1274,6 +1274,13 @@ int lg4ff_init(struct hid_device *hid)
431     int mmode_ret, mmode_idx = -1;
432     u16 real_product_id;
433    
434     + if (list_empty(&hid->inputs)) {
435     + hid_err(hid, "no inputs found\n");
436     + return -ENODEV;
437     + }
438     + hidinput = list_entry(hid->inputs.next, struct hid_input, list);
439     + dev = hidinput->input;
440     +
441     /* Check that the report looks ok */
442     if (!hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7))
443     return -1;
444     diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
445     index e1394af0ae7b..1871cdcd1e0a 100644
446     --- a/drivers/hid/hid-lgff.c
447     +++ b/drivers/hid/hid-lgff.c
448     @@ -127,12 +127,19 @@ static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude)
449    
450     int lgff_init(struct hid_device* hid)
451     {
452     - struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
453     - struct input_dev *dev = hidinput->input;
454     + struct hid_input *hidinput;
455     + struct input_dev *dev;
456     const signed short *ff_bits = ff_joystick;
457     int error;
458     int i;
459    
460     + if (list_empty(&hid->inputs)) {
461     + hid_err(hid, "no inputs found\n");
462     + return -ENODEV;
463     + }
464     + hidinput = list_entry(hid->inputs.next, struct hid_input, list);
465     + dev = hidinput->input;
466     +
467     /* Check that the report looks ok */
468     if (!hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7))
469     return -ENODEV;
470     diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
471     index 38d9deb03d16..434438334fb1 100644
472     --- a/drivers/hid/hid-logitech-hidpp.c
473     +++ b/drivers/hid/hid-logitech-hidpp.c
474     @@ -1238,8 +1238,8 @@ static void hidpp_ff_destroy(struct ff_device *ff)
475     static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
476     {
477     struct hid_device *hid = hidpp->hid_dev;
478     - struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
479     - struct input_dev *dev = hidinput->input;
480     + struct hid_input *hidinput;
481     + struct input_dev *dev;
482     const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
483     const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
484     struct ff_device *ff;
485     @@ -1248,6 +1248,13 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
486     int error, j, num_slots;
487     u8 version;
488    
489     + if (list_empty(&hid->inputs)) {
490     + hid_err(hid, "no inputs found\n");
491     + return -ENODEV;
492     + }
493     + hidinput = list_entry(hid->inputs.next, struct hid_input, list);
494     + dev = hidinput->input;
495     +
496     if (!dev) {
497     hid_err(hid, "Struct input_dev not set!\n");
498     return -EINVAL;
499     diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
500     index eee58d15e745..9633d7a7ac2e 100644
501     --- a/drivers/hid/hid-sony.c
502     +++ b/drivers/hid/hid-sony.c
503     @@ -2008,9 +2008,15 @@ static int sony_play_effect(struct input_dev *dev, void *data,
504    
505     static int sony_init_ff(struct sony_sc *sc)
506     {
507     - struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
508     - struct hid_input, list);
509     - struct input_dev *input_dev = hidinput->input;
510     + struct hid_input *hidinput;
511     + struct input_dev *input_dev;
512     +
513     + if (list_empty(&sc->hdev->inputs)) {
514     + hid_err(sc->hdev, "no inputs found\n");
515     + return -ENODEV;
516     + }
517     + hidinput = list_entry(sc->hdev->inputs.next, struct hid_input, list);
518     + input_dev = hidinput->input;
519    
520     input_set_capability(input_dev, EV_FF, FF_RUMBLE);
521     return input_ff_create_memless(input_dev, NULL, sony_play_effect);
522     diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c
523     index cfa0cb22c9b3..d98e471a5f7b 100644
524     --- a/drivers/hid/hid-tmff.c
525     +++ b/drivers/hid/hid-tmff.c
526     @@ -136,12 +136,18 @@ static int tmff_init(struct hid_device *hid, const signed short *ff_bits)
527     struct tmff_device *tmff;
528     struct hid_report *report;
529     struct list_head *report_list;
530     - struct hid_input *hidinput = list_entry(hid->inputs.next,
531     - struct hid_input, list);
532     - struct input_dev *input_dev = hidinput->input;
533     + struct hid_input *hidinput;
534     + struct input_dev *input_dev;
535     int error;
536     int i;
537    
538     + if (list_empty(&hid->inputs)) {
539     + hid_err(hid, "no inputs found\n");
540     + return -ENODEV;
541     + }
542     + hidinput = list_entry(hid->inputs.next, struct hid_input, list);
543     + input_dev = hidinput->input;
544     +
545     tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
546     if (!tmff)
547     return -ENOMEM;
548     diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
549     index a29756c6ca02..4e7e01be99b1 100644
550     --- a/drivers/hid/hid-zpff.c
551     +++ b/drivers/hid/hid-zpff.c
552     @@ -66,11 +66,17 @@ static int zpff_init(struct hid_device *hid)
553     {
554     struct zpff_device *zpff;
555     struct hid_report *report;
556     - struct hid_input *hidinput = list_entry(hid->inputs.next,
557     - struct hid_input, list);
558     - struct input_dev *dev = hidinput->input;
559     + struct hid_input *hidinput;
560     + struct input_dev *dev;
561     int i, error;
562    
563     + if (list_empty(&hid->inputs)) {
564     + hid_err(hid, "no inputs found\n");
565     + return -ENODEV;
566     + }
567     + hidinput = list_entry(hid->inputs.next, struct hid_input, list);
568     + dev = hidinput->input;
569     +
570     for (i = 0; i < 4; i++) {
571     report = hid_validate_values(hid, HID_OUTPUT_REPORT, 0, i, 1);
572     if (!report)
573     diff --git a/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c b/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c
574     index cac262a912c1..10af8585c820 100644
575     --- a/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c
576     +++ b/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c
577     @@ -322,6 +322,25 @@ static const struct dmi_system_id i2c_hid_dmi_desc_override_table[] = {
578     },
579     .driver_data = (void *)&sipodev_desc
580     },
581     + {
582     + /*
583     + * There are at least 2 Primebook C11B versions, the older
584     + * version has a product-name of "Primebook C11B", and a
585     + * bios version / release / firmware revision of:
586     + * V2.1.2 / 05/03/2018 / 18.2
587     + * The new version has "PRIMEBOOK C11B" as product-name and a
588     + * bios version / release / firmware revision of:
589     + * CFALKSW05_BIOS_V1.1.2 / 11/19/2018 / 19.2
590     + * Only the older version needs this quirk, note the newer
591     + * version will not match as it has a different product-name.
592     + */
593     + .ident = "Trekstor Primebook C11B",
594     + .matches = {
595     + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TREKSTOR"),
596     + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Primebook C11B"),
597     + },
598     + .driver_data = (void *)&sipodev_desc
599     + },
600     {
601     .ident = "Direkt-Tek DTLAPY116-2",
602     .matches = {
603     @@ -330,6 +349,14 @@ static const struct dmi_system_id i2c_hid_dmi_desc_override_table[] = {
604     },
605     .driver_data = (void *)&sipodev_desc
606     },
607     + {
608     + .ident = "Direkt-Tek DTLAPY133-1",
609     + .matches = {
610     + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Direkt-Tek"),
611     + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "DTLAPY133-1"),
612     + },
613     + .driver_data = (void *)&sipodev_desc
614     + },
615     {
616     .ident = "Mediacom Flexbook Edge 11",
617     .matches = {
618     @@ -338,6 +365,14 @@ static const struct dmi_system_id i2c_hid_dmi_desc_override_table[] = {
619     },
620     .driver_data = (void *)&sipodev_desc
621     },
622     + {
623     + .ident = "Odys Winbook 13",
624     + .matches = {
625     + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "AXDIA International GmbH"),
626     + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "WINBOOK 13"),
627     + },
628     + .driver_data = (void *)&sipodev_desc
629     + },
630     { } /* Terminate list */
631     };
632    
633     diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
634     index c3888822add1..b6254ce9ab3b 100644
635     --- a/drivers/iio/accel/bmc150-accel-core.c
636     +++ b/drivers/iio/accel/bmc150-accel-core.c
637     @@ -125,7 +125,7 @@
638     #define BMC150_ACCEL_SLEEP_1_SEC 0x0F
639    
640     #define BMC150_ACCEL_REG_TEMP 0x08
641     -#define BMC150_ACCEL_TEMP_CENTER_VAL 24
642     +#define BMC150_ACCEL_TEMP_CENTER_VAL 23
643    
644     #define BMC150_ACCEL_AXIS_TO_REG(axis) (BMC150_ACCEL_REG_XOUT_L + (axis * 2))
645     #define BMC150_AUTO_SUSPEND_DELAY_MS 2000
646     diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
647     index 85d4ef319c90..dcfbf326f45c 100644
648     --- a/drivers/infiniband/core/cma.c
649     +++ b/drivers/infiniband/core/cma.c
650     @@ -2119,9 +2119,10 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
651     conn_id->cm_id.iw = NULL;
652     cma_exch(conn_id, RDMA_CM_DESTROYING);
653     mutex_unlock(&conn_id->handler_mutex);
654     + mutex_unlock(&listen_id->handler_mutex);
655     cma_deref_id(conn_id);
656     rdma_destroy_id(&conn_id->id);
657     - goto out;
658     + return ret;
659     }
660    
661     mutex_unlock(&conn_id->handler_mutex);
662     diff --git a/drivers/md/dm-bio-prison.c b/drivers/md/dm-bio-prison.c
663     index 03af174485d3..fa2432a89bac 100644
664     --- a/drivers/md/dm-bio-prison.c
665     +++ b/drivers/md/dm-bio-prison.c
666     @@ -32,7 +32,7 @@ static struct kmem_cache *_cell_cache;
667     */
668     struct dm_bio_prison *dm_bio_prison_create(void)
669     {
670     - struct dm_bio_prison *prison = kmalloc(sizeof(*prison), GFP_KERNEL);
671     + struct dm_bio_prison *prison = kzalloc(sizeof(*prison), GFP_KERNEL);
672    
673     if (!prison)
674     return NULL;
675     diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
676     index ee6045d6c0bb..201d90f5d1b3 100644
677     --- a/drivers/md/dm-io.c
678     +++ b/drivers/md/dm-io.c
679     @@ -50,7 +50,7 @@ struct dm_io_client *dm_io_client_create(void)
680     struct dm_io_client *client;
681     unsigned min_ios = dm_get_reserved_bio_based_ios();
682    
683     - client = kmalloc(sizeof(*client), GFP_KERNEL);
684     + client = kzalloc(sizeof(*client), GFP_KERNEL);
685     if (!client)
686     return ERR_PTR(-ENOMEM);
687    
688     diff --git a/drivers/md/dm-kcopyd.c b/drivers/md/dm-kcopyd.c
689     index e0cfde3501e0..4609c5b481e2 100644
690     --- a/drivers/md/dm-kcopyd.c
691     +++ b/drivers/md/dm-kcopyd.c
692     @@ -828,7 +828,7 @@ struct dm_kcopyd_client *dm_kcopyd_client_create(struct dm_kcopyd_throttle *thro
693     int r = -ENOMEM;
694     struct dm_kcopyd_client *kc;
695    
696     - kc = kmalloc(sizeof(*kc), GFP_KERNEL);
697     + kc = kzalloc(sizeof(*kc), GFP_KERNEL);
698     if (!kc)
699     return ERR_PTR(-ENOMEM);
700    
701     diff --git a/drivers/md/dm-region-hash.c b/drivers/md/dm-region-hash.c
702     index 85c32b22a420..91c6f6d72eee 100644
703     --- a/drivers/md/dm-region-hash.c
704     +++ b/drivers/md/dm-region-hash.c
705     @@ -179,7 +179,7 @@ struct dm_region_hash *dm_region_hash_create(
706     ;
707     nr_buckets >>= 1;
708    
709     - rh = kmalloc(sizeof(*rh), GFP_KERNEL);
710     + rh = kzalloc(sizeof(*rh), GFP_KERNEL);
711     if (!rh) {
712     DMERR("unable to allocate region hash memory");
713     return ERR_PTR(-ENOMEM);
714     diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
715     index 2da0b9b213c7..c04d9f22d160 100644
716     --- a/drivers/md/dm-snap.c
717     +++ b/drivers/md/dm-snap.c
718     @@ -19,7 +19,6 @@
719     #include <linux/vmalloc.h>
720     #include <linux/log2.h>
721     #include <linux/dm-kcopyd.h>
722     -#include <linux/semaphore.h>
723    
724     #include "dm.h"
725    
726     @@ -48,7 +47,7 @@ struct dm_exception_table {
727     };
728    
729     struct dm_snapshot {
730     - struct rw_semaphore lock;
731     + struct mutex lock;
732    
733     struct dm_dev *origin;
734     struct dm_dev *cow;
735     @@ -106,8 +105,8 @@ struct dm_snapshot {
736     /* The on disk metadata handler */
737     struct dm_exception_store *store;
738    
739     - /* Maximum number of in-flight COW jobs. */
740     - struct semaphore cow_count;
741     + unsigned in_progress;
742     + wait_queue_head_t in_progress_wait;
743    
744     struct dm_kcopyd_client *kcopyd_client;
745    
746     @@ -158,8 +157,8 @@ struct dm_snapshot {
747     */
748     #define DEFAULT_COW_THRESHOLD 2048
749    
750     -static int cow_threshold = DEFAULT_COW_THRESHOLD;
751     -module_param_named(snapshot_cow_threshold, cow_threshold, int, 0644);
752     +static unsigned cow_threshold = DEFAULT_COW_THRESHOLD;
753     +module_param_named(snapshot_cow_threshold, cow_threshold, uint, 0644);
754     MODULE_PARM_DESC(snapshot_cow_threshold, "Maximum number of chunks being copied on write");
755    
756     DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(snapshot_copy_throttle,
757     @@ -456,9 +455,9 @@ static int __find_snapshots_sharing_cow(struct dm_snapshot *snap,
758     if (!bdev_equal(s->cow->bdev, snap->cow->bdev))
759     continue;
760    
761     - down_read(&s->lock);
762     + mutex_lock(&s->lock);
763     active = s->active;
764     - up_read(&s->lock);
765     + mutex_unlock(&s->lock);
766    
767     if (active) {
768     if (snap_src)
769     @@ -926,7 +925,7 @@ static int remove_single_exception_chunk(struct dm_snapshot *s)
770     int r;
771     chunk_t old_chunk = s->first_merging_chunk + s->num_merging_chunks - 1;
772    
773     - down_write(&s->lock);
774     + mutex_lock(&s->lock);
775    
776     /*
777     * Process chunks (and associated exceptions) in reverse order
778     @@ -941,7 +940,7 @@ static int remove_single_exception_chunk(struct dm_snapshot *s)
779     b = __release_queued_bios_after_merge(s);
780    
781     out:
782     - up_write(&s->lock);
783     + mutex_unlock(&s->lock);
784     if (b)
785     flush_bios(b);
786    
787     @@ -1000,9 +999,9 @@ static void snapshot_merge_next_chunks(struct dm_snapshot *s)
788     if (linear_chunks < 0) {
789     DMERR("Read error in exception store: "
790     "shutting down merge");
791     - down_write(&s->lock);
792     + mutex_lock(&s->lock);
793     s->merge_failed = 1;
794     - up_write(&s->lock);
795     + mutex_unlock(&s->lock);
796     }
797     goto shut;
798     }
799     @@ -1043,10 +1042,10 @@ static void snapshot_merge_next_chunks(struct dm_snapshot *s)
800     previous_count = read_pending_exceptions_done_count();
801     }
802    
803     - down_write(&s->lock);
804     + mutex_lock(&s->lock);
805     s->first_merging_chunk = old_chunk;
806     s->num_merging_chunks = linear_chunks;
807     - up_write(&s->lock);
808     + mutex_unlock(&s->lock);
809    
810     /* Wait until writes to all 'linear_chunks' drain */
811     for (i = 0; i < linear_chunks; i++)
812     @@ -1088,10 +1087,10 @@ static void merge_callback(int read_err, unsigned long write_err, void *context)
813     return;
814    
815     shut:
816     - down_write(&s->lock);
817     + mutex_lock(&s->lock);
818     s->merge_failed = 1;
819     b = __release_queued_bios_after_merge(s);
820     - up_write(&s->lock);
821     + mutex_unlock(&s->lock);
822     error_bios(b);
823    
824     merge_shutdown(s);
825     @@ -1137,7 +1136,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
826     origin_mode = FMODE_WRITE;
827     }
828    
829     - s = kmalloc(sizeof(*s), GFP_KERNEL);
830     + s = kzalloc(sizeof(*s), GFP_KERNEL);
831     if (!s) {
832     ti->error = "Cannot allocate private snapshot structure";
833     r = -ENOMEM;
834     @@ -1190,7 +1189,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
835     s->exception_start_sequence = 0;
836     s->exception_complete_sequence = 0;
837     INIT_LIST_HEAD(&s->out_of_order_list);
838     - init_rwsem(&s->lock);
839     + mutex_init(&s->lock);
840     INIT_LIST_HEAD(&s->list);
841     spin_lock_init(&s->pe_lock);
842     s->state_bits = 0;
843     @@ -1206,7 +1205,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
844     goto bad_hash_tables;
845     }
846    
847     - sema_init(&s->cow_count, (cow_threshold > 0) ? cow_threshold : INT_MAX);
848     + init_waitqueue_head(&s->in_progress_wait);
849    
850     s->kcopyd_client = dm_kcopyd_client_create(&dm_kcopyd_throttle);
851     if (IS_ERR(s->kcopyd_client)) {
852     @@ -1357,9 +1356,9 @@ static void snapshot_dtr(struct dm_target *ti)
853     /* Check whether exception handover must be cancelled */
854     (void) __find_snapshots_sharing_cow(s, &snap_src, &snap_dest, NULL);
855     if (snap_src && snap_dest && (s == snap_src)) {
856     - down_write(&snap_dest->lock);
857     + mutex_lock(&snap_dest->lock);
858     snap_dest->valid = 0;
859     - up_write(&snap_dest->lock);
860     + mutex_unlock(&snap_dest->lock);
861     DMERR("Cancelling snapshot handover.");
862     }
863     up_read(&_origins_lock);
864     @@ -1390,13 +1389,62 @@ static void snapshot_dtr(struct dm_target *ti)
865    
866     dm_exception_store_destroy(s->store);
867    
868     + mutex_destroy(&s->lock);
869     +
870     dm_put_device(ti, s->cow);
871    
872     dm_put_device(ti, s->origin);
873    
874     + WARN_ON(s->in_progress);
875     +
876     kfree(s);
877     }
878    
879     +static void account_start_copy(struct dm_snapshot *s)
880     +{
881     + spin_lock(&s->in_progress_wait.lock);
882     + s->in_progress++;
883     + spin_unlock(&s->in_progress_wait.lock);
884     +}
885     +
886     +static void account_end_copy(struct dm_snapshot *s)
887     +{
888     + spin_lock(&s->in_progress_wait.lock);
889     + BUG_ON(!s->in_progress);
890     + s->in_progress--;
891     + if (likely(s->in_progress <= cow_threshold) &&
892     + unlikely(waitqueue_active(&s->in_progress_wait)))
893     + wake_up_locked(&s->in_progress_wait);
894     + spin_unlock(&s->in_progress_wait.lock);
895     +}
896     +
897     +static bool wait_for_in_progress(struct dm_snapshot *s, bool unlock_origins)
898     +{
899     + if (unlikely(s->in_progress > cow_threshold)) {
900     + spin_lock(&s->in_progress_wait.lock);
901     + if (likely(s->in_progress > cow_threshold)) {
902     + /*
903     + * NOTE: this throttle doesn't account for whether
904     + * the caller is servicing an IO that will trigger a COW
905     + * so excess throttling may result for chunks not required
906     + * to be COW'd. But if cow_threshold was reached, extra
907     + * throttling is unlikely to negatively impact performance.
908     + */
909     + DECLARE_WAITQUEUE(wait, current);
910     + __add_wait_queue(&s->in_progress_wait, &wait);
911     + __set_current_state(TASK_UNINTERRUPTIBLE);
912     + spin_unlock(&s->in_progress_wait.lock);
913     + if (unlock_origins)
914     + up_read(&_origins_lock);
915     + io_schedule();
916     + remove_wait_queue(&s->in_progress_wait, &wait);
917     + return false;
918     + }
919     + spin_unlock(&s->in_progress_wait.lock);
920     + }
921     + return true;
922     +}
923     +
924     /*
925     * Flush a list of buffers.
926     */
927     @@ -1412,7 +1460,7 @@ static void flush_bios(struct bio *bio)
928     }
929     }
930    
931     -static int do_origin(struct dm_dev *origin, struct bio *bio);
932     +static int do_origin(struct dm_dev *origin, struct bio *bio, bool limit);
933    
934     /*
935     * Flush a list of buffers.
936     @@ -1425,7 +1473,7 @@ static void retry_origin_bios(struct dm_snapshot *s, struct bio *bio)
937     while (bio) {
938     n = bio->bi_next;
939     bio->bi_next = NULL;
940     - r = do_origin(s->origin, bio);
941     + r = do_origin(s->origin, bio, false);
942     if (r == DM_MAPIO_REMAPPED)
943     generic_make_request(bio);
944     bio = n;
945     @@ -1477,7 +1525,7 @@ static void pending_complete(void *context, int success)
946    
947     if (!success) {
948     /* Read/write error - snapshot is unusable */
949     - down_write(&s->lock);
950     + mutex_lock(&s->lock);
951     __invalidate_snapshot(s, -EIO);
952     error = 1;
953     goto out;
954     @@ -1485,14 +1533,14 @@ static void pending_complete(void *context, int success)
955    
956     e = alloc_completed_exception(GFP_NOIO);
957     if (!e) {
958     - down_write(&s->lock);
959     + mutex_lock(&s->lock);
960     __invalidate_snapshot(s, -ENOMEM);
961     error = 1;
962     goto out;
963     }
964     *e = pe->e;
965    
966     - down_write(&s->lock);
967     + mutex_lock(&s->lock);
968     if (!s->valid) {
969     free_completed_exception(e);
970     error = 1;
971     @@ -1517,7 +1565,7 @@ out:
972     full_bio->bi_end_io = pe->full_bio_end_io;
973     increment_pending_exceptions_done_count();
974    
975     - up_write(&s->lock);
976     + mutex_unlock(&s->lock);
977    
978     /* Submit any pending write bios */
979     if (error) {
980     @@ -1579,7 +1627,7 @@ static void copy_callback(int read_err, unsigned long write_err, void *context)
981     }
982     list_add(&pe->out_of_order_entry, lh);
983     }
984     - up(&s->cow_count);
985     + account_end_copy(s);
986     }
987    
988     /*
989     @@ -1603,7 +1651,7 @@ static void start_copy(struct dm_snap_pending_exception *pe)
990     dest.count = src.count;
991    
992     /* Hand over to kcopyd */
993     - down(&s->cow_count);
994     + account_start_copy(s);
995     dm_kcopyd_copy(s->kcopyd_client, &src, 1, &dest, 0, copy_callback, pe);
996     }
997    
998     @@ -1623,7 +1671,7 @@ static void start_full_bio(struct dm_snap_pending_exception *pe,
999     pe->full_bio = bio;
1000     pe->full_bio_end_io = bio->bi_end_io;
1001    
1002     - down(&s->cow_count);
1003     + account_start_copy(s);
1004     callback_data = dm_kcopyd_prepare_callback(s->kcopyd_client,
1005     copy_callback, pe);
1006    
1007     @@ -1714,9 +1762,12 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
1008     if (!s->valid)
1009     return -EIO;
1010    
1011     - /* FIXME: should only take write lock if we need
1012     - * to copy an exception */
1013     - down_write(&s->lock);
1014     + if (bio_data_dir(bio) == WRITE) {
1015     + while (unlikely(!wait_for_in_progress(s, false)))
1016     + ; /* wait_for_in_progress() has slept */
1017     + }
1018     +
1019     + mutex_lock(&s->lock);
1020    
1021     if (!s->valid || (unlikely(s->snapshot_overflowed) &&
1022     bio_data_dir(bio) == WRITE)) {
1023     @@ -1739,9 +1790,9 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
1024     if (bio_data_dir(bio) == WRITE) {
1025     pe = __lookup_pending_exception(s, chunk);
1026     if (!pe) {
1027     - up_write(&s->lock);
1028     + mutex_unlock(&s->lock);
1029     pe = alloc_pending_exception(s);
1030     - down_write(&s->lock);
1031     + mutex_lock(&s->lock);
1032    
1033     if (!s->valid || s->snapshot_overflowed) {
1034     free_pending_exception(pe);
1035     @@ -1776,7 +1827,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
1036     bio->bi_iter.bi_size ==
1037     (s->store->chunk_size << SECTOR_SHIFT)) {
1038     pe->started = 1;
1039     - up_write(&s->lock);
1040     + mutex_unlock(&s->lock);
1041     start_full_bio(pe, bio);
1042     goto out;
1043     }
1044     @@ -1786,7 +1837,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
1045     if (!pe->started) {
1046     /* this is protected by snap->lock */
1047     pe->started = 1;
1048     - up_write(&s->lock);
1049     + mutex_unlock(&s->lock);
1050     start_copy(pe);
1051     goto out;
1052     }
1053     @@ -1796,7 +1847,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
1054     }
1055    
1056     out_unlock:
1057     - up_write(&s->lock);
1058     + mutex_unlock(&s->lock);
1059     out:
1060     return r;
1061     }
1062     @@ -1832,7 +1883,7 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio)
1063    
1064     chunk = sector_to_chunk(s->store, bio->bi_iter.bi_sector);
1065    
1066     - down_write(&s->lock);
1067     + mutex_lock(&s->lock);
1068    
1069     /* Full merging snapshots are redirected to the origin */
1070     if (!s->valid)
1071     @@ -1863,12 +1914,12 @@ redirect_to_origin:
1072     bio->bi_bdev = s->origin->bdev;
1073    
1074     if (bio_data_dir(bio) == WRITE) {
1075     - up_write(&s->lock);
1076     - return do_origin(s->origin, bio);
1077     + mutex_unlock(&s->lock);
1078     + return do_origin(s->origin, bio, false);
1079     }
1080    
1081     out_unlock:
1082     - up_write(&s->lock);
1083     + mutex_unlock(&s->lock);
1084    
1085     return r;
1086     }
1087     @@ -1899,7 +1950,7 @@ static int snapshot_preresume(struct dm_target *ti)
1088     down_read(&_origins_lock);
1089     (void) __find_snapshots_sharing_cow(s, &snap_src, &snap_dest, NULL);
1090     if (snap_src && snap_dest) {
1091     - down_read(&snap_src->lock);
1092     + mutex_lock(&snap_src->lock);
1093     if (s == snap_src) {
1094     DMERR("Unable to resume snapshot source until "
1095     "handover completes.");
1096     @@ -1909,7 +1960,7 @@ static int snapshot_preresume(struct dm_target *ti)
1097     "source is suspended.");
1098     r = -EINVAL;
1099     }
1100     - up_read(&snap_src->lock);
1101     + mutex_unlock(&snap_src->lock);
1102     }
1103     up_read(&_origins_lock);
1104    
1105     @@ -1955,11 +2006,11 @@ static void snapshot_resume(struct dm_target *ti)
1106    
1107     (void) __find_snapshots_sharing_cow(s, &snap_src, &snap_dest, NULL);
1108     if (snap_src && snap_dest) {
1109     - down_write(&snap_src->lock);
1110     - down_write_nested(&snap_dest->lock, SINGLE_DEPTH_NESTING);
1111     + mutex_lock(&snap_src->lock);
1112     + mutex_lock_nested(&snap_dest->lock, SINGLE_DEPTH_NESTING);
1113     __handover_exceptions(snap_src, snap_dest);
1114     - up_write(&snap_dest->lock);
1115     - up_write(&snap_src->lock);
1116     + mutex_unlock(&snap_dest->lock);
1117     + mutex_unlock(&snap_src->lock);
1118     }
1119    
1120     up_read(&_origins_lock);
1121     @@ -1974,9 +2025,9 @@ static void snapshot_resume(struct dm_target *ti)
1122     /* Now we have correct chunk size, reregister */
1123     reregister_snapshot(s);
1124    
1125     - down_write(&s->lock);
1126     + mutex_lock(&s->lock);
1127     s->active = 1;
1128     - up_write(&s->lock);
1129     + mutex_unlock(&s->lock);
1130     }
1131    
1132     static uint32_t get_origin_minimum_chunksize(struct block_device *bdev)
1133     @@ -2016,7 +2067,7 @@ static void snapshot_status(struct dm_target *ti, status_type_t type,
1134     switch (type) {
1135     case STATUSTYPE_INFO:
1136    
1137     - down_write(&snap->lock);
1138     + mutex_lock(&snap->lock);
1139    
1140     if (!snap->valid)
1141     DMEMIT("Invalid");
1142     @@ -2041,7 +2092,7 @@ static void snapshot_status(struct dm_target *ti, status_type_t type,
1143     DMEMIT("Unknown");
1144     }
1145    
1146     - up_write(&snap->lock);
1147     + mutex_unlock(&snap->lock);
1148    
1149     break;
1150    
1151     @@ -2107,7 +2158,7 @@ static int __origin_write(struct list_head *snapshots, sector_t sector,
1152     if (dm_target_is_snapshot_merge(snap->ti))
1153     continue;
1154    
1155     - down_write(&snap->lock);
1156     + mutex_lock(&snap->lock);
1157    
1158     /* Only deal with valid and active snapshots */
1159     if (!snap->valid || !snap->active)
1160     @@ -2134,9 +2185,9 @@ static int __origin_write(struct list_head *snapshots, sector_t sector,
1161    
1162     pe = __lookup_pending_exception(snap, chunk);
1163     if (!pe) {
1164     - up_write(&snap->lock);
1165     + mutex_unlock(&snap->lock);
1166     pe = alloc_pending_exception(snap);
1167     - down_write(&snap->lock);
1168     + mutex_lock(&snap->lock);
1169    
1170     if (!snap->valid) {
1171     free_pending_exception(pe);
1172     @@ -2179,7 +2230,7 @@ static int __origin_write(struct list_head *snapshots, sector_t sector,
1173     }
1174    
1175     next_snapshot:
1176     - up_write(&snap->lock);
1177     + mutex_unlock(&snap->lock);
1178    
1179     if (pe_to_start_now) {
1180     start_copy(pe_to_start_now);
1181     @@ -2200,15 +2251,24 @@ next_snapshot:
1182     /*
1183     * Called on a write from the origin driver.
1184     */
1185     -static int do_origin(struct dm_dev *origin, struct bio *bio)
1186     +static int do_origin(struct dm_dev *origin, struct bio *bio, bool limit)
1187     {
1188     struct origin *o;
1189     int r = DM_MAPIO_REMAPPED;
1190    
1191     +again:
1192     down_read(&_origins_lock);
1193     o = __lookup_origin(origin->bdev);
1194     - if (o)
1195     + if (o) {
1196     + if (limit) {
1197     + struct dm_snapshot *s;
1198     + list_for_each_entry(s, &o->snapshots, list)
1199     + if (unlikely(!wait_for_in_progress(s, true)))
1200     + goto again;
1201     + }
1202     +
1203     r = __origin_write(&o->snapshots, bio->bi_iter.bi_sector, bio);
1204     + }
1205     up_read(&_origins_lock);
1206    
1207     return r;
1208     @@ -2321,7 +2381,7 @@ static int origin_map(struct dm_target *ti, struct bio *bio)
1209     dm_accept_partial_bio(bio, available_sectors);
1210    
1211     /* Only tell snapshots if this is a write */
1212     - return do_origin(o->dev, bio);
1213     + return do_origin(o->dev, bio, true);
1214     }
1215    
1216     static long origin_direct_access(struct dm_target *ti, sector_t sector,
1217     diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
1218     index 23a7e108352a..dcb753dbf86e 100644
1219     --- a/drivers/md/dm-thin.c
1220     +++ b/drivers/md/dm-thin.c
1221     @@ -2965,7 +2965,7 @@ static struct pool *pool_create(struct mapped_device *pool_md,
1222     return (struct pool *)pmd;
1223     }
1224    
1225     - pool = kmalloc(sizeof(*pool), GFP_KERNEL);
1226     + pool = kzalloc(sizeof(*pool), GFP_KERNEL);
1227     if (!pool) {
1228     *error = "Error allocating memory for pool";
1229     err_p = ERR_PTR(-ENOMEM);
1230     diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
1231     index 8820fb1aec5b..c1971bca62fb 100644
1232     --- a/drivers/net/bonding/bond_main.c
1233     +++ b/drivers/net/bonding/bond_main.c
1234     @@ -3963,7 +3963,7 @@ out:
1235     * this to-be-skipped slave to send a packet out.
1236     */
1237     old_arr = rtnl_dereference(bond->slave_arr);
1238     - for (idx = 0; idx < old_arr->count; idx++) {
1239     + for (idx = 0; old_arr != NULL && idx < old_arr->count; idx++) {
1240     if (skipslave == old_arr->arr[idx]) {
1241     old_arr->arr[idx] =
1242     old_arr->arr[old_arr->count-1];
1243     diff --git a/drivers/net/usb/sr9800.c b/drivers/net/usb/sr9800.c
1244     index 004c955c1fd1..da0ae16f5c74 100644
1245     --- a/drivers/net/usb/sr9800.c
1246     +++ b/drivers/net/usb/sr9800.c
1247     @@ -336,7 +336,7 @@ static void sr_set_multicast(struct net_device *net)
1248     static int sr_mdio_read(struct net_device *net, int phy_id, int loc)
1249     {
1250     struct usbnet *dev = netdev_priv(net);
1251     - __le16 res;
1252     + __le16 res = 0;
1253    
1254     mutex_lock(&dev->phy_mutex);
1255     sr_set_sw_mii(dev);
1256     diff --git a/drivers/net/wireless/ath/ath6kl/usb.c b/drivers/net/wireless/ath/ath6kl/usb.c
1257     index 9da3594fd010..fc22c5f47927 100644
1258     --- a/drivers/net/wireless/ath/ath6kl/usb.c
1259     +++ b/drivers/net/wireless/ath/ath6kl/usb.c
1260     @@ -132,6 +132,10 @@ ath6kl_usb_alloc_urb_from_pipe(struct ath6kl_usb_pipe *pipe)
1261     struct ath6kl_urb_context *urb_context = NULL;
1262     unsigned long flags;
1263    
1264     + /* bail if this pipe is not initialized */
1265     + if (!pipe->ar_usb)
1266     + return NULL;
1267     +
1268     spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
1269     if (!list_empty(&pipe->urb_list_head)) {
1270     urb_context =
1271     @@ -150,6 +154,10 @@ static void ath6kl_usb_free_urb_to_pipe(struct ath6kl_usb_pipe *pipe,
1272     {
1273     unsigned long flags;
1274    
1275     + /* bail if this pipe is not initialized */
1276     + if (!pipe->ar_usb)
1277     + return;
1278     +
1279     spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
1280     pipe->urb_cnt++;
1281    
1282     diff --git a/drivers/net/wireless/realtek/rtlwifi/ps.c b/drivers/net/wireless/realtek/rtlwifi/ps.c
1283     index d0ffc4d508cf..e8963dd2977c 100644
1284     --- a/drivers/net/wireless/realtek/rtlwifi/ps.c
1285     +++ b/drivers/net/wireless/realtek/rtlwifi/ps.c
1286     @@ -770,6 +770,9 @@ static void rtl_p2p_noa_ie(struct ieee80211_hw *hw, void *data,
1287     return;
1288     } else {
1289     noa_num = (noa_len - 2) / 13;
1290     + if (noa_num > P2P_MAX_NOA_NUM)
1291     + noa_num = P2P_MAX_NOA_NUM;
1292     +
1293     }
1294     noa_index = ie[3];
1295     if (rtlpriv->psc.p2p_ps_info.p2p_ps_mode ==
1296     @@ -864,6 +867,9 @@ static void rtl_p2p_action_ie(struct ieee80211_hw *hw, void *data,
1297     return;
1298     } else {
1299     noa_num = (noa_len - 2) / 13;
1300     + if (noa_num > P2P_MAX_NOA_NUM)
1301     + noa_num = P2P_MAX_NOA_NUM;
1302     +
1303     }
1304     noa_index = ie[3];
1305     if (rtlpriv->psc.p2p_ps_info.p2p_ps_mode ==
1306     diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
1307     index 3c8c6f942e67..a06792966ea9 100644
1308     --- a/drivers/rtc/rtc-pcf8523.c
1309     +++ b/drivers/rtc/rtc-pcf8523.c
1310     @@ -94,8 +94,9 @@ static int pcf8523_voltage_low(struct i2c_client *client)
1311     return !!(value & REG_CONTROL3_BLF);
1312     }
1313    
1314     -static int pcf8523_select_capacitance(struct i2c_client *client, bool high)
1315     +static int pcf8523_load_capacitance(struct i2c_client *client)
1316     {
1317     + u32 load;
1318     u8 value;
1319     int err;
1320    
1321     @@ -103,14 +104,24 @@ static int pcf8523_select_capacitance(struct i2c_client *client, bool high)
1322     if (err < 0)
1323     return err;
1324    
1325     - if (!high)
1326     - value &= ~REG_CONTROL1_CAP_SEL;
1327     - else
1328     + load = 12500;
1329     + of_property_read_u32(client->dev.of_node, "quartz-load-femtofarads",
1330     + &load);
1331     +
1332     + switch (load) {
1333     + default:
1334     + dev_warn(&client->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 12500",
1335     + load);
1336     + /* fall through */
1337     + case 12500:
1338     value |= REG_CONTROL1_CAP_SEL;
1339     + break;
1340     + case 7000:
1341     + value &= ~REG_CONTROL1_CAP_SEL;
1342     + break;
1343     + }
1344    
1345     err = pcf8523_write(client, REG_CONTROL1, value);
1346     - if (err < 0)
1347     - return err;
1348    
1349     return err;
1350     }
1351     @@ -307,9 +318,10 @@ static int pcf8523_probe(struct i2c_client *client,
1352     if (!pcf)
1353     return -ENOMEM;
1354    
1355     - err = pcf8523_select_capacitance(client, true);
1356     + err = pcf8523_load_capacitance(client);
1357     if (err < 0)
1358     - return err;
1359     + dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
1360     + err);
1361    
1362     err = pcf8523_set_pm(client, 0);
1363     if (err < 0)
1364     diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
1365     index d22360849b88..d4a7d740fc62 100644
1366     --- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
1367     +++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
1368     @@ -366,8 +366,10 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
1369     }
1370    
1371     padapter->HalData = kzalloc(sizeof(struct hal_data_8188e), GFP_KERNEL);
1372     - if (!padapter->HalData)
1373     - DBG_88E("cant not alloc memory for HAL DATA\n");
1374     + if (!padapter->HalData) {
1375     + DBG_88E("Failed to allocate memory for HAL data\n");
1376     + goto free_adapter;
1377     + }
1378    
1379     padapter->intf_start = &usb_intf_start;
1380     padapter->intf_stop = &usb_intf_stop;
1381     diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
1382     index cba6bc6ab9ed..c963593eedbe 100644
1383     --- a/drivers/thunderbolt/nhi.c
1384     +++ b/drivers/thunderbolt/nhi.c
1385     @@ -95,9 +95,20 @@ static void __iomem *ring_options_base(struct tb_ring *ring)
1386     return io;
1387     }
1388    
1389     -static void ring_iowrite16desc(struct tb_ring *ring, u32 value, u32 offset)
1390     +static void ring_iowrite_cons(struct tb_ring *ring, u16 cons)
1391     {
1392     - iowrite16(value, ring_desc_base(ring) + offset);
1393     + /*
1394     + * The other 16-bits in the register is read-only and writes to it
1395     + * are ignored by the hardware so we can save one ioread32() by
1396     + * filling the read-only bits with zeroes.
1397     + */
1398     + iowrite32(cons, ring_desc_base(ring) + 8);
1399     +}
1400     +
1401     +static void ring_iowrite_prod(struct tb_ring *ring, u16 prod)
1402     +{
1403     + /* See ring_iowrite_cons() above for explanation */
1404     + iowrite32(prod << 16, ring_desc_base(ring) + 8);
1405     }
1406    
1407     static void ring_iowrite32desc(struct tb_ring *ring, u32 value, u32 offset)
1408     @@ -149,7 +160,10 @@ static void ring_write_descriptors(struct tb_ring *ring)
1409     descriptor->sof = frame->sof;
1410     }
1411     ring->head = (ring->head + 1) % ring->size;
1412     - ring_iowrite16desc(ring, ring->head, ring->is_tx ? 10 : 8);
1413     + if (ring->is_tx)
1414     + ring_iowrite_prod(ring, ring->head);
1415     + else
1416     + ring_iowrite_cons(ring, ring->head);
1417     }
1418     }
1419    
1420     @@ -369,7 +383,7 @@ void ring_stop(struct tb_ring *ring)
1421    
1422     ring_iowrite32options(ring, 0, 0);
1423     ring_iowrite64desc(ring, 0, 0);
1424     - ring_iowrite16desc(ring, 0, ring->is_tx ? 10 : 8);
1425     + ring_iowrite32desc(ring, 0, 8);
1426     ring_iowrite32desc(ring, 0, 12);
1427     ring->head = 0;
1428     ring->tail = 0;
1429     diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
1430     index 82451bb6622b..f80a88d107d7 100644
1431     --- a/drivers/tty/serial/sc16is7xx.c
1432     +++ b/drivers/tty/serial/sc16is7xx.c
1433     @@ -332,6 +332,7 @@ struct sc16is7xx_port {
1434     struct kthread_worker kworker;
1435     struct task_struct *kworker_task;
1436     struct kthread_work irq_work;
1437     + struct mutex efr_lock;
1438     struct sc16is7xx_one p[0];
1439     };
1440    
1441     @@ -503,6 +504,21 @@ static int sc16is7xx_set_baud(struct uart_port *port, int baud)
1442     div /= 4;
1443     }
1444    
1445     + /* In an amazing feat of design, the Enhanced Features Register shares
1446     + * the address of the Interrupt Identification Register, and is
1447     + * switched in by writing a magic value (0xbf) to the Line Control
1448     + * Register. Any interrupt firing during this time will see the EFR
1449     + * where it expects the IIR to be, leading to "Unexpected interrupt"
1450     + * messages.
1451     + *
1452     + * Prevent this possibility by claiming a mutex while accessing the
1453     + * EFR, and claiming the same mutex from within the interrupt handler.
1454     + * This is similar to disabling the interrupt, but that doesn't work
1455     + * because the bulk of the interrupt processing is run as a workqueue
1456     + * job in thread context.
1457     + */
1458     + mutex_lock(&s->efr_lock);
1459     +
1460     lcr = sc16is7xx_port_read(port, SC16IS7XX_LCR_REG);
1461    
1462     /* Open the LCR divisors for configuration */
1463     @@ -518,6 +534,8 @@ static int sc16is7xx_set_baud(struct uart_port *port, int baud)
1464     /* Put LCR back to the normal mode */
1465     sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, lcr);
1466    
1467     + mutex_unlock(&s->efr_lock);
1468     +
1469     sc16is7xx_port_update(port, SC16IS7XX_MCR_REG,
1470     SC16IS7XX_MCR_CLKSEL_BIT,
1471     prescaler);
1472     @@ -700,6 +718,8 @@ static void sc16is7xx_ist(struct kthread_work *ws)
1473     {
1474     struct sc16is7xx_port *s = to_sc16is7xx_port(ws, irq_work);
1475    
1476     + mutex_lock(&s->efr_lock);
1477     +
1478     while (1) {
1479     bool keep_polling = false;
1480     int i;
1481     @@ -709,6 +729,8 @@ static void sc16is7xx_ist(struct kthread_work *ws)
1482     if (!keep_polling)
1483     break;
1484     }
1485     +
1486     + mutex_unlock(&s->efr_lock);
1487     }
1488    
1489     static irqreturn_t sc16is7xx_irq(int irq, void *dev_id)
1490     @@ -903,6 +925,9 @@ static void sc16is7xx_set_termios(struct uart_port *port,
1491     if (!(termios->c_cflag & CREAD))
1492     port->ignore_status_mask |= SC16IS7XX_LSR_BRK_ERROR_MASK;
1493    
1494     + /* As above, claim the mutex while accessing the EFR. */
1495     + mutex_lock(&s->efr_lock);
1496     +
1497     sc16is7xx_port_write(port, SC16IS7XX_LCR_REG,
1498     SC16IS7XX_LCR_CONF_MODE_B);
1499    
1500     @@ -924,6 +949,8 @@ static void sc16is7xx_set_termios(struct uart_port *port,
1501     /* Update LCR register */
1502     sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, lcr);
1503    
1504     + mutex_unlock(&s->efr_lock);
1505     +
1506     /* Get baud rate generator configuration */
1507     baud = uart_get_baud_rate(port, termios, old,
1508     port->uartclk / 16 / 4 / 0xffff,
1509     @@ -1186,6 +1213,7 @@ static int sc16is7xx_probe(struct device *dev,
1510     s->regmap = regmap;
1511     s->devtype = devtype;
1512     dev_set_drvdata(dev, s);
1513     + mutex_init(&s->efr_lock);
1514    
1515     kthread_init_worker(&s->kworker);
1516     kthread_init_work(&s->irq_work, sc16is7xx_ist);
1517     diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
1518     index d2da6aa7f27d..1bb15edcf1e7 100644
1519     --- a/drivers/tty/serial/serial_mctrl_gpio.c
1520     +++ b/drivers/tty/serial/serial_mctrl_gpio.c
1521     @@ -68,6 +68,9 @@ EXPORT_SYMBOL_GPL(mctrl_gpio_set);
1522     struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
1523     enum mctrl_gpio_idx gidx)
1524     {
1525     + if (gpios == NULL)
1526     + return NULL;
1527     +
1528     return gpios->gpio[gidx];
1529     }
1530     EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod);
1531     diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
1532     index 63646dc3ca27..4a87cc478340 100644
1533     --- a/drivers/usb/core/hub.c
1534     +++ b/drivers/usb/core/hub.c
1535     @@ -102,6 +102,8 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem);
1536     static void hub_release(struct kref *kref);
1537     static int usb_reset_and_verify_device(struct usb_device *udev);
1538     static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
1539     +static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
1540     + u16 portstatus);
1541    
1542     static inline char *portspeed(struct usb_hub *hub, int portstatus)
1543     {
1544     @@ -1108,6 +1110,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1545     USB_PORT_FEAT_ENABLE);
1546     }
1547    
1548     + /* Make sure a warm-reset request is handled by port_event */
1549     + if (type == HUB_RESUME &&
1550     + hub_port_warm_reset_required(hub, port1, portstatus))
1551     + set_bit(port1, hub->event_bits);
1552     +
1553     /*
1554     * Add debounce if USB3 link is in polling/link training state.
1555     * Link will automatically transition to Enabled state after
1556     diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
1557     index 139f6cce30b1..95e28ecfde0a 100644
1558     --- a/drivers/usb/gadget/udc/core.c
1559     +++ b/drivers/usb/gadget/udc/core.c
1560     @@ -106,6 +106,17 @@ int usb_ep_enable(struct usb_ep *ep)
1561     if (ep->enabled)
1562     goto out;
1563    
1564     + /* UDC drivers can't handle endpoints with maxpacket size 0 */
1565     + if (usb_endpoint_maxp(ep->desc) == 0) {
1566     + /*
1567     + * We should log an error message here, but we can't call
1568     + * dev_err() because there's no way to find the gadget
1569     + * given only ep.
1570     + */
1571     + ret = -EINVAL;
1572     + goto out;
1573     + }
1574     +
1575     ret = ep->ops->enable(ep, ep->desc);
1576     if (ret)
1577     goto out;
1578     diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
1579     index 52e28b4913ad..0f0cdb7b7bf8 100644
1580     --- a/drivers/usb/misc/ldusb.c
1581     +++ b/drivers/usb/misc/ldusb.c
1582     @@ -499,11 +499,11 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
1583     retval = -EFAULT;
1584     goto unlock_exit;
1585     }
1586     - dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size;
1587     -
1588     retval = bytes_to_read;
1589    
1590     spin_lock_irq(&dev->rbsl);
1591     + dev->ring_tail = (dev->ring_tail + 1) % ring_buffer_size;
1592     +
1593     if (dev->buffer_overflow) {
1594     dev->buffer_overflow = 0;
1595     spin_unlock_irq(&dev->rbsl);
1596     @@ -584,7 +584,7 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
1597     1 << 8, 0,
1598     dev->interrupt_out_buffer,
1599     bytes_to_write,
1600     - USB_CTRL_SET_TIMEOUT * HZ);
1601     + USB_CTRL_SET_TIMEOUT);
1602     if (retval < 0)
1603     dev_err(&dev->intf->dev,
1604     "Couldn't submit HID_REQ_SET_REPORT %d\n",
1605     diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
1606     index f56307059d48..7cac3ee09b09 100644
1607     --- a/drivers/usb/misc/legousbtower.c
1608     +++ b/drivers/usb/misc/legousbtower.c
1609     @@ -898,7 +898,7 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
1610     get_version_reply,
1611     sizeof(*get_version_reply),
1612     1000);
1613     - if (result < sizeof(*get_version_reply)) {
1614     + if (result != sizeof(*get_version_reply)) {
1615     if (result >= 0)
1616     result = -EIO;
1617     dev_err(idev, "get version request failed: %d\n", result);
1618     diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
1619     index d3ea90bef84d..345211f1a491 100644
1620     --- a/drivers/usb/serial/whiteheat.c
1621     +++ b/drivers/usb/serial/whiteheat.c
1622     @@ -604,6 +604,10 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command,
1623    
1624     command_port = port->serial->port[COMMAND_PORT];
1625     command_info = usb_get_serial_port_data(command_port);
1626     +
1627     + if (command_port->bulk_out_size < datasize + 1)
1628     + return -EIO;
1629     +
1630     mutex_lock(&command_info->mutex);
1631     command_info->command_finished = false;
1632    
1633     @@ -677,6 +681,7 @@ static void firm_setup_port(struct tty_struct *tty)
1634     struct device *dev = &port->dev;
1635     struct whiteheat_port_settings port_settings;
1636     unsigned int cflag = tty->termios.c_cflag;
1637     + speed_t baud;
1638    
1639     port_settings.port = port->port_number + 1;
1640    
1641     @@ -737,11 +742,13 @@ static void firm_setup_port(struct tty_struct *tty)
1642     dev_dbg(dev, "%s - XON = %2x, XOFF = %2x\n", __func__, port_settings.xon, port_settings.xoff);
1643    
1644     /* get the baud rate wanted */
1645     - port_settings.baud = tty_get_baud_rate(tty);
1646     - dev_dbg(dev, "%s - baud rate = %d\n", __func__, port_settings.baud);
1647     + baud = tty_get_baud_rate(tty);
1648     + port_settings.baud = cpu_to_le32(baud);
1649     + dev_dbg(dev, "%s - baud rate = %u\n", __func__, baud);
1650    
1651     /* fixme: should set validated settings */
1652     - tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud);
1653     + tty_encode_baud_rate(tty, baud, baud);
1654     +
1655     /* handle any settings that aren't specified in the tty structure */
1656     port_settings.lloop = 0;
1657    
1658     diff --git a/drivers/usb/serial/whiteheat.h b/drivers/usb/serial/whiteheat.h
1659     index 38065df4d2d8..30169c859a74 100644
1660     --- a/drivers/usb/serial/whiteheat.h
1661     +++ b/drivers/usb/serial/whiteheat.h
1662     @@ -91,7 +91,7 @@ struct whiteheat_simple {
1663    
1664     struct whiteheat_port_settings {
1665     __u8 port; /* port number (1 to N) */
1666     - __u32 baud; /* any value 7 - 460800, firmware calculates
1667     + __le32 baud; /* any value 7 - 460800, firmware calculates
1668     best fit; arrives little endian */
1669     __u8 bits; /* 5, 6, 7, or 8 */
1670     __u8 stop; /* 1 or 2, default 1 (2 = 1.5 if bits = 5) */
1671     diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
1672     index afb4b0bf47b3..fd5398efce41 100644
1673     --- a/drivers/usb/storage/scsiglue.c
1674     +++ b/drivers/usb/storage/scsiglue.c
1675     @@ -81,7 +81,6 @@ static const char* host_info(struct Scsi_Host *host)
1676     static int slave_alloc (struct scsi_device *sdev)
1677     {
1678     struct us_data *us = host_to_us(sdev->host);
1679     - int maxp;
1680    
1681     /*
1682     * Set the INQUIRY transfer length to 36. We don't use any of
1683     @@ -90,15 +89,6 @@ static int slave_alloc (struct scsi_device *sdev)
1684     */
1685     sdev->inquiry_len = 36;
1686    
1687     - /*
1688     - * USB has unusual scatter-gather requirements: the length of each
1689     - * scatterlist element except the last must be divisible by the
1690     - * Bulk maxpacket value. Fortunately this value is always a
1691     - * power of 2. Inform the block layer about this requirement.
1692     - */
1693     - maxp = usb_maxpacket(us->pusb_dev, us->recv_bulk_pipe, 0);
1694     - blk_queue_virt_boundary(sdev->request_queue, maxp - 1);
1695     -
1696     /*
1697     * Some host controllers may have alignment requirements.
1698     * We'll play it safe by requiring 512-byte alignment always.
1699     diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
1700     index 97621e5bdad7..597bc550034f 100644
1701     --- a/drivers/usb/storage/uas.c
1702     +++ b/drivers/usb/storage/uas.c
1703     @@ -796,29 +796,9 @@ static int uas_slave_alloc(struct scsi_device *sdev)
1704     {
1705     struct uas_dev_info *devinfo =
1706     (struct uas_dev_info *)sdev->host->hostdata;
1707     - int maxp;
1708    
1709     sdev->hostdata = devinfo;
1710    
1711     - /*
1712     - * We have two requirements here. We must satisfy the requirements
1713     - * of the physical HC and the demands of the protocol, as we
1714     - * definitely want no additional memory allocation in this path
1715     - * ruling out using bounce buffers.
1716     - *
1717     - * For a transmission on USB to continue we must never send
1718     - * a package that is smaller than maxpacket. Hence the length of each
1719     - * scatterlist element except the last must be divisible by the
1720     - * Bulk maxpacket value.
1721     - * If the HC does not ensure that through SG,
1722     - * the upper layer must do that. We must assume nothing
1723     - * about the capabilities off the HC, so we use the most
1724     - * pessimistic requirement.
1725     - */
1726     -
1727     - maxp = usb_maxpacket(devinfo->udev, devinfo->data_in_pipe, 0);
1728     - blk_queue_virt_boundary(sdev->request_queue, maxp - 1);
1729     -
1730     /*
1731     * The protocol has no requirements on alignment in the strict sense.
1732     * Controllers may or may not have alignment restrictions.
1733     diff --git a/fs/binfmt_script.c b/fs/binfmt_script.c
1734     index afdf4e3cafc2..37c2093a24d3 100644
1735     --- a/fs/binfmt_script.c
1736     +++ b/fs/binfmt_script.c
1737     @@ -14,14 +14,31 @@
1738     #include <linux/err.h>
1739     #include <linux/fs.h>
1740    
1741     +static inline bool spacetab(char c) { return c == ' ' || c == '\t'; }
1742     +static inline char *next_non_spacetab(char *first, const char *last)
1743     +{
1744     + for (; first <= last; first++)
1745     + if (!spacetab(*first))
1746     + return first;
1747     + return NULL;
1748     +}
1749     +static inline char *next_terminator(char *first, const char *last)
1750     +{
1751     + for (; first <= last; first++)
1752     + if (spacetab(*first) || !*first)
1753     + return first;
1754     + return NULL;
1755     +}
1756     +
1757     static int load_script(struct linux_binprm *bprm)
1758     {
1759     const char *i_arg, *i_name;
1760     - char *cp;
1761     + char *cp, *buf_end;
1762     struct file *file;
1763     char interp[BINPRM_BUF_SIZE];
1764     int retval;
1765    
1766     + /* Not ours to exec if we don't start with "#!". */
1767     if ((bprm->buf[0] != '#') || (bprm->buf[1] != '!'))
1768     return -ENOEXEC;
1769    
1770     @@ -34,18 +51,40 @@ static int load_script(struct linux_binprm *bprm)
1771     if (bprm->interp_flags & BINPRM_FLAGS_PATH_INACCESSIBLE)
1772     return -ENOENT;
1773    
1774     - /*
1775     - * This section does the #! interpretation.
1776     - * Sorta complicated, but hopefully it will work. -TYT
1777     - */
1778     -
1779     + /* Release since we are not mapping a binary into memory. */
1780     allow_write_access(bprm->file);
1781     fput(bprm->file);
1782     bprm->file = NULL;
1783    
1784     - bprm->buf[BINPRM_BUF_SIZE - 1] = '\0';
1785     - if ((cp = strchr(bprm->buf, '\n')) == NULL)
1786     - cp = bprm->buf+BINPRM_BUF_SIZE-1;
1787     + /*
1788     + * This section handles parsing the #! line into separate
1789     + * interpreter path and argument strings. We must be careful
1790     + * because bprm->buf is not yet guaranteed to be NUL-terminated
1791     + * (though the buffer will have trailing NUL padding when the
1792     + * file size was smaller than the buffer size).
1793     + *
1794     + * We do not want to exec a truncated interpreter path, so either
1795     + * we find a newline (which indicates nothing is truncated), or
1796     + * we find a space/tab/NUL after the interpreter path (which
1797     + * itself may be preceded by spaces/tabs). Truncating the
1798     + * arguments is fine: the interpreter can re-read the script to
1799     + * parse them on its own.
1800     + */
1801     + buf_end = bprm->buf + sizeof(bprm->buf) - 1;
1802     + cp = strnchr(bprm->buf, sizeof(bprm->buf), '\n');
1803     + if (!cp) {
1804     + cp = next_non_spacetab(bprm->buf + 2, buf_end);
1805     + if (!cp)
1806     + return -ENOEXEC; /* Entire buf is spaces/tabs */
1807     + /*
1808     + * If there is no later space/tab/NUL we must assume the
1809     + * interpreter path is truncated.
1810     + */
1811     + if (!next_terminator(cp, buf_end))
1812     + return -ENOEXEC;
1813     + cp = buf_end;
1814     + }
1815     + /* NUL-terminate the buffer and any trailing spaces/tabs. */
1816     *cp = '\0';
1817     while (cp > bprm->buf) {
1818     cp--;
1819     diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
1820     index cc88f4f0325e..bed973330227 100644
1821     --- a/fs/cifs/netmisc.c
1822     +++ b/fs/cifs/netmisc.c
1823     @@ -130,10 +130,6 @@ static const struct smb_to_posix_error mapping_table_ERRSRV[] = {
1824     {0, 0}
1825     };
1826    
1827     -static const struct smb_to_posix_error mapping_table_ERRHRD[] = {
1828     - {0, 0}
1829     -};
1830     -
1831     /*
1832     * Convert a string containing text IPv4 or IPv6 address to binary form.
1833     *
1834     diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
1835     index 60dd2bc10776..1d9fec9c714b 100644
1836     --- a/fs/fuse/dir.c
1837     +++ b/fs/fuse/dir.c
1838     @@ -1654,6 +1654,19 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1839     if (attr->ia_valid & ATTR_SIZE)
1840     is_truncate = true;
1841    
1842     + /* Flush dirty data/metadata before non-truncate SETATTR */
1843     + if (is_wb && S_ISREG(inode->i_mode) &&
1844     + attr->ia_valid &
1845     + (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_MTIME_SET |
1846     + ATTR_TIMES_SET)) {
1847     + err = write_inode_now(inode, true);
1848     + if (err)
1849     + return err;
1850     +
1851     + fuse_set_nowrite(inode);
1852     + fuse_release_nowrite(inode);
1853     + }
1854     +
1855     if (is_truncate) {
1856     fuse_set_nowrite(inode);
1857     set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1858     diff --git a/fs/fuse/file.c b/fs/fuse/file.c
1859     index 1b0e7b1039c1..92f905ea20b0 100644
1860     --- a/fs/fuse/file.c
1861     +++ b/fs/fuse/file.c
1862     @@ -201,7 +201,7 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
1863     {
1864     struct fuse_conn *fc = get_fuse_conn(inode);
1865     int err;
1866     - bool lock_inode = (file->f_flags & O_TRUNC) &&
1867     + bool is_wb_truncate = (file->f_flags & O_TRUNC) &&
1868     fc->atomic_o_trunc &&
1869     fc->writeback_cache;
1870    
1871     @@ -209,16 +209,20 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
1872     if (err)
1873     return err;
1874    
1875     - if (lock_inode)
1876     + if (is_wb_truncate) {
1877     inode_lock(inode);
1878     + fuse_set_nowrite(inode);
1879     + }
1880    
1881     err = fuse_do_open(fc, get_node_id(inode), file, isdir);
1882    
1883     if (!err)
1884     fuse_finish_open(inode, file);
1885    
1886     - if (lock_inode)
1887     + if (is_wb_truncate) {
1888     + fuse_release_nowrite(inode);
1889     inode_unlock(inode);
1890     + }
1891    
1892     return err;
1893     }
1894     diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
1895     index ea29c608be89..8354dfae7038 100644
1896     --- a/fs/nfs/nfs4proc.c
1897     +++ b/fs/nfs/nfs4proc.c
1898     @@ -5544,6 +5544,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
1899     }
1900     status = task->tk_status;
1901     if (setclientid.sc_cred) {
1902     + kfree(clp->cl_acceptor);
1903     clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred);
1904     put_rpccred(setclientid.sc_cred);
1905     }
1906     diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
1907     index c26d046adaaa..6ad76397b31d 100644
1908     --- a/fs/ocfs2/aops.c
1909     +++ b/fs/ocfs2/aops.c
1910     @@ -2046,7 +2046,8 @@ out_write_size:
1911     inode->i_mtime = inode->i_ctime = current_time(inode);
1912     di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
1913     di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
1914     - ocfs2_update_inode_fsync_trans(handle, inode, 1);
1915     + if (handle)
1916     + ocfs2_update_inode_fsync_trans(handle, inode, 1);
1917     }
1918     if (handle)
1919     ocfs2_journal_dirty(handle, wc->w_di_bh);
1920     @@ -2143,13 +2144,30 @@ static int ocfs2_dio_wr_get_block(struct inode *inode, sector_t iblock,
1921     struct ocfs2_dio_write_ctxt *dwc = NULL;
1922     struct buffer_head *di_bh = NULL;
1923     u64 p_blkno;
1924     - loff_t pos = iblock << inode->i_sb->s_blocksize_bits;
1925     + unsigned int i_blkbits = inode->i_sb->s_blocksize_bits;
1926     + loff_t pos = iblock << i_blkbits;
1927     + sector_t endblk = (i_size_read(inode) - 1) >> i_blkbits;
1928     unsigned len, total_len = bh_result->b_size;
1929     int ret = 0, first_get_block = 0;
1930    
1931     len = osb->s_clustersize - (pos & (osb->s_clustersize - 1));
1932     len = min(total_len, len);
1933    
1934     + /*
1935     + * bh_result->b_size is count in get_more_blocks according to write
1936     + * "pos" and "end", we need map twice to return different buffer state:
1937     + * 1. area in file size, not set NEW;
1938     + * 2. area out file size, set NEW.
1939     + *
1940     + * iblock endblk
1941     + * |--------|---------|---------|---------
1942     + * |<-------area in file------->|
1943     + */
1944     +
1945     + if ((iblock <= endblk) &&
1946     + ((iblock + ((len - 1) >> i_blkbits)) > endblk))
1947     + len = (endblk - iblock + 1) << i_blkbits;
1948     +
1949     mlog(0, "get block of %lu at %llu:%u req %u\n",
1950     inode->i_ino, pos, len, total_len);
1951    
1952     @@ -2233,6 +2251,9 @@ static int ocfs2_dio_wr_get_block(struct inode *inode, sector_t iblock,
1953     if (desc->c_needs_zero)
1954     set_buffer_new(bh_result);
1955    
1956     + if (iblock > endblk)
1957     + set_buffer_new(bh_result);
1958     +
1959     /* May sleep in end_io. It should not happen in a irq context. So defer
1960     * it to dio work queue. */
1961     set_buffer_defer_completion(bh_result);
1962     diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
1963     index 4506ec5ec2ea..bfc44644301c 100644
1964     --- a/fs/ocfs2/ioctl.c
1965     +++ b/fs/ocfs2/ioctl.c
1966     @@ -289,7 +289,7 @@ static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb,
1967     if (inode_alloc)
1968     inode_lock(inode_alloc);
1969    
1970     - if (o2info_coherent(&fi->ifi_req)) {
1971     + if (inode_alloc && o2info_coherent(&fi->ifi_req)) {
1972     status = ocfs2_inode_lock(inode_alloc, &bh, 0);
1973     if (status < 0) {
1974     mlog_errno(status);
1975     diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
1976     index e108c945ac1f..c387467d574c 100644
1977     --- a/fs/ocfs2/xattr.c
1978     +++ b/fs/ocfs2/xattr.c
1979     @@ -1497,18 +1497,6 @@ static int ocfs2_xa_check_space(struct ocfs2_xa_loc *loc,
1980     return loc->xl_ops->xlo_check_space(loc, xi);
1981     }
1982    
1983     -static void ocfs2_xa_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash)
1984     -{
1985     - loc->xl_ops->xlo_add_entry(loc, name_hash);
1986     - loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
1987     - /*
1988     - * We can't leave the new entry's xe_name_offset at zero or
1989     - * add_namevalue() will go nuts. We set it to the size of our
1990     - * storage so that it can never be less than any other entry.
1991     - */
1992     - loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);
1993     -}
1994     -
1995     static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc,
1996     struct ocfs2_xattr_info *xi)
1997     {
1998     @@ -2140,29 +2128,31 @@ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
1999     if (rc)
2000     goto out;
2001    
2002     - if (loc->xl_entry) {
2003     - if (ocfs2_xa_can_reuse_entry(loc, xi)) {
2004     - orig_value_size = loc->xl_entry->xe_value_size;
2005     - rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
2006     - if (rc)
2007     - goto out;
2008     - goto alloc_value;
2009     - }
2010     + if (!loc->xl_entry) {
2011     + rc = -EINVAL;
2012     + goto out;
2013     + }
2014    
2015     - if (!ocfs2_xattr_is_local(loc->xl_entry)) {
2016     - orig_clusters = ocfs2_xa_value_clusters(loc);
2017     - rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
2018     - if (rc) {
2019     - mlog_errno(rc);
2020     - ocfs2_xa_cleanup_value_truncate(loc,
2021     - "overwriting",
2022     - orig_clusters);
2023     - goto out;
2024     - }
2025     + if (ocfs2_xa_can_reuse_entry(loc, xi)) {
2026     + orig_value_size = loc->xl_entry->xe_value_size;
2027     + rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
2028     + if (rc)
2029     + goto out;
2030     + goto alloc_value;
2031     + }
2032     +
2033     + if (!ocfs2_xattr_is_local(loc->xl_entry)) {
2034     + orig_clusters = ocfs2_xa_value_clusters(loc);
2035     + rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
2036     + if (rc) {
2037     + mlog_errno(rc);
2038     + ocfs2_xa_cleanup_value_truncate(loc,
2039     + "overwriting",
2040     + orig_clusters);
2041     + goto out;
2042     }
2043     - ocfs2_xa_wipe_namevalue(loc);
2044     - } else
2045     - ocfs2_xa_add_entry(loc, name_hash);
2046     + }
2047     + ocfs2_xa_wipe_namevalue(loc);
2048    
2049     /*
2050     * If we get here, we have a blank entry. Fill it. We grow our
2051     diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
2052     index 3f45d9867e10..651755353374 100644
2053     --- a/fs/xfs/xfs_buf.c
2054     +++ b/fs/xfs/xfs_buf.c
2055     @@ -1674,7 +1674,7 @@ xfs_buftarg_isolate(
2056     * zero. If the value is already zero, we need to reclaim the
2057     * buffer, otherwise it gets another trip through the LRU.
2058     */
2059     - if (!atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
2060     + if (atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
2061     spin_unlock(&bp->b_lock);
2062     return LRU_ROTATE;
2063     }
2064     diff --git a/include/net/llc_conn.h b/include/net/llc_conn.h
2065     index df528a623548..ea985aa7a6c5 100644
2066     --- a/include/net/llc_conn.h
2067     +++ b/include/net/llc_conn.h
2068     @@ -104,7 +104,7 @@ void llc_sk_reset(struct sock *sk);
2069    
2070     /* Access to a connection */
2071     int llc_conn_state_process(struct sock *sk, struct sk_buff *skb);
2072     -int llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb);
2073     +void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb);
2074     void llc_conn_rtn_pdu(struct sock *sk, struct sk_buff *skb);
2075     void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit);
2076     void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit);
2077     diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
2078     index 538f3c4458b0..5d5a137b9067 100644
2079     --- a/include/net/sch_generic.h
2080     +++ b/include/net/sch_generic.h
2081     @@ -276,6 +276,11 @@ static inline struct Qdisc *qdisc_root(const struct Qdisc *qdisc)
2082     return q;
2083     }
2084    
2085     +static inline struct Qdisc *qdisc_root_bh(const struct Qdisc *qdisc)
2086     +{
2087     + return rcu_dereference_bh(qdisc->dev_queue->qdisc);
2088     +}
2089     +
2090     static inline struct Qdisc *qdisc_root_sleeping(const struct Qdisc *qdisc)
2091     {
2092     return qdisc->dev_queue->qdisc_sleeping;
2093     diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
2094     index 579ded2c6ef1..32db5208854d 100644
2095     --- a/include/net/sctp/sctp.h
2096     +++ b/include/net/sctp/sctp.h
2097     @@ -103,6 +103,8 @@ void sctp_addr_wq_mgmt(struct net *, struct sctp_sockaddr_entry *, int);
2098     /*
2099     * sctp/socket.c
2100     */
2101     +int sctp_inet_connect(struct socket *sock, struct sockaddr *uaddr,
2102     + int addr_len, int flags);
2103     int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb);
2104     int sctp_inet_listen(struct socket *sock, int backlog);
2105     void sctp_write_space(struct sock *sk);
2106     diff --git a/include/sound/timer.h b/include/sound/timer.h
2107     index c4d76ff056c6..7ae226ab6990 100644
2108     --- a/include/sound/timer.h
2109     +++ b/include/sound/timer.h
2110     @@ -90,6 +90,8 @@ struct snd_timer {
2111     struct list_head ack_list_head;
2112     struct list_head sack_list_head; /* slow ack list head */
2113     struct tasklet_struct task_queue;
2114     + int max_instances; /* upper limit of timer instances */
2115     + int num_instances; /* current number of timer instances */
2116     };
2117    
2118     struct snd_timer_instance {
2119     diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
2120     index 827ba2caea09..6a170a78b453 100644
2121     --- a/kernel/trace/trace.c
2122     +++ b/kernel/trace/trace.c
2123     @@ -5217,6 +5217,7 @@ waitagain:
2124     sizeof(struct trace_iterator) -
2125     offsetof(struct trace_iterator, seq));
2126     cpumask_clear(iter->started);
2127     + trace_seq_init(&iter->seq);
2128     iter->pos = -1;
2129    
2130     trace_event_read_lock();
2131     diff --git a/net/llc/llc_c_ac.c b/net/llc/llc_c_ac.c
2132     index 4b60f68cb492..8354ae40ec85 100644
2133     --- a/net/llc/llc_c_ac.c
2134     +++ b/net/llc/llc_c_ac.c
2135     @@ -372,6 +372,7 @@ int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
2136     llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
2137     rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
2138     if (likely(!rc)) {
2139     + skb_get(skb);
2140     llc_conn_send_pdu(sk, skb);
2141     llc_conn_ac_inc_vs_by_1(sk, skb);
2142     }
2143     @@ -389,7 +390,8 @@ static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
2144     llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
2145     rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
2146     if (likely(!rc)) {
2147     - rc = llc_conn_send_pdu(sk, skb);
2148     + skb_get(skb);
2149     + llc_conn_send_pdu(sk, skb);
2150     llc_conn_ac_inc_vs_by_1(sk, skb);
2151     }
2152     return rc;
2153     @@ -406,6 +408,7 @@ int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
2154     llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
2155     rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
2156     if (likely(!rc)) {
2157     + skb_get(skb);
2158     llc_conn_send_pdu(sk, skb);
2159     llc_conn_ac_inc_vs_by_1(sk, skb);
2160     }
2161     @@ -916,7 +919,8 @@ static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
2162     llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
2163     rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
2164     if (likely(!rc)) {
2165     - rc = llc_conn_send_pdu(sk, skb);
2166     + skb_get(skb);
2167     + llc_conn_send_pdu(sk, skb);
2168     llc_conn_ac_inc_vs_by_1(sk, skb);
2169     }
2170     return rc;
2171     diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
2172     index b9290a183a2f..94c78cc49d3e 100644
2173     --- a/net/llc/llc_conn.c
2174     +++ b/net/llc/llc_conn.c
2175     @@ -30,7 +30,7 @@
2176     #endif
2177    
2178     static int llc_find_offset(int state, int ev_type);
2179     -static int llc_conn_send_pdus(struct sock *sk, struct sk_buff *skb);
2180     +static void llc_conn_send_pdus(struct sock *sk);
2181     static int llc_conn_service(struct sock *sk, struct sk_buff *skb);
2182     static int llc_exec_conn_trans_actions(struct sock *sk,
2183     struct llc_conn_state_trans *trans,
2184     @@ -193,11 +193,11 @@ out_skb_put:
2185     return rc;
2186     }
2187    
2188     -int llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb)
2189     +void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb)
2190     {
2191     /* queue PDU to send to MAC layer */
2192     skb_queue_tail(&sk->sk_write_queue, skb);
2193     - return llc_conn_send_pdus(sk, skb);
2194     + llc_conn_send_pdus(sk);
2195     }
2196    
2197     /**
2198     @@ -255,7 +255,7 @@ void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit)
2199     if (howmany_resend > 0)
2200     llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
2201     /* any PDUs to re-send are queued up; start sending to MAC */
2202     - llc_conn_send_pdus(sk, NULL);
2203     + llc_conn_send_pdus(sk);
2204     out:;
2205     }
2206    
2207     @@ -296,7 +296,7 @@ void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit)
2208     if (howmany_resend > 0)
2209     llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
2210     /* any PDUs to re-send are queued up; start sending to MAC */
2211     - llc_conn_send_pdus(sk, NULL);
2212     + llc_conn_send_pdus(sk);
2213     out:;
2214     }
2215    
2216     @@ -340,16 +340,12 @@ out:
2217     /**
2218     * llc_conn_send_pdus - Sends queued PDUs
2219     * @sk: active connection
2220     - * @hold_skb: the skb held by caller, or NULL if does not care
2221     *
2222     - * Sends queued pdus to MAC layer for transmission. When @hold_skb is
2223     - * NULL, always return 0. Otherwise, return 0 if @hold_skb is sent
2224     - * successfully, or 1 for failure.
2225     + * Sends queued pdus to MAC layer for transmission.
2226     */
2227     -static int llc_conn_send_pdus(struct sock *sk, struct sk_buff *hold_skb)
2228     +static void llc_conn_send_pdus(struct sock *sk)
2229     {
2230     struct sk_buff *skb;
2231     - int ret = 0;
2232    
2233     while ((skb = skb_dequeue(&sk->sk_write_queue)) != NULL) {
2234     struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
2235     @@ -361,20 +357,10 @@ static int llc_conn_send_pdus(struct sock *sk, struct sk_buff *hold_skb)
2236     skb_queue_tail(&llc_sk(sk)->pdu_unack_q, skb);
2237     if (!skb2)
2238     break;
2239     - dev_queue_xmit(skb2);
2240     - } else {
2241     - bool is_target = skb == hold_skb;
2242     - int rc;
2243     -
2244     - if (is_target)
2245     - skb_get(skb);
2246     - rc = dev_queue_xmit(skb);
2247     - if (is_target)
2248     - ret = rc;
2249     + skb = skb2;
2250     }
2251     + dev_queue_xmit(skb);
2252     }
2253     -
2254     - return ret;
2255     }
2256    
2257     /**
2258     diff --git a/net/llc/llc_s_ac.c b/net/llc/llc_s_ac.c
2259     index a94bd56bcac6..7ae4cc684d3a 100644
2260     --- a/net/llc/llc_s_ac.c
2261     +++ b/net/llc/llc_s_ac.c
2262     @@ -58,8 +58,10 @@ int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
2263     ev->daddr.lsap, LLC_PDU_CMD);
2264     llc_pdu_init_as_ui_cmd(skb);
2265     rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
2266     - if (likely(!rc))
2267     + if (likely(!rc)) {
2268     + skb_get(skb);
2269     rc = dev_queue_xmit(skb);
2270     + }
2271     return rc;
2272     }
2273    
2274     @@ -81,8 +83,10 @@ int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
2275     ev->daddr.lsap, LLC_PDU_CMD);
2276     llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
2277     rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
2278     - if (likely(!rc))
2279     + if (likely(!rc)) {
2280     + skb_get(skb);
2281     rc = dev_queue_xmit(skb);
2282     + }
2283     return rc;
2284     }
2285    
2286     @@ -135,8 +139,10 @@ int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
2287     ev->daddr.lsap, LLC_PDU_CMD);
2288     llc_pdu_init_as_test_cmd(skb);
2289     rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
2290     - if (likely(!rc))
2291     + if (likely(!rc)) {
2292     + skb_get(skb);
2293     rc = dev_queue_xmit(skb);
2294     + }
2295     return rc;
2296     }
2297    
2298     diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c
2299     index 5404d0d195cc..d51ff9df9c95 100644
2300     --- a/net/llc/llc_sap.c
2301     +++ b/net/llc/llc_sap.c
2302     @@ -197,29 +197,22 @@ out:
2303     * After executing actions of the event, upper layer will be indicated
2304     * if needed(on receiving an UI frame). sk can be null for the
2305     * datalink_proto case.
2306     + *
2307     + * This function always consumes a reference to the skb.
2308     */
2309     static void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb)
2310     {
2311     struct llc_sap_state_ev *ev = llc_sap_ev(skb);
2312    
2313     - /*
2314     - * We have to hold the skb, because llc_sap_next_state
2315     - * will kfree it in the sending path and we need to
2316     - * look at the skb->cb, where we encode llc_sap_state_ev.
2317     - */
2318     - skb_get(skb);
2319     ev->ind_cfm_flag = 0;
2320     llc_sap_next_state(sap, skb);
2321     - if (ev->ind_cfm_flag == LLC_IND) {
2322     - if (skb->sk->sk_state == TCP_LISTEN)
2323     - kfree_skb(skb);
2324     - else {
2325     - llc_save_primitive(skb->sk, skb, ev->prim);
2326    
2327     - /* queue skb to the user. */
2328     - if (sock_queue_rcv_skb(skb->sk, skb))
2329     - kfree_skb(skb);
2330     - }
2331     + if (ev->ind_cfm_flag == LLC_IND && skb->sk->sk_state != TCP_LISTEN) {
2332     + llc_save_primitive(skb->sk, skb, ev->prim);
2333     +
2334     + /* queue skb to the user. */
2335     + if (sock_queue_rcv_skb(skb->sk, skb) == 0)
2336     + return;
2337     }
2338     kfree_skb(skb);
2339     }
2340     diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
2341     index 12e3ae09c4ba..95002e56fa48 100644
2342     --- a/net/sched/sch_netem.c
2343     +++ b/net/sched/sch_netem.c
2344     @@ -475,7 +475,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
2345     * skb will be queued.
2346     */
2347     if (count > 1 && (skb2 = skb_clone(skb, GFP_ATOMIC)) != NULL) {
2348     - struct Qdisc *rootq = qdisc_root(sch);
2349     + struct Qdisc *rootq = qdisc_root_bh(sch);
2350     u32 dupsave = q->duplicate; /* prevent duplicating a dup... */
2351    
2352     q->duplicate = 0;
2353     diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
2354     index 31f461f955ec..824ebbffea33 100644
2355     --- a/net/sctp/ipv6.c
2356     +++ b/net/sctp/ipv6.c
2357     @@ -973,7 +973,7 @@ static const struct proto_ops inet6_seqpacket_ops = {
2358     .owner = THIS_MODULE,
2359     .release = inet6_release,
2360     .bind = inet6_bind,
2361     - .connect = inet_dgram_connect,
2362     + .connect = sctp_inet_connect,
2363     .socketpair = sock_no_socketpair,
2364     .accept = inet_accept,
2365     .getname = sctp_getname,
2366     diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
2367     index 833283c8fe11..9cb06ca4eaba 100644
2368     --- a/net/sctp/protocol.c
2369     +++ b/net/sctp/protocol.c
2370     @@ -1014,7 +1014,7 @@ static const struct proto_ops inet_seqpacket_ops = {
2371     .owner = THIS_MODULE,
2372     .release = inet_release, /* Needs to be wrapped... */
2373     .bind = inet_bind,
2374     - .connect = inet_dgram_connect,
2375     + .connect = sctp_inet_connect,
2376     .socketpair = sock_no_socketpair,
2377     .accept = inet_accept,
2378     .getname = inet_getname, /* Semantics are different. */
2379     diff --git a/net/sctp/socket.c b/net/sctp/socket.c
2380     index 574a6a2c48d7..c952abf22535 100644
2381     --- a/net/sctp/socket.c
2382     +++ b/net/sctp/socket.c
2383     @@ -1074,7 +1074,7 @@ out:
2384     */
2385     static int __sctp_connect(struct sock *sk,
2386     struct sockaddr *kaddrs,
2387     - int addrs_size,
2388     + int addrs_size, int flags,
2389     sctp_assoc_t *assoc_id)
2390     {
2391     struct net *net = sock_net(sk);
2392     @@ -1092,7 +1092,6 @@ static int __sctp_connect(struct sock *sk,
2393     union sctp_addr *sa_addr = NULL;
2394     void *addr_buf;
2395     unsigned short port;
2396     - unsigned int f_flags = 0;
2397    
2398     sp = sctp_sk(sk);
2399     ep = sp->ep;
2400     @@ -1240,13 +1239,7 @@ static int __sctp_connect(struct sock *sk,
2401     sp->pf->to_sk_daddr(sa_addr, sk);
2402     sk->sk_err = 0;
2403    
2404     - /* in-kernel sockets don't generally have a file allocated to them
2405     - * if all they do is call sock_create_kern().
2406     - */
2407     - if (sk->sk_socket->file)
2408     - f_flags = sk->sk_socket->file->f_flags;
2409     -
2410     - timeo = sock_sndtimeo(sk, f_flags & O_NONBLOCK);
2411     + timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
2412    
2413     if (assoc_id)
2414     *assoc_id = asoc->assoc_id;
2415     @@ -1341,7 +1334,7 @@ static int __sctp_setsockopt_connectx(struct sock *sk,
2416     {
2417     struct sockaddr *kaddrs;
2418     gfp_t gfp = GFP_KERNEL;
2419     - int err = 0;
2420     + int err = 0, flags = 0;
2421    
2422     pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n",
2423     __func__, sk, addrs, addrs_size);
2424     @@ -1361,11 +1354,18 @@ static int __sctp_setsockopt_connectx(struct sock *sk,
2425     return -ENOMEM;
2426    
2427     if (__copy_from_user(kaddrs, addrs, addrs_size)) {
2428     - err = -EFAULT;
2429     - } else {
2430     - err = __sctp_connect(sk, kaddrs, addrs_size, assoc_id);
2431     + kfree(kaddrs);
2432     + return -EFAULT;
2433     }
2434    
2435     + /* in-kernel sockets don't generally have a file allocated to them
2436     + * if all they do is call sock_create_kern().
2437     + */
2438     + if (sk->sk_socket->file)
2439     + flags = sk->sk_socket->file->f_flags;
2440     +
2441     + err = __sctp_connect(sk, kaddrs, addrs_size, flags, assoc_id);
2442     +
2443     kfree(kaddrs);
2444    
2445     return err;
2446     @@ -3979,31 +3979,36 @@ out_nounlock:
2447     * len: the size of the address.
2448     */
2449     static int sctp_connect(struct sock *sk, struct sockaddr *addr,
2450     - int addr_len)
2451     + int addr_len, int flags)
2452     {
2453     - int err = 0;
2454     struct sctp_af *af;
2455     + int err = -EINVAL;
2456    
2457     lock_sock(sk);
2458     -
2459     pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk,
2460     addr, addr_len);
2461    
2462     /* Validate addr_len before calling common connect/connectx routine. */
2463     af = sctp_get_af_specific(addr->sa_family);
2464     - if (!af || addr_len < af->sockaddr_len) {
2465     - err = -EINVAL;
2466     - } else {
2467     - /* Pass correct addr len to common routine (so it knows there
2468     - * is only one address being passed.
2469     - */
2470     - err = __sctp_connect(sk, addr, af->sockaddr_len, NULL);
2471     - }
2472     + if (af && addr_len >= af->sockaddr_len)
2473     + err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL);
2474    
2475     release_sock(sk);
2476     return err;
2477     }
2478    
2479     +int sctp_inet_connect(struct socket *sock, struct sockaddr *uaddr,
2480     + int addr_len, int flags)
2481     +{
2482     + if (addr_len < sizeof(uaddr->sa_family))
2483     + return -EINVAL;
2484     +
2485     + if (uaddr->sa_family == AF_UNSPEC)
2486     + return -EOPNOTSUPP;
2487     +
2488     + return sctp_connect(sock->sk, uaddr, addr_len, flags);
2489     +}
2490     +
2491     /* FIXME: Write comments. */
2492     static int sctp_disconnect(struct sock *sk, int flags)
2493     {
2494     @@ -7896,7 +7901,6 @@ struct proto sctp_prot = {
2495     .name = "SCTP",
2496     .owner = THIS_MODULE,
2497     .close = sctp_close,
2498     - .connect = sctp_connect,
2499     .disconnect = sctp_disconnect,
2500     .accept = sctp_accept,
2501     .ioctl = sctp_ioctl,
2502     @@ -7935,7 +7939,6 @@ struct proto sctpv6_prot = {
2503     .name = "SCTPv6",
2504     .owner = THIS_MODULE,
2505     .close = sctp_close,
2506     - .connect = sctp_connect,
2507     .disconnect = sctp_disconnect,
2508     .accept = sctp_accept,
2509     .ioctl = sctp_ioctl,
2510     diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
2511     index ac75e6d4eb82..060bc0cc8252 100644
2512     --- a/net/wireless/nl80211.c
2513     +++ b/net/wireless/nl80211.c
2514     @@ -295,7 +295,8 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
2515     [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
2516     [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
2517     .len = IEEE80211_MAX_MESH_ID_LEN },
2518     - [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
2519     + [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_BINARY,
2520     + .len = ETH_ALEN },
2521    
2522     [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
2523     [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
2524     diff --git a/scripts/setlocalversion b/scripts/setlocalversion
2525     index 966dd3924ea9..aa28c3f29809 100755
2526     --- a/scripts/setlocalversion
2527     +++ b/scripts/setlocalversion
2528     @@ -72,8 +72,16 @@ scm_version()
2529     printf -- '-svn%s' "`git svn find-rev $head`"
2530     fi
2531    
2532     - # Check for uncommitted changes
2533     - if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
2534     + # Check for uncommitted changes.
2535     + # First, with git-status, but --no-optional-locks is only
2536     + # supported in git >= 2.14, so fall back to git-diff-index if
2537     + # it fails. Note that git-diff-index does not refresh the
2538     + # index, so it may give misleading results. See
2539     + # git-update-index(1), git-diff-index(1), and git-status(1).
2540     + if {
2541     + git --no-optional-locks status -uno --porcelain 2>/dev/null ||
2542     + git diff-index --name-only HEAD
2543     + } | grep -qvE '^(.. )?scripts/package'; then
2544     printf '%s' -dirty
2545     fi
2546    
2547     diff --git a/sound/core/hrtimer.c b/sound/core/hrtimer.c
2548     index e2f27022b363..d7dddb75e7bb 100644
2549     --- a/sound/core/hrtimer.c
2550     +++ b/sound/core/hrtimer.c
2551     @@ -159,6 +159,7 @@ static int __init snd_hrtimer_init(void)
2552     timer->hw = hrtimer_hw;
2553     timer->hw.resolution = resolution;
2554     timer->hw.ticks = NANO_SEC / resolution;
2555     + timer->max_instances = 100; /* lower the limit */
2556    
2557     err = snd_timer_global_register(timer);
2558     if (err < 0) {
2559     diff --git a/sound/core/timer.c b/sound/core/timer.c
2560     index 152254193c69..19d90aa08218 100644
2561     --- a/sound/core/timer.c
2562     +++ b/sound/core/timer.c
2563     @@ -179,7 +179,7 @@ static void snd_timer_request(struct snd_timer_id *tid)
2564     *
2565     * call this with register_mutex down.
2566     */
2567     -static void snd_timer_check_slave(struct snd_timer_instance *slave)
2568     +static int snd_timer_check_slave(struct snd_timer_instance *slave)
2569     {
2570     struct snd_timer *timer;
2571     struct snd_timer_instance *master;
2572     @@ -189,16 +189,21 @@ static void snd_timer_check_slave(struct snd_timer_instance *slave)
2573     list_for_each_entry(master, &timer->open_list_head, open_list) {
2574     if (slave->slave_class == master->slave_class &&
2575     slave->slave_id == master->slave_id) {
2576     + if (master->timer->num_instances >=
2577     + master->timer->max_instances)
2578     + return -EBUSY;
2579     list_move_tail(&slave->open_list,
2580     &master->slave_list_head);
2581     + master->timer->num_instances++;
2582     spin_lock_irq(&slave_active_lock);
2583     slave->master = master;
2584     slave->timer = master->timer;
2585     spin_unlock_irq(&slave_active_lock);
2586     - return;
2587     + return 0;
2588     }
2589     }
2590     }
2591     + return 0;
2592     }
2593    
2594     /*
2595     @@ -207,7 +212,7 @@ static void snd_timer_check_slave(struct snd_timer_instance *slave)
2596     *
2597     * call this with register_mutex down.
2598     */
2599     -static void snd_timer_check_master(struct snd_timer_instance *master)
2600     +static int snd_timer_check_master(struct snd_timer_instance *master)
2601     {
2602     struct snd_timer_instance *slave, *tmp;
2603    
2604     @@ -215,7 +220,11 @@ static void snd_timer_check_master(struct snd_timer_instance *master)
2605     list_for_each_entry_safe(slave, tmp, &snd_timer_slave_list, open_list) {
2606     if (slave->slave_class == master->slave_class &&
2607     slave->slave_id == master->slave_id) {
2608     + if (master->timer->num_instances >=
2609     + master->timer->max_instances)
2610     + return -EBUSY;
2611     list_move_tail(&slave->open_list, &master->slave_list_head);
2612     + master->timer->num_instances++;
2613     spin_lock_irq(&slave_active_lock);
2614     spin_lock(&master->timer->lock);
2615     slave->master = master;
2616     @@ -227,8 +236,12 @@ static void snd_timer_check_master(struct snd_timer_instance *master)
2617     spin_unlock_irq(&slave_active_lock);
2618     }
2619     }
2620     + return 0;
2621     }
2622    
2623     +static int snd_timer_close_locked(struct snd_timer_instance *timeri,
2624     + struct device **card_devp_to_put);
2625     +
2626     /*
2627     * open a timer instance
2628     * when opening a master, the slave id must be here given.
2629     @@ -239,33 +252,37 @@ int snd_timer_open(struct snd_timer_instance **ti,
2630     {
2631     struct snd_timer *timer;
2632     struct snd_timer_instance *timeri = NULL;
2633     + struct device *card_dev_to_put = NULL;
2634     + int err;
2635    
2636     + mutex_lock(&register_mutex);
2637     if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) {
2638     /* open a slave instance */
2639     if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE ||
2640     tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) {
2641     pr_debug("ALSA: timer: invalid slave class %i\n",
2642     tid->dev_sclass);
2643     - return -EINVAL;
2644     + err = -EINVAL;
2645     + goto unlock;
2646     }
2647     - mutex_lock(&register_mutex);
2648     timeri = snd_timer_instance_new(owner, NULL);
2649     if (!timeri) {
2650     - mutex_unlock(&register_mutex);
2651     - return -ENOMEM;
2652     + err = -ENOMEM;
2653     + goto unlock;
2654     }
2655     timeri->slave_class = tid->dev_sclass;
2656     timeri->slave_id = tid->device;
2657     timeri->flags |= SNDRV_TIMER_IFLG_SLAVE;
2658     list_add_tail(&timeri->open_list, &snd_timer_slave_list);
2659     - snd_timer_check_slave(timeri);
2660     - mutex_unlock(&register_mutex);
2661     - *ti = timeri;
2662     - return 0;
2663     + err = snd_timer_check_slave(timeri);
2664     + if (err < 0) {
2665     + snd_timer_close_locked(timeri, &card_dev_to_put);
2666     + timeri = NULL;
2667     + }
2668     + goto unlock;
2669     }
2670    
2671     /* open a master instance */
2672     - mutex_lock(&register_mutex);
2673     timer = snd_timer_find(tid);
2674     #ifdef CONFIG_MODULES
2675     if (!timer) {
2676     @@ -276,21 +293,26 @@ int snd_timer_open(struct snd_timer_instance **ti,
2677     }
2678     #endif
2679     if (!timer) {
2680     - mutex_unlock(&register_mutex);
2681     - return -ENODEV;
2682     + err = -ENODEV;
2683     + goto unlock;
2684     }
2685     if (!list_empty(&timer->open_list_head)) {
2686     timeri = list_entry(timer->open_list_head.next,
2687     struct snd_timer_instance, open_list);
2688     if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) {
2689     - mutex_unlock(&register_mutex);
2690     - return -EBUSY;
2691     + err = -EBUSY;
2692     + timeri = NULL;
2693     + goto unlock;
2694     }
2695     }
2696     + if (timer->num_instances >= timer->max_instances) {
2697     + err = -EBUSY;
2698     + goto unlock;
2699     + }
2700     timeri = snd_timer_instance_new(owner, timer);
2701     if (!timeri) {
2702     - mutex_unlock(&register_mutex);
2703     - return -ENOMEM;
2704     + err = -ENOMEM;
2705     + goto unlock;
2706     }
2707     /* take a card refcount for safe disconnection */
2708     if (timer->card)
2709     @@ -299,38 +321,47 @@ int snd_timer_open(struct snd_timer_instance **ti,
2710     timeri->slave_id = slave_id;
2711    
2712     if (list_empty(&timer->open_list_head) && timer->hw.open) {
2713     - int err = timer->hw.open(timer);
2714     + err = timer->hw.open(timer);
2715     if (err) {
2716     kfree(timeri->owner);
2717     kfree(timeri);
2718     + timeri = NULL;
2719    
2720     if (timer->card)
2721     - put_device(&timer->card->card_dev);
2722     + card_dev_to_put = &timer->card->card_dev;
2723     module_put(timer->module);
2724     - mutex_unlock(&register_mutex);
2725     - return err;
2726     + goto unlock;
2727     }
2728     }
2729    
2730     list_add_tail(&timeri->open_list, &timer->open_list_head);
2731     - snd_timer_check_master(timeri);
2732     + timer->num_instances++;
2733     + err = snd_timer_check_master(timeri);
2734     + if (err < 0) {
2735     + snd_timer_close_locked(timeri, &card_dev_to_put);
2736     + timeri = NULL;
2737     + }
2738     +
2739     + unlock:
2740     mutex_unlock(&register_mutex);
2741     + /* put_device() is called after unlock for avoiding deadlock */
2742     + if (card_dev_to_put)
2743     + put_device(card_dev_to_put);
2744     *ti = timeri;
2745     - return 0;
2746     + return err;
2747     }
2748     +EXPORT_SYMBOL(snd_timer_open);
2749    
2750     /*
2751     * close a timer instance
2752     + * call this with register_mutex down.
2753     */
2754     -int snd_timer_close(struct snd_timer_instance *timeri)
2755     +static int snd_timer_close_locked(struct snd_timer_instance *timeri,
2756     + struct device **card_devp_to_put)
2757     {
2758     struct snd_timer *timer = NULL;
2759     struct snd_timer_instance *slave, *tmp;
2760    
2761     - if (snd_BUG_ON(!timeri))
2762     - return -ENXIO;
2763     -
2764     - mutex_lock(&register_mutex);
2765     list_del(&timeri->open_list);
2766    
2767     /* force to stop the timer */
2768     @@ -338,6 +369,7 @@ int snd_timer_close(struct snd_timer_instance *timeri)
2769    
2770     timer = timeri->timer;
2771     if (timer) {
2772     + timer->num_instances--;
2773     /* wait, until the active callback is finished */
2774     spin_lock_irq(&timer->lock);
2775     while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) {
2776     @@ -353,6 +385,7 @@ int snd_timer_close(struct snd_timer_instance *timeri)
2777     list_for_each_entry_safe(slave, tmp, &timeri->slave_list_head,
2778     open_list) {
2779     list_move_tail(&slave->open_list, &snd_timer_slave_list);
2780     + timer->num_instances--;
2781     slave->master = NULL;
2782     slave->timer = NULL;
2783     list_del_init(&slave->ack_list);
2784     @@ -376,14 +409,34 @@ int snd_timer_close(struct snd_timer_instance *timeri)
2785     timer->hw.close(timer);
2786     /* release a card refcount for safe disconnection */
2787     if (timer->card)
2788     - put_device(&timer->card->card_dev);
2789     + *card_devp_to_put = &timer->card->card_dev;
2790     module_put(timer->module);
2791     }
2792    
2793     - mutex_unlock(&register_mutex);
2794     return 0;
2795     }
2796    
2797     +/*
2798     + * close a timer instance
2799     + */
2800     +int snd_timer_close(struct snd_timer_instance *timeri)
2801     +{
2802     + struct device *card_dev_to_put = NULL;
2803     + int err;
2804     +
2805     + if (snd_BUG_ON(!timeri))
2806     + return -ENXIO;
2807     +
2808     + mutex_lock(&register_mutex);
2809     + err = snd_timer_close_locked(timeri, &card_dev_to_put);
2810     + mutex_unlock(&register_mutex);
2811     + /* put_device() is called after unlock for avoiding deadlock */
2812     + if (card_dev_to_put)
2813     + put_device(card_dev_to_put);
2814     + return err;
2815     +}
2816     +EXPORT_SYMBOL(snd_timer_close);
2817     +
2818     unsigned long snd_timer_resolution(struct snd_timer_instance *timeri)
2819     {
2820     struct snd_timer * timer;
2821     @@ -397,6 +450,7 @@ unsigned long snd_timer_resolution(struct snd_timer_instance *timeri)
2822     }
2823     return 0;
2824     }
2825     +EXPORT_SYMBOL(snd_timer_resolution);
2826    
2827     static void snd_timer_notify1(struct snd_timer_instance *ti, int event)
2828     {
2829     @@ -588,6 +642,7 @@ int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks)
2830     else
2831     return snd_timer_start1(timeri, true, ticks);
2832     }
2833     +EXPORT_SYMBOL(snd_timer_start);
2834    
2835     /*
2836     * stop the timer instance.
2837     @@ -601,6 +656,7 @@ int snd_timer_stop(struct snd_timer_instance *timeri)
2838     else
2839     return snd_timer_stop1(timeri, true);
2840     }
2841     +EXPORT_SYMBOL(snd_timer_stop);
2842    
2843     /*
2844     * start again.. the tick is kept.
2845     @@ -616,6 +672,7 @@ int snd_timer_continue(struct snd_timer_instance *timeri)
2846     else
2847     return snd_timer_start1(timeri, false, 0);
2848     }
2849     +EXPORT_SYMBOL(snd_timer_continue);
2850    
2851     /*
2852     * pause.. remember the ticks left
2853     @@ -627,6 +684,7 @@ int snd_timer_pause(struct snd_timer_instance * timeri)
2854     else
2855     return snd_timer_stop1(timeri, false);
2856     }
2857     +EXPORT_SYMBOL(snd_timer_pause);
2858    
2859     /*
2860     * reschedule the timer
2861     @@ -808,6 +866,7 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
2862     if (use_tasklet)
2863     tasklet_schedule(&timer->task_queue);
2864     }
2865     +EXPORT_SYMBOL(snd_timer_interrupt);
2866    
2867     /*
2868    
2869     @@ -846,6 +905,7 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
2870     spin_lock_init(&timer->lock);
2871     tasklet_init(&timer->task_queue, snd_timer_tasklet,
2872     (unsigned long)timer);
2873     + timer->max_instances = 1000; /* default limit per timer */
2874     if (card != NULL) {
2875     timer->module = card->module;
2876     err = snd_device_new(card, SNDRV_DEV_TIMER, timer, &ops);
2877     @@ -858,6 +918,7 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
2878     *rtimer = timer;
2879     return 0;
2880     }
2881     +EXPORT_SYMBOL(snd_timer_new);
2882    
2883     static int snd_timer_free(struct snd_timer *timer)
2884     {
2885     @@ -977,6 +1038,7 @@ void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstam
2886     }
2887     spin_unlock_irqrestore(&timer->lock, flags);
2888     }
2889     +EXPORT_SYMBOL(snd_timer_notify);
2890    
2891     /*
2892     * exported functions for global timers
2893     @@ -992,11 +1054,13 @@ int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer)
2894     tid.subdevice = 0;
2895     return snd_timer_new(NULL, id, &tid, rtimer);
2896     }
2897     +EXPORT_SYMBOL(snd_timer_global_new);
2898    
2899     int snd_timer_global_free(struct snd_timer *timer)
2900     {
2901     return snd_timer_free(timer);
2902     }
2903     +EXPORT_SYMBOL(snd_timer_global_free);
2904    
2905     int snd_timer_global_register(struct snd_timer *timer)
2906     {
2907     @@ -1006,6 +1070,7 @@ int snd_timer_global_register(struct snd_timer *timer)
2908     dev.device_data = timer;
2909     return snd_timer_dev_register(&dev);
2910     }
2911     +EXPORT_SYMBOL(snd_timer_global_register);
2912    
2913     /*
2914     * System timer
2915     @@ -2121,17 +2186,3 @@ static void __exit alsa_timer_exit(void)
2916    
2917     module_init(alsa_timer_init)
2918     module_exit(alsa_timer_exit)
2919     -
2920     -EXPORT_SYMBOL(snd_timer_open);
2921     -EXPORT_SYMBOL(snd_timer_close);
2922     -EXPORT_SYMBOL(snd_timer_resolution);
2923     -EXPORT_SYMBOL(snd_timer_start);
2924     -EXPORT_SYMBOL(snd_timer_stop);
2925     -EXPORT_SYMBOL(snd_timer_continue);
2926     -EXPORT_SYMBOL(snd_timer_pause);
2927     -EXPORT_SYMBOL(snd_timer_new);
2928     -EXPORT_SYMBOL(snd_timer_notify);
2929     -EXPORT_SYMBOL(snd_timer_global_new);
2930     -EXPORT_SYMBOL(snd_timer_global_free);
2931     -EXPORT_SYMBOL(snd_timer_global_register);
2932     -EXPORT_SYMBOL(snd_timer_interrupt);
2933     diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c
2934     index 4d3034a68bdf..be2c056eb62d 100644
2935     --- a/sound/firewire/bebob/bebob_stream.c
2936     +++ b/sound/firewire/bebob/bebob_stream.c
2937     @@ -253,8 +253,7 @@ end:
2938     return err;
2939     }
2940    
2941     -static unsigned int
2942     -map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
2943     +static int map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
2944     {
2945     unsigned int sec, sections, ch, channels;
2946     unsigned int pcm, midi, location;
2947     diff --git a/sound/hda/hdac_controller.c b/sound/hda/hdac_controller.c
2948     index 433f3280f709..00c6af2ae1c2 100644
2949     --- a/sound/hda/hdac_controller.c
2950     +++ b/sound/hda/hdac_controller.c
2951     @@ -441,8 +441,6 @@ static void azx_int_disable(struct hdac_bus *bus)
2952     list_for_each_entry(azx_dev, &bus->stream_list, list)
2953     snd_hdac_stream_updateb(azx_dev, SD_CTL, SD_INT_MASK, 0);
2954    
2955     - synchronize_irq(bus->irq);
2956     -
2957     /* disable SIE for all streams */
2958     snd_hdac_chip_writeb(bus, INTCTL, 0);
2959    
2960     diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
2961     index 3d4ea5fd75bf..f2f1d9fd848c 100644
2962     --- a/sound/pci/hda/hda_intel.c
2963     +++ b/sound/pci/hda/hda_intel.c
2964     @@ -1239,9 +1239,9 @@ static int azx_free(struct azx *chip)
2965     }
2966    
2967     if (bus->chip_init) {
2968     - azx_stop_chip(chip);
2969     azx_clear_irq_pending(chip);
2970     azx_stop_all_streams(chip);
2971     + azx_stop_chip(chip);
2972     }
2973    
2974     if (bus->irq >= 0)
2975     diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
2976     index 016d12af6877..0619054bd7a0 100644
2977     --- a/tools/perf/pmu-events/jevents.c
2978     +++ b/tools/perf/pmu-events/jevents.c
2979     @@ -311,12 +311,12 @@ static struct fixed {
2980     const char *name;
2981     const char *event;
2982     } fixed[] = {
2983     - { "inst_retired.any", "event=0xc0" },
2984     - { "inst_retired.any_p", "event=0xc0" },
2985     - { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03" },
2986     - { "cpu_clk_unhalted.thread", "event=0x3c" },
2987     - { "cpu_clk_unhalted.core", "event=0x3c" },
2988     - { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1" },
2989     + { "inst_retired.any", "event=0xc0,period=2000003" },
2990     + { "inst_retired.any_p", "event=0xc0,period=2000003" },
2991     + { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03,period=2000003" },
2992     + { "cpu_clk_unhalted.thread", "event=0x3c,period=2000003" },
2993     + { "cpu_clk_unhalted.core", "event=0x3c,period=2000003" },
2994     + { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1,period=2000003" },
2995     { NULL, NULL},
2996     };
2997    
2998     diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
2999     index c662fef95d14..df6892596dc2 100644
3000     --- a/tools/perf/util/map.c
3001     +++ b/tools/perf/util/map.c
3002     @@ -1,4 +1,5 @@
3003     #include "symbol.h"
3004     +#include <assert.h>
3005     #include <errno.h>
3006     #include <inttypes.h>
3007     #include <limits.h>
3008     @@ -716,6 +717,8 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp
3009     }
3010    
3011     after->start = map->end;
3012     + after->pgoff += map->end - pos->start;
3013     + assert(pos->map_ip(pos, map->end) == after->map_ip(after, map->end));
3014     __map_groups__insert(pos->groups, after);
3015     if (verbose >= 2)
3016     map__fprintf(after, fp);