1. 17 7月, 2014 1 次提交
  2. 20 2月, 2014 1 次提交
  3. 19 2月, 2014 3 次提交
    • W
      usb: gadget: printer: fix memory leak · 7e98f600
      wenlin.kang 提交于
      When read data from g_printer, we see a Segmentation fault. eg:
      
      Unable to handle kernel paging request at virtual address bf048000 pgd
      = cf038000 [bf048000] *pgd=8e8cf811, *pte=00000000, *ppte=00000000
      Internal error: Oops: 7 [#1] PREEMPT ARM Modules linked in: bluetooth
      rfcomm g_printer
      CPU: 0    Not tainted  (3.4.43-WR5.0.1.9_standard #1)
      PC is at __copy_to_user_std+0x310/0x3a8 LR is at 0x4c808010
      pc : [<c036e990>]    lr : [<4c808010>]    psr: 20000013
      sp : cf883ea8  ip : 80801018  fp : cf883f24
      r10: bf04706c  r9 : 18a21205  r8 : 21953888
      r7 : 201588aa  r6 : 5109aa16  r5 : 0705aaa2  r4 : 5140aa8a
      r3 : 0000004c  r2 : 00000fdc  r1 : bf048000  r0 : bef5fc3c
      Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
      Control: 10c5387d  Table: 8f038019  DAC: 00000015 Process
      g_printer_test. (pid: 661, stack limit = 0xcf8822e8)
      Stack: (0xcf883ea8 to 0xcf884000)
      3ea0:                   bf047068 00001fff bef5ecb9 cf882000 00001fff bef5ecb9
      3ec0: 00001fff 00000000 cf2e8724 bf044d3c 80000013 80000013 00000001
      bf04706c
      3ee0: cf883f24 cf883ef0 c012e5ac c0324388 c007c8ac c0046298 00008180
      cf29b900
      3f00: 00002000 bef5ecb8 cf883f68 00000003 cf882000 cf29b900 cf883f54
      cf883f28
      3f20: c012ea08 bf044b0c c000eb88 00000000 cf883f7c 00000000 00000000
      00002000
      3f40: bef5ecb8 00000003 cf883fa4 cf883f58 c012eae8 c012e960 00000001
      bef60cb8
      3f60: 000000a8 c000eb88 00000000 00000000 cf883fa4 00000000 c014329c
      00000000
      3f80: 000000d4 41af63f0 00000003 c000eb88 cf882000 00000000 00000000
      cf883fa8
      3fa0: c000e920 c012eaa4 00000000 000000d4 00000003 bef5ecb8 00002000
      bef5ecb8
      3fc0: 00000000 000000d4 41af63f0 00000003 b6f534c0 00000000 419f9000
      00000000
      3fe0: 00000000 bef5ecac 000086d9 41a986bc 60000010 00000003 0109608a
      0088828a
      Code: f5d1f07c e8b100f0 e1a03c2e e2522020 (e8b15300) ---[ end trace
      97e2618e250e3377 ]--- Segmentation fault
      
      The root cause is the dev->rx_buffers list has been broken.
      When we call printer_read(), the following call tree is triggered:
      
      printer_read()
      	|
      	+---setup_rx_reqs(req)
      	|	|
      	|	+---usb_ep_queue(req)
      	|	|	|
      	|	|	+---...
      	|	|		|
      	|	|		+---rx_complete(req).
      	|	|
      	|	+---add the req to dev->rx_reqs_active
      	|
      	+---while(!list_empty(&dev->rx_buffers)))
      
      The route happens when we don't use DMA or fail to start DMA in USB
      driver. We can see: in the case, in rx_complete() it will add the req
      to dev->rx_buffers. meanwhile we see that we will also add the req to
      dev->rx_reqs_active after usb_ep_queue() return, so this adding will
      break the dev->rx_buffers out.
      
      After, when we call list_empty() to check dev->rx_buffers in while(),
      due to can't check correctly dev->rx_buffers, so the Segmentation fault
      occurs when copy_to_user() is called.
      Signed-off-by: Nwenlin.kang <wenlin.kang@windriver.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      7e98f600
    • W
      usb: gadget: printer: fix possible deadlock · 2c2b0425
      wenlin.kang 提交于
      The problem occurs in follow path.
      
      printer_read()
      	|
      	+---setup_rx_reqs()
      		|
      		+---usb_ep_queue()
      			|
      			+---...
      				|
      				+---rx_complete()
      
      Although it is clear from code, we can't get it normally.
      only when we enable some spin_lock debug config option, we can find it.
      eg:
      BUG: spinlock lockup on CPU#0, g_printer_test_/584
       lock: bf05e158, .magic: dead4ead, .owner: g_printer_test_/584, .owner_cpu: 0
      [<c0016e1c>] (unwind_backtrace+0x0/0x104) from [<c067aef8>] (dump_stack+0x20/0x24)
      [<c067aef8>] (dump_stack+0x20/0x24) from [<c0680bec>] (spin_dump+0x8c/0x94)
      [<c0680bec>] (spin_dump+0x8c/0x94) from [<c039071c>] (do_raw_spin_lock+0x128/0x154)
      [<c039071c>] (do_raw_spin_lock+0x128/0x154) from [<c0685618>] (_raw_spin_lock_irqsave+0x64/0x70)
      [<c0685618>] (_raw_spin_lock_irqsave+0x64/0x70) from [<bf05b4e8>] (rx_complete+0x54/0x10c [g_printer])
      [<bf05b4e8>] (rx_complete+0x54/0x10c [g_printer]) from [<c0480478>] (musb_g_giveback+0x78/0x88)
      [<c0480478>] (musb_g_giveback+0x78/0x88) from [<c048060c>] (rxstate+0xa0/0x10c)
      [<c048060c>] (rxstate+0xa0/0x10c) from [<c0480d50>] (musb_ep_restart+0x44/0x70)
      [<c0480d50>] (musb_ep_restart+0x44/0x70) from [<c0480fe4>] (musb_gadget_queue+0xe8/0xf8)
      [<c0480fe4>] (musb_gadget_queue+0xe8/0xf8) from [<bf05b2b0>] (setup_rx_reqs+0xa4/0x178 [g_printer])
      [<bf05b2b0>] (setup_rx_reqs+0xa4/0x178 [g_printer]) from [<bf05bb58>] (printer_read+0x9c/0x3f4 [g_printer])
      [<bf05bb58>] (printer_read+0x9c/0x3f4 [g_printer]) from [<c01387f0>] (vfs_read+0xb4/0x144)
      [<c01387f0>] (vfs_read+0xb4/0x144) from [<c01388d0>] (sys_read+0x50/0x124)
      [<c01388d0>] (sys_read+0x50/0x124) from [<c000e900>] (ret_fast_syscall+0x0/0x3c)
      
      The root cause is that we use the same lock two time in a path, so to avoid
      the deadlock, we need to unlock in setup_rx_reqs(), and only unlock.
      Signed-off-by: Nwenlin.kang <wenlin.kang@windriver.com>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      2c2b0425
    • J
      usb: gadget: fix error return code · abcdcc29
      Julia Lawall 提交于
      Set the return variable to an error code as done elsewhere in the function.
      
      A simplified version of the semantic match that finds this problem is as
      follows: (http://coccinelle.lip6.fr/)
      
      // <smpl>
      (
      if@p1 (\(ret < 0\|ret != 0\))
       { ... return ret; }
      |
      ret@p1 = 0
      )
      ... when != ret = e1
          when != &ret
      *if(...)
      {
        ... when != ret = e2
            when forall
       return ret;
      }
      
      // </smpl>
      Signed-off-by: NJulia Lawall <Julia.Lawall@lip6.fr>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      abcdcc29
  4. 23 2月, 2013 1 次提交
  5. 31 10月, 2012 1 次提交
    • S
      usb: gadget: always update HS/SS descriptors and create a copy of them · 10287bae
      Sebastian Andrzej Siewior 提交于
      HS and SS descriptors are staticaly created. They are updated during the
      bind process with the endpoint address, string id or interface numbers.
      
      After that, the descriptor chain is linked to struct usb_function which
      is used by composite in order to serve the GET_DESCRIPTOR requests,
      number of available configs and so on.
      
      There is no need to assign the HS descriptor only if the UDC supports
      HS speed because composite won't report those to the host if HS support
      has not been reached. The same reasoning is valid for SS.
      
      This patch makes sure each function updates HS/SS descriptors
      unconditionally and uses the newly introduced helper function to create a
      copy the descriptors for the speed which is supported by the UDC.
      
      While at that, also rename f->descriptors to f->fs_descriptors in order
      to make it more explicit what that means.
      
      Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
      Signed-off-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: NFelipe Balbi <balbi@ti.com>
      10287bae
  6. 10 9月, 2012 12 次提交
  7. 04 5月, 2012 2 次提交
  8. 29 3月, 2012 1 次提交
  9. 12 12月, 2011 2 次提交
  10. 18 9月, 2011 2 次提交
  11. 10 9月, 2011 1 次提交
    • K
      usb gadget: clean up FSF boilerplate text · 28c9fc68
      Klaus Schwarzkopf 提交于
      remove the following two paragraphs as they are not needed:
      
      This program is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
      License for more details.
      
      You should have received a copy of the GNU General Public License along with
      this program; if not, write to the Free Software Foundation, Inc.,59
      Temple Place - Suite 330, Boston, MA  02111-1307, USA.
      Signed-off-by: NKlaus Schwarzkopf <schwarzkopf@sensortherm.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      28c9fc68
  12. 21 7月, 2011 1 次提交
    • J
      fs: push i_mutex and filemap_write_and_wait down into ->fsync() handlers · 02c24a82
      Josef Bacik 提交于
      Btrfs needs to be able to control how filemap_write_and_wait_range() is called
      in fsync to make it less of a painful operation, so push down taking i_mutex and
      the calling of filemap_write_and_wait() down into the ->fsync() handlers.  Some
      file systems can drop taking the i_mutex altogether it seems, like ext3 and
      ocfs2.  For correctness sake I just pushed everything down in all cases to make
      sure that we keep the current behavior the same for everybody, and then each
      individual fs maintainer can make up their mind about what to do from there.
      Thanks,
      Acked-by: NJan Kara <jack@suse.cz>
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      02c24a82
  13. 02 7月, 2011 1 次提交
  14. 29 6月, 2011 1 次提交
  15. 30 4月, 2011 1 次提交
  16. 31 3月, 2011 1 次提交
  17. 23 1月, 2011 2 次提交
    • A
      USB: g_printer: fix bug in module parameter definitions · ad84e4a9
      Alan Stern 提交于
      This patch (as1442) fixes a bug in g_printer: Module parameters should
      not be marked "__initdata" if they are accessible in sysfs (i.e., if
      the mode value in the module_param() macro is nonzero).  Otherwise
      attempts to access the parameters will cause addressing violations.
      
      Character-string module parameters must not be marked "__initdata"
      if the module can be unloaded, because the kernel needs to access the
      parameter variable at unload time in order to free the
      dynamically-allocated string.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      CC: Roland Kletzing <devzero@web.de>
      CC: Craig W. Nadler <craig@nadler.us>
      CC: <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      ad84e4a9
    • A
      USB: g_printer: fix bug in unregistration · d5aa4751
      Alan Stern 提交于
      This patch (as1441) fixes a bug in g_printer.  The gadget driver, char
      device number, and class device should be unregistered in reverse
      order of registration.  As it is now, when the module is unloaded the
      class device gets unregistered first, causing a crash when the unbind
      method tries to access it.
      
      This fixes Bugzilla #25882.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      CC: Roland Kletzing <devzero@web.de>
      CC: Craig W. Nadler <craig@nadler.us>
      CC: <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      d5aa4751
  18. 23 10月, 2010 2 次提交
  19. 15 10月, 2010 1 次提交
    • A
      llseek: automatically add .llseek fop · 6038f373
      Arnd Bergmann 提交于
      All file_operations should get a .llseek operation so we can make
      nonseekable_open the default for future file operations without a
      .llseek pointer.
      
      The three cases that we can automatically detect are no_llseek, seq_lseek
      and default_llseek. For cases where we can we can automatically prove that
      the file offset is always ignored, we use noop_llseek, which maintains
      the current behavior of not returning an error from a seek.
      
      New drivers should normally not use noop_llseek but instead use no_llseek
      and call nonseekable_open at open time.  Existing drivers can be converted
      to do the same when the maintainer knows for certain that no user code
      relies on calling seek on the device file.
      
      The generated code is often incorrectly indented and right now contains
      comments that clarify for each added line why a specific variant was
      chosen. In the version that gets submitted upstream, the comments will
      be gone and I will manually fix the indentation, because there does not
      seem to be a way to do that using coccinelle.
      
      Some amount of new code is currently sitting in linux-next that should get
      the same modifications, which I will do at the end of the merge window.
      
      Many thanks to Julia Lawall for helping me learn to write a semantic
      patch that does all this.
      
      ===== begin semantic patch =====
      // This adds an llseek= method to all file operations,
      // as a preparation for making no_llseek the default.
      //
      // The rules are
      // - use no_llseek explicitly if we do nonseekable_open
      // - use seq_lseek for sequential files
      // - use default_llseek if we know we access f_pos
      // - use noop_llseek if we know we don't access f_pos,
      //   but we still want to allow users to call lseek
      //
      @ open1 exists @
      identifier nested_open;
      @@
      nested_open(...)
      {
      <+...
      nonseekable_open(...)
      ...+>
      }
      
      @ open exists@
      identifier open_f;
      identifier i, f;
      identifier open1.nested_open;
      @@
      int open_f(struct inode *i, struct file *f)
      {
      <+...
      (
      nonseekable_open(...)
      |
      nested_open(...)
      )
      ...+>
      }
      
      @ read disable optional_qualifier exists @
      identifier read_f;
      identifier f, p, s, off;
      type ssize_t, size_t, loff_t;
      expression E;
      identifier func;
      @@
      ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
      {
      <+...
      (
         *off = E
      |
         *off += E
      |
         func(..., off, ...)
      |
         E = *off
      )
      ...+>
      }
      
      @ read_no_fpos disable optional_qualifier exists @
      identifier read_f;
      identifier f, p, s, off;
      type ssize_t, size_t, loff_t;
      @@
      ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
      {
      ... when != off
      }
      
      @ write @
      identifier write_f;
      identifier f, p, s, off;
      type ssize_t, size_t, loff_t;
      expression E;
      identifier func;
      @@
      ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
      {
      <+...
      (
        *off = E
      |
        *off += E
      |
        func(..., off, ...)
      |
        E = *off
      )
      ...+>
      }
      
      @ write_no_fpos @
      identifier write_f;
      identifier f, p, s, off;
      type ssize_t, size_t, loff_t;
      @@
      ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
      {
      ... when != off
      }
      
      @ fops0 @
      identifier fops;
      @@
      struct file_operations fops = {
       ...
      };
      
      @ has_llseek depends on fops0 @
      identifier fops0.fops;
      identifier llseek_f;
      @@
      struct file_operations fops = {
      ...
       .llseek = llseek_f,
      ...
      };
      
      @ has_read depends on fops0 @
      identifier fops0.fops;
      identifier read_f;
      @@
      struct file_operations fops = {
      ...
       .read = read_f,
      ...
      };
      
      @ has_write depends on fops0 @
      identifier fops0.fops;
      identifier write_f;
      @@
      struct file_operations fops = {
      ...
       .write = write_f,
      ...
      };
      
      @ has_open depends on fops0 @
      identifier fops0.fops;
      identifier open_f;
      @@
      struct file_operations fops = {
      ...
       .open = open_f,
      ...
      };
      
      // use no_llseek if we call nonseekable_open
      ////////////////////////////////////////////
      @ nonseekable1 depends on !has_llseek && has_open @
      identifier fops0.fops;
      identifier nso ~= "nonseekable_open";
      @@
      struct file_operations fops = {
      ...  .open = nso, ...
      +.llseek = no_llseek, /* nonseekable */
      };
      
      @ nonseekable2 depends on !has_llseek @
      identifier fops0.fops;
      identifier open.open_f;
      @@
      struct file_operations fops = {
      ...  .open = open_f, ...
      +.llseek = no_llseek, /* open uses nonseekable */
      };
      
      // use seq_lseek for sequential files
      /////////////////////////////////////
      @ seq depends on !has_llseek @
      identifier fops0.fops;
      identifier sr ~= "seq_read";
      @@
      struct file_operations fops = {
      ...  .read = sr, ...
      +.llseek = seq_lseek, /* we have seq_read */
      };
      
      // use default_llseek if there is a readdir
      ///////////////////////////////////////////
      @ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
      identifier fops0.fops;
      identifier readdir_e;
      @@
      // any other fop is used that changes pos
      struct file_operations fops = {
      ... .readdir = readdir_e, ...
      +.llseek = default_llseek, /* readdir is present */
      };
      
      // use default_llseek if at least one of read/write touches f_pos
      /////////////////////////////////////////////////////////////////
      @ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
      identifier fops0.fops;
      identifier read.read_f;
      @@
      // read fops use offset
      struct file_operations fops = {
      ... .read = read_f, ...
      +.llseek = default_llseek, /* read accesses f_pos */
      };
      
      @ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
      identifier fops0.fops;
      identifier write.write_f;
      @@
      // write fops use offset
      struct file_operations fops = {
      ... .write = write_f, ...
      +	.llseek = default_llseek, /* write accesses f_pos */
      };
      
      // Use noop_llseek if neither read nor write accesses f_pos
      ///////////////////////////////////////////////////////////
      
      @ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
      identifier fops0.fops;
      identifier read_no_fpos.read_f;
      identifier write_no_fpos.write_f;
      @@
      // write fops use offset
      struct file_operations fops = {
      ...
       .write = write_f,
       .read = read_f,
      ...
      +.llseek = noop_llseek, /* read and write both use no f_pos */
      };
      
      @ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
      identifier fops0.fops;
      identifier write_no_fpos.write_f;
      @@
      struct file_operations fops = {
      ... .write = write_f, ...
      +.llseek = noop_llseek, /* write uses no f_pos */
      };
      
      @ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
      identifier fops0.fops;
      identifier read_no_fpos.read_f;
      @@
      struct file_operations fops = {
      ... .read = read_f, ...
      +.llseek = noop_llseek, /* read uses no f_pos */
      };
      
      @ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
      identifier fops0.fops;
      @@
      struct file_operations fops = {
      ...
      +.llseek = noop_llseek, /* no read or write fn */
      };
      ===== End semantic patch =====
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Cc: Julia Lawall <julia@diku.dk>
      Cc: Christoph Hellwig <hch@infradead.org>
      6038f373
  20. 11 8月, 2010 2 次提交
    • A
      USB: autoconvert trivial BKL users to private mutex · 925ce689
      Arnd Bergmann 提交于
      All these files use the big kernel lock in a trivial
      way to serialize their private file operations,
      typically resulting from an earlier semi-automatic
      pushdown from VFS.
      
      None of these drivers appears to want to lock against
      other code, and they all use the BKL as the top-level
      lock in their file operations, meaning that there
      is no lock-order inversion problem.
      
      Consequently, we can remove the BKL completely,
      replacing it with a per-file mutex in every case.
      Using a scripted approach means we can avoid
      typos.
      
      file=$1
      name=$2
      if grep -q lock_kernel ${file} ; then
          if grep -q 'include.*linux.mutex.h' ${file} ; then
                  sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
          else
                  sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
          fi
          sed -i ${file} \
              -e "/^#include.*linux.mutex.h/,$ {
                      1,/^\(static\|int\|long\)/ {
                           /^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);
      
      } }"  \
          -e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
          -e '/[      ]*cycle_kernel_lock();/d'
      else
          sed -i -e '/include.*\<smp_lock.h\>/d' ${file}  \
                      -e '/cycle_kernel_lock()/d'
      fi
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      925ce689
    • M
      USB: gadget: section mismatch warning fixed · 89ba85d4
      Michal Nazarewicz 提交于
      In may gadgets bind and bind like functions were in a init section
      as they were only run during initialisation.  However, being
      callback functions they were referenced from structures in “normal”
      sections.  Changing the tag from “__init” to “__ref” fixes the
      warnings.
      Signed-off-by: NMichal Nazarewicz <m.nazarewicz@samsung.com>
      Cc: Kyungmin Park <kyungmin.park@samsung.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      89ba85d4
  21. 30 6月, 2010 1 次提交