[PARPORT] lp_open() race-conditions fix


Andrea Arcangeli (arcangeli@mbox.queen.it)
Sun, 15 Feb 1998 17:00:43 +0100 (CET)


As Tim pointed out there is a race-conditions in lp_open() due LP_BUSY
test. In some cases lp_open() function can recall lp_parport_claim() and
so goes to sleep allowing another process to pass the LP_BUSY test.

Here the fix:

--- linux/drivers/char/lp.c 1998/02/14 16:21:36 1.1
+++ linux/drivers/char/lp.c 1998/02/15 15:57:11
@@ -475,6 +475,7 @@
                 return -ENXIO;
         if (LP_F(minor) & LP_BUSY)
                 return -EBUSY;
+ LP_F(minor) |= LP_BUSY;
 
         MOD_INC_USE_COUNT;
 
@@ -491,23 +492,26 @@
                 if (status & LP_POUTPA) {
                         printk(KERN_INFO "lp%d out of paper\n", minor);
                         MOD_DEC_USE_COUNT;
+ LP_F(minor) &= ~LP_BUSY;
                         return -ENOSPC;
                 } else if (!(status & LP_PSELECD)) {
                         printk(KERN_INFO "lp%d off-line\n", minor);
                         MOD_DEC_USE_COUNT;
+ LP_F(minor) &= ~LP_BUSY;
                         return -EIO;
                 } else if (!(status & LP_PERRORP)) {
                         printk(KERN_ERR "lp%d printer error\n", minor);
                         MOD_DEC_USE_COUNT;
+ LP_F(minor) &= ~LP_BUSY;
                         return -EIO;
                 }
         }
         lp_table[minor].lp_buffer = (char *) kmalloc(LP_BUFFER_SIZE, GFP_KERNEL);
         if (!lp_table[minor].lp_buffer) {
                 MOD_DEC_USE_COUNT;
+ LP_F(minor) &= ~LP_BUSY;
                 return -ENOMEM;
         }
- LP_F(minor) |= LP_BUSY;
         return 0;
 }
 

Andrea[s] Arcangeli

-- To unsubscribe, send mail to: linux-parport-request@torque.net --
-- with the single word "unsubscribe" in the body of the message. --



This archive was generated by hypermail 2.0b3 on Wed 30 Dec 1998 - 10:17:28 EST