staging: comedi: usbduxfast: use comedi_load_firmware()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 20 May 2013 21:28:29 +0000 (14:28 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 21 May 2013 17:59:11 +0000 (10:59 -0700)
Use comedi_load_firmware() instead of duplicating the code in a
private function.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/usbduxfast.c

index f4546b3c4d6d426faf699e6ffe3692cb2fe7c1b3..27898c44e543f97ee200e89573b7a64089b9a014 100644 (file)
@@ -36,7 +36,6 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/kernel.h>
-#include <linux/firmware.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
@@ -978,23 +977,24 @@ static int usbduxfast_attach_common(struct comedi_device *dev)
 }
 
 static int usbduxfast_upload_firmware(struct comedi_device *dev,
-                                     const struct firmware *fw)
+                                     const u8 *data, size_t size,
+                                     unsigned long context)
 {
        struct usb_device *usb = comedi_to_usb_dev(dev);
        uint8_t *buf;
        unsigned char *tmp;
        int ret;
 
-       if (!fw->data)
+       if (!data)
                return 0;
 
-       if (fw->size > FIRMWARE_MAX_LEN) {
+       if (size > FIRMWARE_MAX_LEN) {
                dev_err(dev->class_dev, "firmware binary too large for FX2\n");
                return -ENOMEM;
        }
 
        /* we generate a local buffer for the firmware */
-       buf = kmemdup(fw->data, fw->size, GFP_KERNEL);
+       buf = kmemdup(data, size, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
 
@@ -1023,7 +1023,7 @@ static int usbduxfast_upload_firmware(struct comedi_device *dev,
                              USBDUXFASTSUB_FIRMWARE,
                              VENDOR_DIR_OUT,
                              0, 0x0000,
-                             buf, fw->size,
+                             buf, size,
                              EZTIMEOUT);
        if (ret < 0) {
                dev_err(dev->class_dev, "firmware upload failed\n");
@@ -1047,22 +1047,6 @@ done:
        return ret;
 }
 
-static int usbduxfast_request_firmware(struct comedi_device *dev)
-{
-       struct usb_device *usb = comedi_to_usb_dev(dev);
-       const struct firmware *fw;
-       int ret;
-
-       ret = request_firmware(&fw, FIRMWARE, &usb->dev);
-       if (ret)
-               return ret;
-
-       ret = usbduxfast_upload_firmware(dev, fw);
-       release_firmware(fw);
-
-       return ret;
-}
-
 static int usbduxfast_auto_attach(struct comedi_device *dev,
                                  unsigned long context_unused)
 {
@@ -1107,16 +1091,10 @@ static int usbduxfast_auto_attach(struct comedi_device *dev,
        if (!devpriv->inbuf)
                return -ENOMEM;
 
-       /*
-        * Request, and upload, the firmware so we can
-        * complete the comedi_driver (*auto_attach).
-        */
-       ret = usbduxfast_request_firmware(dev);
-       if (ret) {
-               dev_err(dev->class_dev, "could not load firmware (err=%d)\n",
-                       ret);
+       ret = comedi_load_firmware(dev, &usb->dev, FIRMWARE,
+                                  usbduxfast_upload_firmware, 0);
+       if (ret)
                return ret;
-       }
 
        return usbduxfast_attach_common(dev);
 }