[PATCH 4.4 210/241] tty: max310x: Fix external crystal register setup

2019-06-09 Thread Greg Kroah-Hartman
From: Joe Burmeister 

commit 5d24f455c182d5116dd5db8e1dc501115ecc9c2c upstream.

The datasheet states:

  Bit 4: ClockEnSet the ClockEn bit high to enable an external clocking
(crystal or clock generator at XIN). Set the ClockEn bit to 0 to disable
clocking
  Bit 1: CrystalEnSet the CrystalEn bit high to enable the crystal
oscillator. When using an external clock source at XIN, CrystalEn must
be set low.

The bit 4, MAX310X_CLKSRC_EXTCLK_BIT, should be set and was not.

This was required to make the MAX3107 with an external crystal on our
board able to send or receive data.

Signed-off-by: Joe Burmeister 
Cc: stable 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/tty/serial/max310x.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -571,7 +571,7 @@ static int max310x_set_ref_clk(struct ma
}
 
/* Configure clock source */
-   clksrc = xtal ? MAX310X_CLKSRC_CRYST_BIT : MAX310X_CLKSRC_EXTCLK_BIT;
+   clksrc = MAX310X_CLKSRC_EXTCLK_BIT | (xtal ? MAX310X_CLKSRC_CRYST_BIT : 
0);
 
/* Configure PLL */
if (pllcfg) {




[PATCH 4.4 225/241] Revert "x86/build: Move _etext to actual end of .text"

2019-06-09 Thread Greg Kroah-Hartman
From: Greg Kroah-Hartman 

This reverts commit 392bef709659abea614abfe53cf228e7a59876a4.

It seems to cause lots of problems when using the gold linker, and no
one really needs this at the moment, so just revert it from the stable
trees.

Cc: Sami Tolvanen 
Reported-by: Kees Cook 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Reported-by: Alec Ari 
Cc: Ingo Molnar 
Signed-off-by: Greg Kroah-Hartman 
---
 arch/x86/kernel/vmlinux.lds.S |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -110,10 +110,10 @@ SECTIONS
*(.text.__x86.indirect_thunk)
__indirect_thunk_end = .;
 #endif
-   } :text = 0x9090
 
-   /* End of text section */
-   _etext = .;
+   /* End of text section */
+   _etext = .;
+   } :text = 0x9090
 
NOTES :text :note
 




[PATCH 5.1 43/70] nvme-rdma: fix queue mapping when queue count is limited

2019-06-09 Thread Greg Kroah-Hartman
From: Sagi Grimberg 

commit 5651cd3c43368873d0787b52acb2e0e08f3c5da4 upstream.

When the controller supports less queues than requested, we
should make sure that queue mapping does the right thing and
not assume that all queues are available. This fixes a crash
when the controller supports less queues than requested.

The rules are:
1. if no write/poll queues are requested, we assign the available queues
   to the default queue map. The default and read queue maps share the
   existing queues.
2. if write queues are requested:
  - first make sure that read queue map gets the requested
nr_io_queues count
  - then grant the default queue map the minimum between the requested
nr_write_queues and the remaining queues. If there are no available
queues to dedicate to the default queue map, fallback to (1) and
share all the queues in the existing queue map.
3. if poll queues are requested:
  - map the remaining queues to the poll queue map.

Also, provide a log indication on how we constructed the different
queue maps.

Reported-by: Harris, James R 
Reviewed-by: Max Gurtovoy 
Tested-by: Jim Harris 
Cc:  # v5.0+
Signed-off-by: Sagi Grimberg 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/nvme/host/rdma.c |   99 ---
 1 file changed, 61 insertions(+), 38 deletions(-)

