Commit cc81234a authored by Quentin Deslandes's avatar Quentin Deslandes Committed by Greg Kroah-Hartman

staging: vt6656: clean error path for firmware management

Avoid discarding return value of functions called during firmware
management process. Handle such return value and return 0 on success or
a negative errno value on error.
Signed-off-by: default avatarQuentin Deslandes <quentin.deslandes@itdev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7156f7d9
...@@ -30,98 +30,87 @@ int vnt_download_firmware(struct vnt_private *priv) ...@@ -30,98 +30,87 @@ int vnt_download_firmware(struct vnt_private *priv)
{ {
struct device *dev = &priv->usb->dev; struct device *dev = &priv->usb->dev;
const struct firmware *fw; const struct firmware *fw;
int status;
void *buffer = NULL; void *buffer = NULL;
bool result = false;
u16 length; u16 length;
int ii, rc; int ii;
int ret = 0;
dev_dbg(dev, "---->Download firmware\n"); dev_dbg(dev, "---->Download firmware\n");
rc = request_firmware(&fw, FIRMWARE_NAME, dev); ret = request_firmware(&fw, FIRMWARE_NAME, dev);
if (rc) { if (ret) {
dev_err(dev, "firmware file %s request failed (%d)\n", dev_err(dev, "firmware file %s request failed (%d)\n",
FIRMWARE_NAME, rc); FIRMWARE_NAME, ret);
goto out; goto end;
} }
buffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL); buffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
if (!buffer) if (!buffer) {
ret = -ENOMEM;
goto free_fw; goto free_fw;
}
for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) { for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE); length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
memcpy(buffer, fw->data + ii, length); memcpy(buffer, fw->data + ii, length);
status = vnt_control_out(priv, ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
0, buffer);
0x1200 + ii, if (ret)
0x0000, goto free_buffer;
length,
buffer);
dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size); dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
if (status != STATUS_SUCCESS)
goto free_fw;
} }
result = true; free_buffer:
kfree(buffer);
free_fw: free_fw:
release_firmware(fw); release_firmware(fw);
end:
out: return ret;
kfree(buffer);
return result;
} }
MODULE_FIRMWARE(FIRMWARE_NAME); MODULE_FIRMWARE(FIRMWARE_NAME);
int vnt_firmware_branch_to_sram(struct vnt_private *priv) int vnt_firmware_branch_to_sram(struct vnt_private *priv)
{ {
int status;
dev_dbg(&priv->usb->dev, "---->Branch to Sram\n"); dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
status = vnt_control_out(priv, return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
1,
0x1200,
0x0000,
0,
NULL);
return status == STATUS_SUCCESS;
} }
int vnt_check_firmware_version(struct vnt_private *priv) int vnt_check_firmware_version(struct vnt_private *priv)
{ {
int status; int ret = 0;
status = vnt_control_in(priv, ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
MESSAGE_TYPE_READ, MESSAGE_REQUEST_VERSION, 2,
0, (u8 *)&priv->firmware_version);
MESSAGE_REQUEST_VERSION, if (ret) {
2, dev_dbg(&priv->usb->dev,
(u8 *)&priv->firmware_version); "Could not get firmware version: %d.\n", ret);
goto end;
}
dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n", dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
priv->firmware_version); priv->firmware_version);
if (status != STATUS_SUCCESS) {
dev_dbg(&priv->usb->dev, "Firmware Invalid.\n");
return false;
}
if (priv->firmware_version == 0xFFFF) { if (priv->firmware_version == 0xFFFF) {
dev_dbg(&priv->usb->dev, "In Loader.\n"); dev_dbg(&priv->usb->dev, "In Loader.\n");
return false; ret = -EINVAL;
goto end;
} }
dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
priv->firmware_version);
if (priv->firmware_version < FIRMWARE_VERSION) { if (priv->firmware_version < FIRMWARE_VERSION) {
/* branch to loader for download new firmware */ /* branch to loader for download new firmware */
vnt_firmware_branch_to_sram(priv); ret = vnt_firmware_branch_to_sram(priv);
return false; if (ret) {
dev_dbg(&priv->usb->dev,
"Could not branch to SRAM: %d.\n", ret);
} else {
ret = -EINVAL;
}
} }
return true;
end:
return ret;
} }
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