From 38bf7ba8a7e866350ac24f508f6b3a9685631dcb Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 14 May 2013 13:30:52 -0700 Subject: [PATCH] staging: comedi: usbduxfast: absorb tidy_up() into the (*detach) Now that the usb (*probe) is handled in the comedi_driver (*auto_attach) the comedi_driver (*detach) will be called automatically if the attach fails. The tidy_up() calls in the (*auto_attach) are not needed. Remove them and absorb the code in tidy_up() into the (*detach). Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/usbduxfast.c | 83 +++++++++------------ 1 file changed, 35 insertions(+), 48 deletions(-) diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c index 31993e02e5d9..a0a268b3715e 100644 --- a/drivers/staging/comedi/drivers/usbduxfast.c +++ b/drivers/staging/comedi/drivers/usbduxfast.c @@ -1239,37 +1239,6 @@ static int firmwareUpload(struct usbduxfast_private *devpriv, return 0; } -static void tidy_up(struct usbduxfast_private *devpriv) -{ - if (!devpriv) - return; - - /* shows the usb subsystem that the driver is down */ - if (devpriv->intf) - usb_set_intfdata(devpriv->intf, NULL); - - devpriv->probed = 0; - - if (devpriv->urbIn) { - /* waits until a running transfer is over */ - usb_kill_urb(devpriv->urbIn); - - kfree(devpriv->transfer_buffer); - devpriv->transfer_buffer = NULL; - - usb_free_urb(devpriv->urbIn); - devpriv->urbIn = NULL; - } - - kfree(devpriv->insnBuffer); - devpriv->insnBuffer = NULL; - - kfree(devpriv->dux_commands); - devpriv->dux_commands = NULL; - - devpriv->ai_cmd_running = 0; -} - static int usbduxfast_attach_common(struct comedi_device *dev) { struct usbduxfast_private *devpriv = dev->private; @@ -1349,37 +1318,29 @@ static int usbduxfast_auto_attach(struct comedi_device *dev, usb_set_intfdata(intf, devpriv); devpriv->dux_commands = kmalloc(SIZEOFDUXBUFFER, GFP_KERNEL); - if (!devpriv->dux_commands) { - tidy_up(devpriv); + if (!devpriv->dux_commands) return -ENOMEM; - } devpriv->insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL); - if (!devpriv->insnBuffer) { - tidy_up(devpriv); + if (!devpriv->insnBuffer) return -ENOMEM; - } ret = usb_set_interface(devpriv->usb, devpriv->ifnum, 1); if (ret < 0) { dev_err(&intf->dev, "could not switch to alternate setting 1\n"); - tidy_up(devpriv); return -ENODEV; } devpriv->urbIn = usb_alloc_urb(0, GFP_KERNEL); if (!devpriv->urbIn) { dev_err(&intf->dev, "Could not alloc. urb\n"); - tidy_up(devpriv); return -ENOMEM; } devpriv->transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL); - if (!devpriv->transfer_buffer) { - tidy_up(devpriv); + if (!devpriv->transfer_buffer) return -ENOMEM; - } devpriv->probed = 1; @@ -1400,13 +1361,39 @@ static void usbduxfast_detach(struct comedi_device *dev) { struct usbduxfast_private *devpriv = dev->private; - if (devpriv) { - down(&devpriv->sem); - devpriv->attached = 0; - devpriv->comedidev = NULL; - tidy_up(devpriv); - up(&devpriv->sem); + if (!devpriv) + return; + + down(&devpriv->sem); + + devpriv->attached = 0; + devpriv->comedidev = NULL; + + if (devpriv->intf) + usb_set_intfdata(devpriv->intf, NULL); + + devpriv->probed = 0; + + if (devpriv->urbIn) { + /* waits until a running transfer is over */ + usb_kill_urb(devpriv->urbIn); + + kfree(devpriv->transfer_buffer); + devpriv->transfer_buffer = NULL; + + usb_free_urb(devpriv->urbIn); + devpriv->urbIn = NULL; } + + kfree(devpriv->insnBuffer); + devpriv->insnBuffer = NULL; + + kfree(devpriv->dux_commands); + devpriv->dux_commands = NULL; + + devpriv->ai_cmd_running = 0; + + up(&devpriv->sem); } static struct comedi_driver usbduxfast_driver = { -- 2.39.5