On Fri, Nov 30, 2001 at 06:59:06PM +0530, Masoodur Rahman wrote:
> hi Greg, 
>    here is the newer patch with proper indentation( to the best of my 
> knowledge) 

Thanks.  Here's a patch that applies on top of yours that just removes
the active variable all together.  Could you let me know if it works for
you?

thanks,

greg k-h
diff -Nru a/drivers/usb/bluetooth.c b/drivers/usb/bluetooth.c
--- a/drivers/usb/bluetooth.c   Fri Nov 30 09:17:34 2001
+++ b/drivers/usb/bluetooth.c   Fri Nov 30 09:17:35 2001
@@ -1,11 +1,15 @@
 /*
- * bluetooth.c   Version 0.12
+ * bluetooth.c   Version 0.13
  *
  * Copyright (c) 2000, 2001 Greg Kroah-Hartman <[EMAIL PROTECTED]>
  * Copyright (c) 2000 Mark Douglas Corner      <[EMAIL PROTECTED]>
  *
  * USB Bluetooth driver, based on the Bluetooth Spec version 1.0B
  * 
+ * (2001/11/30) Version 0.13 gkh
+ *     - added locking patch from Masoodur Rahman <[EMAIL PROTECTED]>
+ *     - removed active variable, as open_count will do.
+ *
  * (2001/07/09) Version 0.12 gkh
  *     - removed in_interrupt() call, as it doesn't make sense to do 
  *       that anymore.
@@ -118,7 +122,7 @@
 /*
  * Version Information
  */
-#define DRIVER_VERSION "v0.12"
+#define DRIVER_VERSION "v0.13"
 #define DRIVER_AUTHOR "Greg Kroah-Hartman, Mark Douglas Corner"
 #define DRIVER_DESC "USB Bluetooth tty driver"
 
@@ -170,8 +174,8 @@
        struct tty_struct *     tty;            /* the coresponding tty for this port 
*/
 
        unsigned char           minor;          /* the starting minor number for this 
device */
-       char                    active;         /* someone has this device open */
        int                     throttle;       /* throttled by tty layer */
+       int                     open_count;
        
        __u8                    control_out_bInterfaceNum;
        struct urb *            control_urb_pool[NUM_CONTROL_URBS];
@@ -200,8 +204,7 @@
        unsigned char           int_buffer[EVENT_BUFFER_SIZE];
        unsigned int            bulk_packet_pos;
        unsigned char           bulk_buffer[ACL_BUFFER_SIZE];   /* 64k preallocated, 
fix? */
-       struct semaphore        lock;
-       int                     open_count;
+       struct semaphore        lock;
 };
 
 
@@ -366,9 +369,7 @@
        down (&bluetooth->lock);
  
        ++bluetooth->open_count;
-
-       if (!bluetooth->active) {
-
+       if (bluetooth->open_count == 1) {
                /* set up our structure making the tty driver remember our object, and 
us it */
                tty->driver_data = bluetooth;
                bluetooth->tty = tty;
@@ -378,26 +379,27 @@
                * can get lost. */
                bluetooth->tty->low_latency = 1;
        
-               bluetooth->active = 1;
-
                /* Reset the packet position counters */
                bluetooth->int_packet_pos = 0;
                bluetooth->bulk_packet_pos = 0;
 
 #ifndef BTBUGGYHARDWARE
                /* Start reading from the device */
-               FILL_BULK_URB(bluetooth->read_urb, bluetooth->dev, 
-                     usb_rcvbulkpipe(bluetooth->dev, 
bluetooth->bulk_in_endpointAddress),
-                     bluetooth->bulk_in_buffer, bluetooth->bulk_in_buffer_size, 
-                     bluetooth_read_bulk_callback, bluetooth);
+               FILL_BULK_URB (bluetooth->read_urb, bluetooth->dev, 
+                              usb_rcvbulkpipe(bluetooth->dev, 
+bluetooth->bulk_in_endpointAddress),
+                              bluetooth->bulk_in_buffer,
+                              bluetooth->bulk_in_buffer_size,
+                              bluetooth_read_bulk_callback, bluetooth);
                result = usb_submit_urb(bluetooth->read_urb);
                if (result)
                        dbg(__FUNCTION__ " - usb_submit_urb(read bulk) failed with 
status %d", result);
 #endif
-               FILL_INT_URB(bluetooth->interrupt_in_urb, bluetooth->dev, 
-                    usb_rcvintpipe(bluetooth->dev, 
bluetooth->interrupt_in_endpointAddress),
-                    bluetooth->interrupt_in_buffer, 
bluetooth->interrupt_in_buffer_size, 
-                    bluetooth_int_callback, bluetooth, 
bluetooth->interrupt_in_interval);
+               FILL_INT_URB (bluetooth->interrupt_in_urb, bluetooth->dev,
+                             usb_rcvintpipe(bluetooth->dev, 
+bluetooth->interrupt_in_endpointAddress),
+                             bluetooth->interrupt_in_buffer,
+                             bluetooth->interrupt_in_buffer_size,
+                             bluetooth_int_callback, bluetooth,
+                             bluetooth->interrupt_in_interval);
                result = usb_submit_urb(bluetooth->interrupt_in_urb);
                if (result)
                        dbg(__FUNCTION__ " - usb_submit_urb(interrupt in) failed with 
status %d", result);
@@ -420,7 +422,7 @@
 
        dbg(__FUNCTION__);
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not opened");
                return;
        }
@@ -428,17 +430,14 @@
        down (&bluetooth->lock);
  
        --bluetooth->open_count;
- 
        if (bluetooth->open_count <= 0) {
+               bluetooth->open_count = 0;
 
-       /* shutdown any bulk reads and writes that might be going on */
+               /* shutdown any bulk reads and writes that might be going on */
                for (i = 0; i < NUM_BULK_URBS; ++i)
                        usb_unlink_urb (bluetooth->write_urb_pool[i]);
                usb_unlink_urb (bluetooth->read_urb);
                usb_unlink_urb (bluetooth->interrupt_in_urb);
-
-               bluetooth->active = 0;
-               bluetooth->open_count = 0;
        }
        up(&bluetooth->lock);
 }
@@ -462,7 +461,7 @@
 
        dbg(__FUNCTION__ " - %d byte(s)", count);
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not opened");
                return -EINVAL;
        }
@@ -587,7 +586,7 @@
 
        dbg(__FUNCTION__);
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not open");
                return -EINVAL;
        }
@@ -613,7 +612,7 @@
                return -ENODEV;
        }
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not open");
                return -EINVAL;
        }
@@ -639,7 +638,7 @@
 
        dbg(__FUNCTION__);
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not open");
                return;
        }
@@ -660,7 +659,7 @@
 
        dbg(__FUNCTION__);
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not open");
                return;
        }
@@ -679,7 +678,7 @@
 
        dbg(__FUNCTION__ " - cmd 0x%.4x", cmd);
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not open");
                return -ENODEV;
        }
@@ -699,7 +698,7 @@
 
        dbg(__FUNCTION__);
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not open");
                return;
        }
@@ -721,7 +720,7 @@
 
        dbg(__FUNCTION__);
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not open");
                return;
        }
@@ -746,7 +745,7 @@
 
        dbg(__FUNCTION__);
 
-       if (!bluetooth->active) {
+       if (!bluetooth->open_count) {
                dbg (__FUNCTION__ " - device not open");
                return;
        }
@@ -976,7 +975,7 @@
        }       
 
 exit:
-       if (!bluetooth || !bluetooth->active)
+       if (!bluetooth || !bluetooth->open_count)
                return;
 
        FILL_BULK_URB(bluetooth->read_urb, bluetooth->dev, 
@@ -1233,10 +1232,10 @@
        int i;
 
        if (bluetooth) {
-               if ((bluetooth->active) && (bluetooth->tty))
+               if ((bluetooth->open_count) && (bluetooth->tty))
                        tty_hangup(bluetooth->tty);
 
-               bluetooth->active = 0;
+               bluetooth->open_count = 0;
 
                if (bluetooth->read_urb) {
                        usb_unlink_urb (bluetooth->read_urb);

Reply via email to