18 #include <linux/module.h>
19 #include <linux/errno.h>
21 #include <linux/slab.h>
26 #define MAX_USB_MINORS 256
32 int minor = iminor(inode);
38 c = usb_minors[minor];
43 old_fops = file->
f_op;
44 file->
f_op = new_fops;
47 err = file->
f_op->open(inode,file);
64 static struct usb_class {
71 struct usb_class_driver *drv;
74 if (!drv || !drv->devnode)
76 return drv->devnode(dev, mode);
79 static int init_usb_class(
void)
83 if (usb_class !=
NULL) {
84 kref_get(&usb_class->kref);
94 kref_init(&usb_class->kref);
96 if (IS_ERR(usb_class->class)) {
97 result = IS_ERR(usb_class->class);
103 usb_class->class->devnode = usb_devnode;
109 static void release_usb_class(
struct kref *
kref)
117 static void destroy_usb_class(
void)
120 kref_put(&usb_class->kref, release_usb_class);
127 error = register_chrdev(
USB_MAJOR,
"usb", &usb_fops);
160 struct usb_class_driver *class_driver)
163 int minor_base = class_driver->minor_base;
168 #ifdef CONFIG_USB_DYNAMIC_MINORS
177 if (class_driver->fops ==
NULL)
179 if (intf->minor >= 0)
182 retval = init_usb_class();
186 dev_dbg(&intf->dev,
"looking for a minor, starting at %d\n", minor_base);
190 if (usb_minors[minor])
193 usb_minors[minor] = class_driver->fops;
202 snprintf(name,
sizeof(name), class_driver->name, minor - minor_base);
204 if (temp && (temp[1] !=
'\0'))
211 if (IS_ERR(intf->usb_dev)) {
213 usb_minors[minor] =
NULL;
216 retval = PTR_ERR(intf->usb_dev);
237 struct usb_class_driver *class_driver)
239 if (intf->minor == -1)
242 dev_dbg(&intf->dev,
"removing %d minor\n", intf->minor);
245 usb_minors[intf->minor] =
NULL;
249 intf->usb_dev =
NULL;