1. 31 5月, 2016 1 次提交
  2. 20 4月, 2016 1 次提交
  3. 19 4月, 2016 1 次提交
    • L
      usb: gadget: f_fs: Fix EFAULT generation for async read operations · 332a5b44
      Lars-Peter Clausen 提交于
      In the current implementation functionfs generates a EFAULT for async read
      operations if the read buffer size is larger than the URB data size. Since
      a application does not necessarily know how much data the host side is
      going to send it typically supplies a buffer larger than the actual data,
      which will then result in a EFAULT error.
      
      This behaviour was introduced while refactoring the code to use iov_iter
      interface in commit c993c39b ("gadget/function/f_fs.c: use put iov_iter
      into io_data"). The original code took the minimum over the URB size and
      the user buffer size and then attempted to copy that many bytes using
      copy_to_user(). If copy_to_user() could not copy all data a EFAULT error
      was generated. Restore the original behaviour by only generating a EFAULT
      error when the number of bytes copied is not the size of the URB and the
      target buffer has not been fully filled.
      
      Commit 342f39a6 ("usb: gadget: f_fs: fix check in read operation")
      already fixed the same problem for the synchronous read path.
      
      Fixes: c993c39b ("gadget/function/f_fs.c: use put iov_iter into io_data")
      Acked-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      332a5b44
  4. 05 4月, 2016 1 次提交
    • K
      mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros · 09cbfeaf
      Kirill A. Shutemov 提交于
      PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
      ago with promise that one day it will be possible to implement page
      cache with bigger chunks than PAGE_SIZE.
      
      This promise never materialized.  And unlikely will.
      
      We have many places where PAGE_CACHE_SIZE assumed to be equal to
      PAGE_SIZE.  And it's constant source of confusion on whether
      PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
      especially on the border between fs and mm.
      
      Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
      breakage to be doable.
      
      Let's stop pretending that pages in page cache are special.  They are
      not.
      
      The changes are pretty straight-forward:
      
       - <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
      
       - <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
      
       - PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
      
       - page_cache_get() -> get_page();
      
       - page_cache_release() -> put_page();
      
      This patch contains automated changes generated with coccinelle using
      script below.  For some reason, coccinelle doesn't patch header files.
      I've called spatch for them manually.
      
      The only adjustment after coccinelle is revert of changes to
      PAGE_CAHCE_ALIGN definition: we are going to drop it later.
      
      There are few places in the code where coccinelle didn't reach.  I'll
      fix them manually in a separate patch.  Comments and documentation also
      will be addressed with the separate patch.
      
      virtual patch
      
      @@
      expression E;
      @@
      - E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
      + E
      
      @@
      expression E;
      @@
      - E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
      + E
      
      @@
      @@
      - PAGE_CACHE_SHIFT
      + PAGE_SHIFT
      
      @@
      @@
      - PAGE_CACHE_SIZE
      + PAGE_SIZE
      
      @@
      @@
      - PAGE_CACHE_MASK
      + PAGE_MASK
      
      @@
      expression E;
      @@
      - PAGE_CACHE_ALIGN(E)
      + PAGE_ALIGN(E)
      
      @@
      expression E;
      @@
      - page_cache_get(E)
      + get_page(E)
      
      @@
      expression E;
      @@
      - page_cache_release(E)
      + put_page(E)
      Signed-off-by: NKirill A. Shutemov <kirill.shutemov@linux.intel.com>
      Acked-by: NMichal Hocko <mhocko@suse.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      09cbfeaf
  5. 04 3月, 2016 5 次提交
    • D
      usb: f_fs: avoid race condition with ffs_epfile_io_complete · ef150884
      Du, Changbin 提交于
      ffs_epfile_io and ffs_epfile_io_complete runs in different context, but
      there is no synchronization between them.
      
      consider the following scenario:
      1) ffs_epfile_io interrupted by sigal while
      wait_for_completion_interruptible
      2) then ffs_epfile_io set ret to -EINTR
      3) just before or during usb_ep_dequeue, the request completed
      4) ffs_epfile_io return with -EINTR
      
      In this case, ffs_epfile_io tell caller no transfer success but actually
      it may has been done. This break the caller's pipe.
      
      Below script can help test it (adbd is the process which lies on f_fs).
      while true
      do
         pkill -19 adbd #SIGSTOP
         pkill -18 adbd #SIGCONT
         sleep 0.1
      done
      
      To avoid this, just dequeue the request first. After usb_ep_dequeue, the
      request must be done or canceled.
      
      With this change, we can ensure no race condition in f_fs driver. But
      actually I found some of the udc driver has analogical issue in its
      dequeue implementation. For example,
      1) the dequeue function hold the controller's lock.
      2) before driver request controller  to stop transfer, a request
         completed.
      3) the controller trigger a interrupt, but its irq handler need wait
         dequeue function to release the lock.
      4) dequeue function give back the request with negative status, and
         release lock.
      5) irq handler get lock but the request has already been given back.
      
      So, the dequeue implementation should take care of this case. IMO, it
      can be done as below steps to dequeue a already started request,
      1) request controller to stop transfer on the given ep. HW know the
         actual transfer status.
      2) after hw stop transfer, driver scan if there are any completed one.
      3) if found, process it with real status. if no, the request can
         canceled.
      Signed-off-by: N"Du, Changbin" <changbin.du@intel.com>
      [mina86@mina86.com: rebased on top of refactoring commits]
      Signed-off-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      ef150884
    • M
      usb: f_fs: refactor ffs_epfile_io · ae76e134
      Michal Nazarewicz 提交于
      Eliminate one of the return paths by using a ‘goto error_mutex’ and
      rearrange some if-bodies which results in reduction of the indention level
      and thus hopefully makes the function easier to read and reason about.
      Signed-off-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      ae76e134
    • M
      usb: f_fs: replace unnecessary goto with a return · b3591f67
      Michal Nazarewicz 提交于
      In ffs_epfile_io error label points to a return path which includes
      a kfree(data) call.  However, at the beginning of the function data is
      always NULL so some of the early ‘goto error’ can safely be replaced
      with a trivial return statement.
      Signed-off-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      b3591f67
    • M
      usb: f_fs: fix ffs_epfile_io returning success on req alloc failure · 3163c79e
      Michal Nazarewicz 提交于
      In the AIO path, if allocating of a request failse, the function simply
      goes to the error_lock path whose end result is returning value of ret.
      However, at this point ret’s value is zero (assigned as return value from
      ffs_mutex_lock).
      
      Fix by adding ‘ret = -ENOMEM’ statement.
      Signed-off-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      3163c79e
    • M
      usb: f_fs: fix memory leak when ep changes during transfer · 3de4e205
      Michal Nazarewicz 提交于
      In the ffs_epfile_io function, data buffer is allocated for non-halt
      requests.  Later, after grabing a mutex, the function checks that
      epfile->ep is still ep and if it’s not, it set ret to -ESHUTDOWN and
      follow a path including spin_unlock_irq (just after ‘ret = -ESHUTDOWN’),
      mutex_unlock (after if-else-if-else chain) and returns ret.  Noticeably,
      this does not include freeing of the data buffer.
      
      Fix by introducing a goto which moves control flow to the the end of the
      function where spin_unlock_irq, mutex_unlock and kfree are all called.
      Signed-off-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      3de4e205
  6. 19 11月, 2015 1 次提交
  7. 31 7月, 2015 1 次提交
  8. 07 7月, 2015 1 次提交
  9. 26 5月, 2015 3 次提交
    • R
      usb: gadget: f_fs: add extra check before unregister_gadget_item · f14e9ad1
      Rui Miguel Silva 提交于
      ffs_closed can race with configfs_rmdir which will call config_item_release, so
      add an extra check to avoid calling the unregister_gadget_item with an null
      gadget item.
      Signed-off-by: NRui Miguel Silva <rui.silva@linaro.org>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      f14e9ad1
    • R
      usb: gadget: f_fs: fix check in read operation · 342f39a6
      Rui Miguel Silva 提交于
      when copying to iter the size can be different then the iov count,
      the check for full iov is wrong and make any read on request which
      is not the exactly size of iov to return -EFAULT.
      
      So, just check the success of the copy.
      Signed-off-by: NRui Miguel Silva <rui.silva@linaro.org>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      342f39a6
    • K
      usb: gadget: ffs: fix: Always call ffs_closed() in ffs_data_clear() · 49a79d8b
      Krzysztof Opasiak 提交于
      Originally FFS_FL_CALL_CLOSED_CALLBACK flag has been used to
      indicate if we should call ffs_closed_callback().
      
      Commit 4b187fce ("usb: gadget: FunctionFS: add devices
      management code") changed its semantic to indicate if we should
      call ffs_closed() function which does a little bit more.
      
      This situation leads to:
      
      [  122.362269] ------------[ cut here ]------------
      [  122.362287] WARNING: CPU: 2 PID: 2384 at drivers/usb/gadget/function/f_fs.c:3417 ffs_ep0_write+0x730/0x810 [usb_f_fs]()
      [  122.362292] Modules linked in:
      [  122.362555] CPU: 2 PID: 2384 Comm: adbd Tainted: G        W       4.1.0-0.rc4.git0.1.1.fc22.i686 #1
      [  122.362561] Hardware name: To be filled by O.E.M. To be filled by O.E.M./Aptio CRB, BIOS 5.6.5 07/25/2014
      [  122.362567]  c0d1f947 415badfa 00000000 d1029e64 c0a86e54 00000000 d1029e94 c045b937
      [  122.362584]  c0c37f94 00000002 00000950 f9b313d4 00000d59 f9b2ebf0 f9b2ebf0 fffffff0
      [  122.362600]  00000003 deb53d00 d1029ea4 c045ba42 00000009 00000000 d1029f08 f9b2ebf0
      [  122.362617] Call Trace:
      [  122.362633]  [<c0a86e54>] dump_stack+0x41/0x52
      [  122.362645]  [<c045b937>] warn_slowpath_common+0x87/0xc0
      [  122.362658]  [<f9b2ebf0>] ? ffs_ep0_write+0x730/0x810 [usb_f_fs]
      [  122.362668]  [<f9b2ebf0>] ? ffs_ep0_write+0x730/0x810 [usb_f_fs]
      [  122.362678]  [<c045ba42>] warn_slowpath_null+0x22/0x30
      [  122.362689]  [<f9b2ebf0>] ffs_ep0_write+0x730/0x810 [usb_f_fs]
      [  122.362702]  [<f9b2e4c0>] ? ffs_ep0_read+0x380/0x380 [usb_f_fs]
      [  122.362712]  [<c05a1c1f>] __vfs_write+0x2f/0x100
      [  122.362722]  [<c05a42f2>] ? __sb_start_write+0x52/0x110
      [  122.362731]  [<c05a2534>] vfs_write+0x94/0x1b0
      [  122.362740]  [<c0a8a1c0>] ? mutex_lock+0x10/0x30
      [  122.362749]  [<c05a2f41>] SyS_write+0x51/0xb0
      [  122.362759]  [<c0a8c71f>] sysenter_do_call+0x12/0x12
      [  122.362766] ---[ end trace 0673d3467cecf8db ]---
      
      in some cases (reproduction path below). This commit get back
      semantic of that flag and ensures that ffs_closed() is called
      always when needed but ffs_closed_callback() is called only
      if this flag is set.
      
      Reproduction path:
      Compile kernel without any UDC driver or bound some gadget
      to existing one and then:
      
      $ modprobe g_ffs
      $ mount none -t functionfs mount_point
      $ ffs-example mount_point
      
      This will fail with -ENODEV as there is no udc.
      
      $ ffs-example mount_point
      
      This will fail with -EBUSY because ffs_data has not been
      properly cleaned up.
      Signed-off-by: NKrzysztof Opasiak <k.opasiak@samsung.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      49a79d8b
  10. 12 4月, 2015 1 次提交
  11. 26 3月, 2015 1 次提交
  12. 14 3月, 2015 1 次提交
    • C
      fs: split generic and aio kiocb · 04b2fa9f
      Christoph Hellwig 提交于
      Most callers in the kernel want to perform synchronous file I/O, but
      still have to bloat the stack with a full struct kiocb.  Split out
      the parts needed in filesystem code from those in the aio code, and
      only allocate those needed to pass down argument on the stack.  The
      aio code embedds the generic iocb in the one it allocates and can
      easily get back to it by using container_of.
      
      Also add a ->ki_complete method to struct kiocb, this is used to call
      into the aio code and thus removes the dependency on aio for filesystems
      impementing asynchronous operations.  It will also allow other callers
      to substitute their own completion callback.
      
      We also add a new ->ki_flags field to work around the nasty layering
      violation recently introduced in commit 5e33f6 ("usb: gadget: ffs: add
      eventfd notification about ffs events").
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      04b2fa9f
  13. 18 2月, 2015 3 次提交
  14. 27 1月, 2015 2 次提交
  15. 15 1月, 2015 1 次提交
    • R
      usb: gadget: f_fs: add "no_disconnect" mode · 18d6b32f
      Robert Baldyga 提交于
      Since we can compose gadgets from many functions, there is the problem
      related to gadget breakage while FunctionFS daemon being closed. FFS
      function is userspace code so there is no way to know when it will close
      files (it doesn't matter what is the reason of this situation, it can
      be daemon logic, program breakage, process kill or any other). So when
      we have another function in gadget which, for example, sends some amount
      of data, does some software update or implements some real-time functionality,
      we may want to keep the gadget connected despite FFS function is no longer
      functional.
      
      We can't just remove one of functions from gadget since it has been
      enumerated, so the only way to keep entire gadget working is to make
      broken FFS function deactivated but still visible to host. For this
      purpose this patch introduces "no_disconnect" mode. It can be enabled
      by setting mount option "no_disconnect=1", and results with defering
      function disconnect to the moment of reopen ep0 file or filesystem
      unmount. After closing all endpoint files, FunctionFS is set to state
      FFS_DEACTIVATED.
      
      When ffs->state == FFS_DEACTIVATED:
      - function is still bound and visible to host,
      - setup requests are automatically stalled,
      - transfers on other endpoints are refused,
      - epfiles, except ep0, are deleted from the filesystem,
      - opening ep0 causes the function to be closed, and then FunctionFS
        is ready for descriptors and string write,
      - altsetting change causes the function to be closed - we want to keep
        function alive until another functions are potentialy used, altsetting
        change means that another configuration is being selected or USB cable
        was unplugged, which indicates that we don't need to stay longer in
        FFS_DEACTIVATED state
      - unmounting of the FunctionFS instance causes the function to be closed.
      Tested-by: NDavid Cohen <david.a.cohen@linux.intel.com>
      Acked-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NRobert Baldyga <r.baldyga@samsung.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      18d6b32f
  16. 13 1月, 2015 1 次提交
  17. 23 10月, 2014 2 次提交
  18. 09 10月, 2014 1 次提交
  19. 16 9月, 2014 1 次提交
    • R
      usb: gadget: f_fs: virtual endpoint address mapping · 1b0bf88f
      Robert Baldyga 提交于
      This patch introduces virtual endpoint address mapping. It separates
      function logic form physical endpoint addresses making it more hardware
      independent.
      
      Following modifications changes user space API, so to enable them user
      have to switch on the FUNCTIONFS_VIRTUAL_ADDR flag in descriptors.
      
      Endpoints are now refered using virtual endpoint addresses chosen by
      user in endpoint descpriptors. This applies to each context when endpoint
      address can be used:
      - when accessing endpoint files in FunctionFS filesystemi (in file name),
      - in setup requests directed to specific endpoint (in wIndex field),
      - in descriptors returned by FUNCTIONFS_ENDPOINT_DESC ioctl.
      
      In endpoint file names the endpoint address number is formatted as
      double-digit hexadecimal value ("ep%02x") which has few advantages -
      it is easy to parse, allows to easly recognize endpoint direction basing
      on its name (IN endpoint number starts with digit 8, and OUT with 0)
      which can be useful for debugging purpose, and it makes easier to introduce
      further features allowing to use each endpoint number in both directions
      to have more endpoints available for function if hardware supports this
      (for example we could have ep01 which is endpoint 1 with OUT direction,
      and ep81 which is endpoint 1 with IN direction).
      
      Physical endpoint address can be still obtained using ioctl named
      FUNCTIONFS_ENDPOINT_REVMAP, but now it's not neccesary to handle
      USB transactions properly.
      Signed-off-by: NRobert Baldyga <r.baldyga@samsung.com>
      Acked-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      1b0bf88f
  20. 12 9月, 2014 1 次提交
  21. 09 9月, 2014 2 次提交
  22. 03 9月, 2014 1 次提交
  23. 17 7月, 2014 1 次提交
  24. 10 7月, 2014 2 次提交
  25. 01 7月, 2014 1 次提交
  26. 19 6月, 2014 1 次提交
    • M
      usb: gadget: f_fs: fix NULL pointer dereference when there are no strings · f0688c8b
      Michal Nazarewicz 提交于
      If the descriptors do not need any strings and user space sends empty
      set of strings, the ffs->stringtabs field remains NULL.  Thus
      *ffs->stringtabs in functionfs_bind leads to a NULL pointer
      dereferenece.
      
      The bug was introduced by commit [fd7c9a00: “use usb_string_ids_n()”].
      
      While at it, remove double initialisation of lang local variable in
      that function.
      
      ffs->strings_count does not need to be checked in any way since in
      the above scenario it will remain zero and usb_string_ids_n() is
      a no-operation when colled with 0 argument.
      
      Cc: <stable@vger.kernel.org>  # v2.6.36+
      Signed-off-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      f0688c8b
  27. 14 5月, 2014 1 次提交
  28. 22 4月, 2014 1 次提交