Magellan Linux

Annotation of /trunk/kernel-magellan/patches-3.11/0103-3.11.4-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2296 - (hide annotations) (download)
Mon Oct 7 12:07:09 2013 UTC (10 years, 8 months ago) by niro
File size: 64211 byte(s)
-linux-3.11.4
1 niro 2296 diff --git a/Makefile b/Makefile
2     index 4f91b99..97bae8a1 100644
3     --- a/Makefile
4     +++ b/Makefile
5     @@ -1,6 +1,6 @@
6     VERSION = 3
7     PATCHLEVEL = 11
8     -SUBLEVEL = 3
9     +SUBLEVEL = 4
10     EXTRAVERSION =
11     NAME = Linux for Workgroups
12    
13     diff --git a/arch/arm/crypto/aes-armv4.S b/arch/arm/crypto/aes-armv4.S
14     index 19d6cd6..3a14ea8 100644
15     --- a/arch/arm/crypto/aes-armv4.S
16     +++ b/arch/arm/crypto/aes-armv4.S
17     @@ -148,7 +148,7 @@ AES_Te:
18     @ const AES_KEY *key) {
19     .align 5
20     ENTRY(AES_encrypt)
21     - sub r3,pc,#8 @ AES_encrypt
22     + adr r3,AES_encrypt
23     stmdb sp!,{r1,r4-r12,lr}
24     mov r12,r0 @ inp
25     mov r11,r2
26     @@ -381,7 +381,7 @@ _armv4_AES_encrypt:
27     .align 5
28     ENTRY(private_AES_set_encrypt_key)
29     _armv4_AES_set_encrypt_key:
30     - sub r3,pc,#8 @ AES_set_encrypt_key
31     + adr r3,_armv4_AES_set_encrypt_key
32     teq r0,#0
33     moveq r0,#-1
34     beq .Labrt
35     @@ -843,7 +843,7 @@ AES_Td:
36     @ const AES_KEY *key) {
37     .align 5
38     ENTRY(AES_decrypt)
39     - sub r3,pc,#8 @ AES_decrypt
40     + adr r3,AES_decrypt
41     stmdb sp!,{r1,r4-r12,lr}
42     mov r12,r0 @ inp
43     mov r11,r2
44     diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
45     index 563ed91..5f4ad27 100644
46     --- a/arch/x86/kernel/reboot.c
47     +++ b/arch/x86/kernel/reboot.c
48     @@ -358,6 +358,22 @@ static struct dmi_system_id __initdata reboot_dmi_table[] = {
49     DMI_MATCH(DMI_PRODUCT_NAME, "Precision M6600"),
50     },
51     },
52     + { /* Handle problems with rebooting on the Dell PowerEdge C6100. */
53     + .callback = set_pci_reboot,
54     + .ident = "Dell PowerEdge C6100",
55     + .matches = {
56     + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
57     + DMI_MATCH(DMI_PRODUCT_NAME, "C6100"),
58     + },
59     + },
60     + { /* Some C6100 machines were shipped with vendor being 'Dell'. */
61     + .callback = set_pci_reboot,
62     + .ident = "Dell PowerEdge C6100",
63     + .matches = {
64     + DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
65     + DMI_MATCH(DMI_PRODUCT_NAME, "C6100"),
66     + },
67     + },
68     { }
69     };
70    
71     diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
72     index 90f6ed1..c7e22ab 100644
73     --- a/arch/x86/platform/efi/efi.c
74     +++ b/arch/x86/platform/efi/efi.c
75     @@ -912,10 +912,13 @@ void __init efi_enter_virtual_mode(void)
76    
77     for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
78     md = p;
79     - if (!(md->attribute & EFI_MEMORY_RUNTIME) &&
80     - md->type != EFI_BOOT_SERVICES_CODE &&
81     - md->type != EFI_BOOT_SERVICES_DATA)
82     - continue;
83     + if (!(md->attribute & EFI_MEMORY_RUNTIME)) {
84     +#ifdef CONFIG_X86_64
85     + if (md->type != EFI_BOOT_SERVICES_CODE &&
86     + md->type != EFI_BOOT_SERVICES_DATA)
87     +#endif
88     + continue;
89     + }
90    
91     size = md->num_pages << EFI_PAGE_SHIFT;
92     end = md->phys_addr + size;
93     diff --git a/drivers/base/core.c b/drivers/base/core.c
94     index 8856d74..2d1c6ba 100644
95     --- a/drivers/base/core.c
96     +++ b/drivers/base/core.c
97     @@ -2033,7 +2033,7 @@ EXPORT_SYMBOL_GPL(device_move);
98     */
99     void device_shutdown(void)
100     {
101     - struct device *dev;
102     + struct device *dev, *parent;
103    
104     spin_lock(&devices_kset->list_lock);
105     /*
106     @@ -2050,7 +2050,7 @@ void device_shutdown(void)
107     * prevent it from being freed because parent's
108     * lock is to be held
109     */
110     - get_device(dev->parent);
111     + parent = get_device(dev->parent);
112     get_device(dev);
113     /*
114     * Make sure the device is off the kset list, in the
115     @@ -2060,8 +2060,8 @@ void device_shutdown(void)
116     spin_unlock(&devices_kset->list_lock);
117    
118     /* hold lock to avoid race with probe/release */
119     - if (dev->parent)
120     - device_lock(dev->parent);
121     + if (parent)
122     + device_lock(parent);
123     device_lock(dev);
124    
125     /* Don't allow any more runtime suspends */
126     @@ -2079,11 +2079,11 @@ void device_shutdown(void)
127     }
128    
129     device_unlock(dev);
130     - if (dev->parent)
131     - device_unlock(dev->parent);
132     + if (parent)
133     + device_unlock(parent);
134    
135     put_device(dev);
136     - put_device(dev->parent);
137     + put_device(parent);
138    
139     spin_lock(&devices_kset->list_lock);
140     }
141     diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
142     index bedf15a..7fc8a76 100644
143     --- a/drivers/gpu/drm/i915/intel_display.c
144     +++ b/drivers/gpu/drm/i915/intel_display.c
145     @@ -4735,6 +4735,10 @@ static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
146    
147     pipeconf = 0;
148    
149     + if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
150     + I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE)
151     + pipeconf |= PIPECONF_ENABLE;
152     +
153     if (intel_crtc->pipe == 0 && INTEL_INFO(dev)->gen < 4) {
154     /* Enable pixel doubling when the dot clock is > 90% of the (display)
155     * core speed.
156     diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
157     index 26e162b..3aed1fe 100644
158     --- a/drivers/gpu/drm/i915/intel_dp.c
159     +++ b/drivers/gpu/drm/i915/intel_dp.c
160     @@ -567,7 +567,18 @@ intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
161     DRM_DEBUG_KMS("aux_ch native nack\n");
162     return -EREMOTEIO;
163     case AUX_NATIVE_REPLY_DEFER:
164     - udelay(100);
165     + /*
166     + * For now, just give more slack to branch devices. We
167     + * could check the DPCD for I2C bit rate capabilities,
168     + * and if available, adjust the interval. We could also
169     + * be more careful with DP-to-Legacy adapters where a
170     + * long legacy cable may force very low I2C bit rates.
171     + */
172     + if (intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
173     + DP_DWN_STRM_PORT_PRESENT)
174     + usleep_range(500, 600);
175     + else
176     + usleep_range(300, 400);
177     continue;
178     default:
179     DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
180     diff --git a/drivers/gpu/drm/i915/intel_tv.c b/drivers/gpu/drm/i915/intel_tv.c
181     index 39debd8..d7fe4f8 100644
182     --- a/drivers/gpu/drm/i915/intel_tv.c
183     +++ b/drivers/gpu/drm/i915/intel_tv.c
184     @@ -918,6 +918,14 @@ intel_tv_compute_config(struct intel_encoder *encoder,
185     DRM_DEBUG_KMS("forcing bpc to 8 for TV\n");
186     pipe_config->pipe_bpp = 8*3;
187    
188     + /* TV has it's own notion of sync and other mode flags, so clear them. */
189     + pipe_config->adjusted_mode.flags = 0;
190     +
191     + /*
192     + * FIXME: We don't check whether the input mode is actually what we want
193     + * or whether userspace is doing something stupid.
194     + */
195     +
196     return true;
197     }
198    
199     diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
200     index 7a96842..4a315da 100644
201     --- a/drivers/gpu/drm/radeon/cik.c
202     +++ b/drivers/gpu/drm/radeon/cik.c
203     @@ -2008,10 +2008,8 @@ static void cik_gpu_init(struct radeon_device *rdev)
204     rdev->config.cik.tile_config |= (3 << 0);
205     break;
206     }
207     - if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT)
208     - rdev->config.cik.tile_config |= 1 << 4;
209     - else
210     - rdev->config.cik.tile_config |= 0 << 4;
211     + rdev->config.cik.tile_config |=
212     + ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4;
213     rdev->config.cik.tile_config |=
214     ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
215     rdev->config.cik.tile_config |=
216     @@ -4227,8 +4225,8 @@ static int cik_mc_init(struct radeon_device *rdev)
217     rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
218     rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
219     /* size in MB on si */
220     - rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
221     - rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
222     + rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
223     + rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
224     rdev->mc.visible_vram_size = rdev->mc.aper_size;
225     si_vram_gtt_location(rdev, &rdev->mc);
226     radeon_update_bandwidth_info(rdev);
227     @@ -4506,12 +4504,13 @@ static void cik_vm_decode_fault(struct radeon_device *rdev,
228     u32 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
229     u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
230     u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
231     - char *block = (char *)&mc_client;
232     + char block[5] = { mc_client >> 24, (mc_client >> 16) & 0xff,
233     + (mc_client >> 8) & 0xff, mc_client & 0xff, 0 };
234    
235     - printk("VM fault (0x%02x, vmid %d) at page %u, %s from %s (%d)\n",
236     + printk("VM fault (0x%02x, vmid %d) at page %u, %s from '%s' (0x%08x) (%d)\n",
237     protections, vmid, addr,
238     (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
239     - block, mc_id);
240     + block, mc_client, mc_id);
241     }
242    
243     /**
244     diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
245     index 75349cd..5de5ad5 100644
246     --- a/drivers/gpu/drm/radeon/r100.c
247     +++ b/drivers/gpu/drm/radeon/r100.c
248     @@ -2926,9 +2926,11 @@ static int r100_debugfs_cp_ring_info(struct seq_file *m, void *data)
249     seq_printf(m, "CP_RB_RPTR 0x%08x\n", rdp);
250     seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw);
251     seq_printf(m, "%u dwords in ring\n", count);
252     - for (j = 0; j <= count; j++) {
253     - i = (rdp + j) & ring->ptr_mask;
254     - seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]);
255     + if (ring->ready) {
256     + for (j = 0; j <= count; j++) {
257     + i = (rdp + j) & ring->ptr_mask;
258     + seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]);
259     + }
260     }
261     return 0;
262     }
263     diff --git a/drivers/gpu/drm/radeon/r600_hdmi.c b/drivers/gpu/drm/radeon/r600_hdmi.c
264     index f264df5..a74c2aa 100644
265     --- a/drivers/gpu/drm/radeon/r600_hdmi.c
266     +++ b/drivers/gpu/drm/radeon/r600_hdmi.c
267     @@ -257,10 +257,7 @@ void r600_audio_set_dto(struct drm_encoder *encoder, u32 clock)
268     * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
269     * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
270     */
271     - if (ASIC_IS_DCE3(rdev)) {
272     - /* according to the reg specs, this should DCE3.2 only, but in
273     - * practice it seems to cover DCE3.0 as well.
274     - */
275     + if (ASIC_IS_DCE32(rdev)) {
276     if (dig->dig_encoder == 0) {
277     dto_cntl = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK;
278     dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio);
279     @@ -276,8 +273,21 @@ void r600_audio_set_dto(struct drm_encoder *encoder, u32 clock)
280     WREG32(DCCG_AUDIO_DTO1_MODULE, dto_modulo);
281     WREG32(DCCG_AUDIO_DTO_SELECT, 1); /* select DTO1 */
282     }
283     + } else if (ASIC_IS_DCE3(rdev)) {
284     + /* according to the reg specs, this should DCE3.2 only, but in
285     + * practice it seems to cover DCE3.0/3.1 as well.
286     + */
287     + if (dig->dig_encoder == 0) {
288     + WREG32(DCCG_AUDIO_DTO0_PHASE, base_rate * 100);
289     + WREG32(DCCG_AUDIO_DTO0_MODULE, clock * 100);
290     + WREG32(DCCG_AUDIO_DTO_SELECT, 0); /* select DTO0 */
291     + } else {
292     + WREG32(DCCG_AUDIO_DTO1_PHASE, base_rate * 100);
293     + WREG32(DCCG_AUDIO_DTO1_MODULE, clock * 100);
294     + WREG32(DCCG_AUDIO_DTO_SELECT, 1); /* select DTO1 */
295     + }
296     } else {
297     - /* according to the reg specs, this should be DCE2.0 and DCE3.0 */
298     + /* according to the reg specs, this should be DCE2.0 and DCE3.0/3.1 */
299     WREG32(AUDIO_DTO, AUDIO_DTO_PHASE(base_rate / 10) |
300     AUDIO_DTO_MODULE(clock / 10));
301     }
302     diff --git a/drivers/gpu/drm/radeon/radeon_asic.c b/drivers/gpu/drm/radeon/radeon_asic.c
303     index 38317b9..128279e 100644
304     --- a/drivers/gpu/drm/radeon/radeon_asic.c
305     +++ b/drivers/gpu/drm/radeon/radeon_asic.c
306     @@ -926,6 +926,8 @@ static struct radeon_asic r520_asic = {
307     .wait_for_vblank = &avivo_wait_for_vblank,
308     .set_backlight_level = &atombios_set_backlight_level,
309     .get_backlight_level = &atombios_get_backlight_level,
310     + .hdmi_enable = &r600_hdmi_enable,
311     + .hdmi_setmode = &r600_hdmi_setmode,
312     },
313     .copy = {
314     .blit = &r100_copy_blit,
315     diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
316     index 7c110ef..41b170d 100644
317     --- a/drivers/gpu/drm/radeon/radeon_cs.c
318     +++ b/drivers/gpu/drm/radeon/radeon_cs.c
319     @@ -84,7 +84,7 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
320     VRAM, also but everything into VRAM on AGP cards to avoid
321     image corruptions */
322     if (p->ring == R600_RING_TYPE_UVD_INDEX &&
323     - (i == 0 || p->rdev->flags & RADEON_IS_AGP)) {
324     + (i == 0 || drm_pci_device_is_agp(p->rdev->ddev))) {
325     /* TODO: is this still needed for NI+ ? */
326     p->relocs[i].lobj.domain =
327     RADEON_GEM_DOMAIN_VRAM;
328     diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
329     index 63398ae..d15f27e 100644
330     --- a/drivers/gpu/drm/radeon/radeon_device.c
331     +++ b/drivers/gpu/drm/radeon/radeon_device.c
332     @@ -1297,13 +1297,22 @@ int radeon_device_init(struct radeon_device *rdev,
333     return r;
334     }
335     if ((radeon_testing & 1)) {
336     - radeon_test_moves(rdev);
337     + if (rdev->accel_working)
338     + radeon_test_moves(rdev);
339     + else
340     + DRM_INFO("radeon: acceleration disabled, skipping move tests\n");
341     }
342     if ((radeon_testing & 2)) {
343     - radeon_test_syncing(rdev);
344     + if (rdev->accel_working)
345     + radeon_test_syncing(rdev);
346     + else
347     + DRM_INFO("radeon: acceleration disabled, skipping sync tests\n");
348     }
349     if (radeon_benchmarking) {
350     - radeon_benchmark(rdev, radeon_benchmarking);
351     + if (rdev->accel_working)
352     + radeon_benchmark(rdev, radeon_benchmarking);
353     + else
354     + DRM_INFO("radeon: acceleration disabled, skipping benchmarks\n");
355     }
356     return 0;
357     }
358     diff --git a/drivers/gpu/drm/radeon/radeon_pm.c b/drivers/gpu/drm/radeon/radeon_pm.c
359     index c557850..459eb7d 100644
360     --- a/drivers/gpu/drm/radeon/radeon_pm.c
361     +++ b/drivers/gpu/drm/radeon/radeon_pm.c
362     @@ -919,7 +919,7 @@ static void radeon_pm_resume_old(struct radeon_device *rdev)
363     {
364     /* set up the default clocks if the MC ucode is loaded */
365     if ((rdev->family >= CHIP_BARTS) &&
366     - (rdev->family <= CHIP_HAINAN) &&
367     + (rdev->family <= CHIP_CAYMAN) &&
368     rdev->mc_fw) {
369     if (rdev->pm.default_vddc)
370     radeon_atom_set_voltage(rdev, rdev->pm.default_vddc,
371     @@ -963,7 +963,7 @@ static void radeon_pm_resume_dpm(struct radeon_device *rdev)
372     if (ret) {
373     DRM_ERROR("radeon: dpm resume failed\n");
374     if ((rdev->family >= CHIP_BARTS) &&
375     - (rdev->family <= CHIP_HAINAN) &&
376     + (rdev->family <= CHIP_CAYMAN) &&
377     rdev->mc_fw) {
378     if (rdev->pm.default_vddc)
379     radeon_atom_set_voltage(rdev, rdev->pm.default_vddc,
380     @@ -1014,7 +1014,7 @@ static int radeon_pm_init_old(struct radeon_device *rdev)
381     radeon_pm_init_profile(rdev);
382     /* set up the default clocks if the MC ucode is loaded */
383     if ((rdev->family >= CHIP_BARTS) &&
384     - (rdev->family <= CHIP_HAINAN) &&
385     + (rdev->family <= CHIP_CAYMAN) &&
386     rdev->mc_fw) {
387     if (rdev->pm.default_vddc)
388     radeon_atom_set_voltage(rdev, rdev->pm.default_vddc,
389     @@ -1099,7 +1099,7 @@ static int radeon_pm_init_dpm(struct radeon_device *rdev)
390     if (ret) {
391     rdev->pm.dpm_enabled = false;
392     if ((rdev->family >= CHIP_BARTS) &&
393     - (rdev->family <= CHIP_HAINAN) &&
394     + (rdev->family <= CHIP_CAYMAN) &&
395     rdev->mc_fw) {
396     if (rdev->pm.default_vddc)
397     radeon_atom_set_voltage(rdev, rdev->pm.default_vddc,
398     diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
399     index fb5ea62..09eb679 100644
400     --- a/drivers/gpu/drm/radeon/radeon_ring.c
401     +++ b/drivers/gpu/drm/radeon/radeon_ring.c
402     @@ -846,9 +846,11 @@ static int radeon_debugfs_ring_info(struct seq_file *m, void *data)
403     * packet that is the root issue
404     */
405     i = (ring->rptr + ring->ptr_mask + 1 - 32) & ring->ptr_mask;
406     - for (j = 0; j <= (count + 32); j++) {
407     - seq_printf(m, "r[%5d]=0x%08x\n", i, ring->ring[i]);
408     - i = (i + 1) & ring->ptr_mask;
409     + if (ring->ready) {
410     + for (j = 0; j <= (count + 32); j++) {
411     + seq_printf(m, "r[%5d]=0x%08x\n", i, ring->ring[i]);
412     + i = (i + 1) & ring->ptr_mask;
413     + }
414     }
415     return 0;
416     }
417     diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
418     index 62c2e32..98814d1 100644
419     --- a/drivers/hwmon/applesmc.c
420     +++ b/drivers/hwmon/applesmc.c
421     @@ -525,16 +525,25 @@ static int applesmc_init_smcreg_try(void)
422     {
423     struct applesmc_registers *s = &smcreg;
424     bool left_light_sensor, right_light_sensor;
425     + unsigned int count;
426     u8 tmp[1];
427     int ret;
428    
429     if (s->init_complete)
430     return 0;
431    
432     - ret = read_register_count(&s->key_count);
433     + ret = read_register_count(&count);
434     if (ret)
435     return ret;
436    
437     + if (s->cache && s->key_count != count) {
438     + pr_warn("key count changed from %d to %d\n",
439     + s->key_count, count);
440     + kfree(s->cache);
441     + s->cache = NULL;
442     + }
443     + s->key_count = count;
444     +
445     if (!s->cache)
446     s->cache = kcalloc(s->key_count, sizeof(*s->cache), GFP_KERNEL);
447     if (!s->cache)
448     diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
449     index b39f6f0..0f12382 100644
450     --- a/drivers/md/bcache/bcache.h
451     +++ b/drivers/md/bcache/bcache.h
452     @@ -498,7 +498,7 @@ struct cached_dev {
453     */
454     atomic_t has_dirty;
455    
456     - struct ratelimit writeback_rate;
457     + struct bch_ratelimit writeback_rate;
458     struct delayed_work writeback_rate_update;
459    
460     /*
461     @@ -507,10 +507,9 @@ struct cached_dev {
462     */
463     sector_t last_read;
464    
465     - /* Number of writeback bios in flight */
466     - atomic_t in_flight;
467     + /* Limit number of writeback bios in flight */
468     + struct semaphore in_flight;
469     struct closure_with_timer writeback;
470     - struct closure_waitlist writeback_wait;
471    
472     struct keybuf writeback_keys;
473    
474     diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
475     index 8010eed..22d1ae7 100644
476     --- a/drivers/md/bcache/bset.c
477     +++ b/drivers/md/bcache/bset.c
478     @@ -926,28 +926,45 @@ struct bkey *bch_next_recurse_key(struct btree *b, struct bkey *search)
479    
480     /* Mergesort */
481    
482     +static void sort_key_next(struct btree_iter *iter,
483     + struct btree_iter_set *i)
484     +{
485     + i->k = bkey_next(i->k);
486     +
487     + if (i->k == i->end)
488     + *i = iter->data[--iter->used];
489     +}
490     +
491     static void btree_sort_fixup(struct btree_iter *iter)
492     {
493     while (iter->used > 1) {
494     struct btree_iter_set *top = iter->data, *i = top + 1;
495     - struct bkey *k;
496    
497     if (iter->used > 2 &&
498     btree_iter_cmp(i[0], i[1]))
499     i++;
500    
501     - for (k = i->k;
502     - k != i->end && bkey_cmp(top->k, &START_KEY(k)) > 0;
503     - k = bkey_next(k))
504     - if (top->k > i->k)
505     - __bch_cut_front(top->k, k);
506     - else if (KEY_SIZE(k))
507     - bch_cut_back(&START_KEY(k), top->k);
508     -
509     - if (top->k < i->k || k == i->k)
510     + if (bkey_cmp(top->k, &START_KEY(i->k)) <= 0)
511     break;
512    
513     - heap_sift(iter, i - top, btree_iter_cmp);
514     + if (!KEY_SIZE(i->k)) {
515     + sort_key_next(iter, i);
516     + heap_sift(iter, i - top, btree_iter_cmp);
517     + continue;
518     + }
519     +
520     + if (top->k > i->k) {
521     + if (bkey_cmp(top->k, i->k) >= 0)
522     + sort_key_next(iter, i);
523     + else
524     + bch_cut_front(top->k, i->k);
525     +
526     + heap_sift(iter, i - top, btree_iter_cmp);
527     + } else {
528     + /* can't happen because of comparison func */
529     + BUG_ON(!bkey_cmp(&START_KEY(top->k), &START_KEY(i->k)));
530     + bch_cut_back(&START_KEY(i->k), top->k);
531     + }
532     }
533     }
534    
535     diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
536     index ee37288..391ba90 100644
537     --- a/drivers/md/bcache/btree.c
538     +++ b/drivers/md/bcache/btree.c
539     @@ -617,7 +617,7 @@ static int bch_mca_shrink(struct shrinker *shrink, struct shrink_control *sc)
540     return mca_can_free(c) * c->btree_pages;
541    
542     /* Return -1 if we can't do anything right now */
543     - if (sc->gfp_mask & __GFP_WAIT)
544     + if (sc->gfp_mask & __GFP_IO)
545     mutex_lock(&c->bucket_lock);
546     else if (!mutex_trylock(&c->bucket_lock))
547     return -1;
548     diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
549     index ba95ab8..8435f81 100644
550     --- a/drivers/md/bcache/journal.c
551     +++ b/drivers/md/bcache/journal.c
552     @@ -153,7 +153,8 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
553     bitmap_zero(bitmap, SB_JOURNAL_BUCKETS);
554     pr_debug("%u journal buckets", ca->sb.njournal_buckets);
555    
556     - /* Read journal buckets ordered by golden ratio hash to quickly
557     + /*
558     + * Read journal buckets ordered by golden ratio hash to quickly
559     * find a sequence of buckets with valid journal entries
560     */
561     for (i = 0; i < ca->sb.njournal_buckets; i++) {
562     @@ -166,18 +167,20 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
563     goto bsearch;
564     }
565    
566     - /* If that fails, check all the buckets we haven't checked
567     + /*
568     + * If that fails, check all the buckets we haven't checked
569     * already
570     */
571     pr_debug("falling back to linear search");
572    
573     - for (l = 0; l < ca->sb.njournal_buckets; l++) {
574     - if (test_bit(l, bitmap))
575     - continue;
576     -
577     + for (l = find_first_zero_bit(bitmap, ca->sb.njournal_buckets);
578     + l < ca->sb.njournal_buckets;
579     + l = find_next_zero_bit(bitmap, ca->sb.njournal_buckets, l + 1))
580     if (read_bucket(l))
581     goto bsearch;
582     - }
583     +
584     + if (list_empty(list))
585     + continue;
586     bsearch:
587     /* Binary search */
588     m = r = find_next_bit(bitmap, ca->sb.njournal_buckets, l + 1);
589     @@ -197,10 +200,12 @@ bsearch:
590     r = m;
591     }
592    
593     - /* Read buckets in reverse order until we stop finding more
594     + /*
595     + * Read buckets in reverse order until we stop finding more
596     * journal entries
597     */
598     - pr_debug("finishing up");
599     + pr_debug("finishing up: m %u njournal_buckets %u",
600     + m, ca->sb.njournal_buckets);
601     l = m;
602    
603     while (1) {
604     @@ -228,9 +233,10 @@ bsearch:
605     }
606     }
607    
608     - c->journal.seq = list_entry(list->prev,
609     - struct journal_replay,
610     - list)->j.seq;
611     + if (!list_empty(list))
612     + c->journal.seq = list_entry(list->prev,
613     + struct journal_replay,
614     + list)->j.seq;
615    
616     return 0;
617     #undef read_bucket
618     @@ -428,7 +434,7 @@ static void do_journal_discard(struct cache *ca)
619     return;
620     }
621    
622     - switch (atomic_read(&ja->discard_in_flight) == DISCARD_IN_FLIGHT) {
623     + switch (atomic_read(&ja->discard_in_flight)) {
624     case DISCARD_IN_FLIGHT:
625     return;
626    
627     @@ -689,6 +695,7 @@ void bch_journal_meta(struct cache_set *c, struct closure *cl)
628     if (cl)
629     BUG_ON(!closure_wait(&w->wait, cl));
630    
631     + closure_flush(&c->journal.io);
632     __journal_try_write(c, true);
633     }
634     }
635     diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
636     index 786a1a4..71eb233 100644
637     --- a/drivers/md/bcache/request.c
638     +++ b/drivers/md/bcache/request.c
639     @@ -997,14 +997,17 @@ static void request_write(struct cached_dev *dc, struct search *s)
640     } else {
641     bch_writeback_add(dc);
642    
643     - if (s->op.flush_journal) {
644     + if (bio->bi_rw & REQ_FLUSH) {
645     /* Also need to send a flush to the backing device */
646     - s->op.cache_bio = bio_clone_bioset(bio, GFP_NOIO,
647     - dc->disk.bio_split);
648     + struct bio *flush = bio_alloc_bioset(0, GFP_NOIO,
649     + dc->disk.bio_split);
650    
651     - bio->bi_size = 0;
652     - bio->bi_vcnt = 0;
653     - closure_bio_submit(bio, cl, s->d);
654     + flush->bi_rw = WRITE_FLUSH;
655     + flush->bi_bdev = bio->bi_bdev;
656     + flush->bi_end_io = request_endio;
657     + flush->bi_private = cl;
658     +
659     + closure_bio_submit(flush, cl, s->d);
660     } else {
661     s->op.cache_bio = bio;
662     }
663     diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
664     index 12a2c28..a87fbb5 100644
665     --- a/drivers/md/bcache/sysfs.c
666     +++ b/drivers/md/bcache/sysfs.c
667     @@ -223,8 +223,13 @@ STORE(__cached_dev)
668     }
669    
670     if (attr == &sysfs_label) {
671     - /* note: endlines are preserved */
672     - memcpy(dc->sb.label, buf, SB_LABEL_SIZE);
673     + if (size > SB_LABEL_SIZE)
674     + return -EINVAL;
675     + memcpy(dc->sb.label, buf, size);
676     + if (size < SB_LABEL_SIZE)
677     + dc->sb.label[size] = '\0';
678     + if (size && dc->sb.label[size - 1] == '\n')
679     + dc->sb.label[size - 1] = '\0';
680     bch_write_bdev_super(dc, NULL);
681     if (dc->disk.c) {
682     memcpy(dc->disk.c->uuids[dc->disk.id].label,
683     diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
684     index 98eb811..420dad5 100644
685     --- a/drivers/md/bcache/util.c
686     +++ b/drivers/md/bcache/util.c
687     @@ -190,7 +190,16 @@ void bch_time_stats_update(struct time_stats *stats, uint64_t start_time)
688     stats->last = now ?: 1;
689     }
690    
691     -unsigned bch_next_delay(struct ratelimit *d, uint64_t done)
692     +/**
693     + * bch_next_delay() - increment @d by the amount of work done, and return how
694     + * long to delay until the next time to do some work.
695     + *
696     + * @d - the struct bch_ratelimit to update
697     + * @done - the amount of work done, in arbitrary units
698     + *
699     + * Returns the amount of time to delay by, in jiffies
700     + */
701     +uint64_t bch_next_delay(struct bch_ratelimit *d, uint64_t done)
702     {
703     uint64_t now = local_clock();
704    
705     diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
706     index 1ae2a73..ea345c6 100644
707     --- a/drivers/md/bcache/util.h
708     +++ b/drivers/md/bcache/util.h
709     @@ -450,17 +450,23 @@ read_attribute(name ## _last_ ## frequency_units)
710     (ewma) >> factor; \
711     })
712    
713     -struct ratelimit {
714     +struct bch_ratelimit {
715     + /* Next time we want to do some work, in nanoseconds */
716     uint64_t next;
717     +
718     + /*
719     + * Rate at which we want to do work, in units per nanosecond
720     + * The units here correspond to the units passed to bch_next_delay()
721     + */
722     unsigned rate;
723     };
724    
725     -static inline void ratelimit_reset(struct ratelimit *d)
726     +static inline void bch_ratelimit_reset(struct bch_ratelimit *d)
727     {
728     d->next = local_clock();
729     }
730    
731     -unsigned bch_next_delay(struct ratelimit *d, uint64_t done);
732     +uint64_t bch_next_delay(struct bch_ratelimit *d, uint64_t done);
733    
734     #define __DIV_SAFE(n, d, zero) \
735     ({ \
736     diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
737     index 22cbff5..ba3ee48 100644
738     --- a/drivers/md/bcache/writeback.c
739     +++ b/drivers/md/bcache/writeback.c
740     @@ -94,11 +94,15 @@ static void update_writeback_rate(struct work_struct *work)
741    
742     static unsigned writeback_delay(struct cached_dev *dc, unsigned sectors)
743     {
744     + uint64_t ret;
745     +
746     if (atomic_read(&dc->disk.detaching) ||
747     !dc->writeback_percent)
748     return 0;
749    
750     - return bch_next_delay(&dc->writeback_rate, sectors * 10000000ULL);
751     + ret = bch_next_delay(&dc->writeback_rate, sectors * 10000000ULL);
752     +
753     + return min_t(uint64_t, ret, HZ);
754     }
755    
756     /* Background writeback */
757     @@ -208,7 +212,7 @@ normal_refill:
758    
759     up_write(&dc->writeback_lock);
760    
761     - ratelimit_reset(&dc->writeback_rate);
762     + bch_ratelimit_reset(&dc->writeback_rate);
763    
764     /* Punt to workqueue only so we don't recurse and blow the stack */
765     continue_at(cl, read_dirty, dirty_wq);
766     @@ -318,9 +322,7 @@ static void write_dirty_finish(struct closure *cl)
767     }
768    
769     bch_keybuf_del(&dc->writeback_keys, w);
770     - atomic_dec_bug(&dc->in_flight);
771     -
772     - closure_wake_up(&dc->writeback_wait);
773     + up(&dc->in_flight);
774    
775     closure_return_with_destructor(cl, dirty_io_destructor);
776     }
777     @@ -349,7 +351,7 @@ static void write_dirty(struct closure *cl)
778    
779     closure_bio_submit(&io->bio, cl, &io->dc->disk);
780    
781     - continue_at(cl, write_dirty_finish, dirty_wq);
782     + continue_at(cl, write_dirty_finish, system_wq);
783     }
784    
785     static void read_dirty_endio(struct bio *bio, int error)
786     @@ -369,7 +371,7 @@ static void read_dirty_submit(struct closure *cl)
787    
788     closure_bio_submit(&io->bio, cl, &io->dc->disk);
789    
790     - continue_at(cl, write_dirty, dirty_wq);
791     + continue_at(cl, write_dirty, system_wq);
792     }
793    
794     static void read_dirty(struct closure *cl)
795     @@ -394,12 +396,8 @@ static void read_dirty(struct closure *cl)
796    
797     if (delay > 0 &&
798     (KEY_START(&w->key) != dc->last_read ||
799     - jiffies_to_msecs(delay) > 50)) {
800     - w->private = NULL;
801     -
802     - closure_delay(&dc->writeback, delay);
803     - continue_at(cl, read_dirty, dirty_wq);
804     - }
805     + jiffies_to_msecs(delay) > 50))
806     + delay = schedule_timeout_uninterruptible(delay);
807    
808     dc->last_read = KEY_OFFSET(&w->key);
809    
810     @@ -424,15 +422,10 @@ static void read_dirty(struct closure *cl)
811    
812     trace_bcache_writeback(&w->key);
813    
814     - closure_call(&io->cl, read_dirty_submit, NULL, &dc->disk.cl);
815     + down(&dc->in_flight);
816     + closure_call(&io->cl, read_dirty_submit, NULL, cl);
817    
818     delay = writeback_delay(dc, KEY_SIZE(&w->key));
819     -
820     - atomic_inc(&dc->in_flight);
821     -
822     - if (!closure_wait_event(&dc->writeback_wait, cl,
823     - atomic_read(&dc->in_flight) < 64))
824     - continue_at(cl, read_dirty, dirty_wq);
825     }
826    
827     if (0) {
828     @@ -442,7 +435,11 @@ err:
829     bch_keybuf_del(&dc->writeback_keys, w);
830     }
831    
832     - refill_dirty(cl);
833     + /*
834     + * Wait for outstanding writeback IOs to finish (and keybuf slots to be
835     + * freed) before refilling again
836     + */
837     + continue_at(cl, refill_dirty, dirty_wq);
838     }
839    
840     /* Init */
841     @@ -484,6 +481,7 @@ void bch_sectors_dirty_init(struct cached_dev *dc)
842    
843     void bch_cached_dev_writeback_init(struct cached_dev *dc)
844     {
845     + sema_init(&dc->in_flight, 64);
846     closure_init_unlocked(&dc->writeback);
847     init_rwsem(&dc->writeback_lock);
848    
849     @@ -513,7 +511,7 @@ void bch_writeback_exit(void)
850    
851     int __init bch_writeback_init(void)
852     {
853     - dirty_wq = create_singlethread_workqueue("bcache_writeback");
854     + dirty_wq = create_workqueue("bcache_writeback");
855     if (!dirty_wq)
856     return -ENOMEM;
857    
858     diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
859     index 5adede1..c5b7b3d 100644
860     --- a/drivers/md/dm-mpath.c
861     +++ b/drivers/md/dm-mpath.c
862     @@ -1284,8 +1284,17 @@ static int do_end_io(struct multipath *m, struct request *clone,
863     if (!error && !clone->errors)
864     return 0; /* I/O complete */
865    
866     - if (error == -EOPNOTSUPP || error == -EREMOTEIO || error == -EILSEQ)
867     + if (error == -EOPNOTSUPP || error == -EREMOTEIO || error == -EILSEQ) {
868     + if ((clone->cmd_flags & REQ_WRITE_SAME) &&
869     + !clone->q->limits.max_write_same_sectors) {
870     + struct queue_limits *limits;
871     +
872     + /* device doesn't really support WRITE SAME, disable it */
873     + limits = dm_get_queue_limits(dm_table_get_md(m->ti->table));
874     + limits->max_write_same_sectors = 0;
875     + }
876     return error;
877     + }
878    
879     if (mpio->pgpath)
880     fail_path(mpio->pgpath);
881     diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
882     index 3ac4156..4caa8e6 100644
883     --- a/drivers/md/dm-snap-persistent.c
884     +++ b/drivers/md/dm-snap-persistent.c
885     @@ -256,7 +256,7 @@ static int chunk_io(struct pstore *ps, void *area, chunk_t chunk, int rw,
886     */
887     INIT_WORK_ONSTACK(&req.work, do_metadata);
888     queue_work(ps->metadata_wq, &req.work);
889     - flush_work(&req.work);
890     + flush_workqueue(ps->metadata_wq);
891    
892     return req.result;
893     }
894     diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
895     index c434e5a..aec57d7 100644
896     --- a/drivers/md/dm-snap.c
897     +++ b/drivers/md/dm-snap.c
898     @@ -725,17 +725,16 @@ static int calc_max_buckets(void)
899     */
900     static int init_hash_tables(struct dm_snapshot *s)
901     {
902     - sector_t hash_size, cow_dev_size, origin_dev_size, max_buckets;
903     + sector_t hash_size, cow_dev_size, max_buckets;
904    
905     /*
906     * Calculate based on the size of the original volume or
907     * the COW volume...
908     */
909     cow_dev_size = get_dev_size(s->cow->bdev);
910     - origin_dev_size = get_dev_size(s->origin->bdev);
911     max_buckets = calc_max_buckets();
912    
913     - hash_size = min(origin_dev_size, cow_dev_size) >> s->store->chunk_shift;
914     + hash_size = cow_dev_size >> s->store->chunk_shift;
915     hash_size = min(hash_size, max_buckets);
916    
917     if (hash_size < 64)
918     diff --git a/drivers/md/dm.c b/drivers/md/dm.c
919     index 9e39d2b..995e1fc 100644
920     --- a/drivers/md/dm.c
921     +++ b/drivers/md/dm.c
922     @@ -2250,6 +2250,17 @@ struct target_type *dm_get_immutable_target_type(struct mapped_device *md)
923     }
924    
925     /*
926     + * The queue_limits are only valid as long as you have a reference
927     + * count on 'md'.
928     + */
929     +struct queue_limits *dm_get_queue_limits(struct mapped_device *md)
930     +{
931     + BUG_ON(!atomic_read(&md->holders));
932     + return &md->queue->limits;
933     +}
934     +EXPORT_SYMBOL_GPL(dm_get_queue_limits);
935     +
936     +/*
937     * Fully initialize a request-based queue (->elevator, ->request_fn, etc).
938     */
939     static int dm_init_request_based_queue(struct mapped_device *md)
940     diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c
941     index 749452f..cf80bf5 100644
942     --- a/drivers/misc/mei/amthif.c
943     +++ b/drivers/misc/mei/amthif.c
944     @@ -57,6 +57,7 @@ void mei_amthif_reset_params(struct mei_device *dev)
945     dev->iamthif_ioctl = false;
946     dev->iamthif_state = MEI_IAMTHIF_IDLE;
947     dev->iamthif_timer = 0;
948     + dev->iamthif_stall_timer = 0;
949     }
950    
951     /**
952     diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
953     index 9ecd49a..99cc0b0 100644
954     --- a/drivers/misc/mei/bus.c
955     +++ b/drivers/misc/mei/bus.c
956     @@ -295,10 +295,13 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
957    
958     if (cl->reading_state != MEI_READ_COMPLETE &&
959     !waitqueue_active(&cl->rx_wait)) {
960     +
961     mutex_unlock(&dev->device_lock);
962    
963     if (wait_event_interruptible(cl->rx_wait,
964     - (MEI_READ_COMPLETE == cl->reading_state))) {
965     + cl->reading_state == MEI_READ_COMPLETE ||
966     + mei_cl_is_transitioning(cl))) {
967     +
968     if (signal_pending(current))
969     return -EINTR;
970     return -ERESTARTSYS;
971     diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
972     index 26b157d..b1717bb 100644
973     --- a/drivers/misc/mei/client.h
974     +++ b/drivers/misc/mei/client.h
975     @@ -76,6 +76,12 @@ static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
976     (cl1->host_client_id == cl2->host_client_id) &&
977     (cl1->me_client_id == cl2->me_client_id);
978     }
979     +static inline bool mei_cl_is_transitioning(struct mei_cl *cl)
980     +{
981     + return (MEI_FILE_INITIALIZING == cl->state ||
982     + MEI_FILE_DISCONNECTED == cl->state ||
983     + MEI_FILE_DISCONNECTING == cl->state);
984     +}
985    
986    
987     int mei_cl_flow_ctrl_creds(struct mei_cl *cl);
988     diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
989     index 6127ab6..0a044832 100644
990     --- a/drivers/misc/mei/hbm.c
991     +++ b/drivers/misc/mei/hbm.c
992     @@ -35,11 +35,15 @@ static void mei_hbm_me_cl_allocate(struct mei_device *dev)
993     struct mei_me_client *clients;
994     int b;
995    
996     + dev->me_clients_num = 0;
997     + dev->me_client_presentation_num = 0;
998     + dev->me_client_index = 0;
999     +
1000     /* count how many ME clients we have */
1001     for_each_set_bit(b, dev->me_clients_map, MEI_CLIENTS_MAX)
1002     dev->me_clients_num++;
1003    
1004     - if (dev->me_clients_num <= 0)
1005     + if (dev->me_clients_num == 0)
1006     return;
1007    
1008     kfree(dev->me_clients);
1009     @@ -221,7 +225,7 @@ static int mei_hbm_prop_req(struct mei_device *dev)
1010     struct hbm_props_request *prop_req;
1011     const size_t len = sizeof(struct hbm_props_request);
1012     unsigned long next_client_index;
1013     - u8 client_num;
1014     + unsigned long client_num;
1015    
1016    
1017     client_num = dev->me_client_presentation_num;
1018     @@ -677,8 +681,6 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
1019     if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
1020     dev->hbm_state == MEI_HBM_ENUM_CLIENTS) {
1021     dev->init_clients_timer = 0;
1022     - dev->me_client_presentation_num = 0;
1023     - dev->me_client_index = 0;
1024     mei_hbm_me_cl_allocate(dev);
1025     dev->hbm_state = MEI_HBM_CLIENT_PROPERTIES;
1026    
1027     diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c
1028     index e6f16f8..012b2e0 100644
1029     --- a/drivers/misc/mei/init.c
1030     +++ b/drivers/misc/mei/init.c
1031     @@ -169,6 +169,9 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
1032     memset(&dev->wr_ext_msg, 0, sizeof(dev->wr_ext_msg));
1033     }
1034    
1035     + /* we're already in reset, cancel the init timer */
1036     + dev->init_clients_timer = 0;
1037     +
1038     dev->me_clients_num = 0;
1039     dev->rd_msg_hdr = 0;
1040     dev->wd_pending = false;
1041     diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
1042     index 5e11b5b..e67de23 100644
1043     --- a/drivers/misc/mei/main.c
1044     +++ b/drivers/misc/mei/main.c
1045     @@ -249,19 +249,16 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
1046     mutex_unlock(&dev->device_lock);
1047    
1048     if (wait_event_interruptible(cl->rx_wait,
1049     - (MEI_READ_COMPLETE == cl->reading_state ||
1050     - MEI_FILE_INITIALIZING == cl->state ||
1051     - MEI_FILE_DISCONNECTED == cl->state ||
1052     - MEI_FILE_DISCONNECTING == cl->state))) {
1053     + MEI_READ_COMPLETE == cl->reading_state ||
1054     + mei_cl_is_transitioning(cl))) {
1055     +
1056     if (signal_pending(current))
1057     return -EINTR;
1058     return -ERESTARTSYS;
1059     }
1060    
1061     mutex_lock(&dev->device_lock);
1062     - if (MEI_FILE_INITIALIZING == cl->state ||
1063     - MEI_FILE_DISCONNECTED == cl->state ||
1064     - MEI_FILE_DISCONNECTING == cl->state) {
1065     + if (mei_cl_is_transitioning(cl)) {
1066     rets = -EBUSY;
1067     goto out;
1068     }
1069     diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
1070     index 7b918b2..456b322 100644
1071     --- a/drivers/misc/mei/mei_dev.h
1072     +++ b/drivers/misc/mei/mei_dev.h
1073     @@ -396,9 +396,9 @@ struct mei_device {
1074     struct mei_me_client *me_clients; /* Note: memory has to be allocated */
1075     DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
1076     DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
1077     - u8 me_clients_num;
1078     - u8 me_client_presentation_num;
1079     - u8 me_client_index;
1080     + unsigned long me_clients_num;
1081     + unsigned long me_client_presentation_num;
1082     + unsigned long me_client_index;
1083    
1084     struct mei_cl wd_cl;
1085     enum mei_wd_states wd_state;
1086     diff --git a/drivers/net/wireless/cw1200/cw1200_spi.c b/drivers/net/wireless/cw1200/cw1200_spi.c
1087     index f5e6b48..899cad3 100644
1088     --- a/drivers/net/wireless/cw1200/cw1200_spi.c
1089     +++ b/drivers/net/wireless/cw1200/cw1200_spi.c
1090     @@ -42,7 +42,6 @@ struct hwbus_priv {
1091     spinlock_t lock; /* Serialize all bus operations */
1092     wait_queue_head_t wq;
1093     int claimed;
1094     - int irq_disabled;
1095     };
1096    
1097     #define SDIO_TO_SPI_ADDR(addr) ((addr & 0x1f)>>2)
1098     @@ -238,8 +237,6 @@ static irqreturn_t cw1200_spi_irq_handler(int irq, void *dev_id)
1099     struct hwbus_priv *self = dev_id;
1100    
1101     if (self->core) {
1102     - disable_irq_nosync(self->func->irq);
1103     - self->irq_disabled = 1;
1104     cw1200_irq_handler(self->core);
1105     return IRQ_HANDLED;
1106     } else {
1107     @@ -253,9 +250,10 @@ static int cw1200_spi_irq_subscribe(struct hwbus_priv *self)
1108    
1109     pr_debug("SW IRQ subscribe\n");
1110    
1111     - ret = request_any_context_irq(self->func->irq, cw1200_spi_irq_handler,
1112     - IRQF_TRIGGER_HIGH,
1113     - "cw1200_wlan_irq", self);
1114     + ret = request_threaded_irq(self->func->irq, NULL,
1115     + cw1200_spi_irq_handler,
1116     + IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
1117     + "cw1200_wlan_irq", self);
1118     if (WARN_ON(ret < 0))
1119     goto exit;
1120    
1121     @@ -273,22 +271,13 @@ exit:
1122    
1123     static int cw1200_spi_irq_unsubscribe(struct hwbus_priv *self)
1124     {
1125     + int ret = 0;
1126     +
1127     pr_debug("SW IRQ unsubscribe\n");
1128     disable_irq_wake(self->func->irq);
1129     free_irq(self->func->irq, self);
1130    
1131     - return 0;
1132     -}
1133     -
1134     -static int cw1200_spi_irq_enable(struct hwbus_priv *self, int enable)
1135     -{
1136     - /* Disables are handled by the interrupt handler */
1137     - if (enable && self->irq_disabled) {
1138     - enable_irq(self->func->irq);
1139     - self->irq_disabled = 0;
1140     - }
1141     -
1142     - return 0;
1143     + return ret;
1144     }
1145    
1146     static int cw1200_spi_off(const struct cw1200_platform_data_spi *pdata)
1147     @@ -368,7 +357,6 @@ static struct hwbus_ops cw1200_spi_hwbus_ops = {
1148     .unlock = cw1200_spi_unlock,
1149     .align_size = cw1200_spi_align_size,
1150     .power_mgmt = cw1200_spi_pm,
1151     - .irq_enable = cw1200_spi_irq_enable,
1152     };
1153    
1154     /* Probe Function to be called by SPI stack when device is discovered */
1155     diff --git a/drivers/net/wireless/cw1200/fwio.c b/drivers/net/wireless/cw1200/fwio.c
1156     index 0b2061b..acdff0f 100644
1157     --- a/drivers/net/wireless/cw1200/fwio.c
1158     +++ b/drivers/net/wireless/cw1200/fwio.c
1159     @@ -485,7 +485,7 @@ int cw1200_load_firmware(struct cw1200_common *priv)
1160    
1161     /* Enable interrupt signalling */
1162     priv->hwbus_ops->lock(priv->hwbus_priv);
1163     - ret = __cw1200_irq_enable(priv, 2);
1164     + ret = __cw1200_irq_enable(priv, 1);
1165     priv->hwbus_ops->unlock(priv->hwbus_priv);
1166     if (ret < 0)
1167     goto unsubscribe;
1168     diff --git a/drivers/net/wireless/cw1200/hwbus.h b/drivers/net/wireless/cw1200/hwbus.h
1169     index 51dfb3a..8b2fc83 100644
1170     --- a/drivers/net/wireless/cw1200/hwbus.h
1171     +++ b/drivers/net/wireless/cw1200/hwbus.h
1172     @@ -28,7 +28,6 @@ struct hwbus_ops {
1173     void (*unlock)(struct hwbus_priv *self);
1174     size_t (*align_size)(struct hwbus_priv *self, size_t size);
1175     int (*power_mgmt)(struct hwbus_priv *self, bool suspend);
1176     - int (*irq_enable)(struct hwbus_priv *self, int enable);
1177     };
1178    
1179     #endif /* CW1200_HWBUS_H */
1180     diff --git a/drivers/net/wireless/cw1200/hwio.c b/drivers/net/wireless/cw1200/hwio.c
1181     index 41bd761..ff230b7 100644
1182     --- a/drivers/net/wireless/cw1200/hwio.c
1183     +++ b/drivers/net/wireless/cw1200/hwio.c
1184     @@ -273,21 +273,6 @@ int __cw1200_irq_enable(struct cw1200_common *priv, int enable)
1185     u16 val16;
1186     int ret;
1187    
1188     - /* We need to do this hack because the SPI layer can sleep on I/O
1189     - and the general path involves I/O to the device in interrupt
1190     - context.
1191     -
1192     - However, the initial enable call needs to go to the hardware.
1193     -
1194     - We don't worry about shutdown because we do a full reset which
1195     - clears the interrupt enabled bits.
1196     - */
1197     - if (priv->hwbus_ops->irq_enable) {
1198     - ret = priv->hwbus_ops->irq_enable(priv->hwbus_priv, enable);
1199     - if (ret || enable < 2)
1200     - return ret;
1201     - }
1202     -
1203     if (HIF_8601_SILICON == priv->hw_type) {
1204     ret = __cw1200_reg_read_32(priv, ST90TDS_CONFIG_REG_ID, &val32);
1205     if (ret < 0) {
1206     diff --git a/drivers/staging/vt6656/iwctl.c b/drivers/staging/vt6656/iwctl.c
1207     index d0cf7d8..8872e0f 100644
1208     --- a/drivers/staging/vt6656/iwctl.c
1209     +++ b/drivers/staging/vt6656/iwctl.c
1210     @@ -1634,6 +1634,9 @@ int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info,
1211     if (pMgmt == NULL)
1212     return -EFAULT;
1213    
1214     + if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
1215     + return -ENODEV;
1216     +
1217     buf = kzalloc(sizeof(struct viawget_wpa_param), GFP_KERNEL);
1218     if (buf == NULL)
1219     return -ENOMEM;
1220     diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
1221     index 3a3fdc5..06b966c 100644
1222     --- a/drivers/staging/vt6656/main_usb.c
1223     +++ b/drivers/staging/vt6656/main_usb.c
1224     @@ -1099,6 +1099,8 @@ static int device_close(struct net_device *dev)
1225     memset(pMgmt->abyCurrBSSID, 0, 6);
1226     pMgmt->eCurrState = WMAC_STATE_IDLE;
1227    
1228     + pDevice->flags &= ~DEVICE_FLAGS_OPENED;
1229     +
1230     device_free_tx_bufs(pDevice);
1231     device_free_rx_bufs(pDevice);
1232     device_free_int_bufs(pDevice);
1233     @@ -1110,7 +1112,6 @@ static int device_close(struct net_device *dev)
1234     usb_free_urb(pDevice->pInterruptURB);
1235    
1236     BSSvClearNodeDBTable(pDevice, 0);
1237     - pDevice->flags &=(~DEVICE_FLAGS_OPENED);
1238    
1239     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");
1240    
1241     diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
1242     index 572d481..20e4c94 100644
1243     --- a/drivers/tty/serial/pch_uart.c
1244     +++ b/drivers/tty/serial/pch_uart.c
1245     @@ -658,11 +658,12 @@ static int dma_push_rx(struct eg20t_port *priv, int size)
1246     dev_warn(port->dev, "Rx overrun: dropping %u bytes\n",
1247     size - room);
1248     if (!room)
1249     - return room;
1250     + goto out;
1251    
1252     tty_insert_flip_string(tport, sg_virt(&priv->sg_rx), size);
1253    
1254     port->icount.rx += room;
1255     +out:
1256     tty_kref_put(tty);
1257    
1258     return room;
1259     @@ -1071,6 +1072,8 @@ static void pch_uart_err_ir(struct eg20t_port *priv, unsigned int lsr)
1260     if (tty == NULL) {
1261     for (i = 0; error_msg[i] != NULL; i++)
1262     dev_err(&priv->pdev->dev, error_msg[i]);
1263     + } else {
1264     + tty_kref_put(tty);
1265     }
1266     }
1267    
1268     diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c
1269     index ee7c812..cf1a7a1 100644
1270     --- a/drivers/tty/serial/serial-tegra.c
1271     +++ b/drivers/tty/serial/serial-tegra.c
1272     @@ -726,7 +726,7 @@ static irqreturn_t tegra_uart_isr(int irq, void *data)
1273     static void tegra_uart_stop_rx(struct uart_port *u)
1274     {
1275     struct tegra_uart_port *tup = to_tegra_uport(u);
1276     - struct tty_struct *tty = tty_port_tty_get(&tup->uport.state->port);
1277     + struct tty_struct *tty;
1278     struct tty_port *port = &u->state->port;
1279     struct dma_tx_state state;
1280     unsigned long ier;
1281     @@ -738,6 +738,8 @@ static void tegra_uart_stop_rx(struct uart_port *u)
1282     if (!tup->rx_in_progress)
1283     return;
1284    
1285     + tty = tty_port_tty_get(&tup->uport.state->port);
1286     +
1287     tegra_uart_wait_sym_time(tup, 1); /* wait a character interval */
1288    
1289     ier = tup->ier_shadow;
1290     diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
1291     index 3500d41..088b4ca 100644
1292     --- a/drivers/tty/tty_ioctl.c
1293     +++ b/drivers/tty/tty_ioctl.c
1294     @@ -1201,6 +1201,9 @@ int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
1295     }
1296     return 0;
1297     case TCFLSH:
1298     + retval = tty_check_change(tty);
1299     + if (retval)
1300     + return retval;
1301     return __tty_perform_flush(tty, arg);
1302     default:
1303     /* Try the mode commands */
1304     diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
1305     index 0598650..342aa7f 100644
1306     --- a/drivers/usb/core/devio.c
1307     +++ b/drivers/usb/core/devio.c
1308     @@ -742,6 +742,22 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype,
1309     if ((index & ~USB_DIR_IN) == 0)
1310     return 0;
1311     ret = findintfep(ps->dev, index);
1312     + if (ret < 0) {
1313     + /*
1314     + * Some not fully compliant Win apps seem to get
1315     + * index wrong and have the endpoint number here
1316     + * rather than the endpoint address (with the
1317     + * correct direction). Win does let this through,
1318     + * so we'll not reject it here but leave it to
1319     + * the device to not break KVM. But we warn.
1320     + */
1321     + ret = findintfep(ps->dev, index ^ 0x80);
1322     + if (ret >= 0)
1323     + dev_info(&ps->dev->dev,
1324     + "%s: process %i (%s) requesting ep %02x but needs %02x\n",
1325     + __func__, task_pid_nr(current),
1326     + current->comm, index, index ^ 0x80);
1327     + }
1328     if (ret >= 0)
1329     ret = checkintf(ps, ret);
1330     break;
1331     diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
1332     index ed07ec0..db6f365 100644
1333     --- a/drivers/usb/dwc3/dwc3-pci.c
1334     +++ b/drivers/usb/dwc3/dwc3-pci.c
1335     @@ -48,6 +48,8 @@
1336     /* FIXME define these in <linux/pci_ids.h> */
1337     #define PCI_VENDOR_ID_SYNOPSYS 0x16c3
1338     #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
1339     +#define PCI_DEVICE_ID_INTEL_BYT 0x0f37
1340     +#define PCI_DEVICE_ID_INTEL_MRFLD 0x119e
1341    
1342     struct dwc3_pci {
1343     struct device *dev;
1344     @@ -207,6 +209,8 @@ static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = {
1345     PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
1346     PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
1347     },
1348     + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
1349     + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
1350     { } /* Terminating Entry */
1351     };
1352     MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
1353     diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
1354     index f394f29..b6e9d91 100644
1355     --- a/drivers/usb/gadget/f_fs.c
1356     +++ b/drivers/usb/gadget/f_fs.c
1357     @@ -1034,37 +1034,19 @@ struct ffs_sb_fill_data {
1358     struct ffs_file_perms perms;
1359     umode_t root_mode;
1360     const char *dev_name;
1361     - union {
1362     - /* set by ffs_fs_mount(), read by ffs_sb_fill() */
1363     - void *private_data;
1364     - /* set by ffs_sb_fill(), read by ffs_fs_mount */
1365     - struct ffs_data *ffs_data;
1366     - };
1367     + struct ffs_data *ffs_data;
1368     };
1369    
1370     static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
1371     {
1372     struct ffs_sb_fill_data *data = _data;
1373     struct inode *inode;
1374     - struct ffs_data *ffs;
1375     + struct ffs_data *ffs = data->ffs_data;
1376    
1377     ENTER();
1378    
1379     - /* Initialise data */
1380     - ffs = ffs_data_new();
1381     - if (unlikely(!ffs))
1382     - goto Enomem;
1383     -
1384     ffs->sb = sb;
1385     - ffs->dev_name = kstrdup(data->dev_name, GFP_KERNEL);
1386     - if (unlikely(!ffs->dev_name))
1387     - goto Enomem;
1388     - ffs->file_perms = data->perms;
1389     - ffs->private_data = data->private_data;
1390     -
1391     - /* used by the caller of this function */
1392     - data->ffs_data = ffs;
1393     -
1394     + data->ffs_data = NULL;
1395     sb->s_fs_info = ffs;
1396     sb->s_blocksize = PAGE_CACHE_SIZE;
1397     sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1398     @@ -1080,17 +1062,14 @@ static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
1399     &data->perms);
1400     sb->s_root = d_make_root(inode);
1401     if (unlikely(!sb->s_root))
1402     - goto Enomem;
1403     + return -ENOMEM;
1404    
1405     /* EP0 file */
1406     if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs,
1407     &ffs_ep0_operations, NULL)))
1408     - goto Enomem;
1409     + return -ENOMEM;
1410    
1411     return 0;
1412     -
1413     -Enomem:
1414     - return -ENOMEM;
1415     }
1416    
1417     static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
1418     @@ -1193,6 +1172,7 @@ ffs_fs_mount(struct file_system_type *t, int flags,
1419     struct dentry *rv;
1420     int ret;
1421     void *ffs_dev;
1422     + struct ffs_data *ffs;
1423    
1424     ENTER();
1425    
1426     @@ -1200,18 +1180,30 @@ ffs_fs_mount(struct file_system_type *t, int flags,
1427     if (unlikely(ret < 0))
1428     return ERR_PTR(ret);
1429    
1430     + ffs = ffs_data_new();
1431     + if (unlikely(!ffs))
1432     + return ERR_PTR(-ENOMEM);
1433     + ffs->file_perms = data.perms;
1434     +
1435     + ffs->dev_name = kstrdup(dev_name, GFP_KERNEL);
1436     + if (unlikely(!ffs->dev_name)) {
1437     + ffs_data_put(ffs);
1438     + return ERR_PTR(-ENOMEM);
1439     + }
1440     +
1441     ffs_dev = functionfs_acquire_dev_callback(dev_name);
1442     - if (IS_ERR(ffs_dev))
1443     - return ffs_dev;
1444     + if (IS_ERR(ffs_dev)) {
1445     + ffs_data_put(ffs);
1446     + return ERR_CAST(ffs_dev);
1447     + }
1448     + ffs->private_data = ffs_dev;
1449     + data.ffs_data = ffs;
1450    
1451     - data.dev_name = dev_name;
1452     - data.private_data = ffs_dev;
1453     rv = mount_nodev(t, flags, &data, ffs_sb_fill);
1454     -
1455     - /* data.ffs_data is set by ffs_sb_fill */
1456     - if (IS_ERR(rv))
1457     + if (IS_ERR(rv) && data.ffs_data) {
1458     functionfs_release_dev_callback(data.ffs_data);
1459     -
1460     + ffs_data_put(data.ffs_data);
1461     + }
1462     return rv;
1463     }
1464    
1465     diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
1466     index bd831ec..87c1a2e 100644
1467     --- a/drivers/usb/host/ehci-fsl.c
1468     +++ b/drivers/usb/host/ehci-fsl.c
1469     @@ -130,7 +130,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
1470     }
1471    
1472     /* Enable USB controller, 83xx or 8536 */
1473     - if (pdata->have_sysif_regs)
1474     + if (pdata->have_sysif_regs && pdata->controller_ver < FSL_USB_VER_1_6)
1475     setbits32(hcd->regs + FSL_SOC_USB_CTRL, 0x4);
1476    
1477     /* Don't need to set host mode here. It will be done by tdi_reset() */
1478     @@ -232,15 +232,9 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
1479     case FSL_USB2_PHY_ULPI:
1480     if (pdata->have_sysif_regs && pdata->controller_ver) {
1481     /* controller version 1.6 or above */
1482     + clrbits32(non_ehci + FSL_SOC_USB_CTRL, UTMI_PHY_EN);
1483     setbits32(non_ehci + FSL_SOC_USB_CTRL,
1484     - ULPI_PHY_CLK_SEL);
1485     - /*
1486     - * Due to controller issue of PHY_CLK_VALID in ULPI
1487     - * mode, we set USB_CTRL_USB_EN before checking
1488     - * PHY_CLK_VALID, otherwise PHY_CLK_VALID doesn't work.
1489     - */
1490     - clrsetbits_be32(non_ehci + FSL_SOC_USB_CTRL,
1491     - UTMI_PHY_EN, USB_CTRL_USB_EN);
1492     + ULPI_PHY_CLK_SEL | USB_CTRL_USB_EN);
1493     }
1494     portsc |= PORT_PTS_ULPI;
1495     break;
1496     diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
1497     index 595d210..8fe401c 100644
1498     --- a/drivers/usb/host/ehci-pci.c
1499     +++ b/drivers/usb/host/ehci-pci.c
1500     @@ -403,7 +403,7 @@ static struct pci_driver ehci_pci_driver = {
1501     .remove = usb_hcd_pci_remove,
1502     .shutdown = usb_hcd_pci_shutdown,
1503    
1504     -#ifdef CONFIG_PM_SLEEP
1505     +#ifdef CONFIG_PM
1506     .driver = {
1507     .pm = &usb_hcd_pci_pm_ops
1508     },
1509     diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
1510     index a9d3437..c182262 100644
1511     --- a/drivers/usb/host/ohci-hcd.c
1512     +++ b/drivers/usb/host/ohci-hcd.c
1513     @@ -216,31 +216,26 @@ static int ohci_urb_enqueue (
1514     frame &= ~(ed->interval - 1);
1515     frame |= ed->branch;
1516     urb->start_frame = frame;
1517     + ed->last_iso = frame + ed->interval * (size - 1);
1518     }
1519     } else if (ed->type == PIPE_ISOCHRONOUS) {
1520     u16 next = ohci_frame_no(ohci) + 1;
1521     u16 frame = ed->last_iso + ed->interval;
1522     + u16 length = ed->interval * (size - 1);
1523    
1524     /* Behind the scheduling threshold? */
1525     if (unlikely(tick_before(frame, next))) {
1526    
1527     - /* USB_ISO_ASAP: Round up to the first available slot */
1528     + /* URB_ISO_ASAP: Round up to the first available slot */
1529     if (urb->transfer_flags & URB_ISO_ASAP) {
1530     frame += (next - frame + ed->interval - 1) &
1531     -ed->interval;
1532    
1533     /*
1534     - * Not ASAP: Use the next slot in the stream. If
1535     - * the entire URB falls before the threshold, fail.
1536     + * Not ASAP: Use the next slot in the stream,
1537     + * no matter what.
1538     */
1539     } else {
1540     - if (tick_before(frame + ed->interval *
1541     - (urb->number_of_packets - 1), next)) {
1542     - retval = -EXDEV;
1543     - usb_hcd_unlink_urb_from_ep(hcd, urb);
1544     - goto fail;
1545     - }
1546     -
1547     /*
1548     * Some OHCI hardware doesn't handle late TDs
1549     * correctly. After retiring them it proceeds
1550     @@ -251,9 +246,16 @@ static int ohci_urb_enqueue (
1551     urb_priv->td_cnt = DIV_ROUND_UP(
1552     (u16) (next - frame),
1553     ed->interval);
1554     + if (urb_priv->td_cnt >= urb_priv->length) {
1555     + ++urb_priv->td_cnt; /* Mark it */
1556     + ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n",
1557     + urb, frame, length,
1558     + next);
1559     + }
1560     }
1561     }
1562     urb->start_frame = frame;
1563     + ed->last_iso = frame + length;
1564     }
1565    
1566     /* fill the TDs and link them to the ed; and
1567     diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
1568     index df4a670..e7f577e 100644
1569     --- a/drivers/usb/host/ohci-q.c
1570     +++ b/drivers/usb/host/ohci-q.c
1571     @@ -41,9 +41,13 @@ finish_urb(struct ohci_hcd *ohci, struct urb *urb, int status)
1572     __releases(ohci->lock)
1573     __acquires(ohci->lock)
1574     {
1575     - struct device *dev = ohci_to_hcd(ohci)->self.controller;
1576     + struct device *dev = ohci_to_hcd(ohci)->self.controller;
1577     + struct usb_host_endpoint *ep = urb->ep;
1578     + struct urb_priv *urb_priv;
1579     +
1580     // ASSERT (urb->hcpriv != 0);
1581    
1582     + restart:
1583     urb_free_priv (ohci, urb->hcpriv);
1584     urb->hcpriv = NULL;
1585     if (likely(status == -EINPROGRESS))
1586     @@ -80,6 +84,21 @@ __acquires(ohci->lock)
1587     ohci->hc_control &= ~(OHCI_CTRL_PLE|OHCI_CTRL_IE);
1588     ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
1589     }
1590     +
1591     + /*
1592     + * An isochronous URB that is sumitted too late won't have any TDs
1593     + * (marked by the fact that the td_cnt value is larger than the
1594     + * actual number of TDs). If the next URB on this endpoint is like
1595     + * that, give it back now.
1596     + */
1597     + if (!list_empty(&ep->urb_list)) {
1598     + urb = list_first_entry(&ep->urb_list, struct urb, urb_list);
1599     + urb_priv = urb->hcpriv;
1600     + if (urb_priv->td_cnt > urb_priv->length) {
1601     + status = 0;
1602     + goto restart;
1603     + }
1604     + }
1605     }
1606    
1607    
1608     @@ -546,7 +565,6 @@ td_fill (struct ohci_hcd *ohci, u32 info,
1609     td->hwCBP = cpu_to_hc32 (ohci, data & 0xFFFFF000);
1610     *ohci_hwPSWp(ohci, td, 0) = cpu_to_hc16 (ohci,
1611     (data & 0x0FFF) | 0xE000);
1612     - td->ed->last_iso = info & 0xffff;
1613     } else {
1614     td->hwCBP = cpu_to_hc32 (ohci, data);
1615     }
1616     @@ -996,7 +1014,7 @@ rescan_this:
1617     urb_priv->td_cnt++;
1618    
1619     /* if URB is done, clean up */
1620     - if (urb_priv->td_cnt == urb_priv->length) {
1621     + if (urb_priv->td_cnt >= urb_priv->length) {
1622     modified = completed = 1;
1623     finish_urb(ohci, urb, 0);
1624     }
1625     @@ -1086,7 +1104,7 @@ static void takeback_td(struct ohci_hcd *ohci, struct td *td)
1626     urb_priv->td_cnt++;
1627    
1628     /* If all this urb's TDs are done, call complete() */
1629     - if (urb_priv->td_cnt == urb_priv->length)
1630     + if (urb_priv->td_cnt >= urb_priv->length)
1631     finish_urb(ohci, urb, status);
1632    
1633     /* clean schedule: unlink EDs that are no longer busy */
1634     diff --git a/drivers/usb/host/uhci-pci.c b/drivers/usb/host/uhci-pci.c
1635     index c300bd2f7..0f228c4 100644
1636     --- a/drivers/usb/host/uhci-pci.c
1637     +++ b/drivers/usb/host/uhci-pci.c
1638     @@ -293,7 +293,7 @@ static struct pci_driver uhci_pci_driver = {
1639     .remove = usb_hcd_pci_remove,
1640     .shutdown = uhci_shutdown,
1641    
1642     -#ifdef CONFIG_PM_SLEEP
1643     +#ifdef CONFIG_PM
1644     .driver = {
1645     .pm = &usb_hcd_pci_pm_ops
1646     },
1647     diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
1648     index 041c6dd..da6f56d 100644
1649     --- a/drivers/usb/host/uhci-q.c
1650     +++ b/drivers/usb/host/uhci-q.c
1651     @@ -1303,7 +1303,7 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb,
1652     }
1653    
1654     /* Fell behind? */
1655     - if (uhci_frame_before_eq(frame, next)) {
1656     + if (!uhci_frame_before_eq(next, frame)) {
1657    
1658     /* USB_ISO_ASAP: Round up to the first available slot */
1659     if (urb->transfer_flags & URB_ISO_ASAP)
1660     @@ -1311,13 +1311,17 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb,
1661     -qh->period;
1662    
1663     /*
1664     - * Not ASAP: Use the next slot in the stream. If
1665     - * the entire URB falls before the threshold, fail.
1666     + * Not ASAP: Use the next slot in the stream,
1667     + * no matter what.
1668     */
1669     else if (!uhci_frame_before_eq(next,
1670     frame + (urb->number_of_packets - 1) *
1671     qh->period))
1672     - return -EXDEV;
1673     + dev_dbg(uhci_dev(uhci), "iso underrun %p (%u+%u < %u)\n",
1674     + urb, frame,
1675     + (urb->number_of_packets - 1) *
1676     + qh->period,
1677     + next);
1678     }
1679     }
1680    
1681     diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
1682     index 1d35459..ad5b99b 100644
1683     --- a/drivers/usb/host/xhci-hub.c
1684     +++ b/drivers/usb/host/xhci-hub.c
1685     @@ -286,7 +286,7 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
1686     if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue)
1687     xhci_queue_stop_endpoint(xhci, slot_id, i, suspend);
1688     }
1689     - cmd->command_trb = xhci->cmd_ring->enqueue;
1690     + cmd->command_trb = xhci_find_next_enqueue(xhci->cmd_ring);
1691     list_add_tail(&cmd->cmd_list, &virt_dev->cmd_list);
1692     xhci_queue_stop_endpoint(xhci, slot_id, 0, suspend);
1693     xhci_ring_cmd_db(xhci);
1694     diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
1695     index f00cb20..159e3c6 100644
1696     --- a/drivers/usb/host/xhci-pci.c
1697     +++ b/drivers/usb/host/xhci-pci.c
1698     @@ -345,7 +345,7 @@ static struct pci_driver xhci_pci_driver = {
1699     /* suspend and resume implemented later */
1700    
1701     .shutdown = usb_hcd_pci_shutdown,
1702     -#ifdef CONFIG_PM_SLEEP
1703     +#ifdef CONFIG_PM
1704     .driver = {
1705     .pm = &usb_hcd_pci_pm_ops
1706     },
1707     diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
1708     index 5b08cd8..289e481 100644
1709     --- a/drivers/usb/host/xhci-ring.c
1710     +++ b/drivers/usb/host/xhci-ring.c
1711     @@ -122,6 +122,16 @@ static int enqueue_is_link_trb(struct xhci_ring *ring)
1712     return TRB_TYPE_LINK_LE32(link->control);
1713     }
1714    
1715     +union xhci_trb *xhci_find_next_enqueue(struct xhci_ring *ring)
1716     +{
1717     + /* Enqueue pointer can be left pointing to the link TRB,
1718     + * we must handle that
1719     + */
1720     + if (TRB_TYPE_LINK_LE32(ring->enqueue->link.control))
1721     + return ring->enq_seg->next->trbs;
1722     + return ring->enqueue;
1723     +}
1724     +
1725     /* Updates trb to point to the next TRB in the ring, and updates seg if the next
1726     * TRB is in a new segment. This does not skip over link TRBs, and it does not
1727     * effect the ring dequeue or enqueue pointers.
1728     @@ -847,8 +857,12 @@ remove_finished_td:
1729     /* Otherwise ring the doorbell(s) to restart queued transfers */
1730     ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1731     }
1732     - ep->stopped_td = NULL;
1733     - ep->stopped_trb = NULL;
1734     +
1735     + /* Clear stopped_td and stopped_trb if endpoint is not halted */
1736     + if (!(ep->ep_state & EP_HALTED)) {
1737     + ep->stopped_td = NULL;
1738     + ep->stopped_trb = NULL;
1739     + }
1740    
1741     /*
1742     * Drop the lock and complete the URBs in the cancelled TD list.
1743     @@ -1390,6 +1404,12 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1744     inc_deq(xhci, xhci->cmd_ring);
1745     return;
1746     }
1747     + /* There is no command to handle if we get a stop event when the
1748     + * command ring is empty, event->cmd_trb points to the next
1749     + * unset command
1750     + */
1751     + if (xhci->cmd_ring->dequeue == xhci->cmd_ring->enqueue)
1752     + return;
1753     }
1754    
1755     switch (le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])
1756     diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
1757     index b3c4162..d1fc37f 100644
1758     --- a/drivers/usb/host/xhci.c
1759     +++ b/drivers/usb/host/xhci.c
1760     @@ -2635,15 +2635,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1761     if (command) {
1762     cmd_completion = command->completion;
1763     cmd_status = &command->status;
1764     - command->command_trb = xhci->cmd_ring->enqueue;
1765     -
1766     - /* Enqueue pointer can be left pointing to the link TRB,
1767     - * we must handle that
1768     - */
1769     - if (TRB_TYPE_LINK_LE32(command->command_trb->link.control))
1770     - command->command_trb =
1771     - xhci->cmd_ring->enq_seg->next->trbs;
1772     -
1773     + command->command_trb = xhci_find_next_enqueue(xhci->cmd_ring);
1774     list_add_tail(&command->cmd_list, &virt_dev->cmd_list);
1775     } else {
1776     cmd_completion = &virt_dev->cmd_completion;
1777     @@ -2651,7 +2643,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1778     }
1779     init_completion(cmd_completion);
1780    
1781     - cmd_trb = xhci->cmd_ring->dequeue;
1782     + cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring);
1783     if (!ctx_change)
1784     ret = xhci_queue_configure_endpoint(xhci, in_ctx->dma,
1785     udev->slot_id, must_succeed);
1786     @@ -3468,14 +3460,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
1787    
1788     /* Attempt to submit the Reset Device command to the command ring */
1789     spin_lock_irqsave(&xhci->lock, flags);
1790     - reset_device_cmd->command_trb = xhci->cmd_ring->enqueue;
1791     -
1792     - /* Enqueue pointer can be left pointing to the link TRB,
1793     - * we must handle that
1794     - */
1795     - if (TRB_TYPE_LINK_LE32(reset_device_cmd->command_trb->link.control))
1796     - reset_device_cmd->command_trb =
1797     - xhci->cmd_ring->enq_seg->next->trbs;
1798     + reset_device_cmd->command_trb = xhci_find_next_enqueue(xhci->cmd_ring);
1799    
1800     list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list);
1801     ret = xhci_queue_reset_device(xhci, slot_id);
1802     @@ -3679,7 +3664,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
1803     union xhci_trb *cmd_trb;
1804    
1805     spin_lock_irqsave(&xhci->lock, flags);
1806     - cmd_trb = xhci->cmd_ring->dequeue;
1807     + cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring);
1808     ret = xhci_queue_slot_control(xhci, TRB_ENABLE_SLOT, 0);
1809     if (ret) {
1810     spin_unlock_irqrestore(&xhci->lock, flags);
1811     @@ -3811,7 +3796,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
1812     xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2);
1813    
1814     spin_lock_irqsave(&xhci->lock, flags);
1815     - cmd_trb = xhci->cmd_ring->dequeue;
1816     + cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring);
1817     ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma,
1818     udev->slot_id);
1819     if (ret) {
1820     diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
1821     index 6ab1e60..e63645d 100644
1822     --- a/drivers/usb/host/xhci.h
1823     +++ b/drivers/usb/host/xhci.h
1824     @@ -1851,6 +1851,7 @@ int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command,
1825     union xhci_trb *cmd_trb);
1826     void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
1827     unsigned int ep_index, unsigned int stream_id);
1828     +union xhci_trb *xhci_find_next_enqueue(struct xhci_ring *ring);
1829    
1830     /* xHCI roothub code */
1831     void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1832     diff --git a/fs/bio.c b/fs/bio.c
1833     index c5eae72..5e7507d 100644
1834     --- a/fs/bio.c
1835     +++ b/fs/bio.c
1836     @@ -917,8 +917,8 @@ void bio_copy_data(struct bio *dst, struct bio *src)
1837     src_p = kmap_atomic(src_bv->bv_page);
1838     dst_p = kmap_atomic(dst_bv->bv_page);
1839    
1840     - memcpy(dst_p + dst_bv->bv_offset,
1841     - src_p + src_bv->bv_offset,
1842     + memcpy(dst_p + dst_offset,
1843     + src_p + src_offset,
1844     bytes);
1845    
1846     kunmap_atomic(dst_p);
1847     diff --git a/fs/sysv/super.c b/fs/sysv/super.c
1848     index d0c6a00..eda1095 100644
1849     --- a/fs/sysv/super.c
1850     +++ b/fs/sysv/super.c
1851     @@ -487,6 +487,7 @@ static int v7_fill_super(struct super_block *sb, void *data, int silent)
1852     sbi->s_sb = sb;
1853     sbi->s_block_base = 0;
1854     sbi->s_type = FSTYPE_V7;
1855     + mutex_init(&sbi->s_lock);
1856     sb->s_fs_info = sbi;
1857    
1858     sb_set_blocksize(sb, 512);
1859     diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
1860     index e151d4c..9109e81 100644
1861     --- a/include/linux/device-mapper.h
1862     +++ b/include/linux/device-mapper.h
1863     @@ -405,13 +405,14 @@ int dm_noflush_suspending(struct dm_target *ti);
1864     union map_info *dm_get_mapinfo(struct bio *bio);
1865     union map_info *dm_get_rq_mapinfo(struct request *rq);
1866    
1867     +struct queue_limits *dm_get_queue_limits(struct mapped_device *md);
1868     +
1869     /*
1870     * Geometry functions.
1871     */
1872     int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
1873     int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
1874    
1875     -
1876     /*-----------------------------------------------------------------
1877     * Functions for manipulating device-mapper tables.
1878     *---------------------------------------------------------------*/
1879     diff --git a/kernel/Makefile b/kernel/Makefile
1880     index 35ef118..ed2c9a9 100644
1881     --- a/kernel/Makefile
1882     +++ b/kernel/Makefile
1883     @@ -79,7 +79,7 @@ obj-$(CONFIG_KPROBES) += kprobes.o
1884     obj-$(CONFIG_KGDB) += debug/
1885     obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
1886     obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o
1887     -obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
1888     +obj-y += irq/
1889     obj-$(CONFIG_SECCOMP) += seccomp.o
1890     obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
1891     obj-$(CONFIG_TREE_RCU) += rcutree.o
1892     diff --git a/kernel/irq/Makefile b/kernel/irq/Makefile
1893     index fff1738..639b2e1 100644
1894     --- a/kernel/irq/Makefile
1895     +++ b/kernel/irq/Makefile
1896     @@ -1,8 +1,10 @@
1897     -
1898     -obj-y := irqdesc.o handle.o manage.o spurious.o resend.o chip.o dummychip.o devres.o
1899     +obj-y += devres.o
1900     +ifdef CONFIG_GENERIC_HARDIRQS
1901     +obj-y += irqdesc.o handle.o manage.o spurious.o resend.o chip.o dummychip.o
1902     obj-$(CONFIG_GENERIC_IRQ_CHIP) += generic-chip.o
1903     obj-$(CONFIG_GENERIC_IRQ_PROBE) += autoprobe.o
1904     obj-$(CONFIG_IRQ_DOMAIN) += irqdomain.o
1905     obj-$(CONFIG_PROC_FS) += proc.o
1906     obj-$(CONFIG_GENERIC_PENDING_IRQ) += migration.o
1907     obj-$(CONFIG_PM_SLEEP) += pm.o
1908     +endif
1909     diff --git a/kernel/reboot.c b/kernel/reboot.c
1910     index 269ed93..f813b34 100644
1911     --- a/kernel/reboot.c
1912     +++ b/kernel/reboot.c
1913     @@ -32,7 +32,14 @@ EXPORT_SYMBOL(cad_pid);
1914     #endif
1915     enum reboot_mode reboot_mode DEFAULT_REBOOT_MODE;
1916    
1917     -int reboot_default;
1918     +/*
1919     + * This variable is used privately to keep track of whether or not
1920     + * reboot_type is still set to its default value (i.e., reboot= hasn't
1921     + * been set on the command line). This is needed so that we can
1922     + * suppress DMI scanning for reboot quirks. Without it, it's
1923     + * impossible to override a faulty reboot quirk without recompiling.
1924     + */
1925     +int reboot_default = 1;
1926     int reboot_cpu;
1927     enum reboot_type reboot_type = BOOT_ACPI;
1928     int reboot_force;
1929     diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
1930     index 9896954..5863ba6 100644
1931     --- a/sound/core/compress_offload.c
1932     +++ b/sound/core/compress_offload.c
1933     @@ -837,7 +837,8 @@ static int snd_compress_dev_disconnect(struct snd_device *device)
1934     struct snd_compr *compr;
1935    
1936     compr = device->device_data;
1937     - snd_unregister_device(compr->direction, compr->card, compr->device);
1938     + snd_unregister_device(SNDRV_DEVICE_TYPE_COMPRESS, compr->card,
1939     + compr->device);
1940     return 0;
1941     }
1942    
1943     diff --git a/tools/lib/lk/debugfs.c b/tools/lib/lk/debugfs.c
1944     index 099e7cd..7c43479 100644
1945     --- a/tools/lib/lk/debugfs.c
1946     +++ b/tools/lib/lk/debugfs.c
1947     @@ -5,7 +5,6 @@
1948     #include <stdbool.h>
1949     #include <sys/vfs.h>
1950     #include <sys/mount.h>
1951     -#include <linux/magic.h>
1952     #include <linux/kernel.h>
1953    
1954     #include "debugfs.h"