LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-12-2004, 12:30 AM   #1
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
usb skeleton driver question


source:
/usr/src/my_linux-2.4.20/drivers/usb/usb-skeleton.c

where it is bold, why are they down'ing the semaphore while still holdin on to the other one? wouldnt it make more sense to switch the order of those calls and release one before trying to lock the other? or is there something i'm not seeing here.

Code:
static int skel_open (struct inode *inode, struct file *file)
{
    struct usb_skel *dev = NULL;
    int subminor;
    int retval = 0;

    dbg(__FUNCTION__);

    subminor = MINOR (inode->i_rdev) - USB_SKEL_MINOR_BASE;
    if ((subminor < 0) ||
        (subminor >= MAX_DEVICES)) {
        return -ENODEV;
    }

    /* Increment our usage count for the module.
     * This is redundant here, because "struct file_operations"
     * has an "owner" field. This line is included here soley as
     * a reference for drivers using lesser structures... ;-)
     */
    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;
    }

    /* lock this device */
    down (&dev->sem);

    /* unlock the minor table */
    up (&minor_table_mutex);

    /* increment our usage count for the driver */
    ++dev->open_count;

    /* save our object in the file's private structure */
    file->private_data = dev;

    /* unlock this device */
    up (&dev->sem);

    return retval;
}
 
Old 03-12-2004, 01:19 PM   #2
PSIplus
Member
 
Registered: Feb 2004
Location: Vienna/Austria
Distribution: Debian Unstable
Posts: 36

Rep: Reputation: 15
Hmmm... Seems for me like a preparation for preemble kernel functions... Don't know why it is eactly working this way, but, it think David Brownell was it who changed the behavier of half of the usb architecture to fit with the new needs of 2.6

Watch out your 2.6 source:
drivers/usb/usb-skeleton.c

You'll see what i mean. Overall, semaphore-usage and mutexes got much more complicated in 2.6 from my view of things...

Have Fun!
 
Old 03-12-2004, 03:34 PM   #3
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Original Poster
Rep: Reputation: 30
ewww im not even going to look at 2.6 until i finish 'linux device drivers'. im struggling just to make it thru as it is. thanks for the reply tho.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the skeleton directory for subdomain? koka Linux - Newbie 2 10-21-2005 06:32 PM
ati driver question and console question kholdstayr Slackware 2 07-18-2005 04:30 PM
HELP !!!!!! USB driver badboyspy Linux - Networking 1 12-03-2004 06:08 PM
slackware 10 useradd skeleton.. miguetoo Slackware 2 06-25-2004 02:50 AM
Skeleton directories for new users? jungatheart Linux - Newbie 2 04-24-2004 04:44 PM


All times are GMT -5. The time now is 07:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration