Listing 4. The skel_disconnect Function

/* if the device is not opened, then we clean
   right now */
    if (skel->open_count) {
            minor_table[skel->minor] = NULL;
            if (skel->bulk_in_buffer != NULL)
                    kfree (skel->bulk_in_buffer);
            if (skel->bulk_out_buffer != NULL)
                    kfree (skel->bulk_out_buffer);
            if (skel->write_urb != NULL)
                    usb_free_urb (skel->write_urb);
            kfree (skel);
    } else {
            skel->dev = NULL;
            up (&skel->sem);
    }