On Thursday 30 September 2004 23:40, David Woodhouse wrote:
> On Wed, 2004-09-29 at 13:57 +0200, Duncan Sands wrote:
> > I will check it all out tonight.
> 
> Any comments?

Here is an incremental patch.  It uses a kref for reference counting,
and fixes a reference counting bug in udsl_firmware_start.  I didn't
look at your split version yet, so this is on top of your pre-split
patches.   More changes to follow...

All the best,

Duncan.

Index: mm/drivers/usb/misc/speedtch.c
===================================================================
--- mm.orig/drivers/usb/misc/speedtch.c 2004-10-01 10:30:14.000000000 +0200
+++ mm/drivers/usb/misc/speedtch.c      2004-10-01 16:11:57.311851079 +0200
@@ -61,26 +61,26 @@
  *
  */
 
-#include <asm/atomic.h>
 #include <asm/semaphore.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/timer.h>
-#include <linux/errno.h>
-#include <linux/proc_fs.h>
-#include <linux/slab.h>
-#include <linux/wait.h>
-#include <linux/list.h>
 #include <asm/uaccess.h>
-#include <linux/smp_lock.h>
-#include <linux/interrupt.h>
 #include <linux/atm.h>
 #include <linux/atmdev.h>
 #include <linux/crc32.h>
-#include <linux/init.h>
+#include <linux/errno.h>
 #include <linux/firmware.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/kref.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/proc_fs.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/smp_lock.h>
+#include <linux/timer.h>
+#include <linux/wait.h>
 
 /*
 #define DEBUG
@@ -263,7 +263,7 @@
 };
 
 struct udsl_instance_data {
-       atomic_t refcount;
+       struct kref refcount;
        struct semaphore serialize;
 
        /* USB device part */
@@ -860,19 +860,24 @@
 **  bean counting  **
 ********************/
 
+static inline void udsl_destroy_instance (struct kref *kref)
+{
+       struct udsl_instance_data *instance = container_of (kref, struct 
udsl_instance_data, refcount);
+
+       tasklet_kill (&instance->receive_tasklet);
+       tasklet_kill (&instance->send_tasklet);
+       usb_put_dev (instance->usb_dev);
+       kfree (instance);
+}
+
 static inline void udsl_get_instance (struct udsl_instance_data *instance)
 {
-       atomic_inc (&instance->refcount);
+       kref_get (&instance->refcount);
 }
 
 static inline void udsl_put_instance (struct udsl_instance_data *instance)
 {
-       if (atomic_dec_and_test (&instance->refcount)) {
-               tasklet_kill (&instance->receive_tasklet);
-               tasklet_kill (&instance->send_tasklet);
-               usb_put_dev (instance->usb_dev);
-               kfree (instance);
-       }
+       kref_put (&instance->refcount, udsl_destroy_instance);
 }
 
 
@@ -1424,9 +1429,10 @@
                                       instance,
                                       udsl_firmware_stage1);
 
-       if (ret < 0) {
-               dbg ("udsl_firmware_start: request_firmware_nowait failed (%d)!", ret);
-       }
+       if (ret >= 0)
+               return;
+
+       dbg ("udsl_firmware_start: request_firmware_nowait failed (%d)!", ret);
 
        /* Just pretend it never happened... hope modem_run happens */
 #endif /* CONFIG_FW_LOADER */
@@ -1699,7 +1705,8 @@
 
        INIT_WORK(&instance->poll_work, (void *)udsl_poll_status, instance);
 
-       atomic_set (&instance->refcount, 2); /* one for USB, one for ATM */
+       kref_init (&instance->refcount); /* one for USB */
+       udsl_get_instance (instance);    /* one for ATM */
 
        init_MUTEX (&instance->serialize);
 


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to