Magellan Linux

Contents of /trunk/kernel-magellan/patches-4.11/0106-4.11.7-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2949 - (show annotations) (download)
Mon Jun 26 08:33:00 2017 UTC (6 years, 10 months ago) by niro
File size: 126509 byte(s)
-linux-4.11.7
1 diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
2 index facc20a3f962..952319b73e61 100644
3 --- a/Documentation/admin-guide/kernel-parameters.txt
4 +++ b/Documentation/admin-guide/kernel-parameters.txt
5 @@ -3779,6 +3779,13 @@
6 spia_pedr=
7 spia_peddr=
8
9 + stack_guard_gap= [MM]
10 + override the default stack gap protection. The value
11 + is in page units and it defines how many pages prior
12 + to (for stacks growing down) resp. after (for stacks
13 + growing up) the main stack are reserved for no other
14 + mapping. Default value is 256 pages.
15 +
16 stacktrace [FTRACE]
17 Enabled the stack tracer on boot up.
18
19 diff --git a/Documentation/devicetree/bindings/mfd/axp20x.txt b/Documentation/devicetree/bindings/mfd/axp20x.txt
20 index 8f3ad9ab4637..b41d2601c6ba 100644
21 --- a/Documentation/devicetree/bindings/mfd/axp20x.txt
22 +++ b/Documentation/devicetree/bindings/mfd/axp20x.txt
23 @@ -28,6 +28,9 @@ Optional properties:
24 regulator to drive the OTG VBus, rather then as an input pin
25 which signals whether the board is driving OTG VBus or not.
26
27 +- x-powers,master-mode: Boolean (axp806 only). Set this when the PMIC is
28 + wired for master mode. The default is slave mode.
29 +
30 - <input>-supply: a phandle to the regulator supply node. May be omitted if
31 inputs are unregulated, such as using the IPSOUT output
32 from the PMIC.
33 diff --git a/Makefile b/Makefile
34 index e46e99cbe5d1..1b0fe238d633 100644
35 --- a/Makefile
36 +++ b/Makefile
37 @@ -1,6 +1,6 @@
38 VERSION = 4
39 PATCHLEVEL = 11
40 -SUBLEVEL = 6
41 +SUBLEVEL = 7
42 EXTRAVERSION =
43 NAME = Fearless Coyote
44
45 diff --git a/arch/arc/mm/mmap.c b/arch/arc/mm/mmap.c
46 index 3e25e8d6486b..2e13683dfb24 100644
47 --- a/arch/arc/mm/mmap.c
48 +++ b/arch/arc/mm/mmap.c
49 @@ -65,7 +65,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
50
51 vma = find_vma(mm, addr);
52 if (TASK_SIZE - len >= addr &&
53 - (!vma || addr + len <= vma->vm_start))
54 + (!vma || addr + len <= vm_start_gap(vma)))
55 return addr;
56 }
57
58 diff --git a/arch/arm/boot/dts/am335x-sl50.dts b/arch/arm/boot/dts/am335x-sl50.dts
59 index c5d2589c55fc..fc864a855991 100644
60 --- a/arch/arm/boot/dts/am335x-sl50.dts
61 +++ b/arch/arm/boot/dts/am335x-sl50.dts
62 @@ -220,7 +220,7 @@
63
64 mmc1_pins: pinmux_mmc1_pins {
65 pinctrl-single,pins = <
66 - AM33XX_IOPAD(0x960, PIN_INPUT | MUX_MODE7) /* spi0_cs1.gpio0_6 */
67 + AM33XX_IOPAD(0x96c, PIN_INPUT | MUX_MODE7) /* uart0_rtsn.gpio1_9 */
68 >;
69 };
70
71 @@ -280,10 +280,6 @@
72 AM33XX_IOPAD(0x834, PIN_INPUT_PULLUP | MUX_MODE7) /* nKbdReset - gpmc_ad13.gpio1_13 */
73 AM33XX_IOPAD(0x838, PIN_INPUT_PULLUP | MUX_MODE7) /* nDispReset - gpmc_ad14.gpio1_14 */
74 AM33XX_IOPAD(0x844, PIN_INPUT_PULLUP | MUX_MODE7) /* USB1_enPower - gpmc_a1.gpio1_17 */
75 - /* AVR Programming - SPI Bus (bit bang) - Screen and Keyboard */
76 - AM33XX_IOPAD(0x954, PIN_INPUT_PULLUP | MUX_MODE7) /* Kbd/Disp/BattMOSI spi0_d0.gpio0_3 */
77 - AM33XX_IOPAD(0x958, PIN_INPUT_PULLUP | MUX_MODE7) /* Kbd/Disp/BattMISO spi0_d1.gpio0_4 */
78 - AM33XX_IOPAD(0x950, PIN_INPUT_PULLUP | MUX_MODE7) /* Kbd/Disp/BattSCLK spi0_clk.gpio0_2 */
79 /* PDI Bus - Battery system */
80 AM33XX_IOPAD(0x840, PIN_INPUT_PULLUP | MUX_MODE7) /* nBattReset gpmc_a0.gpio1_16 */
81 AM33XX_IOPAD(0x83c, PIN_INPUT_PULLUP | MUX_MODE7) /* BattPDIData gpmc_ad15.gpio1_15 */
82 @@ -384,7 +380,7 @@
83 pinctrl-names = "default";
84 pinctrl-0 = <&mmc1_pins>;
85 bus-width = <4>;
86 - cd-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
87 + cd-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
88 vmmc-supply = <&vmmcsd_fixed>;
89 };
90
91 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
92 index 2239fde10b80..f0701d8d24df 100644
93 --- a/arch/arm/mm/mmap.c
94 +++ b/arch/arm/mm/mmap.c
95 @@ -90,7 +90,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
96
97 vma = find_vma(mm, addr);
98 if (TASK_SIZE - len >= addr &&
99 - (!vma || addr + len <= vma->vm_start))
100 + (!vma || addr + len <= vm_start_gap(vma)))
101 return addr;
102 }
103
104 @@ -141,7 +141,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
105 addr = PAGE_ALIGN(addr);
106 vma = find_vma(mm, addr);
107 if (TASK_SIZE - len >= addr &&
108 - (!vma || addr + len <= vma->vm_start))
109 + (!vma || addr + len <= vm_start_gap(vma)))
110 return addr;
111 }
112
113 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
114 index da82c25301e7..46aa289c5102 100644
115 --- a/arch/frv/mm/elf-fdpic.c
116 +++ b/arch/frv/mm/elf-fdpic.c
117 @@ -75,7 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
118 addr = PAGE_ALIGN(addr);
119 vma = find_vma(current->mm, addr);
120 if (TASK_SIZE - len >= addr &&
121 - (!vma || addr + len <= vma->vm_start))
122 + (!vma || addr + len <= vm_start_gap(vma)))
123 goto success;
124 }
125
126 diff --git a/arch/mips/boot/Makefile b/arch/mips/boot/Makefile
127 index 2728a9a9c7c5..145b5ce8eb7e 100644
128 --- a/arch/mips/boot/Makefile
129 +++ b/arch/mips/boot/Makefile
130 @@ -128,19 +128,19 @@ quiet_cmd_cpp_its_S = ITS $@
131 -DADDR_BITS=$(ADDR_BITS) \
132 -DADDR_CELLS=$(itb_addr_cells)
133
134 -$(obj)/vmlinux.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S FORCE
135 +$(obj)/vmlinux.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S $(VMLINUX) FORCE
136 $(call if_changed_dep,cpp_its_S,none,vmlinux.bin)
137
138 -$(obj)/vmlinux.gz.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S FORCE
139 +$(obj)/vmlinux.gz.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S $(VMLINUX) FORCE
140 $(call if_changed_dep,cpp_its_S,gzip,vmlinux.bin.gz)
141
142 -$(obj)/vmlinux.bz2.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S FORCE
143 +$(obj)/vmlinux.bz2.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S $(VMLINUX) FORCE
144 $(call if_changed_dep,cpp_its_S,bzip2,vmlinux.bin.bz2)
145
146 -$(obj)/vmlinux.lzma.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S FORCE
147 +$(obj)/vmlinux.lzma.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S $(VMLINUX) FORCE
148 $(call if_changed_dep,cpp_its_S,lzma,vmlinux.bin.lzma)
149
150 -$(obj)/vmlinux.lzo.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S FORCE
151 +$(obj)/vmlinux.lzo.its: $(srctree)/arch/mips/$(PLATFORM)/vmlinux.its.S $(VMLINUX) FORCE
152 $(call if_changed_dep,cpp_its_S,lzo,vmlinux.bin.lzo)
153
154 quiet_cmd_itb-image = ITB $@
155 diff --git a/arch/mips/kernel/branch.c b/arch/mips/kernel/branch.c
156 index b11facd11c9d..f702a459a830 100644
157 --- a/arch/mips/kernel/branch.c
158 +++ b/arch/mips/kernel/branch.c
159 @@ -804,8 +804,10 @@ int __compute_return_epc_for_insn(struct pt_regs *regs,
160 break;
161 }
162 /* Compact branch: BNEZC || JIALC */
163 - if (insn.i_format.rs)
164 + if (!insn.i_format.rs) {
165 + /* JIALC: set $31/ra */
166 regs->regs[31] = epc + 4;
167 + }
168 regs->cp0_epc += 8;
169 break;
170 #endif
171 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
172 index 64dd8bdd92c3..28adeabe851f 100644
173 --- a/arch/mips/mm/mmap.c
174 +++ b/arch/mips/mm/mmap.c
175 @@ -93,7 +93,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
176
177 vma = find_vma(mm, addr);
178 if (TASK_SIZE - len >= addr &&
179 - (!vma || addr + len <= vma->vm_start))
180 + (!vma || addr + len <= vm_start_gap(vma)))
181 return addr;
182 }
183
184 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
185 index e5288638a1d9..378a754ca186 100644
186 --- a/arch/parisc/kernel/sys_parisc.c
187 +++ b/arch/parisc/kernel/sys_parisc.c
188 @@ -90,7 +90,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
189 unsigned long len, unsigned long pgoff, unsigned long flags)
190 {
191 struct mm_struct *mm = current->mm;
192 - struct vm_area_struct *vma;
193 + struct vm_area_struct *vma, *prev;
194 unsigned long task_size = TASK_SIZE;
195 int do_color_align, last_mmap;
196 struct vm_unmapped_area_info info;
197 @@ -117,9 +117,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
198 else
199 addr = PAGE_ALIGN(addr);
200
201 - vma = find_vma(mm, addr);
202 + vma = find_vma_prev(mm, addr, &prev);
203 if (task_size - len >= addr &&
204 - (!vma || addr + len <= vma->vm_start))
205 + (!vma || addr + len <= vm_start_gap(vma)) &&
206 + (!prev || addr >= vm_end_gap(prev)))
207 goto found_addr;
208 }
209
210 @@ -143,7 +144,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
211 const unsigned long len, const unsigned long pgoff,
212 const unsigned long flags)
213 {
214 - struct vm_area_struct *vma;
215 + struct vm_area_struct *vma, *prev;
216 struct mm_struct *mm = current->mm;
217 unsigned long addr = addr0;
218 int do_color_align, last_mmap;
219 @@ -177,9 +178,11 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
220 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
221 else
222 addr = PAGE_ALIGN(addr);
223 - vma = find_vma(mm, addr);
224 +
225 + vma = find_vma_prev(mm, addr, &prev);
226 if (TASK_SIZE - len >= addr &&
227 - (!vma || addr + len <= vma->vm_start))
228 + (!vma || addr + len <= vm_start_gap(vma)) &&
229 + (!prev || addr >= vm_end_gap(prev)))
230 goto found_addr;
231 }
232
233 diff --git a/arch/powerpc/mm/dump_linuxpagetables.c b/arch/powerpc/mm/dump_linuxpagetables.c
234 index 292214afe0f1..e1b6c8bf0627 100644
235 --- a/arch/powerpc/mm/dump_linuxpagetables.c
236 +++ b/arch/powerpc/mm/dump_linuxpagetables.c
237 @@ -57,6 +57,8 @@ struct pg_state {
238 struct seq_file *seq;
239 const struct addr_marker *marker;
240 unsigned long start_address;
241 + unsigned long start_pa;
242 + unsigned long last_pa;
243 unsigned int level;
244 u64 current_flags;
245 };
246 @@ -253,7 +255,9 @@ static void dump_addr(struct pg_state *st, unsigned long addr)
247 const char *unit = units;
248 unsigned long delta;
249
250 - seq_printf(st->seq, "0x%016lx-0x%016lx ", st->start_address, addr-1);
251 + seq_printf(st->seq, "0x%016lx-0x%016lx ", st->start_address, addr-1);
252 + seq_printf(st->seq, "0x%016lx ", st->start_pa);
253 +
254 delta = (addr - st->start_address) >> 10;
255 /* Work out what appropriate unit to use */
256 while (!(delta & 1023) && unit[1]) {
257 @@ -268,11 +272,15 @@ static void note_page(struct pg_state *st, unsigned long addr,
258 unsigned int level, u64 val)
259 {
260 u64 flag = val & pg_level[level].mask;
261 + u64 pa = val & PTE_RPN_MASK;
262 +
263 /* At first no level is set */
264 if (!st->level) {
265 st->level = level;
266 st->current_flags = flag;
267 st->start_address = addr;
268 + st->start_pa = pa;
269 + st->last_pa = pa;
270 seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
271 /*
272 * Dump the section of virtual memory when:
273 @@ -280,9 +288,11 @@ static void note_page(struct pg_state *st, unsigned long addr,
274 * - we change levels in the tree.
275 * - the address is in a different section of memory and is thus
276 * used for a different purpose, regardless of the flags.
277 + * - the pa of this page is not adjacent to the last inspected page
278 */
279 } else if (flag != st->current_flags || level != st->level ||
280 - addr >= st->marker[1].start_address) {
281 + addr >= st->marker[1].start_address ||
282 + pa != st->last_pa + PAGE_SIZE) {
283
284 /* Check the PTE flags */
285 if (st->current_flags) {
286 @@ -306,8 +316,12 @@ static void note_page(struct pg_state *st, unsigned long addr,
287 seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
288 }
289 st->start_address = addr;
290 + st->start_pa = pa;
291 + st->last_pa = pa;
292 st->current_flags = flag;
293 st->level = level;
294 + } else {
295 + st->last_pa = pa;
296 }
297 }
298
299 diff --git a/arch/powerpc/mm/hugetlbpage-radix.c b/arch/powerpc/mm/hugetlbpage-radix.c
300 index 35254a678456..a2b2d97f7eda 100644
301 --- a/arch/powerpc/mm/hugetlbpage-radix.c
302 +++ b/arch/powerpc/mm/hugetlbpage-radix.c
303 @@ -65,7 +65,7 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
304 addr = ALIGN(addr, huge_page_size(h));
305 vma = find_vma(mm, addr);
306 if (TASK_SIZE - len >= addr &&
307 - (!vma || addr + len <= vma->vm_start))
308 + (!vma || addr + len <= vm_start_gap(vma)))
309 return addr;
310 }
311 /*
312 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
313 index a5d9ef59debe..04a6493b68ad 100644
314 --- a/arch/powerpc/mm/mmap.c
315 +++ b/arch/powerpc/mm/mmap.c
316 @@ -107,7 +107,7 @@ radix__arch_get_unmapped_area(struct file *filp, unsigned long addr,
317 addr = PAGE_ALIGN(addr);
318 vma = find_vma(mm, addr);
319 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
320 - (!vma || addr + len <= vma->vm_start))
321 + (!vma || addr + len <= vm_start_gap(vma)))
322 return addr;
323 }
324
325 @@ -143,7 +143,7 @@ radix__arch_get_unmapped_area_topdown(struct file *filp,
326 addr = PAGE_ALIGN(addr);
327 vma = find_vma(mm, addr);
328 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
329 - (!vma || addr + len <= vma->vm_start))
330 + (!vma || addr + len <= vm_start_gap(vma)))
331 return addr;
332 }
333
334 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
335 index 2b27458902ee..c4d5c9c61e0f 100644
336 --- a/arch/powerpc/mm/slice.c
337 +++ b/arch/powerpc/mm/slice.c
338 @@ -105,7 +105,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
339 if ((mm->task_size - len) < addr)
340 return 0;
341 vma = find_vma(mm, addr);
342 - return (!vma || (addr + len) <= vma->vm_start);
343 + return (!vma || (addr + len) <= vm_start_gap(vma));
344 }
345
346 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
347 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
348 index 50618614881f..531e9d5f803a 100644
349 --- a/arch/s390/mm/mmap.c
350 +++ b/arch/s390/mm/mmap.c
351 @@ -100,7 +100,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
352 addr = PAGE_ALIGN(addr);
353 vma = find_vma(mm, addr);
354 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
355 - (!vma || addr + len <= vma->vm_start))
356 + (!vma || addr + len <= vm_start_gap(vma)))
357 return addr;
358 }
359
360 @@ -138,7 +138,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
361 addr = PAGE_ALIGN(addr);
362 vma = find_vma(mm, addr);
363 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
364 - (!vma || addr + len <= vma->vm_start))
365 + (!vma || addr + len <= vm_start_gap(vma)))
366 return addr;
367 }
368
369 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
370 index 08e7af0be4a7..6a1a1297baae 100644
371 --- a/arch/sh/mm/mmap.c
372 +++ b/arch/sh/mm/mmap.c
373 @@ -64,7 +64,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
374
375 vma = find_vma(mm, addr);
376 if (TASK_SIZE - len >= addr &&
377 - (!vma || addr + len <= vma->vm_start))
378 + (!vma || addr + len <= vm_start_gap(vma)))
379 return addr;
380 }
381
382 @@ -114,7 +114,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
383
384 vma = find_vma(mm, addr);
385 if (TASK_SIZE - len >= addr &&
386 - (!vma || addr + len <= vma->vm_start))
387 + (!vma || addr + len <= vm_start_gap(vma)))
388 return addr;
389 }
390
391 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
392 index ef4520efc813..043544d0cda3 100644
393 --- a/arch/sparc/kernel/sys_sparc_64.c
394 +++ b/arch/sparc/kernel/sys_sparc_64.c
395 @@ -120,7 +120,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
396
397 vma = find_vma(mm, addr);
398 if (task_size - len >= addr &&
399 - (!vma || addr + len <= vma->vm_start))
400 + (!vma || addr + len <= vm_start_gap(vma)))
401 return addr;
402 }
403
404 @@ -183,7 +183,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
405
406 vma = find_vma(mm, addr);
407 if (task_size - len >= addr &&
408 - (!vma || addr + len <= vma->vm_start))
409 + (!vma || addr + len <= vm_start_gap(vma)))
410 return addr;
411 }
412
413 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
414 index 7c29d38e6b99..88855e383b34 100644
415 --- a/arch/sparc/mm/hugetlbpage.c
416 +++ b/arch/sparc/mm/hugetlbpage.c
417 @@ -120,7 +120,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
418 addr = ALIGN(addr, huge_page_size(h));
419 vma = find_vma(mm, addr);
420 if (task_size - len >= addr &&
421 - (!vma || addr + len <= vma->vm_start))
422 + (!vma || addr + len <= vm_start_gap(vma)))
423 return addr;
424 }
425 if (mm->get_unmapped_area == arch_get_unmapped_area)
426 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
427 index cb10153b5c9f..03e5cc4e76e4 100644
428 --- a/arch/tile/mm/hugetlbpage.c
429 +++ b/arch/tile/mm/hugetlbpage.c
430 @@ -233,7 +233,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
431 addr = ALIGN(addr, huge_page_size(h));
432 vma = find_vma(mm, addr);
433 if (TASK_SIZE - len >= addr &&
434 - (!vma || addr + len <= vma->vm_start))
435 + (!vma || addr + len <= vm_start_gap(vma)))
436 return addr;
437 }
438 if (current->mm->get_unmapped_area == arch_get_unmapped_area)
439 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
440 index 50215a4b9347..3123e6d00a1b 100644
441 --- a/arch/x86/kernel/sys_x86_64.c
442 +++ b/arch/x86/kernel/sys_x86_64.c
443 @@ -141,7 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
444 addr = PAGE_ALIGN(addr);
445 vma = find_vma(mm, addr);
446 if (end - len >= addr &&
447 - (!vma || addr + len <= vma->vm_start))
448 + (!vma || addr + len <= vm_start_gap(vma)))
449 return addr;
450 }
451
452 @@ -184,7 +184,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
453 addr = PAGE_ALIGN(addr);
454 vma = find_vma(mm, addr);
455 if (TASK_SIZE - len >= addr &&
456 - (!vma || addr + len <= vma->vm_start))
457 + (!vma || addr + len <= vm_start_gap(vma)))
458 return addr;
459 }
460
461 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
462 index c5066a260803..7d09827d7083 100644
463 --- a/arch/x86/mm/hugetlbpage.c
464 +++ b/arch/x86/mm/hugetlbpage.c
465 @@ -145,7 +145,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
466 addr = ALIGN(addr, huge_page_size(h));
467 vma = find_vma(mm, addr);
468 if (TASK_SIZE - len >= addr &&
469 - (!vma || addr + len <= vma->vm_start))
470 + (!vma || addr + len <= vm_start_gap(vma)))
471 return addr;
472 }
473 if (mm->get_unmapped_area == arch_get_unmapped_area)
474 diff --git a/arch/x86/mm/numa_32.c b/arch/x86/mm/numa_32.c
475 index 6b7ce6279133..aca6295350f3 100644
476 --- a/arch/x86/mm/numa_32.c
477 +++ b/arch/x86/mm/numa_32.c
478 @@ -100,5 +100,6 @@ void __init initmem_init(void)
479 printk(KERN_DEBUG "High memory starts at vaddr %08lx\n",
480 (ulong) pfn_to_kaddr(highstart_pfn));
481
482 + __vmalloc_start_set = true;
483 setup_bootmem_allocator();
484 }
485 diff --git a/arch/xtensa/kernel/syscall.c b/arch/xtensa/kernel/syscall.c
486 index 06937928cb72..74afbf02d07e 100644
487 --- a/arch/xtensa/kernel/syscall.c
488 +++ b/arch/xtensa/kernel/syscall.c
489 @@ -88,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
490 /* At this point: (!vmm || addr < vmm->vm_end). */
491 if (TASK_SIZE - len < addr)
492 return -ENOMEM;
493 - if (!vmm || addr + len <= vmm->vm_start)
494 + if (!vmm || addr + len <= vm_start_gap(vmm))
495 return addr;
496 addr = vmm->vm_end;
497 if (flags & MAP_SHARED)
498 diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
499 index 992f7c20760f..88220ff3e1c2 100644
500 --- a/drivers/cpufreq/cpufreq_conservative.c
501 +++ b/drivers/cpufreq/cpufreq_conservative.c
502 @@ -185,8 +185,8 @@ static ssize_t store_down_threshold(struct gov_attr_set *attr_set,
503 int ret;
504 ret = sscanf(buf, "%u", &input);
505
506 - /* cannot be lower than 11 otherwise freq will not fall */
507 - if (ret != 1 || input < 11 || input > 100 ||
508 + /* cannot be lower than 1 otherwise freq will not fall */
509 + if (ret != 1 || input < 1 || input > 100 ||
510 input >= dbs_data->up_threshold)
511 return -EINVAL;
512
513 diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
514 index 33541acdf329..b22e5522d630 100644
515 --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
516 +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
517 @@ -1207,8 +1207,11 @@ static void dce_v10_0_program_watermarks(struct amdgpu_device *adev,
518 u32 tmp, wm_mask, lb_vblank_lead_lines = 0;
519
520 if (amdgpu_crtc->base.enabled && num_heads && mode) {
521 - active_time = 1000000UL * (u32)mode->crtc_hdisplay / (u32)mode->clock;
522 - line_time = min((u32) (1000000UL * (u32)mode->crtc_htotal / (u32)mode->clock), (u32)65535);
523 + active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000,
524 + (u32)mode->clock);
525 + line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000,
526 + (u32)mode->clock);
527 + line_time = min(line_time, (u32)65535);
528
529 /* watermark for high clocks */
530 if (adev->pm.dpm_enabled) {
531 diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
532 index 1388f8a44a2b..f2b2b80b63f7 100644
533 --- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
534 +++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
535 @@ -1176,8 +1176,11 @@ static void dce_v11_0_program_watermarks(struct amdgpu_device *adev,
536 u32 tmp, wm_mask, lb_vblank_lead_lines = 0;
537
538 if (amdgpu_crtc->base.enabled && num_heads && mode) {
539 - active_time = 1000000UL * (u32)mode->crtc_hdisplay / (u32)mode->clock;
540 - line_time = min((u32) (1000000UL * (u32)mode->crtc_htotal / (u32)mode->clock), (u32)65535);
541 + active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000,
542 + (u32)mode->clock);
543 + line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000,
544 + (u32)mode->clock);
545 + line_time = min(line_time, (u32)65535);
546
547 /* watermark for high clocks */
548 if (adev->pm.dpm_enabled) {
549 diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
550 index ea5365580b2d..89a8113e42e5 100644
551 --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
552 +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
553 @@ -983,8 +983,11 @@ static void dce_v6_0_program_watermarks(struct amdgpu_device *adev,
554 fixed20_12 a, b, c;
555
556 if (amdgpu_crtc->base.enabled && num_heads && mode) {
557 - active_time = 1000000UL * (u32)mode->crtc_hdisplay / (u32)mode->clock;
558 - line_time = min((u32) (1000000UL * (u32)mode->crtc_htotal / (u32)mode->clock), (u32)65535);
559 + active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000,
560 + (u32)mode->clock);
561 + line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000,
562 + (u32)mode->clock);
563 + line_time = min(line_time, (u32)65535);
564 priority_a_cnt = 0;
565 priority_b_cnt = 0;
566
567 diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
568 index e52fc925b414..daf8e381c563 100644
569 --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
570 +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
571 @@ -1091,8 +1091,11 @@ static void dce_v8_0_program_watermarks(struct amdgpu_device *adev,
572 u32 tmp, wm_mask, lb_vblank_lead_lines = 0;
573
574 if (amdgpu_crtc->base.enabled && num_heads && mode) {
575 - active_time = 1000000UL * (u32)mode->crtc_hdisplay / (u32)mode->clock;
576 - line_time = min((u32) (1000000UL * (u32)mode->crtc_htotal / (u32)mode->clock), (u32)65535);
577 + active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000,
578 + (u32)mode->clock);
579 + line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000,
580 + (u32)mode->clock);
581 + line_time = min(line_time, (u32)65535);
582
583 /* watermark for high clocks */
584 if (adev->pm.dpm_enabled) {
585 diff --git a/drivers/gpu/drm/i915/i915_gem_shrinker.c b/drivers/gpu/drm/i915/i915_gem_shrinker.c
586 index 70b3832a79dd..a08c2b47fbb3 100644
587 --- a/drivers/gpu/drm/i915/i915_gem_shrinker.c
588 +++ b/drivers/gpu/drm/i915/i915_gem_shrinker.c
589 @@ -59,9 +59,6 @@ static void i915_gem_shrinker_unlock(struct drm_device *dev, bool unlock)
590 return;
591
592 mutex_unlock(&dev->struct_mutex);
593 -
594 - /* expedite the RCU grace period to free some request slabs */
595 - synchronize_rcu_expedited();
596 }
597
598 static bool any_vma_pinned(struct drm_i915_gem_object *obj)
599 @@ -271,8 +268,6 @@ unsigned long i915_gem_shrink_all(struct drm_i915_private *dev_priv)
600 I915_SHRINK_BOUND |
601 I915_SHRINK_UNBOUND |
602 I915_SHRINK_ACTIVE);
603 - synchronize_rcu(); /* wait for our earlier RCU delayed slab frees */
604 -
605 return freed;
606 }
607
608 diff --git a/drivers/gpu/drm/i915/i915_pvinfo.h b/drivers/gpu/drm/i915/i915_pvinfo.h
609 index c0cb2974caac..2cfe96d3e5d1 100644
610 --- a/drivers/gpu/drm/i915/i915_pvinfo.h
611 +++ b/drivers/gpu/drm/i915/i915_pvinfo.h
612 @@ -36,10 +36,6 @@
613 #define VGT_VERSION_MAJOR 1
614 #define VGT_VERSION_MINOR 0
615
616 -#define INTEL_VGT_IF_VERSION_ENCODE(major, minor) ((major) << 16 | (minor))
617 -#define INTEL_VGT_IF_VERSION \
618 - INTEL_VGT_IF_VERSION_ENCODE(VGT_VERSION_MAJOR, VGT_VERSION_MINOR)
619 -
620 /*
621 * notifications from guest to vgpu device model
622 */
623 @@ -55,8 +51,8 @@ enum vgt_g2v_type {
624
625 struct vgt_if {
626 u64 magic; /* VGT_MAGIC */
627 - uint16_t version_major;
628 - uint16_t version_minor;
629 + u16 version_major;
630 + u16 version_minor;
631 u32 vgt_id; /* ID of vGT instance */
632 u32 rsv1[12]; /* pad to offset 0x40 */
633 /*
634 diff --git a/drivers/gpu/drm/i915/i915_vgpu.c b/drivers/gpu/drm/i915/i915_vgpu.c
635 index d0abfd08a01c..2c782510618f 100644
636 --- a/drivers/gpu/drm/i915/i915_vgpu.c
637 +++ b/drivers/gpu/drm/i915/i915_vgpu.c
638 @@ -60,8 +60,8 @@
639 */
640 void i915_check_vgpu(struct drm_i915_private *dev_priv)
641 {
642 - uint64_t magic;
643 - uint32_t version;
644 + u64 magic;
645 + u16 version_major;
646
647 BUILD_BUG_ON(sizeof(struct vgt_if) != VGT_PVINFO_SIZE);
648
649 @@ -69,10 +69,8 @@ void i915_check_vgpu(struct drm_i915_private *dev_priv)
650 if (magic != VGT_MAGIC)
651 return;
652
653 - version = INTEL_VGT_IF_VERSION_ENCODE(
654 - __raw_i915_read16(dev_priv, vgtif_reg(version_major)),
655 - __raw_i915_read16(dev_priv, vgtif_reg(version_minor)));
656 - if (version != INTEL_VGT_IF_VERSION) {
657 + version_major = __raw_i915_read16(dev_priv, vgtif_reg(version_major));
658 + if (version_major < VGT_VERSION_MAJOR) {
659 DRM_INFO("VGT interface version mismatch!\n");
660 return;
661 }
662 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
663 index 5370dbec7a7d..24cee1d6754c 100644
664 --- a/drivers/gpu/drm/i915/intel_display.c
665 +++ b/drivers/gpu/drm/i915/intel_display.c
666 @@ -4633,7 +4633,7 @@ static void cpt_verify_modeset(struct drm_device *dev, int pipe)
667
668 static int
669 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
670 - unsigned scaler_user, int *scaler_id, unsigned int rotation,
671 + unsigned int scaler_user, int *scaler_id,
672 int src_w, int src_h, int dst_w, int dst_h)
673 {
674 struct intel_crtc_scaler_state *scaler_state =
675 @@ -4642,9 +4642,12 @@ skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
676 to_intel_crtc(crtc_state->base.crtc);
677 int need_scaling;
678
679 - need_scaling = drm_rotation_90_or_270(rotation) ?
680 - (src_h != dst_w || src_w != dst_h):
681 - (src_w != dst_w || src_h != dst_h);
682 + /*
683 + * Src coordinates are already rotated by 270 degrees for
684 + * the 90/270 degree plane rotation cases (to match the
685 + * GTT mapping), hence no need to account for rotation here.
686 + */
687 + need_scaling = src_w != dst_w || src_h != dst_h;
688
689 /*
690 * if plane is being disabled or scaler is no more required or force detach
691 @@ -4706,7 +4709,7 @@ int skl_update_scaler_crtc(struct intel_crtc_state *state)
692 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
693
694 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
695 - &state->scaler_state.scaler_id, DRM_ROTATE_0,
696 + &state->scaler_state.scaler_id,
697 state->pipe_src_w, state->pipe_src_h,
698 adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay);
699 }
700 @@ -4735,7 +4738,6 @@ static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
701 ret = skl_update_scaler(crtc_state, force_detach,
702 drm_plane_index(&intel_plane->base),
703 &plane_state->scaler_id,
704 - plane_state->base.rotation,
705 drm_rect_width(&plane_state->base.src) >> 16,
706 drm_rect_height(&plane_state->base.src) >> 16,
707 drm_rect_width(&plane_state->base.dst),
708 diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c
709 index c26251260b83..b43aa29d3dac 100644
710 --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c
711 +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c
712 @@ -1062,7 +1062,7 @@ static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi,
713 }
714
715 err = hdmi_vendor_infoframe_pack(&frame, buffer, sizeof(buffer));
716 - if (err) {
717 + if (err < 0) {
718 dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n",
719 err);
720 return err;
721 diff --git a/drivers/gpu/drm/mxsfb/mxsfb_crtc.c b/drivers/gpu/drm/mxsfb/mxsfb_crtc.c
722 index 1144e0c9e894..0abe77675b76 100644
723 --- a/drivers/gpu/drm/mxsfb/mxsfb_crtc.c
724 +++ b/drivers/gpu/drm/mxsfb/mxsfb_crtc.c
725 @@ -35,6 +35,13 @@
726 #include "mxsfb_drv.h"
727 #include "mxsfb_regs.h"
728
729 +#define MXS_SET_ADDR 0x4
730 +#define MXS_CLR_ADDR 0x8
731 +#define MODULE_CLKGATE BIT(30)
732 +#define MODULE_SFTRST BIT(31)
733 +/* 1 second delay should be plenty of time for block reset */
734 +#define RESET_TIMEOUT 1000000
735 +
736 static u32 set_hsync_pulse_width(struct mxsfb_drm_private *mxsfb, u32 val)
737 {
738 return (val & mxsfb->devdata->hs_wdth_mask) <<
739 @@ -159,6 +166,36 @@ static void mxsfb_disable_controller(struct mxsfb_drm_private *mxsfb)
740 clk_disable_unprepare(mxsfb->clk_disp_axi);
741 }
742
743 +/*
744 + * Clear the bit and poll it cleared. This is usually called with
745 + * a reset address and mask being either SFTRST(bit 31) or CLKGATE
746 + * (bit 30).
747 + */
748 +static int clear_poll_bit(void __iomem *addr, u32 mask)
749 +{
750 + u32 reg;
751 +
752 + writel(mask, addr + MXS_CLR_ADDR);
753 + return readl_poll_timeout(addr, reg, !(reg & mask), 0, RESET_TIMEOUT);
754 +}
755 +
756 +static int mxsfb_reset_block(void __iomem *reset_addr)
757 +{
758 + int ret;
759 +
760 + ret = clear_poll_bit(reset_addr, MODULE_SFTRST);
761 + if (ret)
762 + return ret;
763 +
764 + writel(MODULE_CLKGATE, reset_addr + MXS_CLR_ADDR);
765 +
766 + ret = clear_poll_bit(reset_addr, MODULE_SFTRST);
767 + if (ret)
768 + return ret;
769 +
770 + return clear_poll_bit(reset_addr, MODULE_CLKGATE);
771 +}
772 +
773 static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
774 {
775 struct drm_display_mode *m = &mxsfb->pipe.crtc.state->adjusted_mode;
776 @@ -173,6 +210,11 @@ static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
777 */
778 mxsfb_enable_axi_clk(mxsfb);
779
780 + /* Mandatory eLCDIF reset as per the Reference Manual */
781 + err = mxsfb_reset_block(mxsfb->base);
782 + if (err)
783 + return;
784 +
785 /* Clear the FIFOs */
786 writel(CTRL1_FIFO_CLEAR, mxsfb->base + LCDC_CTRL1 + REG_SET);
787
788 diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
789 index 3f6704cf6608..ec9023bd935b 100644
790 --- a/drivers/gpu/drm/vc4/vc4_bo.c
791 +++ b/drivers/gpu/drm/vc4/vc4_bo.c
792 @@ -313,6 +313,14 @@ void vc4_free_object(struct drm_gem_object *gem_bo)
793 goto out;
794 }
795
796 + /* If this object was partially constructed but CMA allocation
797 + * had failed, just free it.
798 + */
799 + if (!bo->base.vaddr) {
800 + vc4_bo_destroy(bo);
801 + goto out;
802 + }
803 +
804 cache_list = vc4_get_cache_list_for_size(dev, gem_bo->size);
805 if (!cache_list) {
806 vc4_bo_destroy(bo);
807 diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
808 index 89def6034f40..115445dce6f4 100644
809 --- a/drivers/iio/adc/meson_saradc.c
810 +++ b/drivers/iio/adc/meson_saradc.c
811 @@ -440,13 +440,13 @@ static void meson_sar_adc_unlock(struct iio_dev *indio_dev)
812 static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
813 {
814 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
815 - int count;
816 + unsigned int count, tmp;
817
818 for (count = 0; count < MESON_SAR_ADC_MAX_FIFO_SIZE; count++) {
819 if (!meson_sar_adc_get_fifo_count(indio_dev))
820 break;
821
822 - regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, 0);
823 + regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, &tmp);
824 }
825 }
826
827 diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
828 index 4282ceca3d8f..6cbed7eb118a 100644
829 --- a/drivers/iio/adc/ti_am335x_adc.c
830 +++ b/drivers/iio/adc/ti_am335x_adc.c
831 @@ -614,7 +614,7 @@ static int tiadc_probe(struct platform_device *pdev)
832 return -EINVAL;
833 }
834
835 - indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*indio_dev));
836 + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc_dev));
837 if (indio_dev == NULL) {
838 dev_err(&pdev->dev, "failed to allocate iio device\n");
839 return -ENOMEM;
840 diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
841 index b9fcbf18aa99..5faea370ab57 100644
842 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
843 +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
844 @@ -41,6 +41,7 @@ static const int accel_scale[] = {598, 1196, 2392, 4785};
845 static const struct inv_mpu6050_reg_map reg_set_6500 = {
846 .sample_rate_div = INV_MPU6050_REG_SAMPLE_RATE_DIV,
847 .lpf = INV_MPU6050_REG_CONFIG,
848 + .accel_lpf = INV_MPU6500_REG_ACCEL_CONFIG_2,
849 .user_ctrl = INV_MPU6050_REG_USER_CTRL,
850 .fifo_en = INV_MPU6050_REG_FIFO_EN,
851 .gyro_config = INV_MPU6050_REG_GYRO_CONFIG,
852 @@ -205,6 +206,37 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on)
853 EXPORT_SYMBOL_GPL(inv_mpu6050_set_power_itg);
854
855 /**
856 + * inv_mpu6050_set_lpf_regs() - set low pass filter registers, chip dependent
857 + *
858 + * MPU60xx/MPU9150 use only 1 register for accelerometer + gyroscope
859 + * MPU6500 and above have a dedicated register for accelerometer
860 + */
861 +static int inv_mpu6050_set_lpf_regs(struct inv_mpu6050_state *st,
862 + enum inv_mpu6050_filter_e val)
863 +{
864 + int result;
865 +
866 + result = regmap_write(st->map, st->reg->lpf, val);
867 + if (result)
868 + return result;
869 +
870 + switch (st->chip_type) {
871 + case INV_MPU6050:
872 + case INV_MPU6000:
873 + case INV_MPU9150:
874 + /* old chips, nothing to do */
875 + result = 0;
876 + break;
877 + default:
878 + /* set accel lpf */
879 + result = regmap_write(st->map, st->reg->accel_lpf, val);
880 + break;
881 + }
882 +
883 + return result;
884 +}
885 +
886 +/**
887 * inv_mpu6050_init_config() - Initialize hardware, disable FIFO.
888 *
889 * Initial configuration:
890 @@ -227,8 +259,7 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)
891 if (result)
892 return result;
893
894 - d = INV_MPU6050_FILTER_20HZ;
895 - result = regmap_write(st->map, st->reg->lpf, d);
896 + result = inv_mpu6050_set_lpf_regs(st, INV_MPU6050_FILTER_20HZ);
897 if (result)
898 return result;
899
900 @@ -531,6 +562,8 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
901 * would be alising. This function basically search for the
902 * correct low pass parameters based on the fifo rate, e.g,
903 * sampling frequency.
904 + *
905 + * lpf is set automatically when setting sampling rate to avoid any aliases.
906 */
907 static int inv_mpu6050_set_lpf(struct inv_mpu6050_state *st, int rate)
908 {
909 @@ -546,7 +579,7 @@ static int inv_mpu6050_set_lpf(struct inv_mpu6050_state *st, int rate)
910 while ((h < hz[i]) && (i < ARRAY_SIZE(d) - 1))
911 i++;
912 data = d[i];
913 - result = regmap_write(st->map, st->reg->lpf, data);
914 + result = inv_mpu6050_set_lpf_regs(st, data);
915 if (result)
916 return result;
917 st->chip_config.lpf = data;
918 diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
919 index f0e8c5dd9fae..d851581bb0b8 100644
920 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
921 +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
922 @@ -28,6 +28,7 @@
923 * struct inv_mpu6050_reg_map - Notable registers.
924 * @sample_rate_div: Divider applied to gyro output rate.
925 * @lpf: Configures internal low pass filter.
926 + * @accel_lpf: Configures accelerometer low pass filter.
927 * @user_ctrl: Enables/resets the FIFO.
928 * @fifo_en: Determines which data will appear in FIFO.
929 * @gyro_config: gyro config register.
930 @@ -47,6 +48,7 @@
931 struct inv_mpu6050_reg_map {
932 u8 sample_rate_div;
933 u8 lpf;
934 + u8 accel_lpf;
935 u8 user_ctrl;
936 u8 fifo_en;
937 u8 gyro_config;
938 @@ -187,6 +189,7 @@ struct inv_mpu6050_state {
939 #define INV_MPU6050_FIFO_THRESHOLD 500
940
941 /* mpu6500 registers */
942 +#define INV_MPU6500_REG_ACCEL_CONFIG_2 0x1D
943 #define INV_MPU6500_REG_ACCEL_OFFSET 0x77
944
945 /* delay time in milliseconds */
946 diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
947 index c92ddcc190e2..463196668c6b 100644
948 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
949 +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
950 @@ -298,32 +298,40 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
951 return 0;
952 }
953
954 -static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
955 +static int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr,
956 + u8 *val)
957 {
958 - enum st_lsm6dsx_sensor_id id = sensor->id;
959 - int i, err;
960 - u8 val;
961 + int i;
962
963 for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
964 - if (st_lsm6dsx_odr_table[id].odr_avl[i].hz == odr)
965 + if (st_lsm6dsx_odr_table[sensor->id].odr_avl[i].hz == odr)
966 break;
967
968 if (i == ST_LSM6DSX_ODR_LIST_SIZE)
969 return -EINVAL;
970
971 - val = st_lsm6dsx_odr_table[id].odr_avl[i].val;
972 - err = st_lsm6dsx_write_with_mask(sensor->hw,
973 - st_lsm6dsx_odr_table[id].reg.addr,
974 - st_lsm6dsx_odr_table[id].reg.mask,
975 - val);
976 - if (err < 0)
977 - return err;
978 -
979 + *val = st_lsm6dsx_odr_table[sensor->id].odr_avl[i].val;
980 sensor->odr = odr;
981
982 return 0;
983 }
984
985 +static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
986 +{
987 + enum st_lsm6dsx_sensor_id id = sensor->id;
988 + int err;
989 + u8 val;
990 +
991 + err = st_lsm6dsx_check_odr(sensor, odr, &val);
992 + if (err < 0)
993 + return err;
994 +
995 + return st_lsm6dsx_write_with_mask(sensor->hw,
996 + st_lsm6dsx_odr_table[id].reg.addr,
997 + st_lsm6dsx_odr_table[id].reg.mask,
998 + val);
999 +}
1000 +
1001 int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor)
1002 {
1003 int err;
1004 @@ -426,9 +434,12 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
1005 case IIO_CHAN_INFO_SCALE:
1006 err = st_lsm6dsx_set_full_scale(sensor, val2);
1007 break;
1008 - case IIO_CHAN_INFO_SAMP_FREQ:
1009 - err = st_lsm6dsx_set_odr(sensor, val);
1010 + case IIO_CHAN_INFO_SAMP_FREQ: {
1011 + u8 data;
1012 +
1013 + err = st_lsm6dsx_check_odr(sensor, val, &data);
1014 break;
1015 + }
1016 default:
1017 err = -EINVAL;
1018 break;
1019 diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
1020 index 268210ea4990..24fb54398a3b 100644
1021 --- a/drivers/iio/proximity/as3935.c
1022 +++ b/drivers/iio/proximity/as3935.c
1023 @@ -269,8 +269,6 @@ static irqreturn_t as3935_interrupt_handler(int irq, void *private)
1024
1025 static void calibrate_as3935(struct as3935_state *st)
1026 {
1027 - mutex_lock(&st->lock);
1028 -
1029 /* mask disturber interrupt bit */
1030 as3935_write(st, AS3935_INT, BIT(5));
1031
1032 @@ -280,8 +278,6 @@ static void calibrate_as3935(struct as3935_state *st)
1033
1034 mdelay(2);
1035 as3935_write(st, AS3935_TUNE_CAP, (st->tune_cap / TUNE_CAP_DIV));
1036 -
1037 - mutex_unlock(&st->lock);
1038 }
1039
1040 #ifdef CONFIG_PM_SLEEP
1041 @@ -318,6 +314,8 @@ static int as3935_resume(struct device *dev)
1042 val &= ~AS3935_AFE_PWR_BIT;
1043 ret = as3935_write(st, AS3935_AFE_GAIN, val);
1044
1045 + calibrate_as3935(st);
1046 +
1047 err_resume:
1048 mutex_unlock(&st->lock);
1049
1050 diff --git a/drivers/media/cec/cec-api.c b/drivers/media/cec/cec-api.c
1051 index 8950b6c9d6a9..4cd65751cb63 100644
1052 --- a/drivers/media/cec/cec-api.c
1053 +++ b/drivers/media/cec/cec-api.c
1054 @@ -267,16 +267,10 @@ static long cec_receive(struct cec_adapter *adap, struct cec_fh *fh,
1055 bool block, struct cec_msg __user *parg)
1056 {
1057 struct cec_msg msg = {};
1058 - long err = 0;
1059 + long err;
1060
1061 if (copy_from_user(&msg, parg, sizeof(msg)))
1062 return -EFAULT;
1063 - mutex_lock(&adap->lock);
1064 - if (!adap->is_configured && fh->mode_follower < CEC_MODE_MONITOR)
1065 - err = -ENONET;
1066 - mutex_unlock(&adap->lock);
1067 - if (err)
1068 - return err;
1069
1070 err = cec_receive_msg(fh, &msg, block);
1071 if (err)
1072 diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
1073 index eb6548f46cba..5024b460fb66 100644
1074 --- a/drivers/media/platform/coda/coda-common.c
1075 +++ b/drivers/media/platform/coda/coda-common.c
1076 @@ -2126,7 +2126,12 @@ static void coda_fw_callback(const struct firmware *fw, void *context);
1077
1078 static int coda_firmware_request(struct coda_dev *dev)
1079 {
1080 - char *fw = dev->devtype->firmware[dev->firmware];
1081 + char *fw;
1082 +
1083 + if (dev->firmware >= ARRAY_SIZE(dev->devtype->firmware))
1084 + return -EINVAL;
1085 +
1086 + fw = dev->devtype->firmware[dev->firmware];
1087
1088 dev_dbg(&dev->plat_dev->dev, "requesting firmware '%s' for %s\n", fw,
1089 coda_product_name(dev->devtype->product));
1090 @@ -2142,16 +2147,16 @@ static void coda_fw_callback(const struct firmware *fw, void *context)
1091 struct platform_device *pdev = dev->plat_dev;
1092 int i, ret;
1093
1094 - if (!fw && dev->firmware == 1) {
1095 - v4l2_err(&dev->v4l2_dev, "firmware request failed\n");
1096 - goto put_pm;
1097 - }
1098 if (!fw) {
1099 - dev->firmware = 1;
1100 - coda_firmware_request(dev);
1101 + dev->firmware++;
1102 + ret = coda_firmware_request(dev);
1103 + if (ret < 0) {
1104 + v4l2_err(&dev->v4l2_dev, "firmware request failed\n");
1105 + goto put_pm;
1106 + }
1107 return;
1108 }
1109 - if (dev->firmware == 1) {
1110 + if (dev->firmware > 0) {
1111 /*
1112 * Since we can't suppress warnings for failed asynchronous
1113 * firmware requests, report that the fallback firmware was
1114 diff --git a/drivers/media/usb/pvrusb2/pvrusb2-eeprom.c b/drivers/media/usb/pvrusb2/pvrusb2-eeprom.c
1115 index 4af2fb5c85d5..7252f113df2f 100644
1116 --- a/drivers/media/usb/pvrusb2/pvrusb2-eeprom.c
1117 +++ b/drivers/media/usb/pvrusb2/pvrusb2-eeprom.c
1118 @@ -118,15 +118,10 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
1119 memset(&tvdata,0,sizeof(tvdata));
1120
1121 eeprom = pvr2_eeprom_fetch(hdw);
1122 - if (!eeprom) return -EINVAL;
1123 -
1124 - {
1125 - struct i2c_client fake_client;
1126 - /* Newer version expects a useless client interface */
1127 - fake_client.addr = hdw->eeprom_addr;
1128 - fake_client.adapter = &hdw->i2c_adap;
1129 - tveeprom_hauppauge_analog(&fake_client,&tvdata,eeprom);
1130 - }
1131 + if (!eeprom)
1132 + return -EINVAL;
1133 +
1134 + tveeprom_hauppauge_analog(NULL, &tvdata, eeprom);
1135
1136 trace_eeprom("eeprom assumed v4l tveeprom module");
1137 trace_eeprom("eeprom direct call results:");
1138 diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
1139 index 7c1d390ea438..28e1bf64923e 100644
1140 --- a/drivers/media/v4l2-core/videobuf2-core.c
1141 +++ b/drivers/media/v4l2-core/videobuf2-core.c
1142 @@ -868,7 +868,7 @@ EXPORT_SYMBOL_GPL(vb2_core_create_bufs);
1143
1144 void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no)
1145 {
1146 - if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
1147 + if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
1148 return NULL;
1149
1150 return call_ptr_memop(vb, vaddr, vb->planes[plane_no].mem_priv);
1151 diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
1152 index 25115fe2acdf..05129004ed90 100644
1153 --- a/drivers/mfd/axp20x.c
1154 +++ b/drivers/mfd/axp20x.c
1155 @@ -31,6 +31,7 @@
1156
1157 #define AXP20X_OFF 0x80
1158
1159 +#define AXP806_REG_ADDR_EXT_ADDR_MASTER_MODE 0
1160 #define AXP806_REG_ADDR_EXT_ADDR_SLAVE_MODE BIT(4)
1161
1162 static const char * const axp20x_model_names[] = {
1163 @@ -877,15 +878,19 @@ int axp20x_device_probe(struct axp20x_dev *axp20x)
1164 * the these device addressing bits (in the upper 4 bits of the
1165 * registers) match.
1166 *
1167 - * Since we only support an AXP806 chained to an AXP809 in slave
1168 - * mode, and there isn't any existing hardware which uses AXP806
1169 - * in master mode, or has 2 AXP806s in the same system, we can
1170 - * just program the register address extension to the slave mode
1171 - * address.
1172 + * By default we support an AXP806 chained to an AXP809 in slave
1173 + * mode. Boards which use an AXP806 in master mode can set the
1174 + * property "x-powers,master-mode" to override the default.
1175 */
1176 - if (axp20x->variant == AXP806_ID)
1177 - regmap_write(axp20x->regmap, AXP806_REG_ADDR_EXT,
1178 - AXP806_REG_ADDR_EXT_ADDR_SLAVE_MODE);
1179 + if (axp20x->variant == AXP806_ID) {
1180 + if (of_property_read_bool(axp20x->dev->of_node,
1181 + "x-powers,master-mode"))
1182 + regmap_write(axp20x->regmap, AXP806_REG_ADDR_EXT,
1183 + AXP806_REG_ADDR_EXT_ADDR_MASTER_MODE);
1184 + else
1185 + regmap_write(axp20x->regmap, AXP806_REG_ADDR_EXT,
1186 + AXP806_REG_ADDR_EXT_ADDR_SLAVE_MODE);
1187 + }
1188
1189 ret = regmap_add_irq_chip(axp20x->regmap, axp20x->irq,
1190 IRQF_ONESHOT | IRQF_SHARED | axp20x->irq_flags,
1191 diff --git a/drivers/mfd/motorola-cpcap.c b/drivers/mfd/motorola-cpcap.c
1192 index 6aeada7d7ce5..bc26079e9737 100644
1193 --- a/drivers/mfd/motorola-cpcap.c
1194 +++ b/drivers/mfd/motorola-cpcap.c
1195 @@ -71,6 +71,7 @@ static struct regmap_irq_chip cpcap_irq_chip[CPCAP_NR_IRQ_CHIPS] = {
1196 .ack_base = CPCAP_REG_MI1,
1197 .mask_base = CPCAP_REG_MIM1,
1198 .use_ack = true,
1199 + .ack_invert = true,
1200 },
1201 {
1202 .name = "cpcap-m2",
1203 @@ -79,6 +80,7 @@ static struct regmap_irq_chip cpcap_irq_chip[CPCAP_NR_IRQ_CHIPS] = {
1204 .ack_base = CPCAP_REG_MI2,
1205 .mask_base = CPCAP_REG_MIM2,
1206 .use_ack = true,
1207 + .ack_invert = true,
1208 },
1209 {
1210 .name = "cpcap1-4",
1211 @@ -86,8 +88,8 @@ static struct regmap_irq_chip cpcap_irq_chip[CPCAP_NR_IRQ_CHIPS] = {
1212 .status_base = CPCAP_REG_INT1,
1213 .ack_base = CPCAP_REG_INT1,
1214 .mask_base = CPCAP_REG_INTM1,
1215 - .type_base = CPCAP_REG_INTS1,
1216 .use_ack = true,
1217 + .ack_invert = true,
1218 },
1219 };
1220
1221 @@ -126,7 +128,7 @@ static int cpcap_init_irq_chip(struct cpcap_ddata *cpcap, int irq_chip,
1222
1223 ret = devm_regmap_add_irq_chip(&cpcap->spi->dev, cpcap->regmap,
1224 cpcap->spi->irq,
1225 - IRQF_TRIGGER_RISING |
1226 + irq_get_trigger_type(cpcap->spi->irq) |
1227 IRQF_SHARED, -1,
1228 chip, &cpcap->irqdata[irq_chip]);
1229 if (ret) {
1230 diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
1231 index 1aa74c4c3ced..9d167c9af2c6 100644
1232 --- a/drivers/mfd/omap-usb-tll.c
1233 +++ b/drivers/mfd/omap-usb-tll.c
1234 @@ -377,8 +377,8 @@ int omap_tll_init(struct usbhs_omap_platform_data *pdata)
1235 * and use SDR Mode
1236 */
1237 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
1238 - | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
1239 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
1240 + reg |= OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF;
1241 } else if (pdata->port_mode[i] ==
1242 OMAP_EHCI_PORT_MODE_HSIC) {
1243 /*
1244 diff --git a/drivers/misc/c2port/c2port-duramar2150.c b/drivers/misc/c2port/c2port-duramar2150.c
1245 index 5484301d57d9..3dc61ea7dc64 100644
1246 --- a/drivers/misc/c2port/c2port-duramar2150.c
1247 +++ b/drivers/misc/c2port/c2port-duramar2150.c
1248 @@ -129,8 +129,8 @@ static int __init duramar2150_c2port_init(void)
1249
1250 duramar2150_c2port_dev = c2port_device_register("uc",
1251 &duramar2150_c2port_ops, NULL);
1252 - if (!duramar2150_c2port_dev) {
1253 - ret = -ENODEV;
1254 + if (IS_ERR(duramar2150_c2port_dev)) {
1255 + ret = PTR_ERR(duramar2150_c2port_dev);
1256 goto free_region;
1257 }
1258
1259 diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
1260 index aef1846b4de2..5a09a72ab112 100644
1261 --- a/drivers/mtd/maps/Makefile
1262 +++ b/drivers/mtd/maps/Makefile
1263 @@ -17,12 +17,10 @@ obj-$(CONFIG_MTD_CK804XROM) += ck804xrom.o
1264 obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o
1265 obj-$(CONFIG_MTD_PXA2XX) += pxa2xx-flash.o
1266 obj-$(CONFIG_MTD_PHYSMAP) += physmap.o
1267 -ifdef CONFIG_MTD_PHYSMAP_OF_VERSATILE
1268 -physmap_of-objs += physmap_of_versatile.o
1269 -endif
1270 -ifdef CONFIG_MTD_PHYSMAP_OF_GEMINI
1271 -physmap_of-objs += physmap_of_gemini.o
1272 -endif
1273 +physmap_of-objs-y += physmap_of_core.o
1274 +physmap_of-objs-$(CONFIG_MTD_PHYSMAP_OF_VERSATILE) += physmap_of_versatile.o
1275 +physmap_of-objs-$(CONFIG_MTD_PHYSMAP_OF_GEMINI) += physmap_of_gemini.o
1276 +physmap_of-objs := $(physmap_of-objs-y)
1277 obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o
1278 obj-$(CONFIG_MTD_PISMO) += pismo.o
1279 obj-$(CONFIG_MTD_PMC_MSP_EVM) += pmcmsp-flash.o
1280 diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
1281 deleted file mode 100644
1282 index 14e8909c9955..000000000000
1283 --- a/drivers/mtd/maps/physmap_of.c
1284 +++ /dev/null
1285 @@ -1,389 +0,0 @@
1286 -/*
1287 - * Flash mappings described by the OF (or flattened) device tree
1288 - *
1289 - * Copyright (C) 2006 MontaVista Software Inc.
1290 - * Author: Vitaly Wool <vwool@ru.mvista.com>
1291 - *
1292 - * Revised to handle newer style flash binding by:
1293 - * Copyright (C) 2007 David Gibson, IBM Corporation.
1294 - *
1295 - * This program is free software; you can redistribute it and/or modify it
1296 - * under the terms of the GNU General Public License as published by the
1297 - * Free Software Foundation; either version 2 of the License, or (at your
1298 - * option) any later version.
1299 - */
1300 -
1301 -#include <linux/module.h>
1302 -#include <linux/types.h>
1303 -#include <linux/device.h>
1304 -#include <linux/mtd/mtd.h>
1305 -#include <linux/mtd/map.h>
1306 -#include <linux/mtd/partitions.h>
1307 -#include <linux/mtd/concat.h>
1308 -#include <linux/of.h>
1309 -#include <linux/of_address.h>
1310 -#include <linux/of_platform.h>
1311 -#include <linux/slab.h>
1312 -#include "physmap_of_gemini.h"
1313 -#include "physmap_of_versatile.h"
1314 -
1315 -struct of_flash_list {
1316 - struct mtd_info *mtd;
1317 - struct map_info map;
1318 - struct resource *res;
1319 -};
1320 -
1321 -struct of_flash {
1322 - struct mtd_info *cmtd;
1323 - int list_size; /* number of elements in of_flash_list */
1324 - struct of_flash_list list[0];
1325 -};
1326 -
1327 -static int of_flash_remove(struct platform_device *dev)
1328 -{
1329 - struct of_flash *info;
1330 - int i;
1331 -
1332 - info = dev_get_drvdata(&dev->dev);
1333 - if (!info)
1334 - return 0;
1335 - dev_set_drvdata(&dev->dev, NULL);
1336 -
1337 - if (info->cmtd) {
1338 - mtd_device_unregister(info->cmtd);
1339 - if (info->cmtd != info->list[0].mtd)
1340 - mtd_concat_destroy(info->cmtd);
1341 - }
1342 -
1343 - for (i = 0; i < info->list_size; i++) {
1344 - if (info->list[i].mtd)
1345 - map_destroy(info->list[i].mtd);
1346 -
1347 - if (info->list[i].map.virt)
1348 - iounmap(info->list[i].map.virt);
1349 -
1350 - if (info->list[i].res) {
1351 - release_resource(info->list[i].res);
1352 - kfree(info->list[i].res);
1353 - }
1354 - }
1355 - return 0;
1356 -}
1357 -
1358 -static const char * const rom_probe_types[] = {
1359 - "cfi_probe", "jedec_probe", "map_rom" };
1360 -
1361 -/* Helper function to handle probing of the obsolete "direct-mapped"
1362 - * compatible binding, which has an extra "probe-type" property
1363 - * describing the type of flash probe necessary. */
1364 -static struct mtd_info *obsolete_probe(struct platform_device *dev,
1365 - struct map_info *map)
1366 -{
1367 - struct device_node *dp = dev->dev.of_node;
1368 - const char *of_probe;
1369 - struct mtd_info *mtd;
1370 - int i;
1371 -
1372 - dev_warn(&dev->dev, "Device tree uses obsolete \"direct-mapped\" "
1373 - "flash binding\n");
1374 -
1375 - of_probe = of_get_property(dp, "probe-type", NULL);
1376 - if (!of_probe) {
1377 - for (i = 0; i < ARRAY_SIZE(rom_probe_types); i++) {
1378 - mtd = do_map_probe(rom_probe_types[i], map);
1379 - if (mtd)
1380 - return mtd;
1381 - }
1382 - return NULL;
1383 - } else if (strcmp(of_probe, "CFI") == 0) {
1384 - return do_map_probe("cfi_probe", map);
1385 - } else if (strcmp(of_probe, "JEDEC") == 0) {
1386 - return do_map_probe("jedec_probe", map);
1387 - } else {
1388 - if (strcmp(of_probe, "ROM") != 0)
1389 - dev_warn(&dev->dev, "obsolete_probe: don't know probe "
1390 - "type '%s', mapping as rom\n", of_probe);
1391 - return do_map_probe("map_rom", map);
1392 - }
1393 -}
1394 -
1395 -/* When partitions are set we look for a linux,part-probe property which
1396 - specifies the list of partition probers to use. If none is given then the
1397 - default is use. These take precedence over other device tree
1398 - information. */
1399 -static const char * const part_probe_types_def[] = {
1400 - "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
1401 -
1402 -static const char * const *of_get_probes(struct device_node *dp)
1403 -{
1404 - const char *cp;
1405 - int cplen;
1406 - unsigned int l;
1407 - unsigned int count;
1408 - const char **res;
1409 -
1410 - cp = of_get_property(dp, "linux,part-probe", &cplen);
1411 - if (cp == NULL)
1412 - return part_probe_types_def;
1413 -
1414 - count = 0;
1415 - for (l = 0; l != cplen; l++)
1416 - if (cp[l] == 0)
1417 - count++;
1418 -
1419 - res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
1420 - if (!res)
1421 - return NULL;
1422 - count = 0;
1423 - while (cplen > 0) {
1424 - res[count] = cp;
1425 - l = strlen(cp) + 1;
1426 - cp += l;
1427 - cplen -= l;
1428 - count++;
1429 - }
1430 - return res;
1431 -}
1432 -
1433 -static void of_free_probes(const char * const *probes)
1434 -{
1435 - if (probes != part_probe_types_def)
1436 - kfree(probes);
1437 -}
1438 -
1439 -static const struct of_device_id of_flash_match[];
1440 -static int of_flash_probe(struct platform_device *dev)
1441 -{
1442 - const char * const *part_probe_types;
1443 - const struct of_device_id *match;
1444 - struct device_node *dp = dev->dev.of_node;
1445 - struct resource res;
1446 - struct of_flash *info;
1447 - const char *probe_type;
1448 - const __be32 *width;
1449 - int err;
1450 - int i;
1451 - int count;
1452 - const __be32 *p;
1453 - int reg_tuple_size;
1454 - struct mtd_info **mtd_list = NULL;
1455 - resource_size_t res_size;
1456 - bool map_indirect;
1457 - const char *mtd_name = NULL;
1458 -
1459 - match = of_match_device(of_flash_match, &dev->dev);
1460 - if (!match)
1461 - return -EINVAL;
1462 - probe_type = match->data;
1463 -
1464 - reg_tuple_size = (of_n_addr_cells(dp) + of_n_size_cells(dp)) * sizeof(u32);
1465 -
1466 - of_property_read_string(dp, "linux,mtd-name", &mtd_name);
1467 -
1468 - /*
1469 - * Get number of "reg" tuples. Scan for MTD devices on area's
1470 - * described by each "reg" region. This makes it possible (including
1471 - * the concat support) to support the Intel P30 48F4400 chips which
1472 - * consists internally of 2 non-identical NOR chips on one die.
1473 - */
1474 - p = of_get_property(dp, "reg", &count);
1475 - if (!p || count % reg_tuple_size != 0) {
1476 - dev_err(&dev->dev, "Malformed reg property on %s\n",
1477 - dev->dev.of_node->full_name);
1478 - err = -EINVAL;
1479 - goto err_flash_remove;
1480 - }
1481 - count /= reg_tuple_size;
1482 -
1483 - map_indirect = of_property_read_bool(dp, "no-unaligned-direct-access");
1484 -
1485 - err = -ENOMEM;
1486 - info = devm_kzalloc(&dev->dev,
1487 - sizeof(struct of_flash) +
1488 - sizeof(struct of_flash_list) * count, GFP_KERNEL);
1489 - if (!info)
1490 - goto err_flash_remove;
1491 -
1492 - dev_set_drvdata(&dev->dev, info);
1493 -
1494 - mtd_list = kzalloc(sizeof(*mtd_list) * count, GFP_KERNEL);
1495 - if (!mtd_list)
1496 - goto err_flash_remove;
1497 -
1498 - for (i = 0; i < count; i++) {
1499 - err = -ENXIO;
1500 - if (of_address_to_resource(dp, i, &res)) {
1501 - /*
1502 - * Continue with next register tuple if this
1503 - * one is not mappable
1504 - */
1505 - continue;
1506 - }
1507 -
1508 - dev_dbg(&dev->dev, "of_flash device: %pR\n", &res);
1509 -
1510 - err = -EBUSY;
1511 - res_size = resource_size(&res);
1512 - info->list[i].res = request_mem_region(res.start, res_size,
1513 - dev_name(&dev->dev));
1514 - if (!info->list[i].res)
1515 - goto err_out;
1516 -
1517 - err = -ENXIO;
1518 - width = of_get_property(dp, "bank-width", NULL);
1519 - if (!width) {
1520 - dev_err(&dev->dev, "Can't get bank width from device"
1521 - " tree\n");
1522 - goto err_out;
1523 - }
1524 -
1525 - info->list[i].map.name = mtd_name ?: dev_name(&dev->dev);
1526 - info->list[i].map.phys = res.start;
1527 - info->list[i].map.size = res_size;
1528 - info->list[i].map.bankwidth = be32_to_cpup(width);
1529 - info->list[i].map.device_node = dp;
1530 -
1531 - err = of_flash_probe_gemini(dev, dp, &info->list[i].map);
1532 - if (err)
1533 - return err;
1534 - err = of_flash_probe_versatile(dev, dp, &info->list[i].map);
1535 - if (err)
1536 - return err;
1537 -
1538 - err = -ENOMEM;
1539 - info->list[i].map.virt = ioremap(info->list[i].map.phys,
1540 - info->list[i].map.size);
1541 - if (!info->list[i].map.virt) {
1542 - dev_err(&dev->dev, "Failed to ioremap() flash"
1543 - " region\n");
1544 - goto err_out;
1545 - }
1546 -
1547 - simple_map_init(&info->list[i].map);
1548 -
1549 - /*
1550 - * On some platforms (e.g. MPC5200) a direct 1:1 mapping
1551 - * may cause problems with JFFS2 usage, as the local bus (LPB)
1552 - * doesn't support unaligned accesses as implemented in the
1553 - * JFFS2 code via memcpy(). By setting NO_XIP, the
1554 - * flash will not be exposed directly to the MTD users
1555 - * (e.g. JFFS2) any more.
1556 - */
1557 - if (map_indirect)
1558 - info->list[i].map.phys = NO_XIP;
1559 -
1560 - if (probe_type) {
1561 - info->list[i].mtd = do_map_probe(probe_type,
1562 - &info->list[i].map);
1563 - } else {
1564 - info->list[i].mtd = obsolete_probe(dev,
1565 - &info->list[i].map);
1566 - }
1567 -
1568 - /* Fall back to mapping region as ROM */
1569 - if (!info->list[i].mtd) {
1570 - dev_warn(&dev->dev,
1571 - "do_map_probe() failed for type %s\n",
1572 - probe_type);
1573 -
1574 - info->list[i].mtd = do_map_probe("map_rom",
1575 - &info->list[i].map);
1576 - }
1577 - mtd_list[i] = info->list[i].mtd;
1578 -
1579 - err = -ENXIO;
1580 - if (!info->list[i].mtd) {
1581 - dev_err(&dev->dev, "do_map_probe() failed\n");
1582 - goto err_out;
1583 - } else {
1584 - info->list_size++;
1585 - }
1586 - info->list[i].mtd->dev.parent = &dev->dev;
1587 - }
1588 -
1589 - err = 0;
1590 - info->cmtd = NULL;
1591 - if (info->list_size == 1) {
1592 - info->cmtd = info->list[0].mtd;
1593 - } else if (info->list_size > 1) {
1594 - /*
1595 - * We detected multiple devices. Concatenate them together.
1596 - */
1597 - info->cmtd = mtd_concat_create(mtd_list, info->list_size,
1598 - dev_name(&dev->dev));
1599 - }
1600 - if (info->cmtd == NULL)
1601 - err = -ENXIO;
1602 -
1603 - if (err)
1604 - goto err_out;
1605 -
1606 - info->cmtd->dev.parent = &dev->dev;
1607 - mtd_set_of_node(info->cmtd, dp);
1608 - part_probe_types = of_get_probes(dp);
1609 - if (!part_probe_types) {
1610 - err = -ENOMEM;
1611 - goto err_out;
1612 - }
1613 - mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
1614 - NULL, 0);
1615 - of_free_probes(part_probe_types);
1616 -
1617 - kfree(mtd_list);
1618 -
1619 - return 0;
1620 -
1621 -err_out:
1622 - kfree(mtd_list);
1623 -err_flash_remove:
1624 - of_flash_remove(dev);
1625 -
1626 - return err;
1627 -}
1628 -
1629 -static const struct of_device_id of_flash_match[] = {
1630 - {
1631 - .compatible = "cfi-flash",
1632 - .data = (void *)"cfi_probe",
1633 - },
1634 - {
1635 - /* FIXME: JEDEC chips can't be safely and reliably
1636 - * probed, although the mtd code gets it right in
1637 - * practice most of the time. We should use the
1638 - * vendor and device ids specified by the binding to
1639 - * bypass the heuristic probe code, but the mtd layer
1640 - * provides, at present, no interface for doing so
1641 - * :(. */
1642 - .compatible = "jedec-flash",
1643 - .data = (void *)"jedec_probe",
1644 - },
1645 - {
1646 - .compatible = "mtd-ram",
1647 - .data = (void *)"map_ram",
1648 - },
1649 - {
1650 - .compatible = "mtd-rom",
1651 - .data = (void *)"map_rom",
1652 - },
1653 - {
1654 - .type = "rom",
1655 - .compatible = "direct-mapped"
1656 - },
1657 - { },
1658 -};
1659 -MODULE_DEVICE_TABLE(of, of_flash_match);
1660 -
1661 -static struct platform_driver of_flash_driver = {
1662 - .driver = {
1663 - .name = "of-flash",
1664 - .of_match_table = of_flash_match,
1665 - },
1666 - .probe = of_flash_probe,
1667 - .remove = of_flash_remove,
1668 -};
1669 -
1670 -module_platform_driver(of_flash_driver);
1671 -
1672 -MODULE_LICENSE("GPL");
1673 -MODULE_AUTHOR("Vitaly Wool <vwool@ru.mvista.com>");
1674 -MODULE_DESCRIPTION("Device tree based MTD map driver");
1675 diff --git a/drivers/mtd/maps/physmap_of_core.c b/drivers/mtd/maps/physmap_of_core.c
1676 new file mode 100644
1677 index 000000000000..14e8909c9955
1678 --- /dev/null
1679 +++ b/drivers/mtd/maps/physmap_of_core.c
1680 @@ -0,0 +1,389 @@
1681 +/*
1682 + * Flash mappings described by the OF (or flattened) device tree
1683 + *
1684 + * Copyright (C) 2006 MontaVista Software Inc.
1685 + * Author: Vitaly Wool <vwool@ru.mvista.com>
1686 + *
1687 + * Revised to handle newer style flash binding by:
1688 + * Copyright (C) 2007 David Gibson, IBM Corporation.
1689 + *
1690 + * This program is free software; you can redistribute it and/or modify it
1691 + * under the terms of the GNU General Public License as published by the
1692 + * Free Software Foundation; either version 2 of the License, or (at your
1693 + * option) any later version.
1694 + */
1695 +
1696 +#include <linux/module.h>
1697 +#include <linux/types.h>
1698 +#include <linux/device.h>
1699 +#include <linux/mtd/mtd.h>
1700 +#include <linux/mtd/map.h>
1701 +#include <linux/mtd/partitions.h>
1702 +#include <linux/mtd/concat.h>
1703 +#include <linux/of.h>
1704 +#include <linux/of_address.h>
1705 +#include <linux/of_platform.h>
1706 +#include <linux/slab.h>
1707 +#include "physmap_of_gemini.h"
1708 +#include "physmap_of_versatile.h"
1709 +
1710 +struct of_flash_list {
1711 + struct mtd_info *mtd;
1712 + struct map_info map;
1713 + struct resource *res;
1714 +};
1715 +
1716 +struct of_flash {
1717 + struct mtd_info *cmtd;
1718 + int list_size; /* number of elements in of_flash_list */
1719 + struct of_flash_list list[0];
1720 +};
1721 +
1722 +static int of_flash_remove(struct platform_device *dev)
1723 +{
1724 + struct of_flash *info;
1725 + int i;
1726 +
1727 + info = dev_get_drvdata(&dev->dev);
1728 + if (!info)
1729 + return 0;
1730 + dev_set_drvdata(&dev->dev, NULL);
1731 +
1732 + if (info->cmtd) {
1733 + mtd_device_unregister(info->cmtd);
1734 + if (info->cmtd != info->list[0].mtd)
1735 + mtd_concat_destroy(info->cmtd);
1736 + }
1737 +
1738 + for (i = 0; i < info->list_size; i++) {
1739 + if (info->list[i].mtd)
1740 + map_destroy(info->list[i].mtd);
1741 +
1742 + if (info->list[i].map.virt)
1743 + iounmap(info->list[i].map.virt);
1744 +
1745 + if (info->list[i].res) {
1746 + release_resource(info->list[i].res);
1747 + kfree(info->list[i].res);
1748 + }
1749 + }
1750 + return 0;
1751 +}
1752 +
1753 +static const char * const rom_probe_types[] = {
1754 + "cfi_probe", "jedec_probe", "map_rom" };
1755 +
1756 +/* Helper function to handle probing of the obsolete "direct-mapped"
1757 + * compatible binding, which has an extra "probe-type" property
1758 + * describing the type of flash probe necessary. */
1759 +static struct mtd_info *obsolete_probe(struct platform_device *dev,
1760 + struct map_info *map)
1761 +{
1762 + struct device_node *dp = dev->dev.of_node;
1763 + const char *of_probe;
1764 + struct mtd_info *mtd;
1765 + int i;
1766 +
1767 + dev_warn(&dev->dev, "Device tree uses obsolete \"direct-mapped\" "
1768 + "flash binding\n");
1769 +
1770 + of_probe = of_get_property(dp, "probe-type", NULL);
1771 + if (!of_probe) {
1772 + for (i = 0; i < ARRAY_SIZE(rom_probe_types); i++) {
1773 + mtd = do_map_probe(rom_probe_types[i], map);
1774 + if (mtd)
1775 + return mtd;
1776 + }
1777 + return NULL;
1778 + } else if (strcmp(of_probe, "CFI") == 0) {
1779 + return do_map_probe("cfi_probe", map);
1780 + } else if (strcmp(of_probe, "JEDEC") == 0) {
1781 + return do_map_probe("jedec_probe", map);
1782 + } else {
1783 + if (strcmp(of_probe, "ROM") != 0)
1784 + dev_warn(&dev->dev, "obsolete_probe: don't know probe "
1785 + "type '%s', mapping as rom\n", of_probe);
1786 + return do_map_probe("map_rom", map);
1787 + }
1788 +}
1789 +
1790 +/* When partitions are set we look for a linux,part-probe property which
1791 + specifies the list of partition probers to use. If none is given then the
1792 + default is use. These take precedence over other device tree
1793 + information. */
1794 +static const char * const part_probe_types_def[] = {
1795 + "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
1796 +
1797 +static const char * const *of_get_probes(struct device_node *dp)
1798 +{
1799 + const char *cp;
1800 + int cplen;
1801 + unsigned int l;
1802 + unsigned int count;
1803 + const char **res;
1804 +
1805 + cp = of_get_property(dp, "linux,part-probe", &cplen);
1806 + if (cp == NULL)
1807 + return part_probe_types_def;
1808 +
1809 + count = 0;
1810 + for (l = 0; l != cplen; l++)
1811 + if (cp[l] == 0)
1812 + count++;
1813 +
1814 + res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
1815 + if (!res)
1816 + return NULL;
1817 + count = 0;
1818 + while (cplen > 0) {
1819 + res[count] = cp;
1820 + l = strlen(cp) + 1;
1821 + cp += l;
1822 + cplen -= l;
1823 + count++;
1824 + }
1825 + return res;
1826 +}
1827 +
1828 +static void of_free_probes(const char * const *probes)
1829 +{
1830 + if (probes != part_probe_types_def)
1831 + kfree(probes);
1832 +}
1833 +
1834 +static const struct of_device_id of_flash_match[];
1835 +static int of_flash_probe(struct platform_device *dev)
1836 +{
1837 + const char * const *part_probe_types;
1838 + const struct of_device_id *match;
1839 + struct device_node *dp = dev->dev.of_node;
1840 + struct resource res;
1841 + struct of_flash *info;
1842 + const char *probe_type;
1843 + const __be32 *width;
1844 + int err;
1845 + int i;
1846 + int count;
1847 + const __be32 *p;
1848 + int reg_tuple_size;
1849 + struct mtd_info **mtd_list = NULL;
1850 + resource_size_t res_size;
1851 + bool map_indirect;
1852 + const char *mtd_name = NULL;
1853 +
1854 + match = of_match_device(of_flash_match, &dev->dev);
1855 + if (!match)
1856 + return -EINVAL;
1857 + probe_type = match->data;
1858 +
1859 + reg_tuple_size = (of_n_addr_cells(dp) + of_n_size_cells(dp)) * sizeof(u32);
1860 +
1861 + of_property_read_string(dp, "linux,mtd-name", &mtd_name);
1862 +
1863 + /*
1864 + * Get number of "reg" tuples. Scan for MTD devices on area's
1865 + * described by each "reg" region. This makes it possible (including
1866 + * the concat support) to support the Intel P30 48F4400 chips which
1867 + * consists internally of 2 non-identical NOR chips on one die.
1868 + */
1869 + p = of_get_property(dp, "reg", &count);
1870 + if (!p || count % reg_tuple_size != 0) {
1871 + dev_err(&dev->dev, "Malformed reg property on %s\n",
1872 + dev->dev.of_node->full_name);
1873 + err = -EINVAL;
1874 + goto err_flash_remove;
1875 + }
1876 + count /= reg_tuple_size;
1877 +
1878 + map_indirect = of_property_read_bool(dp, "no-unaligned-direct-access");
1879 +
1880 + err = -ENOMEM;
1881 + info = devm_kzalloc(&dev->dev,
1882 + sizeof(struct of_flash) +
1883 + sizeof(struct of_flash_list) * count, GFP_KERNEL);
1884 + if (!info)
1885 + goto err_flash_remove;
1886 +
1887 + dev_set_drvdata(&dev->dev, info);
1888 +
1889 + mtd_list = kzalloc(sizeof(*mtd_list) * count, GFP_KERNEL);
1890 + if (!mtd_list)
1891 + goto err_flash_remove;
1892 +
1893 + for (i = 0; i < count; i++) {
1894 + err = -ENXIO;
1895 + if (of_address_to_resource(dp, i, &res)) {
1896 + /*
1897 + * Continue with next register tuple if this
1898 + * one is not mappable
1899 + */
1900 + continue;
1901 + }
1902 +
1903 + dev_dbg(&dev->dev, "of_flash device: %pR\n", &res);
1904 +
1905 + err = -EBUSY;
1906 + res_size = resource_size(&res);
1907 + info->list[i].res = request_mem_region(res.start, res_size,
1908 + dev_name(&dev->dev));
1909 + if (!info->list[i].res)
1910 + goto err_out;
1911 +
1912 + err = -ENXIO;
1913 + width = of_get_property(dp, "bank-width", NULL);
1914 + if (!width) {
1915 + dev_err(&dev->dev, "Can't get bank width from device"
1916 + " tree\n");
1917 + goto err_out;
1918 + }
1919 +
1920 + info->list[i].map.name = mtd_name ?: dev_name(&dev->dev);
1921 + info->list[i].map.phys = res.start;
1922 + info->list[i].map.size = res_size;
1923 + info->list[i].map.bankwidth = be32_to_cpup(width);
1924 + info->list[i].map.device_node = dp;
1925 +
1926 + err = of_flash_probe_gemini(dev, dp, &info->list[i].map);
1927 + if (err)
1928 + return err;
1929 + err = of_flash_probe_versatile(dev, dp, &info->list[i].map);
1930 + if (err)
1931 + return err;
1932 +
1933 + err = -ENOMEM;
1934 + info->list[i].map.virt = ioremap(info->list[i].map.phys,
1935 + info->list[i].map.size);
1936 + if (!info->list[i].map.virt) {
1937 + dev_err(&dev->dev, "Failed to ioremap() flash"
1938 + " region\n");
1939 + goto err_out;
1940 + }
1941 +
1942 + simple_map_init(&info->list[i].map);
1943 +
1944 + /*
1945 + * On some platforms (e.g. MPC5200) a direct 1:1 mapping
1946 + * may cause problems with JFFS2 usage, as the local bus (LPB)
1947 + * doesn't support unaligned accesses as implemented in the
1948 + * JFFS2 code via memcpy(). By setting NO_XIP, the
1949 + * flash will not be exposed directly to the MTD users
1950 + * (e.g. JFFS2) any more.
1951 + */
1952 + if (map_indirect)
1953 + info->list[i].map.phys = NO_XIP;
1954 +
1955 + if (probe_type) {
1956 + info->list[i].mtd = do_map_probe(probe_type,
1957 + &info->list[i].map);
1958 + } else {
1959 + info->list[i].mtd = obsolete_probe(dev,
1960 + &info->list[i].map);
1961 + }
1962 +
1963 + /* Fall back to mapping region as ROM */
1964 + if (!info->list[i].mtd) {
1965 + dev_warn(&dev->dev,
1966 + "do_map_probe() failed for type %s\n",
1967 + probe_type);
1968 +
1969 + info->list[i].mtd = do_map_probe("map_rom",
1970 + &info->list[i].map);
1971 + }
1972 + mtd_list[i] = info->list[i].mtd;
1973 +
1974 + err = -ENXIO;
1975 + if (!info->list[i].mtd) {
1976 + dev_err(&dev->dev, "do_map_probe() failed\n");
1977 + goto err_out;
1978 + } else {
1979 + info->list_size++;
1980 + }
1981 + info->list[i].mtd->dev.parent = &dev->dev;
1982 + }
1983 +
1984 + err = 0;
1985 + info->cmtd = NULL;
1986 + if (info->list_size == 1) {
1987 + info->cmtd = info->list[0].mtd;
1988 + } else if (info->list_size > 1) {
1989 + /*
1990 + * We detected multiple devices. Concatenate them together.
1991 + */
1992 + info->cmtd = mtd_concat_create(mtd_list, info->list_size,
1993 + dev_name(&dev->dev));
1994 + }
1995 + if (info->cmtd == NULL)
1996 + err = -ENXIO;
1997 +
1998 + if (err)
1999 + goto err_out;
2000 +
2001 + info->cmtd->dev.parent = &dev->dev;
2002 + mtd_set_of_node(info->cmtd, dp);
2003 + part_probe_types = of_get_probes(dp);
2004 + if (!part_probe_types) {
2005 + err = -ENOMEM;
2006 + goto err_out;
2007 + }
2008 + mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
2009 + NULL, 0);
2010 + of_free_probes(part_probe_types);
2011 +
2012 + kfree(mtd_list);
2013 +
2014 + return 0;
2015 +
2016 +err_out:
2017 + kfree(mtd_list);
2018 +err_flash_remove:
2019 + of_flash_remove(dev);
2020 +
2021 + return err;
2022 +}
2023 +
2024 +static const struct of_device_id of_flash_match[] = {
2025 + {
2026 + .compatible = "cfi-flash",
2027 + .data = (void *)"cfi_probe",
2028 + },
2029 + {
2030 + /* FIXME: JEDEC chips can't be safely and reliably
2031 + * probed, although the mtd code gets it right in
2032 + * practice most of the time. We should use the
2033 + * vendor and device ids specified by the binding to
2034 + * bypass the heuristic probe code, but the mtd layer
2035 + * provides, at present, no interface for doing so
2036 + * :(. */
2037 + .compatible = "jedec-flash",
2038 + .data = (void *)"jedec_probe",
2039 + },
2040 + {
2041 + .compatible = "mtd-ram",
2042 + .data = (void *)"map_ram",
2043 + },
2044 + {
2045 + .compatible = "mtd-rom",
2046 + .data = (void *)"map_rom",
2047 + },
2048 + {
2049 + .type = "rom",
2050 + .compatible = "direct-mapped"
2051 + },
2052 + { },
2053 +};
2054 +MODULE_DEVICE_TABLE(of, of_flash_match);
2055 +
2056 +static struct platform_driver of_flash_driver = {
2057 + .driver = {
2058 + .name = "of-flash",
2059 + .of_match_table = of_flash_match,
2060 + },
2061 + .probe = of_flash_probe,
2062 + .remove = of_flash_remove,
2063 +};
2064 +
2065 +module_platform_driver(of_flash_driver);
2066 +
2067 +MODULE_LICENSE("GPL");
2068 +MODULE_AUTHOR("Vitaly Wool <vwool@ru.mvista.com>");
2069 +MODULE_DESCRIPTION("Device tree based MTD map driver");
2070 diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
2071 index eecee7f8dfb7..afcc1312dbaf 100644
2072 --- a/drivers/net/can/usb/gs_usb.c
2073 +++ b/drivers/net/can/usb/gs_usb.c
2074 @@ -265,6 +265,8 @@ static int gs_cmd_reset(struct gs_usb *gsusb, struct gs_can *gsdev)
2075 sizeof(*dm),
2076 1000);
2077
2078 + kfree(dm);
2079 +
2080 return rc;
2081 }
2082
2083 diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
2084 index afb4d048d3e9..54c34298a000 100644
2085 --- a/drivers/phy/phy-rcar-gen3-usb2.c
2086 +++ b/drivers/phy/phy-rcar-gen3-usb2.c
2087 @@ -20,6 +20,7 @@
2088 #include <linux/of_address.h>
2089 #include <linux/phy/phy.h>
2090 #include <linux/platform_device.h>
2091 +#include <linux/pm_runtime.h>
2092 #include <linux/regulator/consumer.h>
2093 #include <linux/workqueue.h>
2094
2095 @@ -395,7 +396,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
2096 struct rcar_gen3_chan *channel;
2097 struct phy_provider *provider;
2098 struct resource *res;
2099 - int irq;
2100 + int irq, ret = 0;
2101
2102 if (!dev->of_node) {
2103 dev_err(dev, "This driver needs device tree\n");
2104 @@ -434,17 +435,24 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
2105 }
2106 }
2107
2108 - /* devm_phy_create() will call pm_runtime_enable(dev); */
2109 + /*
2110 + * devm_phy_create() will call pm_runtime_enable(&phy->dev);
2111 + * And then, phy-core will manage runtime pm for this device.
2112 + */
2113 + pm_runtime_enable(dev);
2114 channel->phy = devm_phy_create(dev, NULL, &rcar_gen3_phy_usb2_ops);
2115 if (IS_ERR(channel->phy)) {
2116 dev_err(dev, "Failed to create USB2 PHY\n");
2117 - return PTR_ERR(channel->phy);
2118 + ret = PTR_ERR(channel->phy);
2119 + goto error;
2120 }
2121
2122 channel->vbus = devm_regulator_get_optional(dev, "vbus");
2123 if (IS_ERR(channel->vbus)) {
2124 - if (PTR_ERR(channel->vbus) == -EPROBE_DEFER)
2125 - return PTR_ERR(channel->vbus);
2126 + if (PTR_ERR(channel->vbus) == -EPROBE_DEFER) {
2127 + ret = PTR_ERR(channel->vbus);
2128 + goto error;
2129 + }
2130 channel->vbus = NULL;
2131 }
2132
2133 @@ -454,15 +462,22 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
2134 provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
2135 if (IS_ERR(provider)) {
2136 dev_err(dev, "Failed to register PHY provider\n");
2137 + ret = PTR_ERR(provider);
2138 + goto error;
2139 } else if (channel->has_otg) {
2140 int ret;
2141
2142 ret = device_create_file(dev, &dev_attr_role);
2143 if (ret < 0)
2144 - return ret;
2145 + goto error;
2146 }
2147
2148 - return PTR_ERR_OR_ZERO(provider);
2149 + return 0;
2150 +
2151 +error:
2152 + pm_runtime_disable(dev);
2153 +
2154 + return ret;
2155 }
2156
2157 static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
2158 @@ -472,6 +487,8 @@ static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
2159 if (channel->has_otg)
2160 device_remove_file(&pdev->dev, &dev_attr_role);
2161
2162 + pm_runtime_disable(&pdev->dev);
2163 +
2164 return 0;
2165 };
2166
2167 diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c
2168 index b91b50f345bd..c1a68ebb529c 100644
2169 --- a/drivers/staging/iio/cdc/ad7152.c
2170 +++ b/drivers/staging/iio/cdc/ad7152.c
2171 @@ -231,16 +231,12 @@ static int ad7152_write_raw_samp_freq(struct device *dev, int val)
2172 if (i >= ARRAY_SIZE(ad7152_filter_rate_table))
2173 i = ARRAY_SIZE(ad7152_filter_rate_table) - 1;
2174
2175 - mutex_lock(&chip->state_lock);
2176 ret = i2c_smbus_write_byte_data(chip->client,
2177 AD7152_REG_CFG2, AD7152_CFG2_OSR(i));
2178 - if (ret < 0) {
2179 - mutex_unlock(&chip->state_lock);
2180 + if (ret < 0)
2181 return ret;
2182 - }
2183
2184 chip->filter_rate_setup = i;
2185 - mutex_unlock(&chip->state_lock);
2186
2187 return ret;
2188 }
2189 diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c
2190 index ea15bc1c300c..197201a70d59 100644
2191 --- a/drivers/staging/iio/light/tsl2x7x_core.c
2192 +++ b/drivers/staging/iio/light/tsl2x7x_core.c
2193 @@ -854,7 +854,7 @@ void tsl2x7x_prox_calculate(int *data, int length,
2194 tmp = data[i] - statP->mean;
2195 sample_sum += tmp * tmp;
2196 }
2197 - statP->stddev = int_sqrt((long)sample_sum) / length;
2198 + statP->stddev = int_sqrt((long)sample_sum / length);
2199 }
2200
2201 /**
2202 diff --git a/drivers/staging/media/platform/bcm2835/bcm2835-camera.c b/drivers/staging/media/platform/bcm2835/bcm2835-camera.c
2203 index ca15a698e018..c4dad30dd133 100644
2204 --- a/drivers/staging/media/platform/bcm2835/bcm2835-camera.c
2205 +++ b/drivers/staging/media/platform/bcm2835/bcm2835-camera.c
2206 @@ -1901,6 +1901,7 @@ static int __init bm2835_mmal_init(void)
2207 unsigned int num_cameras;
2208 struct vchiq_mmal_instance *instance;
2209 unsigned int resolutions[MAX_BCM2835_CAMERAS][2];
2210 + int i;
2211
2212 ret = vchiq_mmal_init(&instance);
2213 if (ret < 0)
2214 @@ -1914,8 +1915,10 @@ static int __init bm2835_mmal_init(void)
2215
2216 for (camera = 0; camera < num_cameras; camera++) {
2217 dev = kzalloc(sizeof(struct bm2835_mmal_dev), GFP_KERNEL);
2218 - if (!dev)
2219 - return -ENOMEM;
2220 + if (!dev) {
2221 + ret = -ENOMEM;
2222 + goto cleanup_gdev;
2223 + }
2224
2225 dev->camera_num = camera;
2226 dev->max_width = resolutions[camera][0];
2227 @@ -1998,9 +2001,10 @@ static int __init bm2835_mmal_init(void)
2228 free_dev:
2229 kfree(dev);
2230
2231 - for ( ; camera > 0; camera--) {
2232 - bcm2835_cleanup_instance(gdev[camera]);
2233 - gdev[camera] = NULL;
2234 +cleanup_gdev:
2235 + for (i = 0; i < camera; i++) {
2236 + bcm2835_cleanup_instance(gdev[i]);
2237 + gdev[i] = NULL;
2238 }
2239 pr_info("%s: error %d while loading driver\n",
2240 BM2835_MMAL_MODULE_NAME, ret);
2241 diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c
2242 index 1c8fa3a1f5bb..88f0420b58a9 100644
2243 --- a/drivers/staging/rtl8188eu/core/rtw_ap.c
2244 +++ b/drivers/staging/rtl8188eu/core/rtw_ap.c
2245 @@ -888,7 +888,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
2246 return _FAIL;
2247
2248
2249 - if (len > MAX_IE_SZ)
2250 + if (len < 0 || len > MAX_IE_SZ)
2251 return _FAIL;
2252
2253 pbss_network->IELength = len;
2254 diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
2255 index f3ea90f0e411..7dddd7e6a01c 100644
2256 --- a/drivers/tty/serial/8250/8250_lpss.c
2257 +++ b/drivers/tty/serial/8250/8250_lpss.c
2258 @@ -183,7 +183,6 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
2259 if (ret)
2260 return;
2261
2262 - pci_set_master(pdev);
2263 pci_try_set_mwi(pdev);
2264
2265 /* Special DMA address for UART */
2266 @@ -216,6 +215,8 @@ static int qrk_serial_setup(struct lpss8250 *lpss, struct uart_port *port)
2267 struct pci_dev *pdev = to_pci_dev(port->dev);
2268 int ret;
2269
2270 + pci_set_master(pdev);
2271 +
2272 ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
2273 if (ret < 0)
2274 return ret;
2275 diff --git a/drivers/tty/serial/efm32-uart.c b/drivers/tty/serial/efm32-uart.c
2276 index ebd8569f9ad5..9fff25be87f9 100644
2277 --- a/drivers/tty/serial/efm32-uart.c
2278 +++ b/drivers/tty/serial/efm32-uart.c
2279 @@ -27,6 +27,7 @@
2280 #define UARTn_FRAME 0x04
2281 #define UARTn_FRAME_DATABITS__MASK 0x000f
2282 #define UARTn_FRAME_DATABITS(n) ((n) - 3)
2283 +#define UARTn_FRAME_PARITY__MASK 0x0300
2284 #define UARTn_FRAME_PARITY_NONE 0x0000
2285 #define UARTn_FRAME_PARITY_EVEN 0x0200
2286 #define UARTn_FRAME_PARITY_ODD 0x0300
2287 @@ -572,12 +573,16 @@ static void efm32_uart_console_get_options(struct efm32_uart_port *efm_port,
2288 16 * (4 + (clkdiv >> 6)));
2289
2290 frame = efm32_uart_read32(efm_port, UARTn_FRAME);
2291 - if (frame & UARTn_FRAME_PARITY_ODD)
2292 + switch (frame & UARTn_FRAME_PARITY__MASK) {
2293 + case UARTn_FRAME_PARITY_ODD:
2294 *parity = 'o';
2295 - else if (frame & UARTn_FRAME_PARITY_EVEN)
2296 + break;
2297 + case UARTn_FRAME_PARITY_EVEN:
2298 *parity = 'e';
2299 - else
2300 + break;
2301 + default:
2302 *parity = 'n';
2303 + }
2304
2305 *bits = (frame & UARTn_FRAME_DATABITS__MASK) -
2306 UARTn_FRAME_DATABITS(4) + 4;
2307 diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
2308 index 1df57461ece4..ebbe05e2fb57 100644
2309 --- a/drivers/tty/serial/sh-sci.c
2310 +++ b/drivers/tty/serial/sh-sci.c
2311 @@ -683,24 +683,37 @@ static void sci_init_pins(struct uart_port *port, unsigned int cflag)
2312 }
2313
2314 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
2315 + u16 data = serial_port_in(port, SCPDR);
2316 u16 ctrl = serial_port_in(port, SCPCR);
2317
2318 /* Enable RXD and TXD pin functions */
2319 ctrl &= ~(SCPCR_RXDC | SCPCR_TXDC);
2320 if (to_sci_port(port)->has_rtscts) {
2321 - /* RTS# is output, driven 1 */
2322 - ctrl |= SCPCR_RTSC;
2323 - serial_port_out(port, SCPDR,
2324 - serial_port_in(port, SCPDR) | SCPDR_RTSD);
2325 + /* RTS# is output, active low, unless autorts */
2326 + if (!(port->mctrl & TIOCM_RTS)) {
2327 + ctrl |= SCPCR_RTSC;
2328 + data |= SCPDR_RTSD;
2329 + } else if (!s->autorts) {
2330 + ctrl |= SCPCR_RTSC;
2331 + data &= ~SCPDR_RTSD;
2332 + } else {
2333 + /* Enable RTS# pin function */
2334 + ctrl &= ~SCPCR_RTSC;
2335 + }
2336 /* Enable CTS# pin function */
2337 ctrl &= ~SCPCR_CTSC;
2338 }
2339 + serial_port_out(port, SCPDR, data);
2340 serial_port_out(port, SCPCR, ctrl);
2341 } else if (sci_getreg(port, SCSPTR)->size) {
2342 u16 status = serial_port_in(port, SCSPTR);
2343
2344 - /* RTS# is output, driven 1 */
2345 - status |= SCSPTR_RTSIO | SCSPTR_RTSDT;
2346 + /* RTS# is always output; and active low, unless autorts */
2347 + status |= SCSPTR_RTSIO;
2348 + if (!(port->mctrl & TIOCM_RTS))
2349 + status |= SCSPTR_RTSDT;
2350 + else if (!s->autorts)
2351 + status &= ~SCSPTR_RTSDT;
2352 /* CTS# and SCK are inputs */
2353 status &= ~(SCSPTR_CTSIO | SCSPTR_SCKIO);
2354 serial_port_out(port, SCSPTR, status);
2355 @@ -2376,6 +2389,10 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
2356
2357 serial_port_out(port, SCFCR, ctrl);
2358 }
2359 + if (port->flags & UPF_HARD_FLOW) {
2360 + /* Refresh (Auto) RTS */
2361 + sci_set_mctrl(port, port->mctrl);
2362 + }
2363
2364 scr_val |= SCSCR_RE | SCSCR_TE |
2365 (s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0));
2366 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
2367 index 6a857e875633..3e28ff1651b4 100644
2368 --- a/drivers/usb/core/hcd.c
2369 +++ b/drivers/usb/core/hcd.c
2370 @@ -2535,6 +2535,7 @@ struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
2371 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex),
2372 GFP_KERNEL);
2373 if (!hcd->bandwidth_mutex) {
2374 + kfree(hcd->address0_mutex);
2375 kfree(hcd);
2376 dev_dbg(dev, "hcd bandwidth mutex alloc failed\n");
2377 return NULL;
2378 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
2379 index f77a4ebde7d5..b8bb20d7acdb 100644
2380 --- a/drivers/usb/core/hub.c
2381 +++ b/drivers/usb/core/hub.c
2382 @@ -1336,7 +1336,13 @@ static int hub_configure(struct usb_hub *hub,
2383 if (ret < 0) {
2384 message = "can't read hub descriptor";
2385 goto fail;
2386 - } else if (hub->descriptor->bNbrPorts > USB_MAXCHILDREN) {
2387 + }
2388 +
2389 + maxchild = USB_MAXCHILDREN;
2390 + if (hub_is_superspeed(hdev))
2391 + maxchild = min_t(unsigned, maxchild, USB_SS_MAXPORTS);
2392 +
2393 + if (hub->descriptor->bNbrPorts > maxchild) {
2394 message = "hub has too many ports!";
2395 ret = -ENODEV;
2396 goto fail;
2397 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
2398 index 81199f6ee3bc..2776da016685 100644
2399 --- a/drivers/usb/dwc3/gadget.c
2400 +++ b/drivers/usb/dwc3/gadget.c
2401 @@ -1258,14 +1258,24 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
2402 __dwc3_gadget_start_isoc(dwc, dep, cur_uf);
2403 dep->flags &= ~DWC3_EP_PENDING_REQUEST;
2404 }
2405 + return 0;
2406 }
2407 - return 0;
2408 +
2409 + if ((dep->flags & DWC3_EP_BUSY) &&
2410 + !(dep->flags & DWC3_EP_MISSED_ISOC)) {
2411 + WARN_ON_ONCE(!dep->resource_index);
2412 + ret = __dwc3_gadget_kick_transfer(dep,
2413 + dep->resource_index);
2414 + }
2415 +
2416 + goto out;
2417 }
2418
2419 if (!dwc3_calc_trbs_left(dep))
2420 return 0;
2421
2422 ret = __dwc3_gadget_kick_transfer(dep, 0);
2423 +out:
2424 if (ret == -EBUSY)
2425 ret = 0;
2426
2427 diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
2428 index a2c916869293..fc4bbdd0fbd6 100644
2429 --- a/drivers/usb/gadget/legacy/inode.c
2430 +++ b/drivers/usb/gadget/legacy/inode.c
2431 @@ -1182,8 +1182,10 @@ dev_release (struct inode *inode, struct file *fd)
2432
2433 /* closing ep0 === shutdown all */
2434
2435 - if (dev->gadget_registered)
2436 + if (dev->gadget_registered) {
2437 usb_gadget_unregister_driver (&gadgetfs_driver);
2438 + dev->gadget_registered = false;
2439 + }
2440
2441 /* at this point "good" hardware has disconnected the
2442 * device from USB; the host won't see it any more.
2443 @@ -1676,9 +1678,10 @@ static void
2444 gadgetfs_suspend (struct usb_gadget *gadget)
2445 {
2446 struct dev_data *dev = get_gadget_data (gadget);
2447 + unsigned long flags;
2448
2449 INFO (dev, "suspended from state %d\n", dev->state);
2450 - spin_lock (&dev->lock);
2451 + spin_lock_irqsave(&dev->lock, flags);
2452 switch (dev->state) {
2453 case STATE_DEV_SETUP: // VERY odd... host died??
2454 case STATE_DEV_CONNECTED:
2455 @@ -1689,7 +1692,7 @@ gadgetfs_suspend (struct usb_gadget *gadget)
2456 default:
2457 break;
2458 }
2459 - spin_unlock (&dev->lock);
2460 + spin_unlock_irqrestore(&dev->lock, flags);
2461 }
2462
2463 static struct usb_gadget_driver gadgetfs_driver = {
2464 diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
2465 index 8cabc5944d5f..d5ec2e4f5359 100644
2466 --- a/drivers/usb/gadget/udc/dummy_hcd.c
2467 +++ b/drivers/usb/gadget/udc/dummy_hcd.c
2468 @@ -442,23 +442,16 @@ static void set_link_state(struct dummy_hcd *dum_hcd)
2469 /* Report reset and disconnect events to the driver */
2470 if (dum->driver && (disconnect || reset)) {
2471 stop_activity(dum);
2472 - spin_unlock(&dum->lock);
2473 if (reset)
2474 usb_gadget_udc_reset(&dum->gadget, dum->driver);
2475 else
2476 dum->driver->disconnect(&dum->gadget);
2477 - spin_lock(&dum->lock);
2478 }
2479 } else if (dum_hcd->active != dum_hcd->old_active) {
2480 - if (dum_hcd->old_active && dum->driver->suspend) {
2481 - spin_unlock(&dum->lock);
2482 + if (dum_hcd->old_active && dum->driver->suspend)
2483 dum->driver->suspend(&dum->gadget);
2484 - spin_lock(&dum->lock);
2485 - } else if (!dum_hcd->old_active && dum->driver->resume) {
2486 - spin_unlock(&dum->lock);
2487 + else if (!dum_hcd->old_active && dum->driver->resume)
2488 dum->driver->resume(&dum->gadget);
2489 - spin_lock(&dum->lock);
2490 - }
2491 }
2492
2493 dum_hcd->old_status = dum_hcd->port_status;
2494 @@ -983,7 +976,9 @@ static int dummy_udc_stop(struct usb_gadget *g)
2495 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
2496 struct dummy *dum = dum_hcd->dum;
2497
2498 + spin_lock_irq(&dum->lock);
2499 dum->driver = NULL;
2500 + spin_unlock_irq(&dum->lock);
2501
2502 return 0;
2503 }
2504 @@ -2008,7 +2003,7 @@ ss_hub_descriptor(struct usb_hub_descriptor *desc)
2505 HUB_CHAR_COMMON_OCPM);
2506 desc->bNbrPorts = 1;
2507 desc->u.ss.bHubHdrDecLat = 0x04; /* Worst case: 0.4 micro sec*/
2508 - desc->u.ss.DeviceRemovable = 0xffff;
2509 + desc->u.ss.DeviceRemovable = 0;
2510 }
2511
2512 static inline void hub_descriptor(struct usb_hub_descriptor *desc)
2513 @@ -2020,8 +2015,8 @@ static inline void hub_descriptor(struct usb_hub_descriptor *desc)
2514 HUB_CHAR_INDV_PORT_LPSM |
2515 HUB_CHAR_COMMON_OCPM);
2516 desc->bNbrPorts = 1;
2517 - desc->u.hs.DeviceRemovable[0] = 0xff;
2518 - desc->u.hs.DeviceRemovable[1] = 0xff;
2519 + desc->u.hs.DeviceRemovable[0] = 0;
2520 + desc->u.hs.DeviceRemovable[1] = 0xff; /* PortPwrCtrlMask */
2521 }
2522
2523 static int dummy_hub_control(
2524 diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
2525 index 3828c2ec8623..1904bb192faf 100644
2526 --- a/drivers/usb/gadget/udc/net2280.c
2527 +++ b/drivers/usb/gadget/udc/net2280.c
2528 @@ -2470,11 +2470,8 @@ static void stop_activity(struct net2280 *dev, struct usb_gadget_driver *driver)
2529 nuke(&dev->ep[i]);
2530
2531 /* report disconnect; the driver is already quiesced */
2532 - if (driver) {
2533 - spin_unlock(&dev->lock);
2534 + if (driver)
2535 driver->disconnect(&dev->gadget);
2536 - spin_lock(&dev->lock);
2537 - }
2538
2539 usb_reinit(dev);
2540 }
2541 @@ -3348,8 +3345,6 @@ static void handle_stat0_irqs(struct net2280 *dev, u32 stat)
2542 BIT(PCI_RETRY_ABORT_INTERRUPT))
2543
2544 static void handle_stat1_irqs(struct net2280 *dev, u32 stat)
2545 -__releases(dev->lock)
2546 -__acquires(dev->lock)
2547 {
2548 struct net2280_ep *ep;
2549 u32 tmp, num, mask, scratch;
2550 @@ -3390,14 +3385,12 @@ __acquires(dev->lock)
2551 if (disconnect || reset) {
2552 stop_activity(dev, dev->driver);
2553 ep0_start(dev);
2554 - spin_unlock(&dev->lock);
2555 if (reset)
2556 usb_gadget_udc_reset
2557 (&dev->gadget, dev->driver);
2558 else
2559 (dev->driver->disconnect)
2560 (&dev->gadget);
2561 - spin_lock(&dev->lock);
2562 return;
2563 }
2564 }
2565 diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c
2566 index 2218f91e92a6..20a6b1a4f26e 100644
2567 --- a/drivers/usb/gadget/udc/renesas_usb3.c
2568 +++ b/drivers/usb/gadget/udc/renesas_usb3.c
2569 @@ -1401,7 +1401,13 @@ static void usb3_request_done_pipen(struct renesas_usb3 *usb3,
2570 struct renesas_usb3_request *usb3_req,
2571 int status)
2572 {
2573 - usb3_pn_stop(usb3);
2574 + unsigned long flags;
2575 +
2576 + spin_lock_irqsave(&usb3->lock, flags);
2577 + if (usb3_pn_change(usb3, usb3_ep->num))
2578 + usb3_pn_stop(usb3);
2579 + spin_unlock_irqrestore(&usb3->lock, flags);
2580 +
2581 usb3_disable_pipe_irq(usb3, usb3_ep->num);
2582 usb3_request_done(usb3_ep, usb3_req, status);
2583
2584 @@ -1430,30 +1436,46 @@ static void usb3_irq_epc_pipen_bfrdy(struct renesas_usb3 *usb3, int num)
2585 {
2586 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num);
2587 struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep);
2588 + bool done = false;
2589
2590 if (!usb3_req)
2591 return;
2592
2593 + spin_lock(&usb3->lock);
2594 + if (usb3_pn_change(usb3, num))
2595 + goto out;
2596 +
2597 if (usb3_ep->dir_in) {
2598 /* Do not stop the IN pipe here to detect LSTTR interrupt */
2599 if (!usb3_write_pipe(usb3_ep, usb3_req, USB3_PN_WRITE))
2600 usb3_clear_bit(usb3, PN_INT_BFRDY, USB3_PN_INT_ENA);
2601 } else {
2602 if (!usb3_read_pipe(usb3_ep, usb3_req, USB3_PN_READ))
2603 - usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0);
2604 + done = true;
2605 }
2606 +
2607 +out:
2608 + /* need to unlock because usb3_request_done_pipen() locks it */
2609 + spin_unlock(&usb3->lock);
2610 +
2611 + if (done)
2612 + usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0);
2613 }
2614
2615 static void usb3_irq_epc_pipen(struct renesas_usb3 *usb3, int num)
2616 {
2617 u32 pn_int_sta;
2618
2619 - if (usb3_pn_change(usb3, num) < 0)
2620 + spin_lock(&usb3->lock);
2621 + if (usb3_pn_change(usb3, num) < 0) {
2622 + spin_unlock(&usb3->lock);
2623 return;
2624 + }
2625
2626 pn_int_sta = usb3_read(usb3, USB3_PN_INT_STA);
2627 pn_int_sta &= usb3_read(usb3, USB3_PN_INT_ENA);
2628 usb3_write(usb3, pn_int_sta, USB3_PN_INT_STA);
2629 + spin_unlock(&usb3->lock);
2630 if (pn_int_sta & PN_INT_LSTTR)
2631 usb3_irq_epc_pipen_lsttr(usb3, num);
2632 if (pn_int_sta & PN_INT_BFRDY)
2633 @@ -1707,6 +1729,9 @@ static int renesas_usb3_start(struct usb_gadget *gadget,
2634 /* hook up the driver */
2635 usb3->driver = driver;
2636
2637 + pm_runtime_enable(usb3_to_dev(usb3));
2638 + pm_runtime_get_sync(usb3_to_dev(usb3));
2639 +
2640 renesas_usb3_init_controller(usb3);
2641
2642 return 0;
2643 @@ -1715,14 +1740,14 @@ static int renesas_usb3_start(struct usb_gadget *gadget,
2644 static int renesas_usb3_stop(struct usb_gadget *gadget)
2645 {
2646 struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget);
2647 - unsigned long flags;
2648
2649 - spin_lock_irqsave(&usb3->lock, flags);
2650 usb3->softconnect = false;
2651 usb3->gadget.speed = USB_SPEED_UNKNOWN;
2652 usb3->driver = NULL;
2653 renesas_usb3_stop_controller(usb3);
2654 - spin_unlock_irqrestore(&usb3->lock, flags);
2655 +
2656 + pm_runtime_put(usb3_to_dev(usb3));
2657 + pm_runtime_disable(usb3_to_dev(usb3));
2658
2659 return 0;
2660 }
2661 @@ -1761,9 +1786,6 @@ static int renesas_usb3_remove(struct platform_device *pdev)
2662 {
2663 struct renesas_usb3 *usb3 = platform_get_drvdata(pdev);
2664
2665 - pm_runtime_put(&pdev->dev);
2666 - pm_runtime_disable(&pdev->dev);
2667 -
2668 usb_del_gadget_udc(&usb3->gadget);
2669
2670 __renesas_usb3_ep_free_request(usb3->ep0_req);
2671 @@ -1948,9 +1970,6 @@ static int renesas_usb3_probe(struct platform_device *pdev)
2672
2673 usb3->workaround_for_vbus = priv->workaround_for_vbus;
2674
2675 - pm_runtime_enable(&pdev->dev);
2676 - pm_runtime_get_sync(&pdev->dev);
2677 -
2678 dev_info(&pdev->dev, "probed\n");
2679
2680 return 0;
2681 diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
2682 index bfa7fa3d2eea..7bf78be1fd32 100644
2683 --- a/drivers/usb/host/r8a66597-hcd.c
2684 +++ b/drivers/usb/host/r8a66597-hcd.c
2685 @@ -1269,7 +1269,7 @@ static void set_td_timer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
2686 time = 30;
2687 break;
2688 default:
2689 - time = 300;
2690 + time = 50;
2691 break;
2692 }
2693
2694 @@ -1785,6 +1785,7 @@ static void r8a66597_td_timer(unsigned long _r8a66597)
2695 pipe = td->pipe;
2696 pipe_stop(r8a66597, pipe);
2697
2698 + /* Select a different address or endpoint */
2699 new_td = td;
2700 do {
2701 list_move_tail(&new_td->queue,
2702 @@ -1794,7 +1795,8 @@ static void r8a66597_td_timer(unsigned long _r8a66597)
2703 new_td = td;
2704 break;
2705 }
2706 - } while (td != new_td && td->address == new_td->address);
2707 + } while (td != new_td && td->address == new_td->address &&
2708 + td->pipe->info.epnum == new_td->pipe->info.epnum);
2709
2710 start_transfer(r8a66597, new_td);
2711
2712 diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
2713 index 96e133f4f7e7..4f28cfebe302 100644
2714 --- a/drivers/usb/host/xhci-mem.c
2715 +++ b/drivers/usb/host/xhci-mem.c
2716 @@ -2128,11 +2128,12 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
2717 {
2718 u32 temp, port_offset, port_count;
2719 int i;
2720 - u8 major_revision;
2721 + u8 major_revision, minor_revision;
2722 struct xhci_hub *rhub;
2723
2724 temp = readl(addr);
2725 major_revision = XHCI_EXT_PORT_MAJOR(temp);
2726 + minor_revision = XHCI_EXT_PORT_MINOR(temp);
2727
2728 if (major_revision == 0x03) {
2729 rhub = &xhci->usb3_rhub;
2730 @@ -2146,7 +2147,9 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
2731 return;
2732 }
2733 rhub->maj_rev = XHCI_EXT_PORT_MAJOR(temp);
2734 - rhub->min_rev = XHCI_EXT_PORT_MINOR(temp);
2735 +
2736 + if (rhub->min_rev < minor_revision)
2737 + rhub->min_rev = minor_revision;
2738
2739 /* Port offset and count in the third dword, see section 7.2 */
2740 temp = readl(addr + 2);
2741 diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
2742 index fcf1f3f63e7a..1bcf971141c0 100644
2743 --- a/drivers/usb/host/xhci-pci.c
2744 +++ b/drivers/usb/host/xhci-pci.c
2745 @@ -201,6 +201,9 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
2746 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
2747 pdev->device == 0x1042)
2748 xhci->quirks |= XHCI_BROKEN_STREAMS;
2749 + if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
2750 + pdev->device == 0x1142)
2751 + xhci->quirks |= XHCI_TRUST_TX_LENGTH;
2752
2753 if (pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241)
2754 xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_7;
2755 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
2756 index e4cb9f0625e8..be0911049c97 100644
2757 --- a/drivers/usb/usbip/vhci_hcd.c
2758 +++ b/drivers/usb/usbip/vhci_hcd.c
2759 @@ -235,14 +235,19 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *buf)
2760
2761 static inline void hub_descriptor(struct usb_hub_descriptor *desc)
2762 {
2763 + int width;
2764 +
2765 memset(desc, 0, sizeof(*desc));
2766 desc->bDescriptorType = USB_DT_HUB;
2767 - desc->bDescLength = 9;
2768 desc->wHubCharacteristics = cpu_to_le16(
2769 HUB_CHAR_INDV_PORT_LPSM | HUB_CHAR_COMMON_OCPM);
2770 +
2771 desc->bNbrPorts = VHCI_HC_PORTS;
2772 - desc->u.hs.DeviceRemovable[0] = 0xff;
2773 - desc->u.hs.DeviceRemovable[1] = 0xff;
2774 + BUILD_BUG_ON(VHCI_HC_PORTS > USB_MAXCHILDREN);
2775 + width = desc->bNbrPorts / 8 + 1;
2776 + desc->bDescLength = USB_DT_HUB_NONVAR_SIZE + 2 * width;
2777 + memset(&desc->u.hs.DeviceRemovable[0], 0, width);
2778 + memset(&desc->u.hs.DeviceRemovable[width], 0xff, width);
2779 }
2780
2781 static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2782 diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
2783 index 34adf9b9c053..b7f1fda40422 100644
2784 --- a/drivers/virtio/virtio_balloon.c
2785 +++ b/drivers/virtio/virtio_balloon.c
2786 @@ -664,6 +664,12 @@ static int virtballoon_restore(struct virtio_device *vdev)
2787 }
2788 #endif
2789
2790 +static int virtballoon_validate(struct virtio_device *vdev)
2791 +{
2792 + __virtio_clear_bit(vdev, VIRTIO_F_IOMMU_PLATFORM);
2793 + return 0;
2794 +}
2795 +
2796 static unsigned int features[] = {
2797 VIRTIO_BALLOON_F_MUST_TELL_HOST,
2798 VIRTIO_BALLOON_F_STATS_VQ,
2799 @@ -676,6 +682,7 @@ static struct virtio_driver virtio_balloon_driver = {
2800 .driver.name = KBUILD_MODNAME,
2801 .driver.owner = THIS_MODULE,
2802 .id_table = id_table,
2803 + .validate = virtballoon_validate,
2804 .probe = virtballoon_probe,
2805 .remove = virtballoon_remove,
2806 .config_changed = virtballoon_changed,
2807 diff --git a/fs/btrfs/hash.c b/fs/btrfs/hash.c
2808 index a97fdc156a03..baacc1866861 100644
2809 --- a/fs/btrfs/hash.c
2810 +++ b/fs/btrfs/hash.c
2811 @@ -38,6 +38,7 @@ u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length)
2812 {
2813 SHASH_DESC_ON_STACK(shash, tfm);
2814 u32 *ctx = (u32 *)shash_desc_ctx(shash);
2815 + u32 retval;
2816 int err;
2817
2818 shash->tfm = tfm;
2819 @@ -47,5 +48,7 @@ u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length)
2820 err = crypto_shash_update(shash, address, length);
2821 BUG_ON(err);
2822
2823 - return *ctx;
2824 + retval = *ctx;
2825 + barrier_data(ctx);
2826 + return retval;
2827 }
2828 diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
2829 index a6ab012a2c6a..c8aabba502f6 100644
2830 --- a/fs/configfs/symlink.c
2831 +++ b/fs/configfs/symlink.c
2832 @@ -83,14 +83,13 @@ static int create_link(struct config_item *parent_item,
2833 ret = -ENOMEM;
2834 sl = kmalloc(sizeof(struct configfs_symlink), GFP_KERNEL);
2835 if (sl) {
2836 - sl->sl_target = config_item_get(item);
2837 spin_lock(&configfs_dirent_lock);
2838 if (target_sd->s_type & CONFIGFS_USET_DROPPING) {
2839 spin_unlock(&configfs_dirent_lock);
2840 - config_item_put(item);
2841 kfree(sl);
2842 return -ENOENT;
2843 }
2844 + sl->sl_target = config_item_get(item);
2845 list_add(&sl->sl_list, &target_sd->s_links);
2846 spin_unlock(&configfs_dirent_lock);
2847 ret = configfs_create_link(sl, parent_item->ci_dentry,
2848 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
2849 index 05d7e2cefc56..90b4a76528d0 100644
2850 --- a/fs/f2fs/f2fs.h
2851 +++ b/fs/f2fs/f2fs.h
2852 @@ -1007,6 +1007,7 @@ static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
2853 {
2854 SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver);
2855 u32 *ctx = (u32 *)shash_desc_ctx(shash);
2856 + u32 retval;
2857 int err;
2858
2859 shash->tfm = sbi->s_chksum_driver;
2860 @@ -1016,7 +1017,9 @@ static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
2861 err = crypto_shash_update(shash, address, length);
2862 BUG_ON(err);
2863
2864 - return *ctx;
2865 + retval = *ctx;
2866 + barrier_data(ctx);
2867 + return retval;
2868 }
2869
2870 static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
2871 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
2872 index dde861387a40..d44f5456eb9b 100644
2873 --- a/fs/hugetlbfs/inode.c
2874 +++ b/fs/hugetlbfs/inode.c
2875 @@ -200,7 +200,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
2876 addr = ALIGN(addr, huge_page_size(h));
2877 vma = find_vma(mm, addr);
2878 if (TASK_SIZE - len >= addr &&
2879 - (!vma || addr + len <= vma->vm_start))
2880 + (!vma || addr + len <= vm_start_gap(vma)))
2881 return addr;
2882 }
2883
2884 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
2885 index 312578089544..f4016826255a 100644
2886 --- a/fs/proc/task_mmu.c
2887 +++ b/fs/proc/task_mmu.c
2888 @@ -300,11 +300,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
2889
2890 /* We don't show the stack guard page in /proc/maps */
2891 start = vma->vm_start;
2892 - if (stack_guard_page_start(vma, start))
2893 - start += PAGE_SIZE;
2894 end = vma->vm_end;
2895 - if (stack_guard_page_end(vma, end))
2896 - end -= PAGE_SIZE;
2897
2898 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
2899 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
2900 diff --git a/fs/read_write.c b/fs/read_write.c
2901 index c4f88afbc67f..f77eb2262eb9 100644
2902 --- a/fs/read_write.c
2903 +++ b/fs/read_write.c
2904 @@ -1210,7 +1210,7 @@ static size_t compat_writev(struct file *file,
2905 if (!(file->f_mode & FMODE_CAN_WRITE))
2906 goto out;
2907
2908 - ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos, 0);
2909 + ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos, flags);
2910
2911 out:
2912 if (ret > 0)
2913 diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
2914 index f7555fc25877..1d622f276e3a 100644
2915 --- a/fs/userfaultfd.c
2916 +++ b/fs/userfaultfd.c
2917 @@ -340,9 +340,28 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason)
2918 bool must_wait, return_to_userland;
2919 long blocking_state;
2920
2921 - BUG_ON(!rwsem_is_locked(&mm->mmap_sem));
2922 -
2923 ret = VM_FAULT_SIGBUS;
2924 +
2925 + /*
2926 + * We don't do userfault handling for the final child pid update.
2927 + *
2928 + * We also don't do userfault handling during
2929 + * coredumping. hugetlbfs has the special
2930 + * follow_hugetlb_page() to skip missing pages in the
2931 + * FOLL_DUMP case, anon memory also checks for FOLL_DUMP with
2932 + * the no_page_table() helper in follow_page_mask(), but the
2933 + * shmem_vm_ops->fault method is invoked even during
2934 + * coredumping without mmap_sem and it ends up here.
2935 + */
2936 + if (current->flags & (PF_EXITING|PF_DUMPCORE))
2937 + goto out;
2938 +
2939 + /*
2940 + * Coredumping runs without mmap_sem so we can only check that
2941 + * the mmap_sem is held, if PF_DUMPCORE was not set.
2942 + */
2943 + WARN_ON_ONCE(!rwsem_is_locked(&mm->mmap_sem));
2944 +
2945 ctx = vmf->vma->vm_userfaultfd_ctx.ctx;
2946 if (!ctx)
2947 goto out;
2948 @@ -361,12 +380,6 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason)
2949 goto out;
2950
2951 /*
2952 - * We don't do userfault handling for the final child pid update.
2953 - */
2954 - if (current->flags & PF_EXITING)
2955 - goto out;
2956 -
2957 - /*
2958 * Check that we can return VM_FAULT_RETRY.
2959 *
2960 * NOTE: it should become possible to return VM_FAULT_RETRY
2961 diff --git a/include/linux/mm.h b/include/linux/mm.h
2962 index 018b134f6427..cec423ba6d4b 100644
2963 --- a/include/linux/mm.h
2964 +++ b/include/linux/mm.h
2965 @@ -1381,12 +1381,6 @@ int clear_page_dirty_for_io(struct page *page);
2966
2967 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
2968
2969 -/* Is the vma a continuation of the stack vma above it? */
2970 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
2971 -{
2972 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
2973 -}
2974 -
2975 static inline bool vma_is_anonymous(struct vm_area_struct *vma)
2976 {
2977 return !vma->vm_ops;
2978 @@ -1402,28 +1396,6 @@ bool vma_is_shmem(struct vm_area_struct *vma);
2979 static inline bool vma_is_shmem(struct vm_area_struct *vma) { return false; }
2980 #endif
2981
2982 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
2983 - unsigned long addr)
2984 -{
2985 - return (vma->vm_flags & VM_GROWSDOWN) &&
2986 - (vma->vm_start == addr) &&
2987 - !vma_growsdown(vma->vm_prev, addr);
2988 -}
2989 -
2990 -/* Is the vma a continuation of the stack vma below it? */
2991 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
2992 -{
2993 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
2994 -}
2995 -
2996 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
2997 - unsigned long addr)
2998 -{
2999 - return (vma->vm_flags & VM_GROWSUP) &&
3000 - (vma->vm_end == addr) &&
3001 - !vma_growsup(vma->vm_next, addr);
3002 -}
3003 -
3004 int vma_is_stack_for_current(struct vm_area_struct *vma);
3005
3006 extern unsigned long move_page_tables(struct vm_area_struct *vma,
3007 @@ -2210,6 +2182,7 @@ void page_cache_async_readahead(struct address_space *mapping,
3008 pgoff_t offset,
3009 unsigned long size);
3010
3011 +extern unsigned long stack_guard_gap;
3012 /* Generic expand stack which grows the stack according to GROWS{UP,DOWN} */
3013 extern int expand_stack(struct vm_area_struct *vma, unsigned long address);
3014
3015 @@ -2238,6 +2211,30 @@ static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * m
3016 return vma;
3017 }
3018
3019 +static inline unsigned long vm_start_gap(struct vm_area_struct *vma)
3020 +{
3021 + unsigned long vm_start = vma->vm_start;
3022 +
3023 + if (vma->vm_flags & VM_GROWSDOWN) {
3024 + vm_start -= stack_guard_gap;
3025 + if (vm_start > vma->vm_start)
3026 + vm_start = 0;
3027 + }
3028 + return vm_start;
3029 +}
3030 +
3031 +static inline unsigned long vm_end_gap(struct vm_area_struct *vma)
3032 +{
3033 + unsigned long vm_end = vma->vm_end;
3034 +
3035 + if (vma->vm_flags & VM_GROWSUP) {
3036 + vm_end += stack_guard_gap;
3037 + if (vm_end < vma->vm_end)
3038 + vm_end = -PAGE_SIZE;
3039 + }
3040 + return vm_end;
3041 +}
3042 +
3043 static inline unsigned long vma_pages(struct vm_area_struct *vma)
3044 {
3045 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
3046 diff --git a/include/uapi/linux/usb/ch11.h b/include/uapi/linux/usb/ch11.h
3047 index 361297e96f58..576c704e3fb8 100644
3048 --- a/include/uapi/linux/usb/ch11.h
3049 +++ b/include/uapi/linux/usb/ch11.h
3050 @@ -22,6 +22,9 @@
3051 */
3052 #define USB_MAXCHILDREN 31
3053
3054 +/* See USB 3.1 spec Table 10-5 */
3055 +#define USB_SS_MAXPORTS 15
3056 +
3057 /*
3058 * Hub request types
3059 */
3060 diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
3061 index a4afe5cc5af1..36dc72a54982 100644
3062 --- a/kernel/irq/manage.c
3063 +++ b/kernel/irq/manage.c
3064 @@ -1310,8 +1310,10 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
3065 ret = __irq_set_trigger(desc,
3066 new->flags & IRQF_TRIGGER_MASK);
3067
3068 - if (ret)
3069 + if (ret) {
3070 + irq_release_resources(desc);
3071 goto out_mask;
3072 + }
3073 }
3074
3075 desc->istate &= ~(IRQS_AUTODETECT | IRQS_SPURIOUS_DISABLED | \
3076 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
3077 index 3b31fc05a0f1..8119ea560688 100644
3078 --- a/kernel/sched/core.c
3079 +++ b/kernel/sched/core.c
3080 @@ -5533,7 +5533,7 @@ void idle_task_exit(void)
3081 BUG_ON(cpu_online(smp_processor_id()));
3082
3083 if (mm != &init_mm) {
3084 - switch_mm_irqs_off(mm, &init_mm, current);
3085 + switch_mm(mm, &init_mm, current);
3086 finish_arch_post_lock_switch();
3087 }
3088 mmdrop(mm);
3089 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
3090 index ce3a31e8eb36..d4847cd73d6b 100644
3091 --- a/kernel/time/alarmtimer.c
3092 +++ b/kernel/time/alarmtimer.c
3093 @@ -387,7 +387,7 @@ void alarm_start_relative(struct alarm *alarm, ktime_t start)
3094 {
3095 struct alarm_base *base = &alarm_bases[alarm->type];
3096
3097 - start = ktime_add(start, base->gettime());
3098 + start = ktime_add_safe(start, base->gettime());
3099 alarm_start(alarm, start);
3100 }
3101 EXPORT_SYMBOL_GPL(alarm_start_relative);
3102 @@ -475,7 +475,7 @@ u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval)
3103 overrun++;
3104 }
3105
3106 - alarm->node.expires = ktime_add(alarm->node.expires, interval);
3107 + alarm->node.expires = ktime_add_safe(alarm->node.expires, interval);
3108 return overrun;
3109 }
3110 EXPORT_SYMBOL_GPL(alarm_forward);
3111 @@ -660,13 +660,21 @@ static int alarm_timer_set(struct k_itimer *timr, int flags,
3112
3113 /* start the timer */
3114 timr->it.alarm.interval = timespec_to_ktime(new_setting->it_interval);
3115 +
3116 + /*
3117 + * Rate limit to the tick as a hot fix to prevent DOS. Will be
3118 + * mopped up later.
3119 + */
3120 + if (timr->it.alarm.interval < TICK_NSEC)
3121 + timr->it.alarm.interval = TICK_NSEC;
3122 +
3123 exp = timespec_to_ktime(new_setting->it_value);
3124 /* Convert (if necessary) to absolute time */
3125 if (flags != TIMER_ABSTIME) {
3126 ktime_t now;
3127
3128 now = alarm_bases[timr->it.alarm.alarmtimer.type].gettime();
3129 - exp = ktime_add(now, exp);
3130 + exp = ktime_add_safe(now, exp);
3131 }
3132
3133 alarm_start(&timr->it.alarm.alarmtimer, exp);
3134 diff --git a/lib/libcrc32c.c b/lib/libcrc32c.c
3135 index 74a54b7f2562..9f79547d1b97 100644
3136 --- a/lib/libcrc32c.c
3137 +++ b/lib/libcrc32c.c
3138 @@ -43,7 +43,7 @@ static struct crypto_shash *tfm;
3139 u32 crc32c(u32 crc, const void *address, unsigned int length)
3140 {
3141 SHASH_DESC_ON_STACK(shash, tfm);
3142 - u32 *ctx = (u32 *)shash_desc_ctx(shash);
3143 + u32 ret, *ctx = (u32 *)shash_desc_ctx(shash);
3144 int err;
3145
3146 shash->tfm = tfm;
3147 @@ -53,7 +53,9 @@ u32 crc32c(u32 crc, const void *address, unsigned int length)
3148 err = crypto_shash_update(shash, address, length);
3149 BUG_ON(err);
3150
3151 - return *ctx;
3152 + ret = *ctx;
3153 + barrier_data(ctx);
3154 + return ret;
3155 }
3156
3157 EXPORT_SYMBOL(crc32c);
3158 diff --git a/mm/gup.c b/mm/gup.c
3159 index fb87cbf37e52..1466f3545870 100644
3160 --- a/mm/gup.c
3161 +++ b/mm/gup.c
3162 @@ -387,11 +387,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
3163 /* mlock all present pages, but do not fault in new pages */
3164 if ((*flags & (FOLL_POPULATE | FOLL_MLOCK)) == FOLL_MLOCK)
3165 return -ENOENT;
3166 - /* For mm_populate(), just skip the stack guard page. */
3167 - if ((*flags & FOLL_POPULATE) &&
3168 - (stack_guard_page_start(vma, address) ||
3169 - stack_guard_page_end(vma, address + PAGE_SIZE)))
3170 - return -ENOENT;
3171 if (*flags & FOLL_WRITE)
3172 fault_flags |= FAULT_FLAG_WRITE;
3173 if (*flags & FOLL_REMOTE)
3174 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
3175 index f3c4f9d22821..209b33e8c247 100644
3176 --- a/mm/huge_memory.c
3177 +++ b/mm/huge_memory.c
3178 @@ -1412,8 +1412,11 @@ int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t pmd)
3179 */
3180 if (unlikely(pmd_trans_migrating(*vmf->pmd))) {
3181 page = pmd_page(*vmf->pmd);
3182 + if (!get_page_unless_zero(page))
3183 + goto out_unlock;
3184 spin_unlock(vmf->ptl);
3185 wait_on_page_locked(page);
3186 + put_page(page);
3187 goto out;
3188 }
3189
3190 @@ -1445,9 +1448,12 @@ int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t pmd)
3191
3192 /* Migration could have started since the pmd_trans_migrating check */
3193 if (!page_locked) {
3194 + page_nid = -1;
3195 + if (!get_page_unless_zero(page))
3196 + goto out_unlock;
3197 spin_unlock(vmf->ptl);
3198 wait_on_page_locked(page);
3199 - page_nid = -1;
3200 + put_page(page);
3201 goto out;
3202 }
3203
3204 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
3205 index d7780dfdf541..b85d3d9fc026 100644
3206 --- a/mm/memory-failure.c
3207 +++ b/mm/memory-failure.c
3208 @@ -1175,7 +1175,10 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
3209 * page_remove_rmap() in try_to_unmap_one(). So to determine page status
3210 * correctly, we save a copy of the page flags at this time.
3211 */
3212 - page_flags = p->flags;
3213 + if (PageHuge(p))
3214 + page_flags = hpage->flags;
3215 + else
3216 + page_flags = p->flags;
3217
3218 /*
3219 * unpoison always clear PG_hwpoison inside page lock
3220 diff --git a/mm/memory.c b/mm/memory.c
3221 index 2437dc08ab36..44a4dfc31682 100644
3222 --- a/mm/memory.c
3223 +++ b/mm/memory.c
3224 @@ -2855,40 +2855,6 @@ int do_swap_page(struct vm_fault *vmf)
3225 }
3226
3227 /*
3228 - * This is like a special single-page "expand_{down|up}wards()",
3229 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
3230 - * doesn't hit another vma.
3231 - */
3232 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
3233 -{
3234 - address &= PAGE_MASK;
3235 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
3236 - struct vm_area_struct *prev = vma->vm_prev;
3237 -
3238 - /*
3239 - * Is there a mapping abutting this one below?
3240 - *
3241 - * That's only ok if it's the same stack mapping
3242 - * that has gotten split..
3243 - */
3244 - if (prev && prev->vm_end == address)
3245 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
3246 -
3247 - return expand_downwards(vma, address - PAGE_SIZE);
3248 - }
3249 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
3250 - struct vm_area_struct *next = vma->vm_next;
3251 -
3252 - /* As VM_GROWSDOWN but s/below/above/ */
3253 - if (next && next->vm_start == address + PAGE_SIZE)
3254 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
3255 -
3256 - return expand_upwards(vma, address + PAGE_SIZE);
3257 - }
3258 - return 0;
3259 -}
3260 -
3261 -/*
3262 * We enter with non-exclusive mmap_sem (to exclude vma changes,
3263 * but allow concurrent faults), and pte mapped but not yet locked.
3264 * We return with mmap_sem still held, but pte unmapped and unlocked.
3265 @@ -2904,10 +2870,6 @@ static int do_anonymous_page(struct vm_fault *vmf)
3266 if (vma->vm_flags & VM_SHARED)
3267 return VM_FAULT_SIGBUS;
3268
3269 - /* Check if we need to add a guard page to the stack */
3270 - if (check_stack_guard_page(vma, vmf->address) < 0)
3271 - return VM_FAULT_SIGSEGV;
3272 -
3273 /*
3274 * Use pte_alloc() instead of pte_alloc_map(). We can't run
3275 * pte_offset_map() on pmds where a huge pmd might be created
3276 diff --git a/mm/mmap.c b/mm/mmap.c
3277 index bfbe8856d134..cde1262776dd 100644
3278 --- a/mm/mmap.c
3279 +++ b/mm/mmap.c
3280 @@ -183,6 +183,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
3281 unsigned long retval;
3282 unsigned long newbrk, oldbrk;
3283 struct mm_struct *mm = current->mm;
3284 + struct vm_area_struct *next;
3285 unsigned long min_brk;
3286 bool populate;
3287 LIST_HEAD(uf);
3288 @@ -229,7 +230,8 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
3289 }
3290
3291 /* Check against existing mmap mappings. */
3292 - if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE))
3293 + next = find_vma(mm, oldbrk);
3294 + if (next && newbrk + PAGE_SIZE > vm_start_gap(next))
3295 goto out;
3296
3297 /* Ok, looks good - let it rip. */
3298 @@ -253,10 +255,22 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
3299
3300 static long vma_compute_subtree_gap(struct vm_area_struct *vma)
3301 {
3302 - unsigned long max, subtree_gap;
3303 - max = vma->vm_start;
3304 - if (vma->vm_prev)
3305 - max -= vma->vm_prev->vm_end;
3306 + unsigned long max, prev_end, subtree_gap;
3307 +
3308 + /*
3309 + * Note: in the rare case of a VM_GROWSDOWN above a VM_GROWSUP, we
3310 + * allow two stack_guard_gaps between them here, and when choosing
3311 + * an unmapped area; whereas when expanding we only require one.
3312 + * That's a little inconsistent, but keeps the code here simpler.
3313 + */
3314 + max = vm_start_gap(vma);
3315 + if (vma->vm_prev) {
3316 + prev_end = vm_end_gap(vma->vm_prev);
3317 + if (max > prev_end)
3318 + max -= prev_end;
3319 + else
3320 + max = 0;
3321 + }
3322 if (vma->vm_rb.rb_left) {
3323 subtree_gap = rb_entry(vma->vm_rb.rb_left,
3324 struct vm_area_struct, vm_rb)->rb_subtree_gap;
3325 @@ -352,7 +366,7 @@ static void validate_mm(struct mm_struct *mm)
3326 anon_vma_unlock_read(anon_vma);
3327 }
3328
3329 - highest_address = vma->vm_end;
3330 + highest_address = vm_end_gap(vma);
3331 vma = vma->vm_next;
3332 i++;
3333 }
3334 @@ -541,7 +555,7 @@ void __vma_link_rb(struct mm_struct *mm, struct vm_area_struct *vma,
3335 if (vma->vm_next)
3336 vma_gap_update(vma->vm_next);
3337 else
3338 - mm->highest_vm_end = vma->vm_end;
3339 + mm->highest_vm_end = vm_end_gap(vma);
3340
3341 /*
3342 * vma->vm_prev wasn't known when we followed the rbtree to find the
3343 @@ -856,7 +870,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
3344 vma_gap_update(vma);
3345 if (end_changed) {
3346 if (!next)
3347 - mm->highest_vm_end = end;
3348 + mm->highest_vm_end = vm_end_gap(vma);
3349 else if (!adjust_next)
3350 vma_gap_update(next);
3351 }
3352 @@ -941,7 +955,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
3353 * mm->highest_vm_end doesn't need any update
3354 * in remove_next == 1 case.
3355 */
3356 - VM_WARN_ON(mm->highest_vm_end != end);
3357 + VM_WARN_ON(mm->highest_vm_end != vm_end_gap(vma));
3358 }
3359 }
3360 if (insert && file)
3361 @@ -1787,7 +1801,7 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
3362
3363 while (true) {
3364 /* Visit left subtree if it looks promising */
3365 - gap_end = vma->vm_start;
3366 + gap_end = vm_start_gap(vma);
3367 if (gap_end >= low_limit && vma->vm_rb.rb_left) {
3368 struct vm_area_struct *left =
3369 rb_entry(vma->vm_rb.rb_left,
3370 @@ -1798,12 +1812,13 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
3371 }
3372 }
3373
3374 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
3375 + gap_start = vma->vm_prev ? vm_end_gap(vma->vm_prev) : 0;
3376 check_current:
3377 /* Check if current node has a suitable gap */
3378 if (gap_start > high_limit)
3379 return -ENOMEM;
3380 - if (gap_end >= low_limit && gap_end - gap_start >= length)
3381 + if (gap_end >= low_limit &&
3382 + gap_end > gap_start && gap_end - gap_start >= length)
3383 goto found;
3384
3385 /* Visit right subtree if it looks promising */
3386 @@ -1825,8 +1840,8 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
3387 vma = rb_entry(rb_parent(prev),
3388 struct vm_area_struct, vm_rb);
3389 if (prev == vma->vm_rb.rb_left) {
3390 - gap_start = vma->vm_prev->vm_end;
3391 - gap_end = vma->vm_start;
3392 + gap_start = vm_end_gap(vma->vm_prev);
3393 + gap_end = vm_start_gap(vma);
3394 goto check_current;
3395 }
3396 }
3397 @@ -1890,7 +1905,7 @@ unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
3398
3399 while (true) {
3400 /* Visit right subtree if it looks promising */
3401 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
3402 + gap_start = vma->vm_prev ? vm_end_gap(vma->vm_prev) : 0;
3403 if (gap_start <= high_limit && vma->vm_rb.rb_right) {
3404 struct vm_area_struct *right =
3405 rb_entry(vma->vm_rb.rb_right,
3406 @@ -1903,10 +1918,11 @@ unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
3407
3408 check_current:
3409 /* Check if current node has a suitable gap */
3410 - gap_end = vma->vm_start;
3411 + gap_end = vm_start_gap(vma);
3412 if (gap_end < low_limit)
3413 return -ENOMEM;
3414 - if (gap_start <= high_limit && gap_end - gap_start >= length)
3415 + if (gap_start <= high_limit &&
3416 + gap_end > gap_start && gap_end - gap_start >= length)
3417 goto found;
3418
3419 /* Visit left subtree if it looks promising */
3420 @@ -1929,7 +1945,7 @@ unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
3421 struct vm_area_struct, vm_rb);
3422 if (prev == vma->vm_rb.rb_right) {
3423 gap_start = vma->vm_prev ?
3424 - vma->vm_prev->vm_end : 0;
3425 + vm_end_gap(vma->vm_prev) : 0;
3426 goto check_current;
3427 }
3428 }
3429 @@ -1967,7 +1983,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3430 unsigned long len, unsigned long pgoff, unsigned long flags)
3431 {
3432 struct mm_struct *mm = current->mm;
3433 - struct vm_area_struct *vma;
3434 + struct vm_area_struct *vma, *prev;
3435 struct vm_unmapped_area_info info;
3436
3437 if (len > TASK_SIZE - mmap_min_addr)
3438 @@ -1978,9 +1994,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3439
3440 if (addr) {
3441 addr = PAGE_ALIGN(addr);
3442 - vma = find_vma(mm, addr);
3443 + vma = find_vma_prev(mm, addr, &prev);
3444 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
3445 - (!vma || addr + len <= vma->vm_start))
3446 + (!vma || addr + len <= vm_start_gap(vma)) &&
3447 + (!prev || addr >= vm_end_gap(prev)))
3448 return addr;
3449 }
3450
3451 @@ -2003,7 +2020,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3452 const unsigned long len, const unsigned long pgoff,
3453 const unsigned long flags)
3454 {
3455 - struct vm_area_struct *vma;
3456 + struct vm_area_struct *vma, *prev;
3457 struct mm_struct *mm = current->mm;
3458 unsigned long addr = addr0;
3459 struct vm_unmapped_area_info info;
3460 @@ -2018,9 +2035,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3461 /* requesting a specific address */
3462 if (addr) {
3463 addr = PAGE_ALIGN(addr);
3464 - vma = find_vma(mm, addr);
3465 + vma = find_vma_prev(mm, addr, &prev);
3466 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
3467 - (!vma || addr + len <= vma->vm_start))
3468 + (!vma || addr + len <= vm_start_gap(vma)) &&
3469 + (!prev || addr >= vm_end_gap(prev)))
3470 return addr;
3471 }
3472
3473 @@ -2155,21 +2173,19 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
3474 * update accounting. This is shared with both the
3475 * grow-up and grow-down cases.
3476 */
3477 -static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, unsigned long grow)
3478 +static int acct_stack_growth(struct vm_area_struct *vma,
3479 + unsigned long size, unsigned long grow)
3480 {
3481 struct mm_struct *mm = vma->vm_mm;
3482 struct rlimit *rlim = current->signal->rlim;
3483 - unsigned long new_start, actual_size;
3484 + unsigned long new_start;
3485
3486 /* address space limit tests */
3487 if (!may_expand_vm(mm, vma->vm_flags, grow))
3488 return -ENOMEM;
3489
3490 /* Stack limit test */
3491 - actual_size = size;
3492 - if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
3493 - actual_size -= PAGE_SIZE;
3494 - if (actual_size > READ_ONCE(rlim[RLIMIT_STACK].rlim_cur))
3495 + if (size > READ_ONCE(rlim[RLIMIT_STACK].rlim_cur))
3496 return -ENOMEM;
3497
3498 /* mlock limit tests */
3499 @@ -2207,16 +2223,32 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
3500 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
3501 {
3502 struct mm_struct *mm = vma->vm_mm;
3503 + struct vm_area_struct *next;
3504 + unsigned long gap_addr;
3505 int error = 0;
3506
3507 if (!(vma->vm_flags & VM_GROWSUP))
3508 return -EFAULT;
3509
3510 - /* Guard against wrapping around to address 0. */
3511 - if (address < PAGE_ALIGN(address+4))
3512 - address = PAGE_ALIGN(address+4);
3513 - else
3514 + /* Guard against exceeding limits of the address space. */
3515 + address &= PAGE_MASK;
3516 + if (address >= TASK_SIZE)
3517 return -ENOMEM;
3518 + address += PAGE_SIZE;
3519 +
3520 + /* Enforce stack_guard_gap */
3521 + gap_addr = address + stack_guard_gap;
3522 +
3523 + /* Guard against overflow */
3524 + if (gap_addr < address || gap_addr > TASK_SIZE)
3525 + gap_addr = TASK_SIZE;
3526 +
3527 + next = vma->vm_next;
3528 + if (next && next->vm_start < gap_addr) {
3529 + if (!(next->vm_flags & VM_GROWSUP))
3530 + return -ENOMEM;
3531 + /* Check that both stack segments have the same anon_vma? */
3532 + }
3533
3534 /* We must make sure the anon_vma is allocated. */
3535 if (unlikely(anon_vma_prepare(vma)))
3536 @@ -2261,7 +2293,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
3537 if (vma->vm_next)
3538 vma_gap_update(vma->vm_next);
3539 else
3540 - mm->highest_vm_end = address;
3541 + mm->highest_vm_end = vm_end_gap(vma);
3542 spin_unlock(&mm->page_table_lock);
3543
3544 perf_event_mmap(vma);
3545 @@ -2282,6 +2314,8 @@ int expand_downwards(struct vm_area_struct *vma,
3546 unsigned long address)
3547 {
3548 struct mm_struct *mm = vma->vm_mm;
3549 + struct vm_area_struct *prev;
3550 + unsigned long gap_addr;
3551 int error;
3552
3553 address &= PAGE_MASK;
3554 @@ -2289,6 +2323,17 @@ int expand_downwards(struct vm_area_struct *vma,
3555 if (error)
3556 return error;
3557
3558 + /* Enforce stack_guard_gap */
3559 + gap_addr = address - stack_guard_gap;
3560 + if (gap_addr > address)
3561 + return -ENOMEM;
3562 + prev = vma->vm_prev;
3563 + if (prev && prev->vm_end > gap_addr) {
3564 + if (!(prev->vm_flags & VM_GROWSDOWN))
3565 + return -ENOMEM;
3566 + /* Check that both stack segments have the same anon_vma? */
3567 + }
3568 +
3569 /* We must make sure the anon_vma is allocated. */
3570 if (unlikely(anon_vma_prepare(vma)))
3571 return -ENOMEM;
3572 @@ -2343,28 +2388,25 @@ int expand_downwards(struct vm_area_struct *vma,
3573 return error;
3574 }
3575
3576 -/*
3577 - * Note how expand_stack() refuses to expand the stack all the way to
3578 - * abut the next virtual mapping, *unless* that mapping itself is also
3579 - * a stack mapping. We want to leave room for a guard page, after all
3580 - * (the guard page itself is not added here, that is done by the
3581 - * actual page faulting logic)
3582 - *
3583 - * This matches the behavior of the guard page logic (see mm/memory.c:
3584 - * check_stack_guard_page()), which only allows the guard page to be
3585 - * removed under these circumstances.
3586 - */
3587 +/* enforced gap between the expanding stack and other mappings. */
3588 +unsigned long stack_guard_gap = 256UL<<PAGE_SHIFT;
3589 +
3590 +static int __init cmdline_parse_stack_guard_gap(char *p)
3591 +{
3592 + unsigned long val;
3593 + char *endptr;
3594 +
3595 + val = simple_strtoul(p, &endptr, 10);
3596 + if (!*endptr)
3597 + stack_guard_gap = val << PAGE_SHIFT;
3598 +
3599 + return 0;
3600 +}
3601 +__setup("stack_guard_gap=", cmdline_parse_stack_guard_gap);
3602 +
3603 #ifdef CONFIG_STACK_GROWSUP
3604 int expand_stack(struct vm_area_struct *vma, unsigned long address)
3605 {
3606 - struct vm_area_struct *next;
3607 -
3608 - address &= PAGE_MASK;
3609 - next = vma->vm_next;
3610 - if (next && next->vm_start == address + PAGE_SIZE) {
3611 - if (!(next->vm_flags & VM_GROWSUP))
3612 - return -ENOMEM;
3613 - }
3614 return expand_upwards(vma, address);
3615 }
3616
3617 @@ -2386,14 +2428,6 @@ find_extend_vma(struct mm_struct *mm, unsigned long addr)
3618 #else
3619 int expand_stack(struct vm_area_struct *vma, unsigned long address)
3620 {
3621 - struct vm_area_struct *prev;
3622 -
3623 - address &= PAGE_MASK;
3624 - prev = vma->vm_prev;
3625 - if (prev && prev->vm_end == address) {
3626 - if (!(prev->vm_flags & VM_GROWSDOWN))
3627 - return -ENOMEM;
3628 - }
3629 return expand_downwards(vma, address);
3630 }
3631
3632 @@ -2491,7 +2525,7 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
3633 vma->vm_prev = prev;
3634 vma_gap_update(vma);
3635 } else
3636 - mm->highest_vm_end = prev ? prev->vm_end : 0;
3637 + mm->highest_vm_end = prev ? vm_end_gap(prev) : 0;
3638 tail_vma->vm_next = NULL;
3639
3640 /* Kill the cache */
3641 diff --git a/mm/swap_cgroup.c b/mm/swap_cgroup.c
3642 index ac6318a064d3..3405b4ee1757 100644
3643 --- a/mm/swap_cgroup.c
3644 +++ b/mm/swap_cgroup.c
3645 @@ -48,6 +48,9 @@ static int swap_cgroup_prepare(int type)
3646 if (!page)
3647 goto not_enough_page;
3648 ctrl->map[idx] = page;
3649 +
3650 + if (!(idx % SWAP_CLUSTER_MAX))
3651 + cond_resched();
3652 }
3653 return 0;
3654 not_enough_page:
3655 diff --git a/net/ipv6/ila/ila_xlat.c b/net/ipv6/ila/ila_xlat.c
3656 index af8f52ee7180..38ae62bb5ed7 100644
3657 --- a/net/ipv6/ila/ila_xlat.c
3658 +++ b/net/ipv6/ila/ila_xlat.c
3659 @@ -68,6 +68,7 @@ static inline u32 ila_locator_hash(struct ila_locator loc)
3660 {
3661 u32 *v = (u32 *)loc.v32;
3662
3663 + __ila_hash_secret_init();
3664 return jhash_2words(v[0], v[1], hashrnd);
3665 }
3666
3667 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
3668 index ac879bb17870..cd3d47818836 100644
3669 --- a/net/mac80211/cfg.c
3670 +++ b/net/mac80211/cfg.c
3671 @@ -862,6 +862,8 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
3672 default:
3673 return -EINVAL;
3674 }
3675 + sdata->u.ap.req_smps = sdata->smps_mode;
3676 +
3677 sdata->needed_rx_chains = sdata->local->rx_chains;
3678
3679 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
3680 diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
3681 index 98999d3d5262..62d13eabe17f 100644
3682 --- a/net/mac80211/ibss.c
3683 +++ b/net/mac80211/ibss.c
3684 @@ -66,6 +66,8 @@ ieee80211_ibss_build_presp(struct ieee80211_sub_if_data *sdata,
3685 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
3686 2 + sizeof(struct ieee80211_ht_cap) +
3687 2 + sizeof(struct ieee80211_ht_operation) +
3688 + 2 + sizeof(struct ieee80211_vht_cap) +
3689 + 2 + sizeof(struct ieee80211_vht_operation) +
3690 ifibss->ie_len;
3691 presp = kzalloc(sizeof(*presp) + frame_len, GFP_KERNEL);
3692 if (!presp)
3693 diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
3694 index 4d7543d1a62c..a654c25f7858 100644
3695 --- a/net/mac80211/rx.c
3696 +++ b/net/mac80211/rx.c
3697 @@ -1587,12 +1587,16 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
3698 */
3699 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
3700 !ieee80211_has_morefrags(hdr->frame_control) &&
3701 + !ieee80211_is_back_req(hdr->frame_control) &&
3702 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
3703 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
3704 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
3705 - /* PM bit is only checked in frames where it isn't reserved,
3706 + /*
3707 + * PM bit is only checked in frames where it isn't reserved,
3708 * in AP mode it's reserved in non-bufferable management frames
3709 * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
3710 + * BAR frames should be ignored as specified in
3711 + * IEEE 802.11-2012 10.2.1.2.
3712 */
3713 (!ieee80211_is_mgmt(hdr->frame_control) ||
3714 ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
3715 @@ -2466,7 +2470,8 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
3716 if (is_multicast_ether_addr(hdr->addr1)) {
3717 mpp_addr = hdr->addr3;
3718 proxied_addr = mesh_hdr->eaddr1;
3719 - } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
3720 + } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
3721 + MESH_FLAGS_AE_A5_A6) {
3722 /* has_a4 already checked in ieee80211_rx_mesh_check */
3723 mpp_addr = hdr->addr4;
3724 proxied_addr = mesh_hdr->eaddr2;
3725 diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
3726 index 3323a2fb289b..1a9d1e56c705 100644
3727 --- a/net/mac80211/sta_info.c
3728 +++ b/net/mac80211/sta_info.c
3729 @@ -2143,7 +2143,7 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
3730 struct ieee80211_sta_rx_stats *cpurxs;
3731
3732 cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
3733 - sinfo->rx_packets += cpurxs->dropped;
3734 + sinfo->rx_dropped_misc += cpurxs->dropped;
3735 }
3736 }
3737
3738 diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
3739 index c1ef22df865f..cc19614ff4e6 100644
3740 --- a/net/mac80211/wpa.c
3741 +++ b/net/mac80211/wpa.c
3742 @@ -17,6 +17,7 @@
3743 #include <asm/unaligned.h>
3744 #include <net/mac80211.h>
3745 #include <crypto/aes.h>
3746 +#include <crypto/algapi.h>
3747
3748 #include "ieee80211_i.h"
3749 #include "michael.h"
3750 @@ -153,7 +154,7 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
3751 data_len = skb->len - hdrlen - MICHAEL_MIC_LEN;
3752 key = &rx->key->conf.key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY];
3753 michael_mic(key, hdr, data, data_len, mic);
3754 - if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0)
3755 + if (crypto_memneq(mic, data + data_len, MICHAEL_MIC_LEN))
3756 goto mic_fail;
3757
3758 /* remove Michael MIC from payload */
3759 @@ -1048,7 +1049,7 @@ ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx)
3760 bip_aad(skb, aad);
3761 ieee80211_aes_cmac(key->u.aes_cmac.tfm, aad,
3762 skb->data + 24, skb->len - 24, mic);
3763 - if (memcmp(mic, mmie->mic, sizeof(mmie->mic)) != 0) {
3764 + if (crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) {
3765 key->u.aes_cmac.icverrors++;
3766 return RX_DROP_UNUSABLE;
3767 }
3768 @@ -1098,7 +1099,7 @@ ieee80211_crypto_aes_cmac_256_decrypt(struct ieee80211_rx_data *rx)
3769 bip_aad(skb, aad);
3770 ieee80211_aes_cmac_256(key->u.aes_cmac.tfm, aad,
3771 skb->data + 24, skb->len - 24, mic);
3772 - if (memcmp(mic, mmie->mic, sizeof(mmie->mic)) != 0) {
3773 + if (crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) {
3774 key->u.aes_cmac.icverrors++;
3775 return RX_DROP_UNUSABLE;
3776 }
3777 @@ -1202,7 +1203,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct ieee80211_rx_data *rx)
3778 if (ieee80211_aes_gmac(key->u.aes_gmac.tfm, aad, nonce,
3779 skb->data + 24, skb->len - 24,
3780 mic) < 0 ||
3781 - memcmp(mic, mmie->mic, sizeof(mmie->mic)) != 0) {
3782 + crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) {
3783 key->u.aes_gmac.icverrors++;
3784 return RX_DROP_UNUSABLE;
3785 }
3786 diff --git a/net/wireless/util.c b/net/wireless/util.c
3787 index 68e5f2ecee1a..8b862ab76947 100644
3788 --- a/net/wireless/util.c
3789 +++ b/net/wireless/util.c
3790 @@ -454,6 +454,8 @@ int ieee80211_data_to_8023_exthdr(struct sk_buff *skb, struct ethhdr *ehdr,
3791 if (iftype == NL80211_IFTYPE_MESH_POINT)
3792 skb_copy_bits(skb, hdrlen, &mesh_flags, 1);
3793
3794 + mesh_flags &= MESH_FLAGS_AE;
3795 +
3796 switch (hdr->frame_control &
3797 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
3798 case cpu_to_le16(IEEE80211_FCTL_TODS):
3799 @@ -469,9 +471,9 @@ int ieee80211_data_to_8023_exthdr(struct sk_buff *skb, struct ethhdr *ehdr,
3800 iftype != NL80211_IFTYPE_STATION))
3801 return -1;
3802 if (iftype == NL80211_IFTYPE_MESH_POINT) {
3803 - if (mesh_flags & MESH_FLAGS_AE_A4)
3804 + if (mesh_flags == MESH_FLAGS_AE_A4)
3805 return -1;
3806 - if (mesh_flags & MESH_FLAGS_AE_A5_A6) {
3807 + if (mesh_flags == MESH_FLAGS_AE_A5_A6) {
3808 skb_copy_bits(skb, hdrlen +
3809 offsetof(struct ieee80211s_hdr, eaddr1),
3810 tmp.h_dest, 2 * ETH_ALEN);
3811 @@ -487,9 +489,9 @@ int ieee80211_data_to_8023_exthdr(struct sk_buff *skb, struct ethhdr *ehdr,
3812 ether_addr_equal(tmp.h_source, addr)))
3813 return -1;
3814 if (iftype == NL80211_IFTYPE_MESH_POINT) {
3815 - if (mesh_flags & MESH_FLAGS_AE_A5_A6)
3816 + if (mesh_flags == MESH_FLAGS_AE_A5_A6)
3817 return -1;
3818 - if (mesh_flags & MESH_FLAGS_AE_A4)
3819 + if (mesh_flags == MESH_FLAGS_AE_A4)
3820 skb_copy_bits(skb, hdrlen +
3821 offsetof(struct ieee80211s_hdr, eaddr1),
3822 tmp.h_source, ETH_ALEN);
3823 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
3824 index 0c2ac318aa7f..71fc0b5570d1 100644
3825 --- a/security/selinux/hooks.c
3826 +++ b/security/selinux/hooks.c
3827 @@ -1106,10 +1106,8 @@ static int selinux_parse_opts_str(char *options,
3828
3829 opts->mnt_opts_flags = kcalloc(NUM_SEL_MNT_OPTS, sizeof(int),
3830 GFP_KERNEL);
3831 - if (!opts->mnt_opts_flags) {
3832 - kfree(opts->mnt_opts);
3833 + if (!opts->mnt_opts_flags)
3834 goto out_err;
3835 - }
3836
3837 if (fscontext) {
3838 opts->mnt_opts[num_mnt_opts] = fscontext;
3839 @@ -1132,6 +1130,7 @@ static int selinux_parse_opts_str(char *options,
3840 return 0;
3841
3842 out_err:
3843 + security_free_mnt_opts(opts);
3844 kfree(context);
3845 kfree(defcontext);
3846 kfree(fscontext);
3847 diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
3848 index c8256a89375a..23d685636a67 100644
3849 --- a/sound/pci/hda/hda_intel.c
3850 +++ b/sound/pci/hda/hda_intel.c
3851 @@ -369,8 +369,10 @@ enum {
3852 #define IS_KBL_LP(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x9d71)
3853 #define IS_KBL_H(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa2f0)
3854 #define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98)
3855 +#define IS_GLK(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x3198)
3856 #define IS_SKL_PLUS(pci) (IS_SKL(pci) || IS_SKL_LP(pci) || IS_BXT(pci)) || \
3857 - IS_KBL(pci) || IS_KBL_LP(pci) || IS_KBL_H(pci)
3858 + IS_KBL(pci) || IS_KBL_LP(pci) || IS_KBL_H(pci) || \
3859 + IS_GLK(pci)
3860
3861 static char *driver_short_names[] = {
3862 [AZX_DRIVER_ICH] = "HDA Intel",
3863 diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
3864 index 01eff6ce6401..d7b0b0a3a2db 100644
3865 --- a/sound/usb/quirks.c
3866 +++ b/sound/usb/quirks.c
3867 @@ -1364,7 +1364,7 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
3868 /* Amanero Combo384 USB interface with native DSD support */
3869 case USB_ID(0x16d0, 0x071a):
3870 if (fp->altsetting == 2) {
3871 - switch (chip->dev->descriptor.bcdDevice) {
3872 + switch (le16_to_cpu(chip->dev->descriptor.bcdDevice)) {
3873 case 0x199:
3874 return SNDRV_PCM_FMTBIT_DSD_U32_LE;
3875 case 0x19b: