1. 04 3月, 2016 1 次提交
    • 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
  2. 19 11月, 2015 1 次提交
  3. 31 7月, 2015 1 次提交
  4. 07 7月, 2015 1 次提交
  5. 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
  6. 12 4月, 2015 1 次提交
  7. 26 3月, 2015 1 次提交
  8. 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
  9. 18 2月, 2015 3 次提交
  10. 27 1月, 2015 2 次提交
  11. 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
  12. 13 1月, 2015 1 次提交
  13. 23 10月, 2014 2 次提交
  14. 09 10月, 2014 1 次提交
  15. 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
  16. 12 9月, 2014 1 次提交
  17. 09 9月, 2014 2 次提交
  18. 03 9月, 2014 1 次提交
  19. 17 7月, 2014 1 次提交
  20. 10 7月, 2014 2 次提交
  21. 01 7月, 2014 1 次提交
  22. 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
  23. 14 5月, 2014 1 次提交
  24. 22 4月, 2014 1 次提交
  25. 16 4月, 2014 1 次提交
    • C
      usb: gadget: ffs: race between ffs_epfile_io() and ffs_func_eps_disable() · 97839ca4
      Chao Bi 提交于
      ffs_epfile_io() is called from userspace, while ffs_func_eps_disable() might be
      called from USB disconnect interrupt, the two functions would run in parallel
      but they are not well protected, that epfile->ep would be removed by
      ffs_func_eps_disable() during ffs_epfile_io() is referring this pointer, then
      it leads to kernel PANIC.
      
      The scenario is as below:
      
      Thread 1                                 Thread 2
         |                                        |
      SyS_read                             dwc3_gadget_disconnect_interrupt
         |                                        |
      ffs_epfile_read                         reset_config
         |                                        |
      ffs_epfile_io                       ffs_func_eps_disable
         |                                        |
       -----                      usb_ep_disable():  epfile->ep->ep->desc = NULL
         |                                        |
      usb_ep_align_maybe():                     -----
      it refers ep->desc->wMaxPacketSize        -----
      Signed-off-by: NChao Bi <chao.bi@intel.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      97839ca4
  26. 18 3月, 2014 1 次提交
  27. 08 3月, 2014 1 次提交
  28. 06 3月, 2014 2 次提交
  29. 20 2月, 2014 1 次提交
    • A
      usb: gadget: fix NULL pointer dereference · f0f42204
      Andrzej Pietrasiewicz 提交于
      Fix possible NULL pointer dereference introduced in
      commit 219580e6 (usb: f_fs: check quirk to pad epout
      buf size when not aligned to maxpacketsize)
      
      In cases we do wait with:
      
      wait_event_interruptible(epfile->wait, (ep = epfile->ep));
      
      for endpoint to be enabled, functionfs_bind() has not been called yet
      and epfile->ffs->gadget is still NULL and the automatic variable 'gadget'
      has been initialized with NULL at the point of its definition.
      Later on it is used as a parameter to:
      
      usb_ep_align_maybe(gadget, ep->ep, len)
      
      which in turn dereferences it.
      
      This patch fixes it by moving the actual assignment to the local 'gadget'
      variable after the potential waiting has completed.
      Signed-off-by: NAndrzej Pietrasiewicz <andrzej.p@samsung.com>
      Acked-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      f0f42204
  30. 19 2月, 2014 2 次提交
    • R
      usb: gadget: f_fs: add aio support · 2e4c7553
      Robert Baldyga 提交于
      This patch adds asynchronous I/O support for FunctionFS endpoint files.
      It adds ffs_epfile_aio_write() and ffs_epfile_aio_read() functions responsible
      for preparing AIO operations.
      
      It also modifies ffs_epfile_io() function, adding aio handling code. Instead
      of extending list of parameters of this function, there is new struct
      ffs_io_data which contains all information needed to perform I/O operation.
      Pointer to this struct replaces "buf" and "len" parameters of ffs_epfile_io()
      function. Allocated buffer is freed immediately only after sync operation,
      because in async IO it's freed in complete funcion. For each async operation
      an USB request is allocated, because it allows to have more than one request
      queued on single endpoint.
      
      According to changes in ffs_epfile_io() function, functions ffs_epfile_write()
      and ffs_epfile_read() are updated to use new API.
      
      For asynchronous I/O operations there is new request complete function named
      ffs_epfile_async_io_complete(), which completes AIO operation, and frees
      used memory.
      Signed-off-by: NRobert Baldyga <r.baldyga@samsung.com>
      Acked-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      2e4c7553
    • R
      usb: gadget: f_fs: add poll for endpoint 0 · 23de91e9
      Robert Baldyga 提交于
      This patch adds poll function for file representing ep0.
      
      Ability of read from or write to ep0 file is related with actual state of ffs:
      - When desctiptors or strings are not written yet, POLLOUT flag is set.
      - If there is any event to read, POLLIN flag is set.
      - If setup request was read, POLLIN and POLLOUT flag is set, to allow
        send response (by performing I/O operation consistent with setup request
        direction) or set stall (by performing I/O operation opposite  setup
        request direction).
      Signed-off-by: NRobert Baldyga <r.baldyga@samsung.com>
      Acked-by: NMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      23de91e9