Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.9 commit in: /
Date: Sun, 26 Feb 2017 20:36:37
Message-Id: 1488141371.e1dd80713909687f4e389508aa8294dc4484e8c3.mpagano@gentoo
1 commit: e1dd80713909687f4e389508aa8294dc4484e8c3
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Sun Feb 26 20:36:11 2017 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Sun Feb 26 20:36:11 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=e1dd8071
7
8 Linux patch 4.9.13
9
10 0000_README | 4 +
11 1012_linux-4.9.13.patch | 1079 +++++++++++++++++++++++++++++++++++++++++++++++
12 2 files changed, 1083 insertions(+)
13
14 diff --git a/0000_README b/0000_README
15 index 7d1182e..ca2aa4b 100644
16 --- a/0000_README
17 +++ b/0000_README
18 @@ -91,6 +91,10 @@ Patch: 1011_linux-4.9.12.patch
19 From: http://www.kernel.org
20 Desc: Linux 4.9.12
21
22 +Patch: 1011_linux-4.9.13.patch
23 +From: http://www.kernel.org
24 +Desc: Linux 4.9.13
25 +
26 Patch: 1500_XATTR_USER_PREFIX.patch
27 From: https://bugs.gentoo.org/show_bug.cgi?id=470644
28 Desc: Support for namespace user.pax.* on tmpfs.
29
30 diff --git a/1012_linux-4.9.13.patch b/1012_linux-4.9.13.patch
31 new file mode 100644
32 index 0000000..a23c877
33 --- /dev/null
34 +++ b/1012_linux-4.9.13.patch
35 @@ -0,0 +1,1079 @@
36 +diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
37 +index 922dec8fa07e..65b05ba6ef98 100644
38 +--- a/Documentation/kernel-parameters.txt
39 ++++ b/Documentation/kernel-parameters.txt
40 +@@ -1391,6 +1391,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
41 + When zero, profiling data is discarded and associated
42 + debugfs files are removed at module unload time.
43 +
44 ++ goldfish [X86] Enable the goldfish android emulator platform.
45 ++ Don't use this when you are not running on the
46 ++ android emulator
47 ++
48 + gpt [EFI] Forces disk with valid GPT signature but
49 + invalid Protective MBR to be treated as GPT. If the
50 + primary GPT is corrupted, it enables the backup/alternate
51 +diff --git a/Makefile b/Makefile
52 +index 3cd6f6fb4f20..14dc2758345b 100644
53 +--- a/Makefile
54 ++++ b/Makefile
55 +@@ -1,6 +1,6 @@
56 + VERSION = 4
57 + PATCHLEVEL = 9
58 +-SUBLEVEL = 12
59 ++SUBLEVEL = 13
60 + EXTRAVERSION =
61 + NAME = Roaring Lionus
62 +
63 +diff --git a/arch/x86/platform/goldfish/goldfish.c b/arch/x86/platform/goldfish/goldfish.c
64 +index 1693107a518e..0d17c0aafeb1 100644
65 +--- a/arch/x86/platform/goldfish/goldfish.c
66 ++++ b/arch/x86/platform/goldfish/goldfish.c
67 +@@ -42,10 +42,22 @@ static struct resource goldfish_pdev_bus_resources[] = {
68 + }
69 + };
70 +
71 ++static bool goldfish_enable __initdata;
72 ++
73 ++static int __init goldfish_setup(char *str)
74 ++{
75 ++ goldfish_enable = true;
76 ++ return 0;
77 ++}
78 ++__setup("goldfish", goldfish_setup);
79 ++
80 + static int __init goldfish_init(void)
81 + {
82 ++ if (!goldfish_enable)
83 ++ return -ENODEV;
84 ++
85 + platform_device_register_simple("goldfish_pdev_bus", -1,
86 +- goldfish_pdev_bus_resources, 2);
87 ++ goldfish_pdev_bus_resources, 2);
88 + return 0;
89 + }
90 + device_initcall(goldfish_init);
91 +diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
92 +index 6bb21b31cfeb..a543ea676de3 100644
93 +--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
94 ++++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
95 +@@ -567,10 +567,14 @@ int mlx5e_stats_flower(struct mlx5e_priv *priv,
96 +
97 + mlx5_fc_query_cached(counter, &bytes, &packets, &lastuse);
98 +
99 ++ preempt_disable();
100 ++
101 + tcf_exts_to_list(f->exts, &actions);
102 + list_for_each_entry(a, &actions, list)
103 + tcf_action_stats_update(a, bytes, packets, lastuse);
104 +
105 ++ preempt_enable();
106 ++
107 + return 0;
108 + }
109 +
110 +diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
111 +index b9087b828eff..3f1971d485f3 100644
112 +--- a/drivers/net/ethernet/ti/cpsw.c
113 ++++ b/drivers/net/ethernet/ti/cpsw.c
114 +@@ -2925,7 +2925,7 @@ static int cpsw_resume(struct device *dev)
115 + {
116 + struct platform_device *pdev = to_platform_device(dev);
117 + struct net_device *ndev = platform_get_drvdata(pdev);
118 +- struct cpsw_common *cpsw = netdev_priv(ndev);
119 ++ struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
120 +
121 + /* Select default pin state */
122 + pinctrl_pm_select_default_state(dev);
123 +diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
124 +index 0fafaa9d903b..d4f495b41bd4 100644
125 +--- a/drivers/net/vxlan.c
126 ++++ b/drivers/net/vxlan.c
127 +@@ -2449,7 +2449,8 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
128 + return -EINVAL;
129 + rt = vxlan_get_route(vxlan, skb, 0, info->key.tos,
130 + info->key.u.ipv4.dst,
131 +- &info->key.u.ipv4.src, NULL, info);
132 ++ &info->key.u.ipv4.src,
133 ++ &info->dst_cache, info);
134 + if (IS_ERR(rt))
135 + return PTR_ERR(rt);
136 + ip_rt_put(rt);
137 +@@ -2459,7 +2460,8 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
138 +
139 + ndst = vxlan6_get_route(vxlan, skb, 0, info->key.tos,
140 + info->key.label, &info->key.u.ipv6.dst,
141 +- &info->key.u.ipv6.src, NULL, info);
142 ++ &info->key.u.ipv6.src,
143 ++ &info->dst_cache, info);
144 + if (IS_ERR(ndst))
145 + return PTR_ERR(ndst);
146 + dst_release(ndst);
147 +diff --git a/drivers/net/wireless/realtek/rtlwifi/usb.c b/drivers/net/wireless/realtek/rtlwifi/usb.c
148 +index 3837bbdecf05..ae0c48f3c2bc 100644
149 +--- a/drivers/net/wireless/realtek/rtlwifi/usb.c
150 ++++ b/drivers/net/wireless/realtek/rtlwifi/usb.c
151 +@@ -831,12 +831,30 @@ static void rtl_usb_stop(struct ieee80211_hw *hw)
152 + struct rtl_priv *rtlpriv = rtl_priv(hw);
153 + struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
154 + struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
155 ++ struct urb *urb;
156 +
157 + /* should after adapter start and interrupt enable. */
158 + set_hal_stop(rtlhal);
159 + cancel_work_sync(&rtlpriv->works.fill_h2c_cmd);
160 + /* Enable software */
161 + SET_USB_STOP(rtlusb);
162 ++
163 ++ /* free pre-allocated URBs from rtl_usb_start() */
164 ++ usb_kill_anchored_urbs(&rtlusb->rx_submitted);
165 ++
166 ++ tasklet_kill(&rtlusb->rx_work_tasklet);
167 ++ cancel_work_sync(&rtlpriv->works.lps_change_work);
168 ++
169 ++ flush_workqueue(rtlpriv->works.rtl_wq);
170 ++
171 ++ skb_queue_purge(&rtlusb->rx_queue);
172 ++
173 ++ while ((urb = usb_get_from_anchor(&rtlusb->rx_cleanup_urbs))) {
174 ++ usb_free_coherent(urb->dev, urb->transfer_buffer_length,
175 ++ urb->transfer_buffer, urb->transfer_dma);
176 ++ usb_free_urb(urb);
177 ++ }
178 ++
179 + rtlpriv->cfg->ops->hw_disable(hw);
180 + }
181 +
182 +diff --git a/drivers/platform/goldfish/pdev_bus.c b/drivers/platform/goldfish/pdev_bus.c
183 +index 1f52462f4cdd..dd9ea463c2a4 100644
184 +--- a/drivers/platform/goldfish/pdev_bus.c
185 ++++ b/drivers/platform/goldfish/pdev_bus.c
186 +@@ -157,23 +157,26 @@ static int goldfish_new_pdev(void)
187 + static irqreturn_t goldfish_pdev_bus_interrupt(int irq, void *dev_id)
188 + {
189 + irqreturn_t ret = IRQ_NONE;
190 ++
191 + while (1) {
192 + u32 op = readl(pdev_bus_base + PDEV_BUS_OP);
193 +- switch (op) {
194 +- case PDEV_BUS_OP_DONE:
195 +- return IRQ_NONE;
196 +
197 ++ switch (op) {
198 + case PDEV_BUS_OP_REMOVE_DEV:
199 + goldfish_pdev_remove();
200 ++ ret = IRQ_HANDLED;
201 + break;
202 +
203 + case PDEV_BUS_OP_ADD_DEV:
204 + goldfish_new_pdev();
205 ++ ret = IRQ_HANDLED;
206 + break;
207 ++
208 ++ case PDEV_BUS_OP_DONE:
209 ++ default:
210 ++ return ret;
211 + }
212 +- ret = IRQ_HANDLED;
213 + }
214 +- return ret;
215 + }
216 +
217 + static int goldfish_pdev_bus_probe(struct platform_device *pdev)
218 +diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
219 +index 7312e7e01b7e..6788e7532dff 100644
220 +--- a/drivers/tty/serial/msm_serial.c
221 ++++ b/drivers/tty/serial/msm_serial.c
222 +@@ -1809,6 +1809,7 @@ static const struct of_device_id msm_match_table[] = {
223 + { .compatible = "qcom,msm-uartdm" },
224 + {}
225 + };
226 ++MODULE_DEVICE_TABLE(of, msm_match_table);
227 +
228 + static struct platform_driver msm_platform_driver = {
229 + .remove = msm_serial_remove,
230 +diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
231 +index 1532cde8a437..7812052dc700 100644
232 +--- a/drivers/usb/serial/ark3116.c
233 ++++ b/drivers/usb/serial/ark3116.c
234 +@@ -99,10 +99,17 @@ static int ark3116_read_reg(struct usb_serial *serial,
235 + usb_rcvctrlpipe(serial->dev, 0),
236 + 0xfe, 0xc0, 0, reg,
237 + buf, 1, ARK_TIMEOUT);
238 +- if (result < 0)
239 ++ if (result < 1) {
240 ++ dev_err(&serial->interface->dev,
241 ++ "failed to read register %u: %d\n",
242 ++ reg, result);
243 ++ if (result >= 0)
244 ++ result = -EIO;
245 ++
246 + return result;
247 +- else
248 +- return buf[0];
249 ++ }
250 ++
251 ++ return buf[0];
252 + }
253 +
254 + static inline int calc_divisor(int bps)
255 +diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
256 +index 8967715fe6fc..b6f1adefb758 100644
257 +--- a/drivers/usb/serial/console.c
258 ++++ b/drivers/usb/serial/console.c
259 +@@ -143,6 +143,7 @@ static int usb_console_setup(struct console *co, char *options)
260 + tty->driver = usb_serial_tty_driver;
261 + tty->index = co->index;
262 + init_ldsem(&tty->ldisc_sem);
263 ++ spin_lock_init(&tty->files_lock);
264 + INIT_LIST_HEAD(&tty->tty_files);
265 + kref_get(&tty->driver->kref);
266 + __module_get(tty->driver->owner);
267 +diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
268 +index 243ac5ebe46a..8bb48751028c 100644
269 +--- a/drivers/usb/serial/cp210x.c
270 ++++ b/drivers/usb/serial/cp210x.c
271 +@@ -172,6 +172,8 @@ static const struct usb_device_id id_table[] = {
272 + { USB_DEVICE(0x1901, 0x0190) }, /* GE B850 CP2105 Recorder interface */
273 + { USB_DEVICE(0x1901, 0x0193) }, /* GE B650 CP2104 PMC interface */
274 + { USB_DEVICE(0x1901, 0x0194) }, /* GE Healthcare Remote Alarm Box */
275 ++ { USB_DEVICE(0x1901, 0x0195) }, /* GE B850/B650/B450 CP2104 DP UART interface */
276 ++ { USB_DEVICE(0x1901, 0x0196) }, /* GE B850 CP2105 DP UART interface */
277 + { USB_DEVICE(0x19CF, 0x3000) }, /* Parrot NMEA GPS Flight Recorder */
278 + { USB_DEVICE(0x1ADB, 0x0001) }, /* Schweitzer Engineering C662 Cable */
279 + { USB_DEVICE(0x1B1C, 0x1C00) }, /* Corsair USB Dongle */
280 +diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
281 +index 6e9fc8bcc285..99a0a5f1b400 100644
282 +--- a/drivers/usb/serial/ftdi_sio.c
283 ++++ b/drivers/usb/serial/ftdi_sio.c
284 +@@ -1807,8 +1807,6 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
285 +
286 + mutex_init(&priv->cfg_lock);
287 +
288 +- priv->flags = ASYNC_LOW_LATENCY;
289 +-
290 + if (quirk && quirk->port_probe)
291 + quirk->port_probe(priv);
292 +
293 +@@ -2072,6 +2070,20 @@ static int ftdi_process_packet(struct usb_serial_port *port,
294 + priv->prev_status = status;
295 + }
296 +
297 ++ /* save if the transmitter is empty or not */
298 ++ if (packet[1] & FTDI_RS_TEMT)
299 ++ priv->transmit_empty = 1;
300 ++ else
301 ++ priv->transmit_empty = 0;
302 ++
303 ++ len -= 2;
304 ++ if (!len)
305 ++ return 0; /* status only */
306 ++
307 ++ /*
308 ++ * Break and error status must only be processed for packets with
309 ++ * data payload to avoid over-reporting.
310 ++ */
311 + flag = TTY_NORMAL;
312 + if (packet[1] & FTDI_RS_ERR_MASK) {
313 + /* Break takes precedence over parity, which takes precedence
314 +@@ -2094,15 +2106,6 @@ static int ftdi_process_packet(struct usb_serial_port *port,
315 + }
316 + }
317 +
318 +- /* save if the transmitter is empty or not */
319 +- if (packet[1] & FTDI_RS_TEMT)
320 +- priv->transmit_empty = 1;
321 +- else
322 +- priv->transmit_empty = 0;
323 +-
324 +- len -= 2;
325 +- if (!len)
326 +- return 0; /* status only */
327 + port->icount.rx += len;
328 + ch = packet + 2;
329 +
330 +@@ -2433,8 +2436,12 @@ static int ftdi_get_modem_status(struct usb_serial_port *port,
331 + FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
332 + 0, priv->interface,
333 + buf, len, WDR_TIMEOUT);
334 +- if (ret < 0) {
335 ++
336 ++ /* NOTE: We allow short responses and handle that below. */
337 ++ if (ret < 1) {
338 + dev_err(&port->dev, "failed to get modem status: %d\n", ret);
339 ++ if (ret >= 0)
340 ++ ret = -EIO;
341 + ret = usb_translate_errors(ret);
342 + goto out;
343 + }
344 +diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
345 +index 4f9af47e6a29..5c4fc3abf6a7 100644
346 +--- a/drivers/usb/serial/mos7840.c
347 ++++ b/drivers/usb/serial/mos7840.c
348 +@@ -1024,6 +1024,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
349 + * (can't set it up in mos7840_startup as the structures *
350 + * were not set up at that time.) */
351 + if (port0->open_ports == 1) {
352 ++ /* FIXME: Buffer never NULL, so URB is not submitted. */
353 + if (serial->port[0]->interrupt_in_buffer == NULL) {
354 + /* set up interrupt urb */
355 + usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
356 +@@ -2119,7 +2120,8 @@ static int mos7840_calc_num_ports(struct usb_serial *serial)
357 + static int mos7840_attach(struct usb_serial *serial)
358 + {
359 + if (serial->num_bulk_in < serial->num_ports ||
360 +- serial->num_bulk_out < serial->num_ports) {
361 ++ serial->num_bulk_out < serial->num_ports ||
362 ++ serial->num_interrupt_in < 1) {
363 + dev_err(&serial->interface->dev, "missing endpoints\n");
364 + return -ENODEV;
365 + }
366 +diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
367 +index 4b7bfb394a32..64bf258e7e00 100644
368 +--- a/drivers/usb/serial/opticon.c
369 ++++ b/drivers/usb/serial/opticon.c
370 +@@ -142,7 +142,7 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
371 + usb_clear_halt(port->serial->dev, port->read_urb->pipe);
372 +
373 + res = usb_serial_generic_open(tty, port);
374 +- if (!res)
375 ++ if (res)
376 + return res;
377 +
378 + /* Request CTS line state, sometimes during opening the current
379 +diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
380 +index 475e6c31b266..ddfd787c461c 100644
381 +--- a/drivers/usb/serial/spcp8x5.c
382 ++++ b/drivers/usb/serial/spcp8x5.c
383 +@@ -232,11 +232,17 @@ static int spcp8x5_get_msr(struct usb_serial_port *port, u8 *status)
384 + ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
385 + GET_UART_STATUS, GET_UART_STATUS_TYPE,
386 + 0, GET_UART_STATUS_MSR, buf, 1, 100);
387 +- if (ret < 0)
388 ++ if (ret < 1) {
389 + dev_err(&port->dev, "failed to get modem status: %d\n", ret);
390 ++ if (ret >= 0)
391 ++ ret = -EIO;
392 ++ goto out;
393 ++ }
394 +
395 + dev_dbg(&port->dev, "0xc0:0x22:0:6 %d - 0x02%x\n", ret, *buf);
396 + *status = *buf;
397 ++ ret = 0;
398 ++out:
399 + kfree(buf);
400 +
401 + return ret;
402 +diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
403 +index cdc6bdd495be..e8889614cec3 100644
404 +--- a/fs/xfs/xfs_iomap.c
405 ++++ b/fs/xfs/xfs_iomap.c
406 +@@ -1068,7 +1068,15 @@ xfs_file_iomap_end_delalloc(
407 + xfs_fileoff_t end_fsb;
408 + int error = 0;
409 +
410 +- start_fsb = XFS_B_TO_FSB(mp, offset + written);
411 ++ /*
412 ++ * start_fsb refers to the first unused block after a short write. If
413 ++ * nothing was written, round offset down to point at the first block in
414 ++ * the range.
415 ++ */
416 ++ if (unlikely(!written))
417 ++ start_fsb = XFS_B_TO_FSBT(mp, offset);
418 ++ else
419 ++ start_fsb = XFS_B_TO_FSB(mp, offset + written);
420 + end_fsb = XFS_B_TO_FSB(mp, offset + length);
421 +
422 + /*
423 +@@ -1080,6 +1088,9 @@ xfs_file_iomap_end_delalloc(
424 + * blocks in the range, they are ours.
425 + */
426 + if (start_fsb < end_fsb) {
427 ++ truncate_pagecache_range(VFS_I(ip), XFS_FSB_TO_B(mp, start_fsb),
428 ++ XFS_FSB_TO_B(mp, end_fsb) - 1);
429 ++
430 + xfs_ilock(ip, XFS_ILOCK_EXCL);
431 + error = xfs_bmap_punch_delalloc_range(ip, start_fsb,
432 + end_fsb - start_fsb);
433 +diff --git a/include/acpi/platform/acenv.h b/include/acpi/platform/acenv.h
434 +index 34cce729109c..fca15390a42c 100644
435 +--- a/include/acpi/platform/acenv.h
436 ++++ b/include/acpi/platform/acenv.h
437 +@@ -177,7 +177,7 @@
438 + #include "acmsvc.h"
439 +
440 + #elif defined(__INTEL_COMPILER)
441 +-#include "acintel.h"
442 ++#include <acpi/platform/acintel.h>
443 +
444 + #endif
445 +
446 +diff --git a/include/acpi/platform/acintel.h b/include/acpi/platform/acintel.h
447 +new file mode 100644
448 +index 000000000000..17bd3b7b4e5a
449 +--- /dev/null
450 ++++ b/include/acpi/platform/acintel.h
451 +@@ -0,0 +1,87 @@
452 ++/******************************************************************************
453 ++ *
454 ++ * Name: acintel.h - VC specific defines, etc.
455 ++ *
456 ++ *****************************************************************************/
457 ++
458 ++/*
459 ++ * Copyright (C) 2000 - 2017, Intel Corp.
460 ++ * All rights reserved.
461 ++ *
462 ++ * Redistribution and use in source and binary forms, with or without
463 ++ * modification, are permitted provided that the following conditions
464 ++ * are met:
465 ++ * 1. Redistributions of source code must retain the above copyright
466 ++ * notice, this list of conditions, and the following disclaimer,
467 ++ * without modification.
468 ++ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
469 ++ * substantially similar to the "NO WARRANTY" disclaimer below
470 ++ * ("Disclaimer") and any redistribution must be conditioned upon
471 ++ * including a substantially similar Disclaimer requirement for further
472 ++ * binary redistribution.
473 ++ * 3. Neither the names of the above-listed copyright holders nor the names
474 ++ * of any contributors may be used to endorse or promote products derived
475 ++ * from this software without specific prior written permission.
476 ++ *
477 ++ * Alternatively, this software may be distributed under the terms of the
478 ++ * GNU General Public License ("GPL") version 2 as published by the Free
479 ++ * Software Foundation.
480 ++ *
481 ++ * NO WARRANTY
482 ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
483 ++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
484 ++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
485 ++ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
486 ++ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
487 ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
488 ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
489 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
490 ++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
491 ++ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
492 ++ * POSSIBILITY OF SUCH DAMAGES.
493 ++ */
494 ++
495 ++#ifndef __ACINTEL_H__
496 ++#define __ACINTEL_H__
497 ++
498 ++/*
499 ++ * Use compiler specific <stdarg.h> is a good practice for even when
500 ++ * -nostdinc is specified (i.e., ACPI_USE_STANDARD_HEADERS undefined.
501 ++ */
502 ++#include <stdarg.h>
503 ++
504 ++/* Configuration specific to Intel 64-bit C compiler */
505 ++
506 ++#define COMPILER_DEPENDENT_INT64 __int64
507 ++#define COMPILER_DEPENDENT_UINT64 unsigned __int64
508 ++#define ACPI_INLINE __inline
509 ++
510 ++/*
511 ++ * Calling conventions:
512 ++ *
513 ++ * ACPI_SYSTEM_XFACE - Interfaces to host OS (handlers, threads)
514 ++ * ACPI_EXTERNAL_XFACE - External ACPI interfaces
515 ++ * ACPI_INTERNAL_XFACE - Internal ACPI interfaces
516 ++ * ACPI_INTERNAL_VAR_XFACE - Internal variable-parameter list interfaces
517 ++ */
518 ++#define ACPI_SYSTEM_XFACE
519 ++#define ACPI_EXTERNAL_XFACE
520 ++#define ACPI_INTERNAL_XFACE
521 ++#define ACPI_INTERNAL_VAR_XFACE
522 ++
523 ++/* remark 981 - operands evaluated in no particular order */
524 ++#pragma warning(disable:981)
525 ++
526 ++/* warn C4100: unreferenced formal parameter */
527 ++#pragma warning(disable:4100)
528 ++
529 ++/* warn C4127: conditional expression is constant */
530 ++#pragma warning(disable:4127)
531 ++
532 ++/* warn C4706: assignment within conditional expression */
533 ++#pragma warning(disable:4706)
534 ++
535 ++/* warn C4214: bit field types other than int */
536 ++#pragma warning(disable:4214)
537 ++
538 ++#endif /* __ACINTEL_H__ */
539 +diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
540 +index 2052011bf9fb..6c70444da3b9 100644
541 +--- a/include/linux/ptr_ring.h
542 ++++ b/include/linux/ptr_ring.h
543 +@@ -111,6 +111,11 @@ static inline int __ptr_ring_produce(struct ptr_ring *r, void *ptr)
544 + return 0;
545 + }
546 +
547 ++/*
548 ++ * Note: resize (below) nests producer lock within consumer lock, so if you
549 ++ * consume in interrupt or BH context, you must disable interrupts/BH when
550 ++ * calling this.
551 ++ */
552 + static inline int ptr_ring_produce(struct ptr_ring *r, void *ptr)
553 + {
554 + int ret;
555 +@@ -242,6 +247,11 @@ static inline void *__ptr_ring_consume(struct ptr_ring *r)
556 + return ptr;
557 + }
558 +
559 ++/*
560 ++ * Note: resize (below) nests producer lock within consumer lock, so if you
561 ++ * call this in interrupt or BH context, you must disable interrupts/BH when
562 ++ * producing.
563 ++ */
564 + static inline void *ptr_ring_consume(struct ptr_ring *r)
565 + {
566 + void *ptr;
567 +@@ -357,7 +367,7 @@ static inline void **__ptr_ring_swap_queue(struct ptr_ring *r, void **queue,
568 + void **old;
569 + void *ptr;
570 +
571 +- while ((ptr = ptr_ring_consume(r)))
572 ++ while ((ptr = __ptr_ring_consume(r)))
573 + if (producer < size)
574 + queue[producer++] = ptr;
575 + else if (destroy)
576 +@@ -372,6 +382,12 @@ static inline void **__ptr_ring_swap_queue(struct ptr_ring *r, void **queue,
577 + return old;
578 + }
579 +
580 ++/*
581 ++ * Note: producer lock is nested within consumer lock, so if you
582 ++ * resize you must make sure all uses nest correctly.
583 ++ * In particular if you consume ring in interrupt or BH context, you must
584 ++ * disable interrupts/BH when doing so.
585 ++ */
586 + static inline int ptr_ring_resize(struct ptr_ring *r, int size, gfp_t gfp,
587 + void (*destroy)(void *))
588 + {
589 +@@ -382,17 +398,25 @@ static inline int ptr_ring_resize(struct ptr_ring *r, int size, gfp_t gfp,
590 + if (!queue)
591 + return -ENOMEM;
592 +
593 +- spin_lock_irqsave(&(r)->producer_lock, flags);
594 ++ spin_lock_irqsave(&(r)->consumer_lock, flags);
595 ++ spin_lock(&(r)->producer_lock);
596 +
597 + old = __ptr_ring_swap_queue(r, queue, size, gfp, destroy);
598 +
599 +- spin_unlock_irqrestore(&(r)->producer_lock, flags);
600 ++ spin_unlock(&(r)->producer_lock);
601 ++ spin_unlock_irqrestore(&(r)->consumer_lock, flags);
602 +
603 + kfree(old);
604 +
605 + return 0;
606 + }
607 +
608 ++/*
609 ++ * Note: producer lock is nested within consumer lock, so if you
610 ++ * resize you must make sure all uses nest correctly.
611 ++ * In particular if you consume ring in interrupt or BH context, you must
612 ++ * disable interrupts/BH when doing so.
613 ++ */
614 + static inline int ptr_ring_resize_multiple(struct ptr_ring **rings, int nrings,
615 + int size,
616 + gfp_t gfp, void (*destroy)(void *))
617 +@@ -412,10 +436,12 @@ static inline int ptr_ring_resize_multiple(struct ptr_ring **rings, int nrings,
618 + }
619 +
620 + for (i = 0; i < nrings; ++i) {
621 +- spin_lock_irqsave(&(rings[i])->producer_lock, flags);
622 ++ spin_lock_irqsave(&(rings[i])->consumer_lock, flags);
623 ++ spin_lock(&(rings[i])->producer_lock);
624 + queues[i] = __ptr_ring_swap_queue(rings[i], queues[i],
625 + size, gfp, destroy);
626 +- spin_unlock_irqrestore(&(rings[i])->producer_lock, flags);
627 ++ spin_unlock(&(rings[i])->producer_lock);
628 ++ spin_unlock_irqrestore(&(rings[i])->consumer_lock, flags);
629 + }
630 +
631 + for (i = 0; i < nrings; ++i)
632 +diff --git a/mm/backing-dev.c b/mm/backing-dev.c
633 +index 8fde443f36d7..6ff2d7744223 100644
634 +--- a/mm/backing-dev.c
635 ++++ b/mm/backing-dev.c
636 +@@ -757,15 +757,20 @@ static int cgwb_bdi_init(struct backing_dev_info *bdi)
637 + if (!bdi->wb_congested)
638 + return -ENOMEM;
639 +
640 ++ atomic_set(&bdi->wb_congested->refcnt, 1);
641 ++
642 + err = wb_init(&bdi->wb, bdi, 1, GFP_KERNEL);
643 + if (err) {
644 +- kfree(bdi->wb_congested);
645 ++ wb_congested_put(bdi->wb_congested);
646 + return err;
647 + }
648 + return 0;
649 + }
650 +
651 +-static void cgwb_bdi_destroy(struct backing_dev_info *bdi) { }
652 ++static void cgwb_bdi_destroy(struct backing_dev_info *bdi)
653 ++{
654 ++ wb_congested_put(bdi->wb_congested);
655 ++}
656 +
657 + #endif /* CONFIG_CGROUP_WRITEBACK */
658 +
659 +diff --git a/net/core/neighbour.c b/net/core/neighbour.c
660 +index 2ae929f9bd06..9901e5b75a05 100644
661 +--- a/net/core/neighbour.c
662 ++++ b/net/core/neighbour.c
663 +@@ -2927,7 +2927,8 @@ static void neigh_proc_update(struct ctl_table *ctl, int write)
664 + return;
665 +
666 + set_bit(index, p->data_state);
667 +- call_netevent_notifiers(NETEVENT_DELAY_PROBE_TIME_UPDATE, p);
668 ++ if (index == NEIGH_VAR_DELAY_PROBE_TIME)
669 ++ call_netevent_notifiers(NETEVENT_DELAY_PROBE_TIME_UPDATE, p);
670 + if (!dev) /* NULL dev means this is default value */
671 + neigh_copy_dflt_parms(net, p, index);
672 + }
673 +diff --git a/net/dccp/input.c b/net/dccp/input.c
674 +index ba347184bda9..8fedc2d49770 100644
675 +--- a/net/dccp/input.c
676 ++++ b/net/dccp/input.c
677 +@@ -606,7 +606,8 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
678 + if (inet_csk(sk)->icsk_af_ops->conn_request(sk,
679 + skb) < 0)
680 + return 1;
681 +- goto discard;
682 ++ consume_skb(skb);
683 ++ return 0;
684 + }
685 + if (dh->dccph_type == DCCP_PKT_RESET)
686 + goto discard;
687 +diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
688 +index 65336f38a5d8..9826695ddfc6 100644
689 +--- a/net/ipv4/ip_sockglue.c
690 ++++ b/net/ipv4/ip_sockglue.c
691 +@@ -105,10 +105,10 @@ static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb,
692 + if (skb->ip_summed != CHECKSUM_COMPLETE)
693 + return;
694 +
695 +- if (offset != 0)
696 +- csum = csum_sub(csum,
697 +- csum_partial(skb_transport_header(skb) + tlen,
698 +- offset, 0));
699 ++ if (offset != 0) {
700 ++ int tend_off = skb_transport_offset(skb) + tlen;
701 ++ csum = csum_sub(csum, skb_checksum(skb, tend_off, offset, 0));
702 ++ }
703 +
704 + put_cmsg(msg, SOL_IP, IP_CHECKSUM, sizeof(__wsum), &csum);
705 + }
706 +diff --git a/net/irda/irqueue.c b/net/irda/irqueue.c
707 +index acbe61c7e683..160dc89335e2 100644
708 +--- a/net/irda/irqueue.c
709 ++++ b/net/irda/irqueue.c
710 +@@ -383,9 +383,6 @@ EXPORT_SYMBOL(hashbin_new);
711 + * for deallocating this structure if it's complex. If not the user can
712 + * just supply kfree, which should take care of the job.
713 + */
714 +-#ifdef CONFIG_LOCKDEP
715 +-static int hashbin_lock_depth = 0;
716 +-#endif
717 + int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
718 + {
719 + irda_queue_t* queue;
720 +@@ -396,22 +393,27 @@ int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
721 + IRDA_ASSERT(hashbin->magic == HB_MAGIC, return -1;);
722 +
723 + /* Synchronize */
724 +- if ( hashbin->hb_type & HB_LOCK ) {
725 +- spin_lock_irqsave_nested(&hashbin->hb_spinlock, flags,
726 +- hashbin_lock_depth++);
727 +- }
728 ++ if (hashbin->hb_type & HB_LOCK)
729 ++ spin_lock_irqsave(&hashbin->hb_spinlock, flags);
730 +
731 + /*
732 + * Free the entries in the hashbin, TODO: use hashbin_clear when
733 + * it has been shown to work
734 + */
735 + for (i = 0; i < HASHBIN_SIZE; i ++ ) {
736 +- queue = dequeue_first((irda_queue_t**) &hashbin->hb_queue[i]);
737 +- while (queue ) {
738 +- if (free_func)
739 +- (*free_func)(queue);
740 +- queue = dequeue_first(
741 +- (irda_queue_t**) &hashbin->hb_queue[i]);
742 ++ while (1) {
743 ++ queue = dequeue_first((irda_queue_t**) &hashbin->hb_queue[i]);
744 ++
745 ++ if (!queue)
746 ++ break;
747 ++
748 ++ if (free_func) {
749 ++ if (hashbin->hb_type & HB_LOCK)
750 ++ spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
751 ++ free_func(queue);
752 ++ if (hashbin->hb_type & HB_LOCK)
753 ++ spin_lock_irqsave(&hashbin->hb_spinlock, flags);
754 ++ }
755 + }
756 + }
757 +
758 +@@ -420,12 +422,8 @@ int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
759 + hashbin->magic = ~HB_MAGIC;
760 +
761 + /* Release lock */
762 +- if ( hashbin->hb_type & HB_LOCK) {
763 ++ if (hashbin->hb_type & HB_LOCK)
764 + spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
765 +-#ifdef CONFIG_LOCKDEP
766 +- hashbin_lock_depth--;
767 +-#endif
768 +- }
769 +
770 + /*
771 + * Free the hashbin structure
772 +diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c
773 +index 7e08a4d3d77d..a646f3481240 100644
774 +--- a/net/kcm/kcmsock.c
775 ++++ b/net/kcm/kcmsock.c
776 +@@ -929,23 +929,25 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
777 + goto out_error;
778 + }
779 +
780 +- /* New message, alloc head skb */
781 +- head = alloc_skb(0, sk->sk_allocation);
782 +- while (!head) {
783 +- kcm_push(kcm);
784 +- err = sk_stream_wait_memory(sk, &timeo);
785 +- if (err)
786 +- goto out_error;
787 +-
788 ++ if (msg_data_left(msg)) {
789 ++ /* New message, alloc head skb */
790 + head = alloc_skb(0, sk->sk_allocation);
791 +- }
792 ++ while (!head) {
793 ++ kcm_push(kcm);
794 ++ err = sk_stream_wait_memory(sk, &timeo);
795 ++ if (err)
796 ++ goto out_error;
797 +
798 +- skb = head;
799 ++ head = alloc_skb(0, sk->sk_allocation);
800 ++ }
801 +
802 +- /* Set ip_summed to CHECKSUM_UNNECESSARY to avoid calling
803 +- * csum_and_copy_from_iter from skb_do_copy_data_nocache.
804 +- */
805 +- skb->ip_summed = CHECKSUM_UNNECESSARY;
806 ++ skb = head;
807 ++
808 ++ /* Set ip_summed to CHECKSUM_UNNECESSARY to avoid calling
809 ++ * csum_and_copy_from_iter from skb_do_copy_data_nocache.
810 ++ */
811 ++ skb->ip_summed = CHECKSUM_UNNECESSARY;
812 ++ }
813 +
814 + start:
815 + while (msg_data_left(msg)) {
816 +@@ -1018,10 +1020,12 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
817 + if (eor) {
818 + bool not_busy = skb_queue_empty(&sk->sk_write_queue);
819 +
820 +- /* Message complete, queue it on send buffer */
821 +- __skb_queue_tail(&sk->sk_write_queue, head);
822 +- kcm->seq_skb = NULL;
823 +- KCM_STATS_INCR(kcm->stats.tx_msgs);
824 ++ if (head) {
825 ++ /* Message complete, queue it on send buffer */
826 ++ __skb_queue_tail(&sk->sk_write_queue, head);
827 ++ kcm->seq_skb = NULL;
828 ++ KCM_STATS_INCR(kcm->stats.tx_msgs);
829 ++ }
830 +
831 + if (msg->msg_flags & MSG_BATCH) {
832 + kcm->tx_wait_more = true;
833 +@@ -1040,8 +1044,10 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
834 + } else {
835 + /* Message not complete, save state */
836 + partial_message:
837 +- kcm->seq_skb = head;
838 +- kcm_tx_msg(head)->last_skb = skb;
839 ++ if (head) {
840 ++ kcm->seq_skb = head;
841 ++ kcm_tx_msg(head)->last_skb = skb;
842 ++ }
843 + }
844 +
845 + KCM_STATS_ADD(kcm->stats.tx_bytes, copied);
846 +diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
847 +index 3e821daf9dd4..8bc5a1bd2d45 100644
848 +--- a/net/llc/llc_conn.c
849 ++++ b/net/llc/llc_conn.c
850 +@@ -821,7 +821,10 @@ void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb)
851 + * another trick required to cope with how the PROCOM state
852 + * machine works. -acme
853 + */
854 ++ skb_orphan(skb);
855 ++ sock_hold(sk);
856 + skb->sk = sk;
857 ++ skb->destructor = sock_efree;
858 + }
859 + if (!sock_owned_by_user(sk))
860 + llc_conn_rcv(sk, skb);
861 +diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c
862 +index d0e1e804ebd7..5404d0d195cc 100644
863 +--- a/net/llc/llc_sap.c
864 ++++ b/net/llc/llc_sap.c
865 +@@ -290,7 +290,10 @@ static void llc_sap_rcv(struct llc_sap *sap, struct sk_buff *skb,
866 +
867 + ev->type = LLC_SAP_EV_TYPE_PDU;
868 + ev->reason = 0;
869 ++ skb_orphan(skb);
870 ++ sock_hold(sk);
871 + skb->sk = sk;
872 ++ skb->destructor = sock_efree;
873 + llc_sap_state_process(sap, skb);
874 + }
875 +
876 +diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
877 +index 7341adf7059d..6dc44d9b4190 100644
878 +--- a/net/netfilter/nf_conntrack_helper.c
879 ++++ b/net/netfilter/nf_conntrack_helper.c
880 +@@ -188,6 +188,26 @@ nf_ct_helper_ext_add(struct nf_conn *ct,
881 + }
882 + EXPORT_SYMBOL_GPL(nf_ct_helper_ext_add);
883 +
884 ++static struct nf_conntrack_helper *
885 ++nf_ct_lookup_helper(struct nf_conn *ct, struct net *net)
886 ++{
887 ++ if (!net->ct.sysctl_auto_assign_helper) {
888 ++ if (net->ct.auto_assign_helper_warned)
889 ++ return NULL;
890 ++ if (!__nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple))
891 ++ return NULL;
892 ++ pr_info("nf_conntrack: default automatic helper assignment "
893 ++ "has been turned off for security reasons and CT-based "
894 ++ " firewall rule not found. Use the iptables CT target "
895 ++ "to attach helpers instead.\n");
896 ++ net->ct.auto_assign_helper_warned = 1;
897 ++ return NULL;
898 ++ }
899 ++
900 ++ return __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
901 ++}
902 ++
903 ++
904 + int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
905 + gfp_t flags)
906 + {
907 +@@ -213,21 +233,14 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
908 + }
909 +
910 + help = nfct_help(ct);
911 +- if (net->ct.sysctl_auto_assign_helper && helper == NULL) {
912 +- helper = __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
913 +- if (unlikely(!net->ct.auto_assign_helper_warned && helper)) {
914 +- pr_info("nf_conntrack: automatic helper "
915 +- "assignment is deprecated and it will "
916 +- "be removed soon. Use the iptables CT target "
917 +- "to attach helpers instead.\n");
918 +- net->ct.auto_assign_helper_warned = true;
919 +- }
920 +- }
921 +
922 + if (helper == NULL) {
923 +- if (help)
924 +- RCU_INIT_POINTER(help->helper, NULL);
925 +- return 0;
926 ++ helper = nf_ct_lookup_helper(ct, net);
927 ++ if (helper == NULL) {
928 ++ if (help)
929 ++ RCU_INIT_POINTER(help->helper, NULL);
930 ++ return 0;
931 ++ }
932 + }
933 +
934 + if (help == NULL) {
935 +diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
936 +index 458722b938c7..34de326b4f09 100644
937 +--- a/net/packet/af_packet.c
938 ++++ b/net/packet/af_packet.c
939 +@@ -1497,6 +1497,8 @@ static void __fanout_link(struct sock *sk, struct packet_sock *po)
940 + f->arr[f->num_members] = sk;
941 + smp_wmb();
942 + f->num_members++;
943 ++ if (f->num_members == 1)
944 ++ dev_add_pack(&f->prot_hook);
945 + spin_unlock(&f->lock);
946 + }
947 +
948 +@@ -1513,6 +1515,8 @@ static void __fanout_unlink(struct sock *sk, struct packet_sock *po)
949 + BUG_ON(i >= f->num_members);
950 + f->arr[i] = f->arr[f->num_members - 1];
951 + f->num_members--;
952 ++ if (f->num_members == 0)
953 ++ __dev_remove_pack(&f->prot_hook);
954 + spin_unlock(&f->lock);
955 + }
956 +
957 +@@ -1619,6 +1623,7 @@ static void fanout_release_data(struct packet_fanout *f)
958 +
959 + static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
960 + {
961 ++ struct packet_rollover *rollover = NULL;
962 + struct packet_sock *po = pkt_sk(sk);
963 + struct packet_fanout *f, *match;
964 + u8 type = type_flags & 0xff;
965 +@@ -1641,23 +1646,28 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
966 + return -EINVAL;
967 + }
968 +
969 ++ mutex_lock(&fanout_mutex);
970 ++
971 ++ err = -EINVAL;
972 + if (!po->running)
973 +- return -EINVAL;
974 ++ goto out;
975 +
976 ++ err = -EALREADY;
977 + if (po->fanout)
978 +- return -EALREADY;
979 ++ goto out;
980 +
981 + if (type == PACKET_FANOUT_ROLLOVER ||
982 + (type_flags & PACKET_FANOUT_FLAG_ROLLOVER)) {
983 +- po->rollover = kzalloc(sizeof(*po->rollover), GFP_KERNEL);
984 +- if (!po->rollover)
985 +- return -ENOMEM;
986 +- atomic_long_set(&po->rollover->num, 0);
987 +- atomic_long_set(&po->rollover->num_huge, 0);
988 +- atomic_long_set(&po->rollover->num_failed, 0);
989 ++ err = -ENOMEM;
990 ++ rollover = kzalloc(sizeof(*rollover), GFP_KERNEL);
991 ++ if (!rollover)
992 ++ goto out;
993 ++ atomic_long_set(&rollover->num, 0);
994 ++ atomic_long_set(&rollover->num_huge, 0);
995 ++ atomic_long_set(&rollover->num_failed, 0);
996 ++ po->rollover = rollover;
997 + }
998 +
999 +- mutex_lock(&fanout_mutex);
1000 + match = NULL;
1001 + list_for_each_entry(f, &fanout_list, list) {
1002 + if (f->id == id &&
1003 +@@ -1687,7 +1697,6 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
1004 + match->prot_hook.func = packet_rcv_fanout;
1005 + match->prot_hook.af_packet_priv = match;
1006 + match->prot_hook.id_match = match_fanout_group;
1007 +- dev_add_pack(&match->prot_hook);
1008 + list_add(&match->list, &fanout_list);
1009 + }
1010 + err = -EINVAL;
1011 +@@ -1704,36 +1713,40 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
1012 + }
1013 + }
1014 + out:
1015 +- mutex_unlock(&fanout_mutex);
1016 +- if (err) {
1017 +- kfree(po->rollover);
1018 ++ if (err && rollover) {
1019 ++ kfree(rollover);
1020 + po->rollover = NULL;
1021 + }
1022 ++ mutex_unlock(&fanout_mutex);
1023 + return err;
1024 + }
1025 +
1026 +-static void fanout_release(struct sock *sk)
1027 ++/* If pkt_sk(sk)->fanout->sk_ref is zero, this function removes
1028 ++ * pkt_sk(sk)->fanout from fanout_list and returns pkt_sk(sk)->fanout.
1029 ++ * It is the responsibility of the caller to call fanout_release_data() and
1030 ++ * free the returned packet_fanout (after synchronize_net())
1031 ++ */
1032 ++static struct packet_fanout *fanout_release(struct sock *sk)
1033 + {
1034 + struct packet_sock *po = pkt_sk(sk);
1035 + struct packet_fanout *f;
1036 +
1037 ++ mutex_lock(&fanout_mutex);
1038 + f = po->fanout;
1039 +- if (!f)
1040 +- return;
1041 ++ if (f) {
1042 ++ po->fanout = NULL;
1043 +
1044 +- mutex_lock(&fanout_mutex);
1045 +- po->fanout = NULL;
1046 ++ if (atomic_dec_and_test(&f->sk_ref))
1047 ++ list_del(&f->list);
1048 ++ else
1049 ++ f = NULL;
1050 +
1051 +- if (atomic_dec_and_test(&f->sk_ref)) {
1052 +- list_del(&f->list);
1053 +- dev_remove_pack(&f->prot_hook);
1054 +- fanout_release_data(f);
1055 +- kfree(f);
1056 ++ if (po->rollover)
1057 ++ kfree_rcu(po->rollover, rcu);
1058 + }
1059 + mutex_unlock(&fanout_mutex);
1060 +
1061 +- if (po->rollover)
1062 +- kfree_rcu(po->rollover, rcu);
1063 ++ return f;
1064 + }
1065 +
1066 + static bool packet_extra_vlan_len_allowed(const struct net_device *dev,
1067 +@@ -2965,6 +2978,7 @@ static int packet_release(struct socket *sock)
1068 + {
1069 + struct sock *sk = sock->sk;
1070 + struct packet_sock *po;
1071 ++ struct packet_fanout *f;
1072 + struct net *net;
1073 + union tpacket_req_u req_u;
1074 +
1075 +@@ -3004,9 +3018,14 @@ static int packet_release(struct socket *sock)
1076 + packet_set_ring(sk, &req_u, 1, 1);
1077 + }
1078 +
1079 +- fanout_release(sk);
1080 ++ f = fanout_release(sk);
1081 +
1082 + synchronize_net();
1083 ++
1084 ++ if (f) {
1085 ++ fanout_release_data(f);
1086 ++ kfree(f);
1087 ++ }
1088 + /*
1089 + * Now the socket is dead. No more input will appear.
1090 + */
1091 +@@ -3958,7 +3977,6 @@ static int packet_notifier(struct notifier_block *this,
1092 + }
1093 + if (msg == NETDEV_UNREGISTER) {
1094 + packet_cached_dev_reset(po);
1095 +- fanout_release(sk);
1096 + po->ifindex = -1;
1097 + if (po->prot_hook.dev)
1098 + dev_put(po->prot_hook.dev);
1099 +diff --git a/net/socket.c b/net/socket.c
1100 +index 73dc69f9681e..6bbccf05854f 100644
1101 +--- a/net/socket.c
1102 ++++ b/net/socket.c
1103 +@@ -2197,8 +2197,10 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
1104 + return err;
1105 +
1106 + err = sock_error(sock->sk);
1107 +- if (err)
1108 ++ if (err) {
1109 ++ datagrams = err;
1110 + goto out_put;
1111 ++ }
1112 +
1113 + entry = mmsg;
1114 + compat_entry = (struct compat_mmsghdr __user *)mmsg;