Thursday, July 19, 2012

linux Kernel 2.6.38 using sema_init

I just found out when upgraded rt73 device drivers that the old Linux kernel and the new version they changed the mutex to semaphore with extra parameter (A mutex is essentially the same thing as a binary semaphore(1 or 0 single resource) vs. counting values that allows multiple program threads to share the same resource)  I could not even grep for the name because the name is totally different. The name is now all low cases sema_init. So the device driver could fail after upgrade to a new Linux kernel and this is the case we need to change the device driver rt73 module rtmp_init.c as follow.
#ifndef init_MUTEX_LOCKED

        sema_init(&(pAd->usbdev_semaphore), 1);            // linux kernel 2.6.38

        sema_init(&(pAd->mlme_semaphore), 1);

        sema_init(&(pAd->RTUSBCmd_semaphore), 1);

#else
        init_MUTEX_LOCKED(&(pAd->usbdev_semaphore)); // linux kernel 2.6.37

        init_MUTEX_LOCKED(&(pAd->mlme_semaphore));

        init_MUTEX_LOCKED(&(pAd->RTUSBCmd_semaphore));  


#endif
//Note:

//currently typically to 1 (in which case the semaphore is called a mutex) 
//From Linus Torvalds
/* Maximum concurrent users 
#define MAX_CONCURRENT_USERS 20
sema_init(&sem, MAX_CONCURRENT_USERS);

However, almost all practical use of semaphores is a special case where
the counter is initialized to 1, and where they are used as simple
mutual exclusion with only one user allowed in the critical region.
Such a semaphore is often called a "mutex" semaphore for MUTual
EXclusion.
*/

No comments: