summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoj Babulal <manoj.babulal@broadcom.com>2018-06-19 10:00:40 -0700
committerMyles Watson <mylesgw@google.com>2018-09-27 22:02:08 +0000
commit3253d4bebfea64374bea2ca2eaeb62ed0f1dfe33 (patch)
treef7fbd12f7032f7908e399f3201b58b70f78f7a1c
parent72f0954f207fa8a6b8cfd42f5aeb98b52d8697d1 (diff)
downloadlibbt-3253d4bebfea64374bea2ca2eaeb62ed0f1dfe33.tar.gz
libbt: Add checks for fw file read errors
The fw file read may fail. This change adds checks to handle failure cases. Test: verified with fw file read fail case Bug: 110460199 Change-Id: If9ebd0db40d0d7f284dcca59b21433a36d1f1100
-rw-r--r--src/hardware.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/hardware.c b/src/hardware.c
index da9b918..701cb86 100644
--- a/src/hardware.c
+++ b/src/hardware.c
@@ -739,29 +739,39 @@ void hw_config_cback(void *p_mem)
hw_cfg_cb.state = HW_CFG_DL_FW_PATCH;
/* fall through intentionally */
case HW_CFG_DL_FW_PATCH:
- p_buf->len = read(hw_cfg_cb.fw_fd, p, HCI_CMD_PREAMBLE_SIZE);
- if (p_buf->len > 0)
+ if (hw_cfg_cb.fw_fd >= 0)
{
- if ((p_buf->len < HCI_CMD_PREAMBLE_SIZE) || \
- (opcode == HCI_VSC_LAUNCH_RAM))
+ int ret = read(hw_cfg_cb.fw_fd, p, HCI_CMD_PREAMBLE_SIZE);
+ if (ret > 0)
{
- ALOGW("firmware patch file might be altered!");
+ if ((ret < HCI_CMD_PREAMBLE_SIZE) || \
+ (opcode == HCI_VSC_LAUNCH_RAM))
+ {
+ ALOGW("firmware patch file might be altered!");
+ }
+ else
+ {
+ p_buf->len = ret;
+ ret = read(hw_cfg_cb.fw_fd, \
+ p+HCI_CMD_PREAMBLE_SIZE,\
+ *(p+HCD_REC_PAYLOAD_LEN_BYTE));
+ if (ret >= 0)
+ {
+ p_buf->len += ret;
+ STREAM_TO_UINT16(opcode,p);
+ is_proceeding = bt_vendor_cbacks->xmit_cb(opcode, \
+ p_buf, hw_config_cback);
+ break;
+ }
+ }
}
- else
+ if (ret < 0)
{
- p_buf->len += read(hw_cfg_cb.fw_fd, \
- p+HCI_CMD_PREAMBLE_SIZE,\
- *(p+HCD_REC_PAYLOAD_LEN_BYTE));
- STREAM_TO_UINT16(opcode,p);
- is_proceeding = bt_vendor_cbacks->xmit_cb(opcode, \
- p_buf, hw_config_cback);
- break;
+ ALOGE("firmware patch file read failed (%s)", strerror(errno));
}
+ close(hw_cfg_cb.fw_fd);
+ hw_cfg_cb.fw_fd = -1;
}
-
- close(hw_cfg_cb.fw_fd);
- hw_cfg_cb.fw_fd = -1;
-
/* Normally the firmware patch configuration file
* sets the new starting baud rate at 115200.
* So, we need update host's baud rate accordingly.