NFC: Fix static code analysis issue

Static code analysis issue observed due to possible
usage of variable without being initialised.

Initialize variable to a generic error code and
move the conditional check to the payload read logic
to align with the read operation return value check and
fix the possible staitic code analysis issue.

Change-Id: I43de34223984255dcbcc9a36722f611b3a1359b6
Signed-off-by: Bhuvan Varshney <bvarshne@codeaurora.org>
This commit is contained in:
Bhuvan Varshney 2021-08-31 13:15:07 +05:30
parent 2fcd1327d0
commit 7900e3d63b

View File

@ -49,7 +49,7 @@ static int send_ese_cmd(struct nfc_dev *nfc_dev)
*/
int read_cold_reset_rsp(struct nfc_dev *nfc_dev, char *header)
{
int ret;
int ret = -EPERM;
struct cold_reset *cold_rst = &nfc_dev->cold_reset;
char *rsp_buf = NULL;
@ -84,9 +84,9 @@ int read_cold_reset_rsp(struct nfc_dev *nfc_dev, char *header)
ret = -EINVAL;
goto error;
}
} else if (header)
} else if (header) {
memcpy(rsp_buf, header, NCI_HDR_LEN);
else {
} else {
dev_err(nfc_dev->nfc_device,
"%s: - invalid or NULL header\n", __func__);
ret = -EINVAL;
@ -101,24 +101,25 @@ int read_cold_reset_rsp(struct nfc_dev *nfc_dev, char *header)
goto error;
}
if (nfc_dev->interface == PLATFORM_IF_I2C)
if (nfc_dev->interface == PLATFORM_IF_I2C) {
ret = nfc_dev->nfc_read(nfc_dev,
&rsp_buf[NCI_PAYLOAD_IDX],
rsp_buf[NCI_PAYLOAD_LEN_IDX],
NCI_CMD_RSP_TIMEOUT);
if (ret <= 0) {
dev_err(nfc_dev->nfc_device,
"%s: failure to read cold reset rsp payload\n",
if (ret <= 0) {
dev_err(nfc_dev->nfc_device,
"%s: failure to read cold reset rsp payload\n",
__func__);
ret = -EIO;
goto error;
ret = -EIO;
goto error;
}
ret = cold_rst->status = rsp_buf[NCI_PAYLOAD_IDX];
pr_debug("nfc ese rsp hdr 0x%x 0x%x 0x%x, payload byte0 0x%x\n",
rsp_buf[0], rsp_buf[1], rsp_buf[2], rsp_buf[3]);
}
ret = cold_rst->status = rsp_buf[NCI_PAYLOAD_IDX];
pr_debug("nfc ese rsp hdr 0x%x 0x%x 0x%x, payload byte0 0x%x\n",
rsp_buf[0], rsp_buf[1], rsp_buf[2], rsp_buf[3]);
error:
kfree(rsp_buf);