--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -641,34 +641,16 @@ static int nvme_rdma_alloc_io_queues(str
 {
struct nvmf_ctrl_options *opts = ctrl->ctrl.opts;
struct ib_device *ibdev = ctrl->device->dev;
-   unsigned int nr_io_queues;
+   unsigned int nr_io_queues, nr_default_queues;
+   unsigned int nr_read_queues, nr_poll_queues;
int i, ret;
 
-   nr_io_queues = min(opts->nr_io_queues, num_online_cpus());
-
-   /*
-* we map queues according to the device irq vectors for
-* optimal locality so we don't need more queues than
-* completion vectors.
-*/
-   nr_io_queues = min_t(unsigned int, nr_io_queues,
-   ibdev->num_comp_vectors);
-
-   if (opts->nr_write_queues) {
-   ctrl->io_queues[HCTX_TYPE_DEFAULT] =
-   min(opts->nr_write_queues, nr_io_queues);
-   nr_io_queues += ctrl->io_queues[HCTX_TYPE_DEFAULT];
-   } else {
-   ctrl->io_queues[HCTX_TYPE_DEFAULT] = nr_io_queues;
-   }
-
-   ctrl->io_queues[HCTX_TYPE_READ] = nr_io_queues;
-
-   if (opts->nr_poll_queues) {
-   ctrl->io_queues[HCTX_TYPE_POLL] =
-   min(opts->nr_poll_queues, num_online_cpus());
-   nr_io_queues += ctrl->io_queues[HCTX_TYPE_POLL];
-   }
+   nr_read_queues = min_t(unsigned int, ibdev->num_comp_vectors,
+   min(opts->nr_io_queues, num_online_cpus()));
+   nr_default_queues =  min_t(unsigned int, ibdev->num_comp_vectors,
+   min(opts->nr_write_queues, num_online_cpus()));
+   nr_poll_queues = min(opts->nr_poll_queues, num_online_cpus());
+   nr_io_queues = nr_read_queues + nr_default_queues + nr_poll_queues;
 
ret = nvme_set_queue_count(>ctrl, _io_queues);
if (ret)
@@ -681,6 +663,34 @@ static int nvme_rdma_alloc_io_queues(str
dev_info(ctrl->ctrl.device,
"creating %d I/O queues.\n", nr_io_queues);
 
+   if (opts->nr_write_queues && nr_read_queues < nr_io_queues) {
+   /*
+* separate read/write queues
+* hand out dedicated default queues only after we have
+* sufficient read queues.
+*/
+   ctrl->io_queues[HCTX_TYPE_READ] = nr_read_queues;
+   nr_io_queues -= ctrl->io_queues[HCTX_TYPE_READ];
+   ctrl->io_queues[HCTX_TYPE_DEFAULT] =
+   min(nr_default_queues, nr_io_queues);
+   nr_io_queues -= ctrl->io_queues[HCTX_TYPE_DEFAULT];
+   } else {
+   /*
+* shared read/write queues
+* either no write queues were requested, or we don't have
+* sufficient queue count to have dedicated default queues.
+*/
+   ctrl->io_queues[HCTX_TYPE_DEFAULT] =
+   min(nr_read_queues, nr_io_queues);
+   nr_io_queues -= ctrl->io_queues[HCTX_TYPE_DEFAULT];
+   }
+
+   if (opts->nr_poll_queues && nr_io_queues) {
+   /* map dedicated poll queues only if we have queues left */
+   ctrl->io_queues[HCTX_TYPE_POLL] =
+   min(nr_poll_queues, nr_io_queues);
+   }
+
for (i = 1; i < ctrl->ctrl.queue_count; i++) {
ret = nvme_rdma_alloc_queue(ctrl, i,
ctrl->ctrl.sqsize + 1);
@@ -1787,17 +1797,24 @@ static void nvme_rdma_complete_rq(struct
 static int nvme_rdma_map_queues(struct blk_mq_tag_set *set)
 {
struct 

[PATCH 4.4 222/241] brcmfmac: add length checks in scheduled scan result handler

2019-06-09 Thread Greg Kroah-Hartman
From: Arend Van Spriel 

commit 4835f37e3bafc138f8bfa3cbed2920dd56fed283 upstream.

Assure the event data buffer is long enough to hold the array
of netinfo items and that SSID length does not exceed the maximum
of 32 characters as per 802.11 spec.

Reviewed-by: Hante Meuleman 
Reviewed-by: Pieter-Paul Giesberts 
Reviewed-by: Franky Lin 
Signed-off-by: Arend van Spriel 
Signed-off-by: Kalle Valo 
[bwh: Backported to 4.4:
 - Move the assignment to "data" along with the assignment to "netinfo_start"
   that depends on it
 - Adjust filename, context, indentation]
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c |   14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

--- a/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
@@ -3328,6 +3328,7 @@ brcmf_notify_sched_scan_results(struct b
struct brcmf_pno_scanresults_le *pfn_result;
u32 result_count;
u32 status;
+   u32 datalen;
 
brcmf_dbg(SCAN, "Enter\n");
 
@@ -3354,6 +3355,14 @@ brcmf_notify_sched_scan_results(struct b
if (result_count > 0) {
int i;
 
+   data += sizeof(struct brcmf_pno_scanresults_le);
+   netinfo_start = (struct brcmf_pno_net_info_le *)data;
+   datalen = e->datalen - ((void *)netinfo_start - (void 
*)pfn_result);
+   if (datalen < result_count * sizeof(*netinfo)) {
+   brcmf_err("insufficient event data\n");
+   goto out_err;
+   }
+
request = kzalloc(sizeof(*request), GFP_KERNEL);
ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
@@ -3363,9 +3372,6 @@ brcmf_notify_sched_scan_results(struct b
}
 
request->wiphy = wiphy;
-   data += sizeof(struct brcmf_pno_scanresults_le);
-   netinfo_start = (struct brcmf_pno_net_info_le *)data;
-
for (i = 0; i < result_count; i++) {
netinfo = _start[i];
if (!netinfo) {
@@ -3375,6 +3381,8 @@ brcmf_notify_sched_scan_results(struct b
goto out_err;
}
 
+   if (netinfo->SSID_len > IEEE80211_MAX_SSID_LEN)
+   netinfo->SSID_len = IEEE80211_MAX_SSID_LEN;
brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
  netinfo->SSID, netinfo->channel);
memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);




[PATCH 4.4 121/241] media: ov2659: make S_FMT succeed even if requested format doesnt match

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit bccb89cf9cd07a0690d519696a00c00a973b3fe4 ]

This driver returns an error if unsupported media bus pixel code is
requested by VIDIOC_SUBDEV_S_FMT.

But according to Documentation/media/uapi/v4l/vidioc-subdev-g-fmt.rst,

Drivers must not return an error solely because the requested format
doesn't match the device capabilities. They must instead modify the
format to match what the hardware can provide.

So select default format code and return success in that case.

This is detected by v4l2-compliance.

Cc: "Lad, Prabhakar" 
Signed-off-by: Akinobu Mita 
Acked-by: Lad, Prabhakar 
Signed-off-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Sasha Levin 
---
 drivers/media/i2c/ov2659.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov2659.c b/drivers/media/i2c/ov2659.c
index 49109f4f5bb4a..fadec1d705829 100644
--- a/drivers/media/i2c/ov2659.c
+++ b/drivers/media/i2c/ov2659.c
@@ -1117,8 +1117,10 @@ static int ov2659_set_fmt(struct v4l2_subdev *sd,
if (ov2659_formats[index].code == mf->code)
break;
 
-   if (index < 0)
-   return -EINVAL;
+   if (index < 0) {
+   index = 0;
+   mf->code = ov2659_formats[index].code;
+   }
 
mf->colorspace = V4L2_COLORSPACE_SRGB;
mf->code = ov2659_formats[index].code;
-- 
2.20.1





[PATCH 4.4 194/241] xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()

2019-06-09 Thread Greg Kroah-Hartman
From: Andrey Smirnov 

commit f7fac17ca925faa03fc5eb854c081a24075f8bad upstream.

Xhci_handshake() implements the algorithm already captured by
readl_poll_timeout_atomic(). Convert the former to use the latter to
avoid repetition.

Turned out this patch also fixes a bug on the AMD Stoneyridge platform
where usleep(1) sometimes takes over 10ms.
This means a 5 second timeout can easily take over 15 seconds which will
trigger the watchdog and reboot the system.

[Add info about patch fixing a bug to commit message -Mathias]
Signed-off-by: Andrey Smirnov 
Tested-by: Raul E Rangel 
Reviewed-by: Raul E Rangel 
Cc: 
Signed-off-by: Mathias Nyman 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/host/xhci.c |   22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -21,6 +21,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -46,7 +47,6 @@ static unsigned int quirks;
 module_param(quirks, uint, S_IRUGO);
 MODULE_PARM_DESC(quirks, "Bit flags for quirks to be enabled as default");
 
-/* TODO: copied from ehci-hcd.c - can this be refactored? */
 /*
  * xhci_handshake - spin reading hc until handshake completes or fails
  * @ptr: address of hc register to be read
@@ -63,18 +63,16 @@ MODULE_PARM_DESC(quirks, "Bit flags for
 int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec)
 {
u32 result;
+   int ret;
 
-   do {
-   result = readl(ptr);
-   if (result == ~(u32)0)  /* card removed */
-   return -ENODEV;
-   result &= mask;
-   if (result == done)
-   return 0;
-   udelay(1);
-   usec--;
-   } while (usec > 0);
-   return -ETIMEDOUT;
+   ret = readl_poll_timeout_atomic(ptr, result,
+   (result & mask) == done ||
+   result == U32_MAX,
+   1, usec);
+   if (result == U32_MAX)  /* card removed */
+   return -ENODEV;
+
+   return ret;
 }
 
 /*




[PATCH 4.4 187/241] net: mvpp2: fix bad MVPP2_TXQ_SCHED_TOKEN_CNTR_REG queue value

2019-06-09 Thread Greg Kroah-Hartman
From: Antoine Tenart 

[ Upstream commit 21808437214637952b61beaba6034d97880fbeb3 ]

MVPP2_TXQ_SCHED_TOKEN_CNTR_REG() expects the logical queue id but
the current code is passing the global tx queue offset, so it ends
up writing to unknown registers (between 0x8280 and 0x82fc, which
seemed to be unused by the hardware). This fixes the issue by using
the logical queue id instead.

Fixes: 3f518509dedc ("ethernet: Add new driver for Marvell Armada 375 network 
unit")
Signed-off-by: Antoine Tenart 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/marvell/mvpp2.c |   10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -3940,7 +3940,7 @@ static inline void mvpp2_gmac_max_rx_siz
 /* Set defaults to the MVPP2 port */
 static void mvpp2_defaults_set(struct mvpp2_port *port)
 {
-   int tx_port_num, val, queue, ptxq, lrxq;
+   int tx_port_num, val, queue, lrxq;
 
/* Configure port to loopback if needed */
if (port->flags & MVPP2_F_LOOPBACK)
@@ -3960,11 +3960,9 @@ static void mvpp2_defaults_set(struct mv
mvpp2_write(port->priv, MVPP2_TXP_SCHED_CMD_1_REG, 0);
 
/* Close bandwidth for all queues */
-   for (queue = 0; queue < MVPP2_MAX_TXQ; queue++) {
-   ptxq = mvpp2_txq_phys(port->id, queue);
+   for (queue = 0; queue < MVPP2_MAX_TXQ; queue++)
mvpp2_write(port->priv,
-   MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(ptxq), 0);
-   }
+   MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(queue), 0);
 
/* Set refill period to 1 usec, refill tokens
 * and bucket size to maximum
@@ -4722,7 +4720,7 @@ static void mvpp2_txq_deinit(struct mvpp
txq->descs_phys= 0;
 
/* Set minimum bandwidth for disabled TXQs */
-   mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq->id), 0);
+   mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq->log_id), 0);
 
/* Set Tx descriptors queue starting address and size */
mvpp2_write(port->priv, MVPP2_TXQ_NUM_REG, txq->id);




[PATCH 4.4 200/241] USB: rio500: fix memory leak in close after disconnect

2019-06-09 Thread Greg Kroah-Hartman
From: Oliver Neukum 

commit e0feb73428b69322dd5caae90b0207de369b5575 upstream.

If a disconnected device is closed, rio_close() must free
the buffers.

Signed-off-by: Oliver Neukum 
Cc: stable 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/misc/rio500.c |   17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -103,9 +103,22 @@ static int close_rio(struct inode *inode
 {
struct rio_usb_data *rio = _instance;
 
-   rio->isopen = 0;
+   /* against disconnect() */
+   mutex_lock(_mutex);
+   mutex_lock(&(rio->lock));
 
-   dev_info(>rio_dev->dev, "Rio closed.\n");
+   rio->isopen = 0;
+   if (!rio->present) {
+   /* cleanup has been delayed */
+   kfree(rio->ibuf);
+   kfree(rio->obuf);
+   rio->ibuf = NULL;
+   rio->obuf = NULL;
+   } else {
+   dev_info(>rio_dev->dev, "Rio closed.\n");
+   }
+   mutex_unlock(&(rio->lock));
+   mutex_unlock(_mutex);
return 0;
 }
 




[PATCH 4.4 206/241] Btrfs: fix race updating log root item during fsync

2019-06-09 Thread Greg Kroah-Hartman
From: Filipe Manana 

commit 06989c799f04810f6876900d4760c0edda369cf7 upstream.

When syncing the log, the final phase of a fsync operation, we need to
either create a log root's item or update the existing item in the log
tree of log roots, and that depends on the current value of the log
root's log_transid - if it's 1 we need to create the log root item,
otherwise it must exist already and we update it. Since there is no
synchronization between updating the log_transid and checking it for
deciding whether the log root's item needs to be created or updated, we
end up with a tiny race window that results in attempts to update the
item to fail because the item was not yet created:

  CPU 1CPU 2

  btrfs_sync_log()

lock root->log_mutex

set log root's log_transid to 1

unlock root->log_mutex

   btrfs_sync_log()

 lock root->log_mutex

 sets log root's
 log_transid to 2

 unlock root->log_mutex

update_log_root()

  sees log root's log_transid
  with a value of 2

calls btrfs_update_root(),
which fails with -EUCLEAN
and causes transaction abort

Until recently the race lead to a BUG_ON at btrfs_update_root(), but after
the recent commit 7ac1e464c4d47 ("btrfs: Don't panic when we can't find a
root key") we just abort the current transaction.

A sample trace of the BUG_ON() on a SLE12 kernel:

  [ cut here ]
  kernel BUG at ../fs/btrfs/root-tree.c:157!
  Oops: Exception in kernel mode, sig: 5 [#1]
  SMP NR_CPUS=2048 NUMA pSeries
  (...)
  Supported: Yes, External
  CPU: 78 PID: 76303 Comm: rtas_errd Tainted: G X 
4.4.156-94.57-default #1
  task: c0ffa906d010 ti: c0ff42b08000 task.ti: c0ff42b08000
  NIP: d00036ae5cdc LR: d00036ae5cd8 CTR: 
  REGS: c0ff42b0b860 TRAP: 0700   Tainted: G X  
(4.4.156-94.57-default)
  MSR: 82029033   CR: 2284  XER: 2000
  CFAR: d00036aba66c SOFTE: 1
  GPR00: d00036ae5cd8 c0ff42b0bae0 d00036bda220 0054
  GPR04: 0001  c78d37c8 
  GPR08: c0e19c00   3736343438312079
  GPR12: 3930373337303434 c7a3a800 007f 0023
  GPR16: c0ffa9d26028 c0ffa9d261f8 0010 c0ffa9d2ab28
  GPR20: c0ff42b0bc48 0001 c0ff9f0d9888 0001
  GPR24: c0ffa9d26000 c0ffa9d261e8 c0ffa9d2a800 c0ff9f0d9888
  GPR28: c0ffa9d26028 c0ffa9d2aa98 0001 c0ffa98f5b20
  NIP [d00036ae5cdc] btrfs_update_root+0x25c/0x4e0 [btrfs]
  LR [d00036ae5cd8] btrfs_update_root+0x258/0x4e0 [btrfs]
  Call Trace:
  [c0ff42b0bae0] [d00036ae5cd8] btrfs_update_root+0x258/0x4e0 [btrfs] 
(unreliable)
  [c0ff42b0bba0] [d00036b53610] btrfs_sync_log+0x2d0/0xc60 [btrfs]
  [c0ff42b0bce0] [d00036b1785c] btrfs_sync_file+0x44c/0x4e0 [btrfs]
  [c0ff42b0bd80] [c032e300] vfs_fsync_range+0x70/0x120
  [c0ff42b0bdd0] [c032e44c] do_fsync+0x5c/0xb0
  [c0ff42b0be10] [c032e8dc] SyS_fdatasync+0x2c/0x40
  [c0ff42b0be30] [c0009488] system_call+0x3c/0x100
  Instruction dump:
  7f43d378 4bffebb9 6000 88d90008 3d22 e8b9 3b390009 e87a01f0
  e8898e08 e8f9 4bfd48e5 6000 <0fe0> e95b0060 3924 394a0ea0
  ---[ end trace 8f2dc8f919cabab8 ]---

So fix this by doing the check of log_transid and updating or creating the
log root's item while holding the root's log_mutex.

Fixes: 7237f1833601d ("Btrfs: fix tree logs parallel sync")
CC: sta...@vger.kernel.org # 4.4+
Signed-off-by: Filipe Manana 
Signed-off-by: David Sterba 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/btrfs/tree-log.c |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2809,6 +2809,12 @@ int btrfs_sync_log(struct btrfs_trans_ha
log->log_transid = root->log_transid;
root->log_start_pid = 0;
/*
+* Update or create log root item under the root's log_mutex to prevent
+* races with concurrent log syncs that can lead to failure to update
+* log root item because it was not created yet.
+*/
+   ret = update_log_root(trans, log);
+   /*
 * IO has been started, blocks of the log tree have WRITTEN flag set
 * in their headers. new modifications of the log will be written to
 * new positions. so it's safe to allow log writers to go in.
@@ -2827,8 +2833,6 @@ int btrfs_sync_log(struct btrfs_trans_ha
 
mutex_unlock(_root_tree->log_mutex);
 
-   ret = update_log_root(trans, log);
-

[PATCH 4.4 203/241] media: smsusb: better handle optional alignment

2019-06-09 Thread Greg Kroah-Hartman
From: Mauro Carvalho Chehab 

commit a47686636d84eaec5c9c6e84bd5f96bed34d526d upstream.

Most Siano devices require an alignment for the response.

Changeset f3be52b0056a ("media: usb: siano: Fix general protection fault in 
smsusb")
changed the logic with gets such aligment, but it now produces a
sparce warning:

drivers/media/usb/siano/smsusb.c: In function 'smsusb_init_device':
drivers/media/usb/siano/smsusb.c:447:37: warning: 'in_maxp' may be used 
uninitialized in this function [-Wmaybe-uninitialized]
  447 |   dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
  | ^~~~

The sparse message itself is bogus, but a broken (or fake) USB
eeprom could produce a negative value for response_alignment.

So, change the code in order to check if the result is not
negative.

Fixes: 31e0456de5be ("media: usb: siano: Fix general protection fault in 
smsusb")
CC: 
Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/media/usb/siano/smsusb.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/drivers/media/usb/siano/smsusb.c
+++ b/drivers/media/usb/siano/smsusb.c
@@ -391,7 +391,7 @@ static int smsusb_init_device(struct usb
struct smsusb_device_t *dev;
void *mdev;
int i, rc;
-   int in_maxp = 0;
+   int align = 0;
 
/* create device object */
dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);
@@ -409,14 +409,14 @@ static int smsusb_init_device(struct usb
 
if (desc->bEndpointAddress & USB_DIR_IN) {
dev->in_ep = desc->bEndpointAddress;
-   in_maxp = usb_endpoint_maxp(desc);
+   align = usb_endpoint_maxp(desc) - sizeof(struct 
sms_msg_hdr);
} else {
dev->out_ep = desc->bEndpointAddress;
}
}
 
pr_debug("in_ep = %02x, out_ep = %02x\n", dev->in_ep, dev->out_ep);
-   if (!dev->in_ep || !dev->out_ep) {  /* Missing endpoints? */
+   if (!dev->in_ep || !dev->out_ep || align < 0) {  /* Missing endpoints? 
*/
smsusb_term_device(intf);
return -ENODEV;
}
@@ -435,7 +435,7 @@ static int smsusb_init_device(struct usb
/* fall-thru */
default:
dev->buffer_size = USB2_BUFFER_SIZE;
-   dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
+   dev->response_alignment = align;
 
params.flags |= SMS_DEVICE_FAMILY2;
break;




[PATCH 4.4 193/241] include/linux/bitops.h: sanitize rotate primitives

2019-06-09 Thread Greg Kroah-Hartman
From: Rasmus Villemoes 

commit ef4d6f6b275c498f8e5626c99dbeefdc5027f843 upstream.

The ror32 implementation (word >> shift) | (word << (32 - shift) has
undefined behaviour if shift is outside the [1, 31] range.  Similarly
for the 64 bit variants.  Most callers pass a compile-time constant
(naturally in that range), but there's an UBSAN report that these may
actually be called with a shift count of 0.

Instead of special-casing that, we can make them DTRT for all values of
shift while also avoiding UB.  For some reason, this was already partly
done for rol32 (which was well-defined for [0, 31]).  gcc 8 recognizes
these patterns as rotates, so for example

  __u32 rol32(__u32 word, unsigned int shift)
  {
return (word << (shift & 31)) | (word >> ((-shift) & 31));
  }

compiles to

0020 :
  20:   89 f8   mov%edi,%eax
  22:   89 f1   mov%esi,%ecx
  24:   d3 c0   rol%cl,%eax
  26:   c3  retq

Older compilers unfortunately do not do as well, but this only affects
the small minority of users that don't pass constants.

Due to integer promotions, ro[lr]8 were already well-defined for shifts
in [0, 8], and ro[lr]16 were mostly well-defined for shifts in [0, 16]
(only mostly - u16 gets promoted to _signed_ int, so if bit 15 is set,
word << 16 is undefined).  For consistency, update those as well.

Link: http://lkml.kernel.org/r/20190410211906.2190-1-li...@rasmusvillemoes.dk
Signed-off-by: Rasmus Villemoes 
Reported-by: Ido Schimmel 
Tested-by: Ido Schimmel 
Reviewed-by: Will Deacon 
Cc: Vadim Pasternak 
Cc: Andrey Ryabinin 
Cc: Jacek Anaszewski 
Cc: Pavel Machek 
Signed-off-by: Andrew Morton 
Signed-off-by: Linus Torvalds 
Signed-off-by: Matthias Kaehlcke 
Signed-off-by: Greg Kroah-Hartman 

---
 include/linux/bitops.h |   16 
 1 file changed, 8 insertions(+), 8 deletions(-)

--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -68,7 +68,7 @@ static __always_inline unsigned long hwe
  */
 static inline __u64 rol64(__u64 word, unsigned int shift)
 {
-   return (word << shift) | (word >> (64 - shift));
+   return (word << (shift & 63)) | (word >> ((-shift) & 63));
 }
 
 /**
@@ -78,7 +78,7 @@ static inline __u64 rol64(__u64 word, un
  */
 static inline __u64 ror64(__u64 word, unsigned int shift)
 {
-   return (word >> shift) | (word << (64 - shift));
+   return (word >> (shift & 63)) | (word << ((-shift) & 63));
 }
 
 /**
@@ -88,7 +88,7 @@ static inline __u64 ror64(__u64 word, un
  */
 static inline __u32 rol32(__u32 word, unsigned int shift)
 {
-   return (word << shift) | (word >> ((-shift) & 31));
+   return (word << (shift & 31)) | (word >> ((-shift) & 31));
 }
 
 /**
@@ -98,7 +98,7 @@ static inline __u32 rol32(__u32 word, un
  */
 static inline __u32 ror32(__u32 word, unsigned int shift)
 {
-   return (word >> shift) | (word << (32 - shift));
+   return (word >> (shift & 31)) | (word << ((-shift) & 31));
 }
 
 /**
@@ -108,7 +108,7 @@ static inline __u32 ror32(__u32 word, un
  */
 static inline __u16 rol16(__u16 word, unsigned int shift)
 {
-   return (word << shift) | (word >> (16 - shift));
+   return (word << (shift & 15)) | (word >> ((-shift) & 15));
 }
 
 /**
@@ -118,7 +118,7 @@ static inline __u16 rol16(__u16 word, un
  */
 static inline __u16 ror16(__u16 word, unsigned int shift)
 {
-   return (word >> shift) | (word << (16 - shift));
+   return (word >> (shift & 15)) | (word << ((-shift) & 15));
 }
 
 /**
@@ -128,7 +128,7 @@ static inline __u16 ror16(__u16 word, un
  */
 static inline __u8 rol8(__u8 word, unsigned int shift)
 {
-   return (word << shift) | (word >> (8 - shift));
+   return (word << (shift & 7)) | (word >> ((-shift) & 7));
 }
 
 /**
@@ -138,7 +138,7 @@ static inline __u8 rol8(__u8 word, unsig
  */
 static inline __u8 ror8(__u8 word, unsigned int shift)
 {
-   return (word >> shift) | (word << (8 - shift));
+   return (word >> (shift & 7)) | (word << ((-shift) & 7));
 }
 
 /**




[PATCH 4.4 212/241] kernel/signal.c: trace_signal_deliver when signal_group_exit

2019-06-09 Thread Greg Kroah-Hartman
From: Zhenliang Wei 

commit 98af37d624ed8c83f1953b1b6b2f6866011fc064 upstream.

In the fixes commit, removing SIGKILL from each thread signal mask and
executing "goto fatal" directly will skip the call to
"trace_signal_deliver".  At this point, the delivery tracking of the
SIGKILL signal will be inaccurate.

Therefore, we need to add trace_signal_deliver before "goto fatal" after
executing sigdelset.

Note: SEND_SIG_NOINFO matches the fact that SIGKILL doesn't have any info.

Link: http://lkml.kernel.org/r/20190425025812.91424-1-weizhenli...@huawei.com
Fixes: cf43a757fd4944 ("signal: Restore the stop PTRACE_EVENT_EXIT")
Signed-off-by: Zhenliang Wei 
Reviewed-by: Christian Brauner 
Reviewed-by: Oleg Nesterov 
Cc: Eric W. Biederman 
Cc: Ivan Delalande 
Cc: Arnd Bergmann 
Cc: Thomas Gleixner 
Cc: Deepa Dinamani 
Cc: Greg Kroah-Hartman 
Cc: 
Signed-off-by: Andrew Morton 
Signed-off-by: Linus Torvalds 
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/signal.c |2 ++
 1 file changed, 2 insertions(+)

--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2244,6 +2244,8 @@ relock:
if (signal_group_exit(signal)) {
ksig->info.si_signo = signr = SIGKILL;
sigdelset(>pending.signal, SIGKILL);
+   trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
+   >action[SIGKILL - 1]);
recalc_sigpending();
goto fatal;
}




[PATCH 4.4 216/241] net: create skb_gso_validate_mac_len()

2019-06-09 Thread Greg Kroah-Hartman
From: Daniel Axtens 

commit 2b16f048729bf35e6c28a40cbfad07239f9dcd90 upstream.

If you take a GSO skb, and split it into packets, will the MAC
length (L2 + L3 + L4 headers + payload) of those packets be small
enough to fit within a given length?

Move skb_gso_mac_seglen() to skbuff.h with other related functions
like skb_gso_network_seglen() so we can use it, and then create
skb_gso_validate_mac_len to do the full calculation.

Signed-off-by: Daniel Axtens 
Signed-off-by: David S. Miller 
[bwh: Backported to 4.4: There is no GSO_BY_FRAGS case to handle, so
 skb_gso_validate_mac_len() becomes a trivial comparison. Put it inline in
 .]
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 include/linux/skbuff.h |   30 ++
 net/sched/sch_tbf.c|   10 --
 2 files changed, 30 insertions(+), 10 deletions(-)

--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3664,5 +3664,35 @@ static inline unsigned int skb_gso_netwo
return hdr_len + skb_gso_transport_seglen(skb);
 }
 
+/**
+ * skb_gso_mac_seglen - Return length of individual segments of a gso packet
+ *
+ * @skb: GSO skb
+ *
+ * skb_gso_mac_seglen is used to determine the real size of the
+ * individual segments, including MAC/L2, Layer3 (IP, IPv6) and L4
+ * headers (TCP/UDP).
+ */
+static inline unsigned int skb_gso_mac_seglen(const struct sk_buff *skb)
+{
+   unsigned int hdr_len = skb_transport_header(skb) - skb_mac_header(skb);
+   return hdr_len + skb_gso_transport_seglen(skb);
+}
+
+/**
+ * skb_gso_validate_mac_len - Will a split GSO skb fit in a given length?
+ *
+ * @skb: GSO skb
+ * @len: length to validate against
+ *
+ * skb_gso_validate_mac_len validates if a given skb will fit a wanted
+ * length once split, including L2, L3 and L4 headers and the payload.
+ */
+static inline bool
+skb_gso_validate_mac_len(const struct sk_buff *skb, unsigned int len)
+{
+   return skb_gso_mac_seglen(skb) <= len;
+}
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SKBUFF_H */
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -142,16 +142,6 @@ static u64 psched_ns_t2l(const struct ps
return len;
 }
 
-/*
- * Return length of individual segments of a gso packet,
- * including all headers (MAC, IP, TCP/UDP)
- */
-static unsigned int skb_gso_mac_seglen(const struct sk_buff *skb)
-{
-   unsigned int hdr_len = skb_transport_header(skb) - skb_mac_header(skb);
-   return hdr_len + skb_gso_transport_seglen(skb);
-}
-
 /* GSO packet is too big, segment it so that tbf can transmit
  * each segment in time
  */




[PATCH 4.9 61/83] media: uvcvideo: Fix uvc_alloc_entity() allocation alignment

2019-06-09 Thread Greg Kroah-Hartman
From: Nadav Amit 

commit 89dd34caf73e28018c58cd193751e41b1f8bdc56 upstream.

The use of ALIGN() in uvc_alloc_entity() is incorrect, since the size of
(entity->pads) is not a power of two. As a stop-gap, until a better
solution is adapted, use roundup() instead.

Found by a static assertion. Compile-tested only.

Fixes: 4ffc2d89f38a ("uvcvideo: Register subdevices for each entity")

Signed-off-by: Nadav Amit 
Signed-off-by: Laurent Pinchart 
Signed-off-by: Mauro Carvalho Chehab 
Cc: Doug Anderson 
Cc: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/media/usb/uvc/uvc_driver.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -868,7 +868,7 @@ static struct uvc_entity *uvc_alloc_enti
unsigned int size;
unsigned int i;
 
-   extra_size = ALIGN(extra_size, sizeof(*entity->pads));
+   extra_size = roundup(extra_size, sizeof(*entity->pads));
num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
 + num_inputs;




[PATCH 4.4 227/241] usb: gadget: fix request length error for isoc transfer

2019-06-09 Thread Greg Kroah-Hartman
From: Peter Chen 

commit 982555fc26f9d8bcdbd5f9db0378fe0682eb4188 upstream.

For isoc endpoint descriptor, the wMaxPacketSize is not real max packet
size (see Table 9-13. Standard Endpoint Descriptor, USB 2.0 specifcation),
it may contain the number of packet, so the real max packet should be
ep->desc->wMaxPacketSize && 0x7ff.

Cc: Felipe F. Tonello 
Cc: Felipe Balbi 
Fixes: 16b114a6d797 ("usb: gadget: fix usb_ep_align_maybe
  endianness and new usb_ep_aligna")

Signed-off-by: Peter Chen 
Signed-off-by: Felipe Balbi 
Signed-off-by: Nobuhiro Iwamatsu 
Signed-off-by: Greg Kroah-Hartman 

---
 include/linux/usb/gadget.h |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -671,7 +671,9 @@ static inline struct usb_gadget *dev_to_
  */
 static inline size_t usb_ep_align(struct usb_ep *ep, size_t len)
 {
-   return round_up(len, (size_t)le16_to_cpu(ep->desc->wMaxPacketSize));
+   int max_packet_size = (size_t)usb_endpoint_maxp(ep->desc) & 0x7ff;
+
+   return round_up(len, max_packet_size);
 }
 
 /**




[PATCH 4.4 235/241] parisc: Use implicit space register selection for loading the coherence index of I/O pdirs

2019-06-09 Thread Greg Kroah-Hartman
From: John David Anglin 

commit 63923d2c3800919774f5c651d503d1dd2adaddd5 upstream.

We only support I/O to kernel space. Using %sr1 to load the coherence
index may be racy unless interrupts are disabled. This patch changes the
code used to load the coherence index to use implicit space register
selection. This saves one instruction and eliminates the race.

Tested on rp3440, c8000 and c3750.

Signed-off-by: John David Anglin 
Cc: sta...@vger.kernel.org
Signed-off-by: Helge Deller 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/parisc/ccio-dma.c  |4 +---
 drivers/parisc/sba_iommu.c |3 +--
 2 files changed, 2 insertions(+), 5 deletions(-)

--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -563,8 +563,6 @@ ccio_io_pdir_entry(u64 *pdir_ptr, space_
/* We currently only support kernel addresses */
BUG_ON(sid != KERNEL_SPACE);
 
-   mtsp(sid,1);
-
/*
** WORD 1 - low order word
** "hints" parm includes the VALID bit!
@@ -595,7 +593,7 @@ ccio_io_pdir_entry(u64 *pdir_ptr, space_
** Grab virtual index [0:11]
** Deposit virt_idx bits into I/O PDIR word
*/
-   asm volatile ("lci %%r0(%%sr1, %1), %0" : "=r" (ci) : "r" (vba));
+   asm volatile ("lci %%r0(%1), %0" : "=r" (ci) : "r" (vba));
asm volatile ("extru %1,19,12,%0" : "+r" (ci) : "r" (ci));
asm volatile ("depw  %1,15,12,%0" : "+r" (pa) : "r" (ci));
 
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -573,8 +573,7 @@ sba_io_pdir_entry(u64 *pdir_ptr, space_t
pa = virt_to_phys(vba);
pa &= IOVP_MASK;
 
-   mtsp(sid,1);
-   asm("lci 0(%%sr1, %1), %0" : "=r" (ci) : "r" (vba));
+   asm("lci 0(%1), %0" : "=r" (ci) : "r" (vba));
pa |= (ci >> PAGE_SHIFT) & 0xff;  /* move CI (8 bits) into lowest byte 
*/
 
pa |= SBA_PDIR_VALID_BIT;   /* set "valid" bit */




[PATCH 4.4 229/241] ethtool: fix potential userspace buffer overflow

2019-06-09 Thread Greg Kroah-Hartman
From: Vivien Didelot 

[ Upstream commit 0ee4e76937d69128a6a66861ba393ebdc2ffc8a2 ]

ethtool_get_regs() allocates a buffer of size ops->get_regs_len(),
and pass it to the kernel driver via ops->get_regs() for filling.

There is no restriction about what the kernel drivers can or cannot do
with the open ethtool_regs structure. They usually set regs->version
and ignore regs->len or set it to the same size as ops->get_regs_len().

But if userspace allocates a smaller buffer for the registers dump,
we would cause a userspace buffer overflow in the final copy_to_user()
call, which uses the regs.len value potentially reset by the driver.

To fix this, make this case obvious and store regs.len before calling
ops->get_regs(), to only copy as much data as requested by userspace,
up to the value returned by ops->get_regs_len().

While at it, remove the redundant check for non-null regbuf.

Signed-off-by: Vivien Didelot 
Reviewed-by: Michal Kubecek 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 net/core/ethtool.c |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -893,13 +893,16 @@ static int ethtool_get_regs(struct net_d
return -ENOMEM;
}
 
+   if (regs.len < reglen)
+   reglen = regs.len;
+
ops->get_regs(dev, , regbuf);
 
ret = -EFAULT;
if (copy_to_user(useraddr, , sizeof(regs)))
goto out;
useraddr += offsetof(struct ethtool_regs, data);
-   if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
+   if (copy_to_user(useraddr, regbuf, reglen))
goto out;
ret = 0;
 




[PATCH 4.4 211/241] memcg: make it work on sparse non-0-node systems

2019-06-09 Thread Greg Kroah-Hartman
From: Jiri Slaby 

commit 3e8589963773a5c23e2f1fe4bcad0e9a90b7f471 upstream.

We have a single node system with node 0 disabled:
  Scanning NUMA topology in Northbridge 24
  Number of physical nodes 2
  Skipping disabled node 0
  Node 1 MemBase  Limit fbff
  NODE_DATA(1) allocated [mem 0xfbfda000-0xfbfe]

This causes crashes in memcg when system boots:
  BUG: unable to handle kernel NULL pointer dereference at 0008
  #PF error: [normal kernel read fault]
...
  RIP: 0010:list_lru_add+0x94/0x170
...
  Call Trace:
   d_lru_add+0x44/0x50
   dput.part.34+0xfc/0x110
   __fput+0x108/0x230
   task_work_run+0x9f/0xc0
   exit_to_usermode_loop+0xf5/0x100

It is reproducible as far as 4.12.  I did not try older kernels.  You have
to have a new enough systemd, e.g.  241 (the reason is unknown -- was not
investigated).  Cannot be reproduced with systemd 234.

The system crashes because the size of lru array is never updated in
memcg_update_all_list_lrus and the reads are past the zero-sized array,
causing dereferences of random memory.

The root cause are list_lru_memcg_aware checks in the list_lru code.  The
test in list_lru_memcg_aware is broken: it assumes node 0 is always
present, but it is not true on some systems as can be seen above.

So fix this by avoiding checks on node 0.  Remember the memcg-awareness by
a bool flag in struct list_lru.

Link: http://lkml.kernel.org/r/20190522091940.3615-1-jsl...@suse.cz
Fixes: 60d3fd32a7a9 ("list_lru: introduce per-memcg lists")
Signed-off-by: Jiri Slaby 
Acked-by: Michal Hocko 
Suggested-by: Vladimir Davydov 
Acked-by: Vladimir Davydov 
Reviewed-by: Shakeel Butt 
Cc: Johannes Weiner 
Cc: Raghavendra K T 
Cc: 
Signed-off-by: Andrew Morton 
Signed-off-by: Linus Torvalds 
Signed-off-by: Greg Kroah-Hartman 

---
 include/linux/list_lru.h |1 +
 mm/list_lru.c|8 +++-
 2 files changed, 4 insertions(+), 5 deletions(-)

--- a/include/linux/list_lru.h
+++ b/include/linux/list_lru.h
@@ -51,6 +51,7 @@ struct list_lru {
struct list_lru_node*node;
 #ifdef CONFIG_MEMCG_KMEM
struct list_headlist;
+   boolmemcg_aware;
 #endif
 };
 
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -42,11 +42,7 @@ static void list_lru_unregister(struct l
 #ifdef CONFIG_MEMCG_KMEM
 static inline bool list_lru_memcg_aware(struct list_lru *lru)
 {
-   /*
-* This needs node 0 to be always present, even
-* in the systems supporting sparse numa ids.
-*/
-   return !!lru->node[0].memcg_lrus;
+   return lru->memcg_aware;
 }
 
 static inline struct list_lru_one *
@@ -389,6 +385,8 @@ static int memcg_init_list_lru(struct li
 {
int i;
 
+   lru->memcg_aware = memcg_aware;
+
if (!memcg_aware)
return 0;
 




[PATCH 4.4 184/241] usbnet: fix kernel crash after disconnect

2019-06-09 Thread Greg Kroah-Hartman
From: Kloetzke Jan 

[ Upstream commit ad70411a978d1e6e97b1e341a7bde9a79af0c93d ]

When disconnecting cdc_ncm the kernel sporadically crashes shortly
after the disconnect:

  [   57.868812] Unable to handle kernel NULL pointer dereference at virtual 
address 
  ...
  [   58.006653] PC is at 0x0
  [   58.009202] LR is at call_timer_fn+0xec/0x1b4
  [   58.013567] pc : [<>] lr : [] pstate: 
0145
  [   58.020976] sp : ff8008003da0
  [   58.024295] x29: ff8008003da0 x28: 0001
  [   58.029618] x27: 000a x26: 0100
  [   58.034941] x25:  x24: ff8008003e68
  [   58.040263] x23:  x22: 
  [   58.045587] x21:  x20: ffc68fac1808
  [   58.050910] x19: 0100 x18: 
  [   58.056232] x17: 007f885aff8c x16: 007f883a9f10
  [   58.061556] x15: 0001 x14: 006e
  [   58.066878] x13:  x12: 00ba
  [   58.072201] x11: ffc69ff1db30 x10: 0020
  [   58.077524] x9 : 800018001000 x8 : 0001
  [   58.082847] x7 : 0800 x6 : ff8008003e70
  [   58.088169] x5 : ffc69ff17a28 x4 : 138b
  [   58.093492] x3 :  x2 : 
  [   58.098814] x1 :  x0 : 
  ...
  [   58.205800] [<  (null)>]   (null)
  [   58.210521] [] expire_timers+0xa0/0x14c
  [   58.215937] [] run_timer_softirq+0xe8/0x128
  [   58.221702] [] __do_softirq+0x298/0x348
  [   58.227118] [] irq_exit+0x74/0xbc
  [   58.232009] [] __handle_domain_irq+0x78/0xac
  [   58.237857] [] gic_handle_irq+0x80/0xac
  ...

The crash happens roughly 125..130ms after the disconnect. This
correlates with the 'delay' timer that is started on certain USB tx/rx
errors in the URB completion handler.

The problem is a race of usbnet_stop() with usbnet_start_xmit(). In
usbnet_stop() we call usbnet_terminate_urbs() to cancel all URBs in
flight. This only makes sense if no new URBs are submitted
concurrently, though. But the usbnet_start_xmit() can run at the same
time on another CPU which almost unconditionally submits an URB. The
error callback of the new URB will then schedule the timer after it was
already stopped.

The fix adds a check if the tx queue is stopped after the tx list lock
has been taken. This should reliably prevent the submission of new URBs
while usbnet_terminate_urbs() does its job. The same thing is done on
the rx side even though it might be safe due to other flags that are
checked there.

Signed-off-by: Jan Klötzke 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/usb/usbnet.c |6 ++
 1 file changed, 6 insertions(+)

--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -499,6 +499,7 @@ static int rx_submit (struct usbnet *dev
 
if (netif_running (dev->net) &&
netif_device_present (dev->net) &&
+   test_bit(EVENT_DEV_OPEN, >flags) &&
!test_bit (EVENT_RX_HALT, >flags) &&
!test_bit (EVENT_DEV_ASLEEP, >flags)) {
switch (retval = usb_submit_urb (urb, GFP_ATOMIC)) {
@@ -1385,6 +1386,11 @@ netdev_tx_t usbnet_start_xmit (struct sk
spin_unlock_irqrestore(>txq.lock, flags);
goto drop;
}
+   if (netif_queue_stopped(net)) {
+   usb_autopm_put_interface_async(dev->intf);
+   spin_unlock_irqrestore(>txq.lock, flags);
+   goto drop;
+   }
 
 #ifdef CONFIG_PM
/* if this triggers the device is still a sleep */




[PATCH 4.4 228/241] media: uvcvideo: Fix uvc_alloc_entity() allocation alignment

2019-06-09 Thread Greg Kroah-Hartman
From: Nadav Amit 

commit 89dd34caf73e28018c58cd193751e41b1f8bdc56 upstream.

The use of ALIGN() in uvc_alloc_entity() is incorrect, since the size of
(entity->pads) is not a power of two. As a stop-gap, until a better
solution is adapted, use roundup() instead.

Found by a static assertion. Compile-tested only.

Fixes: 4ffc2d89f38a ("uvcvideo: Register subdevices for each entity")

Signed-off-by: Nadav Amit 
Signed-off-by: Laurent Pinchart 
Signed-off-by: Mauro Carvalho Chehab 
Cc: Doug Anderson 
Cc: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/media/usb/uvc/uvc_driver.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -868,7 +868,7 @@ static struct uvc_entity *uvc_alloc_enti
unsigned int size;
unsigned int i;
 
-   extra_size = ALIGN(extra_size, sizeof(*entity->pads));
+   extra_size = roundup(extra_size, sizeof(*entity->pads));
num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
 + num_inputs;




[PATCH 4.4 231/241] net/mlx4_en: ethtool, Remove unsupported SFP EEPROM high pages query

2019-06-09 Thread Greg Kroah-Hartman
From: Erez Alfasi 

[ Upstream commit 135dd9594f127c8a82d141c3c8430e9e2143216a ]

Querying EEPROM high pages data for SFP module is currently
not supported by our driver but is still tried, resulting in
invalid FW queries.

Set the EEPROM ethtool data length to 256 for SFP module to
limit the reading for page 0 only and prevent invalid FW queries.

Fixes: 7202da8b7f71 ("ethtool, net/mlx4_en: Cable info, get_module_info/eeprom 
ethtool support")
Signed-off-by: Erez Alfasi 
Signed-off-by: Tariq Toukan 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/mellanox/mlx4/en_ethtool.c |4 +++-
 drivers/net/ethernet/mellanox/mlx4/port.c   |5 -
 2 files changed, 3 insertions(+), 6 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
@@ -1906,6 +1906,8 @@ static int mlx4_en_set_tunable(struct ne
return ret;
 }
 
+#define MLX4_EEPROM_PAGE_LEN 256
+
 static int mlx4_en_get_module_info(struct net_device *dev,
   struct ethtool_modinfo *modinfo)
 {
@@ -1940,7 +1942,7 @@ static int mlx4_en_get_module_info(struc
break;
case MLX4_MODULE_ID_SFP:
modinfo->type = ETH_MODULE_SFF_8472;
-   modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
+   modinfo->eeprom_len = MLX4_EEPROM_PAGE_LEN;
break;
default:
return -ENOSYS;
--- a/drivers/net/ethernet/mellanox/mlx4/port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/port.c
@@ -1398,11 +1398,6 @@ int mlx4_get_module_info(struct mlx4_dev
size -= offset + size - I2C_PAGE_SIZE;
 
i2c_addr = I2C_ADDR_LOW;
-   if (offset >= I2C_PAGE_SIZE) {
-   /* Reset offset to high page */
-   i2c_addr = I2C_ADDR_HIGH;
-   offset -= I2C_PAGE_SIZE;
-   }
 
cable_info = (struct mlx4_cable_info *)inmad->data;
cable_info->dev_mem_address = cpu_to_be16(offset);




[PATCH 4.4 237/241] MIPS: pistachio: Build uImage.gz by default

2019-06-09 Thread Greg Kroah-Hartman
From: Paul Burton 

commit e4f2d1af7163becb181419af9dece9206001e0a6 upstream.

The pistachio platform uses the U-Boot bootloader & generally boots a
kernel in the uImage format. As such it's useful to build one when
building the kernel, but to do so currently requires the user to
manually specify a uImage target on the make command line.

Make uImage.gz the pistachio platform's default build target, so that
the default is to build a kernel image that we can actually boot on a
board such as the MIPS Creator Ci40.

Marked for stable backport as far as v4.1 where pistachio support was
introduced. This is primarily useful for CI systems such as kernelci.org
which will benefit from us building a suitable image which can then be
booted as part of automated testing, extending our test coverage to the
affected stable branches.

Signed-off-by: Paul Burton 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Kevin Hilman 
Tested-by: Kevin Hilman 
URL: https://groups.io/g/kernelci/message/388
Cc: sta...@vger.kernel.org # v4.1+
Cc: linux-m...@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/pistachio/Platform |1 +
 1 file changed, 1 insertion(+)

--- a/arch/mips/pistachio/Platform
+++ b/arch/mips/pistachio/Platform
@@ -6,3 +6,4 @@ cflags-$(CONFIG_MACH_PISTACHIO) +=  
\
-I$(srctree)/arch/mips/include/asm/mach-pistachio
 load-$(CONFIG_MACH_PISTACHIO)  += 0x8040
 zload-$(CONFIG_MACH_PISTACHIO) += 0x8100
+all-$(CONFIG_MACH_PISTACHIO)   := uImage.gz




[PATCH 4.4 238/241] genwqe: Prevent an integer overflow in the ioctl

2019-06-09 Thread Greg Kroah-Hartman
From: Dan Carpenter 

commit 110080cea0d0e4dfdb0b536e7f8a5633ead6a781 upstream.

There are a couple potential integer overflows here.

round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);

The first thing is that the "m->size + (...)" addition could overflow,
and the second is that round_up() overflows to zero if the result is
within PAGE_SIZE of the type max.

In this code, the "m->size" variable is an u64 but we're saving the
result in "map_size" which is an unsigned long and genwqe_user_vmap()
takes an unsigned long as well.  So I have used ULONG_MAX as the upper
bound.  From a practical perspective unsigned long is fine/better than
trying to change all the types to u64.

Fixes: eaf4722d4645 ("GenWQE Character device and DDCB queue")
Signed-off-by: Dan Carpenter 
Cc: stable 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/misc/genwqe/card_dev.c   |2 ++
 drivers/misc/genwqe/card_utils.c |4 
 2 files changed, 6 insertions(+)

--- a/drivers/misc/genwqe/card_dev.c
+++ b/drivers/misc/genwqe/card_dev.c
@@ -782,6 +782,8 @@ static int genwqe_pin_mem(struct genwqe_
 
if ((m->addr == 0x0) || (m->size == 0))
return -EINVAL;
+   if (m->size > ULONG_MAX - PAGE_SIZE - (m->addr & ~PAGE_MASK))
+   return -EINVAL;
 
map_addr = (m->addr & PAGE_MASK);
map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);
--- a/drivers/misc/genwqe/card_utils.c
+++ b/drivers/misc/genwqe/card_utils.c
@@ -582,6 +582,10 @@ int genwqe_user_vmap(struct genwqe_dev *
/* determine space needed for page_list. */
data = (unsigned long)uaddr;
offs = offset_in_page(data);
+   if (size > ULONG_MAX - PAGE_SIZE - offs) {
+   m->size = 0;/* mark unused and not added */
+   return -EINVAL;
+   }
m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE);
 
m->page_list = kcalloc(m->nr_pages,




[PATCH 4.4 234/241] rcu: locking and unlocking need to always be at least barriers

2019-06-09 Thread Greg Kroah-Hartman
From: Linus Torvalds 

commit 66be4e66a7f422128748e3c3ef6ee72b20a6197b upstream.

Herbert Xu pointed out that commit bb73c52bad36 ("rcu: Don't disable
preemption for Tiny and Tree RCU readers") was incorrect in making the
preempt_disable/enable() be conditional on CONFIG_PREEMPT_COUNT.

If CONFIG_PREEMPT_COUNT isn't enabled, the preemption enable/disable is
a no-op, but still is a compiler barrier.

And RCU locking still _needs_ that compiler barrier.

It is simply fundamentally not true that RCU locking would be a complete
no-op: we still need to guarantee (for example) that things that can
trap and cause preemption cannot migrate into the RCU locked region.

The way we do that is by making it a barrier.

See for example commit 386afc91144b ("spinlocks and preemption points
need to be at least compiler barriers") from back in 2013 that had
similar issues with spinlocks that become no-ops on UP: they must still
constrain the compiler from moving other operations into the critical
region.

Now, it is true that a lot of RCU operations already use READ_ONCE() and
WRITE_ONCE() (which in practice likely would never be re-ordered wrt
anything remotely interesting), but it is also true that that is not
globally the case, and that it's not even necessarily always possible
(ie bitfields etc).

Reported-by: Herbert Xu 
Fixes: bb73c52bad36 ("rcu: Don't disable preemption for Tiny and Tree RCU 
readers")
Cc: sta...@kernel.org
Cc: Boqun Feng 
Cc: Paul E. McKenney 
Signed-off-by: Linus Torvalds 
Signed-off-by: Greg Kroah-Hartman 

---
 include/linux/rcupdate.h |6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -297,14 +297,12 @@ void synchronize_rcu(void);
 
 static inline void __rcu_read_lock(void)
 {
-   if (IS_ENABLED(CONFIG_PREEMPT_COUNT))
-   preempt_disable();
+   preempt_disable();
 }
 
 static inline void __rcu_read_unlock(void)
 {
-   if (IS_ENABLED(CONFIG_PREEMPT_COUNT))
-   preempt_enable();
+   preempt_enable();
 }
 
 static inline void synchronize_rcu(void)




[PATCH 4.4 232/241] net: rds: fix memory leak in rds_ib_flush_mr_pool

2019-06-09 Thread Greg Kroah-Hartman
From: Zhu Yanjun 

[ Upstream commit 85cb928787eab6a2f4ca9d2a798b6f3bed53ced1 ]

When the following tests last for several hours, the problem will occur.

Server:
rds-stress -r 1.1.1.16 -D 1M
Client:
rds-stress -r 1.1.1.14 -s 1.1.1.16 -D 1M -T 30

The following will occur.

"
Starting up
tsks   tx/s   rx/s  tx+rx K/smbi K/smbo K/s tx us/c   rtt us cpu
%
  1  0  0   0.00   0.00   0.000.00 0.00 -1.00
  1  0  0   0.00   0.00   0.000.00 0.00 -1.00
  1  0  0   0.00   0.00   0.000.00 0.00 -1.00
  1  0  0   0.00   0.00   0.000.00 0.00 -1.00
"
>From vmcore, we can find that clean_list is NULL.

>From the source code, rds_mr_flushd calls rds_ib_mr_pool_flush_worker.
Then rds_ib_mr_pool_flush_worker calls
"
 rds_ib_flush_mr_pool(pool, 0, NULL);
"
Then in function
"
int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
 int free_all, struct rds_ib_mr **ibmr_ret)
"
ibmr_ret is NULL.

In the source code,
"
...
list_to_llist_nodes(pool, _list, _nodes, _tail);
if (ibmr_ret)
*ibmr_ret = llist_entry(clean_nodes, struct rds_ib_mr, llnode);

/* more than one entry in llist nodes */
if (clean_nodes->next)
llist_add_batch(clean_nodes->next, clean_tail, >clean_list);
...
"
When ibmr_ret is NULL, llist_entry is not executed. clean_nodes->next
instead of clean_nodes is added in clean_list.
So clean_nodes is discarded. It can not be used again.
The workqueue is executed periodically. So more and more clean_nodes are
discarded. Finally the clean_list is NULL.
Then this problem will occur.

Fixes: 1bc144b62524 ("net, rds, Replace xlist in net/rds/xlist.h with llist")
Signed-off-by: Zhu Yanjun 
Acked-by: Santosh Shilimkar 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 net/rds/ib_rdma.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

--- a/net/rds/ib_rdma.c
+++ b/net/rds/ib_rdma.c
@@ -725,12 +725,14 @@ static int rds_ib_flush_mr_pool(struct r
wait_clean_list_grace();
 
list_to_llist_nodes(pool, _list, _nodes, 
_tail);
-   if (ibmr_ret)
+   if (ibmr_ret) {
*ibmr_ret = llist_entry(clean_nodes, struct rds_ib_mr, 
llnode);
-
+   clean_nodes = clean_nodes->next;
+   }
/* more than one entry in llist nodes */
-   if (clean_nodes->next)
-   llist_add_batch(clean_nodes->next, clean_tail, 
>clean_list);
+   if (clean_nodes)
+   llist_add_batch(clean_nodes, clean_tail,
+   >clean_list);
 
}
 




[PATCH 4.4 233/241] pktgen: do not sleep with the thread lock held.

2019-06-09 Thread Greg Kroah-Hartman
From: Paolo Abeni 

[ Upstream commit 720f1de4021f09898b8c8443f3b3e995991b6e3a ]

Currently, the process issuing a "start" command on the pktgen procfs
interface, acquires the pktgen thread lock and never release it, until
all pktgen threads are completed. The above can blocks indefinitely any
other pktgen command and any (even unrelated) netdevice removal - as
the pktgen netdev notifier acquires the same lock.

The issue is demonstrated by the following script, reported by Matteo:

ip -b - <<'EOF'
link add type dummy
link add type veth
link set dummy0 up
EOF
modprobe pktgen
echo reset >/proc/net/pktgen/pgctrl
{
echo rem_device_all
echo add_device dummy0
} >/proc/net/pktgen/kpktgend_0
echo count 0 >/proc/net/pktgen/dummy0
echo start >/proc/net/pktgen/pgctrl &
sleep 1
rmmod veth

Fix the above releasing the thread lock around the sleep call.

Additionally we must prevent racing with forcefull rmmod - as the
thread lock no more protects from them. Instead, acquire a self-reference
before waiting for any thread. As a side effect, running

rmmod pktgen

while some thread is running now fails with "module in use" error,
before this patch such command hanged indefinitely.

Note: the issue predates the commit reported in the fixes tag, but
this fix can't be applied before the mentioned commit.

v1 -> v2:
 - no need to check for thread existence after flipping the lock,
   pktgen threads are freed only at net exit time
 -

Fixes: 6146e6a43b35 ("[PKTGEN]: Removes thread_{un,}lock() macros.")
Reported-and-tested-by: Matteo Croce 
Signed-off-by: Paolo Abeni 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 net/core/pktgen.c |   11 +++
 1 file changed, 11 insertions(+)

--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3139,7 +3139,13 @@ static int pktgen_wait_thread_run(struct
 {
while (thread_is_running(t)) {
 
+   /* note: 't' will still be around even after the unlock/lock
+* cycle because pktgen_thread threads are only cleared at
+* net exit
+*/
+   mutex_unlock(_thread_lock);
msleep_interruptible(100);
+   mutex_lock(_thread_lock);
 
if (signal_pending(current))
goto signal;
@@ -3154,6 +3160,10 @@ static int pktgen_wait_all_threads_run(s
struct pktgen_thread *t;
int sig = 1;
 
+   /* prevent from racing with rmmod */
+   if (!try_module_get(THIS_MODULE))
+   return sig;
+
mutex_lock(_thread_lock);
 
list_for_each_entry(t, >pktgen_threads, th_list) {
@@ -3167,6 +3177,7 @@ static int pktgen_wait_all_threads_run(s
t->control |= (T_STOP);
 
mutex_unlock(_thread_lock);
+   module_put(THIS_MODULE);
return sig;
 }
 




[PATCH 4.4 236/241] fuse: fallocate: fix return with locked inode

2019-06-09 Thread Greg Kroah-Hartman
From: Miklos Szeredi 

commit 35d6fcbb7c3e296a52136347346a698a35af3fda upstream.

Do the proper cleanup in case the size check fails.

Tested with xfstests:generic/228

Reported-by: kbuild test robot 
Reported-by: Dan Carpenter 
Fixes: 0cbade024ba5 ("fuse: honor RLIMIT_FSIZE in fuse_file_fallocate")
Cc: Liu Bo 
Cc:  # v3.5
Signed-off-by: Miklos Szeredi 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/fuse/file.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2951,7 +2951,7 @@ static long fuse_file_fallocate(struct f
offset + length > i_size_read(inode)) {
err = inode_newsize_ok(inode, offset + length);
if (err)
-   return err;
+   goto out;
}
 
if (!(mode & FALLOC_FL_KEEP_SIZE))




[PATCH 4.4 240/241] fs: stream_open - opener for stream-like files so that read and write can run simultaneously without deadlock

2019-06-09 Thread Greg Kroah-Hartman
From: Kirill Smelkov 

commit 10dce8af34226d90fa56746a934f8da5dcdba3df upstream.

Commit 9c225f2655e3 ("vfs: atomic f_pos accesses as per POSIX") added
locking for file.f_pos access and in particular made concurrent read and
write not possible - now both those functions take f_pos lock for the
whole run, and so if e.g. a read is blocked waiting for data, write will
deadlock waiting for that read to complete.

This caused regression for stream-like files where previously read and
write could run simultaneously, but after that patch could not do so
anymore. See e.g. commit 581d21a2d02a ("xenbus: fix deadlock on writes
to /proc/xen/xenbus") which fixes such regression for particular case of
/proc/xen/xenbus.

The patch that added f_pos lock in 2014 did so to guarantee POSIX thread
safety for read/write/lseek and added the locking to file descriptors of
all regular files. In 2014 that thread-safety problem was not new as it
was already discussed earlier in 2006.

However even though 2006'th version of Linus's patch was adding f_pos
locking "only for files that are marked seekable with FMODE_LSEEK (thus
avoiding the stream-like objects like pipes and sockets)", the 2014
version - the one that actually made it into the tree as 9c225f2655e3 -
is doing so irregardless of whether a file is seekable or not.

See

https://lore.kernel.org/lkml/53022db1.4070...@gmail.com/
https://lwn.net/Articles/180387
https://lwn.net/Articles/180396

for historic context.

The reason that it did so is, probably, that there are many files that
are marked non-seekable, but e.g. their read implementation actually
depends on knowing current position to correctly handle the read. Some
examples:

kernel/power/user.c snapshot_read
fs/debugfs/file.c   u32_array_read
fs/fuse/control.c   fuse_conn_waiting_read + ...
drivers/hwmon/asus_atk0110.catk_debugfs_ggrp_read
arch/s390/hypfs/inode.c hypfs_read_iter
...

Despite that, many nonseekable_open users implement read and write with
pure stream semantics - they don't depend on passed ppos at all. And for
those cases where read could wait for something inside, it creates a
situation similar to xenbus - the write could be never made to go until
read is done, and read is waiting for some, potentially external, event,
for potentially unbounded time -> deadlock.

Besides xenbus, there are 14 such places in the kernel that I've found
with semantic patch (see below):

drivers/xen/evtchn.c:667:8-24: ERROR: evtchn_fops: .read() can deadlock 
.write()
drivers/isdn/capi/capi.c:963:8-24: ERROR: capi_fops: .read() can 
deadlock .write()
drivers/input/evdev.c:527:1-17: ERROR: evdev_fops: .read() can deadlock 
.write()
drivers/char/pcmcia/cm4000_cs.c:1685:7-23: ERROR: cm4000_fops: .read() 
can deadlock .write()
net/rfkill/core.c:1146:8-24: ERROR: rfkill_fops: .read() can deadlock 
.write()
drivers/s390/char/fs3270.c:488:1-17: ERROR: fs3270_fops: .read() can 
deadlock .write()
drivers/usb/misc/ldusb.c:310:1-17: ERROR: ld_usb_fops: .read() can 
deadlock .write()
drivers/hid/uhid.c:635:1-17: ERROR: uhid_fops: .read() can deadlock 
.write()
net/batman-adv/icmp_socket.c:80:1-17: ERROR: batadv_fops: .read() can 
deadlock .write()
drivers/media/rc/lirc_dev.c:198:1-17: ERROR: lirc_fops: .read() can 
deadlock .write()
drivers/leds/uleds.c:77:1-17: ERROR: uleds_fops: .read() can deadlock 
.write()
drivers/input/misc/uinput.c:400:1-17: ERROR: uinput_fops: .read() can 
deadlock .write()
drivers/infiniband/core/user_mad.c:985:7-23: ERROR: umad_fops: .read() 
can deadlock .write()
drivers/gnss/core.c:45:1-17: ERROR: gnss_fops: .read() can deadlock 
.write()

In addition to the cases above another regression caused by f_pos
locking is that now FUSE filesystems that implement open with
FOPEN_NONSEEKABLE flag, can no longer implement bidirectional
stream-like files - for the same reason as above e.g. read can deadlock
write locking on file.f_pos in the kernel.

FUSE's FOPEN_NONSEEKABLE was added in 2008 in a7c1b990f715 ("fuse:
implement nonseekable open") to support OSSPD. OSSPD implements /dev/dsp
in userspace with FOPEN_NONSEEKABLE flag, with corresponding read and
write routines not depending on current position at all, and with both
read and write being potentially blocking operations:

See

https://github.com/libfuse/osspd
https://lwn.net/Articles/308445

https://github.com/libfuse/osspd/blob/14a9cff0/osspd.c#L1406
https://github.com/libfuse/osspd/blob/14a9cff0/osspd.c#L1438-L1477
https://github.com/libfuse/osspd/blob/14a9cff0/osspd.c#L1479-L1510

Corresponding libfuse example/test also describes FOPEN_NONSEEKABLE as
"somewhat pipe-like files ..." with read handler not using offset.
However that test implements only read without write and cannot exercise
the deadlock scenario:



[PATCH 4.4 230/241] neighbor: Call __ipv4_neigh_lookup_noref in neigh_xmit

2019-06-09 Thread Greg Kroah-Hartman
From: David Ahern 

[ Upstream commit 4b2a2bfeb3f056461a90bd621e8bd7d03fa47f60 ]

Commit cd9ff4de0107 changed the key for IFF_POINTOPOINT devices to
INADDR_ANY but neigh_xmit which is used for MPLS encapsulations was not
updated to use the altered key. The result is that every packet Tx does
a lookup on the gateway address which does not find an entry, a new one
is created only to find the existing one in the table right before the
insert since arp_constructor was updated to reset the primary key. This
is seen in the allocs and destroys counters:
ip -s -4 ntable show | head -10 | grep alloc

which increase for each packet showing the unnecessary overhread.

Fix by having neigh_xmit use __ipv4_neigh_lookup_noref for NEIGH_ARP_TABLE.

Fixes: cd9ff4de0107 ("ipv4: Make neigh lookup keys for loopback/point-to-point 
devices be INADDR_ANY")
Reported-by: Alan Maguire 
Signed-off-by: David Ahern 
Tested-by: Alan Maguire 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 net/core/neighbour.c |9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2490,7 +2491,13 @@ int neigh_xmit(int index, struct net_dev
if (!tbl)
goto out;
rcu_read_lock_bh();
-   neigh = __neigh_lookup_noref(tbl, addr, dev);
+   if (index == NEIGH_ARP_TABLE) {
+   u32 key = *((u32 *)addr);
+
+   neigh = __ipv4_neigh_lookup_noref(dev, key);
+   } else {
+   neigh = __neigh_lookup_noref(tbl, addr, dev);
+   }
if (!neigh)
neigh = __neigh_create(tbl, addr, dev, false);
err = PTR_ERR(neigh);




[PATCH 4.4 239/241] drm/gma500/cdv: Check vbt config bits when detecting lvds panels

2019-06-09 Thread Greg Kroah-Hartman
From: Patrik Jakobsson 

commit 7c420636860a719049fae9403e2c87804f53bdde upstream.

Some machines have an lvds child device in vbt even though a panel is
not attached. To make detection more reliable we now also check the lvds
config bits available in the vbt.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1665766
Cc: sta...@vger.kernel.org
Reviewed-by: Hans de Goede 
Signed-off-by: Patrik Jakobsson 
Link: 
https://patchwork.freedesktop.org/patch/msgid/20190416114607.1072-1-patrik.r.jakobs...@gmail.com
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/gma500/cdv_intel_lvds.c |3 +++
 drivers/gpu/drm/gma500/intel_bios.c |3 +++
 drivers/gpu/drm/gma500/psb_drv.h|1 +
 3 files changed, 7 insertions(+)

--- a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
@@ -620,6 +620,9 @@ void cdv_intel_lvds_init(struct drm_devi
int pipe;
u8 pin;
 
+   if (!dev_priv->lvds_enabled_in_vbt)
+   return;
+
pin = GMBUS_PORT_PANEL;
if (!lvds_is_present_in_vbt(dev, )) {
DRM_DEBUG_KMS("LVDS is not present in VBT\n");
--- a/drivers/gpu/drm/gma500/intel_bios.c
+++ b/drivers/gpu/drm/gma500/intel_bios.c
@@ -436,6 +436,9 @@ parse_driver_features(struct drm_psb_pri
if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
dev_priv->edp.support = 1;
 
+   dev_priv->lvds_enabled_in_vbt = driver->lvds_config != 0;
+   DRM_DEBUG_KMS("LVDS VBT config bits: 0x%x\n", driver->lvds_config);
+
/* This bit means to use 96Mhz for DPLL_A or not */
if (driver->primary_lfp_id)
dev_priv->dplla_96mhz = true;
--- a/drivers/gpu/drm/gma500/psb_drv.h
+++ b/drivers/gpu/drm/gma500/psb_drv.h
@@ -536,6 +536,7 @@ struct drm_psb_private {
int lvds_ssc_freq;
bool is_lvds_on;
bool is_mipi_on;
+   bool lvds_enabled_in_vbt;
u32 mipi_ctrl_display;
 
unsigned int core_freq;




[PATCH 4.4 241/241] fuse: Add FOPEN_STREAM to use stream_open()

2019-06-09 Thread Greg Kroah-Hartman
From: Kirill Smelkov 

commit bbd84f33652f852ce5992d65db4d020aba21f882 upstream.

Starting from commit 9c225f2655e3 ("vfs: atomic f_pos accesses as per
POSIX") files opened even via nonseekable_open gate read and write via lock
and do not allow them to be run simultaneously. This can create read vs
write deadlock if a filesystem is trying to implement a socket-like file
which is intended to be simultaneously used for both read and write from
filesystem client.  See commit 10dce8af3422 ("fs: stream_open - opener for
stream-like files so that read and write can run simultaneously without
deadlock") for details and e.g. commit 581d21a2d02a ("xenbus: fix deadlock
on writes to /proc/xen/xenbus") for a similar deadlock example on
/proc/xen/xenbus.

To avoid such deadlock it was tempting to adjust fuse_finish_open to use
stream_open instead of nonseekable_open on just FOPEN_NONSEEKABLE flags,
but grepping through Debian codesearch shows users of FOPEN_NONSEEKABLE,
and in particular GVFS which actually uses offset in its read and write
handlers

https://codesearch.debian.net/search?q=-%3Enonseekable+%3D

https://gitlab.gnome.org/GNOME/gvfs/blob/1.40.0-6-gcbc54396/client/gvfsfusedaemon.c#L1080

https://gitlab.gnome.org/GNOME/gvfs/blob/1.40.0-6-gcbc54396/client/gvfsfusedaemon.c#L1247-1346

https://gitlab.gnome.org/GNOME/gvfs/blob/1.40.0-6-gcbc54396/client/gvfsfusedaemon.c#L1399-1481

so if we would do such a change it will break a real user.

Add another flag (FOPEN_STREAM) for filesystem servers to indicate that the
opened handler is having stream-like semantics; does not use file position
and thus the kernel is free to issue simultaneous read and write request on
opened file handle.

This patch together with stream_open() should be added to stable kernels
starting from v3.14+. This will allow to patch OSSPD and other FUSE
filesystems that provide stream-like files to return FOPEN_STREAM |
FOPEN_NONSEEKABLE in open handler and this way avoid the deadlock on all
kernel versions. This should work because fuse_finish_open ignores unknown
open flags returned from a filesystem and so passing FOPEN_STREAM to a
kernel that is not aware of this flag cannot hurt. In turn the kernel that
is not aware of FOPEN_STREAM will be < v3.14 where just FOPEN_NONSEEKABLE
is sufficient to implement streams without read vs write deadlock.

Cc: sta...@vger.kernel.org # v3.14+
Signed-off-by: Kirill Smelkov 
Signed-off-by: Miklos Szeredi 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/fuse/file.c|4 +++-
 include/uapi/linux/fuse.h |2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -178,7 +178,9 @@ void fuse_finish_open(struct inode *inod
file->f_op = _direct_io_file_operations;
if (!(ff->open_flags & FOPEN_KEEP_CACHE))
invalidate_inode_pages2(inode->i_mapping);
-   if (ff->open_flags & FOPEN_NONSEEKABLE)
+   if (ff->open_flags & FOPEN_STREAM)
+   stream_open(inode, file);
+   else if (ff->open_flags & FOPEN_NONSEEKABLE)
nonseekable_open(inode, file);
if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) {
struct fuse_inode *fi = get_fuse_inode(inode);
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -205,10 +205,12 @@ struct fuse_file_lock {
  * FOPEN_DIRECT_IO: bypass page cache for this open file
  * FOPEN_KEEP_CACHE: don't invalidate the data cache on open
  * FOPEN_NONSEEKABLE: the file is not seekable
+ * FOPEN_STREAM: the file is stream-like (no file position at all)
  */
 #define FOPEN_DIRECT_IO(1 << 0)
 #define FOPEN_KEEP_CACHE   (1 << 1)
 #define FOPEN_NONSEEKABLE  (1 << 2)
+#define FOPEN_STREAM   (1 << 4)
 
 /**
  * INIT request/reply flags




[PATCH 4.4 223/241] brcmfmac: add subtype check for event handling in data path

2019-06-09 Thread Greg Kroah-Hartman
From: Arend van Spriel 

commit a4176ec356c73a46c07c181c6d04039fafa34a9f upstream.

For USB there is no separate channel being used to pass events
from firmware to the host driver and as such are passed over the
data path. In order to detect mock event messages an additional
check is needed on event subtype. This check is added conditionally
using unlikely() keyword.

Reviewed-by: Hante Meuleman 
Reviewed-by: Pieter-Paul Giesberts 
Reviewed-by: Franky Lin 
Signed-off-by: Arend van Spriel 
Signed-off-by: Kalle Valo 
[bwh: Backported to 4.4: adjust filenames]
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/wireless/brcm80211/brcmfmac/core.c   |5 +++--
 drivers/net/wireless/brcm80211/brcmfmac/fweh.h   |   16 
 drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c |2 +-
 3 files changed, 16 insertions(+), 7 deletions(-)

--- a/drivers/net/wireless/brcm80211/brcmfmac/core.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/core.c
@@ -548,7 +548,8 @@ void brcmf_rx_frame(struct device *dev,
} else {
/* Process special event packets */
if (handle_event)
-   brcmf_fweh_process_skb(ifp->drvr, skb);
+   brcmf_fweh_process_skb(ifp->drvr, skb,
+  BCMILCP_SUBTYPE_VENDOR_LONG);
 
brcmf_netif_rx(ifp, skb);
}
@@ -575,7 +576,7 @@ void brcmf_rx_event(struct device *dev,
 
skb->protocol = eth_type_trans(skb, ifp->ndev);
 
-   brcmf_fweh_process_skb(ifp->drvr, skb);
+   brcmf_fweh_process_skb(ifp->drvr, skb, 0);
brcmu_pkt_buf_free_skb(skb);
 }
 
--- a/drivers/net/wireless/brcm80211/brcmfmac/fweh.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/fweh.h
@@ -181,7 +181,7 @@ enum brcmf_fweh_event_code {
  */
 #define BRCM_OUI   "\x00\x10\x18"
 #define BCMILCP_BCM_SUBTYPE_EVENT  1
-
+#define BCMILCP_SUBTYPE_VENDOR_LONG32769
 
 /**
  * struct brcm_ethhdr - broadcom specific ether header.
@@ -302,10 +302,10 @@ void brcmf_fweh_process_event(struct brc
 void brcmf_fweh_p2pdev_setup(struct brcmf_if *ifp, bool ongoing);
 
 static inline void brcmf_fweh_process_skb(struct brcmf_pub *drvr,
- struct sk_buff *skb)
+ struct sk_buff *skb, u16 stype)
 {
struct brcmf_event *event_packet;
-   u16 usr_stype;
+   u16 subtype, usr_stype;
 
/* only process events when protocol matches */
if (skb->protocol != cpu_to_be16(ETH_P_LINK_CTL))
@@ -314,8 +314,16 @@ static inline void brcmf_fweh_process_sk
if ((skb->len + ETH_HLEN) < sizeof(*event_packet))
return;
 
-   /* check for BRCM oui match */
event_packet = (struct brcmf_event *)skb_mac_header(skb);
+
+   /* check subtype if needed */
+   if (unlikely(stype)) {
+   subtype = get_unaligned_be16(_packet->hdr.subtype);
+   if (subtype != stype)
+   return;
+   }
+
+   /* check for BRCM oui match */
if (memcmp(BRCM_OUI, _packet->hdr.oui[0],
   sizeof(event_packet->hdr.oui)))
return;
--- a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
@@ -1112,7 +1112,7 @@ static void brcmf_msgbuf_process_event(s
 
skb->protocol = eth_type_trans(skb, ifp->ndev);
 
-   brcmf_fweh_process_skb(ifp->drvr, skb);
+   brcmf_fweh_process_skb(ifp->drvr, skb, 0);
 
 exit:
brcmu_pkt_buf_free_skb(skb);




[PATCH 4.4 218/241] brcmfmac: Add length checks on firmware events

2019-06-09 Thread Greg Kroah-Hartman
From: Hante Meuleman 

commit 0aedbcaf6f182690790d98d90d5fe1e64c846c34 upstream.

Add additional length checks on firmware events to create more
robust code.

Reviewed-by: Arend Van Spriel 
Reviewed-by: Franky (Zhenhui) Lin 
Reviewed-by: Pieter-Paul Giesberts 
Reviewed-by: Lei Zhang 
Signed-off-by: Hante Meuleman 
Signed-off-by: Arend van Spriel 
Signed-off-by: Kalle Valo 
[bwh: Backported to 4.4:
 - Drop changes to brcmf_wowl_nd_results()
 - Adjust filenames]
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c |5 +
 drivers/net/wireless/brcm80211/brcmfmac/fweh.c |   57 +++--
 drivers/net/wireless/brcm80211/brcmfmac/fweh.h |   68 -
 drivers/net/wireless/brcm80211/brcmfmac/p2p.c  |   10 +++
 4 files changed, 82 insertions(+), 58 deletions(-)

--- a/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
@@ -3331,6 +3331,11 @@ brcmf_notify_sched_scan_results(struct b
 
brcmf_dbg(SCAN, "Enter\n");
 
+   if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
+   brcmf_dbg(SCAN, "Event data to small. Ignore\n");
+   return 0;
+   }
+
if (e->event_code == BRCMF_E_PFN_NET_LOST) {
brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
return 0;
--- a/drivers/net/wireless/brcm80211/brcmfmac/fweh.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/fweh.c
@@ -26,50 +26,6 @@
 #include "fwil.h"
 
 /**
- * struct brcm_ethhdr - broadcom specific ether header.
- *
- * @subtype: subtype for this packet.
- * @length: TODO: length of appended data.
- * @version: version indication.
- * @oui: OUI of this packet.
- * @usr_subtype: subtype for this OUI.
- */
-struct brcm_ethhdr {
-   __be16 subtype;
-   __be16 length;
-   u8 version;
-   u8 oui[3];
-   __be16 usr_subtype;
-} __packed;
-
-struct brcmf_event_msg_be {
-   __be16 version;
-   __be16 flags;
-   __be32 event_type;
-   __be32 status;
-   __be32 reason;
-   __be32 auth_type;
-   __be32 datalen;
-   u8 addr[ETH_ALEN];
-   char ifname[IFNAMSIZ];
-   u8 ifidx;
-   u8 bsscfgidx;
-} __packed;
-
-/**
- * struct brcmf_event - contents of broadcom event packet.
- *
- * @eth: standard ether header.
- * @hdr: broadcom specific ether header.
- * @msg: common part of the actual event message.
- */
-struct brcmf_event {
-   struct ethhdr eth;
-   struct brcm_ethhdr hdr;
-   struct brcmf_event_msg_be msg;
-} __packed;
-
-/**
  * struct brcmf_fweh_queue_item - event item on event queue.
  *
  * @q: list element for queuing.
@@ -85,6 +41,7 @@ struct brcmf_fweh_queue_item {
u8 ifidx;
u8 ifaddr[ETH_ALEN];
struct brcmf_event_msg_be emsg;
+   u32 datalen;
u8 data[0];
 };
 
@@ -294,6 +251,11 @@ static void brcmf_fweh_event_worker(stru
brcmf_dbg_hex_dump(BRCMF_EVENT_ON(), event->data,
   min_t(u32, emsg.datalen, 64),
   "event payload, len=%d\n", emsg.datalen);
+   if (emsg.datalen > event->datalen) {
+   brcmf_err("event invalid length header=%d, msg=%d\n",
+ event->datalen, emsg.datalen);
+   goto event_free;
+   }
 
/* special handling of interface event */
if (event->code == BRCMF_E_IF) {
@@ -439,7 +401,8 @@ int brcmf_fweh_activate_events(struct br
  * dispatch the event to a registered handler (using worker).
  */
 void brcmf_fweh_process_event(struct brcmf_pub *drvr,
- struct brcmf_event *event_packet)
+ struct brcmf_event *event_packet,
+ u32 packet_len)
 {
enum brcmf_fweh_event_code code;
struct brcmf_fweh_info *fweh = >fweh;
@@ -459,6 +422,9 @@ void brcmf_fweh_process_event(struct brc
if (code != BRCMF_E_IF && !fweh->evt_handler[code])
return;
 
+   if (datalen > BRCMF_DCMD_MAXLEN)
+   return;
+
if (in_interrupt())
alloc_flag = GFP_ATOMIC;
 
@@ -472,6 +438,7 @@ void brcmf_fweh_process_event(struct brc
/* use memcpy to get aligned event message */
memcpy(>emsg, _packet->msg, sizeof(event->emsg));
memcpy(event->data, data, datalen);
+   event->datalen = datalen;
memcpy(event->ifaddr, event_packet->eth.h_dest, ETH_ALEN);
 
brcmf_fweh_queue_event(fweh, event);
--- a/drivers/net/wireless/brcm80211/brcmfmac/fweh.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/fweh.h
@@ -27,7 +27,6 @@
 struct brcmf_pub;
 struct brcmf_if;
 struct brcmf_cfg80211_info;
-struct brcmf_event;
 
 /* list of firmware events */
 #define BRCMF_FWEH_EVENT_ENUM_DEFLIST \
@@ -180,13 +179,55 @@ enum brcmf_fweh_event_code {
 /**
  * definitions for event 

[PATCH 4.4 192/241] sparc64: Fix regression in non-hypervisor TLB flush xcall

2019-06-09 Thread Greg Kroah-Hartman
From: James Clarke 

commit d3c976c14ad8af421134c428b0a89ff8dd3bd8f8 upstream.

Previously, %g2 would end up with the value PAGE_SIZE, but after the
commit mentioned below it ends up with the value 1 due to being reused
for a different purpose. We need it to be PAGE_SIZE as we use it to step
through pages in our demap loop, otherwise we set different flags in the
low 12 bits of the address written to, thereby doing things other than a
nucleus page flush.

Fixes: a74ad5e660a9 ("sparc64: Handle extremely large kernel TLB range flushes 
more gracefully.")
Reported-by: Meelis Roos 
Tested-by: Meelis Roos 
Signed-off-by: James Clarke 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/sparc/mm/ultra.S |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/arch/sparc/mm/ultra.S
+++ b/arch/sparc/mm/ultra.S
@@ -586,7 +586,7 @@ xcall_flush_tlb_kernel_range:   /* 44 insn
sub %g7, %g1, %g3
srlx%g3, 18, %g2
brnz,pn %g2, 2f
-add%g2, 1, %g2
+sethi  %hi(PAGE_SIZE), %g2
sub %g3, %g2, %g3
or  %g1, 0x20, %g1  ! Nucleus
 1: stxa%g0, [%g1 + %g3] ASI_DMMU_DEMAP
@@ -750,7 +750,7 @@ __cheetah_xcall_flush_tlb_kernel_range:
sub %g7, %g1, %g3
srlx%g3, 18, %g2
brnz,pn %g2, 2f
-add%g2, 1, %g2
+sethi  %hi(PAGE_SIZE), %g2
sub %g3, %g2, %g3
or  %g1, 0x20, %g1  ! Nucleus
 1: stxa%g0, [%g1 + %g3] ASI_DMMU_DEMAP




[PATCH 4.4 191/241] tipc: fix modprobe tipc failed after switch order of device registration -v2

2019-06-09 Thread Greg Kroah-Hartman
From: Junwei Hu 

commit 526f5b851a96566803ee4bee60d0a34df56c77f8 upstream.

Error message printed:
modprobe: ERROR: could not insert 'tipc': Address family not
supported by protocol.
when modprobe tipc after the following patch: switch order of
device registration, commit 7e27e8d6130c
("tipc: switch order of device registration to fix a crash")

Because sock_create_kern(net, AF_TIPC, ...) called by
tipc_topsrv_create_listener() in the initialization process
of tipc_init_net(), so tipc_socket_init() must be execute before that.
Meanwhile, tipc_net_id need to be initialized when sock_create()
called, and tipc_socket_init() is no need to be called for each namespace.

I add a variable tipc_topsrv_net_ops, and split the
register_pernet_subsys() of tipc into two parts, and split
tipc_socket_init() with initialization of pernet params.

By the way, I fixed resources rollback error when tipc_bcast_init()
failed in tipc_init_net().

Fixes: 7e27e8d6130c ("tipc: switch order of device registration to fix a crash")
Signed-off-by: Junwei Hu 
Reported-by: Wang Wang 
Reported-by: syzbot+1e8114b61079bfe9c...@syzkaller.appspotmail.com
Reviewed-by: Kang Zhou 
Reviewed-by: Suanming Mou 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 

---
 net/tipc/core.c   |   18 --
 net/tipc/subscr.c |   14 --
 net/tipc/subscr.h |5 +++--
 3 files changed, 27 insertions(+), 10 deletions(-)

--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -70,9 +70,6 @@ static int __net_init tipc_init_net(stru
goto out_nametbl;
 
INIT_LIST_HEAD(>dist_queue);
-   err = tipc_topsrv_start(net);
-   if (err)
-   goto out_subscr;
 
err = tipc_bcast_init(net);
if (err)
@@ -81,8 +78,6 @@ static int __net_init tipc_init_net(stru
return 0;
 
 out_bclink:
-   tipc_bcast_stop(net);
-out_subscr:
tipc_nametbl_stop(net);
 out_nametbl:
tipc_sk_rht_destroy(net);
@@ -92,7 +87,6 @@ out_sk_rht:
 
 static void __net_exit tipc_exit_net(struct net *net)
 {
-   tipc_topsrv_stop(net);
tipc_net_stop(net);
tipc_bcast_stop(net);
tipc_nametbl_stop(net);
@@ -106,6 +100,11 @@ static struct pernet_operations tipc_net
.size = sizeof(struct tipc_net),
 };
 
+static struct pernet_operations tipc_topsrv_net_ops = {
+   .init = tipc_topsrv_init_net,
+   .exit = tipc_topsrv_exit_net,
+};
+
 static int __init tipc_init(void)
 {
int err;
@@ -138,6 +137,10 @@ static int __init tipc_init(void)
if (err)
goto out_socket;
 
+   err = register_pernet_subsys(_topsrv_net_ops);
+   if (err)
+   goto out_pernet_topsrv;
+
err = tipc_bearer_setup();
if (err)
goto out_bearer;
@@ -145,6 +148,8 @@ static int __init tipc_init(void)
pr_info("Started in single node mode\n");
return 0;
 out_bearer:
+   unregister_pernet_subsys(_topsrv_net_ops);
+out_pernet_topsrv:
tipc_socket_stop();
 out_socket:
unregister_pernet_subsys(_net_ops);
@@ -162,6 +167,7 @@ out_netlink:
 static void __exit tipc_exit(void)
 {
tipc_bearer_cleanup();
+   unregister_pernet_subsys(_topsrv_net_ops);
tipc_socket_stop();
unregister_pernet_subsys(_net_ops);
tipc_netlink_stop();
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -306,7 +306,7 @@ static void *tipc_subscrb_connect_cb(int
return (void *)tipc_subscrb_create(conid);
 }
 
-int tipc_topsrv_start(struct net *net)
+static int tipc_topsrv_start(struct net *net)
 {
struct tipc_net *tn = net_generic(net, tipc_net_id);
const char name[] = "topology_server";
@@ -344,7 +344,7 @@ int tipc_topsrv_start(struct net *net)
return tipc_server_start(topsrv);
 }
 
-void tipc_topsrv_stop(struct net *net)
+static void tipc_topsrv_stop(struct net *net)
 {
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct tipc_server *topsrv = tn->topsrv;
@@ -353,3 +353,13 @@ void tipc_topsrv_stop(struct net *net)
kfree(topsrv->saddr);
kfree(topsrv);
 }
+
+int __net_init tipc_topsrv_init_net(struct net *net)
+{
+   return tipc_topsrv_start(net);
+}
+
+void __net_exit tipc_topsrv_exit_net(struct net *net)
+{
+   tipc_topsrv_stop(net);
+}
--- a/net/tipc/subscr.h
+++ b/net/tipc/subscr.h
@@ -77,7 +77,8 @@ int tipc_subscrp_check_overlap(struct ti
 void tipc_subscrp_report_overlap(struct tipc_subscription *sub,
 u32 found_lower, u32 found_upper, u32 event,
 u32 port_ref, u32 node, int must);
-int tipc_topsrv_start(struct net *net);
-void tipc_topsrv_stop(struct net *net);
+
+int __net_init tipc_topsrv_init_net(struct net *net);
+void __net_exit tipc_topsrv_exit_net(struct net *net);
 
 #endif




[PATCH 4.4 188/241] crypto: vmx - ghash: do nosimd fallback manually

2019-06-09 Thread Greg Kroah-Hartman
From: Daniel Axtens 

commit 357d065a44cdd77ed5ff35155a989f2a763e96ef upstream.

VMX ghash was using a fallback that did not support interleaving simd
and nosimd operations, leading to failures in the extended test suite.

If I understood correctly, Eric's suggestion was to use the same
data format that the generic code uses, allowing us to call into it
with the same contexts. I wasn't able to get that to work - I think
there's a very different key structure and data layout being used.

So instead steal the arm64 approach and perform the fallback
operations directly if required.

Fixes: cc333cd68dfa ("crypto: vmx - Adding GHASH routines for VMX module")
Cc: sta...@vger.kernel.org # v4.1+
Reported-by: Eric Biggers 
Signed-off-by: Daniel Axtens 
Acked-by: Ard Biesheuvel 
Tested-by: Michael Ellerman 
Signed-off-by: Herbert Xu 
Signed-off-by: Daniel Axtens 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/crypto/vmx/ghash.c |  218 ++---
 1 file changed, 89 insertions(+), 129 deletions(-)

--- a/drivers/crypto/vmx/ghash.c
+++ b/drivers/crypto/vmx/ghash.c
@@ -1,22 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
 /**
  * GHASH routines supporting VMX instructions on the Power 8
  *
- * Copyright (C) 2015 International Business Machines Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 only.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Copyright (C) 2015, 2019 International Business Machines Inc.
  *
  * Author: Marcelo Henrique Cerri 
+ *
+ * Extended by Daniel Axtens  to replace the fallback
+ * mechanism. The new approach is based on arm64 code, which is:
+ *   Copyright (C) 2014 - 2018 Linaro Ltd. 
  */
 
 #include 
@@ -39,71 +31,25 @@ void gcm_ghash_p8(u64 Xi[2], const u128
  const u8 *in, size_t len);
 
 struct p8_ghash_ctx {
+   /* key used by vector asm */
u128 htable[16];
-   struct crypto_shash *fallback;
+   /* key used by software fallback */
+   be128 key;
 };
 
 struct p8_ghash_desc_ctx {
u64 shash[2];
u8 buffer[GHASH_DIGEST_SIZE];
int bytes;
-   struct shash_desc fallback_desc;
 };
 
-static int p8_ghash_init_tfm(struct crypto_tfm *tfm)
-{
-   const char *alg = "ghash-generic";
-   struct crypto_shash *fallback;
-   struct crypto_shash *shash_tfm = __crypto_shash_cast(tfm);
-   struct p8_ghash_ctx *ctx = crypto_tfm_ctx(tfm);
-
-   fallback = crypto_alloc_shash(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
-   if (IS_ERR(fallback)) {
-   printk(KERN_ERR
-  "Failed to allocate transformation for '%s': %ld\n",
-  alg, PTR_ERR(fallback));
-   return PTR_ERR(fallback);
-   }
-
-   crypto_shash_set_flags(fallback,
-  crypto_shash_get_flags((struct crypto_shash
-  *) tfm));
-
-   /* Check if the descsize defined in the algorithm is still enough. */
-   if (shash_tfm->descsize < sizeof(struct p8_ghash_desc_ctx)
-   + crypto_shash_descsize(fallback)) {
-   printk(KERN_ERR
-  "Desc size of the fallback implementation (%s) does not 
match the expected value: %lu vs %u\n",
-  alg,
-  shash_tfm->descsize - sizeof(struct p8_ghash_desc_ctx),
-  crypto_shash_descsize(fallback));
-   return -EINVAL;
-   }
-   ctx->fallback = fallback;
-
-   return 0;
-}
-
-static void p8_ghash_exit_tfm(struct crypto_tfm *tfm)
-{
-   struct p8_ghash_ctx *ctx = crypto_tfm_ctx(tfm);
-
-   if (ctx->fallback) {
-   crypto_free_shash(ctx->fallback);
-   ctx->fallback = NULL;
-   }
-}
-
 static int p8_ghash_init(struct shash_desc *desc)
 {
-   struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(desc->tfm));
struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
 
dctx->bytes = 0;
memset(dctx->shash, 0, GHASH_DIGEST_SIZE);
-   dctx->fallback_desc.tfm = ctx->fallback;
-   dctx->fallback_desc.flags = desc->flags;
-   return crypto_shash_init(>fallback_desc);
+   return 0;
 }
 
 static int p8_ghash_setkey(struct crypto_shash *tfm, const u8 *key,
@@ -122,7 +68,53 @@ static int p8_ghash_setkey(struct crypto
gcm_init_p8(ctx->htable, (const u64 *) key);
pagefault_enable();
preempt_enable();

[PATCH 4.4 224/241] userfaultfd: dont pin the user memory in userfaultfd_file_create()

2019-06-09 Thread Greg Kroah-Hartman
From: Oleg Nesterov 

commit d2005e3f41d4f9299e2df6a967c8beb5086967a9 upstream.

userfaultfd_file_create() increments mm->mm_users; this means that the
memory won't be unmapped/freed if mm owner exits/execs, and UFFDIO_COPY
after that can populate the orphaned mm more.

Change userfaultfd_file_create() and userfaultfd_ctx_put() to use
mm->mm_count to pin mm_struct.  This means that
atomic_inc_not_zero(mm->mm_users) is needed when we are going to
actually play with this memory.  Except handle_userfault() path doesn't
need this, the caller must already have a reference.

The patch adds the new trivial helper, mmget_not_zero(), it can have
more users.

Link: http://lkml.kernel.org/r/20160516172254.ga8...@redhat.com
Signed-off-by: Oleg Nesterov 
Cc: Andrea Arcangeli 
Cc: Michal Hocko 
Signed-off-by: Andrew Morton 
Signed-off-by: Linus Torvalds 
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 fs/userfaultfd.c  |   41 -
 include/linux/sched.h |7 ++-
 2 files changed, 34 insertions(+), 14 deletions(-)

--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -137,7 +137,7 @@ static void userfaultfd_ctx_put(struct u
VM_BUG_ON(waitqueue_active(>fault_wqh));
VM_BUG_ON(spin_is_locked(>fd_wqh.lock));
VM_BUG_ON(waitqueue_active(>fd_wqh));
-   mmput(ctx->mm);
+   mmdrop(ctx->mm);
kmem_cache_free(userfaultfd_ctx_cachep, ctx);
}
 }
@@ -434,6 +434,9 @@ static int userfaultfd_release(struct in
 
ACCESS_ONCE(ctx->released) = true;
 
+   if (!mmget_not_zero(mm))
+   goto wakeup;
+
/*
 * Flush page faults out of all CPUs. NOTE: all page faults
 * must be retried without returning VM_FAULT_SIGBUS if
@@ -466,7 +469,8 @@ static int userfaultfd_release(struct in
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
}
up_write(>mmap_sem);
-
+   mmput(mm);
+wakeup:
/*
 * After no new page faults can wait on this fault_*wqh, flush
 * the last page faults that may have been already waiting on
@@ -760,10 +764,12 @@ static int userfaultfd_register(struct u
start = uffdio_register.range.start;
end = start + uffdio_register.range.len;
 
+   ret = -ENOMEM;
+   if (!mmget_not_zero(mm))
+   goto out;
+
down_write(>mmap_sem);
vma = find_vma_prev(mm, start, );
-
-   ret = -ENOMEM;
if (!vma)
goto out_unlock;
 
@@ -864,6 +870,7 @@ static int userfaultfd_register(struct u
} while (vma && vma->vm_start < end);
 out_unlock:
up_write(>mmap_sem);
+   mmput(mm);
if (!ret) {
/*
 * Now that we scanned all vmas we can already tell
@@ -902,10 +909,12 @@ static int userfaultfd_unregister(struct
start = uffdio_unregister.start;
end = start + uffdio_unregister.len;
 
+   ret = -ENOMEM;
+   if (!mmget_not_zero(mm))
+   goto out;
+
down_write(>mmap_sem);
vma = find_vma_prev(mm, start, );
-
-   ret = -ENOMEM;
if (!vma)
goto out_unlock;
 
@@ -998,6 +1007,7 @@ static int userfaultfd_unregister(struct
} while (vma && vma->vm_start < end);
 out_unlock:
up_write(>mmap_sem);
+   mmput(mm);
 out:
return ret;
 }
@@ -1067,9 +1077,11 @@ static int userfaultfd_copy(struct userf
goto out;
if (uffdio_copy.mode & ~UFFDIO_COPY_MODE_DONTWAKE)
goto out;
-
-   ret = mcopy_atomic(ctx->mm, uffdio_copy.dst, uffdio_copy.src,
-  uffdio_copy.len);
+   if (mmget_not_zero(ctx->mm)) {
+   ret = mcopy_atomic(ctx->mm, uffdio_copy.dst, uffdio_copy.src,
+  uffdio_copy.len);
+   mmput(ctx->mm);
+   }
if (unlikely(put_user(ret, _uffdio_copy->copy)))
return -EFAULT;
if (ret < 0)
@@ -1110,8 +1122,11 @@ static int userfaultfd_zeropage(struct u
if (uffdio_zeropage.mode & ~UFFDIO_ZEROPAGE_MODE_DONTWAKE)
goto out;
 
-   ret = mfill_zeropage(ctx->mm, uffdio_zeropage.range.start,
-uffdio_zeropage.range.len);
+   if (mmget_not_zero(ctx->mm)) {
+   ret = mfill_zeropage(ctx->mm, uffdio_zeropage.range.start,
+uffdio_zeropage.range.len);
+   mmput(ctx->mm);
+   }
if (unlikely(put_user(ret, _uffdio_zeropage->zeropage)))
return -EFAULT;
if (ret < 0)
@@ -1289,12 +1304,12 @@ static struct file *userfaultfd_file_cre
ctx->released = false;
ctx->mm = current->mm;
/* prevent the mm struct to be freed */
-   atomic_inc(>mm->mm_users);
+   atomic_inc(>mm->mm_count);
 
file = anon_inode_getfile("[userfaultfd]", _fops, ctx,
  O_RDWR | 

[PATCH 4.4 219/241] brcmfmac: screening firmware event packet

2019-06-09 Thread Greg Kroah-Hartman
From: Franky Lin 

commit c56caa9db8abbbfb9e31325e0897705aa897db37 upstream.

Firmware uses asynchronized events as a communication method to the
host. The event packets are marked as ETH_P_LINK_CTL protocol type. For
SDIO and PCIe bus, this kind of packets are delivered through virtual
event channel not data channel. This patch adds a screening logic to
make sure the event handler only processes the events coming from the
correct channel.

Reviewed-by: Pieter-Paul Giesberts 
Signed-off-by: Franky Lin 
Signed-off-by: Arend van Spriel 
Signed-off-by: Kalle Valo 
[bwh: Backported to 4.4 adjust filenames]
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/wireless/brcm80211/brcmfmac/bus.h|4 +-
 drivers/net/wireless/brcm80211/brcmfmac/core.c   |   46 ++-
 drivers/net/wireless/brcm80211/brcmfmac/core.h   |3 +
 drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c |   42 -
 drivers/net/wireless/brcm80211/brcmfmac/sdio.c   |   32 
 drivers/net/wireless/brcm80211/brcmfmac/usb.c|2 -
 6 files changed, 90 insertions(+), 39 deletions(-)

--- a/drivers/net/wireless/brcm80211/brcmfmac/bus.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bus.h
@@ -214,7 +214,9 @@ bool brcmf_c_prec_enq(struct device *dev
  int prec);
 
 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
-void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
+void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_evnt);
+/* Receive async event packet from firmware. Callee disposes of rxp. */
+void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
 
 /* Indication from bus module regarding presence/insertion of dongle. */
 int brcmf_attach(struct device *dev);
--- a/drivers/net/wireless/brcm80211/brcmfmac/core.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/core.c
@@ -301,16 +301,17 @@ void brcmf_txflowblock(struct device *de
brcmf_fws_bus_blocked(drvr, state);
 }
 
-void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb)
+void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb,
+   bool handle_event)
 {
-   skb->dev = ifp->ndev;
-   skb->protocol = eth_type_trans(skb, skb->dev);
+   skb->protocol = eth_type_trans(skb, ifp->ndev);
 
if (skb->pkt_type == PACKET_MULTICAST)
ifp->stats.multicast++;
 
/* Process special event packets */
-   brcmf_fweh_process_skb(ifp->drvr, skb);
+   if (handle_event)
+   brcmf_fweh_process_skb(ifp->drvr, skb);
 
if (!(ifp->ndev->flags & IFF_UP)) {
brcmu_pkt_buf_free_skb(skb);
@@ -371,7 +372,7 @@ static void brcmf_rxreorder_process_info
/* validate flags and flow id */
if (flags == 0xFF) {
brcmf_err("invalid flags...so ignore this packet\n");
-   brcmf_netif_rx(ifp, pkt);
+   brcmf_netif_rx(ifp, pkt, false);
return;
}
 
@@ -383,7 +384,7 @@ static void brcmf_rxreorder_process_info
if (rfi == NULL) {
brcmf_dbg(INFO, "received flags to cleanup, but no flow 
(%d) yet\n",
  flow_id);
-   brcmf_netif_rx(ifp, pkt);
+   brcmf_netif_rx(ifp, pkt, false);
return;
}
 
@@ -408,7 +409,7 @@ static void brcmf_rxreorder_process_info
rfi = kzalloc(buf_size, GFP_ATOMIC);
if (rfi == NULL) {
brcmf_err("failed to alloc buffer\n");
-   brcmf_netif_rx(ifp, pkt);
+   brcmf_netif_rx(ifp, pkt, false);
return;
}
 
@@ -522,11 +523,11 @@ static void brcmf_rxreorder_process_info
 netif_rx:
skb_queue_walk_safe(_list, pkt, pnext) {
__skb_unlink(pkt, _list);
-   brcmf_netif_rx(ifp, pkt);
+   brcmf_netif_rx(ifp, pkt, false);
}
 }
 
-void brcmf_rx_frame(struct device *dev, struct sk_buff *skb)
+void brcmf_rx_frame(struct device *dev, struct sk_buff *skb, bool handle_evnt)
 {
struct brcmf_if *ifp;
struct brcmf_bus *bus_if = dev_get_drvdata(dev);
@@ -550,7 +551,32 @@ void brcmf_rx_frame(struct device *dev,
if (rd->reorder)
brcmf_rxreorder_process_info(ifp, rd->reorder, skb);
else
-   brcmf_netif_rx(ifp, skb);
+   brcmf_netif_rx(ifp, skb, handle_evnt);
+}
+
+void brcmf_rx_event(struct device *dev, struct sk_buff *skb)
+{
+   struct brcmf_if *ifp;
+   struct brcmf_bus *bus_if = dev_get_drvdata(dev);
+   struct brcmf_pub *drvr = bus_if->drvr;
+   int ret;
+
+   brcmf_dbg(EVENT, "Enter: %s: rxp=%p\n", dev_name(dev), skb);
+
+   /* process and remove protocol-specific header */
+   ret = brcmf_proto_hdrpull(drvr, true, skb, );
+
+   if (ret || !ifp || !ifp->ndev) {

[PATCH 4.4 220/241] brcmfmac: revise handling events in receive path

2019-06-09 Thread Greg Kroah-Hartman
From: Arend van Spriel 

commit 9c349892ccc90c6de2baaa69cc78449f58082273 upstream.

Move event handling out of brcmf_netif_rx() avoiding the need
to pass a flag. This flag is only ever true for USB hosts as
other interface use separate brcmf_rx_event() function.

Reviewed-by: Hante Meuleman 
Reviewed-by: Pieter-Paul Giesberts 
Reviewed-by: Franky Lin 
Signed-off-by: Arend van Spriel 
Signed-off-by: Kalle Valo 
[bwh: Backported to 4.4 as dependency of commit a4176ec356c7
 "brcmfmac: add subtype check for event handling in data path"
 - Adjust filenames, context]
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/wireless/brcm80211/brcmfmac/bus.h|2 -
 drivers/net/wireless/brcm80211/brcmfmac/core.c   |   32 +++
 drivers/net/wireless/brcm80211/brcmfmac/core.h   |3 --
 drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c |2 -
 4 files changed, 19 insertions(+), 20 deletions(-)

--- a/drivers/net/wireless/brcm80211/brcmfmac/bus.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bus.h
@@ -214,7 +214,7 @@ bool brcmf_c_prec_enq(struct device *dev
  int prec);
 
 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
-void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_evnt);
+void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool 
handle_event);
 /* Receive async event packet from firmware. Callee disposes of rxp. */
 void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
 
--- a/drivers/net/wireless/brcm80211/brcmfmac/core.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/core.c
@@ -301,18 +301,11 @@ void brcmf_txflowblock(struct device *de
brcmf_fws_bus_blocked(drvr, state);
 }
 
-void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb,
-   bool handle_event)
+void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb)
 {
-   skb->protocol = eth_type_trans(skb, ifp->ndev);
-
if (skb->pkt_type == PACKET_MULTICAST)
ifp->stats.multicast++;
 
-   /* Process special event packets */
-   if (handle_event)
-   brcmf_fweh_process_skb(ifp->drvr, skb);
-
if (!(ifp->ndev->flags & IFF_UP)) {
brcmu_pkt_buf_free_skb(skb);
return;
@@ -372,7 +365,7 @@ static void brcmf_rxreorder_process_info
/* validate flags and flow id */
if (flags == 0xFF) {
brcmf_err("invalid flags...so ignore this packet\n");
-   brcmf_netif_rx(ifp, pkt, false);
+   brcmf_netif_rx(ifp, pkt);
return;
}
 
@@ -384,7 +377,7 @@ static void brcmf_rxreorder_process_info
if (rfi == NULL) {
brcmf_dbg(INFO, "received flags to cleanup, but no flow 
(%d) yet\n",
  flow_id);
-   brcmf_netif_rx(ifp, pkt, false);
+   brcmf_netif_rx(ifp, pkt);
return;
}
 
@@ -409,7 +402,7 @@ static void brcmf_rxreorder_process_info
rfi = kzalloc(buf_size, GFP_ATOMIC);
if (rfi == NULL) {
brcmf_err("failed to alloc buffer\n");
-   brcmf_netif_rx(ifp, pkt, false);
+   brcmf_netif_rx(ifp, pkt);
return;
}
 
@@ -523,11 +516,11 @@ static void brcmf_rxreorder_process_info
 netif_rx:
skb_queue_walk_safe(_list, pkt, pnext) {
__skb_unlink(pkt, _list);
-   brcmf_netif_rx(ifp, pkt, false);
+   brcmf_netif_rx(ifp, pkt);
}
 }
 
-void brcmf_rx_frame(struct device *dev, struct sk_buff *skb, bool handle_evnt)
+void brcmf_rx_frame(struct device *dev, struct sk_buff *skb, bool handle_event)
 {
struct brcmf_if *ifp;
struct brcmf_bus *bus_if = dev_get_drvdata(dev);
@@ -547,11 +540,18 @@ void brcmf_rx_frame(struct device *dev,
return;
}
 
+   skb->protocol = eth_type_trans(skb, ifp->ndev);
+
rd = (struct brcmf_skb_reorder_data *)skb->cb;
-   if (rd->reorder)
+   if (rd->reorder) {
brcmf_rxreorder_process_info(ifp, rd->reorder, skb);
-   else
-   brcmf_netif_rx(ifp, skb, handle_evnt);
+   } else {
+   /* Process special event packets */
+   if (handle_event)
+   brcmf_fweh_process_skb(ifp->drvr, skb);
+
+   brcmf_netif_rx(ifp, skb);
+   }
 }
 
 void brcmf_rx_event(struct device *dev, struct sk_buff *skb)
--- a/drivers/net/wireless/brcm80211/brcmfmac/core.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/core.h
@@ -215,8 +215,7 @@ int brcmf_get_next_free_bsscfgidx(struct
 void brcmf_txflowblock_if(struct brcmf_if *ifp,
  enum brcmf_netif_stop_reason reason, bool state);
 void brcmf_txfinalize(struct brcmf_if *ifp, struct sk_buff *txp, bool success);
-void brcmf_netif_rx(struct 

[PATCH 4.4 215/241] binder: replace "%p" with "%pK"

2019-06-09 Thread Greg Kroah-Hartman
From: Todd Kjos 

commit 8ca86f1639ec5890d400fff9211aca22d0a392eb upstream.

The format specifier "%p" can leak kernel addresses. Use
"%pK" instead. There were 4 remaining cases in binder.c.

Signed-off-by: Todd Kjos 
Signed-off-by: Greg Kroah-Hartman 
[bwh: Backported to 4.4: adjust context]
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/android/binder.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -1249,7 +1249,7 @@ static void binder_transaction_buffer_re
int debug_id = buffer->debug_id;
 
binder_debug(BINDER_DEBUG_TRANSACTION,
-"%d buffer release %d, size %zd-%zd, failed at %p\n",
+"%d buffer release %d, size %zd-%zd, failed at %pK\n",
 proc->pid, buffer->debug_id,
 buffer->data_size, buffer->offsets_size, failed_at);
 
@@ -2105,7 +2105,7 @@ static int binder_thread_write(struct bi
}
}
binder_debug(BINDER_DEBUG_DEAD_BINDER,
-"%d:%d BC_DEAD_BINDER_DONE %016llx found 
%p\n",
+"%d:%d BC_DEAD_BINDER_DONE %016llx found 
%pK\n",
 proc->pid, thread->pid, (u64)cookie,
 death);
if (death == NULL) {
@@ -3249,7 +3249,7 @@ static void print_binder_transaction(str
 struct binder_transaction *t)
 {
seq_printf(m,
-  "%s %d: %p from %d:%d to %d:%d code %x flags %x pri %ld r%d",
+  "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld 
r%d",
   prefix, t->debug_id, t,
   t->from ? t->from->proc->pid : 0,
   t->from ? t->from->pid : 0,
@@ -3263,7 +3263,7 @@ static void print_binder_transaction(str
if (t->buffer->target_node)
seq_printf(m, " node %d",
   t->buffer->target_node->debug_id);
-   seq_printf(m, " size %zd:%zd data %p\n",
+   seq_printf(m, " size %zd:%zd data %pK\n",
   t->buffer->data_size, t->buffer->offsets_size,
   t->buffer->data);
 }




[PATCH 4.4 190/241] Revert "tipc: fix modprobe tipc failed after switch order of device registration"

2019-06-09 Thread Greg Kroah-Hartman
From: David S. Miller 

commit 5593530e56943182ebb6d81eca8a3be6db6dbba4 upstream.

This reverts commit 532b0f7ece4cb2ffd24dc723ddf55242d1188e5e.

More revisions coming up.

Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 

---
 net/tipc/core.c |   14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -61,10 +61,6 @@ static int __net_init tipc_init_net(stru
INIT_LIST_HEAD(>node_list);
spin_lock_init(>node_list_lock);
 
-   err = tipc_socket_init();
-   if (err)
-   goto out_socket;
-
err = tipc_sk_rht_init(net);
if (err)
goto out_sk_rht;
@@ -91,8 +87,6 @@ out_subscr:
 out_nametbl:
tipc_sk_rht_destroy(net);
 out_sk_rht:
-   tipc_socket_stop();
-out_socket:
return err;
 }
 
@@ -103,7 +97,6 @@ static void __net_exit tipc_exit_net(str
tipc_bcast_stop(net);
tipc_nametbl_stop(net);
tipc_sk_rht_destroy(net);
-   tipc_socket_stop();
 }
 
 static struct pernet_operations tipc_net_ops = {
@@ -141,6 +134,10 @@ static int __init tipc_init(void)
if (err)
goto out_pernet;
 
+   err = tipc_socket_init();
+   if (err)
+   goto out_socket;
+
err = tipc_bearer_setup();
if (err)
goto out_bearer;
@@ -148,6 +145,8 @@ static int __init tipc_init(void)
pr_info("Started in single node mode\n");
return 0;
 out_bearer:
+   tipc_socket_stop();
+out_socket:
unregister_pernet_subsys(_net_ops);
 out_pernet:
tipc_unregister_sysctl();
@@ -163,6 +162,7 @@ out_netlink:
 static void __exit tipc_exit(void)
 {
tipc_bearer_cleanup();
+   tipc_socket_stop();
unregister_pernet_subsys(_net_ops);
tipc_netlink_stop();
tipc_netlink_compat_stop();




[PATCH 4.4 189/241] xen/pciback: Dont disable PCI_COMMAND on PCI device reset.

2019-06-09 Thread Greg Kroah-Hartman
From: Konrad Rzeszutek Wilk 

commit 7681f31ec9cdacab4fd10570be924f2cef6669ba upstream.

There is no need for this at all. Worst it means that if
the guest tries to write to BARs it could lead (on certain
platforms) to PCI SERR errors.

Please note that with af6fc858a35b90e89ea7a7ee58e66628c55c776b
"xen-pciback: limit guest control of command register"
a guest is still allowed to enable those control bits (safely), but
is not allowed to disable them and that therefore a well behaved
frontend which enables things before using them will still
function correctly.

This is done via an write to the configuration register 0x4 which
triggers on the backend side:
command_write
  \- pci_enable_device
 \- pci_enable_device_flags
\- do_pci_enable_device
   \- pcibios_enable_device
  \-pci_enable_resourcess
[which enables the PCI_COMMAND_MEMORY|PCI_COMMAND_IO]

However guests (and drivers) which don't do this could cause
problems, including the security issues which XSA-120 sought
to address.

Reported-by: Jan Beulich 
Signed-off-by: Konrad Rzeszutek Wilk 
Reviewed-by: Prarit Bhargava 
Signed-off-by: Juergen Gross 
Cc: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/xen/xen-pciback/pciback_ops.c |2 --
 1 file changed, 2 deletions(-)

--- a/drivers/xen/xen-pciback/pciback_ops.c
+++ b/drivers/xen/xen-pciback/pciback_ops.c
@@ -126,8 +126,6 @@ void xen_pcibk_reset_device(struct pci_d
if (pci_is_enabled(dev))
pci_disable_device(dev);
 
-   pci_write_config_word(dev, PCI_COMMAND, 0);
-
dev->is_busmaster = 0;
} else {
pci_read_config_word(dev, PCI_COMMAND, );




[PATCH 4.4 226/241] net: cdc_ncm: GetNtbFormat endian fix

2019-06-09 Thread Greg Kroah-Hartman
From: Bjørn Mork 

commit 6314dab4b8fb8493d810e175cb340376052c69b6 upstream.

The GetNtbFormat and SetNtbFormat requests operate on 16 bit little
endian values. We get away with ignoring this most of the time, because
we only care about USB_CDC_NCM_NTB16_FORMAT which is 0x.  This
fails for USB_CDC_NCM_NTB32_FORMAT.

Fix comparison between LE value from device and constant by converting
the constant to LE.

Reported-by: Ben Hutchings 
Fixes: 2b02c20ce0c2 ("cdc_ncm: Set NTB format again after altsetting switch for 
Huawei devices")
Cc: Enrico Mioso 
Cc: Christian Panton 
Signed-off-by: Bjørn Mork 
Acked-By: Enrico Mioso 
Signed-off-by: David S. Miller 
Signed-off-by: Nobuhiro Iwamatsu 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/net/usb/cdc_ncm.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -727,7 +727,7 @@ int cdc_ncm_bind_common(struct usbnet *d
int err;
u8 iface_no;
struct usb_cdc_parsed_header hdr;
-   u16 curr_ntb_format;
+   __le16 curr_ntb_format;
 
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx)
@@ -841,7 +841,7 @@ int cdc_ncm_bind_common(struct usbnet *d
goto error2;
}
 
-   if (curr_ntb_format == USB_CDC_NCM_NTB32_FORMAT) {
+   if (curr_ntb_format == cpu_to_le16(USB_CDC_NCM_NTB32_FORMAT)) {
dev_info(>dev, "resetting NTB format to 16-bit");
err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_FORMAT,
   USB_TYPE_CLASS | USB_DIR_OUT




[PATCH 4.4 221/241] brcmfmac: fix incorrect event channel deduction

2019-06-09 Thread Greg Kroah-Hartman
From: Gavin Li 

commit 8e290cecdd0178f3d4cf7d463c51dc7e462843b4 upstream.

brcmf_sdio_fromevntchan() was being called on the the data frame
rather than the software header, causing some frames to be
mischaracterized as on the event channel rather than the data channel.

This fixes a major performance regression (due to dropped packets). With
this patch the download speed jumped from 1Mbit/s back up to 40MBit/s due
to the sheer amount of packets being incorrectly processed.

Fixes: c56caa9db8ab ("brcmfmac: screening firmware event packet")
Signed-off-by: Gavin Li 
Acked-by: Arend van Spriel 
[kv...@codeaurora.org: improve commit logs based on email discussion]
Signed-off-by: Kalle Valo 
[bwh: Backported to 4.4: adjust filename]
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/wireless/brcm80211/brcmfmac/sdio.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
@@ -1765,7 +1765,7 @@ static u8 brcmf_sdio_rxglom(struct brcmf
   pfirst->len, pfirst->next,
   pfirst->prev);
skb_unlink(pfirst, >glom);
-   if (brcmf_sdio_fromevntchan(pfirst->data))
+   if (brcmf_sdio_fromevntchan([SDPCM_HWHDR_LEN]))
brcmf_rx_event(bus->sdiodev->dev, pfirst);
else
brcmf_rx_frame(bus->sdiodev->dev, pfirst,




[PATCH 4.4 217/241] bnx2x: disable GSO where gso_size is too big for hardware

2019-06-09 Thread Greg Kroah-Hartman
From: Daniel Axtens 

commit 8914a595110a6eca69a5e275b323f5d09e18f4f9 upstream.

If a bnx2x card is passed a GSO packet with a gso_size larger than
~9700 bytes, it will cause a firmware error that will bring the card
down:

bnx2x: [bnx2x_attn_int_deasserted3:4323(enP24p1s0f0)]MC assert!
bnx2x: [bnx2x_mc_assert:720(enP24p1s0f0)]XSTORM_ASSERT_LIST_INDEX 0x2
bnx2x: [bnx2x_mc_assert:736(enP24p1s0f0)]XSTORM_ASSERT_INDEX 0x0 = 0x 
0x25e43e47 0x00463e01 0x00010052
bnx2x: [bnx2x_mc_assert:750(enP24p1s0f0)]Chip Revision: everest3, FW Version: 
7_13_1
... (dump of values continues) ...

Detect when the mac length of a GSO packet is greater than the maximum
packet size (9700 bytes) and disable GSO.

Signed-off-by: Daniel Axtens 
Reviewed-by: Eric Dumazet 
Signed-off-by: David S. Miller 
Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c |   18 ++
 1 file changed, 18 insertions(+)

--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -12824,6 +12824,24 @@ static netdev_features_t bnx2x_features_
  struct net_device *dev,
  netdev_features_t features)
 {
+   /*
+* A skb with gso_size + header length > 9700 will cause a
+* firmware panic. Drop GSO support.
+*
+* Eventually the upper layer should not pass these packets down.
+*
+* For speed, if the gso_size is <= 9000, assume there will
+* not be 700 bytes of headers and pass it through. Only do a
+* full (slow) validation if the gso_size is > 9000.
+*
+* (Due to the way SKB_BY_FRAGS works this will also do a full
+* validation in that case.)
+*/
+   if (unlikely(skb_is_gso(skb) &&
+(skb_shinfo(skb)->gso_size > 9000) &&
+!skb_gso_validate_mac_len(skb, 9700)))
+   features &= ~NETIF_F_GSO_MASK;
+
features = vlan_features_check(skb, features);
return vxlan_features_check(skb, features);
 }




[PATCH 4.4 209/241] tty: serial: msm_serial: Fix XON/XOFF

2019-06-09 Thread Greg Kroah-Hartman
From: Jorge Ramirez-Ortiz 

commit 61c0e37950b88bad590056286c1d766b1f167f4e upstream.

When the tty layer requests the uart to throttle, the current code
executing in msm_serial will trigger "Bad mode in Error Handler" and
generate an invalid stack frame in pstore before rebooting (that is if
pstore is indeed configured: otherwise the user shall just notice a
reboot with no further information dumped to the console).

This patch replaces the PIO byte accessor with the word accessor
already used in PIO mode.

Fixes: 68252424a7c7 ("tty: serial: msm: Support big-endian CPUs")
Cc: sta...@vger.kernel.org
Signed-off-by: Jorge Ramirez-Ortiz 
Reviewed-by: Bjorn Andersson 
Reviewed-by: Stephen Boyd 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/tty/serial/msm_serial.c |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/drivers/tty/serial/msm_serial.c
+++ b/drivers/tty/serial/msm_serial.c
@@ -703,6 +703,7 @@ static void msm_handle_tx(struct uart_po
struct circ_buf *xmit = _port->uart.state->xmit;
struct msm_dma *dma = _port->tx_dma;
unsigned int pio_count, dma_count, dma_min;
+   char buf[4] = { 0 };
void __iomem *tf;
int err = 0;
 
@@ -712,10 +713,12 @@ static void msm_handle_tx(struct uart_po
else
tf = port->membase + UART_TF;
 
+   buf[0] = port->x_char;
+
if (msm_port->is_uartdm)
msm_reset_dm_count(port, 1);
 
-   iowrite8_rep(tf, >x_char, 1);
+   iowrite32_rep(tf, buf, 1);
port->icount.tx++;
port->x_char = 0;
return;




[PATCH 4.4 213/241] CIFS: cifs_read_allocate_pages: dont iterate through whole page array on ENOMEM

2019-06-09 Thread Greg Kroah-Hartman
From: Roberto Bergantinos Corpas 

commit 31fad7d41e73731f05b8053d17078638cf850fa6 upstream.

 In cifs_read_allocate_pages, in case of ENOMEM, we go through
whole rdata->pages array but we have failed the allocation before
nr_pages, therefore we may end up calling put_page with NULL
pointer, causing oops

Signed-off-by: Roberto Bergantinos Corpas 
Acked-by: Pavel Shilovsky 
Signed-off-by: Steve French 
CC: Stable 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/cifs/file.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2829,7 +2829,9 @@ cifs_read_allocate_pages(struct cifs_rea
}
 
if (rc) {
-   for (i = 0; i < nr_pages; i++) {
+   unsigned int nr_page_failed = i;
+
+   for (i = 0; i < nr_page_failed; i++) {
put_page(rdata->pages[i]);
rdata->pages[i] = NULL;
}




[PATCH 4.4 214/241] binder: Replace "%p" with "%pK" for stable

2019-06-09 Thread Greg Kroah-Hartman
From: Ben Hutchings 

This was done as part of upstream commits fdfb4a99b6ab "8inder:
separate binder allocator structure from binder proc", 19c987241ca1
"binder: separate out binder_alloc functions", and 7a4408c6bd3e
"binder: make sure accesses to proc/thread are safe".  However, those
commits made lots of other changes that are not suitable for stable.

Signed-off-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/android/binder.c |   28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -477,7 +477,7 @@ static void binder_insert_free_buffer(st
new_buffer_size = binder_buffer_size(proc, new_buffer);
 
binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-"%d: add free buffer, size %zd, at %p\n",
+"%d: add free buffer, size %zd, at %pK\n",
  proc->pid, new_buffer_size, new_buffer);
 
while (*p) {
@@ -555,7 +555,7 @@ static int binder_update_page_range(stru
struct mm_struct *mm;
 
binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-"%d: %s pages %p-%p\n", proc->pid,
+"%d: %s pages %pK-%pK\n", proc->pid,
 allocate ? "allocate" : "free", start, end);
 
if (end <= start)
@@ -595,7 +595,7 @@ static int binder_update_page_range(stru
BUG_ON(*page);
*page = alloc_page(GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
if (*page == NULL) {
-   pr_err("%d: binder_alloc_buf failed for page at %p\n",
+   pr_err("%d: binder_alloc_buf failed for page at %pK\n",
proc->pid, page_addr);
goto err_alloc_page_failed;
}
@@ -604,7 +604,7 @@ static int binder_update_page_range(stru
flush_cache_vmap((unsigned long)page_addr,
(unsigned long)page_addr + PAGE_SIZE);
if (ret != 1) {
-   pr_err("%d: binder_alloc_buf failed to map page at %p 
in kernel\n",
+   pr_err("%d: binder_alloc_buf failed to map page at %pK 
in kernel\n",
   proc->pid, page_addr);
goto err_map_kernel_failed;
}
@@ -708,7 +708,7 @@ static struct binder_buffer *binder_allo
}
 
binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-"%d: binder_alloc_buf size %zd got buffer %p size %zd\n",
+"%d: binder_alloc_buf size %zd got buffer %pK size %zd\n",
  proc->pid, size, buffer, buffer_size);
 
has_page_addr =
@@ -738,7 +738,7 @@ static struct binder_buffer *binder_allo
binder_insert_free_buffer(proc, new_buffer);
}
binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-"%d: binder_alloc_buf size %zd got %p\n",
+"%d: binder_alloc_buf size %zd got %pK\n",
  proc->pid, size, buffer);
buffer->data_size = data_size;
buffer->offsets_size = offsets_size;
@@ -778,7 +778,7 @@ static void binder_delete_free_buffer(st
if (buffer_end_page(prev) == buffer_end_page(buffer))
free_page_end = 0;
binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-"%d: merge free, buffer %p share page with %p\n",
+"%d: merge free, buffer %pK share page with %pK\n",
  proc->pid, buffer, prev);
}
 
@@ -791,14 +791,14 @@ static void binder_delete_free_buffer(st
buffer_start_page(buffer))
free_page_start = 0;
binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-"%d: merge free, buffer %p share page with 
%p\n",
+"%d: merge free, buffer %pK share page 
with %pK\n",
  proc->pid, buffer, prev);
}
}
list_del(>entry);
if (free_page_start || free_page_end) {
binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-"%d: merge free, buffer %p do not share page%s%s 
with %p or %p\n",
+"%d: merge free, buffer %pK do not share page%s%s 
with %pK or %pK\n",
 proc->pid, buffer, free_page_start ? "" : " end",
 free_page_end ? "" : " start", prev, next);
binder_update_page_range(proc, 0, free_page_start ?
@@ -819,7 +819,7 @@ static void binder_free_buf(struct binde
ALIGN(buffer->offsets_size, sizeof(void *));
 
binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-"%d: binder_free_buf %p size %zd buffer_size %zd\n",
+"%d: binder_free_buf %pK size %zd buffer_size 

[PATCH 4.4 185/241] tipc: Avoid copying bytes beyond the supplied data

2019-06-09 Thread Greg Kroah-Hartman
From: Chris Packham 

TLV_SET is called with a data pointer and a len parameter that tells us
how many bytes are pointed to by data. When invoking memcpy() we need
to careful to only copy len bytes.

Previously we would copy TLV_LENGTH(len) bytes which would copy an extra
4 bytes past the end of the data pointer which newer GCC versions
complain about.

 In file included from test.c:17:
 In function 'TLV_SET',
 inlined from 'test' at test.c:186:5:
 /usr/include/linux/tipc_config.h:317:3:
 warning: 'memcpy' forming offset [33, 36] is out of the bounds [0, 32]
 of object 'bearer_name' with type 'char[32]' [-Warray-bounds]
 memcpy(TLV_DATA(tlv_ptr), data, tlv_len);
 ^~~~
 test.c: In function 'test':
 test.c::161:10: note:
 'bearer_name' declared here
 char bearer_name[TIPC_MAX_BEARER_NAME];
  ^~~

We still want to ensure any padding bytes at the end are initialised, do
this with a explicit memset() rather than copy bytes past the end of
data. Apply the same logic to TCM_SET.

Signed-off-by: Chris Packham 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 include/uapi/linux/tipc_config.h |   10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

--- a/include/uapi/linux/tipc_config.h
+++ b/include/uapi/linux/tipc_config.h
@@ -301,8 +301,10 @@ static inline int TLV_SET(void *tlv, __u
tlv_ptr = (struct tlv_desc *)tlv;
tlv_ptr->tlv_type = htons(type);
tlv_ptr->tlv_len  = htons(tlv_len);
-   if (len && data)
-   memcpy(TLV_DATA(tlv_ptr), data, tlv_len);
+   if (len && data) {
+   memcpy(TLV_DATA(tlv_ptr), data, len);
+   memset(TLV_DATA(tlv_ptr) + len, 0, TLV_SPACE(len) - tlv_len);
+   }
return TLV_SPACE(len);
 }
 
@@ -399,8 +401,10 @@ static inline int TCM_SET(void *msg, __u
tcm_hdr->tcm_len   = htonl(msg_len);
tcm_hdr->tcm_type  = htons(cmd);
tcm_hdr->tcm_flags = htons(flags);
-   if (data_len && data)
+   if (data_len && data) {
memcpy(TCM_DATA(msg), data, data_len);
+   memset(TCM_DATA(msg) + data_len, 0, TCM_SPACE(data_len) - 
msg_len);
+   }
return TCM_SPACE(data_len);
 }
 




[PATCH 4.4 201/241] media: usb: siano: Fix general protection fault in smsusb

2019-06-09 Thread Greg Kroah-Hartman
From: Alan Stern 

commit 31e0456de5be379b10fea0fa94a681057114a96e upstream.

The syzkaller USB fuzzer found a general-protection-fault bug in the
smsusb part of the Siano DVB driver.  The fault occurs during probe
because the driver assumes without checking that the device has both
IN and OUT endpoints and the IN endpoint is ep1.

By slightly rearranging the driver's initialization code, we can make
the appropriate checks early on and thus avoid the problem.  If the
expected endpoints aren't present, the new code safely returns -ENODEV
from the probe routine.

Signed-off-by: Alan Stern 
Reported-and-tested-by: syzbot+53f029db71c19a473...@syzkaller.appspotmail.com
CC: 
Reviewed-by: Johan Hovold 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/media/usb/siano/smsusb.c |   33 -
 1 file changed, 20 insertions(+), 13 deletions(-)

--- a/drivers/media/usb/siano/smsusb.c
+++ b/drivers/media/usb/siano/smsusb.c
@@ -391,6 +391,7 @@ static int smsusb_init_device(struct usb
struct smsusb_device_t *dev;
void *mdev;
int i, rc;
+   int in_maxp;
 
/* create device object */
dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);
@@ -402,6 +403,24 @@ static int smsusb_init_device(struct usb
dev->udev = interface_to_usbdev(intf);
dev->state = SMSUSB_DISCONNECTED;
 
+   for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
+   struct usb_endpoint_descriptor *desc =
+   >cur_altsetting->endpoint[i].desc;
+
+   if (desc->bEndpointAddress & USB_DIR_IN) {
+   dev->in_ep = desc->bEndpointAddress;
+   in_maxp = usb_endpoint_maxp(desc);
+   } else {
+   dev->out_ep = desc->bEndpointAddress;
+   }
+   }
+
+   pr_debug("in_ep = %02x, out_ep = %02x\n", dev->in_ep, dev->out_ep);
+   if (!dev->in_ep || !dev->out_ep) {  /* Missing endpoints? */
+   smsusb_term_device(intf);
+   return -ENODEV;
+   }
+
params.device_type = sms_get_board(board_id)->type;
 
switch (params.device_type) {
@@ -416,24 +435,12 @@ static int smsusb_init_device(struct usb
/* fall-thru */
default:
dev->buffer_size = USB2_BUFFER_SIZE;
-   dev->response_alignment =
-   le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) -
-   sizeof(struct sms_msg_hdr);
+   dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr);
 
params.flags |= SMS_DEVICE_FAMILY2;
break;
}
 
-   for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
-   if (intf->cur_altsetting->endpoint[i].desc. bEndpointAddress & 
USB_DIR_IN)
-   dev->in_ep = 
intf->cur_altsetting->endpoint[i].desc.bEndpointAddress;
-   else
-   dev->out_ep = 
intf->cur_altsetting->endpoint[i].desc.bEndpointAddress;
-   }
-
-   pr_debug("in_ep = %02x, out_ep = %02x\n",
-   dev->in_ep, dev->out_ep);
-
params.device = >udev->dev;
params.buffer_size = dev->buffer_size;
params.num_buffers = MAX_BUFFERS;




[PATCH 4.4 186/241] bnxt_en: Fix aggregation buffer leak under OOM condition.

2019-06-09 Thread Greg Kroah-Hartman
From: Michael Chan 

[ Upstream commit 296d5b54163964b7ae536b8b57dfbd21d4e868e1 ]

For every RX packet, the driver replenishes all buffers used for that
packet and puts them back into the RX ring and RX aggregation ring.
In one code path where the RX packet has one RX buffer and one or more
aggregation buffers, we missed recycling the aggregation buffer(s) if
we are unable to allocate a new SKB buffer.  This leads to the
aggregation ring slowly running out of buffers over time.  Fix it
by properly recycling the aggregation buffers.

Fixes: c0c050c58d84 ("bnxt_en: New Broadcom ethernet driver.")
Reported-by: Rakesh Hemnani 
Signed-off-by: Michael Chan 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c |2 ++
 1 file changed, 2 insertions(+)

--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -1140,6 +1140,8 @@ static int bnxt_rx_pkt(struct bnxt *bp,
skb = bnxt_copy_skb(bnapi, data, len, dma_addr);
bnxt_reuse_rx_data(rxr, cons, data);
if (!skb) {
+   if (agg_bufs)
+   bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, 
agg_bufs);
rc = -ENOMEM;
goto next_rx;
}




[PATCH 4.4 208/241] drm/nouveau/i2c: Disable i2c bus access after ->fini()

2019-06-09 Thread Greg Kroah-Hartman
From: Lyude Paul 

commit 342406e4fbba9a174125fbfe6aeac3d64ef90f76 upstream.

For a while, we've had the problem of i2c bus access not grabbing
a runtime PM ref when it's being used in userspace by i2c-dev, resulting
in nouveau spamming the kernel log with errors if anything attempts to
access the i2c bus while the GPU is in runtime suspend. An example:

[  130.078386] nouveau :01:00.0: i2c: aux 000d: begin idle timeout 

Since the GPU is in runtime suspend, the MMIO region that the i2c bus is
on isn't accessible. On x86, the standard behavior for accessing an
unavailable MMIO region is to just return ~0.

Except, that turned out to be a lie. While computers with a clean
concious will return ~0 in this scenario, some machines will actually
completely hang a CPU on certian bad MMIO accesses. This was witnessed
with someone's Lenovo ThinkPad P50, where sensors-detect attempting to
access the i2c bus while the GPU was suspended would result in a CPU
hang:

  CPU: 5 PID: 12438 Comm: sensors-detect Not tainted 
5.0.0-0.rc4.git3.1.fc30.x86_64 #1
  Hardware name: LENOVO 20EQS64N17/20EQS64N17, BIOS N1EET74W (1.47 ) 11/21/2017
  RIP: 0010:ioread32+0x2b/0x30
  Code: 81 ff ff ff 03 00 77 20 48 81 ff 00 00 01 00 76 05 0f b7 d7 ed c3
  48 c7 c6 e1 0c 36 96 e8 2d ff ff ff b8 ff ff ff ff c3 8b 07  0f 1f
  40 00 49 89 f0 48 81 fe ff ff 03 00 76 04 40 88 3e c3 48
  RSP: 0018:aac3c5007b48 EFLAGS: 0292 ORIG_RAX: ff13
  RAX: 0000 RBX: 0000 RCX: 043017a97186
  RDX: 0aaa RSI: 0005 RDI: aac3c400e4e4
  RBP: 9e6443902c00 R08: aac3c400e4e4 R09: aac3c5007be7
  R10: 0004 R11: 0001 R12: 9e6445dd
  R13: e4e4 R14: 03c4 R15: 
  FS:  7f253155a740() GS:9e644f60() knlGS:
  CS:  0010 DS:  ES:  CR0: 80050033
  CR2: 5630d1500358 CR3: 000417c44006 CR4: 003606e0
  DR0:  DR1:  DR2: 
  DR3:  DR6: fffe0ff0 DR7: 0400
  Call Trace:
   g94_i2c_aux_xfer+0x326/0x850 [nouveau]
   nvkm_i2c_aux_i2c_xfer+0x9e/0x140 [nouveau]
   __i2c_transfer+0x14b/0x620
   i2c_smbus_xfer_emulated+0x159/0x680
   ? _raw_spin_unlock_irqrestore+0x1/0x60
   ? rt_mutex_slowlock.constprop.0+0x13d/0x1e0
   ? __lock_is_held+0x59/0xa0
   __i2c_smbus_xfer+0x138/0x5a0
   i2c_smbus_xfer+0x4f/0x80
   i2cdev_ioctl_smbus+0x162/0x2d0 [i2c_dev]
   i2cdev_ioctl+0x1db/0x2c0 [i2c_dev]
   do_vfs_ioctl+0x408/0x750
   ksys_ioctl+0x5e/0x90
   __x64_sys_ioctl+0x16/0x20
   do_syscall_64+0x60/0x1e0
   entry_SYSCALL_64_after_hwframe+0x49/0xbe
  RIP: 0033:0x7f25317f546b
  Code: 0f 1e fa 48 8b 05 1d da 0c 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff
  ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa b8 10 00 00 00 0f 05 <48> 3d 01
  f0 ff ff 73 01 c3 48 8b 0d ed d9 0c 00 f7 d8 64 89 01 48
  RSP: 002b:7ffc88caab68 EFLAGS: 0246 ORIG_RAX: 0010
  RAX: ffda RBX: 5630d0fe7260 RCX: 7f25317f546b
  RDX: 5630d1598e80 RSI: 0720 RDI: 0003
  RBP: 5630d155b968 R08: 0001 R09: 5630d15a1da0
  R10: 0070 R11: 0246 R12: 5630d1598e80
  R13: 5630d12f3d28 R14: 0720 R15: 5630d12f3ce0
  watchdog: BUG: soft lockup - CPU#5 stuck for 23s! [sensors-detect:12438]

Yikes! While I wanted to try to make it so that accessing an i2c bus on
nouveau would wake up the GPU as needed, airlied pointed out that pretty
much any usecase for userspace accessing an i2c bus on a GPU (mainly for
the DDC brightness control that some displays have) is going to only be
useful while there's at least one display enabled on the GPU anyway, and
the GPU never sleeps while there's displays running.

Since teaching the i2c bus to wake up the GPU on userspace accesses is a
good deal more difficult than it might seem, mostly due to the fact that
we have to use the i2c bus during runtime resume of the GPU, we instead
opt for the easiest solution: don't let userspace access i2c busses on
the GPU at all while it's in runtime suspend.

Changes since v1:
* Also disable i2c busses that run over DP AUX

Signed-off-by: Lyude Paul 
Cc: sta...@vger.kernel.org
Signed-off-by: Ben Skeggs 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h |2 +
 drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c |   26 +-
 drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.h |2 +
 drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c|   15 
 drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.c |   21 -
 drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.h |1 
 6 files changed, 65 insertions(+), 2 deletions(-)

--- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h
+++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h
@@ -37,6 +37,7 @@ struct nvkm_i2c_bus {

[PATCH 4.4 204/241] scsi: zfcp: fix missing zfcp_port reference put on -EBUSY from port_remove

2019-06-09 Thread Greg Kroah-Hartman
From: Steffen Maier 

commit d27e5e07f9c49bf2a6a4ef254ce531c1b4fb5a38 upstream.

With this early return due to zfcp_unit child(ren), we don't use the
zfcp_port reference from the earlier zfcp_get_port_by_wwpn() anymore and
need to put it.

Signed-off-by: Steffen Maier 
Fixes: d99b601b6338 ("[SCSI] zfcp: restore refcount check on port_remove")
Cc:  #3.7+
Reviewed-by: Jens Remus 
Reviewed-by: Benjamin Block 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/s390/scsi/zfcp_sysfs.c |1 +
 1 file changed, 1 insertion(+)

--- a/drivers/s390/scsi/zfcp_sysfs.c
+++ b/drivers/s390/scsi/zfcp_sysfs.c
@@ -263,6 +263,7 @@ static ssize_t zfcp_sysfs_port_remove_st
if (atomic_read(>units) > 0) {
retval = -EBUSY;
mutex_unlock(_sysfs_port_units_mutex);
+   put_device(>dev); /* undo zfcp_get_port_by_wwpn() */
goto out;
}
/* port is about to be removed, so no more unit_add */




[PATCH 4.4 205/241] scsi: zfcp: fix to prevent port_remove with pure auto scan LUNs (only sdevs)

2019-06-09 Thread Greg Kroah-Hartman
From: Steffen Maier 

commit ef4021fe5fd77ced0323cede27979d80a56211ca upstream.

When the user tries to remove a zfcp port via sysfs, we only rejected it if
there are zfcp unit children under the port. With purely automatically
scanned LUNs there are no zfcp units but only SCSI devices. In such cases,
the port_remove erroneously continued. We close the port and this
implicitly closes all LUNs under the port. The SCSI devices survive with
their private zfcp_scsi_dev still holding a reference to the "removed"
zfcp_port (still allocated but invisible in sysfs) [zfcp_get_port_by_wwpn
in zfcp_scsi_slave_alloc]. This is not a problem as long as the fc_rport
stays blocked. Once (auto) port scan brings back the removed port, we
unblock its fc_rport again by design.  However, there is no mechanism that
would recover (open) the LUNs under the port (no "ersfs_3" without
zfcp_unit [zfcp_erp_strategy_followup_success]).  Any pending or new I/O to
such LUN leads to repeated:

  Done: NEEDS_RETRY Result: hostbyte=DID_IMM_RETRY driverbyte=DRIVER_OK

See also v4.10 commit 6f2ce1c6af37 ("scsi: zfcp: fix rport unblock race
with LUN recovery"). Even a manual LUN recovery
(echo 0 > /sys/bus/scsi/devices/H:C:T:L/zfcp_failed)
does not help, as the LUN links to the old "removed" port which remains
to lack ZFCP_STATUS_COMMON_RUNNING [zfcp_erp_required_act].
The only workaround is to first ensure that the fc_rport is blocked
(e.g. port_remove again in case it was re-discovered by (auto) port scan),
then delete the SCSI devices, and finally re-discover by (auto) port scan.
The port scan includes an fc_rport unblock, which in turn triggers
a new scan on the scsi target to freshly get new pure auto scan LUNs.

Fix this by rejecting port_remove also if there are SCSI devices
(even without any zfcp_unit) under this port. Re-use mechanics from v3.7
commit d99b601b6338 ("[SCSI] zfcp: restore refcount check on port_remove").
However, we have to give up zfcp_sysfs_port_units_mutex earlier in unit_add
to prevent a deadlock with scsi_host scan taking shost->scan_mutex first
and then zfcp_sysfs_port_units_mutex now in our zfcp_scsi_slave_alloc().

Signed-off-by: Steffen Maier 
Fixes: b62a8d9b45b9 ("[SCSI] zfcp: Use SCSI device data zfcp scsi dev instead 
of zfcp unit")
Fixes: f8210e34887e ("[SCSI] zfcp: Allow midlayer to scan for LUNs when running 
in NPIV mode")
Cc:  #2.6.37+
Reviewed-by: Benjamin Block 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/s390/scsi/zfcp_ext.h   |1 
 drivers/s390/scsi/zfcp_scsi.c  |9 ++
 drivers/s390/scsi/zfcp_sysfs.c |   54 -
 drivers/s390/scsi/zfcp_unit.c  |8 +-
 4 files changed, 65 insertions(+), 7 deletions(-)

--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -161,6 +161,7 @@ extern const struct attribute_group *zfc
 extern struct mutex zfcp_sysfs_port_units_mutex;
 extern struct device_attribute *zfcp_sysfs_sdev_attrs[];
 extern struct device_attribute *zfcp_sysfs_shost_attrs[];
+bool zfcp_sysfs_port_is_removing(const struct zfcp_port *const port);
 
 /* zfcp_unit.c */
 extern int zfcp_unit_add(struct zfcp_port *, u64);
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -124,6 +124,15 @@ static int zfcp_scsi_slave_alloc(struct
 
zfcp_sdev->erp_action.port = port;
 
+   mutex_lock(_sysfs_port_units_mutex);
+   if (zfcp_sysfs_port_is_removing(port)) {
+   /* port is already gone */
+   mutex_unlock(_sysfs_port_units_mutex);
+   put_device(>dev); /* undo zfcp_get_port_by_wwpn() */
+   return -ENXIO;
+   }
+   mutex_unlock(_sysfs_port_units_mutex);
+
unit = zfcp_unit_find(port, zfcp_scsi_dev_lun(sdev));
if (unit)
put_device(>dev);
--- a/drivers/s390/scsi/zfcp_sysfs.c
+++ b/drivers/s390/scsi/zfcp_sysfs.c
@@ -237,6 +237,53 @@ static ZFCP_DEV_ATTR(adapter, port_resca
 
 DEFINE_MUTEX(zfcp_sysfs_port_units_mutex);
 
+static void zfcp_sysfs_port_set_removing(struct zfcp_port *const port)
+{
+   lockdep_assert_held(_sysfs_port_units_mutex);
+   atomic_set(>units, -1);
+}
+
+bool zfcp_sysfs_port_is_removing(const struct zfcp_port *const port)
+{
+   lockdep_assert_held(_sysfs_port_units_mutex);
+   return atomic_read(>units) == -1;
+}
+
+static bool zfcp_sysfs_port_in_use(struct zfcp_port *const port)
+{
+   struct zfcp_adapter *const adapter = port->adapter;
+   unsigned long flags;
+   struct scsi_device *sdev;
+   bool in_use = true;
+
+   mutex_lock(_sysfs_port_units_mutex);
+   if (atomic_read(>units) > 0)
+   goto unlock_port_units_mutex; /* zfcp_unit(s) under port */
+
+   spin_lock_irqsave(adapter->scsi_host->host_lock, flags);
+   __shost_for_each_device(sdev, adapter->scsi_host) {
+   const struct zfcp_scsi_dev *zsdev = sdev_to_zfcp(sdev);
+
+   if (sdev->sdev_state == SDEV_DEL ||
+   

[PATCH 4.4 195/241] usb: xhci: avoid null pointer deref when bos field is NULL

2019-06-09 Thread Greg Kroah-Hartman
From: Carsten Schmid 

commit 7aa1bb2ffd84d6b9b5f546b079bb15cd0ab6e76e upstream.

With defective USB sticks we see the following error happen:
usb 1-3: new high-speed USB device number 6 using xhci_hcd
usb 1-3: device descriptor read/64, error -71
usb 1-3: device descriptor read/64, error -71
usb 1-3: new high-speed USB device number 7 using xhci_hcd
usb 1-3: device descriptor read/64, error -71
usb 1-3: unable to get BOS descriptor set
usb 1-3: New USB device found, idVendor=0781, idProduct=5581
usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
...
BUG: unable to handle kernel NULL pointer dereference at 0008

This comes from the following place:
[ 1660.215380] IP: xhci_set_usb2_hardware_lpm+0xdf/0x3d0 [xhci_hcd]
[ 1660.222092] PGD 0 P4D 0
[ 1660.224918] Oops:  [#1] PREEMPT SMP NOPTI
[ 1660.425520] CPU: 1 PID: 38 Comm: kworker/1:1 Tainted: P U  W  O
4.14.67-apl #1
[ 1660.434277] Workqueue: usb_hub_wq hub_event [usbcore]
[ 1660.439918] task: a295b6ae4c80 task.stack: ad458015
[ 1660.446532] RIP: 0010:xhci_set_usb2_hardware_lpm+0xdf/0x3d0 [xhci_hcd]
[ 1660.453821] RSP: 0018:ad4580153c70 EFLAGS: 00010046
[ 1660.459655] RAX:  RBX: a295b4d7c000 RCX: 0002
[ 1660.467625] RDX: 0002 RSI: 984a55b2 RDI: 984a55b2
[ 1660.475586] RBP: ad4580153cc8 R08: 00d6520a R09: 0001
[ 1660.483556] R10: ad4580a004a0 R11: 0286 R12: a295b4d7c000
[ 1660.491525] R13: 00010648 R14: a295a84e1800 R15: 
[ 1660.499494] FS:  () GS:a295bfc8() 
knlGS:
[ 1660.508530] CS:  0010 DS:  ES:  CR0: 80050033
[ 1660.514947] CR2: 0008 CR3: 00025a114000 CR4: 003406a0
[ 1660.522917] Call Trace:
[ 1660.525657]  usb_set_usb2_hardware_lpm+0x3d/0x70 [usbcore]
[ 1660.531792]  usb_disable_device+0x242/0x260 [usbcore]
[ 1660.537439]  usb_disconnect+0xc1/0x2b0 [usbcore]
[ 1660.542600]  hub_event+0x596/0x18f0 [usbcore]
[ 1660.547467]  ? trace_preempt_on+0xdf/0x100
[ 1660.552040]  ? process_one_work+0x1c1/0x410
[ 1660.556708]  process_one_work+0x1d2/0x410
[ 1660.561184]  ? preempt_count_add.part.3+0x21/0x60
[ 1660.566436]  worker_thread+0x2d/0x3f0
[ 1660.570522]  kthread+0x122/0x140
[ 1660.574123]  ? process_one_work+0x410/0x410
[ 1660.578792]  ? kthread_create_on_node+0x60/0x60
[ 1660.583849]  ret_from_fork+0x3a/0x50
[ 1660.587839] Code: 00 49 89 c3 49 8b 84 24 50 16 00 00 8d 4a ff 48 8d 04 c8 
48 89 ca 4c 8b 10 45 8b 6a 04 48 8b 00 48 89 45 c0 49 8b 86 80 03 00 00 <48> 8b 
40 08 8b 40 03 0f 1f 44 00 00 45 85 ff 0f 84 81 01 00 00
[ 1660.608980] RIP: xhci_set_usb2_hardware_lpm+0xdf/0x3d0 [xhci_hcd] RSP: 
ad4580153c70
[ 1660.617921] CR2: 0008

Tracking this down shows that udev->bos is NULL in the following code:
(xhci.c, in xhci_set_usb2_hardware_lpm)
field = le32_to_cpu(udev->bos->ext_cap->bmAttributes);  <<< here

xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n",
enable ? "enable" : "disable", port_num + 1);

if (enable) {
/* Host supports BESL timeout instead of HIRD */
if (udev->usb2_hw_lpm_besl_capable) {
/* if device doesn't have a preferred BESL value use a
 * default one which works with mixed HIRD and BESL
 * systems. See XHCI_DEFAULT_BESL definition in xhci.h
 */
if ((field & USB_BESL_SUPPORT) &&
(field & USB_BESL_BASELINE_VALID))
hird = USB_GET_BESL_BASELINE(field);
else
hird = udev->l1_params.besl;

The failing case is when disabling LPM. So it is sufficient to avoid
access to udev->bos by moving the instruction into the "enable" clause.

Cc: Stable 
Signed-off-by: Carsten Schmid 
Signed-off-by: Mathias Nyman 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/host/xhci.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4191,7 +4191,6 @@ int xhci_set_usb2_hardware_lpm(struct us
pm_addr = port_array[port_num] + PORTPMSC;
pm_val = readl(pm_addr);
hlpm_addr = port_array[port_num] + PORTHLPMC;
-   field = le32_to_cpu(udev->bos->ext_cap->bmAttributes);
 
xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n",
enable ? "enable" : "disable", port_num + 1);
@@ -4203,6 +4202,7 @@ int xhci_set_usb2_hardware_lpm(struct us
 * default one which works with mixed HIRD and BESL
 * systems. See XHCI_DEFAULT_BESL definition in xhci.h
 */
+   field = le32_to_cpu(udev->bos->ext_cap->bmAttributes);
if ((field & USB_BESL_SUPPORT) &&
 

[PATCH 4.4 196/241] USB: Fix slab-out-of-bounds write in usb_get_bos_descriptor

2019-06-09 Thread Greg Kroah-Hartman
From: Alan Stern 

commit a03ff54460817c76105f81f3aa8ef655759ccc9a upstream.

The syzkaller USB fuzzer found a slab-out-of-bounds write bug in the
USB core, caused by a failure to check the actual size of a BOS
descriptor.  This patch adds a check to make sure the descriptor is at
least as large as it is supposed to be, so that the code doesn't
inadvertently access memory beyond the end of the allocated region
when assigning to dev->bos->desc->bNumDeviceCaps later on.

Signed-off-by: Alan Stern 
Reported-and-tested-by: syzbot+71f1e64501a309fcc...@syzkaller.appspotmail.com
CC: 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/config.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -902,8 +902,8 @@ int usb_get_bos_descriptor(struct usb_de
 
/* Get BOS descriptor */
ret = usb_get_descriptor(dev, USB_DT_BOS, 0, bos, USB_DT_BOS_SIZE);
-   if (ret < USB_DT_BOS_SIZE) {
-   dev_err(ddev, "unable to get BOS descriptor\n");
+   if (ret < USB_DT_BOS_SIZE || bos->bLength < USB_DT_BOS_SIZE) {
+   dev_err(ddev, "unable to get BOS descriptor or descriptor too 
short\n");
if (ret >= 0)
ret = -ENOMSG;
kfree(bos);




[PATCH 4.4 198/241] USB: Add LPM quirk for Surface Dock GigE adapter

2019-06-09 Thread Greg Kroah-Hartman
From: Maximilian Luz 

commit ea261113385ac0a71c2838185f39e8452d54b152 upstream.

Without USB_QUIRK_NO_LPM ethernet will not work and rtl8152 will
complain with

r8152 : Stop submitting intr, status -71

Adding the quirk resolves this. As the dock is externally powered, this
should not have any drawbacks.

Signed-off-by: Maximilian Luz 
Cc: stable 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/quirks.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -64,6 +64,9 @@ static const struct usb_device_id usb_qu
/* Microsoft LifeCam-VX700 v2.0 */
{ USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME },
 
+   /* Microsoft Surface Dock Ethernet (RTL8153 GigE) */
+   { USB_DEVICE(0x045e, 0x07c6), .driver_info = USB_QUIRK_NO_LPM },
+
/* Cherry Stream G230 2.0 (G85-231) and 3.0 (G85-232) */
{ USB_DEVICE(0x046a, 0x0023), .driver_info = USB_QUIRK_RESET_RESUME },
 




[PATCH 4.4 197/241] USB: sisusbvga: fix oops in error path of sisusb_probe

2019-06-09 Thread Greg Kroah-Hartman
From: Oliver Neukum 

commit 9a5729f68d3a82786aea110b1bfe610be318f80a upstream.

The pointer used to log a failure of usb_register_dev() must
be set before the error is logged.

v2: fix that minor is not available before registration

Signed-off-by: oliver Neukum 
Reported-by: syzbot+a0cbdbd6d169020c8...@syzkaller.appspotmail.com
Fixes: 7b5cd5fefbe02 ("USB: SisUSB2VGA: Convert printk to dev_* macros")
Cc: stable 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/misc/sisusbvga/sisusb.c |   15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -3103,6 +3103,13 @@ static int sisusb_probe(struct usb_inter
 
mutex_init(&(sisusb->lock));
 
+   sisusb->sisusb_dev = dev;
+   sisusb->vrambase   = SISUSB_PCI_MEMBASE;
+   sisusb->mmiobase   = SISUSB_PCI_MMIOBASE;
+   sisusb->mmiosize   = SISUSB_PCI_MMIOSIZE;
+   sisusb->ioportbase = SISUSB_PCI_IOPORTBASE;
+   /* Everything else is zero */
+
/* Register device */
retval = usb_register_dev(intf, _sisusb_class);
if (retval) {
@@ -3112,13 +3119,7 @@ static int sisusb_probe(struct usb_inter
goto error_1;
}
 
-   sisusb->sisusb_dev = dev;
-   sisusb->minor  = intf->minor;
-   sisusb->vrambase   = SISUSB_PCI_MEMBASE;
-   sisusb->mmiobase   = SISUSB_PCI_MMIOBASE;
-   sisusb->mmiosize   = SISUSB_PCI_MMIOSIZE;
-   sisusb->ioportbase = SISUSB_PCI_IOPORTBASE;
-   /* Everything else is zero */
+   sisusb->minor = intf->minor;
 
/* Allocate buffers */
sisusb->ibufsize = SISUSB_IBUF_SIZE;




[PATCH 4.4 207/241] ALSA: hda/realtek - Set default power save node to 0

2019-06-09 Thread Greg Kroah-Hartman
From: Kailang Yang 

commit 317d9313925cd8388304286c0d3c8dda7f060a2d upstream.

I measured power consumption between power_save_node=1 and power_save_node=0.
It's almost the same.
Codec will enter to runtime suspend and suspend.
That pin also will enter to D3. Don't need to enter to D3 by single pin.
So, Disable power_save_node as default. It will avoid more issues.
Windows Driver also has not this option at runtime PM.

Signed-off-by: Kailang Yang 
Cc: 
Signed-off-by: Takashi Iwai 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/pci/hda/patch_realtek.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -6236,7 +6236,7 @@ static int patch_alc269(struct hda_codec
 
spec = codec->spec;
spec->gen.shared_mic_vref_pin = 0x18;
-   codec->power_save_node = 1;
+   codec->power_save_node = 0;
 
 #ifdef CONFIG_PM
codec->patch_ops.suspend = alc269_suspend;




[PATCH 4.4 199/241] USB: rio500: refuse more than one device at a time

2019-06-09 Thread Greg Kroah-Hartman
From: Oliver Neukum 

commit 3864d33943b4a76c6e64616280e98d2410b1190f upstream.

This driver is using a global variable. It cannot handle more than
one device at a time. The issue has been existing since the dawn
of the driver.

Signed-off-by: Oliver Neukum 
Reported-by: syzbot+35f04d136fc975a70...@syzkaller.appspotmail.com
Cc: stable 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/misc/rio500.c |   24 ++--
 1 file changed, 18 insertions(+), 6 deletions(-)

--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -464,15 +464,23 @@ static int probe_rio(struct usb_interfac
 {
struct usb_device *dev = interface_to_usbdev(intf);
struct rio_usb_data *rio = _instance;
-   int retval;
+   int retval = 0;
 
-   dev_info(>dev, "USB Rio found at address %d\n", dev->devnum);
+   mutex_lock(_mutex);
+   if (rio->present) {
+   dev_info(>dev, "Second USB Rio at address %d refused\n", 
dev->devnum);
+   retval = -EBUSY;
+   goto bail_out;
+   } else {
+   dev_info(>dev, "USB Rio found at address %d\n", 
dev->devnum);
+   }
 
retval = usb_register_dev(intf, _rio_class);
if (retval) {
dev_err(>dev,
"Not able to get a minor for this device.\n");
-   return -ENOMEM;
+   retval = -ENOMEM;
+   goto bail_out;
}
 
rio->rio_dev = dev;
@@ -481,7 +489,8 @@ static int probe_rio(struct usb_interfac
dev_err(>dev,
"probe_rio: Not enough memory for the output buffer\n");
usb_deregister_dev(intf, _rio_class);
-   return -ENOMEM;
+   retval = -ENOMEM;
+   goto bail_out;
}
dev_dbg(>dev, "obuf address:%p\n", rio->obuf);
 
@@ -490,7 +499,8 @@ static int probe_rio(struct usb_interfac
"probe_rio: Not enough memory for the input buffer\n");
usb_deregister_dev(intf, _rio_class);
kfree(rio->obuf);
-   return -ENOMEM;
+   retval = -ENOMEM;
+   goto bail_out;
}
dev_dbg(>dev, "ibuf address:%p\n", rio->ibuf);
 
@@ -498,8 +508,10 @@ static int probe_rio(struct usb_interfac
 
usb_set_intfdata (intf, rio);
rio->present = 1;
+bail_out:
+   mutex_unlock(_mutex);
 
-   return 0;
+   return retval;
 }
 
 static void disconnect_rio(struct usb_interface *intf)




[PATCH 4.4 202/241] media: usb: siano: Fix false-positive "uninitialized variable" warning

2019-06-09 Thread Greg Kroah-Hartman
From: Alan Stern 

commit 45457c01171fd1488a7000d1751c06ed8560ee38 upstream.

GCC complains about an apparently uninitialized variable recently
added to smsusb_init_device().  It's a false positive, but to silence
the warning this patch adds a trivial initialization.

Signed-off-by: Alan Stern 
Reported-by: kbuild test robot 
CC: 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/media/usb/siano/smsusb.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/media/usb/siano/smsusb.c
+++ b/drivers/media/usb/siano/smsusb.c
@@ -391,7 +391,7 @@ static int smsusb_init_device(struct usb
struct smsusb_device_t *dev;
void *mdev;
int i, rc;
-   int in_maxp;
+   int in_maxp = 0;
 
/* create device object */
dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);




[PATCH 4.4 145/241] cpufreq/pasemi: fix possible object reference leak

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit a9acc26b75f652f697e02a9febe2ab0da648a571 ]

The call to of_get_cpu_node returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./drivers/cpufreq/pasemi-cpufreq.c:212:1-7: ERROR: missing of_node_put; 
acquired a node pointer with refcount incremented on line 147, but without a 
corresponding object release within this function.
./drivers/cpufreq/pasemi-cpufreq.c:220:1-7: ERROR: missing of_node_put; 
acquired a node pointer with refcount incremented on line 147, but without a 
corresponding object release within this function.

Signed-off-by: Wen Yang 
Cc: "Rafael J. Wysocki" 
Cc: Viresh Kumar 
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Viresh Kumar 
Signed-off-by: Sasha Levin 
---
 drivers/cpufreq/pasemi-cpufreq.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c
index 35dd4d7ffee08..58c933f483004 100644
--- a/drivers/cpufreq/pasemi-cpufreq.c
+++ b/drivers/cpufreq/pasemi-cpufreq.c
@@ -146,6 +146,7 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy 
*policy)
 
cpu = of_get_cpu_node(policy->cpu, NULL);
 
+   of_node_put(cpu);
if (!cpu)
goto out;
 
-- 
2.20.1





[PATCH 4.4 183/241] net: stmmac: fix reset gpio free missing

2019-06-09 Thread Greg Kroah-Hartman
From: Jisheng Zhang 

[ Upstream commit 49ce881c0d4c4a7a35358d9dccd5f26d0e56fc61 ]

Commit 984203ceff27 ("net: stmmac: mdio: remove reset gpio free")
removed the reset gpio free, when the driver is unbinded or rmmod,
we miss the gpio free.

This patch uses managed API to request the reset gpio, so that the
gpio could be freed properly.

Fixes: 984203ceff27 ("net: stmmac: mdio: remove reset gpio free")
Signed-off-by: Jisheng Zhang 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -154,7 +154,8 @@ int stmmac_mdio_reset(struct mii_bus *bu
of_property_read_u32_array(np,
"snps,reset-delays-us", data->delays, 3);
 
-   if (gpio_request(data->reset_gpio, "mdio-reset"))
+   if (devm_gpio_request(priv->device, data->reset_gpio,
+ "mdio-reset"))
return 0;
}
 




[PATCH 4.4 143/241] s390: cio: fix cio_irb declaration

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit e91012ee855ad9f5ef2ab106a3de51db93fe4d0c ]

clang points out that the declaration of cio_irb does not match the
definition exactly, it is missing the alignment attribute:

../drivers/s390/cio/cio.c:50:1: warning: section does not match previous 
declaration [-Wsection]
DEFINE_PER_CPU_ALIGNED(struct irb, cio_irb);
^
../include/linux/percpu-defs.h:150:2: note: expanded from macro 
'DEFINE_PER_CPU_ALIGNED'
DEFINE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION) \
^
../include/linux/percpu-defs.h:93:9: note: expanded from macro 
'DEFINE_PER_CPU_SECTION'
extern __PCPU_ATTRS(sec) __typeof__(type) name; \
   ^
../include/linux/percpu-defs.h:49:26: note: expanded from macro '__PCPU_ATTRS'
__percpu __attribute__((section(PER_CPU_BASE_SECTION sec))) \
^
../drivers/s390/cio/cio.h:118:1: note: previous attribute is here
DECLARE_PER_CPU(struct irb, cio_irb);
^
../include/linux/percpu-defs.h:111:2: note: expanded from macro 
'DECLARE_PER_CPU'
DECLARE_PER_CPU_SECTION(type, name, "")
^
../include/linux/percpu-defs.h:87:9: note: expanded from macro 
'DECLARE_PER_CPU_SECTION'
extern __PCPU_ATTRS(sec) __typeof__(type) name
   ^
../include/linux/percpu-defs.h:49:26: note: expanded from macro '__PCPU_ATTRS'
__percpu __attribute__((section(PER_CPU_BASE_SECTION sec))) \
^
Use DECLARE_PER_CPU_ALIGNED() here, to make the two match.

Signed-off-by: Arnd Bergmann 
Reviewed-by: Nathan Chancellor 
Signed-off-by: Sebastian Ott 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Sasha Levin 
---
 drivers/s390/cio/cio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h
index a01376ae17493..fdb87520543fe 100644
--- a/drivers/s390/cio/cio.h
+++ b/drivers/s390/cio/cio.h
@@ -102,7 +102,7 @@ struct subchannel {
struct schib_config config;
 } __attribute__ ((aligned(8)));
 
-DECLARE_PER_CPU(struct irb, cio_irb);
+DECLARE_PER_CPU_ALIGNED(struct irb, cio_irb);
 
 #define to_subchannel(n) container_of(n, struct subchannel, dev)
 
-- 
2.20.1





[PATCH 4.4 141/241] PM / core: Propagate dev->power.wakeup_path when no callbacks

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit dc351d4c5f4fe4d0f274d6d660227be0c3a03317 ]

The dev->power.direct_complete flag may become set in device_prepare() in
case the device don't have any PM callbacks (dev->power.no_pm_callbacks is
set). This leads to a broken behaviour, when there is child having wakeup
enabled and relies on its parent to be used in the wakeup path.

More precisely, when the direct complete path becomes selected for the
child in __device_suspend(), the propagation of the dev->power.wakeup_path
becomes skipped as well.

Let's address this problem, by checking if the device is a part the wakeup
path or has wakeup enabled, then prevent the direct complete path from
being used.

Reported-by: Loic Pallardy 
Signed-off-by: Ulf Hansson 
[ rjw: Comment cleanup ]
Signed-off-by: Rafael J. Wysocki 
Signed-off-by: Sasha Levin 
---
 drivers/base/power/main.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 05409141ec077..8efdb823826c8 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1378,6 +1378,10 @@ static int __device_suspend(struct device *dev, 
pm_message_t state, bool async)
if (dev->power.syscore)
goto Complete;
 
+   /* Avoid direct_complete to let wakeup_path propagate. */
+   if (device_may_wakeup(dev) || dev->power.wakeup_path)
+   dev->power.direct_complete = false;
+
if (dev->power.direct_complete) {
if (pm_runtime_status_suspended(dev)) {
pm_runtime_disable(dev);
-- 
2.20.1





[PATCH 4.4 136/241] hwmon: (f71805f) Use request_muxed_region for Super-IO accesses

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 73e6ff71a7ea924fb7121d576a2d41e3be3fc6b5 ]

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Unable to handle kernel paging request at virtual address ffbffee0002e
pgd = ffc1d68d4000
[ffbffee0002e] *pgd=, *pud=
Internal error: Oops: 9446 [#1] PREEMPT SMP
Modules linked in: f71805f(+) hwmon
CPU: 3 PID: 1659 Comm: insmod Not tainted 4.5.0+ #88
Hardware name: linux,dummy-virt (DT)
task: ffc1f6665400 ti: ffc1d6418000 task.ti: ffc1d6418000
PC is at f71805f_find+0x6c/0x358 [f71805f]

Also, other drivers may attempt to access the LPC bus at the same time,
resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested
address space is supported, and to ensure that access by multiple
drivers is synchronized.

Fixes: e53004e20a58e ("hwmon: New f71805f driver")
Reported-by: Kefeng Wang 
Reported-by: John Garry 
Cc: John Garry 
Acked-by: John Garry 
Signed-off-by: Guenter Roeck 
Signed-off-by: Sasha Levin 
---
 drivers/hwmon/f71805f.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index facd05cda26da..e8c0898864277 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -96,17 +96,23 @@ superio_select(int base, int ld)
outb(ld, base + 1);
 }
 
-static inline void
+static inline int
 superio_enter(int base)
 {
+   if (!request_muxed_region(base, 2, DRVNAME))
+   return -EBUSY;
+
outb(0x87, base);
outb(0x87, base);
+
+   return 0;
 }
 
 static inline void
 superio_exit(int base)
 {
outb(0xaa, base);
+   release_region(base, 2);
 }
 
 /*
@@ -1561,7 +1567,7 @@ static int __init f71805f_device_add(unsigned short 
address,
 static int __init f71805f_find(int sioaddr, unsigned short *address,
   struct f71805f_sio_data *sio_data)
 {
-   int err = -ENODEV;
+   int err;
u16 devid;
 
static const char * const names[] = {
@@ -1569,8 +1575,11 @@ static int __init f71805f_find(int sioaddr, unsigned 
short *address,
"F71872F/FG or F71806F/FG",
};
 
-   superio_enter(sioaddr);
+   err = superio_enter(sioaddr);
+   if (err)
+   return err;
 
+   err = -ENODEV;
devid = superio_inw(sioaddr, SIO_REG_MANID);
if (devid != SIO_FINTEK_ID)
goto exit;
-- 
2.20.1





[PATCH 4.4 182/241] net-gro: fix use-after-free read in napi_gro_frags()

2019-06-09 Thread Greg Kroah-Hartman
From: Eric Dumazet 

[ Upstream commit a4270d6795b0580287453ea55974d948393e66ef ]

If a network driver provides to napi_gro_frags() an
skb with a page fragment of exactly 14 bytes, the call
to gro_pull_from_frag0() will 'consume' the fragment
by calling skb_frag_unref(skb, 0), and the page might
be freed and reused.

Reading eth->h_proto at the end of napi_frags_skb() might
read mangled data, or crash under specific debugging features.

BUG: KASAN: use-after-free in napi_frags_skb net/core/dev.c:5833 [inline]
BUG: KASAN: use-after-free in napi_gro_frags+0xc6f/0xd10 net/core/dev.c:5841
Read of size 2 at addr 88809366840c by task syz-executor599/8957

CPU: 1 PID: 8957 Comm: syz-executor599 Not tainted 5.2.0-rc1+ #32
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 
01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x172/0x1f0 lib/dump_stack.c:113
 print_address_description.cold+0x7c/0x20d mm/kasan/report.c:188
 __kasan_report.cold+0x1b/0x40 mm/kasan/report.c:317
 kasan_report+0x12/0x20 mm/kasan/common.c:614
 __asan_report_load_n_noabort+0xf/0x20 mm/kasan/generic_report.c:142
 napi_frags_skb net/core/dev.c:5833 [inline]
 napi_gro_frags+0xc6f/0xd10 net/core/dev.c:5841
 tun_get_user+0x2f3c/0x3ff0 drivers/net/tun.c:1991
 tun_chr_write_iter+0xbd/0x156 drivers/net/tun.c:2037
 call_write_iter include/linux/fs.h:1872 [inline]
 do_iter_readv_writev+0x5f8/0x8f0 fs/read_write.c:693
 do_iter_write fs/read_write.c:970 [inline]
 do_iter_write+0x184/0x610 fs/read_write.c:951
 vfs_writev+0x1b3/0x2f0 fs/read_write.c:1015
 do_writev+0x15b/0x330 fs/read_write.c:1058

Fixes: a50e233c50db ("net-gro: restore frag0 optimization")
Signed-off-by: Eric Dumazet 
Reported-by: syzbot 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 net/core/dev.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4550,7 +4550,6 @@ static struct sk_buff *napi_frags_skb(st
skb_reset_mac_header(skb);
skb_gro_reset_offset(skb);
 
-   eth = skb_gro_header_fast(skb, 0);
if (unlikely(skb_gro_header_hard(skb, hlen))) {
eth = skb_gro_header_slow(skb, hlen, 0);
if (unlikely(!eth)) {
@@ -4558,6 +4557,7 @@ static struct sk_buff *napi_frags_skb(st
return NULL;
}
} else {
+   eth = (const struct ethhdr *)skb->data;
gro_pull_from_frag0(skb, hlen);
NAPI_GRO_CB(skb)->frag0 += hlen;
NAPI_GRO_CB(skb)->frag0_len -= hlen;




[PATCH 4.4 180/241] ipv6: Consider sk_bound_dev_if when binding a raw socket to an address

2019-06-09 Thread Greg Kroah-Hartman
From: Mike Manning 

[ Upstream commit 72f7cfab6f93a8ea825fab8ccfb016d064269f7f ]

IPv6 does not consider if the socket is bound to a device when binding
to an address. The result is that a socket can be bound to eth0 and
then bound to the address of eth1. If the device is a VRF, the result
is that a socket can only be bound to an address in the default VRF.

Resolve by considering the device if sk_bound_dev_if is set.

Signed-off-by: Mike Manning 
Reviewed-by: David Ahern 
Tested-by: David Ahern 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 
---
 net/ipv6/raw.c |2 ++
 1 file changed, 2 insertions(+)

--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -283,7 +283,9 @@ static int rawv6_bind(struct sock *sk, s
/* Binding to link-local address requires an interface 
*/
if (!sk->sk_bound_dev_if)
goto out_unlock;
+   }
 
+   if (sk->sk_bound_dev_if) {
err = -ENODEV;
dev = dev_get_by_index_rcu(sock_net(sk),
   sk->sk_bound_dev_if);




[PATCH 4.4 140/241] mmc: sdhci-of-esdhc: add erratum eSDHC-A001 and A-008358 support

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 05cb6b2a66fa7837211a060878e91be5eb10cb07 ]

eSDHC-A001: The data timeout counter (SYSCTL[DTOCV]) is not
reliable for DTOCV values 0x4(2^17 SD clock), 0x8(2^21 SD clock),
and 0xC(2^25 SD clock). The data timeout counter can count from
2^13–2^27, but for values 2^17, 2^21, and 2^25, the timeout
counter counts for only 2^13 SD clocks.
A-008358: The data timeout counter value loaded into the timeout
counter is less than expected and can result into early timeout
error in case of eSDHC data transactions. The table below shows
the expected vs actual timeout period for different values of
SYSCTL[DTOCV]:
these two erratum has the same quirk to control it, and set
SDHCI_QUIRK_RESET_AFTER_REQUEST to fix above issue.

Signed-off-by: Yinbo Zhu 
Acked-by: Adrian Hunter 
Signed-off-by: Ulf Hansson 
Signed-off-by: Sasha Levin 
---
 drivers/mmc/host/sdhci-of-esdhc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-of-esdhc.c 
b/drivers/mmc/host/sdhci-of-esdhc.c
index a5a11e7ab53b4..356b294c93c9e 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -624,8 +624,10 @@ static int sdhci_esdhc_probe(struct platform_device *pdev)
if (esdhc->vendor_ver > VENDOR_V_22)
host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ;
 
-   if (of_find_compatible_node(NULL, NULL, "fsl,p2020-esdhc"))
+   if (of_find_compatible_node(NULL, NULL, "fsl,p2020-esdhc")) {
host->quirks2 |= SDHCI_QUIRK_RESET_AFTER_REQUEST;
+   host->quirks2 |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
+   }
 
if (of_device_is_compatible(np, "fsl,p5040-esdhc") ||
of_device_is_compatible(np, "fsl,p5020-esdhc") ||
-- 
2.20.1





[PATCH 4.4 178/241] spi: Fix zero length xfer bug

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 5442dcaa0d90fc376bdfc179a018931a8f43dea4 ]

This fixes a bug for messages containing both zero length and
unidirectional xfers.

The function spi_map_msg will allocate dummy tx and/or rx buffers
for use with unidirectional transfers when the hardware can only do
a bidirectional transfer.  That dummy buffer will be used in place
of a NULL buffer even when the xfer length is 0.

Then in the function __spi_map_msg, if he hardware can dma,
the zero length xfer will have spi_map_buf called on the dummy
buffer.

Eventually, __sg_alloc_table is called and returns -EINVAL
because nents == 0.

This fix prevents the error by not using the dummy buffer when
the xfer length is zero.

Signed-off-by: Chris Lesiak 
Signed-off-by: Mark Brown 
Signed-off-by: Sasha Levin 
---
 drivers/spi/spi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 04fd651f9e3e3..c132c676df3a6 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -903,6 +903,8 @@ static int spi_map_msg(struct spi_master *master, struct 
spi_message *msg)
if (max_tx || max_rx) {
list_for_each_entry(xfer, >transfers,
transfer_list) {
+   if (!xfer->len)
+   continue;
if (!xfer->tx_buf)
xfer->tx_buf = master->dummy_tx;
if (!xfer->rx_buf)
-- 
2.20.1





[PATCH 4.4 174/241] media: saa7146: avoid high stack usage with clang

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 03aa4f191a36f33fce015387f84efa0eee94408e ]

Two saa7146/hexium files contain a construct that causes a warning
when built with clang:

drivers/media/pci/saa7146/hexium_orion.c:210:12: error: stack frame size of 
2272 bytes in function 'hexium_probe'
  [-Werror,-Wframe-larger-than=]
static int hexium_probe(struct saa7146_dev *dev)
   ^
drivers/media/pci/saa7146/hexium_gemini.c:257:12: error: stack frame size of 
2304 bytes in function 'hexium_attach'
  [-Werror,-Wframe-larger-than=]
static int hexium_attach(struct saa7146_dev *dev, struct 
saa7146_pci_extension_data *info)
   ^

This one happens regardless of KASAN, and the problem is that a
constructor to initialize a dynamically allocated structure leads
to a copy of that structure on the stack, whereas gcc initializes
it in place.

Link: https://bugs.llvm.org/show_bug.cgi?id=40776

Signed-off-by: Arnd Bergmann 
Reviewed-by: Nick Desaulniers 
Signed-off-by: Hans Verkuil 
[hverkuil-ci...@xs4all.nl: fix checkpatch warnings]
Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Sasha Levin 
---
 drivers/media/pci/saa7146/hexium_gemini.c | 5 ++---
 drivers/media/pci/saa7146/hexium_orion.c  | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/saa7146/hexium_gemini.c 
b/drivers/media/pci/saa7146/hexium_gemini.c
index 03cbcd2095c6e..d4b3ce8282856 100644
--- a/drivers/media/pci/saa7146/hexium_gemini.c
+++ b/drivers/media/pci/saa7146/hexium_gemini.c
@@ -270,9 +270,8 @@ static int hexium_attach(struct saa7146_dev *dev, struct 
saa7146_pci_extension_d
/* enable i2c-port pins */
saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26));
 
-   hexium->i2c_adapter = (struct i2c_adapter) {
-   .name = "hexium gemini",
-   };
+   strscpy(hexium->i2c_adapter.name, "hexium gemini",
+   sizeof(hexium->i2c_adapter.name));
saa7146_i2c_adapter_prepare(dev, >i2c_adapter, 
SAA7146_I2C_BUS_BIT_RATE_480);
if (i2c_add_adapter(>i2c_adapter) < 0) {
DEB_S("cannot register i2c-device. skipping.\n");
diff --git a/drivers/media/pci/saa7146/hexium_orion.c 
b/drivers/media/pci/saa7146/hexium_orion.c
index 15f0d66ff78a2..214396b1ca73c 100644
--- a/drivers/media/pci/saa7146/hexium_orion.c
+++ b/drivers/media/pci/saa7146/hexium_orion.c
@@ -232,9 +232,8 @@ static int hexium_probe(struct saa7146_dev *dev)
saa7146_write(dev, DD1_STREAM_B, 0x);
saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
 
-   hexium->i2c_adapter = (struct i2c_adapter) {
-   .name = "hexium orion",
-   };
+   strscpy(hexium->i2c_adapter.name, "hexium orion",
+   sizeof(hexium->i2c_adapter.name));
saa7146_i2c_adapter_prepare(dev, >i2c_adapter, 
SAA7146_I2C_BUS_BIT_RATE_480);
if (i2c_add_adapter(>i2c_adapter) < 0) {
DEB_S("cannot register i2c-device. skipping.\n");
-- 
2.20.1





[PATCH 4.4 173/241] media: go7007: avoid clang frame overflow warning with KASAN

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit ed713a4a1367aca5c0f2f329579465db00c17995 ]

clang-8 warns about one function here when KASAN is enabled, even
without the 'asan-stack' option:

drivers/media/usb/go7007/go7007-fw.c:1551:5: warning: stack frame size of 2656 
bytes in function

I have reported this issue in the llvm bugzilla, but to make
it work with the clang-8 release, a small annotation is still
needed.

Link: https://bugs.llvm.org/show_bug.cgi?id=38809

Signed-off-by: Arnd Bergmann 
Signed-off-by: Hans Verkuil 
[hverkuil-ci...@xs4all.nl: fix checkpatch warning]
Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Sasha Levin 
---
 drivers/media/usb/go7007/go7007-fw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/go7007/go7007-fw.c 
b/drivers/media/usb/go7007/go7007-fw.c
index 60bf5f0644d11..a5efcd4f7b4f5 100644
--- a/drivers/media/usb/go7007/go7007-fw.c
+++ b/drivers/media/usb/go7007/go7007-fw.c
@@ -1499,8 +1499,8 @@ static int modet_to_package(struct go7007 *go, __le16 
*code, int space)
return cnt;
 }
 
-static int do_special(struct go7007 *go, u16 type, __le16 *code, int space,
-   int *framelen)
+static noinline_for_stack int do_special(struct go7007 *go, u16 type,
+__le16 *code, int space, int *framelen)
 {
switch (type) {
case SPECIAL_FRM_HEAD:
-- 
2.20.1





[PATCH 4.4 166/241] media: wl128x: prevent two potential buffer overflows

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 9c2ccc324b3a6cbc865ab8b3e1a09e93d3c8ade9 ]

Smatch marks skb->data as untrusted so it warns that "evt_hdr->dlen"
can copy up to 255 bytes and we only have room for two bytes.  Even
if this comes from the firmware and we trust it, the new policy
generally is just to fix it as kernel hardenning.

I can't test this code so I tried to be very conservative.  I considered
not allowing "evt_hdr->dlen == 1" because it doesn't initialize the
whole variable but in the end I decided to allow it and manually
initialized "asic_id" and "asic_ver" to zero.

Fixes: e8454ff7b9a4 ("[media] drivers:media:radio: wl128x: FM Driver Common 
sources")

Signed-off-by: Dan Carpenter 
Signed-off-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Sasha Levin 
---
 drivers/media/radio/wl128x/fmdrv_common.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/radio/wl128x/fmdrv_common.c 
b/drivers/media/radio/wl128x/fmdrv_common.c
index ebc73b0342496..51639a3f7abe4 100644
--- a/drivers/media/radio/wl128x/fmdrv_common.c
+++ b/drivers/media/radio/wl128x/fmdrv_common.c
@@ -494,7 +494,8 @@ int fmc_send_cmd(struct fmdev *fmdev, u8 fm_op, u16 type, 
void *payload,
return -EIO;
}
/* Send response data to caller */
-   if (response != NULL && response_len != NULL && evt_hdr->dlen) {
+   if (response != NULL && response_len != NULL && evt_hdr->dlen &&
+   evt_hdr->dlen <= payload_len) {
/* Skip header info and copy only response data */
skb_pull(skb, sizeof(struct fm_event_msg_hdr));
memcpy(response, skb->data, evt_hdr->dlen);
@@ -590,6 +591,8 @@ static void fm_irq_handle_flag_getcmd_resp(struct fmdev 
*fmdev)
return;
 
fm_evt_hdr = (void *)skb->data;
+   if (fm_evt_hdr->dlen > sizeof(fmdev->irq_info.flag))
+   return;
 
/* Skip header info and copy only response data */
skb_pull(skb, sizeof(struct fm_event_msg_hdr));
@@ -1315,7 +1318,7 @@ static int load_default_rx_configuration(struct fmdev 
*fmdev)
 static int fm_power_up(struct fmdev *fmdev, u8 mode)
 {
u16 payload;
-   __be16 asic_id, asic_ver;
+   __be16 asic_id = 0, asic_ver = 0;
int resp_len, ret;
u8 fw_name[50];
 
-- 
2.20.1





[PATCH 4.4 172/241] media: m88ds3103: serialize reset messages in m88ds3103_set_frontend

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 981fbe3da20a6f35f17977453bce7dfc1664d74f ]

Ref: https://bugzilla.kernel.org/show_bug.cgi?id=199323

Users are experiencing problems with the DVBSky S960/S960C USB devices
since the following commit:

9d659ae: ("locking/mutex: Add lock handoff to avoid starvation")

The device malfunctions after running for an indeterminable period of
time, and the problem can only be cleared by rebooting the machine.

It is possible to encourage the problem to surface by blocking the
signal to the LNB.

Further debugging revealed the cause of the problem.

In the following capture:
- thread #1325 is running m88ds3103_set_frontend
- thread #42 is running ts2020_stat_work

a> [1325] usb 1-1: dvb_usb_v2_generic_io: >>> 08 68 02 07 80
   [1325] usb 1-1: dvb_usb_v2_generic_io: <<< 08
   [42] usb 1-1: dvb_usb_v2_generic_io: >>> 09 01 01 68 3f
   [42] usb 1-1: dvb_usb_v2_generic_io: <<< 08 ff
   [42] usb 1-1: dvb_usb_v2_generic_io: >>> 08 68 02 03 11
   [42] usb 1-1: dvb_usb_v2_generic_io: <<< 07
   [42] usb 1-1: dvb_usb_v2_generic_io: >>> 09 01 01 60 3d
   [42] usb 1-1: dvb_usb_v2_generic_io: <<< 07 ff
b> [1325] usb 1-1: dvb_usb_v2_generic_io: >>> 08 68 02 07 00
   [1325] usb 1-1: dvb_usb_v2_generic_io: <<< 07
   [42] usb 1-1: dvb_usb_v2_generic_io: >>> 08 68 02 03 11
   [42] usb 1-1: dvb_usb_v2_generic_io: <<< 07
   [42] usb 1-1: dvb_usb_v2_generic_io: >>> 09 01 01 60 21
   [42] usb 1-1: dvb_usb_v2_generic_io: <<< 07 ff
   [42] usb 1-1: dvb_usb_v2_generic_io: >>> 08 68 02 03 11
   [42] usb 1-1: dvb_usb_v2_generic_io: <<< 07
   [42] usb 1-1: dvb_usb_v2_generic_io: >>> 09 01 01 60 66
   [42] usb 1-1: dvb_usb_v2_generic_io: <<< 07 ff
   [1325] usb 1-1: dvb_usb_v2_generic_io: >>> 08 68 02 03 11
   [1325] usb 1-1: dvb_usb_v2_generic_io: <<< 07
   [1325] usb 1-1: dvb_usb_v2_generic_io: >>> 08 60 02 10 0b
   [1325] usb 1-1: dvb_usb_v2_generic_io: <<< 07

Two i2c messages are sent to perform a reset in m88ds3103_set_frontend:

  a. 0x07, 0x80
  b. 0x07, 0x00

However, as shown in the capture, the regmap mutex is being handed over
to another thread (ts2020_stat_work) in between these two messages.

>From here, the device responds to every i2c message with an 07 message,
and will only return to normal operation following a power cycle.

Use regmap_multi_reg_write to group the two reset messages, ensuring
both are processed before the regmap mutex is unlocked.

Signed-off-by: James Hutchinson 
Reviewed-by: Antti Palosaari 
Signed-off-by: Sean Young 
Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Sasha Levin 
---
 drivers/media/dvb-frontends/m88ds3103.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/media/dvb-frontends/m88ds3103.c 
b/drivers/media/dvb-frontends/m88ds3103.c
index d14d075ab1d63..9f0956e739a45 100644
--- a/drivers/media/dvb-frontends/m88ds3103.c
+++ b/drivers/media/dvb-frontends/m88ds3103.c
@@ -309,6 +309,9 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
u16 u16tmp, divide_ratio = 0;
u32 tuner_frequency, target_mclk;
s32 s32tmp;
+   static const struct reg_sequence reset_buf[] = {
+   {0x07, 0x80}, {0x07, 0x00}
+   };
 
dev_dbg(>dev,
"delivery_system=%d modulation=%d frequency=%u symbol_rate=%d 
inversion=%d pilot=%d rolloff=%d\n",
@@ -321,11 +324,7 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
}
 
/* reset */
-   ret = regmap_write(dev->regmap, 0x07, 0x80);
-   if (ret)
-   goto err;
-
-   ret = regmap_write(dev->regmap, 0x07, 0x00);
+   ret = regmap_multi_reg_write(dev->regmap, reset_buf, 2);
if (ret)
goto err;
 
-- 
2.20.1





[PATCH 4.4 139/241] mmc: sdhci-of-esdhc: add erratum eSDHC5 support

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit a46e42712596b51874f04c73f1cdf1017f88df52 ]

Software writing to the Transfer Type configuration register
(system clock domain) can cause a setup/hold violation in the
CRC flops (card clock domain), which can cause write accesses
to be sent with corrupt CRC values. This issue occurs only for
write preceded by read. this erratum is to fix this issue.

Signed-off-by: Yinbo Zhu 
Acked-by: Adrian Hunter 
Signed-off-by: Ulf Hansson 
Signed-off-by: Sasha Levin 
---
 drivers/mmc/host/sdhci-of-esdhc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mmc/host/sdhci-of-esdhc.c 
b/drivers/mmc/host/sdhci-of-esdhc.c
index ac66c61d9433c..a5a11e7ab53b4 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -624,6 +624,9 @@ static int sdhci_esdhc_probe(struct platform_device *pdev)
if (esdhc->vendor_ver > VENDOR_V_22)
host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ;
 
+   if (of_find_compatible_node(NULL, NULL, "fsl,p2020-esdhc"))
+   host->quirks2 |= SDHCI_QUIRK_RESET_AFTER_REQUEST;
+
if (of_device_is_compatible(np, "fsl,p5040-esdhc") ||
of_device_is_compatible(np, "fsl,p5020-esdhc") ||
of_device_is_compatible(np, "fsl,p4080-esdhc") ||
-- 
2.20.1





[PATCH 4.4 170/241] usb: core: Add PM runtime calls to usb_hcd_platform_shutdown

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 8ead7e817224d7832fe51a19783cb8fcadc79467 ]

If ohci-platform is runtime suspended, we can currently get an "imprecise
external abort" on reboot with ohci-platform loaded when PM runtime
is implemented for the SoC.

Let's fix this by adding PM runtime support to usb_hcd_platform_shutdown.

Signed-off-by: Tony Lindgren 
Acked-by: Alan Stern 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/usb/core/hcd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 9c4f9b6e57e29..99c146f4b6b51 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -3007,6 +3007,9 @@ usb_hcd_platform_shutdown(struct platform_device *dev)
 {
struct usb_hcd *hcd = platform_get_drvdata(dev);
 
+   /* No need for pm_runtime_put(), we're shutting down */
+   pm_runtime_get_sync(>dev);
+
if (hcd->driver->shutdown)
hcd->driver->shutdown(hcd);
 }
-- 
2.20.1





[PATCH 4.4 160/241] chardev: add additional check for minor range overlap

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit de36e16d1557a0b6eb328bc3516359a12ba5c25c ]

Current overlap checking cannot correctly handle
a case which is baseminor < existing baseminor &&
baseminor + minorct > existing baseminor + minorct.

Signed-off-by: Chengguang Xu 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 fs/char_dev.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/fs/char_dev.c b/fs/char_dev.c
index 24b142569ca9b..d0655ca894816 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -130,6 +130,12 @@ __register_chrdev_region(unsigned int major, unsigned int 
baseminor,
ret = -EBUSY;
goto out;
}
+
+   if (new_min < old_min && new_max > old_max) {
+   ret = -EBUSY;
+   goto out;
+   }
+
}
 
cd->next = *cp;
-- 
2.20.1





[PATCH 4.4 163/241] ASoC: fsl_utils: fix a leaked reference by adding missing of_node_put

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit c705247136a523488eac806bd357c3e5d79a7acd ]

The call to of_parse_phandle returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./sound/soc/fsl/fsl_utils.c:74:2-8: ERROR: missing of_node_put; acquired a node 
pointer with refcount incremented on line 38, but without a corresponding 
object release within this function.

Signed-off-by: Wen Yang 
Cc: Timur Tabi 
Cc: Nicolin Chen 
Cc: Xiubo Li 
Cc: Fabio Estevam 
Cc: Liam Girdwood 
Cc: Mark Brown 
Cc: Jaroslav Kysela 
Cc: Takashi Iwai 
Cc: alsa-de...@alsa-project.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown 
Signed-off-by: Sasha Levin 
---
 sound/soc/fsl/fsl_utils.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/fsl/fsl_utils.c b/sound/soc/fsl/fsl_utils.c
index b9e42b503a377..4f8bdb7650e84 100644
--- a/sound/soc/fsl/fsl_utils.c
+++ b/sound/soc/fsl/fsl_utils.c
@@ -75,6 +75,7 @@ int fsl_asoc_get_dma_channel(struct device_node *ssi_np,
iprop = of_get_property(dma_np, "cell-index", NULL);
if (!iprop) {
of_node_put(dma_np);
+   of_node_put(dma_channel_np);
return -EINVAL;
}
*dma_id = be32_to_cpup(iprop);
-- 
2.20.1





[PATCH 4.4 164/241] cxgb3/l2t: Fix undefined behaviour

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 76497732932f15e7323dc805e8ea8dc11bb587cf ]

The use of zero-sized array causes undefined behaviour when it is not
the last member in a structure. As it happens to be in this case.

Also, the current code makes use of a language extension to the C90
standard, but the preferred mechanism to declare variable-length
types such as this one is a flexible array member, introduced in
C99:

struct foo {
int stuff;
struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last. Which is beneficial
to cultivate a high-quality code.

Fixes: e48f129c2f20 ("[SCSI] cxgb3i: convert cdev->l2opt to use rcu to prevent 
NULL dereference")
Signed-off-by: Gustavo A. R. Silva 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/chelsio/cxgb3/l2t.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h 
b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
index 8cffcdfd56782..38b5858c335a9 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
@@ -75,8 +75,8 @@ struct l2t_data {
struct l2t_entry *rover;/* starting point for next allocation */
atomic_t nfree; /* number of free entries */
rwlock_t lock;
-   struct l2t_entry l2tab[0];
struct rcu_head rcu_head;   /* to handle rcu cleanup */
+   struct l2t_entry l2tab[];
 };
 
 typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
-- 
2.20.1





[PATCH 4.4 169/241] rcutorture: Fix cleanup path for invalid torture_type strings

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit b813afae7ab6a5e91b4e16cc567331d9c2ae1f04 ]

If the specified rcutorture.torture_type is not in the rcu_torture_init()
function's torture_ops[] array, rcutorture prints some console messages
and then invokes rcu_torture_cleanup() to set state so that a future
torture test can run.  However, rcu_torture_cleanup() also attempts to
end the test that didn't actually start, and in doing so relies on the
value of cur_ops, a value that is not particularly relevant in this case.
This can result in confusing output or even follow-on failures due to
attempts to use facilities that have not been properly initialized.

This commit therefore sets the value of cur_ops to NULL in this case
and inserts a check near the beginning of rcu_torture_cleanup(),
thus avoiding relying on an irrelevant cur_ops value.

Reported-by: kernel test robot 
Signed-off-by: Paul E. McKenney 
Signed-off-by: Sasha Levin 
---
 kernel/rcu/rcutorture.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index d89328e260df6..041a02b334d73 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1603,6 +1603,10 @@ rcu_torture_cleanup(void)
cur_ops->cb_barrier();
return;
}
+   if (!cur_ops) {
+   torture_cleanup_end();
+   return;
+   }
 
rcu_torture_barrier_cleanup();
torture_stop_kthread(rcu_torture_stall, stall_task);
@@ -1741,6 +1745,7 @@ rcu_torture_init(void)
pr_alert(" %s", torture_ops[i]->name);
pr_alert("\n");
firsterr = -EINVAL;
+   cur_ops = NULL;
goto unwind;
}
if (cur_ops->fqs == NULL && fqs_duration != 0) {
-- 
2.20.1





[PATCH 4.4 161/241] HID: core: move Usage Page concatenation to Main item

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 58e75155009cc85629955d3482f36a1e0eec ]

As seen on some USB wireless keyboards manufactured by Primax, the HID
parser was using some assumptions that are not always true. In this case
it's s the fact that, inside the scope of a main item, an Usage Page
will always precede an Usage.

The spec is not pretty clear as 6.2.2.7 states "Any usage that follows
is interpreted as a Usage ID and concatenated with the Usage Page".
While 6.2.2.8 states "When the parser encounters a main item it
concatenates the last declared Usage Page with a Usage to form a
complete usage value." Being somewhat contradictory it was decided to
match Window's implementation, which follows 6.2.2.8.

In summary, the patch moves the Usage Page concatenation from the local
item parsing function to the main item parsing function.

Signed-off-by: Nicolas Saenz Julienne 
Reviewed-by: Terry Junge 
Signed-off-by: Benjamin Tissoires 
Signed-off-by: Sasha Levin 
---
 drivers/hid/hid-core.c | 36 
 include/linux/hid.h|  1 +
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 4564ecf711815..9b2b41d683dea 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -200,13 +200,14 @@ static unsigned hid_lookup_collection(struct hid_parser 
*parser, unsigned type)
  * Add a usage to the temporary parser table.
  */
 
-static int hid_add_usage(struct hid_parser *parser, unsigned usage)
+static int hid_add_usage(struct hid_parser *parser, unsigned usage, u8 size)
 {
if (parser->local.usage_index >= HID_MAX_USAGES) {
hid_err(parser->device, "usage index exceeded\n");
return -1;
}
parser->local.usage[parser->local.usage_index] = usage;
+   parser->local.usage_size[parser->local.usage_index] = size;
parser->local.collection_index[parser->local.usage_index] =
parser->collection_stack_ptr ?
parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
@@ -463,10 +464,7 @@ static int hid_parser_local(struct hid_parser *parser, 
struct hid_item *item)
return 0;
}
 
-   if (item->size <= 2)
-   data = (parser->global.usage_page << 16) + data;
-
-   return hid_add_usage(parser, data);
+   return hid_add_usage(parser, data, item->size);
 
case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
 
@@ -475,9 +473,6 @@ static int hid_parser_local(struct hid_parser *parser, 
struct hid_item *item)
return 0;
}
 
-   if (item->size <= 2)
-   data = (parser->global.usage_page << 16) + data;
-
parser->local.usage_minimum = data;
return 0;
 
@@ -488,9 +483,6 @@ static int hid_parser_local(struct hid_parser *parser, 
struct hid_item *item)
return 0;
}
 
-   if (item->size <= 2)
-   data = (parser->global.usage_page << 16) + data;
-
count = data - parser->local.usage_minimum;
if (count + parser->local.usage_index >= HID_MAX_USAGES) {
/*
@@ -510,7 +502,7 @@ static int hid_parser_local(struct hid_parser *parser, 
struct hid_item *item)
}
 
for (n = parser->local.usage_minimum; n <= data; n++)
-   if (hid_add_usage(parser, n)) {
+   if (hid_add_usage(parser, n, item->size)) {
dbg_hid("hid_add_usage failed\n");
return -1;
}
@@ -524,6 +516,22 @@ static int hid_parser_local(struct hid_parser *parser, 
struct hid_item *item)
return 0;
 }
 
+/*
+ * Concatenate Usage Pages into Usages where relevant:
+ * As per specification, 6.2.2.8: "When the parser encounters a main item it
+ * concatenates the last declared Usage Page with a Usage to form a complete
+ * usage value."
+ */
+
+static void hid_concatenate_usage_page(struct hid_parser *parser)
+{
+   int i;
+
+   for (i = 0; i < parser->local.usage_index; i++)
+   if (parser->local.usage_size[i] <= 2)
+   parser->local.usage[i] += parser->global.usage_page << 
16;
+}
+
 /*
  * Process a main item.
  */
@@ -533,6 +541,8 @@ static int hid_parser_main(struct hid_parser *parser, 
struct hid_item *item)
__u32 data;
int ret;
 
+   hid_concatenate_usage_page(parser);
+
data = item_udata(item);
 
switch (item->tag) {
@@ -746,6 +756,8 @@ static int hid_scan_main(struct hid_parser *parser, struct 
hid_item *item)
__u32 data;
int i;
 
+   hid_concatenate_usage_page(parser);
+
data = item_udata(item);
 
switch (item->tag) {
diff --git a/include/linux/hid.h b/include/linux/hid.h
index fd86687f81196..5f31318851366 100644
--- 

[PATCH 4.4 167/241] virtio_console: initialize vtermno value for ports

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 4b0a2c5ff7215206ea6135a405f17c5f6fca7d00 ]

For regular serial ports we do not initialize value of vtermno
variable. A garbage value is assigned for non console ports.
The value can be observed as a random integer with [1].

[1] vim /sys/kernel/debug/virtio-ports/vport*p*

This patch initialize the value of vtermno for console serial
ports to '1' and regular serial ports are initiaized to '0'.

Reported-by: si...@redhat.com
Signed-off-by: Pankaj Gupta 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/char/virtio_console.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 2aca689061e1f..df9eab91c2d25 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -76,7 +76,7 @@ struct ports_driver_data {
/* All the console devices handled by this driver */
struct list_head consoles;
 };
-static struct ports_driver_data pdrvdata;
+static struct ports_driver_data pdrvdata = { .next_vtermno = 1};
 
 static DEFINE_SPINLOCK(pdrvdata_lock);
 static DECLARE_COMPLETION(early_console_added);
@@ -1419,6 +1419,7 @@ static int add_port(struct ports_device *portdev, u32 id)
port->async_queue = NULL;
 
port->cons.ws.ws_row = port->cons.ws.ws_col = 0;
+   port->cons.vtermno = 0;
 
port->host_connected = port->guest_connected = false;
port->stats = (struct port_stats) { 0 };
-- 
2.20.1





[PATCH 4.4 154/241] brcmfmac: convert dev_init_lock mutex to completion

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit a9fd0953fa4a62887306be28641b4b0809f3b2fd ]

Leaving dev_init_lock mutex locked in probe causes BUG and a WARNING when
kernel is compiled with CONFIG_PROVE_LOCKING. Convert mutex to completion
which silences those warnings and improves code readability.

Fix below errors when connecting the USB WiFi dongle:

brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac43143 for chip BCM43143/2
BUG: workqueue leaked lock or atomic: kworker/0:2/0x/434
 last function: hub_event
1 lock held by kworker/0:2/434:
 #0: 18d5dcdf (>dev_init_lock){+.+.}, at: brcmf_usb_probe+0x78/0x550 
[brcmfmac]
CPU: 0 PID: 434 Comm: kworker/0:2 Not tainted 4.19.23-00084-g454a789-dirty #123
Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
Workqueue: usb_hub_wq hub_event
[<8011237c>] (unwind_backtrace) from [<8010d74c>] (show_stack+0x10/0x14)
[<8010d74c>] (show_stack) from [<809c4324>] (dump_stack+0xa8/0xd4)
[<809c4324>] (dump_stack) from [<8014195c>] (process_one_work+0x710/0x808)
[<8014195c>] (process_one_work) from [<80141a80>] (worker_thread+0x2c/0x564)
[<80141a80>] (worker_thread) from [<80147bcc>] (kthread+0x13c/0x16c)
[<80147bcc>] (kthread) from [<801010b4>] (ret_from_fork+0x14/0x20)
Exception stack(0xed1d9fb0 to 0xed1d9ff8)
9fa0:    
9fc0:        
9fe0:     0013 

==
WARNING: possible circular locking dependency detected
4.19.23-00084-g454a789-dirty #123 Not tainted
--
kworker/0:2/434 is trying to acquire lock:
e29cf799 ((wq_completion)"events"){+.+.}, at: process_one_work+0x174/0x808

but task is already holding lock:
18d5dcdf (>dev_init_lock){+.+.}, at: brcmf_usb_probe+0x78/0x550 
[brcmfmac]

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (>dev_init_lock){+.+.}:
   mutex_lock_nested+0x1c/0x24
   brcmf_usb_probe+0x78/0x550 [brcmfmac]
   usb_probe_interface+0xc0/0x1bc
   really_probe+0x228/0x2c0
   __driver_attach+0xe4/0xe8
   bus_for_each_dev+0x68/0xb4
   bus_add_driver+0x19c/0x214
   driver_register+0x78/0x110
   usb_register_driver+0x84/0x148
   process_one_work+0x228/0x808
   worker_thread+0x2c/0x564
   kthread+0x13c/0x16c
   ret_from_fork+0x14/0x20
 (null)

-> #1 (brcmf_driver_work){+.+.}:
   worker_thread+0x2c/0x564
   kthread+0x13c/0x16c
   ret_from_fork+0x14/0x20
 (null)

-> #0 ((wq_completion)"events"){+.+.}:
   process_one_work+0x1b8/0x808
   worker_thread+0x2c/0x564
   kthread+0x13c/0x16c
   ret_from_fork+0x14/0x20
 (null)

other info that might help us debug this:

Chain exists of:
  (wq_completion)"events" --> brcmf_driver_work --> >dev_init_lock

 Possible unsafe locking scenario:

   CPU0CPU1
   
  lock(>dev_init_lock);
   lock(brcmf_driver_work);
   lock(>dev_init_lock);
  lock((wq_completion)"events");

 *** DEADLOCK ***

1 lock held by kworker/0:2/434:
 #0: 18d5dcdf (>dev_init_lock){+.+.}, at: brcmf_usb_probe+0x78/0x550 
[brcmfmac]

stack backtrace:
CPU: 0 PID: 434 Comm: kworker/0:2 Not tainted 4.19.23-00084-g454a789-dirty #123
Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
Workqueue: events request_firmware_work_func
[<8011237c>] (unwind_backtrace) from [<8010d74c>] (show_stack+0x10/0x14)
[<8010d74c>] (show_stack) from [<809c4324>] (dump_stack+0xa8/0xd4)
[<809c4324>] (dump_stack) from [<80172838>] (print_circular_bug+0x210/0x330)
[<80172838>] (print_circular_bug) from [<80175940>] 
(__lock_acquire+0x160c/0x1a30)
[<80175940>] (__lock_acquire) from [<8017671c>] (lock_acquire+0xe0/0x268)
[<8017671c>] (lock_acquire) from [<80141404>] (process_one_work+0x1b8/0x808)
[<80141404>] (process_one_work) from [<80141a80>] (worker_thread+0x2c/0x564)
[<80141a80>] (worker_thread) from [<80147bcc>] (kthread+0x13c/0x16c)
[<80147bcc>] (kthread) from [<801010b4>] (ret_from_fork+0x14/0x20)
Exception stack(0xed1d9fb0 to 0xed1d9ff8)
9fa0:    
9fc0:        
9fe0:     0013 

Signed-off-by: Piotr Figiel 
Signed-off-by: Kalle Valo 
Signed-off-by: Sasha Levin 
---
 drivers/net/wireless/brcm80211/brcmfmac/usb.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c 
b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
index 689e64d004bc5..32b7b8a8f80c6 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
@@ -144,7 +144,7 @@ struct brcmf_usbdev_info 

[PATCH 4.4 152/241] brcmfmac: fix missing checks for kmemdup

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 46953f97224d56a12ccbe9c6acaa84ca0dab2780 ]

In case kmemdup fails, the fix sets conn_info->req_ie_len and
conn_info->resp_ie_len to zero to avoid buffer overflows.

Signed-off-by: Kangjie Lu 
Acked-by: Arend van Spriel 
Signed-off-by: Kalle Valo 
Signed-off-by: Sasha Levin 
---
 drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c 
b/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
index ad35e760ed3f0..e3f5dacd918d7 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
@@ -4836,6 +4836,8 @@ static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info 
*cfg,
conn_info->req_ie =
kmemdup(cfg->extra_buf, conn_info->req_ie_len,
GFP_KERNEL);
+   if (!conn_info->req_ie)
+   conn_info->req_ie_len = 0;
} else {
conn_info->req_ie_len = 0;
conn_info->req_ie = NULL;
@@ -4852,6 +4854,8 @@ static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info 
*cfg,
conn_info->resp_ie =
kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
GFP_KERNEL);
+   if (!conn_info->resp_ie)
+   conn_info->resp_ie_len = 0;
} else {
conn_info->resp_ie_len = 0;
conn_info->resp_ie = NULL;
-- 
2.20.1





[PATCH 4.4 153/241] b43: shut up clang -Wuninitialized variable warning

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit d825db346270dbceef83b7b750dbc29f1d7dcc0e ]

Clang warns about what is clearly a case of passing an uninitalized
variable into a static function:

drivers/net/wireless/broadcom/b43/phy_lp.c:1852:23: error: variable 'gains' is 
uninitialized when used here
  [-Werror,-Wuninitialized]
lpphy_papd_cal(dev, gains, 0, 1, 30);
^
drivers/net/wireless/broadcom/b43/phy_lp.c:1838:2: note: variable 'gains' is 
declared here
struct lpphy_tx_gains gains, oldgains;
^
1 error generated.

However, this function is empty, and its arguments are never evaluated,
so gcc in contrast does not warn here. Both compilers behave in a
reasonable way as far as I can tell, so we should change the code
to avoid the warning everywhere.

We could just eliminate the lpphy_papd_cal() function entirely,
given that it has had the TODO comment in it for 10 years now
and is rather unlikely to ever get done. I'm doing a simpler
change here, and just pass the 'oldgains' variable in that has
been initialized, based on the guess that this is what was
originally meant.

Fixes: 2c0d6100da3e ("b43: LP-PHY: Begin implementing calibration & software 
RFKILL support")
Signed-off-by: Arnd Bergmann 
Acked-by: Larry Finger 
Reviewed-by: Nathan Chancellor 
Signed-off-by: Kalle Valo 
Signed-off-by: Sasha Levin 
---
 drivers/net/wireless/b43/phy_lp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/b43/phy_lp.c 
b/drivers/net/wireless/b43/phy_lp.c
index 058a9f2320503..55cb07693ae80 100644
--- a/drivers/net/wireless/b43/phy_lp.c
+++ b/drivers/net/wireless/b43/phy_lp.c
@@ -1834,7 +1834,7 @@ static void lpphy_papd_cal(struct b43_wldev *dev, struct 
lpphy_tx_gains gains,
 static void lpphy_papd_cal_txpwr(struct b43_wldev *dev)
 {
struct b43_phy_lp *lpphy = dev->phy.lp;
-   struct lpphy_tx_gains gains, oldgains;
+   struct lpphy_tx_gains oldgains;
int old_txpctl, old_afe_ovr, old_rf, old_bbmult;
 
lpphy_read_tx_pctl_mode_from_hardware(dev);
@@ -1848,9 +1848,9 @@ static void lpphy_papd_cal_txpwr(struct b43_wldev *dev)
lpphy_set_tx_power_control(dev, B43_LPPHY_TXPCTL_OFF);
 
if (dev->dev->chip_id == 0x4325 && dev->dev->chip_rev == 0)
-   lpphy_papd_cal(dev, gains, 0, 1, 30);
+   lpphy_papd_cal(dev, oldgains, 0, 1, 30);
else
-   lpphy_papd_cal(dev, gains, 0, 1, 65);
+   lpphy_papd_cal(dev, oldgains, 0, 1, 65);
 
if (old_afe_ovr)
lpphy_set_tx_gains(dev, oldgains);
-- 
2.20.1





[PATCH 4.4 156/241] scsi: ufs: Fix regulator load and icc-level configuration

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 0487fff76632ec023d394a05b82e87a971db8c03 ]

Currently if a regulator has "-fixed-regulator" property in device
tree, it will skip current limit initialization.  This lead to a zero
"max_uA" value in struct ufs_vreg.

However, "regulator_set_load" operation shall be required on regulators
which have valid current limits, otherwise a zero "max_uA" set by
"regulator_set_load" may cause unexpected behavior when this regulator is
enabled or set as high power mode.

Similarly, in device's icc_level configuration flow, the target icc_level
shall be updated if regulator also has valid current limit, otherwise a
wrong icc_level will be calculated by zero "max_uA" and thus causes
unexpected results after it is written to device.

Signed-off-by: Stanley Chu 
Reviewed-by: Avri Altman 
Acked-by: Alim Akhtar 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/ufs/ufshcd.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index c94d465de941e..ed76381fce4cc 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -4144,19 +4144,19 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct 
ufs_hba *hba,
goto out;
}
 
-   if (hba->vreg_info.vcc)
+   if (hba->vreg_info.vcc && hba->vreg_info.vcc->max_uA)
icc_level = ufshcd_get_max_icc_level(
hba->vreg_info.vcc->max_uA,
POWER_DESC_MAX_ACTV_ICC_LVLS - 1,
_buf[PWR_DESC_ACTIVE_LVLS_VCC_0]);
 
-   if (hba->vreg_info.vccq)
+   if (hba->vreg_info.vccq && hba->vreg_info.vccq->max_uA)
icc_level = ufshcd_get_max_icc_level(
hba->vreg_info.vccq->max_uA,
icc_level,
_buf[PWR_DESC_ACTIVE_LVLS_VCCQ_0]);
 
-   if (hba->vreg_info.vccq2)
+   if (hba->vreg_info.vccq2 && hba->vreg_info.vccq2->max_uA)
icc_level = ufshcd_get_max_icc_level(
hba->vreg_info.vccq2->max_uA,
icc_level,
@@ -4390,6 +4390,15 @@ static int ufshcd_config_vreg_load(struct device *dev, 
struct ufs_vreg *vreg,
if (!vreg)
return 0;
 
+   /*
+* "set_load" operation shall be required on those regulators
+* which specifically configured current limitation. Otherwise
+* zero max_uA may cause unexpected behavior when regulator is
+* enabled or set as high power mode.
+*/
+   if (!vreg->max_uA)
+   return 0;
+
ret = regulator_set_load(vreg->reg, ua);
if (ret < 0) {
dev_err(dev, "%s: %s set load (ua=%d) failed, err=%d\n",
-- 
2.20.1





[PATCH 4.4 158/241] arm64: cpu_ops: fix a leaked reference by adding missing of_node_put

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 92606ec9285fb84cd9b5943df23f07d741384bfc ]

The call to of_get_next_child returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
  ./arch/arm64/kernel/cpu_ops.c:102:1-7: ERROR: missing of_node_put;
  acquired a node pointer with refcount incremented on line 69, but
  without a corresponding object release within this function.

Signed-off-by: Wen Yang 
Reviewed-by: Florian Fainelli 
Cc: Catalin Marinas 
Cc: Will Deacon 
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Will Deacon 
Signed-off-by: Sasha Levin 
---
 arch/arm64/kernel/cpu_ops.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kernel/cpu_ops.c b/arch/arm64/kernel/cpu_ops.c
index b6bd7d4477683..fbd6aead48e10 100644
--- a/arch/arm64/kernel/cpu_ops.c
+++ b/arch/arm64/kernel/cpu_ops.c
@@ -73,6 +73,7 @@ static const char *__init cpu_read_enable_method(int cpu)
pr_err("%s: missing enable-method property\n",
dn->full_name);
}
+   of_node_put(dn);
} else {
enable_method = acpi_get_enable_method(cpu);
if (!enable_method)
-- 
2.20.1





[PATCH 4.4 157/241] scsi: ufs: Avoid configuring regulator with undefined voltage range

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 3b141e8cfd54ba3e5c610717295b2a02aab26a05 ]

For regulators used by UFS, vcc, vccq and vccq2 will have voltage range
initialized by ufshcd_populate_vreg(), however other regulators may have
undefined voltage range if dt-bindings have no such definition.

In above undefined case, both "min_uV" and "max_uV" fields in ufs_vreg
struct will be zero values and these values will be configured on
regulators in different power modes.

Currently this may have no harm if both "min_uV" and "max_uV" always keep
"zero values" because regulator_set_voltage() will always bypass such
invalid values and return "good" results.

However improper values shall be fixed to avoid potential bugs.  Simply
bypass voltage configuration if voltage range is not defined.

Signed-off-by: Stanley Chu 
Reviewed-by: Avri Altman 
Acked-by: Alim Akhtar 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/ufs/ufshcd.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index ed76381fce4cc..7322a17660d10 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -4434,12 +4434,15 @@ static int ufshcd_config_vreg(struct device *dev,
name = vreg->name;
 
if (regulator_count_voltages(reg) > 0) {
-   min_uV = on ? vreg->min_uV : 0;
-   ret = regulator_set_voltage(reg, min_uV, vreg->max_uV);
-   if (ret) {
-   dev_err(dev, "%s: %s set voltage failed, err=%d\n",
+   if (vreg->min_uV && vreg->max_uV) {
+   min_uV = on ? vreg->min_uV : 0;
+   ret = regulator_set_voltage(reg, min_uV, vreg->max_uV);
+   if (ret) {
+   dev_err(dev,
+   "%s: %s set voltage failed, err=%d\n",
__func__, name, ret);
-   goto out;
+   goto out;
+   }
}
 
uA_load = on ? vreg->max_uA : 0;
-- 
2.20.1





[PATCH 4.4 138/241] mmc_spi: add a status check for spi_sync_locked

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 611025983b7976df0183390a63a2166411d177f1 ]

In case spi_sync_locked fails, the fix reports the error and
returns the error code upstream.

Signed-off-by: Kangjie Lu 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Ulf Hansson 
Signed-off-by: Sasha Levin 
---
 drivers/mmc/host/mmc_spi.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index e03ec74f3fb08..40a369c7005a8 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -819,6 +819,10 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct 
spi_transfer *t,
}
 
status = spi_sync_locked(spi, >m);
+   if (status < 0) {
+   dev_dbg(>dev, "read error %d\n", status);
+   return status;
+   }
 
if (host->dma_dev) {
dma_sync_single_for_cpu(host->dma_dev,
-- 
2.20.1





[PATCH 4.4 090/241] at76c50x-usb: Dont register led_trigger if usb_register_driver failed

2019-06-09 Thread Greg Kroah-Hartman
From: YueHaibing 

commit 09ac2694b0475f96be895848687ebcbba97eeecf upstream.

Syzkaller report this:

[ 1213.468581] BUG: unable to handle kernel paging request at fbfff83bf338
[ 1213.469530] #PF error: [normal kernel read fault]
[ 1213.469530] PGD 237fe4067 P4D 237fe4067 PUD 237e60067 PMD 1c868b067 PTE 0
[ 1213.473514] Oops:  [#1] SMP KASAN PTI
[ 1213.473514] CPU: 0 PID: 6321 Comm: syz-executor.0 Tainted: G C   
 5.1.0-rc3+ #8
[ 1213.473514] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
1.10.2-1ubuntu1 04/01/2014
[ 1213.473514] RIP: 0010:strcmp+0x31/0xa0
[ 1213.473514] Code: 00 00 00 00 fc ff df 55 53 48 83 ec 08 eb 0a 84 db 48 89 
ef 74 5a 4c 89 e6 48 89 f8 48 89 fa 48 8d 6f 01 48 c1 e8 03 83 e2 07 <42> 0f b6 
04 28 38 d0 7f 04 84 c0 75 50 48 89 f0 48 89 f2 0f b6 5d
[ 1213.473514] RSP: 0018:8881f2b7f950 EFLAGS: 00010246
[ 1213.473514] RAX: 183bf338 RBX: 8881ea6f7240 RCX: 825350c6
[ 1213.473514] RDX:  RSI: c1ee19c0 RDI: c1df99c0
[ 1213.473514] RBP: c1df99c1 R08: 0001 R09: 0004
[ 1213.473514] R10:  R11: 8881de353f00 R12: 8881ee727900
[ 1213.473514] R13: dc00 R14: 0001 R15: c1eeaaf0
[ 1213.473514] FS:  7fa66fa01700() GS:8881f720() 
knlGS:
[ 1213.473514] CS:  0010 DS:  ES:  CR0: 80050033
[ 1213.473514] CR2: fbfff83bf338 CR3: 0001ebb9e005 CR4: 007606f0
[ 1213.473514] DR0:  DR1:  DR2: 
[ 1213.473514] DR3:  DR6: fffe0ff0 DR7: 0400
[ 1213.473514] PKRU: 5554
[ 1213.473514] Call Trace:
[ 1213.473514]  led_trigger_register+0x112/0x3f0
[ 1213.473514]  led_trigger_register_simple+0x7a/0x110
[ 1213.473514]  ? 0xc1c1
[ 1213.473514]  at76_mod_init+0x77/0x1000 [at76c50x_usb]
[ 1213.473514]  do_one_initcall+0xbc/0x47d
[ 1213.473514]  ? perf_trace_initcall_level+0x3a0/0x3a0
[ 1213.473514]  ? kasan_unpoison_shadow+0x30/0x40
[ 1213.473514]  ? kasan_unpoison_shadow+0x30/0x40
[ 1213.473514]  do_init_module+0x1b5/0x547
[ 1213.473514]  load_module+0x6405/0x8c10
[ 1213.473514]  ? module_frob_arch_sections+0x20/0x20
[ 1213.473514]  ? kernel_read_file+0x1e6/0x5d0
[ 1213.473514]  ? find_held_lock+0x32/0x1c0
[ 1213.473514]  ? cap_capable+0x1ae/0x210
[ 1213.473514]  ? __do_sys_finit_module+0x162/0x190
[ 1213.473514]  __do_sys_finit_module+0x162/0x190
[ 1213.473514]  ? __ia32_sys_init_module+0xa0/0xa0
[ 1213.473514]  ? __mutex_unlock_slowpath+0xdc/0x690
[ 1213.473514]  ? wait_for_completion+0x370/0x370
[ 1213.473514]  ? vfs_write+0x204/0x4a0
[ 1213.473514]  ? do_syscall_64+0x18/0x450
[ 1213.473514]  do_syscall_64+0x9f/0x450
[ 1213.473514]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
[ 1213.473514] RIP: 0033:0x462e99
[ 1213.473514] Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 
f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 
f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
[ 1213.473514] RSP: 002b:7fa66fa00c58 EFLAGS: 0246 ORIG_RAX: 
0139
[ 1213.473514] RAX: ffda RBX: 0073bf00 RCX: 00462e99
[ 1213.473514] RDX:  RSI: 2300 RDI: 0003
[ 1213.473514] RBP: 7fa66fa00c70 R08:  R09: 
[ 1213.473514] R10:  R11: 0246 R12: 7fa66fa016bc
[ 1213.473514] R13: 004bcefa R14: 006f6fb0 R15: 0004

If usb_register failed, no need to call led_trigger_register_simple.

Reported-by: Hulk Robot 
Fixes: 1264b951463a ("at76c50x-usb: add driver")
Signed-off-by: YueHaibing 
Signed-off-by: Kalle Valo 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/net/wireless/at76c50x-usb.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/net/wireless/at76c50x-usb.c
+++ b/drivers/net/wireless/at76c50x-usb.c
@@ -2582,8 +2582,8 @@ static int __init at76_mod_init(void)
if (result < 0)
printk(KERN_ERR DRIVER_NAME
   ": usb_register failed (status %d)\n", result);
-
-   led_trigger_register_simple("at76_usb-tx", _tx);
+   else
+   led_trigger_register_simple("at76_usb-tx", _tx);
return result;
 }
 




[PATCH 4.4 146/241] cpufreq: pmac32: fix possible object reference leak

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 8d10dc28a9ea6e8c02e825dab28699f3c72b02d9 ]

The call to of_find_node_by_name returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./drivers/cpufreq/pmac32-cpufreq.c:557:2-8: ERROR: missing of_node_put; 
acquired a node pointer with refcount incremented on line 552, but without a 
corresponding object release within this function.
./drivers/cpufreq/pmac32-cpufreq.c:569:1-7: ERROR: missing of_node_put; 
acquired a node pointer with refcount incremented on line 552, but without a 
corresponding object release within this function.
./drivers/cpufreq/pmac32-cpufreq.c:598:1-7: ERROR: missing of_node_put; 
acquired a node pointer with refcount incremented on line 587, but without a 
corresponding object release within this function.

Signed-off-by: Wen Yang 
Cc: "Rafael J. Wysocki" 
Cc: Viresh Kumar 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: linux...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Viresh Kumar 
Signed-off-by: Sasha Levin 
---
 drivers/cpufreq/pmac32-cpufreq.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/cpufreq/pmac32-cpufreq.c b/drivers/cpufreq/pmac32-cpufreq.c
index 1f49d97a70ea1..14928e0dc3265 100644
--- a/drivers/cpufreq/pmac32-cpufreq.c
+++ b/drivers/cpufreq/pmac32-cpufreq.c
@@ -549,6 +549,7 @@ static int pmac_cpufreq_init_7447A(struct device_node 
*cpunode)
volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select");
if (volt_gpio_np)
voltage_gpio = read_gpio(volt_gpio_np);
+   of_node_put(volt_gpio_np);
if (!voltage_gpio){
printk(KERN_ERR "cpufreq: missing cpu-vcore-select gpio\n");
return 1;
@@ -585,6 +586,7 @@ static int pmac_cpufreq_init_750FX(struct device_node 
*cpunode)
if (volt_gpio_np)
voltage_gpio = read_gpio(volt_gpio_np);
 
+   of_node_put(volt_gpio_np);
pvr = mfspr(SPRN_PVR);
has_cpu_l2lve = !((pvr & 0xf00) == 0x100);
 
-- 
2.20.1





[PATCH 4.4 148/241] iio: ad_sigma_delta: Properly handle SPI bus locking vs CS assertion

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit df1d80aee963480c5c2938c64ec0ac3e4a0df2e0 ]

For devices from the SigmaDelta family we need to keep CS low when doing a
conversion, since the device will use the MISO line as a interrupt to
indicate that the conversion is complete.

This is why the driver locks the SPI bus and when the SPI bus is locked
keeps as long as a conversion is going on. The current implementation gets
one small detail wrong though. CS is only de-asserted after the SPI bus is
unlocked. This means it is possible for a different SPI device on the same
bus to send a message which would be wrongfully be addressed to the
SigmaDelta device as well. Make sure that the last SPI transfer that is
done while holding the SPI bus lock de-asserts the CS signal.

Signed-off-by: Lars-Peter Clausen 
Signed-off-by: Alexandru Ardelean 
Signed-off-by: Jonathan Cameron 
Signed-off-by: Sasha Levin 
---
 drivers/iio/adc/ad_sigma_delta.c   | 16 +++-
 include/linux/iio/adc/ad_sigma_delta.h |  1 +
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index a1d072ecb7171..30f200ad6b978 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -62,7 +62,7 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, 
unsigned int reg,
struct spi_transfer t = {
.tx_buf = data,
.len= size + 1,
-   .cs_change  = sigma_delta->bus_locked,
+   .cs_change  = sigma_delta->keep_cs_asserted,
};
struct spi_message m;
int ret;
@@ -217,6 +217,7 @@ static int ad_sd_calibrate(struct ad_sigma_delta 
*sigma_delta,
 
spi_bus_lock(sigma_delta->spi->master);
sigma_delta->bus_locked = true;
+   sigma_delta->keep_cs_asserted = true;
reinit_completion(_delta->completion);
 
ret = ad_sigma_delta_set_mode(sigma_delta, mode);
@@ -234,9 +235,10 @@ static int ad_sd_calibrate(struct ad_sigma_delta 
*sigma_delta,
ret = 0;
}
 out:
+   sigma_delta->keep_cs_asserted = false;
+   ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
sigma_delta->bus_locked = false;
spi_bus_unlock(sigma_delta->spi->master);
-   ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
 
return ret;
 }
@@ -288,6 +290,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev 
*indio_dev,
 
spi_bus_lock(sigma_delta->spi->master);
sigma_delta->bus_locked = true;
+   sigma_delta->keep_cs_asserted = true;
reinit_completion(_delta->completion);
 
ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_SINGLE);
@@ -297,9 +300,6 @@ int ad_sigma_delta_single_conversion(struct iio_dev 
*indio_dev,
ret = wait_for_completion_interruptible_timeout(
_delta->completion, HZ);
 
-   sigma_delta->bus_locked = false;
-   spi_bus_unlock(sigma_delta->spi->master);
-
if (ret == 0)
ret = -EIO;
if (ret < 0)
@@ -315,7 +315,10 @@ int ad_sigma_delta_single_conversion(struct iio_dev 
*indio_dev,
sigma_delta->irq_dis = true;
}
 
+   sigma_delta->keep_cs_asserted = false;
ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
+   sigma_delta->bus_locked = false;
+   spi_bus_unlock(sigma_delta->spi->master);
mutex_unlock(_dev->mlock);
 
if (ret)
@@ -352,6 +355,8 @@ static int ad_sd_buffer_postenable(struct iio_dev 
*indio_dev)
 
spi_bus_lock(sigma_delta->spi->master);
sigma_delta->bus_locked = true;
+   sigma_delta->keep_cs_asserted = true;
+
ret = ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_CONTINUOUS);
if (ret)
goto err_unlock;
@@ -380,6 +385,7 @@ static int ad_sd_buffer_postdisable(struct iio_dev 
*indio_dev)
sigma_delta->irq_dis = true;
}
 
+   sigma_delta->keep_cs_asserted = false;
ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
 
sigma_delta->bus_locked = false;
diff --git a/include/linux/iio/adc/ad_sigma_delta.h 
b/include/linux/iio/adc/ad_sigma_delta.h
index 6cc48ac55fd2a..40b14736c73de 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -66,6 +66,7 @@ struct ad_sigma_delta {
boolirq_dis;
 
boolbus_locked;
+   boolkeep_cs_asserted;
 
uint8_t comm;
 
-- 
2.20.1





[PATCH 4.4 151/241] rtlwifi: fix a potential NULL pointer dereference

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 765976285a8c8db3f0eb7f033829a899d0c2786e ]

In case alloc_workqueue fails, the fix reports the error and
returns to avoid NULL pointer dereference.

Signed-off-by: Kangjie Lu 
Signed-off-by: Kalle Valo 
Signed-off-by: Sasha Levin 
---
 drivers/net/wireless/realtek/rtlwifi/base.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index aab752328c269..5013d8c1d4a60 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -466,6 +466,11 @@ static void _rtl_init_deferred_work(struct ieee80211_hw 
*hw)
/* <2> work queue */
rtlpriv->works.hw = hw;
rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
+   if (unlikely(!rtlpriv->works.rtl_wq)) {
+   pr_err("Failed to allocate work queue\n");
+   return;
+   }
+
INIT_DELAYED_WORK(>works.watchdog_wq,
  (void *)rtl_watchdog_wq_callback);
INIT_DELAYED_WORK(>works.ips_nic_off_wq,
-- 
2.20.1





[PATCH 4.4 149/241] iio: hmc5843: fix potential NULL pointer dereferences

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 536cc27deade8f1ec3c1beefa60d5fbe0f6fcb28 ]

devm_regmap_init_i2c may fail and return NULL. The fix returns
the error when it fails.

Signed-off-by: Kangjie Lu 
Signed-off-by: Jonathan Cameron 
Signed-off-by: Sasha Levin 
---
 drivers/staging/iio/magnetometer/hmc5843_i2c.c | 7 ++-
 drivers/staging/iio/magnetometer/hmc5843_spi.c | 7 ++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/magnetometer/hmc5843_i2c.c 
b/drivers/staging/iio/magnetometer/hmc5843_i2c.c
index 3e06ceb320596..676a8e329eeb6 100644
--- a/drivers/staging/iio/magnetometer/hmc5843_i2c.c
+++ b/drivers/staging/iio/magnetometer/hmc5843_i2c.c
@@ -59,8 +59,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config 
= {
 static int hmc5843_i2c_probe(struct i2c_client *cli,
 const struct i2c_device_id *id)
 {
+   struct regmap *regmap = devm_regmap_init_i2c(cli,
+   _i2c_regmap_config);
+   if (IS_ERR(regmap))
+   return PTR_ERR(regmap);
+
return hmc5843_common_probe(>dev,
-   devm_regmap_init_i2c(cli, _i2c_regmap_config),
+   regmap,
id->driver_data, id->name);
 }
 
diff --git a/drivers/staging/iio/magnetometer/hmc5843_spi.c 
b/drivers/staging/iio/magnetometer/hmc5843_spi.c
index 8be198058ea20..fded442a3c1d1 100644
--- a/drivers/staging/iio/magnetometer/hmc5843_spi.c
+++ b/drivers/staging/iio/magnetometer/hmc5843_spi.c
@@ -59,6 +59,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = 
{
 static int hmc5843_spi_probe(struct spi_device *spi)
 {
int ret;
+   struct regmap *regmap;
const struct spi_device_id *id = spi_get_device_id(spi);
 
spi->mode = SPI_MODE_3;
@@ -68,8 +69,12 @@ static int hmc5843_spi_probe(struct spi_device *spi)
if (ret)
return ret;
 
+   regmap = devm_regmap_init_spi(spi, _spi_regmap_config);
+   if (IS_ERR(regmap))
+   return PTR_ERR(regmap);
+
return hmc5843_common_probe(>dev,
-   devm_regmap_init_spi(spi, _spi_regmap_config),
+   regmap,
id->driver_data, id->name);
 }
 
-- 
2.20.1





[PATCH 4.4 137/241] scsi: libsas: Do discovery on empty PHY to update PHY info

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit d8649fc1c5e40e691d589ed825998c36a947491c ]

When we discover the PHY is empty in sas_rediscover_dev(), the PHY
information (like negotiated linkrate) is not updated.

As such, for a user examining sysfs for that PHY, they would see
incorrect values:

root@(none)$ cd /sys/class/sas_phy/phy-0:0:20
root@(none)$ more negotiated_linkrate
3.0 Gbit
root@(none)$ echo 0 > enable
root@(none)$ more negotiated_linkrate
3.0 Gbit

So fix this, simply discover the PHY again, even though we know it's empty;
in the above example, this gives us:

root@(none)$ more negotiated_linkrate
Phy disabled

We must do this after unregistering the device associated with the PHY
(in sas_unregister_devs_sas_addr()).

Signed-off-by: John Garry 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/libsas/sas_expander.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/scsi/libsas/sas_expander.c 
b/drivers/scsi/libsas/sas_expander.c
index 1a6f65db615e8..ee1f9ee995e53 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -2027,6 +2027,11 @@ static int sas_rediscover_dev(struct domain_device *dev, 
int phy_id, bool last)
if ((SAS_ADDR(sas_addr) == 0) || (res == -ECOMM)) {
phy->phy_state = PHY_EMPTY;
sas_unregister_devs_sas_addr(dev, phy_id, last);
+   /*
+* Even though the PHY is empty, for convenience we discover
+* the PHY to update the PHY info, like negotiated linkrate.
+*/
+   sas_ex_phy_discover(dev, phy_id);
return res;
} else if (SAS_ADDR(sas_addr) == SAS_ADDR(phy->attached_sas_addr) &&
   dev_type_flutter(type, phy->attached_dev_type)) {
-- 
2.20.1





[PATCH 4.4 132/241] hwmon: (vt1211) Use request_muxed_region for Super-IO accesses

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 14b97ba5c20056102b3dd22696bf17b057e60976 ]

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Also, other drivers may attempt to access the LPC bus at the same time,
resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested
address space is supported, and to ensure that access by multiple drivers
is synchronized.

Fixes: 2219cd81a6cd ("hwmon/vt1211: Add probing of alternate config index port")
Signed-off-by: Guenter Roeck 
Signed-off-by: Sasha Levin 
---
 drivers/hwmon/vt1211.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
index 3a6bfa51cb94f..95d5e8ec8b7fc 100644
--- a/drivers/hwmon/vt1211.c
+++ b/drivers/hwmon/vt1211.c
@@ -226,15 +226,21 @@ static inline void superio_select(int sio_cip, int ldn)
outb(ldn, sio_cip + 1);
 }
 
-static inline void superio_enter(int sio_cip)
+static inline int superio_enter(int sio_cip)
 {
+   if (!request_muxed_region(sio_cip, 2, DRVNAME))
+   return -EBUSY;
+
outb(0x87, sio_cip);
outb(0x87, sio_cip);
+
+   return 0;
 }
 
 static inline void superio_exit(int sio_cip)
 {
outb(0xaa, sio_cip);
+   release_region(sio_cip, 2);
 }
 
 /* -
@@ -1282,11 +1288,14 @@ static int __init vt1211_device_add(unsigned short 
address)
 
 static int __init vt1211_find(int sio_cip, unsigned short *address)
 {
-   int err = -ENODEV;
+   int err;
int devid;
 
-   superio_enter(sio_cip);
+   err = superio_enter(sio_cip);
+   if (err)
+   return err;
 
+   err = -ENODEV;
devid = force_id ? force_id : superio_inb(sio_cip, SIO_VT1211_DEVID);
if (devid != SIO_VT1211_ID)
goto EXIT;
-- 
2.20.1





[PATCH 4.4 094/241] cxgb4: Fix error path in cxgb4_init_module

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit a3147770bea76c8dbad73eca3a24c2118da5e719 ]

BUG: unable to handle kernel paging request at a016a270
PGD 3270067 P4D 3270067 PUD 3271063 PMD 230bbd067 PTE 0
Oops:  [#1
CPU: 0 PID: 6134 Comm: modprobe Not tainted 5.1.0+ #33
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org 04/01/2014
RIP: 0010:atomic_notifier_chain_register+0x24/0x60
Code: 1f 80 00 00 00 00 55 48 89 e5 41 54 49 89 f4 53 48 89 fb e8 ae b4 38 01 
48 8b 53 38 48 8d 4b 38 48 85 d2 74 20 45 8b 44 24 10 <44> 3b 42 10 7e 08 eb 13 
44 39 42 10 7c 0d 48 8d 4a 08 48 8b 52 08
RSP: 0018:c9e2bc60 EFLAGS: 00010086
RAX: 0292 RBX: 83467240 RCX: 83467278
RDX: a016a260 RSI: 83752140 RDI: 83467240
RBP: c9e2bc70 R08:  R09: 0001
R10:  R11: 014fa61f R12: a01c8260
R13: 888231091e00 R14:  R15: c9e2be78
FS:  7fbd8d7cd540() GS:888237a0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: a016a270 CR3: 00022c7e3000 CR4: 06f0
Call Trace:
 register_inet6addr_notifier+0x13/0x20
 cxgb4_init_module+0x6c/0x1000 [cxgb4
 ? 0xa01d7000
 do_one_initcall+0x6c/0x3cc
 ? do_init_module+0x22/0x1f1
 ? rcu_read_lock_sched_held+0x97/0xb0
 ? kmem_cache_alloc_trace+0x325/0x3b0
 do_init_module+0x5b/0x1f1
 load_module+0x1db1/0x2690
 ? m_show+0x1d0/0x1d0
 __do_sys_finit_module+0xc5/0xd0
 __x64_sys_finit_module+0x15/0x20
 do_syscall_64+0x6b/0x1d0
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

If pci_register_driver fails, register inet6addr_notifier is
pointless. This patch fix the error path in cxgb4_init_module.

Fixes: b5a02f503caa ("cxgb4 : Update ipv6 address handling api")
Signed-off-by: YueHaibing 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c 
b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index a3e1498ca67ce..3b96622de8ff2 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -5061,15 +5061,24 @@ static int __init cxgb4_init_module(void)
 
ret = pci_register_driver(_driver);
if (ret < 0)
-   debugfs_remove(cxgb4_debugfs_root);
+   goto err_pci;
 
 #if IS_ENABLED(CONFIG_IPV6)
if (!inet6addr_registered) {
-   register_inet6addr_notifier(_inet6addr_notifier);
-   inet6addr_registered = true;
+   ret = register_inet6addr_notifier(_inet6addr_notifier);
+   if (ret)
+   pci_unregister_driver(_driver);
+   else
+   inet6addr_registered = true;
}
 #endif
 
+   if (ret == 0)
+   return ret;
+
+err_pci:
+   debugfs_remove(cxgb4_debugfs_root);
+
return ret;
 }
 
-- 
2.20.1





[PATCH 4.4 131/241] RDMA/cxgb4: Fix null pointer dereference on alloc_skb failure

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit a6d2a5a92e67d151c98886babdc86d530d27111c ]

Currently if alloc_skb fails to allocate the skb a null skb is passed to
t4_set_arp_err_handler and this ends up dereferencing the null skb.  Avoid
the NULL pointer dereference by checking for a NULL skb and returning
early.

Addresses-Coverity: ("Dereference null return")
Fixes: b38a0ad8ec11 ("RDMA/cxgb4: Set arp error handler for PASS_ACCEPT_RPL 
messages")
Signed-off-by: Colin Ian King 
Acked-by: Potnuri Bharat Teja 
Signed-off-by: Jason Gunthorpe 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/hw/cxgb4/cm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index c9cffced00ca1..54fd4d81a3f1f 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -360,6 +360,8 @@ static struct sk_buff *get_skb(struct sk_buff *skb, int 
len, gfp_t gfp)
skb_reset_transport_header(skb);
} else {
skb = alloc_skb(len, gfp);
+   if (!skb)
+   return NULL;
}
t4_set_arp_err_handler(skb, NULL, NULL);
return skb;
-- 
2.20.1





[PATCH 4.4 096/241] powerpc/boot: Fix missing check of lseek() return value

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit 5d085ec04a000fefb5182d3b03ee46ca96d8389b ]

This is detected by Coverity scan: CID: 1440481

Signed-off-by: Bo YU 
Signed-off-by: Michael Ellerman 
Signed-off-by: Sasha Levin 
---
 arch/powerpc/boot/addnote.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/boot/addnote.c b/arch/powerpc/boot/addnote.c
index 9d9f6f334d3cc..3da3e2b1b51bc 100644
--- a/arch/powerpc/boot/addnote.c
+++ b/arch/powerpc/boot/addnote.c
@@ -223,7 +223,11 @@ main(int ac, char **av)
PUT_16(E_PHNUM, np + 2);
 
/* write back */
-   lseek(fd, (long) 0, SEEK_SET);
+   i = lseek(fd, (long) 0, SEEK_SET);
+   if (i < 0) {
+   perror("lseek");
+   exit(1);
+   }
i = write(fd, buf, n);
if (i < 0) {
perror("write");
-- 
2.20.1





[PATCH 4.4 133/241] hwmon: (smsc47m1) Use request_muxed_region for Super-IO accesses

2019-06-09 Thread Greg Kroah-Hartman
[ Upstream commit d6410408ad2a798c4cc685252c1baa713be0ad69 ]

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Also, other drivers may attempt to access the LPC bus at the same time,
resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested
address space is supported, and to ensure that access by multiple drivers
is synchronized.

Fixes: 8d5d45fb1468 ("I2C: Move hwmon drivers (2/3)")
Reported-by: Kefeng Wang 
Reported-by: John Garry 
Cc: John Garry 
Acked-by: John Garry 
Signed-off-by: Guenter Roeck 
Signed-off-by: Sasha Levin 
---
 drivers/hwmon/smsc47m1.c | 28 +++-
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 5d323186d2c10..d24df0c50bea4 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -73,16 +73,21 @@ superio_inb(int reg)
 /* logical device for fans is 0x0A */
 #define superio_select() superio_outb(0x07, 0x0A)
 
-static inline void
+static inline int
 superio_enter(void)
 {
+   if (!request_muxed_region(REG, 2, DRVNAME))
+   return -EBUSY;
+
outb(0x55, REG);
+   return 0;
 }
 
 static inline void
 superio_exit(void)
 {
outb(0xAA, REG);
+   release_region(REG, 2);
 }
 
 #define SUPERIO_REG_ACT0x30
@@ -531,8 +536,12 @@ static int __init smsc47m1_find(struct smsc47m1_sio_data 
*sio_data)
 {
u8 val;
unsigned short addr;
+   int err;
+
+   err = superio_enter();
+   if (err)
+   return err;
 
-   superio_enter();
val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 
/*
@@ -608,13 +617,14 @@ static int __init smsc47m1_find(struct smsc47m1_sio_data 
*sio_data)
 static void smsc47m1_restore(const struct smsc47m1_sio_data *sio_data)
 {
if ((sio_data->activate & 0x01) == 0) {
-   superio_enter();
-   superio_select();
-
-   pr_info("Disabling device\n");
-   superio_outb(SUPERIO_REG_ACT, sio_data->activate);
-
-   superio_exit();
+   if (!superio_enter()) {
+   superio_select();
+   pr_info("Disabling device\n");
+   superio_outb(SUPERIO_REG_ACT, sio_data->activate);
+   superio_exit();
+   } else {
+   pr_warn("Failed to disable device\n");
+   }
}
 }
 
-- 
2.20.1





<    1   2   3   4   5   6   7   8   >