Commit 45933ab2 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

USB: convert the drivers/usb/image files to the new USB driver model.

parent 72df1a80
...@@ -30,13 +30,14 @@ struct list_head hpusbscsi_devices; ...@@ -30,13 +30,14 @@ struct list_head hpusbscsi_devices;
/* USB related parts */ /* USB related parts */
static void * static int
hpusbscsi_usb_probe (struct usb_device *dev, unsigned int interface, hpusbscsi_usb_probe (struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct hpusbscsi *new; struct hpusbscsi *new;
struct usb_device *dev = interface_to_usbdev (intf);
struct usb_interface_descriptor *altsetting = struct usb_interface_descriptor *altsetting =
&(dev->actconfig->interface[interface].altsetting[0]); &(intf->altsetting[0]);
int i, result; int i, result;
...@@ -44,7 +45,7 @@ hpusbscsi_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -44,7 +45,7 @@ hpusbscsi_usb_probe (struct usb_device *dev, unsigned int interface,
if (altsetting->bNumEndpoints != 3) { if (altsetting->bNumEndpoints != 3) {
printk (KERN_ERR "Wrong number of endpoints\n"); printk (KERN_ERR "Wrong number of endpoints\n");
return NULL; return -ENODEV;
} }
/* descriptor allocation */ /* descriptor allocation */
...@@ -53,19 +54,19 @@ hpusbscsi_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -53,19 +54,19 @@ hpusbscsi_usb_probe (struct usb_device *dev, unsigned int interface,
(struct hpusbscsi *) kmalloc (sizeof (struct hpusbscsi), (struct hpusbscsi *) kmalloc (sizeof (struct hpusbscsi),
GFP_KERNEL); GFP_KERNEL);
if (new == NULL) if (new == NULL)
return NULL; return -ENOMEM;
DEBUG ("Allocated memory\n"); DEBUG ("Allocated memory\n");
memset (new, 0, sizeof (struct hpusbscsi)); memset (new, 0, sizeof (struct hpusbscsi));
new->dataurb = usb_alloc_urb(0, GFP_KERNEL); new->dataurb = usb_alloc_urb(0, GFP_KERNEL);
if (!new->dataurb) { if (!new->dataurb) {
kfree (new); kfree (new);
return NULL; return -ENOMEM;
} }
new->controlurb = usb_alloc_urb(0, GFP_KERNEL); new->controlurb = usb_alloc_urb(0, GFP_KERNEL);
if (!new->controlurb) { if (!new->controlurb) {
usb_free_urb (new->dataurb); usb_free_urb (new->dataurb);
kfree (new); kfree (new);
return NULL; return -ENOMEM;
} }
new->dev = dev; new->dev = dev;
init_waitqueue_head (&new->pending); init_waitqueue_head (&new->pending);
...@@ -135,20 +136,24 @@ hpusbscsi_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -135,20 +136,24 @@ hpusbscsi_usb_probe (struct usb_device *dev, unsigned int interface,
/* adding to list for module unload */ /* adding to list for module unload */
list_add (&hpusbscsi_devices, &new->lh); list_add (&hpusbscsi_devices, &new->lh);
return new; dev_set_drvdata(&intf->dev, new);
return 0;
err_out: err_out:
usb_free_urb (new->controlurb); usb_free_urb (new->controlurb);
usb_free_urb (new->dataurb); usb_free_urb (new->dataurb);
kfree (new); kfree (new);
return NULL; return -ENODEV;
} }
static void static void
hpusbscsi_usb_disconnect (struct usb_device *dev, void *ptr) hpusbscsi_usb_disconnect (struct usb_interface *intf)
{ {
usb_unlink_urb((((struct hpusbscsi *) ptr)->controlurb)); struct hpusbscsi *desc = dev_get_drvdata(&intf->dev);
((struct hpusbscsi *) ptr)->dev = NULL;
dev_set_drvdata(&intf->dev, NULL);
if (desc)
usb_unlink_urb(desc->controlurb);
} }
static struct usb_device_id hpusbscsi_usb_ids[] = { static struct usb_device_id hpusbscsi_usb_ids[] = {
......
...@@ -406,11 +406,12 @@ static struct file_operations mdc800_device_ops; ...@@ -406,11 +406,12 @@ 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
*/ */
static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum, static int mdc800_usb_probe (struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
int i,j; int i,j;
struct usb_interface_descriptor *intf_desc; struct usb_interface_descriptor *intf_desc;
struct usb_device *dev = interface_to_usbdev (intf);
int irq_interval=0; int irq_interval=0;
int retval; int retval;
...@@ -420,15 +421,15 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum, ...@@ -420,15 +421,15 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum,
if (mdc800->dev != 0) if (mdc800->dev != 0)
{ {
warn ("only one Mustek MDC800 is supported."); warn ("only one Mustek MDC800 is supported.");
return 0; return -ENODEV;
} }
if (dev->descriptor.bNumConfigurations != 1) if (dev->descriptor.bNumConfigurations != 1)
{ {
err ("probe fails -> wrong Number of Configuration"); err ("probe fails -> wrong Number of Configuration");
return 0; return -ENODEV;
} }
intf_desc=&dev->actconfig->interface[ifnum].altsetting[0]; intf_desc = &intf->altsetting[0];
if ( if (
( intf_desc->bInterfaceClass != 0xff ) ( intf_desc->bInterfaceClass != 0xff )
...@@ -438,7 +439,7 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum, ...@@ -438,7 +439,7 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum,
) )
{ {
err ("probe fails -> wrong Interface"); err ("probe fails -> wrong Interface");
return 0; return -ENODEV;
} }
/* Check the Endpoints */ /* Check the Endpoints */
...@@ -461,16 +462,16 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum, ...@@ -461,16 +462,16 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum,
if (mdc800->endpoint[i] == -1) if (mdc800->endpoint[i] == -1)
{ {
err ("probe fails -> Wrong Endpoints."); err ("probe fails -> Wrong Endpoints.");
return 0; return -ENODEV;
} }
} }
usb_driver_claim_interface (&mdc800_usb_driver, &dev->actconfig->interface[ifnum], mdc800); usb_driver_claim_interface (&mdc800_usb_driver, intf, mdc800);
if (usb_set_interface (dev, ifnum, 0) < 0) if (usb_set_interface (dev, intf_desc->bInterfaceNumber, 0) < 0)
{ {
err ("MDC800 Configuration fails."); err ("MDC800 Configuration fails.");
return 0; return -ENODEV;
} }
info ("Found Mustek MDC800 on USB."); info ("Found Mustek MDC800 on USB.");
...@@ -480,7 +481,7 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum, ...@@ -480,7 +481,7 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum,
retval = usb_register_dev (&mdc800_device_ops, MDC800_DEVICE_MINOR_BASE, 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 -ENODEV;
} }
mdc800->dev=dev; mdc800->dev=dev;
...@@ -522,33 +523,37 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum, ...@@ -522,33 +523,37 @@ static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum,
up (&mdc800->io_lock); up (&mdc800->io_lock);
return mdc800; dev_set_drvdata(&intf->dev, mdc800);
return 0;
} }
/* /*
* Disconnect USB device (maybe the MDC800) * Disconnect USB device (maybe the MDC800)
*/ */
static void mdc800_usb_disconnect (struct usb_device *dev,void* ptr) static void mdc800_usb_disconnect (struct usb_interface *intf)
{ {
struct mdc800_data* mdc800=(struct mdc800_data*) ptr; struct mdc800_data* mdc800 = dev_get_drvdata(&intf->dev);
dbg ("(mdc800_usb_disconnect) called"); dbg ("(mdc800_usb_disconnect) called");
if (mdc800->state == NOT_CONNECTED) if (mdc800) {
return; if (mdc800->state == NOT_CONNECTED)
return;
usb_deregister_dev (1, mdc800->minor);
mdc800->state=NOT_CONNECTED; usb_deregister_dev (1, mdc800->minor);
usb_unlink_urb (mdc800->irq_urb); mdc800->state=NOT_CONNECTED;
usb_unlink_urb (mdc800->write_urb);
usb_unlink_urb (mdc800->download_urb);
usb_driver_release_interface (&mdc800_usb_driver, &dev->actconfig->interface[1]); usb_unlink_urb (mdc800->irq_urb);
usb_unlink_urb (mdc800->write_urb);
usb_unlink_urb (mdc800->download_urb);
mdc800->dev=0; usb_driver_release_interface (&mdc800_usb_driver, intf);
mdc800->dev=0;
dev_set_drvdata(&intf->dev, NULL);
}
info ("Mustek MDC800 disconnected from USB."); info ("Mustek MDC800 disconnected from USB.");
} }
......
...@@ -154,9 +154,9 @@ ...@@ -154,9 +154,9 @@
/* USB layer driver interface */ /* USB layer driver interface */
static void *mts_usb_probe(struct usb_device *dev, unsigned int interface, static int mts_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id); const struct usb_device_id *id);
static void mts_usb_disconnect(struct usb_device *dev, void *ptr); static void mts_usb_disconnect(struct usb_interface *intf);
static struct usb_device_id mts_usb_ids []; static struct usb_device_id mts_usb_ids [];
...@@ -773,18 +773,21 @@ static Scsi_Host_Template mts_scsi_host_template = { ...@@ -773,18 +773,21 @@ static Scsi_Host_Template mts_scsi_host_template = {
/* USB layer driver interface implementation */ /* USB layer driver interface implementation */
static void mts_usb_disconnect (struct usb_device *dev, void *ptr) static void mts_usb_disconnect (struct usb_interface *intf)
{ {
struct mts_desc* to_remove = (struct mts_desc*)ptr; struct mts_desc* to_remove = dev_get_drvdata(&intf->dev);
MTS_DEBUG_GOT_HERE(); MTS_DEBUG_GOT_HERE();
/* leave the list - lock it */ dev_set_drvdata(&intf->dev, NULL);
down(&mts_list_semaphore); if (to_remove) {
/* leave the list - lock it */
down(&mts_list_semaphore);
mts_remove_nolock(to_remove); mts_remove_nolock(to_remove);
up(&mts_list_semaphore); up(&mts_list_semaphore);
}
} }
struct vendor_product struct vendor_product
...@@ -834,8 +837,8 @@ static struct usb_device_id mts_usb_ids [] = ...@@ -834,8 +837,8 @@ static struct usb_device_id mts_usb_ids [] =
MODULE_DEVICE_TABLE (usb, mts_usb_ids); MODULE_DEVICE_TABLE (usb, mts_usb_ids);
static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, static int mts_usb_probe (struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
int i; int i;
int result; int result;
...@@ -846,6 +849,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -846,6 +849,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface,
struct mts_desc * new_desc; struct mts_desc * new_desc;
struct vendor_product const* p; struct vendor_product const* p;
struct usb_device *dev = interface_to_usbdev (intf);
/* the altsettting 0 on the interface we're probing */ /* the altsettting 0 on the interface we're probing */
struct usb_interface_descriptor *altsetting; struct usb_interface_descriptor *altsetting;
...@@ -869,8 +873,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -869,8 +873,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface,
p->name ); p->name );
/* the altsettting 0 on the interface we're probing */ /* the altsettting 0 on the interface we're probing */
altsetting = altsetting = &(intf->altsetting[0]);
&(dev->actconfig->interface[interface].altsetting[0]);
/* Check if the config is sane */ /* Check if the config is sane */
...@@ -878,7 +881,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -878,7 +881,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface,
if ( altsetting->bNumEndpoints != MTS_EP_TOTAL ) { if ( altsetting->bNumEndpoints != MTS_EP_TOTAL ) {
MTS_WARNING( "expecting %d got %d endpoints! Bailing out.\n", MTS_WARNING( "expecting %d got %d endpoints! Bailing out.\n",
(int)MTS_EP_TOTAL, (int)altsetting->bNumEndpoints ); (int)MTS_EP_TOTAL, (int)altsetting->bNumEndpoints );
return NULL; return -ENODEV;
} }
for( i = 0; i < altsetting->bNumEndpoints; i++ ) { for( i = 0; i < altsetting->bNumEndpoints; i++ ) {
...@@ -896,7 +899,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -896,7 +899,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface,
else { else {
if ( ep_out != -1 ) { if ( ep_out != -1 ) {
MTS_WARNING( "can only deal with one output endpoints. Bailing out." ); MTS_WARNING( "can only deal with one output endpoints. Bailing out." );
return NULL; return -ENODEV;
} }
ep_out = altsetting->endpoint[i].bEndpointAddress & ep_out = altsetting->endpoint[i].bEndpointAddress &
...@@ -909,7 +912,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -909,7 +912,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface,
if ( ep_out == -1 ) { if ( ep_out == -1 ) {
MTS_WARNING( "couldn't find an output bulk endpoint. Bailing out.\n" ); MTS_WARNING( "couldn't find an output bulk endpoint. Bailing out.\n" );
return NULL; return -ENODEV;
} }
...@@ -932,7 +935,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -932,7 +935,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface,
default: default:
MTS_DEBUG( "unknown error %d from usb_set_interface\n", MTS_DEBUG( "unknown error %d from usb_set_interface\n",
(int)result ); (int)result );
return NULL; return -ENODEV;
} }
...@@ -941,19 +944,18 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -941,19 +944,18 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface,
if (new_desc == NULL) if (new_desc == NULL)
{ {
MTS_ERROR("couldn't allocate scanner desc, bailing out!\n"); MTS_ERROR("couldn't allocate scanner desc, bailing out!\n");
return NULL; return -ENOMEM;
} }
memset( new_desc, 0, sizeof(*new_desc) ); memset( new_desc, 0, sizeof(*new_desc) );
new_desc->urb = usb_alloc_urb(0, GFP_KERNEL); new_desc->urb = usb_alloc_urb(0, GFP_KERNEL);
if (!new_desc->urb) { if (!new_desc->urb) {
kfree(new_desc); kfree(new_desc);
return NULL; return -ENOMEM;
} }
/* initialising that descriptor */ /* initialising that descriptor */
new_desc->usb_dev = dev; new_desc->usb_dev = dev;
new_desc->interface = interface;
init_MUTEX(&new_desc->lock); init_MUTEX(&new_desc->lock);
...@@ -1000,7 +1002,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -1000,7 +1002,7 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface,
/* FIXME: need more cleanup? */ /* FIXME: need more cleanup? */
kfree( new_desc ); kfree( new_desc );
return NULL; return -ENOMEM;
} }
MTS_DEBUG_GOT_HERE(); MTS_DEBUG_GOT_HERE();
...@@ -1015,7 +1017,8 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface, ...@@ -1015,7 +1017,8 @@ static void * mts_usb_probe (struct usb_device *dev, unsigned int interface,
MTS_DEBUG("completed probe and exiting happily\n"); MTS_DEBUG("completed probe and exiting happily\n");
return (void *)new_desc; dev_set_drvdata(&intf->dev, new_desc);
return 0;
} }
......
...@@ -33,8 +33,6 @@ struct mts_desc { ...@@ -33,8 +33,6 @@ struct mts_desc {
struct usb_device *usb_dev; struct usb_device *usb_dev;
int interface;
/* Endpoint addresses */ /* Endpoint addresses */
u8 ep_out; u8 ep_out;
u8 ep_response; u8 ep_response;
......
...@@ -818,10 +818,11 @@ file_operations usb_scanner_fops = { ...@@ -818,10 +818,11 @@ file_operations usb_scanner_fops = {
.release = close_scanner, .release = close_scanner,
}; };
static void * static int
probe_scanner(struct usb_device *dev, unsigned int ifnum, probe_scanner(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct usb_device *dev = interface_to_usbdev (intf);
struct scn_usb_data *scn; struct scn_usb_data *scn;
struct usb_interface_descriptor *interface; struct usb_interface_descriptor *interface;
struct usb_endpoint_descriptor *endpoint; struct usb_endpoint_descriptor *endpoint;
...@@ -876,8 +877,8 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -876,8 +877,8 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
valid_device = 1; valid_device = 1;
} }
if (!valid_device) if (!valid_device)
return NULL; /* We didn't find anything pleasing */ return -ENODEV; /* We didn't find anything pleasing */
/* /*
* After this point we can be a little noisy about what we are trying to * After this point we can be a little noisy about what we are trying to
...@@ -886,16 +887,16 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -886,16 +887,16 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
if (dev->descriptor.bNumConfigurations != 1) { if (dev->descriptor.bNumConfigurations != 1) {
info("probe_scanner: Only one device configuration is supported."); info("probe_scanner: Only one device configuration is supported.");
return NULL; return -ENODEV;
} }
if (dev->config[0].bNumInterfaces != 1) { if (dev->config[0].bNumInterfaces != 1) {
info("probe_scanner: Only one device interface is supported."); info("probe_scanner: Only one device interface is supported.");
return NULL; return -ENODEV;
} }
interface = dev->config[0].interface[ifnum].altsetting; interface = intf->altsetting;
endpoint = interface[ifnum].endpoint; endpoint = interface->endpoint;
/* /*
* Start checking for two bulk endpoints OR two bulk endpoints *and* one * Start checking for two bulk endpoints OR two bulk endpoints *and* one
...@@ -907,7 +908,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -907,7 +908,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
if ((interface->bNumEndpoints != 2) && (interface->bNumEndpoints != 3)) { if ((interface->bNumEndpoints != 2) && (interface->bNumEndpoints != 3)) {
info("probe_scanner: Only two or three endpoints supported."); info("probe_scanner: Only two or three endpoints supported.");
return NULL; return -ENODEV;
} }
ep_cnt = have_bulk_in = have_bulk_out = have_intr = 0; ep_cnt = have_bulk_in = have_bulk_out = have_intr = 0;
...@@ -935,7 +936,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -935,7 +936,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
continue; continue;
} }
info("probe_scanner: Undetected endpoint -- consult Documentation/usb/scanner.txt."); info("probe_scanner: Undetected endpoint -- consult Documentation/usb/scanner.txt.");
return NULL; /* Shouldn't ever get here unless we have something weird */ return -EIO; /* Shouldn't ever get here unless we have something weird */
} }
...@@ -948,18 +949,18 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -948,18 +949,18 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
case 2: case 2:
if (!have_bulk_in || !have_bulk_out) { if (!have_bulk_in || !have_bulk_out) {
info("probe_scanner: Two bulk endpoints required."); info("probe_scanner: Two bulk endpoints required.");
return NULL; return -EIO;
} }
break; break;
case 3: case 3:
if (!have_bulk_in || !have_bulk_out || !have_intr) { if (!have_bulk_in || !have_bulk_out || !have_intr) {
info("probe_scanner: Two bulk endpoints and one interrupt endpoint required."); info("probe_scanner: Two bulk endpoints and one interrupt endpoint required.");
return NULL; return -EIO;
} }
break; break;
default: default:
info("probe_scanner: Endpoint determination failed -- consult Documentation/usb/scanner.txt"); info("probe_scanner: Endpoint determination failed -- consult Documentation/usb/scanner.txt");
return NULL; return -EIO;
} }
...@@ -975,14 +976,14 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -975,14 +976,14 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
if (retval) { if (retval) {
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 -ENOMEM;
} }
/* 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]) {
err("probe_scanner: No more minor devices remaining."); err("probe_scanner: No more minor devices remaining.");
up(&scn_mutex); up(&scn_mutex);
return NULL; return -ENOMEM;
} }
dbg("probe_scanner: Allocated minor:%d", scn_minor); dbg("probe_scanner: Allocated minor:%d", scn_minor);
...@@ -990,7 +991,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -990,7 +991,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
if (!(scn = kmalloc (sizeof (struct scn_usb_data), GFP_KERNEL))) { if (!(scn = kmalloc (sizeof (struct scn_usb_data), GFP_KERNEL))) {
err("probe_scanner: Out of memory."); err("probe_scanner: Out of memory.");
up(&scn_mutex); up(&scn_mutex);
return NULL; return -ENOMEM;
} }
memset (scn, 0, sizeof(struct scn_usb_data)); memset (scn, 0, sizeof(struct scn_usb_data));
...@@ -998,7 +999,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -998,7 +999,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
if (!scn->scn_irq) { if (!scn->scn_irq) {
kfree(scn); kfree(scn);
up(&scn_mutex); up(&scn_mutex);
return NULL; return -ENOMEM;
} }
init_MUTEX(&(scn->sem)); /* Initializes to unlocked */ init_MUTEX(&(scn->sem)); /* Initializes to unlocked */
...@@ -1018,7 +1019,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -1018,7 +1019,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
err("probe_scanner(%d): Unable to allocate INT URB.", scn_minor); err("probe_scanner(%d): Unable to allocate INT URB.", scn_minor);
kfree(scn); kfree(scn);
up(&scn_mutex); up(&scn_mutex);
return NULL; return -ENOMEM;
} }
} }
...@@ -1028,7 +1029,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -1028,7 +1029,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
err("probe_scanner(%d): Not enough memory for the output buffer.", scn_minor); err("probe_scanner(%d): Not enough memory for the output buffer.", scn_minor);
kfree(scn); kfree(scn);
up(&scn_mutex); up(&scn_mutex);
return NULL; return -ENOMEM;
} }
dbg("probe_scanner(%d): obuf address:%p", scn_minor, scn->obuf); dbg("probe_scanner(%d): obuf address:%p", scn_minor, scn->obuf);
...@@ -1037,7 +1038,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -1037,7 +1038,7 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
kfree(scn->obuf); kfree(scn->obuf);
kfree(scn); kfree(scn);
up(&scn_mutex); up(&scn_mutex);
return NULL; return -ENOMEM;
} }
dbg("probe_scanner(%d): ibuf address:%p", scn_minor, scn->ibuf); dbg("probe_scanner(%d): ibuf address:%p", scn_minor, scn->ibuf);
...@@ -1083,45 +1084,54 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum, ...@@ -1083,45 +1084,54 @@ probe_scanner(struct usb_device *dev, unsigned int ifnum,
up(&scn_mutex); up(&scn_mutex);
return scn; dev_set_drvdata(&intf->dev, scn);
return 0;
} }
static void static void
disconnect_scanner(struct usb_device *dev, void *ptr) disconnect_scanner(struct usb_interface *intf)
{ {
struct scn_usb_data *scn = (struct scn_usb_data *) ptr; struct scn_usb_data *scn = dev_get_drvdata(&intf->dev);
down (&scn_mutex); dev_set_drvdata(&intf->dev, NULL);
down (&(scn->sem)); if (scn) {
down (&scn_mutex);
down (&(scn->sem));
if(scn->intr_ep) { if(scn->intr_ep) {
dbg("disconnect_scanner(%d): Unlinking IRQ URB", scn->scn_minor); dbg("disconnect_scanner(%d): Unlinking IRQ URB", scn->scn_minor);
usb_unlink_urb(scn->scn_irq); usb_unlink_urb(scn->scn_irq);
}
usb_driver_release_interface(&scanner_driver,
&scn->scn_dev->actconfig->interface[scn->ifnum]);
kfree(scn->ibuf);
kfree(scn->obuf);
dbg("disconnect_scanner: De-allocating minor:%d", scn->scn_minor);
devfs_unregister(scn->devfs);
usb_deregister_dev(1, scn->scn_minor);
p_scn_table[scn->scn_minor] = NULL;
usb_free_urb(scn->scn_irq);
up (&(scn->sem));
kfree (scn);
up (&scn_mutex);
} }
usb_driver_release_interface(&scanner_driver,
&scn->scn_dev->actconfig->interface[scn->ifnum]);
kfree(scn->ibuf);
kfree(scn->obuf);
dbg("disconnect_scanner: De-allocating minor:%d", scn->scn_minor);
devfs_unregister(scn->devfs);
usb_deregister_dev(1, scn->scn_minor);
p_scn_table[scn->scn_minor] = NULL;
usb_free_urb(scn->scn_irq);
up (&(scn->sem));
kfree (scn);
up (&scn_mutex);
} }
/* we want to look at all devices, as the vendor/product id can change
* depending on the command line argument */
static struct usb_device_id ids[] = {
{.driver_info = 42},
{}
};
static struct static struct
usb_driver scanner_driver = { usb_driver scanner_driver = {
.name = "usbscanner", .name = "usbscanner",
.probe = probe_scanner, .probe = probe_scanner,
.disconnect = disconnect_scanner, .disconnect = disconnect_scanner,
.id_table = NULL, /* This would be scanner_device_ids, but we .id_table = ids,
need to check every USB device, in case
we match a user defined vendor/product ID. */
}; };
void __exit void __exit
......
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