Hi,

I recently saw an article in Linux Journal about writing a USB device
driver. One thing that leapt out at me was that the skeleton driver
code called MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT in the
file_operations open and release methods. Aren't these macros Linux
2.2-isms that have been made redundant by the file_operations.owner
field? Since the owner field is already correctly set to THIS_MODULE,
I have attached a patch to remove the MOD_XXX_USE_COUNT macro
calls. After all, asking a module to lock itself has an implicit race
condition.

This patch is against Linux 2.4.16.

Cheers,
Chris

--- drivers/usb/usb-skeleton.c.orig     Tue Dec  4 13:05:28 2001
+++ drivers/usb/usb-skeleton.c  Tue Dec  4 13:06:42 2001
@@ -215,15 +215,11 @@
                return -ENODEV;
        }
 
-       /* increment our usage count for the module */
-       MOD_INC_USE_COUNT;
-
        /* lock our minor table and get our local data for this minor */
        down (&minor_table_mutex);
        dev = minor_table[subminor];
        if (dev == NULL) {
                up (&minor_table_mutex);
-               MOD_DEC_USE_COUNT;
                return -ENODEV;
        }
 
@@ -278,7 +274,6 @@
                /* the device was unplugged before the file was released */
                up (&dev->sem);
                skel_delete (dev);
-               MOD_DEC_USE_COUNT;
                up (&minor_table_mutex);
                return 0;
        }
@@ -290,9 +285,6 @@
                usb_unlink_urb (dev->write_urb);
                dev->open_count = 0;
        }
-
-       /* decrement our usage count for the module */
-       MOD_DEC_USE_COUNT;
 
 exit_not_opened:
        up (&dev->sem);

_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to