Commit 26f8beab authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

USB: Fixups due to the changes in struct usb_device for file_operations and minor number handling

parent 05752c5d
...@@ -372,7 +372,7 @@ static void usblp_cleanup (struct usblp *usblp) ...@@ -372,7 +372,7 @@ static void usblp_cleanup (struct usblp *usblp)
{ {
devfs_unregister (usblp->devfs); devfs_unregister (usblp->devfs);
usblp_table [usblp->minor] = NULL; usblp_table [usblp->minor] = NULL;
usb_deregister_dev (&usblp_driver, 1, usblp->minor); usb_deregister_dev (1, usblp->minor);
info("usblp%d: removed", usblp->minor); info("usblp%d: removed", usblp->minor);
kfree (usblp->writeurb->transfer_buffer); kfree (usblp->writeurb->transfer_buffer);
...@@ -812,21 +812,11 @@ static void *usblp_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -812,21 +812,11 @@ static void *usblp_probe(struct usb_device *dev, unsigned int ifnum,
init_waitqueue_head(&usblp->wait); init_waitqueue_head(&usblp->wait);
usblp->ifnum = ifnum; usblp->ifnum = ifnum;
retval = usb_register_dev(&usblp_driver, 1, &usblp->minor); retval = usb_register_dev(&usblp_fops, USBLP_MINOR_BASE, 1, &usblp->minor);
if (retval) { if (retval) {
if (retval != -ENODEV) {
err("Not able to get a minor for this device."); err("Not able to get a minor for this device.");
goto abort; goto abort;
} }
/* Look for a free usblp_table entry on our own. */
while (usblp_table[usblp->minor]) {
usblp->minor++;
if (usblp->minor >= USBLP_MINORS) {
err("no more free usblp devices");
goto abort;
}
}
}
usblp->writeurb = usb_alloc_urb(0, GFP_KERNEL); usblp->writeurb = usb_alloc_urb(0, GFP_KERNEL);
if (!usblp->writeurb) { if (!usblp->writeurb) {
...@@ -901,7 +891,7 @@ static void *usblp_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -901,7 +891,7 @@ static void *usblp_probe(struct usb_device *dev, unsigned int ifnum,
return usblp; return usblp;
abort_minor: abort_minor:
usb_deregister_dev (&usblp_driver, 1, usblp->minor); usb_deregister_dev (1, usblp->minor);
abort: abort:
if (usblp) { if (usblp) {
usb_free_urb(usblp->writeurb); usb_free_urb(usblp->writeurb);
...@@ -1111,9 +1101,6 @@ static struct usb_driver usblp_driver = { ...@@ -1111,9 +1101,6 @@ static struct usb_driver usblp_driver = {
name: "usblp", name: "usblp",
probe: usblp_probe, probe: usblp_probe,
disconnect: usblp_disconnect, disconnect: usblp_disconnect,
fops: &usblp_fops,
minor: USBLP_MINOR_BASE,
num_minors: USBLP_MINORS,
id_table: usblp_ids, id_table: usblp_ids,
}; };
......
...@@ -401,6 +401,7 @@ static void mdc800_usb_download_notify (struct urb *urb) ...@@ -401,6 +401,7 @@ static void mdc800_usb_download_notify (struct urb *urb)
***************************************************************************/ ***************************************************************************/
static struct usb_driver mdc800_usb_driver; static struct usb_driver mdc800_usb_driver;
static struct file_operations mdc800_device_ops;
/* /*
* Callback to search the Mustek MDC800 on the USB Bus * Callback to search the Mustek MDC800 on the USB Bus
...@@ -476,7 +477,7 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum, ...@@ -476,7 +477,7 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum,
down (&mdc800->io_lock); down (&mdc800->io_lock);
retval = usb_register_dev (&mdc800_usb_driver, 1, &mdc800->minor); retval = usb_register_dev (&mdc800_device_ops, MDC800_DEVICE_MINOR_BASE, 1, &mdc800->minor);
if (retval && (retval != -ENODEV)) { if (retval && (retval != -ENODEV)) {
err ("Not able to get a minor for this device."); err ("Not able to get a minor for this device.");
return 0; return 0;
...@@ -537,7 +538,7 @@ static void mdc800_usb_disconnect (struct usb_device *dev,void* ptr) ...@@ -537,7 +538,7 @@ static void mdc800_usb_disconnect (struct usb_device *dev,void* ptr)
if (mdc800->state == NOT_CONNECTED) if (mdc800->state == NOT_CONNECTED)
return; return;
usb_deregister_dev (&mdc800_usb_driver, 1, mdc800->minor); usb_deregister_dev (1, mdc800->minor);
mdc800->state=NOT_CONNECTED; mdc800->state=NOT_CONNECTED;
...@@ -942,12 +943,10 @@ MODULE_DEVICE_TABLE (usb, mdc800_table); ...@@ -942,12 +943,10 @@ MODULE_DEVICE_TABLE (usb, mdc800_table);
*/ */
static struct usb_driver mdc800_usb_driver = static struct usb_driver mdc800_usb_driver =
{ {
owner: THIS_MODULE,
name: "mdc800", name: "mdc800",
probe: mdc800_usb_probe, probe: mdc800_usb_probe,
disconnect: mdc800_usb_disconnect, disconnect: mdc800_usb_disconnect,
fops: &mdc800_device_ops,
minor: MDC800_DEVICE_MINOR_BASE,
num_minors: 1,
id_table: mdc800_table id_table: mdc800_table
}; };
......
...@@ -971,18 +971,12 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -971,18 +971,12 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
down(&scn_mutex); down(&scn_mutex);
retval = usb_register_dev(&scanner_driver, 1, &scn_minor); retval = usb_register_dev(&usb_scanner_fops, SCN_BASE_MNR, 1, &scn_minor);
if (retval) { if (retval) {
if (retval != -ENODEV) {
err ("Not able to get a minor for this device."); err ("Not able to get a minor for this device.");
up(&scn_mutex); up(&scn_mutex);
return NULL; return NULL;
} }
for (scn_minor = 0; scn_minor < SCN_MAX_MNR; scn_minor++) {
if (!p_scn_table[scn_minor])
break;
}
}
/* Check to make sure that the last slot isn't already taken */ /* Check to make sure that the last slot isn't already taken */
if (p_scn_table[scn_minor]) { if (p_scn_table[scn_minor]) {
...@@ -1112,7 +1106,7 @@ disconnect_scanner(struct usb_device *dev, void *ptr) ...@@ -1112,7 +1106,7 @@ disconnect_scanner(struct usb_device *dev, void *ptr)
dbg("disconnect_scanner: De-allocating minor:%d", scn->scn_minor); dbg("disconnect_scanner: De-allocating minor:%d", scn->scn_minor);
devfs_unregister(scn->devfs); devfs_unregister(scn->devfs);
usb_deregister_dev(&scanner_driver, 1, scn->scn_minor); usb_deregister_dev(1, scn->scn_minor);
p_scn_table[scn->scn_minor] = NULL; p_scn_table[scn->scn_minor] = NULL;
usb_free_urb(scn->scn_irq); usb_free_urb(scn->scn_irq);
up (&(scn->sem)); up (&(scn->sem));
...@@ -1125,9 +1119,6 @@ usb_driver scanner_driver = { ...@@ -1125,9 +1119,6 @@ usb_driver scanner_driver = {
name: "usbscanner", name: "usbscanner",
probe: probe_scanner, probe: probe_scanner,
disconnect: disconnect_scanner, disconnect: disconnect_scanner,
fops: &usb_scanner_fops,
minor: SCN_BASE_MNR,
num_minors: SCN_MAX_MNR,
id_table: NULL, /* This would be scanner_device_ids, but we id_table: NULL, /* This would be scanner_device_ids, but we
need to check every USB device, in case need to check every USB device, in case
we match a user defined vendor/product ID. */ we match a user defined vendor/product ID. */
......
...@@ -193,7 +193,7 @@ static int hiddev_fasync(int fd, struct file *file, int on) ...@@ -193,7 +193,7 @@ static int hiddev_fasync(int fd, struct file *file, int on)
static void hiddev_cleanup(struct hiddev *hiddev) static void hiddev_cleanup(struct hiddev *hiddev)
{ {
devfs_unregister(hiddev->devfs); devfs_unregister(hiddev->devfs);
usb_deregister_dev(&hiddev_driver, 1, hiddev->minor); usb_deregister_dev(1, hiddev->minor);
hiddev_table[hiddev->minor] = NULL; hiddev_table[hiddev->minor] = NULL;
kfree(hiddev); kfree(hiddev);
} }
...@@ -626,21 +626,16 @@ int hiddev_connect(struct hid_device *hid) ...@@ -626,21 +626,16 @@ int hiddev_connect(struct hid_device *hid)
if (i == hid->maxapplication) if (i == hid->maxapplication)
return -1; return -1;
retval = usb_register_dev (&hiddev_driver, 1, &minor); retval = usb_register_dev (&hiddev_fops, HIDDEV_MINOR_BASE, 1, &minor);
if (retval) { if (retval) {
if (retval != -ENODEV) {
err ("Not able to get a minor for this device."); err ("Not able to get a minor for this device.");
return -1; return -1;
} }
for (minor = 0; minor < HIDDEV_MINORS && hiddev_table[minor]; minor++);
if (minor == HIDDEV_MINORS) {
printk(KERN_ERR "hiddev: no more free hiddev devices\n");
return -1;
}
}
if (!(hiddev = kmalloc(sizeof(struct hiddev), GFP_KERNEL))) if (!(hiddev = kmalloc(sizeof(struct hiddev), GFP_KERNEL))) {
usb_deregister_dev (1, minor);
return -1; return -1;
}
memset(hiddev, 0, sizeof(struct hiddev)); memset(hiddev, 0, sizeof(struct hiddev));
init_waitqueue_head(&hiddev->wait); init_waitqueue_head(&hiddev->wait);
...@@ -708,9 +703,6 @@ static void *hiddev_usbd_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -708,9 +703,6 @@ static void *hiddev_usbd_probe(struct usb_device *dev, unsigned int ifnum,
static /* const */ struct usb_driver hiddev_driver = { static /* const */ struct usb_driver hiddev_driver = {
name: "hiddev", name: "hiddev",
probe: hiddev_usbd_probe, probe: hiddev_usbd_probe,
fops: &hiddev_fops,
minor: HIDDEV_MINOR_BASE,
num_minors: HIDDEV_MINORS,
}; };
int __init hiddev_init(void) int __init hiddev_init(void)
......
...@@ -742,14 +742,9 @@ static void *dabusb_probe (struct usb_device *usbdev, unsigned int ifnum, ...@@ -742,14 +742,9 @@ static void *dabusb_probe (struct usb_device *usbdev, unsigned int ifnum,
if (ifnum != _DABUSB_IF && usbdev->descriptor.idProduct == 0x9999) if (ifnum != _DABUSB_IF && usbdev->descriptor.idProduct == 0x9999)
return NULL; return NULL;
retval = usb_register_dev (&dabusb_driver, 1, &devnum); retval = usb_register_dev (&dabusb_fops, DABUSB_MINOR, 1, &devnum);
if (retval) { if (retval)
if (retval != -ENODEV)
return NULL; return NULL;
devnum = dabusb_find_struct ();
if (devnum == -1)
return NULL;
}
s = &dabusb[devnum]; s = &dabusb[devnum];
...@@ -791,7 +786,7 @@ static void dabusb_disconnect (struct usb_device *usbdev, void *ptr) ...@@ -791,7 +786,7 @@ static void dabusb_disconnect (struct usb_device *usbdev, void *ptr)
dbg("dabusb_disconnect"); dbg("dabusb_disconnect");
usb_deregister_dev (&dabusb_driver, 1, s->devnum); usb_deregister_dev (1, s->devnum);
s->remove_pending = 1; s->remove_pending = 1;
wake_up (&s->wait); wake_up (&s->wait);
if (s->state == _started) if (s->state == _started)
...@@ -814,9 +809,6 @@ static struct usb_driver dabusb_driver = ...@@ -814,9 +809,6 @@ static struct usb_driver dabusb_driver =
name: "dabusb", name: "dabusb",
probe: dabusb_probe, probe: dabusb_probe,
disconnect: dabusb_disconnect, disconnect: dabusb_disconnect,
fops: &dabusb_fops,
minor: DABUSB_MINOR,
num_minors: NRDABUSB,
id_table: dabusb_ids, id_table: dabusb_ids,
}; };
......
...@@ -1948,24 +1948,12 @@ static void *auerswald_probe (struct usb_device *usbdev, unsigned int ifnum, ...@@ -1948,24 +1948,12 @@ static void *auerswald_probe (struct usb_device *usbdev, unsigned int ifnum,
init_waitqueue_head (&cp->bufferwait); init_waitqueue_head (&cp->bufferwait);
down (&dev_table_mutex); down (&dev_table_mutex);
ret = usb_register_dev (&auerswald_driver, 1, &dtindex); ret = usb_register_dev (&auerswald_fops, AUER_MINOR_BASE, 1, &dtindex);
if (ret) { if (ret) {
if (ret != -ENODEV) {
err ("Not able to get a minor for this device."); err ("Not able to get a minor for this device.");
up (&dev_table_mutex); up (&dev_table_mutex);
goto pfail; goto pfail;
} }
/* find a free slot in the device table */
for (dtindex = 0; dtindex < AUER_MAX_DEVICES; ++dtindex) {
if (dev_table[dtindex] == NULL)
break;
}
if ( dtindex >= AUER_MAX_DEVICES) {
err ("more than %d devices plugged in, can not handle this device", AUER_MAX_DEVICES);
up (&dev_table_mutex);
goto pfail;
}
}
/* Give the device a name */ /* Give the device a name */
sprintf (cp->name, AU_PREFIX "%d", dtindex); sprintf (cp->name, AU_PREFIX "%d", dtindex);
...@@ -2096,7 +2084,7 @@ static void auerswald_disconnect (struct usb_device *usbdev, void *driver_contex ...@@ -2096,7 +2084,7 @@ static void auerswald_disconnect (struct usb_device *usbdev, void *driver_contex
devfs_unregister (cp->devfs); devfs_unregister (cp->devfs);
/* give back our USB minor number */ /* give back our USB minor number */
usb_deregister_dev (&auerswald_driver, 1, cp->dtindex); usb_deregister_dev (1, cp->dtindex);
/* Stop the interrupt endpoint */ /* Stop the interrupt endpoint */
auerswald_int_release (cp); auerswald_int_release (cp);
...@@ -2153,9 +2141,6 @@ static struct usb_driver auerswald_driver = { ...@@ -2153,9 +2141,6 @@ static struct usb_driver auerswald_driver = {
name: "auerswald", name: "auerswald",
probe: auerswald_probe, probe: auerswald_probe,
disconnect: auerswald_disconnect, disconnect: auerswald_disconnect,
fops: &auerswald_fops,
minor: AUER_MINOR_BASE,
num_minors: AUER_MAX_DEVICES,
id_table: auerswald_ids, id_table: auerswald_ids,
}; };
......
...@@ -246,9 +246,6 @@ static struct usb_driver brlvger_driver = ...@@ -246,9 +246,6 @@ static struct usb_driver brlvger_driver =
name: "brlvger", name: "brlvger",
probe: brlvger_probe, probe: brlvger_probe,
disconnect: brlvger_disconnect, disconnect: brlvger_disconnect,
fops: &brlvger_fops,
minor: BRLVGER_MINOR,
num_minors: MAX_NR_BRLVGER_DEVS,
id_table: brlvger_ids, id_table: brlvger_ids,
}; };
...@@ -316,22 +313,11 @@ brlvger_probe (struct usb_device *dev, unsigned ifnum, ...@@ -316,22 +313,11 @@ brlvger_probe (struct usb_device *dev, unsigned ifnum,
down(&reserve_sem); down(&reserve_sem);
retval = usb_register_dev(&brlvger_driver, 1, &i); retval = usb_register_dev(&brlvger_fops, BRLVGER_MINOR, 1, &i);
if (retval) { if (retval) {
if (retval != -ENODEV) {
err("Not able to get a minor for this device."); err("Not able to get a minor for this device.");
goto error; goto error;
} }
for( i = 0; i < MAX_NR_BRLVGER_DEVS; i++ )
if( display_table[i] == NULL )
break;
if( i == MAX_NR_BRLVGER_DEVS ) {
err( "This driver cannot handle more than %d "
"braille displays", MAX_NR_BRLVGER_DEVS);
goto error;
}
}
if( !(priv = kmalloc (sizeof *priv, GFP_KERNEL)) ){ if( !(priv = kmalloc (sizeof *priv, GFP_KERNEL)) ){
err("No more memory"); err("No more memory");
...@@ -431,7 +417,7 @@ brlvger_disconnect(struct usb_device *dev, void *ptr) ...@@ -431,7 +417,7 @@ brlvger_disconnect(struct usb_device *dev, void *ptr)
info("Display %d disconnecting", priv->subminor); info("Display %d disconnecting", priv->subminor);
devfs_unregister(priv->devfs); devfs_unregister(priv->devfs);
usb_deregister_dev(&brlvger_driver, 1, priv->subminor); usb_deregister_dev(1, priv->subminor);
down(&disconnect_sem); down(&disconnect_sem);
display_table[priv->subminor] = NULL; display_table[priv->subminor] = NULL;
......
...@@ -49,7 +49,11 @@ ...@@ -49,7 +49,11 @@
#define DRIVER_AUTHOR "Cesar Miquel <miquel@df.uba.ar>" #define DRIVER_AUTHOR "Cesar Miquel <miquel@df.uba.ar>"
#define DRIVER_DESC "USB Rio 500 driver" #define DRIVER_DESC "USB Rio 500 driver"
#define RIO_MINOR 64 #ifdef CONFIG_USB_DYNAMIC_MINORS
#define RIO_MINOR 0
#else
#define RIO_MINOR 64
#endif
/* stall/wait timeout for rio */ /* stall/wait timeout for rio */
#define NAK_TIMEOUT (HZ) #define NAK_TIMEOUT (HZ)
...@@ -65,6 +69,7 @@ struct rio_usb_data { ...@@ -65,6 +69,7 @@ struct rio_usb_data {
unsigned int ifnum; /* Interface number of the USB device */ unsigned int ifnum; /* Interface number of the USB device */
int isopen; /* nz if open */ int isopen; /* nz if open */
int present; /* Device is present on the bus */ int present; /* Device is present on the bus */
int minor; /* minor number assigned to us */
char *obuf, *ibuf; /* transfer buffers */ char *obuf, *ibuf; /* transfer buffers */
char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */ char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */
wait_queue_head_t wait_q; /* for timeouts */ wait_queue_head_t wait_q; /* for timeouts */
...@@ -449,9 +454,16 @@ static void *probe_rio(struct usb_device *dev, unsigned int ifnum, ...@@ -449,9 +454,16 @@ static void *probe_rio(struct usb_device *dev, unsigned int ifnum,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct rio_usb_data *rio = &rio_instance; struct rio_usb_data *rio = &rio_instance;
int retval;
info("USB Rio found at address %d", dev->devnum); info("USB Rio found at address %d", dev->devnum);
retval = usb_register_dev(&usb_rio_fops, RIO_MINOR, 1, &rio->minor);
if (retval) {
err("Not able to get a minor for this device.");
return NULL;
}
rio->present = 1; rio->present = 1;
rio->rio_dev = dev; rio->rio_dev = dev;
...@@ -486,6 +498,7 @@ static void disconnect_rio(struct usb_device *dev, void *ptr) ...@@ -486,6 +498,7 @@ static void disconnect_rio(struct usb_device *dev, void *ptr)
struct rio_usb_data *rio = (struct rio_usb_data *) ptr; struct rio_usb_data *rio = (struct rio_usb_data *) ptr;
devfs_unregister(rio->devfs); devfs_unregister(rio->devfs);
usb_deregister_dev(1, rio->minor);
down(&(rio->lock)); down(&(rio->lock));
if (rio->isopen) { if (rio->isopen) {
...@@ -515,9 +528,6 @@ static struct usb_driver rio_driver = { ...@@ -515,9 +528,6 @@ static struct usb_driver rio_driver = {
name: "rio500", name: "rio500",
probe: probe_rio, probe: probe_rio,
disconnect: disconnect_rio, disconnect: disconnect_rio,
fops: &usb_rio_fops,
minor: RIO_MINOR,
num_minors: 1,
id_table: rio_table, id_table: rio_table,
}; };
......
...@@ -189,9 +189,6 @@ static struct usb_driver skel_driver = { ...@@ -189,9 +189,6 @@ static struct usb_driver skel_driver = {
name: "skeleton", name: "skeleton",
probe: skel_probe, probe: skel_probe,
disconnect: skel_disconnect, disconnect: skel_disconnect,
fops: &skel_fops,
minor: USB_SKEL_MINOR_BASE,
num_minors: MAX_DEVICES,
id_table: skel_table, id_table: skel_table,
}; };
...@@ -532,29 +529,18 @@ static void * skel_probe(struct usb_device *udev, unsigned int ifnum, const stru ...@@ -532,29 +529,18 @@ static void * skel_probe(struct usb_device *udev, unsigned int ifnum, const stru
} }
down (&minor_table_mutex); down (&minor_table_mutex);
retval = usb_register_dev (&skel_driver, 1, &minor); retval = usb_register_dev (&skel_fops, USB_SKEL_MINOR_BASE, 1, &minor);
if (retval) { if (retval) {
if (retval != -ENODEV) {
/* something prevented us from registering this driver */ /* something prevented us from registering this driver */
err ("Not able to get a minor for this device."); err ("Not able to get a minor for this device.");
goto exit; goto exit;
} }
/* we could not get a dynamic minor, so lets find one of our own */
for (minor = 0; minor < MAX_DEVICES; ++minor) {
if (minor_table[minor] == NULL)
break;
}
if (minor >= MAX_DEVICES) {
err ("Too many devices plugged in, can not handle this device.");
goto exit;
}
}
/* allocate memory for our device state and intialize it */ /* allocate memory for our device state and intialize it */
dev = kmalloc (sizeof(struct usb_skel), GFP_KERNEL); dev = kmalloc (sizeof(struct usb_skel), GFP_KERNEL);
if (dev == NULL) { if (dev == NULL) {
err ("Out of memory"); err ("Out of memory");
goto exit; goto exit_minor;
} }
memset (dev, 0x00, sizeof (*dev)); memset (dev, 0x00, sizeof (*dev));
minor_table[minor] = dev; minor_table[minor] = dev;
...@@ -628,6 +614,9 @@ static void * skel_probe(struct usb_device *udev, unsigned int ifnum, const stru ...@@ -628,6 +614,9 @@ static void * skel_probe(struct usb_device *udev, unsigned int ifnum, const stru
skel_delete (dev); skel_delete (dev);
dev = NULL; dev = NULL;
exit_minor:
usb_deregister_dev (1, minor);
exit: exit:
up (&minor_table_mutex); up (&minor_table_mutex);
return dev; return dev;
...@@ -655,7 +644,7 @@ static void skel_disconnect(struct usb_device *udev, void *ptr) ...@@ -655,7 +644,7 @@ static void skel_disconnect(struct usb_device *udev, void *ptr)
devfs_unregister (dev->devfs); devfs_unregister (dev->devfs);
/* give back our dynamic minor */ /* give back our dynamic minor */
usb_deregister_dev (&skel_driver, 1, minor); usb_deregister_dev (1, minor);
/* if the device is not opened, then we clean up right now */ /* if the device is not opened, then we clean up right now */
if (!dev->open_count) { if (!dev->open_count) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment