Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:3.4 commit in: /
Date: Fri, 27 Jun 2014 17:24:46
Message-Id: 1403889731.ce9777db91df0719bbfa9bd38d863096d2664397.mpagano@gentoo
1 commit: ce9777db91df0719bbfa9bd38d863096d2664397
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Fri Jun 27 17:22:11 2014 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Fri Jun 27 17:22:11 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/linux-patches.git;a=commit;h=ce9777db
7
8 Linux patches 3.4.94 and 3.4.95
9
10 ---
11 0000_README | 8 +
12 1093_linux-3.4.94.patch | 293 +++++++
13 1094_linux-3.4.95.patch | 2054 +++++++++++++++++++++++++++++++++++++++++++++++
14 3 files changed, 2355 insertions(+)
15
16 diff --git a/0000_README b/0000_README
17 index 7148101..1db991a 100644
18 --- a/0000_README
19 +++ b/0000_README
20 @@ -411,6 +411,14 @@ Patch: 1092_linux-3.4.93.patch
21 From: http://www.kernel.org
22 Desc: Linux 3.4.93
23
24 +Patch: 1093_linux-3.4.94.patch
25 +From: http://www.kernel.org
26 +Desc: Linux 3.4.94
27 +
28 +Patch: 1094_linux-3.4.95.patch
29 +From: http://www.kernel.org
30 +Desc: Linux 3.4.95
31 +
32 Patch: 1500_XATTR_USER_PREFIX.patch
33 From: https://bugs.gentoo.org/show_bug.cgi?id=470644
34 Desc: Support for namespace user.pax.* on tmpfs.
35
36 diff --git a/1093_linux-3.4.94.patch b/1093_linux-3.4.94.patch
37 new file mode 100644
38 index 0000000..059857d
39 --- /dev/null
40 +++ b/1093_linux-3.4.94.patch
41 @@ -0,0 +1,293 @@
42 +diff --git a/Makefile b/Makefile
43 +index 20f420096dfa..0864af4a683b 100644
44 +--- a/Makefile
45 ++++ b/Makefile
46 +@@ -1,6 +1,6 @@
47 + VERSION = 3
48 + PATCHLEVEL = 4
49 +-SUBLEVEL = 93
50 ++SUBLEVEL = 94
51 + EXTRAVERSION =
52 + NAME = Saber-toothed Squirrel
53 +
54 +diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
55 +index 6524c6e21896..694aeedcbf88 100644
56 +--- a/arch/powerpc/Makefile
57 ++++ b/arch/powerpc/Makefile
58 +@@ -67,9 +67,11 @@ LDFLAGS_vmlinux-y := -Bstatic
59 + LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie
60 + LDFLAGS_vmlinux := $(LDFLAGS_vmlinux-y)
61 +
62 ++asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
63 ++
64 + CFLAGS-$(CONFIG_PPC64) := -mminimal-toc -mtraceback=no -mcall-aixdesc
65 + CFLAGS-$(CONFIG_PPC32) := -ffixed-r2 -mmultiple
66 +-KBUILD_CPPFLAGS += -Iarch/$(ARCH)
67 ++KBUILD_CPPFLAGS += -Iarch/$(ARCH) $(asinstr)
68 + KBUILD_AFLAGS += -Iarch/$(ARCH)
69 + KBUILD_CFLAGS += -msoft-float -pipe -Iarch/$(ARCH) $(CFLAGS-y)
70 + CPP = $(CC) -E $(KBUILD_CFLAGS)
71 +diff --git a/arch/powerpc/include/asm/ppc_asm.h b/arch/powerpc/include/asm/ppc_asm.h
72 +index 50f73aa2ba21..6f5a837431e9 100644
73 +--- a/arch/powerpc/include/asm/ppc_asm.h
74 ++++ b/arch/powerpc/include/asm/ppc_asm.h
75 +@@ -294,11 +294,16 @@ n:
76 + * ld rY,ADDROFF(name)(rX)
77 + */
78 + #ifdef __powerpc64__
79 ++#ifdef HAVE_AS_ATHIGH
80 ++#define __AS_ATHIGH high
81 ++#else
82 ++#define __AS_ATHIGH h
83 ++#endif
84 + #define LOAD_REG_IMMEDIATE(reg,expr) \
85 + lis (reg),(expr)@highest; \
86 + ori (reg),(reg),(expr)@higher; \
87 + rldicr (reg),(reg),32,31; \
88 +- oris (reg),(reg),(expr)@h; \
89 ++ oris (reg),(reg),(expr)@__AS_ATHIGH; \
90 + ori (reg),(reg),(expr)@l;
91 +
92 + #define LOAD_REG_ADDR(reg,name) \
93 +diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
94 +index ccd7b6711196..0e87baf8fcc2 100644
95 +--- a/drivers/ata/ahci.c
96 ++++ b/drivers/ata/ahci.c
97 +@@ -441,6 +441,8 @@ static const struct pci_device_id ahci_pci_tbl[] = {
98 + .driver_data = board_ahci_yes_fbs },
99 + { PCI_DEVICE(0x1b4b, 0x9230),
100 + .driver_data = board_ahci_yes_fbs },
101 ++ { PCI_DEVICE(PCI_VENDOR_ID_TTI, 0x0642),
102 ++ .driver_data = board_ahci_yes_fbs },
103 +
104 + /* Promise */
105 + { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci }, /* PDC42819 */
106 +diff --git a/drivers/net/ethernet/mellanox/mlx4/en_cq.c b/drivers/net/ethernet/mellanox/mlx4/en_cq.c
107 +index 00b81272e314..174b622dcaef 100644
108 +--- a/drivers/net/ethernet/mellanox/mlx4/en_cq.c
109 ++++ b/drivers/net/ethernet/mellanox/mlx4/en_cq.c
110 +@@ -55,7 +55,6 @@ int mlx4_en_create_cq(struct mlx4_en_priv *priv,
111 +
112 + cq->ring = ring;
113 + cq->is_tx = mode;
114 +- spin_lock_init(&cq->lock);
115 +
116 + err = mlx4_alloc_hwq_res(mdev->dev, &cq->wqres,
117 + cq->buf_size, 2 * PAGE_SIZE);
118 +diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
119 +index 31b455a49273..467a51171d47 100644
120 +--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
121 ++++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
122 +@@ -370,15 +370,11 @@ static void mlx4_en_netpoll(struct net_device *dev)
123 + {
124 + struct mlx4_en_priv *priv = netdev_priv(dev);
125 + struct mlx4_en_cq *cq;
126 +- unsigned long flags;
127 + int i;
128 +
129 + for (i = 0; i < priv->rx_ring_num; i++) {
130 + cq = &priv->rx_cq[i];
131 +- spin_lock_irqsave(&cq->lock, flags);
132 +- napi_synchronize(&cq->napi);
133 +- mlx4_en_process_rx_cq(dev, cq, 0);
134 +- spin_unlock_irqrestore(&cq->lock, flags);
135 ++ napi_schedule(&cq->napi);
136 + }
137 + }
138 + #endif
139 +diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
140 +index d69fee41f24a..8df3c4be3ff1 100644
141 +--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
142 ++++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
143 +@@ -301,7 +301,6 @@ struct mlx4_en_cq {
144 + struct mlx4_cq mcq;
145 + struct mlx4_hwq_resources wqres;
146 + int ring;
147 +- spinlock_t lock;
148 + struct net_device *dev;
149 + struct napi_struct napi;
150 + /* Per-core Tx cq processing support */
151 +diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
152 +index e5f416f8042d..1a7955a39070 100644
153 +--- a/drivers/scsi/megaraid/megaraid_sas.h
154 ++++ b/drivers/scsi/megaraid/megaraid_sas.h
155 +@@ -1294,7 +1294,6 @@ struct megasas_instance {
156 + u32 *reply_queue;
157 + dma_addr_t reply_queue_h;
158 +
159 +- unsigned long base_addr;
160 + struct megasas_register_set __iomem *reg_set;
161 +
162 + struct megasas_pd_list pd_list[MEGASAS_MAX_PD];
163 +diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
164 +index 79261628d067..618870033dd0 100644
165 +--- a/drivers/scsi/megaraid/megaraid_sas_base.c
166 ++++ b/drivers/scsi/megaraid/megaraid_sas_base.c
167 +@@ -3445,6 +3445,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
168 + u32 max_sectors_1;
169 + u32 max_sectors_2;
170 + u32 tmp_sectors, msix_enable;
171 ++ resource_size_t base_addr;
172 + struct megasas_register_set __iomem *reg_set;
173 + struct megasas_ctrl_info *ctrl_info;
174 + unsigned long bar_list;
175 +@@ -3453,14 +3454,14 @@ static int megasas_init_fw(struct megasas_instance *instance)
176 + /* Find first memory bar */
177 + bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM);
178 + instance->bar = find_first_bit(&bar_list, sizeof(unsigned long));
179 +- instance->base_addr = pci_resource_start(instance->pdev, instance->bar);
180 + if (pci_request_selected_regions(instance->pdev, instance->bar,
181 + "megasas: LSI")) {
182 + printk(KERN_DEBUG "megasas: IO memory region busy!\n");
183 + return -EBUSY;
184 + }
185 +
186 +- instance->reg_set = ioremap_nocache(instance->base_addr, 8192);
187 ++ base_addr = pci_resource_start(instance->pdev, instance->bar);
188 ++ instance->reg_set = ioremap_nocache(base_addr, 8192);
189 +
190 + if (!instance->reg_set) {
191 + printk(KERN_DEBUG "megasas: Failed to map IO mem\n");
192 +diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c
193 +index 826653fff70e..aafcf0330014 100644
194 +--- a/drivers/staging/zram/zram_sysfs.c
195 ++++ b/drivers/staging/zram/zram_sysfs.c
196 +@@ -99,18 +99,23 @@ static ssize_t reset_store(struct device *dev,
197 + return -ENOMEM;
198 +
199 + /* Do not reset an active device! */
200 +- if (bdev->bd_holders)
201 +- return -EBUSY;
202 ++ if (bdev->bd_holders) {
203 ++ ret = -EBUSY;
204 ++ goto out;
205 ++ }
206 +
207 + ret = kstrtou16(buf, 10, &do_reset);
208 + if (ret)
209 +- return ret;
210 ++ goto out;
211 +
212 +- if (!do_reset)
213 +- return -EINVAL;
214 ++ if (!do_reset) {
215 ++ ret = -EINVAL;
216 ++ goto out;
217 ++ }
218 +
219 + /* Make sure all pending I/O is finished */
220 + fsync_bdev(bdev);
221 ++ bdput(bdev);
222 +
223 + down_write(&zram->init_lock);
224 + if (zram->init_done)
225 +@@ -118,6 +123,10 @@ static ssize_t reset_store(struct device *dev,
226 + up_write(&zram->init_lock);
227 +
228 + return len;
229 ++
230 ++out:
231 ++ bdput(bdev);
232 ++ return ret;
233 + }
234 +
235 + static ssize_t num_reads_show(struct device *dev,
236 +@@ -188,10 +197,12 @@ static ssize_t mem_used_total_show(struct device *dev,
237 + u64 val = 0;
238 + struct zram *zram = dev_to_zram(dev);
239 +
240 ++ down_read(&zram->init_lock);
241 + if (zram->init_done) {
242 + val = zs_get_total_size_bytes(zram->mem_pool) +
243 + ((u64)(zram->stats.pages_expand) << PAGE_SHIFT);
244 + }
245 ++ up_read(&zram->init_lock);
246 +
247 + return sprintf(buf, "%llu\n", val);
248 + }
249 +diff --git a/kernel/auditsc.c b/kernel/auditsc.c
250 +index af1de0f34eae..549071209258 100644
251 +--- a/kernel/auditsc.c
252 ++++ b/kernel/auditsc.c
253 +@@ -868,6 +868,22 @@ static enum audit_state audit_filter_task(struct task_struct *tsk, char **key)
254 + return AUDIT_BUILD_CONTEXT;
255 + }
256 +
257 ++static int audit_in_mask(const struct audit_krule *rule, unsigned long val)
258 ++{
259 ++ int word, bit;
260 ++
261 ++ if (val > 0xffffffff)
262 ++ return false;
263 ++
264 ++ word = AUDIT_WORD(val);
265 ++ if (word >= AUDIT_BITMASK_SIZE)
266 ++ return false;
267 ++
268 ++ bit = AUDIT_BIT(val);
269 ++
270 ++ return rule->mask[word] & bit;
271 ++}
272 ++
273 + /* At syscall entry and exit time, this filter is called if the
274 + * audit_state is not low enough that auditing cannot take place, but is
275 + * also not high enough that we already know we have to write an audit
276 +@@ -885,11 +901,8 @@ static enum audit_state audit_filter_syscall(struct task_struct *tsk,
277 +
278 + rcu_read_lock();
279 + if (!list_empty(list)) {
280 +- int word = AUDIT_WORD(ctx->major);
281 +- int bit = AUDIT_BIT(ctx->major);
282 +-
283 + list_for_each_entry_rcu(e, list, list) {
284 +- if ((e->rule.mask[word] & bit) == bit &&
285 ++ if (audit_in_mask(&e->rule, ctx->major) &&
286 + audit_filter_rules(tsk, &e->rule, ctx, NULL,
287 + &state, false)) {
288 + rcu_read_unlock();
289 +@@ -909,20 +922,16 @@ static enum audit_state audit_filter_syscall(struct task_struct *tsk,
290 + static int audit_filter_inode_name(struct task_struct *tsk,
291 + struct audit_names *n,
292 + struct audit_context *ctx) {
293 +- int word, bit;
294 + int h = audit_hash_ino((u32)n->ino);
295 + struct list_head *list = &audit_inode_hash[h];
296 + struct audit_entry *e;
297 + enum audit_state state;
298 +
299 +- word = AUDIT_WORD(ctx->major);
300 +- bit = AUDIT_BIT(ctx->major);
301 +-
302 + if (list_empty(list))
303 + return 0;
304 +
305 + list_for_each_entry_rcu(e, list, list) {
306 +- if ((e->rule.mask[word] & bit) == bit &&
307 ++ if (audit_in_mask(&e->rule, ctx->major) &&
308 + audit_filter_rules(tsk, &e->rule, ctx, n, &state, false)) {
309 + ctx->current_state = state;
310 + return 1;
311 +diff --git a/net/ipv4/netfilter/nf_defrag_ipv4.c b/net/ipv4/netfilter/nf_defrag_ipv4.c
312 +index 9bb1b8a37a22..010288fdcc90 100644
313 +--- a/net/ipv4/netfilter/nf_defrag_ipv4.c
314 ++++ b/net/ipv4/netfilter/nf_defrag_ipv4.c
315 +@@ -22,7 +22,6 @@
316 + #endif
317 + #include <net/netfilter/nf_conntrack_zones.h>
318 +
319 +-/* Returns new sk_buff, or NULL */
320 + static int nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user)
321 + {
322 + int err;
323 +@@ -33,8 +32,10 @@ static int nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user)
324 + err = ip_defrag(skb, user);
325 + local_bh_enable();
326 +
327 +- if (!err)
328 ++ if (!err) {
329 + ip_send_check(ip_hdr(skb));
330 ++ skb->local_df = 1;
331 ++ }
332 +
333 + return err;
334 + }
335
336 diff --git a/1094_linux-3.4.95.patch b/1094_linux-3.4.95.patch
337 new file mode 100644
338 index 0000000..38f55d2
339 --- /dev/null
340 +++ b/1094_linux-3.4.95.patch
341 @@ -0,0 +1,2054 @@
342 +diff --git a/Makefile b/Makefile
343 +index 0864af4a683b..fda1dab589be 100644
344 +--- a/Makefile
345 ++++ b/Makefile
346 +@@ -1,6 +1,6 @@
347 + VERSION = 3
348 + PATCHLEVEL = 4
349 +-SUBLEVEL = 94
350 ++SUBLEVEL = 95
351 + EXTRAVERSION =
352 + NAME = Saber-toothed Squirrel
353 +
354 +diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
355 +index 1995cb05acf2..6e49bb47f8b2 100644
356 +--- a/drivers/net/ethernet/mellanox/mlx4/main.c
357 ++++ b/drivers/net/ethernet/mellanox/mlx4/main.c
358 +@@ -92,8 +92,6 @@ MODULE_PARM_DESC(log_num_mgm_entry_size, "log mgm size, that defines the num"
359 + " 10 gives 248.range: 9<="
360 + " log_num_mgm_entry_size <= 12");
361 +
362 +-#define MLX4_VF (1 << 0)
363 +-
364 + #define HCA_GLOBAL_CAP_MASK 0
365 + #define PF_CONTEXT_BEHAVIOUR_MASK 0
366 +
367 +@@ -1731,7 +1729,7 @@ static void mlx4_free_ownership(struct mlx4_dev *dev)
368 + iounmap(owner);
369 + }
370 +
371 +-static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
372 ++static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data)
373 + {
374 + struct mlx4_priv *priv;
375 + struct mlx4_dev *dev;
376 +@@ -1754,12 +1752,11 @@ static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
377 + /*
378 + * Check for BARs.
379 + */
380 +- if (((id == NULL) || !(id->driver_data & MLX4_VF)) &&
381 ++ if (!(pci_dev_data & MLX4_PCI_DEV_IS_VF) &&
382 + !(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
383 + dev_err(&pdev->dev, "Missing DCS, aborting."
384 +- "(id == 0X%p, id->driver_data: 0x%lx,"
385 +- " pci_resource_flags(pdev, 0):0x%lx)\n", id,
386 +- id ? id->driver_data : 0, pci_resource_flags(pdev, 0));
387 ++ "(driver_data: 0x%x, pci_resource_flags(pdev, 0):0x%lx)\n",
388 ++ pci_dev_data, pci_resource_flags(pdev, 0));
389 + err = -ENODEV;
390 + goto err_disable_pdev;
391 + }
392 +@@ -1801,15 +1798,8 @@ static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
393 + /* Allow large DMA segments, up to the firmware limit of 1 GB */
394 + dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024);
395 +
396 +- priv = kzalloc(sizeof *priv, GFP_KERNEL);
397 +- if (!priv) {
398 +- dev_err(&pdev->dev, "Device struct alloc failed, "
399 +- "aborting.\n");
400 +- err = -ENOMEM;
401 +- goto err_release_regions;
402 +- }
403 +-
404 +- dev = &priv->dev;
405 ++ dev = pci_get_drvdata(pdev);
406 ++ priv = mlx4_priv(dev);
407 + dev->pdev = pdev;
408 + INIT_LIST_HEAD(&priv->ctx_list);
409 + spin_lock_init(&priv->ctx_lock);
410 +@@ -1824,7 +1814,7 @@ static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
411 +
412 + dev->rev_id = pdev->revision;
413 + /* Detect if this device is a virtual function */
414 +- if (id && id->driver_data & MLX4_VF) {
415 ++ if (pci_dev_data & MLX4_PCI_DEV_IS_VF) {
416 + /* When acting as pf, we normally skip vfs unless explicitly
417 + * requested to probe them. */
418 + if (num_vfs && extended_func_num(pdev) > probe_vf) {
419 +@@ -1970,7 +1960,7 @@ slave_start:
420 + mlx4_sense_init(dev);
421 + mlx4_start_sense(dev);
422 +
423 +- pci_set_drvdata(pdev, dev);
424 ++ priv->removed = 0;
425 +
426 + return 0;
427 +
428 +@@ -2037,79 +2027,111 @@ err_disable_pdev:
429 + static int __devinit mlx4_init_one(struct pci_dev *pdev,
430 + const struct pci_device_id *id)
431 + {
432 ++ struct mlx4_priv *priv;
433 ++ struct mlx4_dev *dev;
434 ++
435 + printk_once(KERN_INFO "%s", mlx4_version);
436 +
437 +- return __mlx4_init_one(pdev, id);
438 ++ priv = kzalloc(sizeof(*priv), GFP_KERNEL);
439 ++ if (!priv)
440 ++ return -ENOMEM;
441 ++
442 ++ dev = &priv->dev;
443 ++ pci_set_drvdata(pdev, dev);
444 ++ priv->pci_dev_data = id->driver_data;
445 ++
446 ++ return __mlx4_init_one(pdev, id->driver_data);
447 + }
448 +
449 +-static void mlx4_remove_one(struct pci_dev *pdev)
450 ++static void __mlx4_remove_one(struct pci_dev *pdev)
451 + {
452 + struct mlx4_dev *dev = pci_get_drvdata(pdev);
453 + struct mlx4_priv *priv = mlx4_priv(dev);
454 ++ int pci_dev_data;
455 + int p;
456 +
457 +- if (dev) {
458 +- /* in SRIOV it is not allowed to unload the pf's
459 +- * driver while there are alive vf's */
460 +- if (mlx4_is_master(dev)) {
461 +- if (mlx4_how_many_lives_vf(dev))
462 +- printk(KERN_ERR "Removing PF when there are assigned VF's !!!\n");
463 +- }
464 +- mlx4_stop_sense(dev);
465 +- mlx4_unregister_device(dev);
466 ++ if (priv->removed)
467 ++ return;
468 +
469 +- for (p = 1; p <= dev->caps.num_ports; p++) {
470 +- mlx4_cleanup_port_info(&priv->port[p]);
471 +- mlx4_CLOSE_PORT(dev, p);
472 +- }
473 ++ pci_dev_data = priv->pci_dev_data;
474 +
475 +- mlx4_cleanup_counters_table(dev);
476 +- mlx4_cleanup_mcg_table(dev);
477 +- mlx4_cleanup_qp_table(dev);
478 +- mlx4_cleanup_srq_table(dev);
479 +- mlx4_cleanup_cq_table(dev);
480 +- mlx4_cmd_use_polling(dev);
481 +- mlx4_cleanup_eq_table(dev);
482 +- mlx4_cleanup_mr_table(dev);
483 +- mlx4_cleanup_xrcd_table(dev);
484 +- mlx4_cleanup_pd_table(dev);
485 ++ /* in SRIOV it is not allowed to unload the pf's
486 ++ * driver while there are alive vf's */
487 ++ if (mlx4_is_master(dev)) {
488 ++ if (mlx4_how_many_lives_vf(dev))
489 ++ printk(KERN_ERR "Removing PF when there are assigned VF's !!!\n");
490 ++ }
491 ++ mlx4_stop_sense(dev);
492 ++ mlx4_unregister_device(dev);
493 +
494 +- if (mlx4_is_master(dev))
495 +- mlx4_free_resource_tracker(dev);
496 +-
497 +- iounmap(priv->kar);
498 +- mlx4_uar_free(dev, &priv->driver_uar);
499 +- mlx4_cleanup_uar_table(dev);
500 +- if (!mlx4_is_slave(dev))
501 +- mlx4_clear_steering(dev);
502 +- mlx4_free_eq_table(dev);
503 +- if (mlx4_is_master(dev))
504 +- mlx4_multi_func_cleanup(dev);
505 +- mlx4_close_hca(dev);
506 +- if (mlx4_is_slave(dev))
507 +- mlx4_multi_func_cleanup(dev);
508 +- mlx4_cmd_cleanup(dev);
509 +-
510 +- if (dev->flags & MLX4_FLAG_MSI_X)
511 +- pci_disable_msix(pdev);
512 +- if (num_vfs && (dev->flags & MLX4_FLAG_SRIOV)) {
513 +- mlx4_warn(dev, "Disabling sriov\n");
514 +- pci_disable_sriov(pdev);
515 +- }
516 ++ for (p = 1; p <= dev->caps.num_ports; p++) {
517 ++ mlx4_cleanup_port_info(&priv->port[p]);
518 ++ mlx4_CLOSE_PORT(dev, p);
519 ++ }
520 ++
521 ++ mlx4_cleanup_counters_table(dev);
522 ++ mlx4_cleanup_mcg_table(dev);
523 ++ mlx4_cleanup_qp_table(dev);
524 ++ mlx4_cleanup_srq_table(dev);
525 ++ mlx4_cleanup_cq_table(dev);
526 ++ mlx4_cmd_use_polling(dev);
527 ++ mlx4_cleanup_eq_table(dev);
528 ++ mlx4_cleanup_mr_table(dev);
529 ++ mlx4_cleanup_xrcd_table(dev);
530 ++ mlx4_cleanup_pd_table(dev);
531 ++
532 ++ if (mlx4_is_master(dev))
533 ++ mlx4_free_resource_tracker(dev);
534 ++
535 ++ iounmap(priv->kar);
536 ++ mlx4_uar_free(dev, &priv->driver_uar);
537 ++ mlx4_cleanup_uar_table(dev);
538 ++ if (!mlx4_is_slave(dev))
539 ++ mlx4_clear_steering(dev);
540 ++ mlx4_free_eq_table(dev);
541 ++ if (mlx4_is_master(dev))
542 ++ mlx4_multi_func_cleanup(dev);
543 ++ mlx4_close_hca(dev);
544 ++ if (mlx4_is_slave(dev))
545 ++ mlx4_multi_func_cleanup(dev);
546 ++ mlx4_cmd_cleanup(dev);
547 +
548 +- if (!mlx4_is_slave(dev))
549 +- mlx4_free_ownership(dev);
550 +- kfree(priv);
551 +- pci_release_regions(pdev);
552 +- pci_disable_device(pdev);
553 +- pci_set_drvdata(pdev, NULL);
554 ++ if (dev->flags & MLX4_FLAG_MSI_X)
555 ++ pci_disable_msix(pdev);
556 ++ if (num_vfs && (dev->flags & MLX4_FLAG_SRIOV)) {
557 ++ mlx4_warn(dev, "Disabling sriov\n");
558 ++ pci_disable_sriov(pdev);
559 + }
560 ++
561 ++ if (!mlx4_is_slave(dev))
562 ++ mlx4_free_ownership(dev);
563 ++
564 ++ pci_release_regions(pdev);
565 ++ pci_disable_device(pdev);
566 ++ memset(priv, 0, sizeof(*priv));
567 ++ priv->pci_dev_data = pci_dev_data;
568 ++ priv->removed = 1;
569 ++}
570 ++
571 ++static void mlx4_remove_one(struct pci_dev *pdev)
572 ++{
573 ++ struct mlx4_dev *dev = pci_get_drvdata(pdev);
574 ++ struct mlx4_priv *priv = mlx4_priv(dev);
575 ++
576 ++ __mlx4_remove_one(pdev);
577 ++ kfree(priv);
578 ++ pci_set_drvdata(pdev, NULL);
579 + }
580 +
581 + int mlx4_restart_one(struct pci_dev *pdev)
582 + {
583 +- mlx4_remove_one(pdev);
584 +- return __mlx4_init_one(pdev, NULL);
585 ++ struct mlx4_dev *dev = pci_get_drvdata(pdev);
586 ++ struct mlx4_priv *priv = mlx4_priv(dev);
587 ++ int pci_dev_data;
588 ++
589 ++ pci_dev_data = priv->pci_dev_data;
590 ++ __mlx4_remove_one(pdev);
591 ++ return __mlx4_init_one(pdev, pci_dev_data);
592 + }
593 +
594 + static DEFINE_PCI_DEVICE_TABLE(mlx4_pci_table) = {
595 +@@ -2138,11 +2160,11 @@ static DEFINE_PCI_DEVICE_TABLE(mlx4_pci_table) = {
596 + /* MT26478 ConnectX2 40GigE PCIe gen2 */
597 + { PCI_VDEVICE(MELLANOX, 0x676e), 0 },
598 + /* MT25400 Family [ConnectX-2 Virtual Function] */
599 +- { PCI_VDEVICE(MELLANOX, 0x1002), MLX4_VF },
600 ++ { PCI_VDEVICE(MELLANOX, 0x1002), MLX4_PCI_DEV_IS_VF },
601 + /* MT27500 Family [ConnectX-3] */
602 + { PCI_VDEVICE(MELLANOX, 0x1003), 0 },
603 + /* MT27500 Family [ConnectX-3 Virtual Function] */
604 +- { PCI_VDEVICE(MELLANOX, 0x1004), MLX4_VF },
605 ++ { PCI_VDEVICE(MELLANOX, 0x1004), MLX4_PCI_DEV_IS_VF },
606 + { PCI_VDEVICE(MELLANOX, 0x1005), 0 }, /* MT27510 Family */
607 + { PCI_VDEVICE(MELLANOX, 0x1006), 0 }, /* MT27511 Family */
608 + { PCI_VDEVICE(MELLANOX, 0x1007), 0 }, /* MT27520 Family */
609 +diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
610 +index 2a0ff2cc7182..a3ef1dff163d 100644
611 +--- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
612 ++++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
613 +@@ -711,6 +711,10 @@ struct mlx4_steer {
614 + struct list_head steer_entries[MLX4_NUM_STEERS];
615 + };
616 +
617 ++enum {
618 ++ MLX4_PCI_DEV_IS_VF = 1 << 0,
619 ++};
620 ++
621 + struct mlx4_priv {
622 + struct mlx4_dev dev;
623 +
624 +@@ -718,6 +722,9 @@ struct mlx4_priv {
625 + struct list_head ctx_list;
626 + spinlock_t ctx_lock;
627 +
628 ++ int pci_dev_data;
629 ++ int removed;
630 ++
631 + struct list_head pgdir_list;
632 + struct mutex pgdir_mutex;
633 +
634 +diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
635 +index 8f81805c6825..d16800f5168a 100644
636 +--- a/drivers/net/team/team.c
637 ++++ b/drivers/net/team/team.c
638 +@@ -889,6 +889,7 @@ static int team_change_mtu(struct net_device *dev, int new_mtu)
639 + * to traverse list in reverse under rcu_read_lock
640 + */
641 + mutex_lock(&team->lock);
642 ++ team->port_mtu_change_allowed = true;
643 + list_for_each_entry(port, &team->port_list, list) {
644 + err = dev_set_mtu(port->dev, new_mtu);
645 + if (err) {
646 +@@ -897,6 +898,7 @@ static int team_change_mtu(struct net_device *dev, int new_mtu)
647 + goto unwind;
648 + }
649 + }
650 ++ team->port_mtu_change_allowed = false;
651 + mutex_unlock(&team->lock);
652 +
653 + dev->mtu = new_mtu;
654 +@@ -906,6 +908,7 @@ static int team_change_mtu(struct net_device *dev, int new_mtu)
655 + unwind:
656 + list_for_each_entry_continue_reverse(port, &team->port_list, list)
657 + dev_set_mtu(port->dev, dev->mtu);
658 ++ team->port_mtu_change_allowed = false;
659 + mutex_unlock(&team->lock);
660 +
661 + return err;
662 +@@ -1671,7 +1674,9 @@ static int team_device_event(struct notifier_block *unused,
663 + break;
664 + case NETDEV_CHANGEMTU:
665 + /* Forbid to change mtu of underlaying device */
666 +- return NOTIFY_BAD;
667 ++ if (!port->team->port_mtu_change_allowed)
668 ++ return NOTIFY_BAD;
669 ++ break;
670 + case NETDEV_PRE_TYPE_CHANGE:
671 + /* Forbid to change type of underlaying device */
672 + return NOTIFY_BAD;
673 +diff --git a/drivers/target/iscsi/iscsi_target_auth.c b/drivers/target/iscsi/iscsi_target_auth.c
674 +index b54f6ecf90d9..cbb04f37ec36 100644
675 +--- a/drivers/target/iscsi/iscsi_target_auth.c
676 ++++ b/drivers/target/iscsi/iscsi_target_auth.c
677 +@@ -342,6 +342,16 @@ static int chap_server_compute_md5(
678 + goto out;
679 + }
680 + /*
681 ++ * During mutual authentication, the CHAP_C generated by the
682 ++ * initiator must not match the original CHAP_C generated by
683 ++ * the target.
684 ++ */
685 ++ if (!memcmp(challenge_binhex, chap->challenge, CHAP_CHALLENGE_LENGTH)) {
686 ++ pr_err("initiator CHAP_C matches target CHAP_C, failing"
687 ++ " login attempt\n");
688 ++ goto out;
689 ++ }
690 ++ /*
691 + * Generate CHAP_N and CHAP_R for mutual authentication.
692 + */
693 + tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);
694 +diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
695 +index f509888b7ad0..2f2540ff21f6 100644
696 +--- a/drivers/usb/class/cdc-acm.c
697 ++++ b/drivers/usb/class/cdc-acm.c
698 +@@ -123,13 +123,23 @@ static void acm_release_minor(struct acm *acm)
699 + static int acm_ctrl_msg(struct acm *acm, int request, int value,
700 + void *buf, int len)
701 + {
702 +- int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
703 ++ int retval;
704 ++
705 ++ retval = usb_autopm_get_interface(acm->control);
706 ++ if (retval)
707 ++ return retval;
708 ++
709 ++ retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
710 + request, USB_RT_ACM, value,
711 + acm->control->altsetting[0].desc.bInterfaceNumber,
712 + buf, len, 5000);
713 ++
714 + dev_dbg(&acm->control->dev,
715 + "%s - rq 0x%02x, val %#x, len %#x, result %d\n",
716 + __func__, request, value, len, retval);
717 ++
718 ++ usb_autopm_put_interface(acm->control);
719 ++
720 + return retval < 0 ? retval : 0;
721 + }
722 +
723 +@@ -234,12 +244,9 @@ static int acm_write_start(struct acm *acm, int wbn)
724 + acm->susp_count);
725 + usb_autopm_get_interface_async(acm->control);
726 + if (acm->susp_count) {
727 +- if (!acm->delayed_wb)
728 +- acm->delayed_wb = wb;
729 +- else
730 +- usb_autopm_put_interface_async(acm->control);
731 ++ usb_anchor_urb(wb->urb, &acm->delayed);
732 + spin_unlock_irqrestore(&acm->write_lock, flags);
733 +- return 0; /* A white lie */
734 ++ return 0;
735 + }
736 + usb_mark_last_busy(acm->dev);
737 +
738 +@@ -535,6 +542,7 @@ static int acm_port_activate(struct tty_port *port, struct tty_struct *tty)
739 + {
740 + struct acm *acm = container_of(port, struct acm, port);
741 + int retval = -ENODEV;
742 ++ int i;
743 +
744 + dev_dbg(&acm->control->dev, "%s\n", __func__);
745 +
746 +@@ -583,6 +591,8 @@ static int acm_port_activate(struct tty_port *port, struct tty_struct *tty)
747 + return 0;
748 +
749 + error_submit_read_urbs:
750 ++ for (i = 0; i < acm->rx_buflimit; i++)
751 ++ usb_kill_urb(acm->read_urbs[i]);
752 + acm->ctrlout = 0;
753 + acm_set_control(acm, acm->ctrlout);
754 + error_set_control:
755 +@@ -610,21 +620,35 @@ static void acm_port_destruct(struct tty_port *port)
756 + static void acm_port_shutdown(struct tty_port *port)
757 + {
758 + struct acm *acm = container_of(port, struct acm, port);
759 ++ struct urb *urb;
760 ++ struct acm_wb *wb;
761 + int i;
762 ++ int pm_err;
763 +
764 + dev_dbg(&acm->control->dev, "%s\n", __func__);
765 +
766 + mutex_lock(&acm->mutex);
767 + if (!acm->disconnected) {
768 +- usb_autopm_get_interface(acm->control);
769 ++ pm_err = usb_autopm_get_interface(acm->control);
770 + acm_set_control(acm, acm->ctrlout = 0);
771 ++
772 ++ for (;;) {
773 ++ urb = usb_get_from_anchor(&acm->delayed);
774 ++ if (!urb)
775 ++ break;
776 ++ wb = urb->context;
777 ++ wb->use = 0;
778 ++ usb_autopm_put_interface_async(acm->control);
779 ++ }
780 ++
781 + usb_kill_urb(acm->ctrlurb);
782 + for (i = 0; i < ACM_NW; i++)
783 + usb_kill_urb(acm->wb[i].urb);
784 + for (i = 0; i < acm->rx_buflimit; i++)
785 + usb_kill_urb(acm->read_urbs[i]);
786 + acm->control->needs_remote_wakeup = 0;
787 +- usb_autopm_put_interface(acm->control);
788 ++ if (!pm_err)
789 ++ usb_autopm_put_interface(acm->control);
790 + }
791 + mutex_unlock(&acm->mutex);
792 + }
793 +@@ -1211,6 +1235,7 @@ made_compressed_probe:
794 + acm->bInterval = epread->bInterval;
795 + tty_port_init(&acm->port);
796 + acm->port.ops = &acm_port_ops;
797 ++ init_usb_anchor(&acm->delayed);
798 +
799 + buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
800 + if (!buf) {
801 +@@ -1441,18 +1466,15 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message)
802 + struct acm *acm = usb_get_intfdata(intf);
803 + int cnt;
804 +
805 ++ spin_lock_irq(&acm->read_lock);
806 ++ spin_lock(&acm->write_lock);
807 + if (PMSG_IS_AUTO(message)) {
808 +- int b;
809 +-
810 +- spin_lock_irq(&acm->write_lock);
811 +- b = acm->transmitting;
812 +- spin_unlock_irq(&acm->write_lock);
813 +- if (b)
814 ++ if (acm->transmitting) {
815 ++ spin_unlock(&acm->write_lock);
816 ++ spin_unlock_irq(&acm->read_lock);
817 + return -EBUSY;
818 ++ }
819 + }
820 +-
821 +- spin_lock_irq(&acm->read_lock);
822 +- spin_lock(&acm->write_lock);
823 + cnt = acm->susp_count++;
824 + spin_unlock(&acm->write_lock);
825 + spin_unlock_irq(&acm->read_lock);
826 +@@ -1460,8 +1482,7 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message)
827 + if (cnt)
828 + return 0;
829 +
830 +- if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags))
831 +- stop_data_traffic(acm);
832 ++ stop_data_traffic(acm);
833 +
834 + return 0;
835 + }
836 +@@ -1469,29 +1490,24 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message)
837 + static int acm_resume(struct usb_interface *intf)
838 + {
839 + struct acm *acm = usb_get_intfdata(intf);
840 +- struct acm_wb *wb;
841 ++ struct urb *urb;
842 + int rv = 0;
843 +- int cnt;
844 +
845 + spin_lock_irq(&acm->read_lock);
846 +- acm->susp_count -= 1;
847 +- cnt = acm->susp_count;
848 +- spin_unlock_irq(&acm->read_lock);
849 ++ spin_lock(&acm->write_lock);
850 +
851 +- if (cnt)
852 +- return 0;
853 ++ if (--acm->susp_count)
854 ++ goto out;
855 +
856 + if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) {
857 +- rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO);
858 +-
859 +- spin_lock_irq(&acm->write_lock);
860 +- if (acm->delayed_wb) {
861 +- wb = acm->delayed_wb;
862 +- acm->delayed_wb = NULL;
863 +- spin_unlock_irq(&acm->write_lock);
864 +- acm_start_wb(acm, wb);
865 +- } else {
866 +- spin_unlock_irq(&acm->write_lock);
867 ++ rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC);
868 ++
869 ++ for (;;) {
870 ++ urb = usb_get_from_anchor(&acm->delayed);
871 ++ if (!urb)
872 ++ break;
873 ++
874 ++ acm_start_wb(acm, urb->context);
875 + }
876 +
877 + /*
878 +@@ -1499,12 +1515,14 @@ static int acm_resume(struct usb_interface *intf)
879 + * do the write path at all cost
880 + */
881 + if (rv < 0)
882 +- goto err_out;
883 ++ goto out;
884 +
885 +- rv = acm_submit_read_urbs(acm, GFP_NOIO);
886 ++ rv = acm_submit_read_urbs(acm, GFP_ATOMIC);
887 + }
888 ++out:
889 ++ spin_unlock(&acm->write_lock);
890 ++ spin_unlock_irq(&acm->read_lock);
891 +
892 +-err_out:
893 + return rv;
894 + }
895 +
896 +diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
897 +index 35ef887b7417..96147806b9a4 100644
898 +--- a/drivers/usb/class/cdc-acm.h
899 ++++ b/drivers/usb/class/cdc-acm.h
900 +@@ -117,7 +117,7 @@ struct acm {
901 + unsigned int throttled:1; /* actually throttled */
902 + unsigned int throttle_req:1; /* throttle requested */
903 + u8 bInterval;
904 +- struct acm_wb *delayed_wb; /* write queued for a device about to be woken */
905 ++ struct usb_anchor delayed; /* writes queued for a device about to be woken */
906 + };
907 +
908 + #define CDC_DATA_INTERFACE_TYPE 0x0a
909 +diff --git a/include/linux/if_team.h b/include/linux/if_team.h
910 +index 58404b0c5010..b159b10d915d 100644
911 +--- a/include/linux/if_team.h
912 ++++ b/include/linux/if_team.h
913 +@@ -113,6 +113,7 @@ struct team {
914 +
915 + const struct team_mode *mode;
916 + struct team_mode_ops ops;
917 ++ bool port_mtu_change_allowed;
918 + long mode_priv[TEAM_MODE_PRIV_LONGS];
919 + };
920 +
921 +diff --git a/include/linux/lzo.h b/include/linux/lzo.h
922 +index d793497ec1ca..a0848d9377e5 100644
923 +--- a/include/linux/lzo.h
924 ++++ b/include/linux/lzo.h
925 +@@ -4,28 +4,28 @@
926 + * LZO Public Kernel Interface
927 + * A mini subset of the LZO real-time data compression library
928 + *
929 +- * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@×××××××××.com>
930 ++ * Copyright (C) 1996-2012 Markus F.X.J. Oberhumer <markus@×××××××××.com>
931 + *
932 + * The full LZO package can be found at:
933 + * http://www.oberhumer.com/opensource/lzo/
934 + *
935 +- * Changed for kernel use by:
936 ++ * Changed for Linux kernel use by:
937 + * Nitin Gupta <nitingupta910@×××××.com>
938 + * Richard Purdie <rpurdie@××××××××××.com>
939 + */
940 +
941 +-#define LZO1X_MEM_COMPRESS (16384 * sizeof(unsigned char *))
942 +-#define LZO1X_1_MEM_COMPRESS LZO1X_MEM_COMPRESS
943 ++#define LZO1X_1_MEM_COMPRESS (8192 * sizeof(unsigned short))
944 ++#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS
945 +
946 + #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
947 +
948 +-/* This requires 'workmem' of size LZO1X_1_MEM_COMPRESS */
949 ++/* This requires 'wrkmem' of size LZO1X_1_MEM_COMPRESS */
950 + int lzo1x_1_compress(const unsigned char *src, size_t src_len,
951 +- unsigned char *dst, size_t *dst_len, void *wrkmem);
952 ++ unsigned char *dst, size_t *dst_len, void *wrkmem);
953 +
954 + /* safe decompression with overrun testing */
955 + int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
956 +- unsigned char *dst, size_t *dst_len);
957 ++ unsigned char *dst, size_t *dst_len);
958 +
959 + /*
960 + * Return values (< 0 = Error)
961 +@@ -40,5 +40,6 @@ int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
962 + #define LZO_E_EOF_NOT_FOUND (-7)
963 + #define LZO_E_INPUT_NOT_CONSUMED (-8)
964 + #define LZO_E_NOT_YET_IMPLEMENTED (-9)
965 ++#define LZO_E_INVALID_ARGUMENT (-10)
966 +
967 + #endif
968 +diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
969 +index 2040bff945d4..2d643649f0f8 100644
970 +--- a/include/net/inetpeer.h
971 ++++ b/include/net/inetpeer.h
972 +@@ -114,16 +114,9 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
973 + /* can be called with or without local BH being disabled */
974 + static inline int inet_getid(struct inet_peer *p, int more)
975 + {
976 +- int old, new;
977 + more++;
978 + inet_peer_refcheck(p);
979 +- do {
980 +- old = atomic_read(&p->ip_id_count);
981 +- new = old + more;
982 +- if (!new)
983 +- new = 1;
984 +- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
985 +- return new;
986 ++ return atomic_add_return(more, &p->ip_id_count) - more;
987 + }
988 +
989 + #endif /* _NET_INETPEER_H */
990 +diff --git a/include/sound/core.h b/include/sound/core.h
991 +index 93896ad1fcdd..8d29d28d3696 100644
992 +--- a/include/sound/core.h
993 ++++ b/include/sound/core.h
994 +@@ -120,6 +120,8 @@ struct snd_card {
995 + int user_ctl_count; /* count of all user controls */
996 + struct list_head controls; /* all controls for this card */
997 + struct list_head ctl_files; /* active control files */
998 ++ struct mutex user_ctl_lock; /* protects user controls against
999 ++ concurrent access */
1000 +
1001 + struct snd_info_entry *proc_root; /* root for soundcard specific files */
1002 + struct snd_info_entry *proc_id; /* the card id */
1003 +diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
1004 +index 638dadf6295f..67106f88dca1 100644
1005 +--- a/kernel/time/tick-sched.c
1006 ++++ b/kernel/time/tick-sched.c
1007 +@@ -296,8 +296,10 @@ static void tick_nohz_stop_sched_tick(struct tick_sched *ts)
1008 + tick_do_timer_cpu = TICK_DO_TIMER_NONE;
1009 + }
1010 +
1011 +- if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE))
1012 ++ if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE)) {
1013 ++ ts->sleep_length = (ktime_t) { .tv64 = NSEC_PER_SEC/HZ };
1014 + return;
1015 ++ }
1016 +
1017 + if (need_resched())
1018 + return;
1019 +diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c
1020 +index 4531294fa62f..960183d4258f 100644
1021 +--- a/lib/decompress_unlzo.c
1022 ++++ b/lib/decompress_unlzo.c
1023 +@@ -31,7 +31,7 @@
1024 + */
1025 +
1026 + #ifdef STATIC
1027 +-#include "lzo/lzo1x_decompress.c"
1028 ++#include "lzo/lzo1x_decompress_safe.c"
1029 + #else
1030 + #include <linux/decompress/unlzo.h>
1031 + #endif
1032 +diff --git a/lib/lzo/Makefile b/lib/lzo/Makefile
1033 +index e764116ea12d..f0f7d7ca2b83 100644
1034 +--- a/lib/lzo/Makefile
1035 ++++ b/lib/lzo/Makefile
1036 +@@ -1,5 +1,5 @@
1037 + lzo_compress-objs := lzo1x_compress.o
1038 +-lzo_decompress-objs := lzo1x_decompress.o
1039 ++lzo_decompress-objs := lzo1x_decompress_safe.o
1040 +
1041 + obj-$(CONFIG_LZO_COMPRESS) += lzo_compress.o
1042 + obj-$(CONFIG_LZO_DECOMPRESS) += lzo_decompress.o
1043 +diff --git a/lib/lzo/lzo1x_compress.c b/lib/lzo/lzo1x_compress.c
1044 +index a6040990a62e..236eb21167b5 100644
1045 +--- a/lib/lzo/lzo1x_compress.c
1046 ++++ b/lib/lzo/lzo1x_compress.c
1047 +@@ -1,194 +1,243 @@
1048 + /*
1049 +- * LZO1X Compressor from MiniLZO
1050 ++ * LZO1X Compressor from LZO
1051 + *
1052 +- * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@×××××××××.com>
1053 ++ * Copyright (C) 1996-2012 Markus F.X.J. Oberhumer <markus@×××××××××.com>
1054 + *
1055 + * The full LZO package can be found at:
1056 + * http://www.oberhumer.com/opensource/lzo/
1057 + *
1058 +- * Changed for kernel use by:
1059 ++ * Changed for Linux kernel use by:
1060 + * Nitin Gupta <nitingupta910@×××××.com>
1061 + * Richard Purdie <rpurdie@××××××××××.com>
1062 + */
1063 +
1064 + #include <linux/module.h>
1065 + #include <linux/kernel.h>
1066 +-#include <linux/lzo.h>
1067 + #include <asm/unaligned.h>
1068 ++#include <linux/lzo.h>
1069 + #include "lzodefs.h"
1070 +
1071 + static noinline size_t
1072 +-_lzo1x_1_do_compress(const unsigned char *in, size_t in_len,
1073 +- unsigned char *out, size_t *out_len, void *wrkmem)
1074 ++lzo1x_1_do_compress(const unsigned char *in, size_t in_len,
1075 ++ unsigned char *out, size_t *out_len,
1076 ++ size_t ti, void *wrkmem)
1077 + {
1078 ++ const unsigned char *ip;
1079 ++ unsigned char *op;
1080 + const unsigned char * const in_end = in + in_len;
1081 +- const unsigned char * const ip_end = in + in_len - M2_MAX_LEN - 5;
1082 +- const unsigned char ** const dict = wrkmem;
1083 +- const unsigned char *ip = in, *ii = ip;
1084 +- const unsigned char *end, *m, *m_pos;
1085 +- size_t m_off, m_len, dindex;
1086 +- unsigned char *op = out;
1087 ++ const unsigned char * const ip_end = in + in_len - 20;
1088 ++ const unsigned char *ii;
1089 ++ lzo_dict_t * const dict = (lzo_dict_t *) wrkmem;
1090 +
1091 +- ip += 4;
1092 ++ op = out;
1093 ++ ip = in;
1094 ++ ii = ip;
1095 ++ ip += ti < 4 ? 4 - ti : 0;
1096 +
1097 + for (;;) {
1098 +- dindex = ((size_t)(0x21 * DX3(ip, 5, 5, 6)) >> 5) & D_MASK;
1099 +- m_pos = dict[dindex];
1100 +-
1101 +- if (m_pos < in)
1102 +- goto literal;
1103 +-
1104 +- if (ip == m_pos || ((size_t)(ip - m_pos) > M4_MAX_OFFSET))
1105 +- goto literal;
1106 +-
1107 +- m_off = ip - m_pos;
1108 +- if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
1109 +- goto try_match;
1110 +-
1111 +- dindex = (dindex & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f);
1112 +- m_pos = dict[dindex];
1113 +-
1114 +- if (m_pos < in)
1115 +- goto literal;
1116 +-
1117 +- if (ip == m_pos || ((size_t)(ip - m_pos) > M4_MAX_OFFSET))
1118 +- goto literal;
1119 +-
1120 +- m_off = ip - m_pos;
1121 +- if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
1122 +- goto try_match;
1123 +-
1124 +- goto literal;
1125 +-
1126 +-try_match:
1127 +- if (get_unaligned((const unsigned short *)m_pos)
1128 +- == get_unaligned((const unsigned short *)ip)) {
1129 +- if (likely(m_pos[2] == ip[2]))
1130 +- goto match;
1131 +- }
1132 +-
1133 ++ const unsigned char *m_pos;
1134 ++ size_t t, m_len, m_off;
1135 ++ u32 dv;
1136 + literal:
1137 +- dict[dindex] = ip;
1138 +- ++ip;
1139 ++ ip += 1 + ((ip - ii) >> 5);
1140 ++next:
1141 + if (unlikely(ip >= ip_end))
1142 + break;
1143 +- continue;
1144 +-
1145 +-match:
1146 +- dict[dindex] = ip;
1147 +- if (ip != ii) {
1148 +- size_t t = ip - ii;
1149 ++ dv = get_unaligned_le32(ip);
1150 ++ t = ((dv * 0x1824429d) >> (32 - D_BITS)) & D_MASK;
1151 ++ m_pos = in + dict[t];
1152 ++ dict[t] = (lzo_dict_t) (ip - in);
1153 ++ if (unlikely(dv != get_unaligned_le32(m_pos)))
1154 ++ goto literal;
1155 +
1156 ++ ii -= ti;
1157 ++ ti = 0;
1158 ++ t = ip - ii;
1159 ++ if (t != 0) {
1160 + if (t <= 3) {
1161 + op[-2] |= t;
1162 +- } else if (t <= 18) {
1163 ++ COPY4(op, ii);
1164 ++ op += t;
1165 ++ } else if (t <= 16) {
1166 + *op++ = (t - 3);
1167 ++ COPY8(op, ii);
1168 ++ COPY8(op + 8, ii + 8);
1169 ++ op += t;
1170 + } else {
1171 +- size_t tt = t - 18;
1172 +-
1173 +- *op++ = 0;
1174 +- while (tt > 255) {
1175 +- tt -= 255;
1176 ++ if (t <= 18) {
1177 ++ *op++ = (t - 3);
1178 ++ } else {
1179 ++ size_t tt = t - 18;
1180 + *op++ = 0;
1181 ++ while (unlikely(tt > 255)) {
1182 ++ tt -= 255;
1183 ++ *op++ = 0;
1184 ++ }
1185 ++ *op++ = tt;
1186 + }
1187 +- *op++ = tt;
1188 ++ do {
1189 ++ COPY8(op, ii);
1190 ++ COPY8(op + 8, ii + 8);
1191 ++ op += 16;
1192 ++ ii += 16;
1193 ++ t -= 16;
1194 ++ } while (t >= 16);
1195 ++ if (t > 0) do {
1196 ++ *op++ = *ii++;
1197 ++ } while (--t > 0);
1198 + }
1199 +- do {
1200 +- *op++ = *ii++;
1201 +- } while (--t > 0);
1202 + }
1203 +
1204 +- ip += 3;
1205 +- if (m_pos[3] != *ip++ || m_pos[4] != *ip++
1206 +- || m_pos[5] != *ip++ || m_pos[6] != *ip++
1207 +- || m_pos[7] != *ip++ || m_pos[8] != *ip++) {
1208 +- --ip;
1209 +- m_len = ip - ii;
1210 ++ m_len = 4;
1211 ++ {
1212 ++#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && defined(LZO_USE_CTZ64)
1213 ++ u64 v;
1214 ++ v = get_unaligned((const u64 *) (ip + m_len)) ^
1215 ++ get_unaligned((const u64 *) (m_pos + m_len));
1216 ++ if (unlikely(v == 0)) {
1217 ++ do {
1218 ++ m_len += 8;
1219 ++ v = get_unaligned((const u64 *) (ip + m_len)) ^
1220 ++ get_unaligned((const u64 *) (m_pos + m_len));
1221 ++ if (unlikely(ip + m_len >= ip_end))
1222 ++ goto m_len_done;
1223 ++ } while (v == 0);
1224 ++ }
1225 ++# if defined(__LITTLE_ENDIAN)
1226 ++ m_len += (unsigned) __builtin_ctzll(v) / 8;
1227 ++# elif defined(__BIG_ENDIAN)
1228 ++ m_len += (unsigned) __builtin_clzll(v) / 8;
1229 ++# else
1230 ++# error "missing endian definition"
1231 ++# endif
1232 ++#elif defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && defined(LZO_USE_CTZ32)
1233 ++ u32 v;
1234 ++ v = get_unaligned((const u32 *) (ip + m_len)) ^
1235 ++ get_unaligned((const u32 *) (m_pos + m_len));
1236 ++ if (unlikely(v == 0)) {
1237 ++ do {
1238 ++ m_len += 4;
1239 ++ v = get_unaligned((const u32 *) (ip + m_len)) ^
1240 ++ get_unaligned((const u32 *) (m_pos + m_len));
1241 ++ if (v != 0)
1242 ++ break;
1243 ++ m_len += 4;
1244 ++ v = get_unaligned((const u32 *) (ip + m_len)) ^
1245 ++ get_unaligned((const u32 *) (m_pos + m_len));
1246 ++ if (unlikely(ip + m_len >= ip_end))
1247 ++ goto m_len_done;
1248 ++ } while (v == 0);
1249 ++ }
1250 ++# if defined(__LITTLE_ENDIAN)
1251 ++ m_len += (unsigned) __builtin_ctz(v) / 8;
1252 ++# elif defined(__BIG_ENDIAN)
1253 ++ m_len += (unsigned) __builtin_clz(v) / 8;
1254 ++# else
1255 ++# error "missing endian definition"
1256 ++# endif
1257 ++#else
1258 ++ if (unlikely(ip[m_len] == m_pos[m_len])) {
1259 ++ do {
1260 ++ m_len += 1;
1261 ++ if (ip[m_len] != m_pos[m_len])
1262 ++ break;
1263 ++ m_len += 1;
1264 ++ if (ip[m_len] != m_pos[m_len])
1265 ++ break;
1266 ++ m_len += 1;
1267 ++ if (ip[m_len] != m_pos[m_len])
1268 ++ break;
1269 ++ m_len += 1;
1270 ++ if (ip[m_len] != m_pos[m_len])
1271 ++ break;
1272 ++ m_len += 1;
1273 ++ if (ip[m_len] != m_pos[m_len])
1274 ++ break;
1275 ++ m_len += 1;
1276 ++ if (ip[m_len] != m_pos[m_len])
1277 ++ break;
1278 ++ m_len += 1;
1279 ++ if (ip[m_len] != m_pos[m_len])
1280 ++ break;
1281 ++ m_len += 1;
1282 ++ if (unlikely(ip + m_len >= ip_end))
1283 ++ goto m_len_done;
1284 ++ } while (ip[m_len] == m_pos[m_len]);
1285 ++ }
1286 ++#endif
1287 ++ }
1288 ++m_len_done:
1289 +
1290 +- if (m_off <= M2_MAX_OFFSET) {
1291 +- m_off -= 1;
1292 +- *op++ = (((m_len - 1) << 5)
1293 +- | ((m_off & 7) << 2));
1294 +- *op++ = (m_off >> 3);
1295 +- } else if (m_off <= M3_MAX_OFFSET) {
1296 +- m_off -= 1;
1297 ++ m_off = ip - m_pos;
1298 ++ ip += m_len;
1299 ++ ii = ip;
1300 ++ if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) {
1301 ++ m_off -= 1;
1302 ++ *op++ = (((m_len - 1) << 5) | ((m_off & 7) << 2));
1303 ++ *op++ = (m_off >> 3);
1304 ++ } else if (m_off <= M3_MAX_OFFSET) {
1305 ++ m_off -= 1;
1306 ++ if (m_len <= M3_MAX_LEN)
1307 + *op++ = (M3_MARKER | (m_len - 2));
1308 +- goto m3_m4_offset;
1309 +- } else {
1310 +- m_off -= 0x4000;
1311 +-
1312 +- *op++ = (M4_MARKER | ((m_off & 0x4000) >> 11)
1313 +- | (m_len - 2));
1314 +- goto m3_m4_offset;
1315 ++ else {
1316 ++ m_len -= M3_MAX_LEN;
1317 ++ *op++ = M3_MARKER | 0;
1318 ++ while (unlikely(m_len > 255)) {
1319 ++ m_len -= 255;
1320 ++ *op++ = 0;
1321 ++ }
1322 ++ *op++ = (m_len);
1323 + }
1324 ++ *op++ = (m_off << 2);
1325 ++ *op++ = (m_off >> 6);
1326 + } else {
1327 +- end = in_end;
1328 +- m = m_pos + M2_MAX_LEN + 1;
1329 +-
1330 +- while (ip < end && *m == *ip) {
1331 +- m++;
1332 +- ip++;
1333 +- }
1334 +- m_len = ip - ii;
1335 +-
1336 +- if (m_off <= M3_MAX_OFFSET) {
1337 +- m_off -= 1;
1338 +- if (m_len <= 33) {
1339 +- *op++ = (M3_MARKER | (m_len - 2));
1340 +- } else {
1341 +- m_len -= 33;
1342 +- *op++ = M3_MARKER | 0;
1343 +- goto m3_m4_len;
1344 +- }
1345 +- } else {
1346 +- m_off -= 0x4000;
1347 +- if (m_len <= M4_MAX_LEN) {
1348 +- *op++ = (M4_MARKER
1349 +- | ((m_off & 0x4000) >> 11)
1350 ++ m_off -= 0x4000;
1351 ++ if (m_len <= M4_MAX_LEN)
1352 ++ *op++ = (M4_MARKER | ((m_off >> 11) & 8)
1353 + | (m_len - 2));
1354 +- } else {
1355 +- m_len -= M4_MAX_LEN;
1356 +- *op++ = (M4_MARKER
1357 +- | ((m_off & 0x4000) >> 11));
1358 +-m3_m4_len:
1359 +- while (m_len > 255) {
1360 +- m_len -= 255;
1361 +- *op++ = 0;
1362 +- }
1363 +-
1364 +- *op++ = (m_len);
1365 ++ else {
1366 ++ m_len -= M4_MAX_LEN;
1367 ++ *op++ = (M4_MARKER | ((m_off >> 11) & 8));
1368 ++ while (unlikely(m_len > 255)) {
1369 ++ m_len -= 255;
1370 ++ *op++ = 0;
1371 + }
1372 ++ *op++ = (m_len);
1373 + }
1374 +-m3_m4_offset:
1375 +- *op++ = ((m_off & 63) << 2);
1376 ++ *op++ = (m_off << 2);
1377 + *op++ = (m_off >> 6);
1378 + }
1379 +-
1380 +- ii = ip;
1381 +- if (unlikely(ip >= ip_end))
1382 +- break;
1383 ++ goto next;
1384 + }
1385 +-
1386 + *out_len = op - out;
1387 +- return in_end - ii;
1388 ++ return in_end - (ii - ti);
1389 + }
1390 +
1391 +-int lzo1x_1_compress(const unsigned char *in, size_t in_len, unsigned char *out,
1392 +- size_t *out_len, void *wrkmem)
1393 ++int lzo1x_1_compress(const unsigned char *in, size_t in_len,
1394 ++ unsigned char *out, size_t *out_len,
1395 ++ void *wrkmem)
1396 + {
1397 +- const unsigned char *ii;
1398 ++ const unsigned char *ip = in;
1399 + unsigned char *op = out;
1400 +- size_t t;
1401 ++ size_t l = in_len;
1402 ++ size_t t = 0;
1403 +
1404 +- if (unlikely(in_len <= M2_MAX_LEN + 5)) {
1405 +- t = in_len;
1406 +- } else {
1407 +- t = _lzo1x_1_do_compress(in, in_len, op, out_len, wrkmem);
1408 ++ while (l > 20) {
1409 ++ size_t ll = l <= (M4_MAX_OFFSET + 1) ? l : (M4_MAX_OFFSET + 1);
1410 ++ uintptr_t ll_end = (uintptr_t) ip + ll;
1411 ++ if ((ll_end + ((t + ll) >> 5)) <= ll_end)
1412 ++ break;
1413 ++ BUILD_BUG_ON(D_SIZE * sizeof(lzo_dict_t) > LZO1X_1_MEM_COMPRESS);
1414 ++ memset(wrkmem, 0, D_SIZE * sizeof(lzo_dict_t));
1415 ++ t = lzo1x_1_do_compress(ip, ll, op, out_len, t, wrkmem);
1416 ++ ip += ll;
1417 + op += *out_len;
1418 ++ l -= ll;
1419 + }
1420 ++ t += l;
1421 +
1422 + if (t > 0) {
1423 +- ii = in + in_len - t;
1424 ++ const unsigned char *ii = in + in_len - t;
1425 +
1426 + if (op == out && t <= 238) {
1427 + *op++ = (17 + t);
1428 +@@ -198,16 +247,21 @@ int lzo1x_1_compress(const unsigned char *in, size_t in_len, unsigned char *out,
1429 + *op++ = (t - 3);
1430 + } else {
1431 + size_t tt = t - 18;
1432 +-
1433 + *op++ = 0;
1434 + while (tt > 255) {
1435 + tt -= 255;
1436 + *op++ = 0;
1437 + }
1438 +-
1439 + *op++ = tt;
1440 + }
1441 +- do {
1442 ++ if (t >= 16) do {
1443 ++ COPY8(op, ii);
1444 ++ COPY8(op + 8, ii + 8);
1445 ++ op += 16;
1446 ++ ii += 16;
1447 ++ t -= 16;
1448 ++ } while (t >= 16);
1449 ++ if (t > 0) do {
1450 + *op++ = *ii++;
1451 + } while (--t > 0);
1452 + }
1453 +@@ -223,4 +277,3 @@ EXPORT_SYMBOL_GPL(lzo1x_1_compress);
1454 +
1455 + MODULE_LICENSE("GPL");
1456 + MODULE_DESCRIPTION("LZO1X-1 Compressor");
1457 +-
1458 +diff --git a/lib/lzo/lzo1x_decompress.c b/lib/lzo/lzo1x_decompress.c
1459 +deleted file mode 100644
1460 +index f2fd09850223..000000000000
1461 +--- a/lib/lzo/lzo1x_decompress.c
1462 ++++ /dev/null
1463 +@@ -1,255 +0,0 @@
1464 +-/*
1465 +- * LZO1X Decompressor from MiniLZO
1466 +- *
1467 +- * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@×××××××××.com>
1468 +- *
1469 +- * The full LZO package can be found at:
1470 +- * http://www.oberhumer.com/opensource/lzo/
1471 +- *
1472 +- * Changed for kernel use by:
1473 +- * Nitin Gupta <nitingupta910@×××××.com>
1474 +- * Richard Purdie <rpurdie@××××××××××.com>
1475 +- */
1476 +-
1477 +-#ifndef STATIC
1478 +-#include <linux/module.h>
1479 +-#include <linux/kernel.h>
1480 +-#endif
1481 +-
1482 +-#include <asm/unaligned.h>
1483 +-#include <linux/lzo.h>
1484 +-#include "lzodefs.h"
1485 +-
1486 +-#define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x))
1487 +-#define HAVE_OP(x, op_end, op) ((size_t)(op_end - op) < (x))
1488 +-#define HAVE_LB(m_pos, out, op) (m_pos < out || m_pos >= op)
1489 +-
1490 +-#define COPY4(dst, src) \
1491 +- put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst))
1492 +-
1493 +-int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
1494 +- unsigned char *out, size_t *out_len)
1495 +-{
1496 +- const unsigned char * const ip_end = in + in_len;
1497 +- unsigned char * const op_end = out + *out_len;
1498 +- const unsigned char *ip = in, *m_pos;
1499 +- unsigned char *op = out;
1500 +- size_t t;
1501 +-
1502 +- *out_len = 0;
1503 +-
1504 +- if (*ip > 17) {
1505 +- t = *ip++ - 17;
1506 +- if (t < 4)
1507 +- goto match_next;
1508 +- if (HAVE_OP(t, op_end, op))
1509 +- goto output_overrun;
1510 +- if (HAVE_IP(t + 1, ip_end, ip))
1511 +- goto input_overrun;
1512 +- do {
1513 +- *op++ = *ip++;
1514 +- } while (--t > 0);
1515 +- goto first_literal_run;
1516 +- }
1517 +-
1518 +- while ((ip < ip_end)) {
1519 +- t = *ip++;
1520 +- if (t >= 16)
1521 +- goto match;
1522 +- if (t == 0) {
1523 +- if (HAVE_IP(1, ip_end, ip))
1524 +- goto input_overrun;
1525 +- while (*ip == 0) {
1526 +- t += 255;
1527 +- ip++;
1528 +- if (HAVE_IP(1, ip_end, ip))
1529 +- goto input_overrun;
1530 +- }
1531 +- t += 15 + *ip++;
1532 +- }
1533 +- if (HAVE_OP(t + 3, op_end, op))
1534 +- goto output_overrun;
1535 +- if (HAVE_IP(t + 4, ip_end, ip))
1536 +- goto input_overrun;
1537 +-
1538 +- COPY4(op, ip);
1539 +- op += 4;
1540 +- ip += 4;
1541 +- if (--t > 0) {
1542 +- if (t >= 4) {
1543 +- do {
1544 +- COPY4(op, ip);
1545 +- op += 4;
1546 +- ip += 4;
1547 +- t -= 4;
1548 +- } while (t >= 4);
1549 +- if (t > 0) {
1550 +- do {
1551 +- *op++ = *ip++;
1552 +- } while (--t > 0);
1553 +- }
1554 +- } else {
1555 +- do {
1556 +- *op++ = *ip++;
1557 +- } while (--t > 0);
1558 +- }
1559 +- }
1560 +-
1561 +-first_literal_run:
1562 +- t = *ip++;
1563 +- if (t >= 16)
1564 +- goto match;
1565 +- m_pos = op - (1 + M2_MAX_OFFSET);
1566 +- m_pos -= t >> 2;
1567 +- m_pos -= *ip++ << 2;
1568 +-
1569 +- if (HAVE_LB(m_pos, out, op))
1570 +- goto lookbehind_overrun;
1571 +-
1572 +- if (HAVE_OP(3, op_end, op))
1573 +- goto output_overrun;
1574 +- *op++ = *m_pos++;
1575 +- *op++ = *m_pos++;
1576 +- *op++ = *m_pos;
1577 +-
1578 +- goto match_done;
1579 +-
1580 +- do {
1581 +-match:
1582 +- if (t >= 64) {
1583 +- m_pos = op - 1;
1584 +- m_pos -= (t >> 2) & 7;
1585 +- m_pos -= *ip++ << 3;
1586 +- t = (t >> 5) - 1;
1587 +- if (HAVE_LB(m_pos, out, op))
1588 +- goto lookbehind_overrun;
1589 +- if (HAVE_OP(t + 3 - 1, op_end, op))
1590 +- goto output_overrun;
1591 +- goto copy_match;
1592 +- } else if (t >= 32) {
1593 +- t &= 31;
1594 +- if (t == 0) {
1595 +- if (HAVE_IP(1, ip_end, ip))
1596 +- goto input_overrun;
1597 +- while (*ip == 0) {
1598 +- t += 255;
1599 +- ip++;
1600 +- if (HAVE_IP(1, ip_end, ip))
1601 +- goto input_overrun;
1602 +- }
1603 +- t += 31 + *ip++;
1604 +- }
1605 +- m_pos = op - 1;
1606 +- m_pos -= get_unaligned_le16(ip) >> 2;
1607 +- ip += 2;
1608 +- } else if (t >= 16) {
1609 +- m_pos = op;
1610 +- m_pos -= (t & 8) << 11;
1611 +-
1612 +- t &= 7;
1613 +- if (t == 0) {
1614 +- if (HAVE_IP(1, ip_end, ip))
1615 +- goto input_overrun;
1616 +- while (*ip == 0) {
1617 +- t += 255;
1618 +- ip++;
1619 +- if (HAVE_IP(1, ip_end, ip))
1620 +- goto input_overrun;
1621 +- }
1622 +- t += 7 + *ip++;
1623 +- }
1624 +- m_pos -= get_unaligned_le16(ip) >> 2;
1625 +- ip += 2;
1626 +- if (m_pos == op)
1627 +- goto eof_found;
1628 +- m_pos -= 0x4000;
1629 +- } else {
1630 +- m_pos = op - 1;
1631 +- m_pos -= t >> 2;
1632 +- m_pos -= *ip++ << 2;
1633 +-
1634 +- if (HAVE_LB(m_pos, out, op))
1635 +- goto lookbehind_overrun;
1636 +- if (HAVE_OP(2, op_end, op))
1637 +- goto output_overrun;
1638 +-
1639 +- *op++ = *m_pos++;
1640 +- *op++ = *m_pos;
1641 +- goto match_done;
1642 +- }
1643 +-
1644 +- if (HAVE_LB(m_pos, out, op))
1645 +- goto lookbehind_overrun;
1646 +- if (HAVE_OP(t + 3 - 1, op_end, op))
1647 +- goto output_overrun;
1648 +-
1649 +- if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) {
1650 +- COPY4(op, m_pos);
1651 +- op += 4;
1652 +- m_pos += 4;
1653 +- t -= 4 - (3 - 1);
1654 +- do {
1655 +- COPY4(op, m_pos);
1656 +- op += 4;
1657 +- m_pos += 4;
1658 +- t -= 4;
1659 +- } while (t >= 4);
1660 +- if (t > 0)
1661 +- do {
1662 +- *op++ = *m_pos++;
1663 +- } while (--t > 0);
1664 +- } else {
1665 +-copy_match:
1666 +- *op++ = *m_pos++;
1667 +- *op++ = *m_pos++;
1668 +- do {
1669 +- *op++ = *m_pos++;
1670 +- } while (--t > 0);
1671 +- }
1672 +-match_done:
1673 +- t = ip[-2] & 3;
1674 +- if (t == 0)
1675 +- break;
1676 +-match_next:
1677 +- if (HAVE_OP(t, op_end, op))
1678 +- goto output_overrun;
1679 +- if (HAVE_IP(t + 1, ip_end, ip))
1680 +- goto input_overrun;
1681 +-
1682 +- *op++ = *ip++;
1683 +- if (t > 1) {
1684 +- *op++ = *ip++;
1685 +- if (t > 2)
1686 +- *op++ = *ip++;
1687 +- }
1688 +-
1689 +- t = *ip++;
1690 +- } while (ip < ip_end);
1691 +- }
1692 +-
1693 +- *out_len = op - out;
1694 +- return LZO_E_EOF_NOT_FOUND;
1695 +-
1696 +-eof_found:
1697 +- *out_len = op - out;
1698 +- return (ip == ip_end ? LZO_E_OK :
1699 +- (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
1700 +-input_overrun:
1701 +- *out_len = op - out;
1702 +- return LZO_E_INPUT_OVERRUN;
1703 +-
1704 +-output_overrun:
1705 +- *out_len = op - out;
1706 +- return LZO_E_OUTPUT_OVERRUN;
1707 +-
1708 +-lookbehind_overrun:
1709 +- *out_len = op - out;
1710 +- return LZO_E_LOOKBEHIND_OVERRUN;
1711 +-}
1712 +-#ifndef STATIC
1713 +-EXPORT_SYMBOL_GPL(lzo1x_decompress_safe);
1714 +-
1715 +-MODULE_LICENSE("GPL");
1716 +-MODULE_DESCRIPTION("LZO1X Decompressor");
1717 +-
1718 +-#endif
1719 +diff --git a/lib/lzo/lzo1x_decompress_safe.c b/lib/lzo/lzo1x_decompress_safe.c
1720 +new file mode 100644
1721 +index 000000000000..8563081e8da3
1722 +--- /dev/null
1723 ++++ b/lib/lzo/lzo1x_decompress_safe.c
1724 +@@ -0,0 +1,257 @@
1725 ++/*
1726 ++ * LZO1X Decompressor from LZO
1727 ++ *
1728 ++ * Copyright (C) 1996-2012 Markus F.X.J. Oberhumer <markus@×××××××××.com>
1729 ++ *
1730 ++ * The full LZO package can be found at:
1731 ++ * http://www.oberhumer.com/opensource/lzo/
1732 ++ *
1733 ++ * Changed for Linux kernel use by:
1734 ++ * Nitin Gupta <nitingupta910@×××××.com>
1735 ++ * Richard Purdie <rpurdie@××××××××××.com>
1736 ++ */
1737 ++
1738 ++#ifndef STATIC
1739 ++#include <linux/module.h>
1740 ++#include <linux/kernel.h>
1741 ++#endif
1742 ++#include <asm/unaligned.h>
1743 ++#include <linux/lzo.h>
1744 ++#include "lzodefs.h"
1745 ++
1746 ++#define HAVE_IP(t, x) \
1747 ++ (((size_t)(ip_end - ip) >= (size_t)(t + x)) && \
1748 ++ (((t + x) >= t) && ((t + x) >= x)))
1749 ++
1750 ++#define HAVE_OP(t, x) \
1751 ++ (((size_t)(op_end - op) >= (size_t)(t + x)) && \
1752 ++ (((t + x) >= t) && ((t + x) >= x)))
1753 ++
1754 ++#define NEED_IP(t, x) \
1755 ++ do { \
1756 ++ if (!HAVE_IP(t, x)) \
1757 ++ goto input_overrun; \
1758 ++ } while (0)
1759 ++
1760 ++#define NEED_OP(t, x) \
1761 ++ do { \
1762 ++ if (!HAVE_OP(t, x)) \
1763 ++ goto output_overrun; \
1764 ++ } while (0)
1765 ++
1766 ++#define TEST_LB(m_pos) \
1767 ++ do { \
1768 ++ if ((m_pos) < out) \
1769 ++ goto lookbehind_overrun; \
1770 ++ } while (0)
1771 ++
1772 ++int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
1773 ++ unsigned char *out, size_t *out_len)
1774 ++{
1775 ++ unsigned char *op;
1776 ++ const unsigned char *ip;
1777 ++ size_t t, next;
1778 ++ size_t state = 0;
1779 ++ const unsigned char *m_pos;
1780 ++ const unsigned char * const ip_end = in + in_len;
1781 ++ unsigned char * const op_end = out + *out_len;
1782 ++
1783 ++ op = out;
1784 ++ ip = in;
1785 ++
1786 ++ if (unlikely(in_len < 3))
1787 ++ goto input_overrun;
1788 ++ if (*ip > 17) {
1789 ++ t = *ip++ - 17;
1790 ++ if (t < 4) {
1791 ++ next = t;
1792 ++ goto match_next;
1793 ++ }
1794 ++ goto copy_literal_run;
1795 ++ }
1796 ++
1797 ++ for (;;) {
1798 ++ t = *ip++;
1799 ++ if (t < 16) {
1800 ++ if (likely(state == 0)) {
1801 ++ if (unlikely(t == 0)) {
1802 ++ while (unlikely(*ip == 0)) {
1803 ++ t += 255;
1804 ++ ip++;
1805 ++ NEED_IP(1, 0);
1806 ++ }
1807 ++ t += 15 + *ip++;
1808 ++ }
1809 ++ t += 3;
1810 ++copy_literal_run:
1811 ++#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
1812 ++ if (likely(HAVE_IP(t, 15) && HAVE_OP(t, 15))) {
1813 ++ const unsigned char *ie = ip + t;
1814 ++ unsigned char *oe = op + t;
1815 ++ do {
1816 ++ COPY8(op, ip);
1817 ++ op += 8;
1818 ++ ip += 8;
1819 ++ COPY8(op, ip);
1820 ++ op += 8;
1821 ++ ip += 8;
1822 ++ } while (ip < ie);
1823 ++ ip = ie;
1824 ++ op = oe;
1825 ++ } else
1826 ++#endif
1827 ++ {
1828 ++ NEED_OP(t, 0);
1829 ++ NEED_IP(t, 3);
1830 ++ do {
1831 ++ *op++ = *ip++;
1832 ++ } while (--t > 0);
1833 ++ }
1834 ++ state = 4;
1835 ++ continue;
1836 ++ } else if (state != 4) {
1837 ++ next = t & 3;
1838 ++ m_pos = op - 1;
1839 ++ m_pos -= t >> 2;
1840 ++ m_pos -= *ip++ << 2;
1841 ++ TEST_LB(m_pos);
1842 ++ NEED_OP(2, 0);
1843 ++ op[0] = m_pos[0];
1844 ++ op[1] = m_pos[1];
1845 ++ op += 2;
1846 ++ goto match_next;
1847 ++ } else {
1848 ++ next = t & 3;
1849 ++ m_pos = op - (1 + M2_MAX_OFFSET);
1850 ++ m_pos -= t >> 2;
1851 ++ m_pos -= *ip++ << 2;
1852 ++ t = 3;
1853 ++ }
1854 ++ } else if (t >= 64) {
1855 ++ next = t & 3;
1856 ++ m_pos = op - 1;
1857 ++ m_pos -= (t >> 2) & 7;
1858 ++ m_pos -= *ip++ << 3;
1859 ++ t = (t >> 5) - 1 + (3 - 1);
1860 ++ } else if (t >= 32) {
1861 ++ t = (t & 31) + (3 - 1);
1862 ++ if (unlikely(t == 2)) {
1863 ++ while (unlikely(*ip == 0)) {
1864 ++ t += 255;
1865 ++ ip++;
1866 ++ NEED_IP(1, 0);
1867 ++ }
1868 ++ t += 31 + *ip++;
1869 ++ NEED_IP(2, 0);
1870 ++ }
1871 ++ m_pos = op - 1;
1872 ++ next = get_unaligned_le16(ip);
1873 ++ ip += 2;
1874 ++ m_pos -= next >> 2;
1875 ++ next &= 3;
1876 ++ } else {
1877 ++ m_pos = op;
1878 ++ m_pos -= (t & 8) << 11;
1879 ++ t = (t & 7) + (3 - 1);
1880 ++ if (unlikely(t == 2)) {
1881 ++ while (unlikely(*ip == 0)) {
1882 ++ t += 255;
1883 ++ ip++;
1884 ++ NEED_IP(1, 0);
1885 ++ }
1886 ++ t += 7 + *ip++;
1887 ++ NEED_IP(2, 0);
1888 ++ }
1889 ++ next = get_unaligned_le16(ip);
1890 ++ ip += 2;
1891 ++ m_pos -= next >> 2;
1892 ++ next &= 3;
1893 ++ if (m_pos == op)
1894 ++ goto eof_found;
1895 ++ m_pos -= 0x4000;
1896 ++ }
1897 ++ TEST_LB(m_pos);
1898 ++#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
1899 ++ if (op - m_pos >= 8) {
1900 ++ unsigned char *oe = op + t;
1901 ++ if (likely(HAVE_OP(t, 15))) {
1902 ++ do {
1903 ++ COPY8(op, m_pos);
1904 ++ op += 8;
1905 ++ m_pos += 8;
1906 ++ COPY8(op, m_pos);
1907 ++ op += 8;
1908 ++ m_pos += 8;
1909 ++ } while (op < oe);
1910 ++ op = oe;
1911 ++ if (HAVE_IP(6, 0)) {
1912 ++ state = next;
1913 ++ COPY4(op, ip);
1914 ++ op += next;
1915 ++ ip += next;
1916 ++ continue;
1917 ++ }
1918 ++ } else {
1919 ++ NEED_OP(t, 0);
1920 ++ do {
1921 ++ *op++ = *m_pos++;
1922 ++ } while (op < oe);
1923 ++ }
1924 ++ } else
1925 ++#endif
1926 ++ {
1927 ++ unsigned char *oe = op + t;
1928 ++ NEED_OP(t, 0);
1929 ++ op[0] = m_pos[0];
1930 ++ op[1] = m_pos[1];
1931 ++ op += 2;
1932 ++ m_pos += 2;
1933 ++ do {
1934 ++ *op++ = *m_pos++;
1935 ++ } while (op < oe);
1936 ++ }
1937 ++match_next:
1938 ++ state = next;
1939 ++ t = next;
1940 ++#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
1941 ++ if (likely(HAVE_IP(6, 0) && HAVE_OP(4, 0))) {
1942 ++ COPY4(op, ip);
1943 ++ op += t;
1944 ++ ip += t;
1945 ++ } else
1946 ++#endif
1947 ++ {
1948 ++ NEED_IP(t, 3);
1949 ++ NEED_OP(t, 0);
1950 ++ while (t > 0) {
1951 ++ *op++ = *ip++;
1952 ++ t--;
1953 ++ }
1954 ++ }
1955 ++ }
1956 ++
1957 ++eof_found:
1958 ++ *out_len = op - out;
1959 ++ return (t != 3 ? LZO_E_ERROR :
1960 ++ ip == ip_end ? LZO_E_OK :
1961 ++ ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN);
1962 ++
1963 ++input_overrun:
1964 ++ *out_len = op - out;
1965 ++ return LZO_E_INPUT_OVERRUN;
1966 ++
1967 ++output_overrun:
1968 ++ *out_len = op - out;
1969 ++ return LZO_E_OUTPUT_OVERRUN;
1970 ++
1971 ++lookbehind_overrun:
1972 ++ *out_len = op - out;
1973 ++ return LZO_E_LOOKBEHIND_OVERRUN;
1974 ++}
1975 ++#ifndef STATIC
1976 ++EXPORT_SYMBOL_GPL(lzo1x_decompress_safe);
1977 ++
1978 ++MODULE_LICENSE("GPL");
1979 ++MODULE_DESCRIPTION("LZO1X Decompressor");
1980 ++
1981 ++#endif
1982 +diff --git a/lib/lzo/lzodefs.h b/lib/lzo/lzodefs.h
1983 +index b6d482c492ef..6710b83ce72e 100644
1984 +--- a/lib/lzo/lzodefs.h
1985 ++++ b/lib/lzo/lzodefs.h
1986 +@@ -1,19 +1,37 @@
1987 + /*
1988 + * lzodefs.h -- architecture, OS and compiler specific defines
1989 + *
1990 +- * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@×××××××××.com>
1991 ++ * Copyright (C) 1996-2012 Markus F.X.J. Oberhumer <markus@×××××××××.com>
1992 + *
1993 + * The full LZO package can be found at:
1994 + * http://www.oberhumer.com/opensource/lzo/
1995 + *
1996 +- * Changed for kernel use by:
1997 ++ * Changed for Linux kernel use by:
1998 + * Nitin Gupta <nitingupta910@×××××.com>
1999 + * Richard Purdie <rpurdie@××××××××××.com>
2000 + */
2001 +
2002 +-#define LZO_VERSION 0x2020
2003 +-#define LZO_VERSION_STRING "2.02"
2004 +-#define LZO_VERSION_DATE "Oct 17 2005"
2005 ++
2006 ++#define COPY4(dst, src) \
2007 ++ put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst))
2008 ++#if defined(__x86_64__)
2009 ++#define COPY8(dst, src) \
2010 ++ put_unaligned(get_unaligned((const u64 *)(src)), (u64 *)(dst))
2011 ++#else
2012 ++#define COPY8(dst, src) \
2013 ++ COPY4(dst, src); COPY4((dst) + 4, (src) + 4)
2014 ++#endif
2015 ++
2016 ++#if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN)
2017 ++#error "conflicting endian definitions"
2018 ++#elif defined(__x86_64__)
2019 ++#define LZO_USE_CTZ64 1
2020 ++#define LZO_USE_CTZ32 1
2021 ++#elif defined(__i386__) || defined(__powerpc__)
2022 ++#define LZO_USE_CTZ32 1
2023 ++#elif defined(__arm__) && (__LINUX_ARM_ARCH__ >= 5)
2024 ++#define LZO_USE_CTZ32 1
2025 ++#endif
2026 +
2027 + #define M1_MAX_OFFSET 0x0400
2028 + #define M2_MAX_OFFSET 0x0800
2029 +@@ -34,10 +52,8 @@
2030 + #define M3_MARKER 32
2031 + #define M4_MARKER 16
2032 +
2033 +-#define D_BITS 14
2034 +-#define D_MASK ((1u << D_BITS) - 1)
2035 ++#define lzo_dict_t unsigned short
2036 ++#define D_BITS 13
2037 ++#define D_SIZE (1u << D_BITS)
2038 ++#define D_MASK (D_SIZE - 1)
2039 + #define D_HIGH ((D_MASK >> 1) + 1)
2040 +-
2041 +-#define DX2(p, s1, s2) (((((size_t)((p)[2]) << (s2)) ^ (p)[1]) \
2042 +- << (s1)) ^ (p)[0])
2043 +-#define DX3(p, s1, s2, s3) ((DX2((p)+1, s2, s3) << (s1)) ^ (p)[0])
2044 +diff --git a/lib/nlattr.c b/lib/nlattr.c
2045 +index 01c67507dc43..60abf1b5545a 100644
2046 +--- a/lib/nlattr.c
2047 ++++ b/lib/nlattr.c
2048 +@@ -13,6 +13,7 @@
2049 + #include <linux/skbuff.h>
2050 + #include <linux/string.h>
2051 + #include <linux/types.h>
2052 ++#include <linux/ratelimit.h>
2053 + #include <net/netlink.h>
2054 +
2055 + static const u16 nla_attr_minlen[NLA_TYPE_MAX+1] = {
2056 +@@ -197,8 +198,8 @@ int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head,
2057 + }
2058 +
2059 + if (unlikely(rem > 0))
2060 +- printk(KERN_WARNING "netlink: %d bytes leftover after parsing "
2061 +- "attributes.\n", rem);
2062 ++ pr_warn_ratelimited("netlink: %d bytes leftover after parsing attributes in process `%s'.\n",
2063 ++ rem, current->comm);
2064 +
2065 + err = 0;
2066 + errout:
2067 +diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
2068 +index d2f634880bdd..490132664d07 100644
2069 +--- a/net/ipv4/ipip.c
2070 ++++ b/net/ipv4/ipip.c
2071 +@@ -908,4 +908,5 @@ static void __exit ipip_fini(void)
2072 + module_init(ipip_init);
2073 + module_exit(ipip_fini);
2074 + MODULE_LICENSE("GPL");
2075 ++MODULE_ALIAS_RTNL_LINK("ipip");
2076 + MODULE_ALIAS_NETDEV("tunl0");
2077 +diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
2078 +index 5a2d819d8262..077b9a3f8d25 100644
2079 +--- a/net/ipv6/ip6_output.c
2080 ++++ b/net/ipv6/ip6_output.c
2081 +@@ -611,7 +611,7 @@ int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
2082 + void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
2083 + {
2084 + static atomic_t ipv6_fragmentation_id;
2085 +- int old, new;
2086 ++ int ident;
2087 +
2088 + if (rt && !(rt->dst.flags & DST_NOPEER)) {
2089 + struct inet_peer *peer;
2090 +@@ -624,13 +624,8 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
2091 + return;
2092 + }
2093 + }
2094 +- do {
2095 +- old = atomic_read(&ipv6_fragmentation_id);
2096 +- new = old + 1;
2097 +- if (!new)
2098 +- new = 1;
2099 +- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
2100 +- fhdr->identification = htonl(new);
2101 ++ ident = atomic_inc_return(&ipv6_fragmentation_id);
2102 ++ fhdr->identification = htonl(ident);
2103 + }
2104 +
2105 + int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
2106 +diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
2107 +index aa21da6a09cd..b876a2f81263 100644
2108 +--- a/net/ipv6/ip6_tunnel.c
2109 ++++ b/net/ipv6/ip6_tunnel.c
2110 +@@ -57,6 +57,7 @@
2111 + MODULE_AUTHOR("Ville Nuorvala");
2112 + MODULE_DESCRIPTION("IPv6 tunneling device");
2113 + MODULE_LICENSE("GPL");
2114 ++MODULE_ALIAS_RTNL_LINK("ip6tnl");
2115 + MODULE_ALIAS_NETDEV("ip6tnl0");
2116 +
2117 + #ifdef IP6_TNL_DEBUG
2118 +diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
2119 +index c4ffd1743528..3f20ba4f9547 100644
2120 +--- a/net/ipv6/sit.c
2121 ++++ b/net/ipv6/sit.c
2122 +@@ -1303,4 +1303,5 @@ static int __init sit_init(void)
2123 + module_init(sit_init);
2124 + module_exit(sit_cleanup);
2125 + MODULE_LICENSE("GPL");
2126 ++MODULE_ALIAS_RTNL_LINK("sit");
2127 + MODULE_ALIAS_NETDEV("sit0");
2128 +diff --git a/net/sctp/associola.c b/net/sctp/associola.c
2129 +index 3c04692d699a..25b207b3ffe4 100644
2130 +--- a/net/sctp/associola.c
2131 ++++ b/net/sctp/associola.c
2132 +@@ -389,7 +389,7 @@ void sctp_association_free(struct sctp_association *asoc)
2133 + /* Only real associations count against the endpoint, so
2134 + * don't bother for if this is a temporary association.
2135 + */
2136 +- if (!asoc->temp) {
2137 ++ if (!list_empty(&asoc->asocs)) {
2138 + list_del(&asoc->asocs);
2139 +
2140 + /* Decrement the backlog value for a TCP-style listening
2141 +diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c
2142 +index 8901501425f4..c487715698ab 100644
2143 +--- a/security/integrity/evm/evm_main.c
2144 ++++ b/security/integrity/evm/evm_main.c
2145 +@@ -271,12 +271,20 @@ static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name,
2146 + * @xattr_value: pointer to the new extended attribute value
2147 + * @xattr_value_len: pointer to the new extended attribute value length
2148 + *
2149 +- * Updating 'security.evm' requires CAP_SYS_ADMIN privileges and that
2150 +- * the current value is valid.
2151 ++ * Before allowing the 'security.evm' protected xattr to be updated,
2152 ++ * verify the existing value is valid. As only the kernel should have
2153 ++ * access to the EVM encrypted key needed to calculate the HMAC, prevent
2154 ++ * userspace from writing HMAC value. Writing 'security.evm' requires
2155 ++ * requires CAP_SYS_ADMIN privileges.
2156 + */
2157 + int evm_inode_setxattr(struct dentry *dentry, const char *xattr_name,
2158 + const void *xattr_value, size_t xattr_value_len)
2159 + {
2160 ++ const struct evm_ima_xattr_data *xattr_data = xattr_value;
2161 ++
2162 ++ if ((strcmp(xattr_name, XATTR_NAME_EVM) == 0)
2163 ++ && (xattr_data->type == EVM_XATTR_HMAC))
2164 ++ return -EPERM;
2165 + return evm_protect_xattr(dentry, xattr_name, xattr_value,
2166 + xattr_value_len);
2167 + }
2168 +diff --git a/sound/core/control.c b/sound/core/control.c
2169 +index daa4fc8872f3..e773d5ed1e9a 100644
2170 +--- a/sound/core/control.c
2171 ++++ b/sound/core/control.c
2172 +@@ -288,6 +288,10 @@ static bool snd_ctl_remove_numid_conflict(struct snd_card *card,
2173 + {
2174 + struct snd_kcontrol *kctl;
2175 +
2176 ++ /* Make sure that the ids assigned to the control do not wrap around */
2177 ++ if (card->last_numid >= UINT_MAX - count)
2178 ++ card->last_numid = 0;
2179 ++
2180 + list_for_each_entry(kctl, &card->controls, list) {
2181 + if (kctl->id.numid < card->last_numid + 1 + count &&
2182 + kctl->id.numid + kctl->count > card->last_numid + 1) {
2183 +@@ -329,6 +333,7 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
2184 + {
2185 + struct snd_ctl_elem_id id;
2186 + unsigned int idx;
2187 ++ unsigned int count;
2188 + int err = -EINVAL;
2189 +
2190 + if (! kcontrol)
2191 +@@ -336,6 +341,9 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
2192 + if (snd_BUG_ON(!card || !kcontrol->info))
2193 + goto error;
2194 + id = kcontrol->id;
2195 ++ if (id.index > UINT_MAX - kcontrol->count)
2196 ++ goto error;
2197 ++
2198 + down_write(&card->controls_rwsem);
2199 + if (snd_ctl_find_id(card, &id)) {
2200 + up_write(&card->controls_rwsem);
2201 +@@ -357,8 +365,9 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
2202 + card->controls_count += kcontrol->count;
2203 + kcontrol->id.numid = card->last_numid + 1;
2204 + card->last_numid += kcontrol->count;
2205 ++ count = kcontrol->count;
2206 + up_write(&card->controls_rwsem);
2207 +- for (idx = 0; idx < kcontrol->count; idx++, id.index++, id.numid++)
2208 ++ for (idx = 0; idx < count; idx++, id.index++, id.numid++)
2209 + snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
2210 + return 0;
2211 +
2212 +@@ -387,6 +396,7 @@ int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol,
2213 + bool add_on_replace)
2214 + {
2215 + struct snd_ctl_elem_id id;
2216 ++ unsigned int count;
2217 + unsigned int idx;
2218 + struct snd_kcontrol *old;
2219 + int ret;
2220 +@@ -422,8 +432,9 @@ add:
2221 + card->controls_count += kcontrol->count;
2222 + kcontrol->id.numid = card->last_numid + 1;
2223 + card->last_numid += kcontrol->count;
2224 ++ count = kcontrol->count;
2225 + up_write(&card->controls_rwsem);
2226 +- for (idx = 0; idx < kcontrol->count; idx++, id.index++, id.numid++)
2227 ++ for (idx = 0; idx < count; idx++, id.index++, id.numid++)
2228 + snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
2229 + return 0;
2230 +
2231 +@@ -894,9 +905,9 @@ static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
2232 + result = kctl->put(kctl, control);
2233 + }
2234 + if (result > 0) {
2235 ++ struct snd_ctl_elem_id id = control->id;
2236 + up_read(&card->controls_rwsem);
2237 +- snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
2238 +- &control->id);
2239 ++ snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &id);
2240 + return 0;
2241 + }
2242 + }
2243 +@@ -988,6 +999,7 @@ static int snd_ctl_elem_unlock(struct snd_ctl_file *file,
2244 +
2245 + struct user_element {
2246 + struct snd_ctl_elem_info info;
2247 ++ struct snd_card *card;
2248 + void *elem_data; /* element data */
2249 + unsigned long elem_data_size; /* size of element data in bytes */
2250 + void *tlv_data; /* TLV data */
2251 +@@ -1031,7 +1043,9 @@ static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol,
2252 + {
2253 + struct user_element *ue = kcontrol->private_data;
2254 +
2255 ++ mutex_lock(&ue->card->user_ctl_lock);
2256 + memcpy(&ucontrol->value, ue->elem_data, ue->elem_data_size);
2257 ++ mutex_unlock(&ue->card->user_ctl_lock);
2258 + return 0;
2259 + }
2260 +
2261 +@@ -1040,10 +1054,12 @@ static int snd_ctl_elem_user_put(struct snd_kcontrol *kcontrol,
2262 + {
2263 + int change;
2264 + struct user_element *ue = kcontrol->private_data;
2265 +-
2266 ++
2267 ++ mutex_lock(&ue->card->user_ctl_lock);
2268 + change = memcmp(&ucontrol->value, ue->elem_data, ue->elem_data_size) != 0;
2269 + if (change)
2270 + memcpy(ue->elem_data, &ucontrol->value, ue->elem_data_size);
2271 ++ mutex_unlock(&ue->card->user_ctl_lock);
2272 + return change;
2273 + }
2274 +
2275 +@@ -1063,19 +1079,32 @@ static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kcontrol,
2276 + new_data = memdup_user(tlv, size);
2277 + if (IS_ERR(new_data))
2278 + return PTR_ERR(new_data);
2279 ++ mutex_lock(&ue->card->user_ctl_lock);
2280 + change = ue->tlv_data_size != size;
2281 + if (!change)
2282 + change = memcmp(ue->tlv_data, new_data, size);
2283 + kfree(ue->tlv_data);
2284 + ue->tlv_data = new_data;
2285 + ue->tlv_data_size = size;
2286 ++ mutex_unlock(&ue->card->user_ctl_lock);
2287 + } else {
2288 +- if (! ue->tlv_data_size || ! ue->tlv_data)
2289 +- return -ENXIO;
2290 +- if (size < ue->tlv_data_size)
2291 +- return -ENOSPC;
2292 ++ int ret = 0;
2293 ++
2294 ++ mutex_lock(&ue->card->user_ctl_lock);
2295 ++ if (!ue->tlv_data_size || !ue->tlv_data) {
2296 ++ ret = -ENXIO;
2297 ++ goto err_unlock;
2298 ++ }
2299 ++ if (size < ue->tlv_data_size) {
2300 ++ ret = -ENOSPC;
2301 ++ goto err_unlock;
2302 ++ }
2303 + if (copy_to_user(tlv, ue->tlv_data, ue->tlv_data_size))
2304 +- return -EFAULT;
2305 ++ ret = -EFAULT;
2306 ++err_unlock:
2307 ++ mutex_unlock(&ue->card->user_ctl_lock);
2308 ++ if (ret)
2309 ++ return ret;
2310 + }
2311 + return change;
2312 + }
2313 +@@ -1133,8 +1162,6 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
2314 + struct user_element *ue;
2315 + int idx, err;
2316 +
2317 +- if (!replace && card->user_ctl_count >= MAX_USER_CONTROLS)
2318 +- return -ENOMEM;
2319 + if (info->count < 1)
2320 + return -EINVAL;
2321 + access = info->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE :
2322 +@@ -1143,21 +1170,16 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
2323 + SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE));
2324 + info->id.numid = 0;
2325 + memset(&kctl, 0, sizeof(kctl));
2326 +- down_write(&card->controls_rwsem);
2327 +- _kctl = snd_ctl_find_id(card, &info->id);
2328 +- err = 0;
2329 +- if (_kctl) {
2330 +- if (replace)
2331 +- err = snd_ctl_remove(card, _kctl);
2332 +- else
2333 +- err = -EBUSY;
2334 +- } else {
2335 +- if (replace)
2336 +- err = -ENOENT;
2337 ++
2338 ++ if (replace) {
2339 ++ err = snd_ctl_remove_user_ctl(file, &info->id);
2340 ++ if (err)
2341 ++ return err;
2342 + }
2343 +- up_write(&card->controls_rwsem);
2344 +- if (err < 0)
2345 +- return err;
2346 ++
2347 ++ if (card->user_ctl_count >= MAX_USER_CONTROLS)
2348 ++ return -ENOMEM;
2349 ++
2350 + memcpy(&kctl.id, &info->id, sizeof(info->id));
2351 + kctl.count = info->owner ? info->owner : 1;
2352 + access |= SNDRV_CTL_ELEM_ACCESS_USER;
2353 +@@ -1207,6 +1229,7 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
2354 + ue = kzalloc(sizeof(struct user_element) + private_size, GFP_KERNEL);
2355 + if (ue == NULL)
2356 + return -ENOMEM;
2357 ++ ue->card = card;
2358 + ue->info = *info;
2359 + ue->info.access = 0;
2360 + ue->elem_data = (char *)ue + sizeof(*ue);
2361 +@@ -1318,8 +1341,9 @@ static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file,
2362 + }
2363 + err = kctl->tlv.c(kctl, op_flag, tlv.length, _tlv->tlv);
2364 + if (err > 0) {
2365 ++ struct snd_ctl_elem_id id = kctl->id;
2366 + up_read(&card->controls_rwsem);
2367 +- snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_TLV, &kctl->id);
2368 ++ snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_TLV, &id);
2369 + return 0;
2370 + }
2371 + } else {
2372 +diff --git a/sound/core/init.c b/sound/core/init.c
2373 +index 7b012d15c2cf..41020d7395f3 100644
2374 +--- a/sound/core/init.c
2375 ++++ b/sound/core/init.c
2376 +@@ -208,6 +208,7 @@ int snd_card_create(int idx, const char *xid,
2377 + INIT_LIST_HEAD(&card->devices);
2378 + init_rwsem(&card->controls_rwsem);
2379 + rwlock_init(&card->ctl_files_rwlock);
2380 ++ mutex_init(&card->user_ctl_lock);
2381 + INIT_LIST_HEAD(&card->controls);
2382 + INIT_LIST_HEAD(&card->ctl_files);
2383 + spin_lock_init(&card->files_lock);
2384 +diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
2385 +index 2415dcec3265..4dac0b332a36 100644
2386 +--- a/sound/pci/hda/patch_realtek.c
2387 ++++ b/sound/pci/hda/patch_realtek.c
2388 +@@ -7062,6 +7062,7 @@ static const struct hda_codec_preset snd_hda_preset_realtek[] = {
2389 + { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
2390 + { .id = 0x10ec0671, .name = "ALC671", .patch = patch_alc662 },
2391 + { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
2392 ++ { .id = 0x10ec0867, .name = "ALC891", .patch = patch_alc882 },
2393 + { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
2394 + { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
2395 + { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },