1. 12 Oct, 2017 40 commits
    • Sergey Senozhatsky's avatar
      lib/ratelimit.c: use deferred printk() version · 1c089129
      Sergey Senozhatsky authored
      commit 656d61ce upstream.
      
      printk_ratelimit() invokes ___ratelimit() which may invoke a normal
      printk() (pr_warn() in this particular case) to warn about suppressed
      output.  Given that printk_ratelimit() may be called from anywhere, that
      pr_warn() is dangerous - it may end up deadlocking the system.  Fix
      ___ratelimit() by using deferred printk().
      
      Sasha reported the following lockdep error:
      
       : Unregister pv shared memory for cpu 8
       : select_fallback_rq: 3 callbacks suppressed
       : process 8583 (trinity-c78) no longer affine to cpu8
       :
       : ======================================================
       : WARNING: possible circular locking dependency detected
       : 4.14.0-rc2-next-20170927+ #252 Not tainted
       : ------------------------------------------------------
       : migration/8/62 is trying to acquire lock:
       : (&port_lock_key){-.-.}, at: serial8250_console_write()
       :
       : but task is already holding lock:
       : (&rq->lock){-.-.}, at: sched_cpu_dying()
       :
       : which lock already depends on the new lock.
       :
       :
       : the existing dependency chain (in reverse order) is:
       :
       : -> #3 (&rq->lock){-.-.}:
       : __lock_acquire()
       : lock_acquire()
       : _raw_spin_lock()
       : task_fork_fair()
       : sched_fork()
       : copy_process.part.31()
       : _do_fork()
       : kernel_thread()
       : rest_init()
       : start_kernel()
       : x86_64_start_reservations()
       : x86_64_start_kernel()
       : verify_cpu()
       :
       : -> #2 (&p->pi_lock){-.-.}:
       : __lock_acquire()
       : lock_acquire()
       : _raw_spin_lock_irqsave()
       : try_to_wake_up()
       : default_wake_function()
       : woken_wake_function()
       : __wake_up_common()
       : __wake_up_common_lock()
       : __wake_up()
       : tty_wakeup()
       : tty_port_default_wakeup()
       : tty_port_tty_wakeup()
       : uart_write_wakeup()
       : serial8250_tx_chars()
       : serial8250_handle_irq.part.25()
       : serial8250_default_handle_irq()
       : serial8250_interrupt()
       : __handle_irq_event_percpu()
       : handle_irq_event_percpu()
       : handle_irq_event()
       : handle_level_irq()
       : handle_irq()
       : do_IRQ()
       : ret_from_intr()
       : native_safe_halt()
       : default_idle()
       : arch_cpu_idle()
       : default_idle_call()
       : do_idle()
       : cpu_startup_entry()
       : rest_init()
       : start_kernel()
       : x86_64_start_reservations()
       : x86_64_start_kernel()
       : verify_cpu()
       :
       : -> #1 (&tty->write_wait){-.-.}:
       : __lock_acquire()
       : lock_acquire()
       : _raw_spin_lock_irqsave()
       : __wake_up_common_lock()
       : __wake_up()
       : tty_wakeup()
       : tty_port_default_wakeup()
       : tty_port_tty_wakeup()
       : uart_write_wakeup()
       : serial8250_tx_chars()
       : serial8250_handle_irq.part.25()
       : serial8250_default_handle_irq()
       : serial8250_interrupt()
       : __handle_irq_event_percpu()
       : handle_irq_event_percpu()
       : handle_irq_event()
       : handle_level_irq()
       : handle_irq()
       : do_IRQ()
       : ret_from_intr()
       : native_safe_halt()
       : default_idle()
       : arch_cpu_idle()
       : default_idle_call()
       : do_idle()
       : cpu_startup_entry()
       : rest_init()
       : start_kernel()
       : x86_64_start_reservations()
       : x86_64_start_kernel()
       : verify_cpu()
       :
       : -> #0 (&port_lock_key){-.-.}:
       : check_prev_add()
       : __lock_acquire()
       : lock_acquire()
       : _raw_spin_lock_irqsave()
       : serial8250_console_write()
       : univ8250_console_write()
       : console_unlock()
       : vprintk_emit()
       : vprintk_default()
       : vprintk_func()
       : printk()
       : ___ratelimit()
       : __printk_ratelimit()
       : select_fallback_rq()
       : sched_cpu_dying()
       : cpuhp_invoke_callback()
       : take_cpu_down()
       : multi_cpu_stop()
       : cpu_stopper_thread()
       : smpboot_thread_fn()
       : kthread()
       : ret_from_fork()
       :
       : other info that might help us debug this:
       :
       : Chain exists of:
       :   &port_lock_key --> &p->pi_lock --> &rq->lock
       :
       :  Possible unsafe locking scenario:
       :
       :        CPU0                    CPU1
       :        ----                    ----
       :   lock(&rq->lock);
       :                                lock(&p->pi_lock);
       :                                lock(&rq->lock);
       :   lock(&port_lock_key);
       :
       :  *** DEADLOCK ***
       :
       : 4 locks held by migration/8/62:
       : #0: (&p->pi_lock){-.-.}, at: sched_cpu_dying()
       : #1: (&rq->lock){-.-.}, at: sched_cpu_dying()
       : #2: (printk_ratelimit_state.lock){....}, at: ___ratelimit()
       : #3: (console_lock){+.+.}, at: vprintk_emit()
       :
       : stack backtrace:
       : CPU: 8 PID: 62 Comm: migration/8 Not tainted 4.14.0-rc2-next-20170927+ #252
       : Call Trace:
       : dump_stack()
       : print_circular_bug()
       : check_prev_add()
       : ? add_lock_to_list.isra.26()
       : ? check_usage()
       : ? kvm_clock_read()
       : ? kvm_sched_clock_read()
       : ? sched_clock()
       : ? check_preemption_disabled()
       : __lock_acquire()
       : ? __lock_acquire()
       : ? add_lock_to_list.isra.26()
       : ? debug_check_no_locks_freed()
       : ? memcpy()
       : lock_acquire()
       : ? serial8250_console_write()
       : _raw_spin_lock_irqsave()
       : ? serial8250_console_write()
       : serial8250_console_write()
       : ? serial8250_start_tx()
       : ? lock_acquire()
       : ? memcpy()
       : univ8250_console_write()
       : console_unlock()
       : ? __down_trylock_console_sem()
       : vprintk_emit()
       : vprintk_default()
       : vprintk_func()
       : printk()
       : ? show_regs_print_info()
       : ? lock_acquire()
       : ___ratelimit()
       : __printk_ratelimit()
       : select_fallback_rq()
       : sched_cpu_dying()
       : ? sched_cpu_starting()
       : ? rcutree_dying_cpu()
       : ? sched_cpu_starting()
       : cpuhp_invoke_callback()
       : ? cpu_disable_common()
       : take_cpu_down()
       : ? trace_hardirqs_off_caller()
       : ? cpuhp_invoke_callback()
       : multi_cpu_stop()
       : ? __this_cpu_preempt_check()
       : ? cpu_stop_queue_work()
       : cpu_stopper_thread()
       : ? cpu_stop_create()
       : smpboot_thread_fn()
       : ? sort_range()
       : ? schedule()
       : ? __kthread_parkme()
       : kthread()
       : ? sort_range()
       : ? kthread_create_on_node()
       : ret_from_fork()
       : process 9121 (trinity-c78) no longer affine to cpu8
       : smpboot: CPU 8 is now offline
      
      Link: http://lkml.kernel.org/r/20170928120405.18273-1-sergey.senozhatsky@gmail.com
      Fixes: 6b1d174b ("ratelimit: extend to print suppressed messages on release")
      Signed-off-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Reported-by: default avatarSasha Levin <levinsasha928@gmail.com>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@elte.hu>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1c089129
    • Michal Hocko's avatar
      mm, oom_reaper: skip mm structs with mmu notifiers · 2b819707
      Michal Hocko authored
      commit 4d4bbd85 upstream.
      
      Andrea has noticed that the oom_reaper doesn't invalidate the range via
      mmu notifiers (mmu_notifier_invalidate_range_start/end) and that can
      corrupt the memory of the kvm guest for example.
      
      tlb_flush_mmu_tlbonly already invokes mmu notifiers but that is not
      sufficient as per Andrea:
      
       "mmu_notifier_invalidate_range cannot be used in replacement of
        mmu_notifier_invalidate_range_start/end. For KVM
        mmu_notifier_invalidate_range is a noop and rightfully so. A MMU
        notifier implementation has to implement either ->invalidate_range
        method or the invalidate_range_start/end methods, not both. And if you
        implement invalidate_range_start/end like KVM is forced to do, calling
        mmu_notifier_invalidate_range in common code is a noop for KVM.
      
        For those MMU notifiers that can get away only implementing
        ->invalidate_range, the ->invalidate_range is implicitly called by
        mmu_notifier_invalidate_range_end(). And only those secondary MMUs
        that share the same pagetable with the primary MMU (like AMD iommuv2)
        can get away only implementing ->invalidate_range"
      
      As the callback is allowed to sleep and the implementation is out of
      hand of the MM it is safer to simply bail out if there is an mmu
      notifier registered.  In order to not fail too early make the
      mm_has_notifiers check under the oom_lock and have a little nap before
      failing to give the current oom victim some more time to exit.
      
      [akpm@linux-foundation.org: coding-style fixes]
      Link: http://lkml.kernel.org/r/20170913113427.2291-1-mhocko@kernel.org
      Fixes: aac45363 ("mm, oom: introduce oom reaper")
      Signed-off-by: default avatarMichal Hocko <mhocko@suse.com>
      Reported-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
      Reviewed-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b819707
    • Stefan Wahren's avatar
      staging: vchiq_2835_arm: Fix NULL ptr dereference in free_pagelist · 8a056a11
      Stefan Wahren authored
      commit 974d4d03 upstream.
      
      This fixes a NULL pointer dereference on RPi 2 with multi_v7_defconfig.
      The function page_address() could return NULL with enabled CONFIG_HIGHMEM.
      So fix this by using kmap() instead.
      Signed-off-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
      Fixes: 71bad7f0 ("staging: add bcm2708 vchiq driver")
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8a056a11
    • Andrey Konovalov's avatar
      uwb: ensure that endpoint is interrupt · 8928c5b2
      Andrey Konovalov authored
      commit 70e743e4 upstream.
      
      hwarc_neep_init() assumes that endpoint 0 is interrupt, but there's no
      check for that, which results in a WARNING in USB core code, when a bad
      USB descriptor is provided from a device:
      
      usb 1-1: BOGUS urb xfer, pipe 1 != type 3
      ------------[ cut here ]------------
      WARNING: CPU: 0 PID: 3 at drivers/usb/core/urb.c:449 usb_submit_urb+0xf8a/0x11d0
      Modules linked in:
      CPU: 0 PID: 3 Comm: kworker/0:0 Not tainted 4.13.0+ #111
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
      Workqueue: usb_hub_wq hub_event
      task: ffff88006bdc1a00 task.stack: ffff88006bde8000
      RIP: 0010:usb_submit_urb+0xf8a/0x11d0 drivers/usb/core/urb.c:448
      RSP: 0018:ffff88006bdee3c0 EFLAGS: 00010282
      RAX: 0000000000000029 RBX: ffff8800672a7200 RCX: 0000000000000000
      RDX: 0000000000000029 RSI: ffff88006c815c78 RDI: ffffed000d7bdc6a
      RBP: ffff88006bdee4c0 R08: fffffbfff0fe00ff R09: fffffbfff0fe00ff
      R10: 0000000000000018 R11: fffffbfff0fe00fe R12: 1ffff1000d7bdc7f
      R13: 0000000000000003 R14: 0000000000000001 R15: ffff88006b02cc90
      FS:  0000000000000000(0000) GS:ffff88006c800000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007fe4daddf000 CR3: 000000006add6000 CR4: 00000000000006f0
      Call Trace:
       hwarc_neep_init+0x4ce/0x9c0 drivers/uwb/hwa-rc.c:710
       uwb_rc_add+0x2fb/0x730 drivers/uwb/lc-rc.c:361
       hwarc_probe+0x34e/0x9b0 drivers/uwb/hwa-rc.c:858
       usb_probe_interface+0x351/0x8d0 drivers/usb/core/driver.c:361
       really_probe drivers/base/dd.c:385
       driver_probe_device+0x610/0xa00 drivers/base/dd.c:529
       __device_attach_driver+0x230/0x290 drivers/base/dd.c:625
       bus_for_each_drv+0x15e/0x210 drivers/base/bus.c:463
       __device_attach+0x269/0x3c0 drivers/base/dd.c:682
       device_initial_probe+0x1f/0x30 drivers/base/dd.c:729
       bus_probe_device+0x1da/0x280 drivers/base/bus.c:523
       device_add+0xcf9/0x1640 drivers/base/core.c:1703
       usb_set_configuration+0x1064/0x1890 drivers/usb/core/message.c:1932
       generic_probe+0x73/0xe0 drivers/usb/core/generic.c:174
       usb_probe_device+0xaf/0xe0 drivers/usb/core/driver.c:266
       really_probe drivers/base/dd.c:385
       driver_probe_device+0x610/0xa00 drivers/base/dd.c:529
       __device_attach_driver+0x230/0x290 drivers/base/dd.c:625
       bus_for_each_drv+0x15e/0x210 drivers/base/bus.c:463
       __device_attach+0x269/0x3c0 drivers/base/dd.c:682
       device_initial_probe+0x1f/0x30 drivers/base/dd.c:729
       bus_probe_device+0x1da/0x280 drivers/base/bus.c:523
       device_add+0xcf9/0x1640 drivers/base/core.c:1703
       usb_new_device+0x7b8/0x1020 drivers/usb/core/hub.c:2457
       hub_port_connect drivers/usb/core/hub.c:4890
       hub_port_connect_change drivers/usb/core/hub.c:4996
       port_event drivers/usb/core/hub.c:5102
       hub_event+0x23c8/0x37c0 drivers/usb/core/hub.c:5182
       process_one_work+0x9fb/0x1570 kernel/workqueue.c:2097
       worker_thread+0x1e4/0x1350 kernel/workqueue.c:2231
       kthread+0x324/0x3f0 kernel/kthread.c:231
       ret_from_fork+0x25/0x30 arch/x86/entry/entry_64.S:425
      Code: 48 8b 85 30 ff ff ff 48 8d b8 98 00 00 00 e8 8e 93 07 ff 45 89
      e8 44 89 f1 4c 89 fa 48 89 c6 48 c7 c7 a0 e5 55 86 e8 20 08 8f fd <0f>
      ff e9 9b f7 ff ff e8 4a 04 d6 fd e9 80 f7 ff ff e8 60 11 a6
      ---[ end trace 55d741234124cfc3 ]---
      
      Check that endpoint is interrupt.
      
      Found by syzkaller.
      Signed-off-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8928c5b2
    • Andrey Konovalov's avatar
      uwb: properly check kthread_run return value · 8ff7adb9
      Andrey Konovalov authored
      commit bbf26183 upstream.
      
      uwbd_start() calls kthread_run() and checks that the return value is
      not NULL. But the return value is not NULL in case kthread_run() fails,
      it takes the form of ERR_PTR(-EINTR).
      
      Use IS_ERR() instead.
      
      Also add a check to uwbd_stop().
      Signed-off-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8ff7adb9
    • Lukas Wunner's avatar
      iio: adc: mcp320x: Fix oops on module unload · ec8a7153
      Lukas Wunner authored
      commit 0964e409 upstream.
      
      The driver calls spi_get_drvdata() in its ->remove hook even though it
      has never called spi_set_drvdata().  Stack trace for posterity:
      
      Unable to handle kernel NULL pointer dereference at virtual address 00000220
      Internal error: Oops: 5 [#1] SMP ARM
      [<8072f564>] (mutex_lock) from [<7f1400d0>] (iio_device_unregister+0x24/0x7c [industrialio])
      [<7f1400d0>] (iio_device_unregister [industrialio]) from [<7f15e020>] (mcp320x_remove+0x20/0x30 [mcp320x])
      [<7f15e020>] (mcp320x_remove [mcp320x]) from [<8055a8cc>] (spi_drv_remove+0x2c/0x44)
      [<8055a8cc>] (spi_drv_remove) from [<805087bc>] (__device_release_driver+0x98/0x134)
      [<805087bc>] (__device_release_driver) from [<80509180>] (driver_detach+0xdc/0xe0)
      [<80509180>] (driver_detach) from [<8050823c>] (bus_remove_driver+0x5c/0xb0)
      [<8050823c>] (bus_remove_driver) from [<80509ab0>] (driver_unregister+0x38/0x58)
      [<80509ab0>] (driver_unregister) from [<7f15e69c>] (mcp320x_driver_exit+0x14/0x1c [mcp320x])
      [<7f15e69c>] (mcp320x_driver_exit [mcp320x]) from [<801a78d0>] (SyS_delete_module+0x184/0x1d0)
      [<801a78d0>] (SyS_delete_module) from [<80108100>] (ret_fast_syscall+0x0/0x1c)
      
      Fixes: f5ce4a7a ("iio: adc: add driver for MCP3204/08 12-bit ADC")
      Cc: Oskar Andero <oskar.andero@gmail.com>
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ec8a7153
    • Lukas Wunner's avatar
      iio: adc: mcp320x: Fix readout of negative voltages · 1daa7c5a
      Lukas Wunner authored
      commit e6f47943 upstream.
      
      Commit f686a36b ("iio: adc: mcp320x: Add support for mcp3301")
      returns a signed voltage from mcp320x_adc_conversion() but neglects that
      the caller interprets a negative return value as failure.  Only mcp3301
      (and the upcoming mcp3550/1/3) is affected as the other chips are
      incapable of measuring negative voltages.
      
      Fix and while at it, add mcp3301 to the list of supported chips at the
      top of the file.
      
      Fixes: f686a36b ("iio: adc: mcp320x: Add support for mcp3301")
      Cc: Andrea Galbusera <gizero@gmail.com>
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1daa7c5a
    • Dragos Bogdan's avatar
      iio: ad7793: Fix the serial interface reset · 8b97d5b6
      Dragos Bogdan authored
      commit 7ee3b7eb upstream.
      
      The serial interface can be reset by writing 32 consecutive 1s to the device.
      'ret' was initialized correctly but its value was overwritten when
      ad7793_check_platform_data() was called. Since a dedicated reset function
      is present now, it should be used instead.
      
      Fixes: 2edb769d ("iio:ad7793: Add support for the ad7798 and ad7799")
      Signed-off-by: default avatarDragos Bogdan <dragos.bogdan@analog.com>
      Acked-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8b97d5b6
    • Colin Parker's avatar
      IIO: BME280: Updates to Humidity readings need ctrl_reg write! · f0865d60
      Colin Parker authored
      commit 4b1f0c31 upstream.
      
      The ctrl_reg register needs to be written after any write to
      the humidity registers. The value written to the ctrl_reg register
      does not necessarily need to change, but a write operation must
      occur.
      
      The regmap_update_bits functions will not write to a register
      if the register value matches the value to be written. This saves
      unnecessary bus operations.  The change in this patch forces a bus
      write during the chip_config operation by switching to
      regmap_write_bits.
      
      This will fix issues where the Humidity Sensor Oversampling bits
      are not updated after initialization.
      Signed-off-by: default avatarColin Parker <colin.parker@aclima.io>
      Acked-by: default avatarAndreas Klinger <ak@it-klinger.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f0865d60
    • Matt Fornero's avatar
      iio: core: Return error for failed read_reg · 9af1bd5e
      Matt Fornero authored
      commit 3d62c78a upstream.
      
      If an IIO device returns an error code for a read access via debugfs, it
      is currently ignored by the IIO core (other than emitting an error
      message). Instead, return this error code to user space, so upper layers
      can detect it correctly.
      Signed-off-by: default avatarMatt Fornero <matt.fornero@mathworks.com>
      Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9af1bd5e
    • Stefan Popa's avatar
      staging: iio: ad7192: Fix - use the dedicated reset function avoiding dma from stack. · 8edd1ce3
      Stefan Popa authored
      commit f790923f upstream.
      
      Depends on: 691c4b95d1 ("iio: ad_sigma_delta: Implement a dedicated reset function")
      
      SPI host drivers can use DMA to transfer data, so the buffer should be properly allocated.
      Keeping it on the stack could cause an undefined behavior.
      
      The dedicated reset function solves this issue.
      Signed-off-by: default avatarStefan Popa <stefan.popa@analog.com>
      Acked-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Acked-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8edd1ce3
    • Dragos Bogdan's avatar
      iio: ad_sigma_delta: Implement a dedicated reset function · 1f266a13
      Dragos Bogdan authored
      commit 7fc10de8 upstream.
      
      Since most of the SD ADCs have the option of reseting the serial
      interface by sending a number of SCLKs with CS = 0 and DIN = 1,
      a dedicated function that can do this is usefull.
      
      Needed for the patch:  iio: ad7793: Fix the serial interface reset
      Signed-off-by: default avatarDragos Bogdan <dragos.bogdan@analog.com>
      Acked-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1f266a13
    • Christophe JAILLET's avatar
      iio: adc: twl4030: Disable the vusb3v1 rugulator in the error handling path of... · a2002c92
      Christophe JAILLET authored
      iio: adc: twl4030: Disable the vusb3v1 rugulator in the error handling path of 'twl4030_madc_probe()'
      
      commit 7f70be6e upstream.
      
      Commit 7cc97d77 has introduced a call to 'regulator_disable()' in the
      .remove function.
      So we should also have such a call in the .probe function in case of
      error after a successful 'regulator_enable()' call.
      
      Add a new label for that and use it.
      
      Fixes: 7cc97d77 ("iio: adc: twl4030: Fix ADC[3:6] readings")
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      a2002c92
    • Christophe JAILLET's avatar
      iio: adc: twl4030: Fix an error handling path in 'twl4030_madc_probe()' · ab676614
      Christophe JAILLET authored
      commit 245a396a upstream.
      
      If 'devm_regulator_get()' fails, we should go through the existing error
      handling path instead of returning directly, as done is all the other
      error handling paths in this function.
      
      Fixes: 7cc97d77 ("iio: adc: twl4030: Fix ADC[3:6] readings")
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ab676614
    • Kai-Heng Feng's avatar
      Revert "xhci: Limit USB2 port wake support for AMD Promontory hosts" · a13481f8
      Kai-Heng Feng authored
      commit bcd6a7aa upstream.
      
      This reverts commit dec08194.
      
      Commit dec08194 ("xhci: Limit USB2 port wake support for AMD Promontory
      hosts") makes all high speed USB ports on ASUS PRIME B350M-A cease to
      function after enabling runtime PM.
      
      All boards with this chipsets will be affected, so revert the commit.
      
      The original patch was added to stable 4.9, 4.11 and 4.12 and needs
      to reverted from there as well
      Signed-off-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a13481f8
    • Mathias Nyman's avatar
      xhci: set missing SuperSpeedPlus Link Protocol bit in roothub descriptor · f77615db
      Mathias Nyman authored
      commit 7bea22b1 upstream.
      
      A SuperSpeedPlus roothub needs to have the Link Protocol (LP) bit set in
      the bmSublinkSpeedAttr[] entry of a SuperSpeedPlus descriptor.
      
      If the xhci controller has an optional Protocol Speed ID (PSI) table then
      that will be used as a base to create the roothub SuperSpeedPlus
      descriptor.
      The PSI table does not however necessary contain the LP bit so we need
      to set it manually.
      
      Check the psi speed and set LP bit if speed is 10Gbps or higher.
      We're not setting it for 5 to 10Gbps as USB 3.1 specification always
      mention SuperSpeedPlus for 10Gbps or higher, and some SSIC USB 3.0 speeds
      can be over 5Gbps, such as SSIC-G3B-L1 at 5830 Mbps
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f77615db
    • Mathias Nyman's avatar
      xhci: Fix sleeping with spin_lock_irq() held in ASmedia 1042A workaround · f1a04773
      Mathias Nyman authored
      commit 4ec1cd3e upstream.
      
      The flow control workaround for ASM1042A xHC hosts sleeps between
      register polling. The workaround gets called in several places, among
      them with spin_lock_irq() held when xHC host is resumed or hoplug removed.
      
      This was noticed as kernel panics at resume on a Dell XPS15 9550 with
      TB16 thunderbolt dock.
      
      Avoid sleeping with spin_lock_irq() held, use udelay() instead
      
      The original workaround was added to 4.9 and 4.12 stable releases,
      this patch needs to be applied to those as well.
      
      Fixes: 9da5a109 ("xhci: Bad Ethernet performance plugged in ASM1042A host")
      Reported-by: default avatarJose Marino <marinoj@nso.edu>
      Tested-by: default avatarJose Marino <marinoj@nso.edu>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f1a04773
    • Mathias Nyman's avatar
      xhci: fix finding correct bus_state structure for USB 3.1 hosts · 67e752e1
      Mathias Nyman authored
      commit 5a838a13 upstream.
      
      xhci driver keeps a bus_state structure for each hcd (usb2 and usb3)
      
      The structure is picked based on hcd speed, but driver only compared
      for HCD_USB3 speed, returning the wrong bus_state for HCD_USB31 hosts.
      
      This caused null pointer dereference errors in bus_resume function.
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      67e752e1
    • Greg Kroah-Hartman's avatar
      USB: fix out-of-bounds in usb_set_configuration · a6d4ce2e
      Greg Kroah-Hartman authored
      commit bd7a3fe7 upstream.
      
      Andrey Konovalov reported a possible out-of-bounds problem for a USB interface
      association descriptor.  He writes:
      	It seems there's no proper size check of a USB_DT_INTERFACE_ASSOCIATION
      	descriptor. It's only checked that the size is >= 2 in
      	usb_parse_configuration(), so find_iad() might do out-of-bounds access
      	to intf_assoc->bInterfaceCount.
      
      And he's right, we don't check for crazy descriptors of this type very well, so
      resolve this problem.  Yet another issue found by syzkaller...
      Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Tested-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a6d4ce2e
    • Dmitry Fleytman's avatar
      usb: Increase quirk delay for USB devices · 43feb29d
      Dmitry Fleytman authored
      commit b2a542bb upstream.
      
      Commit e0429362
      ("usb: Add device quirk for Logitech HD Pro Webcams C920 and C930e")
      introduced quirk to workaround an issue with some Logitech webcams.
      
      The workaround is introducing delay for some USB operations.
      
      According to our testing, delay introduced by original commit
      is not long enough and in rare cases we still see issues described
      by the aforementioned commit.
      
      This patch increases delays introduced by original commit.
      Having this patch applied we do not see those problems anymore.
      Signed-off-by: default avatarDmitry Fleytman <dmitry@daynix.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      43feb29d
    • Greg Kroah-Hartman's avatar
      USB: core: harden cdc_parse_cdc_header · 767f7a2c
      Greg Kroah-Hartman authored
      commit 2e1c4239 upstream.
      
      Andrey Konovalov reported a possible out-of-bounds problem for the
      cdc_parse_cdc_header function.  He writes:
      	It looks like cdc_parse_cdc_header() doesn't validate buflen
      	before accessing buffer[1], buffer[2] and so on. The only check
      	present is while (buflen > 0).
      
      So fix this issue up by properly validating the buffer length matches
      what the descriptor says it is.
      Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Tested-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      767f7a2c
    • Alan Stern's avatar
      USB: uas: fix bug in handling of alternate settings · d77606e9
      Alan Stern authored
      commit 786de92b upstream.
      
      The uas driver has a subtle bug in the way it handles alternate
      settings.  The uas_find_uas_alt_setting() routine returns an
      altsetting value (the bAlternateSetting number in the descriptor), but
      uas_use_uas_driver() then treats that value as an index to the
      intf->altsetting array, which it isn't.
      
      Normally this doesn't cause any problems because the various
      alternate settings have bAlternateSetting values 0, 1, 2, ..., so the
      value is equal to the index in the array.  But this is not guaranteed,
      and Andrey Konovalov used the syzkaller fuzzer with KASAN to get a
      slab-out-of-bounds error by violating this assumption.
      
      This patch fixes the bug by making uas_find_uas_alt_setting() return a
      pointer to the altsetting entry rather than either the value or the
      index.  Pointers are less subject to misinterpretation.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Tested-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      CC: Oliver Neukum <oneukum@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d77606e9
    • Alan Stern's avatar
      USB: g_mass_storage: Fix deadlock when driver is unbound · da785bb6
      Alan Stern authored
      commit 1fbbb78f upstream.
      
      As a holdover from the old g_file_storage gadget, the g_mass_storage
      legacy gadget driver attempts to unregister itself when its main
      operating thread terminates (if it hasn't been unregistered already).
      This is not strictly necessary; it was never more than an attempt to
      have the gadget fail cleanly if something went wrong and the main
      thread was killed.
      
      However, now that the UDC core manages gadget drivers independently of
      UDC drivers, this scheme doesn't work any more.  A simple test:
      
      	modprobe dummy-hcd
      	modprobe g-mass-storage file=...
      	rmmod dummy-hcd
      
      ends up in a deadlock with the following backtrace:
      
       sysrq: SysRq : Show Blocked State
         task                PC stack   pid father
       file-storage    D    0  1130      2 0x00000000
       Call Trace:
        __schedule+0x53e/0x58c
        schedule+0x6e/0x77
        schedule_preempt_disabled+0xd/0xf
        __mutex_lock.isra.1+0x129/0x224
        ? _raw_spin_unlock_irqrestore+0x12/0x14
        __mutex_lock_slowpath+0x12/0x14
        mutex_lock+0x28/0x2b
        usb_gadget_unregister_driver+0x29/0x9b [udc_core]
        usb_composite_unregister+0x10/0x12 [libcomposite]
        msg_cleanup+0x1d/0x20 [g_mass_storage]
        msg_thread_exits+0xd/0xdd7 [g_mass_storage]
        fsg_main_thread+0x1395/0x13d6 [usb_f_mass_storage]
        ? __schedule+0x573/0x58c
        kthread+0xd9/0xdb
        ? do_set_interface+0x25c/0x25c [usb_f_mass_storage]
        ? init_completion+0x1e/0x1e
        ret_from_fork+0x19/0x24
       rmmod           D    0  1155    683 0x00000000
       Call Trace:
        __schedule+0x53e/0x58c
        schedule+0x6e/0x77
        schedule_timeout+0x26/0xbc
        ? __schedule+0x573/0x58c
        do_wait_for_common+0xb3/0x128
        ? usleep_range+0x81/0x81
        ? wake_up_q+0x3f/0x3f
        wait_for_common+0x2e/0x45
        wait_for_completion+0x17/0x19
        fsg_common_put+0x34/0x81 [usb_f_mass_storage]
        fsg_free_inst+0x13/0x1e [usb_f_mass_storage]
        usb_put_function_instance+0x1a/0x25 [libcomposite]
        msg_unbind+0x2a/0x42 [g_mass_storage]
        __composite_unbind+0x4a/0x6f [libcomposite]
        composite_unbind+0x12/0x14 [libcomposite]
        usb_gadget_remove_driver+0x4f/0x77 [udc_core]
        usb_del_gadget_udc+0x52/0xcc [udc_core]
        dummy_udc_remove+0x27/0x2c [dummy_hcd]
        platform_drv_remove+0x1d/0x31
        device_release_driver_internal+0xe9/0x16d
        device_release_driver+0x11/0x13
        bus_remove_device+0xd2/0xe2
        device_del+0x19f/0x221
        ? selinux_capable+0x22/0x27
        platform_device_del+0x21/0x63
        platform_device_unregister+0x10/0x1a
        cleanup+0x20/0x817 [dummy_hcd]
        SyS_delete_module+0x10c/0x197
        ? ____fput+0xd/0xf
        ? task_work_run+0x55/0x62
        ? prepare_exit_to_usermode+0x65/0x75
        do_fast_syscall_32+0x86/0xc3
        entry_SYSENTER_32+0x4e/0x7c
      
      What happens is that removing the dummy-hcd driver causes the UDC core
      to unbind the gadget driver, which it does while holding the udc_lock
      mutex.  The unbind routine in g_mass_storage tells the main thread to
      exit and waits for it to terminate.
      
      But as mentioned above, when the main thread exits it tries to
      unregister the mass-storage function driver.  Via the composite
      framework this ends up calling usb_gadget_unregister_driver(), which
      tries to acquire the udc_lock mutex.  The result is deadlock.
      
      The simplest way to fix the problem is not to be so clever: The main
      thread doesn't have to unregister the function driver.  The side
      effects won't be so terrible; if the gadget is still attached to a USB
      host when the main thread is killed, it will appear to the host as
      though the gadget's firmware has crashed -- a reasonably accurate
      interpretation, and an all-too-common occurrence for USB mass-storage
      devices.
      
      In fact, the code to unregister the driver when the main thread exits
      is specific to g-mass-storage; it is not used when f-mass-storage is
      included as a function in a larger composite device.  Therefore the
      entire mechanism responsible for this (the fsg_operations structure
      with its ->thread_exits method, the fsg_common_set_ops() routine, and
      the msg_thread_exits() callback routine) can all be eliminated.  Even
      the msg_registered bitflag can be removed, because now the driver is
      unregistered in only one place rather than in two places.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Acked-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Acked-by: default avatarMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      da785bb6
    • Li Jun's avatar
      usb: gadget: mass_storage: set msg_registered after msg registered · 2b5c7b95
      Li Jun authored
      commit 8e55d303 upstream.
      
      If there is no UDC available, the msg register will fail and this
      flag will not be set, but the driver is already added into pending
      driver list, then the module removal modprobe -r can not remove
      the driver from the pending list.
      Signed-off-by: default avatarLi Jun <jun.li@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b5c7b95
    • Dan Carpenter's avatar
      USB: devio: Don't corrupt user memory · 77a4be89
      Dan Carpenter authored
      commit fa1ed74e upstream.
      
      The user buffer has "uurb->buffer_length" bytes.  If the kernel has more
      information than that, we should truncate it instead of writing past
      the end of the user's buffer.  I added a WARN_ONCE() to help the user
      debug the issue.
      Reported-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      77a4be89
    • Alan Stern's avatar
      USB: dummy-hcd: Fix erroneous synchronization change · e39b1714
      Alan Stern authored
      commit 7dbd8f4c upstream.
      
      A recent change to the synchronization in dummy-hcd was incorrect.
      The issue was that dummy_udc_stop() contained no locking and therefore
      could race with various gadget driver callbacks, and the fix was to
      add locking and issue the callbacks with the private spinlock held.
      
      UDC drivers aren't supposed to do this.  Gadget driver callback
      routines are allowed to invoke functions in the UDC driver, and these
      functions will generally try to acquire the private spinlock.  This
      would deadlock the driver.
      
      The correct solution is to drop the spinlock before issuing callbacks,
      and avoid races by emulating the synchronize_irq() call that all real
      UDC drivers must perform in their ->udc_stop() routines after
      disabling interrupts.  This involves adding a flag to dummy-hcd's
      private structure to keep track of whether interrupts are supposed to
      be enabled, and adding a counter to keep track of ongoing callbacks so
      that dummy_udc_stop() can wait for them all to finish.
      
      A real UDC driver won't receive disconnect, reset, suspend, resume, or
      setup events once it has disabled interrupts.  dummy-hcd will receive
      them but won't try to issue any gadget driver callbacks, which should
      be just as good.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Fixes: f16443a0 ("USB: gadgetfs, dummy-hcd, net2280: fix locking for callbacks")
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e39b1714
    • Alan Stern's avatar
      USB: dummy-hcd: fix infinite-loop resubmission bug · 795f5501
      Alan Stern authored
      commit 0173a68b upstream.
      
      The dummy-hcd HCD/UDC emulator tries not to do too much work during
      each timer interrupt.  But it doesn't try very hard; currently all
      it does is limit the total amount of bulk data transferred.  Other
      transfer types aren't limited, and URBs that transfer no data (because
      of an error, perhaps) don't count toward the limit, even though on a
      real USB bus they would consume at least a minimum overhead.
      
      This means it's possible to get the driver stuck in an infinite loop,
      for example, if the host class driver resubmits an URB every time it
      completes (which is common for interrupt URBs).  Each time the URB is
      resubmitted it gets added to the end of the pending-URBs list, and
      dummy-hcd doesn't stop until that list is empty.  Andrey Konovalov was
      able to trigger this failure mode using the syzkaller fuzzer.
      
      This patch fixes the infinite-loop problem by restricting the URBs
      handled during each timer interrupt to those that were already on the
      pending list when the interrupt routine started.  Newly added URBs
      won't be processed until the next timer interrupt.  The problem of
      properly accounting for non-bulk bandwidth (as well as packet and
      transaction overhead) is not addressed here.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Tested-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      795f5501
    • Alan Stern's avatar
      USB: dummy-hcd: fix connection failures (wrong speed) · 5effe995
      Alan Stern authored
      commit fe659bcc upstream.
      
      The dummy-hcd UDC driver is not careful about the way it handles
      connection speeds.  It ignores the module parameter that is supposed
      to govern the maximum connection speed and it doesn't set the HCD
      flags properly for the case where it ends up running at full speed.
      
      The result is that in many cases, gadget enumeration over dummy-hcd
      fails because the bMaxPacketSize byte in the device descriptor is set
      incorrectly.  For example, the default settings call for a high-speed
      connection, but the maxpacket value for ep0 ends up being set for a
      Super-Speed connection.
      
      This patch fixes the problem by initializing the gadget's max_speed
      and the HCD flags correctly.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5effe995
    • Bjørn Mork's avatar
      USB: cdc-wdm: ignore -EPIPE from GetEncapsulatedResponse · 12071de6
      Bjørn Mork authored
      commit 8fec9355 upstream.
      
      The driver will forward errors to userspace after turning most of them
      into -EIO. But all status codes are not equal. The -EPIPE (stall) in
      particular can be seen more as a result of normal USB signaling than
      an actual error. The state is automatically cleared by the USB core
      without intervention from either driver or userspace.
      
      And most devices and firmwares will never trigger a stall as a result
      of GetEncapsulatedResponse. This is in fact a requirement for CDC WDM
      devices. Quoting from section 7.1 of the CDC WMC spec revision 1.1:
      
        The function shall not return STALL in response to
        GetEncapsulatedResponse.
      
      But this driver is also handling GetEncapsulatedResponse on behalf of
      the qmi_wwan and cdc_mbim drivers. Unfortunately the relevant specs
      are not as clear wrt stall. So some QMI and MBIM devices *will*
      occasionally stall, causing the GetEncapsulatedResponse to return an
      -EPIPE status. Translating this into -EIO for userspace has proven to
      be harmful. Treating it as an empty read is safer, making the driver
      behave as if the device was conforming to the CDC WDM spec.
      
      There have been numerous reports of issues related to -EPIPE errors
      from some newer CDC MBIM devices in particular, like for example the
      Fibocom L831-EAU.  Testing on this device has shown that the issues
      go away if we simply ignore the -EPIPE status.  Similar handling of
      -EPIPE is already known from e.g. usb_get_string()
      
      The -EPIPE log message is still kept to let us track devices with this
      unexpected behaviour, hoping that it attracts attention from firmware
      developers.
      
      Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100938Reported-and-tested-by: default avatarChristian Ehrig <christian.ehrig@mediamarktsaturn-bt.com>
      Reported-and-tested-by: default avatarPatrick Chilton <chpatrick@gmail.com>
      Reported-and-tested-by: default avatarAndreas Böhler <news@aboehler.at>
      Signed-off-by: default avatarBjørn Mork <bjorn@mork.no>
      Acked-by: default avatarOliver Neukum <oneukum@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12071de6
    • Jim Dickerson's avatar
      usb: pci-quirks.c: Corrected timeout values used in handshake · 0b104f92
      Jim Dickerson authored
      commit 114ec3a6 upstream.
      
      Servers were emitting failed handoff messages but were not
      waiting the full 1 second as designated in section 4.22.1 of
      the eXtensible Host Controller Interface specifications. The
      handshake was using wrong units so calls were made with milliseconds
      not microseconds. Comments referenced 5 seconds not 1 second as
      in specs.
      
      The wrong units were also corrected in a second handshake call.
      Signed-off-by: default avatarJim Dickerson <jim.dickerson@hpe.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0b104f92
    • Takashi Iwai's avatar
      ALSA: usb-audio: Check out-of-bounds access by corrupted buffer descriptor · 37b6d898
      Takashi Iwai authored
      commit bfc81a8b upstream.
      
      When a USB-audio device receives a maliciously adjusted or corrupted
      buffer descriptor, the USB-audio driver may access an out-of-bounce
      value at its parser.  This was detected by syzkaller, something like:
      
        BUG: KASAN: slab-out-of-bounds in usb_audio_probe+0x27b2/0x2ab0
        Read of size 1 at addr ffff88006b83a9e8 by task kworker/0:1/24
        CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted 4.14.0-rc1-42251-gebb2c243 #224
        Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
        Workqueue: usb_hub_wq hub_event
        Call Trace:
         __dump_stack lib/dump_stack.c:16
         dump_stack+0x292/0x395 lib/dump_stack.c:52
         print_address_description+0x78/0x280 mm/kasan/report.c:252
         kasan_report_error mm/kasan/report.c:351
         kasan_report+0x22f/0x340 mm/kasan/report.c:409
         __asan_report_load1_noabort+0x19/0x20 mm/kasan/report.c:427
         snd_usb_create_streams sound/usb/card.c:248
         usb_audio_probe+0x27b2/0x2ab0 sound/usb/card.c:605
         usb_probe_interface+0x35d/0x8e0 drivers/usb/core/driver.c:361
         really_probe drivers/base/dd.c:413
         driver_probe_device+0x610/0xa00 drivers/base/dd.c:557
         __device_attach_driver+0x230/0x290 drivers/base/dd.c:653
         bus_for_each_drv+0x161/0x210 drivers/base/bus.c:463
         __device_attach+0x26e/0x3d0 drivers/base/dd.c:710
         device_initial_probe+0x1f/0x30 drivers/base/dd.c:757
         bus_probe_device+0x1eb/0x290 drivers/base/bus.c:523
         device_add+0xd0b/0x1660 drivers/base/core.c:1835
         usb_set_configuration+0x104e/0x1870 drivers/usb/core/message.c:1932
         generic_probe+0x73/0xe0 drivers/usb/core/generic.c:174
         usb_probe_device+0xaf/0xe0 drivers/usb/core/driver.c:266
         really_probe drivers/base/dd.c:413
         driver_probe_device+0x610/0xa00 drivers/base/dd.c:557
         __device_attach_driver+0x230/0x290 drivers/base/dd.c:653
         bus_for_each_drv+0x161/0x210 drivers/base/bus.c:463
         __device_attach+0x26e/0x3d0 drivers/base/dd.c:710
         device_initial_probe+0x1f/0x30 drivers/base/dd.c:757
         bus_probe_device+0x1eb/0x290 drivers/base/bus.c:523
         device_add+0xd0b/0x1660 drivers/base/core.c:1835
         usb_new_device+0x7b8/0x1020 drivers/usb/core/hub.c:2457
         hub_port_connect drivers/usb/core/hub.c:4903
         hub_port_connect_change drivers/usb/core/hub.c:5009
         port_event drivers/usb/core/hub.c:5115
         hub_event+0x194d/0x3740 drivers/usb/core/hub.c:5195
         process_one_work+0xc7f/0x1db0 kernel/workqueue.c:2119
         worker_thread+0x221/0x1850 kernel/workqueue.c:2253
         kthread+0x3a1/0x470 kernel/kthread.c:231
         ret_from_fork+0x2a/0x40 arch/x86/entry/entry_64.S:431
      
      This patch adds the checks of out-of-bounce accesses at appropriate
      places and bails out when it goes out of the given buffer.
      Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Tested-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      37b6d898
    • Yoshihiro Shimoda's avatar
      usb: renesas_usbhs: fix usbhsf_fifo_clear() for RX direction · eb5df140
      Yoshihiro Shimoda authored
      commit 0a2ce62b upstream.
      
      This patch fixes an issue that the usbhsf_fifo_clear() is possible
      to cause 10 msec delay if the pipe is RX direction and empty because
      the FRDY bit will never be set to 1 in such case.
      
      Fixes: e8d548d5 ("usb: renesas_usbhs: fifo became independent from pipe.")
      Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eb5df140
    • Yoshihiro Shimoda's avatar
      usb: renesas_usbhs: fix the BCLR setting condition for non-DCP pipe · 4661c9b5
      Yoshihiro Shimoda authored
      commit 6124607a upstream.
      
      This patch fixes an issue that the driver sets the BCLR bit of
      {C,Dn}FIFOCTR register to 1 even when it's non-DCP pipe and
      the FRDY bit of {C,Dn}FIFOCTR register is set to 1.
      
      Fixes: e8d548d5 ("usb: renesas_usbhs: fifo became independent from pipe.")
      Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4661c9b5
    • Alan Stern's avatar
      usb-storage: fix bogus hardware error messages for ATA pass-thru devices · 760d0f10
      Alan Stern authored
      commit a4fd4a72 upstream.
      
      Ever since commit a621bac3 ("scsi_lib: correctly retry failed zero
      length REQ_TYPE_FS commands"), people have been getting bogus error
      messages for USB disk drives using ATA pass-thru.  For example:
      
      [ 1344.880193] sd 6:0:0:0: [sdb] Attached SCSI disk
      [ 1345.069152] sd 6:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_ERROR driverbyte=DRIVER_SENSE
      [ 1345.069159] sd 6:0:0:0: [sdb] tag#0 Sense Key : Hardware Error [current] [descriptor]
      [ 1345.069162] sd 6:0:0:0: [sdb] tag#0 Add. Sense: No additional sense information
      [ 1345.069168] sd 6:0:0:0: [sdb] tag#0 CDB: ATA command pass through(16) 85 06 20 00 00 00 00 00 00 00 00 00 00 00 e5 00
      [ 1345.172252] sd 6:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_ERROR driverbyte=DRIVER_SENSE
      [ 1345.172258] sd 6:0:0:0: [sdb] tag#0 Sense Key : Hardware Error [current] [descriptor]
      [ 1345.172261] sd 6:0:0:0: [sdb] tag#0 Add. Sense: No additional sense information
      [ 1345.172266] sd 6:0:0:0: [sdb] tag#0 CDB: ATA command pass through(12)/Blank a1 06 20 da 00 00 4f c2 00 b0 00 00
      
      These messages can be quite annoying, because programs like udisks2
      provoke them every 10 minutes or so.  Other programs can also have
      this effect, such as those in smartmontools.
      
      I don't fully understand how that commit induced the SCSI core to log
      these error messages, but the underlying cause for them is code added
      to usb-storage by commit f1a0743b ("USB: storage: When a device
      returns no sense data, call it a Hardware Error").  At the time it was
      necessary to do this, in order to prevent an infinite retry loop with
      some not-so-great mass storage devices.
      
      However, the ATA pass-thru protocol uses SCSI sense data to return
      command status values, and some devices always report Check Condition
      status for ATA pass-thru commands to ensure that the host retrieves
      the sense data, even if the command succeeded.  This violates the USB
      mass-storage protocol (Check Condition status is supposed to mean the
      command failed), but we can't help that.
      
      This patch attempts to mitigate the problem of these bogus error
      reports by changing usb-storage.  The HARDWARE ERROR sense key will be
      inserted only for commands that aren't ATA pass-thru.
      
      Thanks to Ewan Milne for pointing out that this mechanism was present
      in usb-storage.  8 years after writing it, I had completely forgotten
      its existence.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Tested-by: default avatarKris Lindgren <kris.lindgren@gmail.com>
      Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1351305
      CC: Ewan D. Milne <emilne@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      760d0f10
    • Alan Stern's avatar
      usb-storage: unusual_devs entry to fix write-access regression for Seagate external drives · dd52953f
      Alan Stern authored
      commit 113f6eb6 upstream.
      
      Kris Lindgren reports that without the NO_WP_DETECT flag, his Seagate
      external disk drive fails all write accesses.  This regresssion dates
      back approximately to the start of the 4.x kernel releases.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Reported-by: default avatarKris Lindgren <kris.lindgren@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dd52953f
    • Yoshihiro Shimoda's avatar
      usb: gadget: udc: renesas_usb3: Fix return value of usb3_write_pipe() · d21653d0
      Yoshihiro Shimoda authored
      commit 447b8a01 upstream.
      
      This patch fixes an issue that this driver cannot go status stage
      in control read when the req.zero is set to 1 and the len in
      usb3_write_pipe() is set to 0. Otherwise, if we use g_ncm driver,
      usb enumeration takes long time (5 seconds or more).
      
      Fixes: 746bfe63 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 peripheral controller")
      Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d21653d0
    • Yoshihiro Shimoda's avatar
      usb: gadget: udc: renesas_usb3: fix Pn_RAMMAP.Pn_MPKT value · db73b389
      Yoshihiro Shimoda authored
      commit 73f2f574 upstream.
      
      According to the datasheet of R-Car Gen3, the Pn_RAMMAP.Pn_MPKT should
      be set to one of 8, 16, 32, 64, 512 and 1024. Otherwise, when a gadget
      driver uses an interrupt endpoint, unexpected behavior happens. So,
      this patch fixes it.
      
      Fixes: 746bfe63 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 peripheral controller")
      Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      db73b389
    • Yoshihiro Shimoda's avatar
      usb: gadget: udc: renesas_usb3: fix for no-data control transfer · 25533678
      Yoshihiro Shimoda authored
      commit 4dcf4bab upstream.
      
      When bRequestType & USB_DIR_IN is false and req.length is 0 in control
      transfer, since it means non-data, this driver should not set the mode
      as control write. So, this patch fixes it.
      
      Fixes: 746bfe63 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 peripheral controller")
      Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      25533678
    • Nicolas Ferre's avatar
      usb: gadget: udc: atmel: set vbus irqflags explicitly · 744f9e1d
      Nicolas Ferre authored
      commit 6baeda12 upstream.
      
      The driver triggers actions on both edges of the vbus signal.
      
      The former PIO controller was triggering IRQs on both falling and rising edges
      by default. Newer PIO controller don't, so it's better to set it explicitly to
      IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING.
      
      Without this patch we may trigger the connection with host but only on some
      bouncing signal conditions and thus lose connecting events.
      Acked-by: default avatarLudovic Desroches <ludovic.desroches@microchip.com>
      Signed-off-by: default avatarNicolas Ferre <nicolas.ferre@microchip.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      744f9e1d
    • Alan Stern's avatar
      USB: gadgetfs: fix copy_to_user while holding spinlock · 7f850036
      Alan Stern authored
      commit 6e76c01e upstream.
      
      The gadgetfs driver as a long-outstanding FIXME, regarding a call of
      copy_to_user() made while holding a spinlock.  This patch fixes the
      issue by dropping the spinlock and using the dev->udc_usage mechanism
      introduced by another recent patch to guard against status changes
      while the lock isn't held.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Acked-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7f850036