提交 1b4997e6 编写于 作者: H H Hartley Sweeten 提交者: Greg Kroah-Hartman

staging: comedi: usbduxfast: tidy up firmwareUpload()

Rename the CamelCase function and just pass the const struct
firmware * directly instead of parsing out the data and size.

Rename the CamelCasae local val 'fwBuf'.

Use goto to provide a common exit path that frees the local
buffer for the firmware when an error is encountered.
Signed-off-by: NH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 060f2154
...@@ -1123,48 +1123,43 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev, ...@@ -1123,48 +1123,43 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
#define FIRMWARE_MAX_LEN 0x2000 #define FIRMWARE_MAX_LEN 0x2000
static int firmwareUpload(struct comedi_device *dev, static int usbduxfast_upload_firmware(struct comedi_device *dev,
const u8 *firmwareBinary, int sizeFirmware) const struct firmware *fw)
{ {
uint8_t *fwBuf; uint8_t *buf;
int ret; int ret;
if (!firmwareBinary) if (!fw->data)
return 0; return 0;
if (sizeFirmware > FIRMWARE_MAX_LEN) { if (fw->size > FIRMWARE_MAX_LEN) {
dev_err(dev->class_dev, "firmware binary too large for FX2\n"); dev_err(dev->class_dev, "firmware binary too large for FX2\n");
return -ENOMEM; return -ENOMEM;
} }
/* we generate a local buffer for the firmware */ /* we generate a local buffer for the firmware */
fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL); buf = kmemdup(fw->data, fw->size, GFP_KERNEL);
if (!fwBuf) { if (!buf)
dev_err(dev->class_dev, "mem alloc for firmware failed\n");
return -ENOMEM; return -ENOMEM;
}
ret = usbduxfastsub_stop(dev); ret = usbduxfastsub_stop(dev);
if (ret < 0) { if (ret < 0) {
dev_err(dev->class_dev, "can not stop firmware\n"); dev_err(dev->class_dev, "can not stop firmware\n");
kfree(fwBuf); goto done;
return ret;
} }
ret = usbduxfastsub_upload(dev, fwBuf, 0, sizeFirmware); ret = usbduxfastsub_upload(dev, buf, 0, fw->size);
if (ret < 0) { if (ret < 0) {
dev_err(dev->class_dev, "firmware upload failed\n"); dev_err(dev->class_dev, "firmware upload failed\n");
kfree(fwBuf); goto done;
return ret;
} }
ret = usbduxfastsub_start(dev); ret = usbduxfastsub_start(dev);
if (ret < 0) { if (ret < 0)
dev_err(dev->class_dev, "can not start firmware\n"); dev_err(dev->class_dev, "can not start firmware\n");
kfree(fwBuf);
return ret; done:
} kfree(buf);
kfree(fwBuf); return ret;
return 0;
} }
static int usbduxfast_attach_common(struct comedi_device *dev) static int usbduxfast_attach_common(struct comedi_device *dev)
...@@ -1211,7 +1206,7 @@ static int usbduxfast_request_firmware(struct comedi_device *dev) ...@@ -1211,7 +1206,7 @@ static int usbduxfast_request_firmware(struct comedi_device *dev)
if (ret) if (ret)
return ret; return ret;
ret = firmwareUpload(dev, fw->data, fw->size); ret = usbduxfast_upload_firmware(dev, fw);
release_firmware(fw); release_firmware(fw);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册