NFC: digital: Rearrange NFC-DEP DEP_REQ/DEP_RES Code

Rearrange some of the code in digital_in_recv_dep_res()
and digital_tg_recv_dep_req() so the initial code looks
similar.  The real reason is prepare the code for some
upcoming patches that require these changes.

Reviewed-by: Thierry Escande <thierry.escande@linux.intel.com>
Tested-by: Thierry Escande <thierry.escande@linux.intel.com>
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Mark A. Greer 2014-09-23 16:38:03 -07:00 committed by Samuel Ortiz
parent b15829ba5e
commit 6ce306682f

View file

@ -400,10 +400,10 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
goto exit; goto exit;
} }
size = sizeof(struct digital_dep_req_res);
dep_res = (struct digital_dep_req_res *)resp->data; dep_res = (struct digital_dep_req_res *)resp->data;
if (resp->len < sizeof(struct digital_dep_req_res) || if (resp->len < size || dep_res->dir != DIGITAL_NFC_DEP_FRAME_DIR_IN ||
dep_res->dir != DIGITAL_NFC_DEP_FRAME_DIR_IN ||
dep_res->cmd != DIGITAL_CMD_DEP_RES) { dep_res->cmd != DIGITAL_CMD_DEP_RES) {
rc = -EIO; rc = -EIO;
goto error; goto error;
@ -411,6 +411,16 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
pfb = dep_res->pfb; pfb = dep_res->pfb;
if (DIGITAL_NFC_DEP_DID_BIT_SET(pfb))
size++;
if (size > resp->len) {
rc = -EIO;
goto error;
}
skb_pull(resp, size);
switch (DIGITAL_NFC_DEP_PFB_TYPE(pfb)) { switch (DIGITAL_NFC_DEP_PFB_TYPE(pfb)) {
case DIGITAL_NFC_DEP_PFB_I_PDU: case DIGITAL_NFC_DEP_PFB_I_PDU:
if (DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni) { if (DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni) {
@ -435,7 +445,7 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
goto error; goto error;
} }
rc = digital_in_send_rtox(ddev, data_exch, resp->data[3]); rc = digital_in_send_rtox(ddev, data_exch, resp->data[0]);
if (rc) if (rc)
goto error; goto error;
@ -449,18 +459,6 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
goto error; goto error;
} }
size = sizeof(struct digital_dep_req_res);
if (DIGITAL_NFC_DEP_DID_BIT_SET(pfb))
size++;
if (size > resp->len) {
rc = -EIO;
goto error;
}
skb_pull(resp, size);
exit: exit:
data_exch->cb(data_exch->cb_context, resp, rc); data_exch->cb(data_exch->cb_context, resp, rc);
@ -524,6 +522,7 @@ static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg,
{ {
int rc; int rc;
struct digital_dep_req_res *dep_req; struct digital_dep_req_res *dep_req;
u8 pfb;
size_t size; size_t size;
if (IS_ERR(resp)) { if (IS_ERR(resp)) {
@ -553,18 +552,22 @@ static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg,
goto exit; goto exit;
} }
if (DIGITAL_NFC_DEP_DID_BIT_SET(dep_req->pfb)) pfb = dep_req->pfb;
if (DIGITAL_NFC_DEP_DID_BIT_SET(pfb))
size++; size++;
if (resp->len < size) { if (size > resp->len) {
rc = -EIO; rc = -EIO;
goto exit; goto exit;
} }
switch (DIGITAL_NFC_DEP_PFB_TYPE(dep_req->pfb)) { skb_pull(resp, size);
switch (DIGITAL_NFC_DEP_PFB_TYPE(pfb)) {
case DIGITAL_NFC_DEP_PFB_I_PDU: case DIGITAL_NFC_DEP_PFB_I_PDU:
pr_debug("DIGITAL_NFC_DEP_PFB_I_PDU\n"); pr_debug("DIGITAL_NFC_DEP_PFB_I_PDU\n");
ddev->curr_nfc_dep_pni = DIGITAL_NFC_DEP_PFB_PNI(dep_req->pfb); ddev->curr_nfc_dep_pni = DIGITAL_NFC_DEP_PFB_PNI(pfb);
break; break;
case DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU: case DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU:
pr_err("Received a ACK/NACK PDU\n"); pr_err("Received a ACK/NACK PDU\n");
@ -576,8 +579,6 @@ static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg,
goto exit; goto exit;
} }
skb_pull(resp, size);
rc = nfc_tm_data_received(ddev->nfc_dev, resp); rc = nfc_tm_data_received(ddev->nfc_dev, resp);
exit: exit: