1. 07 11月, 2018 3 次提交
  2. 16 10月, 2018 1 次提交
    • A
      USB: fix the usbfs flag sanitization for control transfers · 665c365a
      Alan Stern 提交于
      Commit 7a68d9fb ("USB: usbdevfs: sanitize flags more") checks the
      transfer flags for URBs submitted from userspace via usbfs.  However,
      the check for whether the USBDEVFS_URB_SHORT_NOT_OK flag should be
      allowed for a control transfer was added in the wrong place, before
      the code has properly determined the direction of the control
      transfer.  (Control transfers are special because for them, the
      direction is set by the bRequestType byte of the Setup packet rather
      than direction bit of the endpoint address.)
      
      This patch moves code which sets up the allow_short flag for control
      transfers down after is_in has been set to the correct value.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-and-tested-by: syzbot+24a30223a4b609bb802e@syzkaller.appspotmail.com
      Fixes: 7a68d9fb ("USB: usbdevfs: sanitize flags more")
      CC: Oliver Neukum <oneukum@suse.com>
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      665c365a
  3. 09 10月, 2018 2 次提交
  4. 03 10月, 2018 3 次提交
    • E
      signal: Distinguish between kernel_siginfo and siginfo · ae7795bc
      Eric W. Biederman 提交于
      Linus recently observed that if we did not worry about the padding
      member in struct siginfo it is only about 48 bytes, and 48 bytes is
      much nicer than 128 bytes for allocating on the stack and copying
      around in the kernel.
      
      The obvious thing of only adding the padding when userspace is
      including siginfo.h won't work as there are sigframe definitions in
      the kernel that embed struct siginfo.
      
      So split siginfo in two; kernel_siginfo and siginfo.  Keeping the
      traditional name for the userspace definition.  While the version that
      is used internally to the kernel and ultimately will not be padded to
      128 bytes is called kernel_siginfo.
      
      The definition of struct kernel_siginfo I have put in include/signal_types.h
      
      A set of buildtime checks has been added to verify the two structures have
      the same field offsets.
      
      To make it easy to verify the change kernel_siginfo retains the same
      size as siginfo.  The reduction in size comes in a following change.
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      ae7795bc
    • B
      usb: export firmware port location in sysfs · 355c74e5
      Bjørn Mork 提交于
      The platform firmware "location" data is used to find port peer
      relationships. But firmware is an unreliable source, and there are
      real world examples of errors leading to missing or wrong peer
      relationships.  Debugging this is currently hard.
      
      Exporting the location attribute makes it easier to spot mismatches
      between the firmware data and the real world.
      Signed-off-by: NBjørn Mork <bjorn@mork.no>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      355c74e5
    • Z
      usb: hub: try old enumeration scheme first for high speed devices · bd0e6c96
      Zeng Tao 提交于
      The new scheme is required just to support legacy low and full-speed
      devices. For high speed devices, it will slower the enumeration speed.
      So in this patch we try the "old" enumeration scheme first for high speed
      devices, and this is what Windows does since Windows 8.
      Signed-off-by: NZeng Tao <prime.zeng@hisilicon.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Reviewed-by: NRoger Quadros <rogerq@ti.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bd0e6c96
  5. 28 9月, 2018 1 次提交
    • J
      usb: core: added uevent for over-current · 201af55d
      Jon Flatley 提交于
      After commit 1cbd53c8 ("usb: core: introduce per-port over-current
      counters") usb ports expose a sysfs value 'over_current_count'
      to user space. This value on its own is not very useful as it requires
      manual polling.
      
      As a solution, fire a udev event from the usb hub device that specifies
      the values 'OVER_CURRENT_PORT' and 'OVER_CURRENT_COUNT' that indicate
      the path of the usb port where the over-current event occurred and the
      value of 'over_current_count' in sysfs. Additionally, call
      sysfs_notify() so the sysfs value supports poll().
      Signed-off-by: NJon Flatley <jflat@chromium.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      201af55d
  6. 20 9月, 2018 7 次提交
    • H
      usb: core: safely deal with the dynamic quirk lists · 16c4cb19
      Harry Pan 提交于
      Applying dynamic usbcore quirks in early booting when the slab is
      not yet ready would cause kernel panic of null pointer dereference
      because the quirk_count has been counted as 1 while the quirk_list
      was failed to allocate.
      
      i.e.,
      [    1.044970] BUG: unable to handle kernel NULL pointer dereference at           (null)
      [    1.044995] IP: [<ffffffffb0953ec7>] usb_detect_quirks+0x88/0xd1
      [    1.045016] PGD 0
      [    1.045026] Oops: 0000 [#1] PREEMPT SMP
      [    1.046986] gsmi: Log Shutdown Reason 0x03
      [    1.046995] Modules linked in:
      [    1.047008] CPU: 0 PID: 81 Comm: kworker/0:3 Not tainted 4.4.154 #28
      [    1.047016] Hardware name: Google Coral/Coral, BIOS Google_Coral.10068.27.0 12/04/2017
      [    1.047028] Workqueue: usb_hub_wq hub_event
      [    1.047037] task: ffff88017a321c80 task.stack: ffff88017a384000
      [    1.047044] RIP: 0010:[<ffffffffb0953ec7>]  [<ffffffffb0953ec7>] usb_detect_quirks+0x88/0xd1
      
      To tackle this odd, let's balance the quirk_count to 0 when the kcalloc
      call fails, and defer the quirk setting into a lower level callback
      which ensures that the kernel memory management has been initialized.
      
      Fixes: 027bd6ca ("usb: core: Add "quirks" parameter for usbcore")
      Signed-off-by: NHarry Pan <harry.pan@intel.com>
      Acked-by: NKai-Heng Feng <kai.heng.feng@canonical.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      16c4cb19
    • S
      usbcore: Select UAC3 configuration for audio if present · f13912d3
      Saranya Gopal 提交于
      USB audio class 3.0 specification introduced many significant
      changes like
       - new power domains, support for LPM/L1
       - new cluster descriptor
       - new high capability and class-specific string descriptors
       - BADD profiles
       - ... and many other things (check spec from link below:
      http://www.usb.org/developers/docs/devclass_docs/USB_Audio_v3.0.zip)
      
      Now that UAC3 is supported in linux, choose UAC3
      configuration for audio if the device supports it.
      Selecting this configuration will enable the system to
      save power by leveraging the new power domains and LPM L1
      capability and also support new codec types and data formats
      for consumer audio applications.
      Signed-off-by: NSaranya Gopal <saranya.gopal@intel.com>
      Reviewed-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f13912d3
    • A
      USB: handle NULL config in usb_find_alt_setting() · c9a4cb20
      Alan Stern 提交于
      usb_find_alt_setting() takes a pointer to a struct usb_host_config as
      an argument; it searches for an interface with specified interface and
      alternate setting numbers in that config.  However, it crashes if the
      usb_host_config pointer argument is NULL.
      
      Since this is a general-purpose routine, available for use in many
      places, we want to to be more robust.  This patch makes it return NULL
      whenever the config argument is NULL.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: syzbot+19c3aaef85a89d451eac@syzkaller.appspotmail.com
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c9a4cb20
    • A
      USB: fix error handling in usb_driver_claim_interface() · bd729f9d
      Alan Stern 提交于
      The syzbot fuzzing project found a use-after-free bug in the USB
      core.  The bug was caused by usbfs not unbinding from an interface
      when the USB device file was closed, which led another process to
      attempt the unbind later on, after the private data structure had been
      deallocated.
      
      The reason usbfs did not unbind the interface at the appropriate time
      was because it thought the interface had never been claimed in the
      first place.  This was caused by the fact that
      usb_driver_claim_interface() does not clean up properly when
      device_bind_driver() returns an error.  Although the error code gets
      passed back to the caller, the iface->dev.driver pointer remains set
      and iface->condition remains equal to USB_INTERFACE_BOUND.
      
      This patch adds proper error handling to usb_driver_claim_interface().
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: syzbot+f84aa7209ccec829536f@syzkaller.appspotmail.com
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bd729f9d
    • A
      USB: remove LPM management from usb_driver_claim_interface() · c183813f
      Alan Stern 提交于
      usb_driver_claim_interface() disables and re-enables Link Power
      Management, but it shouldn't do either one, for the reasons listed
      below.  This patch removes the two LPM-related function calls from the
      routine.
      
      The reason for disabling LPM in the analogous function
      usb_probe_interface() is so that drivers won't have to deal with
      unwanted LPM transitions in their probe routine.  But
      usb_driver_claim_interface() doesn't call the driver's probe routine
      (or any other callbacks), so that reason doesn't apply here.
      
      Furthermore, no driver other than usbfs will ever call
      usb_driver_claim_interface() unless it is already bound to another
      interface in the same device, which means disabling LPM here would be
      redundant.  usbfs doesn't interact with LPM at all.
      
      Lastly, the error return from usb_unlocked_disable_lpm() isn't handled
      properly; the code doesn't clean up its earlier actions before
      returning.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Fixes: 8306095f ("USB: Disable USB 3.0 LPM in critical sections.")
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c183813f
    • O
      USB: usbdevfs: restore warning for nonsensical flags · 81e0403b
      Oliver Neukum 提交于
      If we filter flags before they reach the core we need to generate our
      own warnings.
      Signed-off-by: NOliver Neukum <oneukum@suse.com>
      Fixes: 0cb54a3e ("USB: debugging code shouldn't alter control flow")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      81e0403b
    • O
      USB: usbdevfs: sanitize flags more · 7a68d9fb
      Oliver Neukum 提交于
      Requesting a ZERO_PACKET or not is sensible only for output.
      In the input direction the device decides.
      Likewise accepting short packets makes sense only for input.
      
      This allows operation with panic_on_warn without opening up
      a local DOS.
      Signed-off-by: NOliver Neukum <oneukum@suse.com>
      Reported-by: syzbot+843efa30c8821bd69f53@syzkaller.appspotmail.com
      Fixes: 0cb54a3e ("USB: debugging code shouldn't alter control flow")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7a68d9fb
  7. 11 9月, 2018 5 次提交
  8. 05 9月, 2018 4 次提交
  9. 21 7月, 2018 1 次提交
  10. 06 7月, 2018 3 次提交
  11. 28 6月, 2018 2 次提交
  12. 25 6月, 2018 1 次提交
    • A
      USB: Report wakeup events on root-hub ports · 379cacc5
      Alan Stern 提交于
      When a USB device attached to a root-hub port sends a wakeup request
      to a sleeping system, we do not report the wakeup event to the PM
      core.  This is because a system resume involves waking up all
      suspended USB ports as quickly as possible; without the normal
      USB_RESUME_TIMEOUT delay, the host controller driver doesn't set the
      USB_PORT_STAT_C_SUSPEND flag and so usb_port_resume() doesn't realize
      that a wakeup request was received.
      
      However, some environments (such as Chrome OS) want to have all wakeup
      events reported so they can be ascribed to the appropriate device.  To
      accommodate these environments, this patch adds a new routine to the
      hub driver and a corresponding new HCD method to be used when a root
      hub resumes.  The HCD method returns a bitmap of ports that have
      initiated a wakeup signal but not yet completed resuming.  The hub
      driver can then report to the PM core that the child devices attached
      to these ports initiated a wakeup event.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Suggested-by: NAnshuman Gupta <anshuman.gupta@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      379cacc5
  13. 13 6月, 2018 2 次提交
    • K
      treewide: kzalloc() -> kcalloc() · 6396bb22
      Kees Cook 提交于
      The kzalloc() function has a 2-factor argument form, kcalloc(). This
      patch replaces cases of:
      
              kzalloc(a * b, gfp)
      
      with:
              kcalloc(a * b, gfp)
      
      as well as handling cases of:
      
              kzalloc(a * b * c, gfp)
      
      with:
      
              kzalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kzalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kzalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kzalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kzalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kzalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kzalloc
      + kcalloc
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kzalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(sizeof(THING) * C2, ...)
      |
        kzalloc(sizeof(TYPE) * C2, ...)
      |
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(C1 * C2, ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      6396bb22
    • K
      treewide: kmalloc() -> kmalloc_array() · 6da2ec56
      Kees Cook 提交于
      The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
      patch replaces cases of:
      
              kmalloc(a * b, gfp)
      
      with:
              kmalloc_array(a * b, gfp)
      
      as well as handling cases of:
      
              kmalloc(a * b * c, gfp)
      
      with:
      
              kmalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kmalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kmalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The tools/ directory was manually excluded, since it has its own
      implementation of kmalloc().
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kmalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kmalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kmalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kmalloc
      + kmalloc_array
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kmalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kmalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kmalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kmalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kmalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kmalloc(C1 * C2 * C3, ...)
      |
        kmalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kmalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kmalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kmalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kmalloc(sizeof(THING) * C2, ...)
      |
        kmalloc(sizeof(TYPE) * C2, ...)
      |
        kmalloc(C1 * C2 * C3, ...)
      |
        kmalloc(C1 * C2, ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      6da2ec56
  14. 31 5月, 2018 5 次提交
    • G
      USB: core: no need to check return value of debugfs_create functions · b708692d
      Greg Kroah-Hartman 提交于
      When calling debugfs functions, there is no need to ever check the
      return value.  The function can work or not, but the code logic should
      never do something different based on this.
      
      Cc: Johan Hovold <johan@kernel.org>
      Cc: Kai-Heng Feng <kai.heng.feng@canonical.com>
      Cc: Peter Chen <peter.chen@nxp.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b708692d
    • N
      usb: hub: Per-port setting to reduce TRSTRCY to 10 ms · aa071a92
      Nicolas Boichat 提交于
      Currently, the USB hub core waits for 50 ms after enumerating the
      device. This was added to help "some high speed devices" to
      enumerate (b789696a "[PATCH] USB: relax usbcore reset timings").
      
      On some devices, the time-to-active is important, so we provide
      a per-port option to reduce the time to what the USB specification
      requires: 10 ms.
      Signed-off-by: NNicolas Boichat <drinkcat@chromium.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aa071a92
    • N
      usb: hub: Per-port setting to use old enumeration scheme · 25244227
      Nicolas Boichat 提交于
      The "old" enumeration scheme is considerably faster (it takes
      ~244ms instead of ~356ms to get the descriptor).
      
      It is currently only possible to use the old scheme globally
      (/sys/module/usbcore/parameters/old_scheme_first), which is not
      desirable as the new scheme was introduced to increase compatibility
      with more devices.
      
      However, in our case, we care about time-to-active for a specific
      USB device (which we make the firmware for), on a specific port
      (that is pogo-pin based: not a standard USB port). This new
      sysfs option makes it possible to use the old scheme on a single
      port only.
      Signed-off-by: NNicolas Boichat <drinkcat@chromium.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      25244227
    • R
      usb: core: message: remove extra endianness conversion in usb_set_isoch_delay · 48b73d0f
      Ruslan Bilovol 提交于
      No need to do extra endianness conversion in
      usb_set_isoch_delay because it is already done
      in usb_control_msg()
      
      Fixes: 886ee36e ("usb: core: add support for USB_REQ_SET_ISOCH_DELAY")
      Cc: Dmytro Panchenko <dmytro.panchenko@globallogic.com>
      Cc: Felipe Balbi <felipe.balbi@linux.intel.com>
      Cc: stable <stable@vger.kernel.org> # v4.16+
      Signed-off-by: NRuslan Bilovol <ruslan.bilovol@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      48b73d0f
    • M
      driver core: hold dev's parent lock when needed · 8c97a46a
      Martin Liu 提交于
      SoC have internal I/O buses that can't be proved for devices. The
      devices on the buses can be accessed directly without additinal
      configuration required. This type of bus is represented as
      "simple-bus". In some platforms, we name "soc" with "simple-bus"
      attribute and many devices are hooked under it described in DT
      (device tree).
      
      In commit bf74ad5b ("Hold the device's parent's lock during
      probe and remove") to solve USB subsystem lock sequence since
      USB device's characteristic. Thus "soc" needs to be locked
      whenever a device and driver's probing happen under "soc" bus.
      During this period, an async driver tries to probe a device which
      is under the "soc" bus would be blocked until previous driver
      finish the probing and release "soc" lock. And the next probing
      under the "soc" bus need to wait for async finish. Because of
      that, driver's async probe for init time improvement will be
      shadowed.
      
      Since many devices don't have USB devices' characteristic, they
      actually don't need parent's lock. Thus, we introduce a lock flag
      in bus_type struct and driver core would lock the parent lock base
      on the flag. For USB, we set this flag in usb_bus_type to keep
      original lock behavior in driver core.
      
      Async probe could have more benefit after this patch.
      Signed-off-by: NMartin Liu <liumartin@google.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8c97a46a