diff --git a/acx_func.h b/acx_func.h index a8e2482..239698b 100644 --- a/acx_func.h +++ b/acx_func.h @@ -307,27 +307,18 @@ acx_unlock_helper(acx_device_t *adev, un acx_unlock_debug(adev, where); spin_unlock_irqrestore(&adev->lock, *fp); } -static inline void -acx_down_helper(acx_device_t *adev, const char* where) -{ - acx_down_debug(adev, where); -} -static inline void -acx_up_helper(acx_device_t *adev, const char* where) -{ - acx_up_debug(adev, where); -} + #define acx_lock(adev, flags) acx_lock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__)) #define acx_unlock(adev, flags) acx_unlock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__)) -#define acx_sem_lock(adev) acx_down_helper(adev, __FILE__ ":" STRING(__LINE__)) -#define acx_sem_unlock(adev) acx_up_helper(adev, __FILE__ ":" STRING(__LINE__)) +#define acx_sem_lock(adev) mutex_lock(&(adev)->mutex) +#define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex) #elif defined(DO_LOCKING) #define acx_lock(adev, flags) spin_lock_irqsave(&adev->lock, flags) #define acx_unlock(adev, flags) spin_unlock_irqrestore(&adev->lock, flags) -#define acx_sem_lock(adev) down(&adev->sem) -#define acx_sem_unlock(adev) up(&adev->sem) +#define acx_sem_lock(adev) mutex_lock(&(adev)->mutex) +#define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex) #define acx_lock_unhold() ((void)0) #define acx_sem_unhold() ((void)0) diff --git a/acx_struct.h b/acx_struct.h index 0bd18c4..65d6cf5 100644 --- a/acx_struct.h +++ b/acx_struct.h @@ -1142,7 +1142,7 @@ struct acx_device { /* FIXME: try to convert semaphore to more efficient mutex according to Ingo Molnar's docs (but not before driver is in mainline or pre-mutex Linux 2.6.10 is very outdated). */ - struct semaphore sem; + struct mutex mutex; spinlock_t lock; #if defined(PARANOID_LOCKING) /* Lock debugging */ const char *last_sem; diff --git a/common.c b/common.c index 70e8afc..c019cef 100644 --- a/common.c +++ b/common.c @@ -189,59 +189,7 @@ acx_unlock_debug(acx_device_t *adev, con } } } -void -acx_down_debug(acx_device_t *adev, const char* where) -{ - int sem_count; - unsigned long timeout = jiffies + 5*HZ; - - where = sanitize_str(where); - for (;;) { - sem_count = atomic_read(&adev->sem.count); - if (sem_count) break; - if (time_after(jiffies, timeout)) - break; - msleep(5); - } - if (!sem_count) { - printk(KERN_EMERG "D STATE at %s! last sem at %s\n", - where, adev->last_sem); - dump_stack(); - } - adev->last_sem = where; - adev->sem_time = jiffies; - down(&adev->sem); - if (acx_debug & L_LOCK) { - printk("%s: sem_down %d -> %d\n", - where, sem_count, atomic_read(&adev->sem.count)); - } -} -void -acx_up_debug(acx_device_t *adev, const char* where) -{ - int sem_count = atomic_read(&adev->sem.count); - if (sem_count) { - where = sanitize_str(where); - printk(KERN_EMERG "STRAY UP at %s! sem.count=%d\n", where, sem_count); - dump_stack(); - } - if (acx_debug & L_LOCK) { - unsigned long diff = jiffies - adev->sem_time; - if (diff > max_sem_time) { - where = sanitize_str(where); - printk("max sem hold time %ld jiffies from %s " - "to %s\n", diff, adev->last_sem, where); - max_sem_time = diff; - } - } - up(&adev->sem); - if (acx_debug & L_LOCK) { - where = sanitize_str(where); - printk("%s: sem_up %d -> %d\n", - where, sem_count, atomic_read(&adev->sem.count)); - } -} #endif /* PARANOID_LOCKING */ diff --git a/pci.c b/pci.c index 910155f..a390606 100644 --- a/pci.c +++ b/pci.c @@ -1617,7 +1617,7 @@ acxpci_e_probe(struct pci_dev *pdev, con adev = ndev2adev(ndev); spin_lock_init(&adev->lock); /* initial state: unlocked */ /* We do not start with downed sem: we want PARANOID_LOCKING to work */ - sema_init(&adev->sem, 1); /* initial state: 1 (upped) */ + mutex_init(&adev->mutex); /* initial state: 1 (upped) */ /* since nobody can see new netdev yet, we can as well ** just _presume_ that we're under sem (instead of actually taking it): */ /* acx_sem_lock(adev); */ diff --git a/usb.c b/usb.c index 3183743..cd610e4 100644 --- a/usb.c +++ b/usb.c @@ -869,7 +869,7 @@ acxusb_e_probe(struct usb_interface *int adev->usbdev = usbdev; spin_lock_init(&adev->lock); /* initial state: unlocked */ - sema_init(&adev->sem, 1); /* initial state: 1 (upped) */ + mutex_init(&adev->mutex); /* initial state: 1 (upped) */ /* Check that this is really the hardware we know about. ** If not sure, at least notify the user that he