1. 04 1月, 2012 1 次提交
  2. 02 7月, 2011 1 次提交
  3. 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
  4. 11 8月, 2010 1 次提交
  5. 19 7月, 2010 1 次提交
  6. 21 5月, 2010 1 次提交
  7. 03 3月, 2010 4 次提交
  8. 20 9月, 2009 1 次提交
  9. 16 6月, 2009 1 次提交
  10. 25 3月, 2009 1 次提交
    • P
      usblp: continuously poll for status · dd44be6b
      Pete Zaitcev 提交于
      The usblp in 2.6.18 polled for status regardless if we actually needed it.
      At some point I dropped it, to save the batteries if nothing else.
      As it turned out, printers exist (e.g. Canon BJC-3000) that need prodding
      this way or else they stop. This patch restores the old behaviour.
      If you want to save battery, don't leave jobs in the print queue.
      
      I tested this on my printers by printing and examining usbmon traces
      to make sure status is being requested and printers continue to print.
      Tuomas Jäntti verified the fix on BJC-3000.
      Signed-off-by: NPete Zaitcev <zaitcev@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      dd44be6b
  11. 28 1月, 2009 1 次提交
    • B
      USB: usblp.c: add USBLP_QUIRK_BIDIR to Brother HL-1440 · 06a743bf
      Brandon Philips 提交于
      My Brother HL-1440 would print one document before CUPS would stop
      printing with the error "Printer not connected; will retry in 30
      seconds...". I traced this down to the CUPS usb backend getting an EIO
      out of usblp on the IOCNR_GET_DEVICE_ID IOCTL. Adding the
      USBLP_QUIRK_BIDIR fixes the problem but is it the right solution?
      
      output from strace /usr/lib/cups/backend/usb after printing a document
      (Note: SNDCTL_DSP_SYNC == IOCNR_GET_DEVICE_ID):
      
      before patch
      
      open("/dev/usb/lp0", O_RDWR|O_EXCL)     = 3
      ioctl(3, SNDCTL_DSP_SYNC, 0x7fff2478cef0) = -1 EIO (Input/output error)
      
      after patch
      
      open("/dev/usb/lp0", O_RDWR|O_EXCL)     = 3
      ioctl(3, SNDCTL_DSP_SYNC, 0x7fffb8d474c0) = 0
      
      Possibly related bug: https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/35638Signed-off-by: NBrandon Philips <bphilips@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      06a743bf
  12. 18 10月, 2008 2 次提交
  13. 22 2月, 2008 1 次提交
  14. 13 10月, 2007 5 次提交
    • P
      usblp: Fix a double kfree · 42cb967f
      Pete Zaitcev 提交于
      If submit fails, slab hits a BUG() because of a double kfree.
      The today's lesson is, you cannot just slap USB_FREE_BUFFER on code
      without adjusting the error paths.
      
      The patch is made bigger by opportunistic refactoring.
      Signed-Off-By: NPete Zaitcev <zaitcev@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      42cb967f
    • P
      usblp: Cosmetics · 283face8
      Pete Zaitcev 提交于
      This is a small bunch of cosmetic fixes:
       - Timeout is not a write timeout anymore, rename
       - Condition in poll was confusingly backwards, invert and simplify
       - The comment log gave a wrong impression of version 0.13, terminate it.
      Signed-off-by: NPete Zaitcev <zaitcev@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      283face8
    • P
      usblp: mutex in usblp_check_status · fc401e69
      Pete Zaitcev 提交于
      Add a mutex to protect the ->statusbuf. Not really an issue, because CUPS
      is single-threaded when it talks to the printer, but I feel safer this way.
      This should be deadlock-free, but I kept this as a separate patch in case
      someone ends running a git bisect.
      Signed-off-by: NPete Zaitcev <zaitcev@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      fc401e69
    • P
      usblp: Make use of URB_FREE_BUFFER · e8fa0ce6
      Pete Zaitcev 提交于
      Employ the new API URB_FREE_BUFFER that we've got. There was talk of a combined
      constructor for this case, but apparently it's not happening, so just set the
      flag explicitly for now.
      Signed-off-by: NPete Zaitcev <zaitcev@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      e8fa0ce6
    • P
      usblp: Implement the ENOSPC convention · 7f477358
      Pete Zaitcev 提交于
      This patch implements a mode when a printer returns ENOSPC when it runs
      out of paper. The default remains the same as before. An application which
      wishes to use this function has to enable it explicitly with an ioctl
      LPABORT.
      
      This is done on a request by our (Fedora) CUPS guy, Tim Waugh. The API is
      similar enough to the lp0's one that CUPS works with both (but see below),
      but it's has some differences.
      
      Most importantly, the abort mode is persistent in case of lp0: once tunelp
      was run your cat fill blow up until you reboot or run tunelp again. For
      usblp, I made it so the abort mode is only in effect as long as device
      is open. This way you can mix and match CUPS and cat(1) freely and nothing
      bad happens even if you run out of paper. It is also safer in the face
      of any unexpected crashes.
      
      It has to be noted that mixing LPABORT and O_NONBLOCK is not advised.
      It probably does not do what you want: instead of returning -ENOSPC
      it will always return -EAGAIN (because it would otherwise block while
      waiting for the paper). Applications which use O_NONBLOCK should continue
      to use LPGETSTATUS like before.
      
      Finally, CUPS actually requires patching to take full advantage of this.
      It has several components; those which invoke LPABORT work, but some of
      them need the ioctl added. This is completely compatible, you can mix
      old CUPS and new kernels or vice versa.
      Signed-off-by: NPete Zaitcev <zaitcev@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      7f477358
  15. 20 7月, 2007 2 次提交
  16. 13 7月, 2007 1 次提交
    • P
      USB: usblp: add dynamic URBs, fix races · 317c67b8
      Pete Zaitcev 提交于
      This patch's main bulk aims to make usblp the premier driver for code
      pillaging once again. The code is as streamlined as possible and is bug-free
      as possible. The usb-skeleton performs the same function, but is somewhat
      abstract. The usblp is usb-skeleton which is actually used by many.
      
      Since I combed a few small bugs away, this also fixes the small races we
      had in usblp for a while. For example, now it's possible for several threads
      to make write(2) calls (sounds silly, but consider a printer for paper
      record, where every line of text is self-contained and thus it's all right
      to have them interleaved). Also gone are issues with interrupts using
      barriers dangerously.
      
      This patch makes use of Oliver's anchor, and so it must trail the anchor
      patch on the way to Linus.
      Signed-off-by: NPete Zaitcev <zaitcev@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      317c67b8
  17. 09 6月, 2007 1 次提交
  18. 23 5月, 2007 1 次提交
  19. 09 5月, 2007 1 次提交
  20. 20 3月, 2007 1 次提交
  21. 08 2月, 2007 1 次提交
  22. 06 1月, 2007 1 次提交
    • M
      USB: usblp.c - add Kyocera Mita FS 820 to list of "quirky" printers · 4f45d038
      Martin Williges 提交于
      This patch gets the Kyocera FS-820 working with cups 1.2 via usb again. It
      adds the printer to the list of "quirky" printers. The printer seems not
      answer to ID requests some seconds after plugging in. Patch is based on
      linux-2.6.19.1.
      
      Background:
      As far as I could see (strace, usbmon), the Kyocera FS-820 answers to ID
      requests only a few seconds after plugging it in. This applies to detecting
      it with cups and is also true for the printing itself, which is initiated
      with an ID request. Since I have little usb knowledge, maybe someone can
      interpret the data, especially the fist bulk transfer - why request 8192
      bytes? This is the second version of the patch.
      
      usbmon output of printing an email without patch:
      tail -F /tmp/printlog.txt
      c636e140 3374734463 S Bi:002:02 -115 8192 <
      c9d43b40 3374734494 S Ci:002:00 s a1 00 0000 0000 03ff 1023 <
      c9d43b40 3379732301 C Ci:002:00 -104 0
      c636e140 3379733294 C Bi:002:02 -2 0
      [...repeating...]
      
      with patch:
      tail -F /tmp/printlog.txt
      d9cb82c0 3729790131 S Ci:002:00 s a1 00 0000 0000 03ff 1023 <
      d9cb82c0 3729791725 C Ci:002:00 0 91 = 005b4944 3a46532d 3832303b 4d46473a
       4b796f63 6572613b 434d443a 50434c58 df956320 3732493190 S Bo:002:01 -115
       1347 = 1b252d31 32333435 5840504a 4c0a4050 4a4c2053 4554204d 414e5541
       4c464545 [...more data...]
      Signed-off-by: NMartin Williges <kernel@zut.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      4f45d038
  23. 21 12月, 2006 1 次提交
  24. 04 11月, 2006 2 次提交
  25. 18 10月, 2006 1 次提交
  26. 05 10月, 2006 1 次提交
    • D
      IRQ: Maintain regs pointer globally rather than passing to IRQ handlers · 7d12e780
      David Howells 提交于
      Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
      of passing regs around manually through all ~1800 interrupt handlers in the
      Linux kernel.
      
      The regs pointer is used in few places, but it potentially costs both stack
      space and code to pass it around.  On the FRV arch, removing the regs parameter
      from all the genirq function results in a 20% speed up of the IRQ exit path
      (ie: from leaving timer_interrupt() to leaving do_IRQ()).
      
      Where appropriate, an arch may override the generic storage facility and do
      something different with the variable.  On FRV, for instance, the address is
      maintained in GR28 at all times inside the kernel as part of general exception
      handling.
      
      Having looked over the code, it appears that the parameter may be handed down
      through up to twenty or so layers of functions.  Consider a USB character
      device attached to a USB hub, attached to a USB controller that posts its
      interrupts through a cascaded auxiliary interrupt controller.  A character
      device driver may want to pass regs to the sysrq handler through the input
      layer which adds another few layers of parameter passing.
      
      I've build this code with allyesconfig for x86_64 and i386.  I've runtested the
      main part of the code on FRV and i386, though I can't test most of the drivers.
      I've also done partial conversion for powerpc and MIPS - these at least compile
      with minimal configurations.
      
      This will affect all archs.  Mostly the changes should be relatively easy.
      Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
      
      	struct pt_regs *old_regs = set_irq_regs(regs);
      
      And put the old one back at the end:
      
      	set_irq_regs(old_regs);
      
      Don't pass regs through to generic_handle_irq() or __do_IRQ().
      
      In timer_interrupt(), this sort of change will be necessary:
      
      	-	update_process_times(user_mode(regs));
      	-	profile_tick(CPU_PROFILING, regs);
      	+	update_process_times(user_mode(get_irq_regs()));
      	+	profile_tick(CPU_PROFILING);
      
      I'd like to move update_process_times()'s use of get_irq_regs() into itself,
      except that i386, alone of the archs, uses something other than user_mode().
      
      Some notes on the interrupt handling in the drivers:
      
       (*) input_dev() is now gone entirely.  The regs pointer is no longer stored in
           the input_dev struct.
      
       (*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking.  It does
           something different depending on whether it's been supplied with a regs
           pointer or not.
      
       (*) Various IRQ handler function pointers have been moved to type
           irq_handler_t.
      Signed-Off-By: NDavid Howells <dhowells@redhat.com>
      (cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
      7d12e780
  27. 28 9月, 2006 3 次提交
  28. 21 3月, 2006 1 次提交